Satoru Takabayashi | 5ebb4ce | 2018-08-16 10:28:13 +0900 | [diff] [blame] | 1 | // Copyright 2018 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "crash-reporter/test_util.h" |
| 6 | |
| 7 | #include <base/files/file_util.h> |
Satoru Takabayashi | 8ce6db8 | 2018-08-17 15:18:41 +0900 | [diff] [blame^] | 8 | #include <gtest/gtest.h> |
| 9 | |
| 10 | using testing::Invoke; |
| 11 | using testing::_; |
Satoru Takabayashi | 5ebb4ce | 2018-08-16 10:28:13 +0900 | [diff] [blame] | 12 | |
| 13 | namespace test_util { |
| 14 | |
Satoru Takabayashi | 8ce6db8 | 2018-08-17 15:18:41 +0900 | [diff] [blame^] | 15 | namespace { |
| 16 | |
| 17 | std::map<std::string, std::string>* g_active_sessions; |
| 18 | |
| 19 | // Implementation of |
| 20 | // SessionManagerInterfaceProxyMock::RetrieveActiveSessions(). |
| 21 | bool RetrieveActiveSessionsImpl( |
| 22 | std::map<std::string, std::string>* out_sessions, |
| 23 | brillo::ErrorPtr* error, |
| 24 | int timeout_ms = dbus::ObjectProxy::TIMEOUT_USE_DEFAULT) { |
| 25 | DCHECK(g_active_sessions); // Set in SetActiveSessions(). |
| 26 | *out_sessions = *g_active_sessions; |
| 27 | return true; |
| 28 | } |
| 29 | |
| 30 | } // namespace |
| 31 | |
Satoru Takabayashi | 5ebb4ce | 2018-08-16 10:28:13 +0900 | [diff] [blame] | 32 | bool CreateFile(const base::FilePath& file_path, base::StringPiece content) { |
| 33 | if (!base::CreateDirectory(file_path.DirName())) |
| 34 | return false; |
| 35 | return base::WriteFile(file_path, content.data(), content.size()) == |
| 36 | content.size(); |
| 37 | } |
| 38 | |
Satoru Takabayashi | 8ce6db8 | 2018-08-17 15:18:41 +0900 | [diff] [blame^] | 39 | void SetActiveSessions(org::chromium::SessionManagerInterfaceProxyMock* mock, |
| 40 | const std::map<std::string, std::string>& sessions) { |
| 41 | if (g_active_sessions) |
| 42 | delete g_active_sessions; |
| 43 | g_active_sessions = new std::map<std::string, std::string>(sessions); |
| 44 | |
| 45 | EXPECT_CALL(*mock, RetrieveActiveSessions(_, _, _)) |
| 46 | .WillRepeatedly(Invoke(&RetrieveActiveSessionsImpl)); |
| 47 | } |
| 48 | |
Satoru Takabayashi | 5ebb4ce | 2018-08-16 10:28:13 +0900 | [diff] [blame] | 49 | } // namespace test_util |