blob: 67a34b5b12b298bf70719b133769dadd4937dc3f [file] [log] [blame]
Satoru Takabayashi5ebb4ce2018-08-16 10:28:13 +09001// 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 Takabayashi8ce6db82018-08-17 15:18:41 +09008#include <gtest/gtest.h>
9
10using testing::Invoke;
11using testing::_;
Satoru Takabayashi5ebb4ce2018-08-16 10:28:13 +090012
13namespace test_util {
14
Satoru Takabayashi8ce6db82018-08-17 15:18:41 +090015namespace {
16
17std::map<std::string, std::string>* g_active_sessions;
18
19// Implementation of
20// SessionManagerInterfaceProxyMock::RetrieveActiveSessions().
21bool 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 Takabayashi5ebb4ce2018-08-16 10:28:13 +090032bool 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 Takabayashi8ce6db82018-08-17 15:18:41 +090039void 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 Takabayashi5ebb4ce2018-08-16 10:28:13 +090049} // namespace test_util