blob: e204914b2d78251226afb39018bbc7dfa2825bb9 [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#ifndef CRASH_REPORTER_TEST_UTIL_H_
6#define CRASH_REPORTER_TEST_UTIL_H_
7
Satoru Takabayashi8ce6db82018-08-17 15:18:41 +09008#include <map>
9#include <string>
10
Satoru Takabayashi5ebb4ce2018-08-16 10:28:13 +090011#include <base/files/file_path.h>
12#include <base/strings/string_piece.h>
Ian Barkley-Yeungc377b092019-10-09 19:23:53 -070013#include <base/time/time.h>
Satoru Takabayashi5ebb4ce2018-08-16 10:28:13 +090014
Satoru Takabayashi8ce6db82018-08-17 15:18:41 +090015#include <session_manager/dbus-proxy-mocks.h>
16
Satoru Takabayashi5ebb4ce2018-08-16 10:28:13 +090017namespace test_util {
18
Ian Barkley-Yeungc377b092019-10-09 19:23:53 -070019// Get an assumed "now" for things that mocks out the current time. Always
20// returns 2018-04-20 13:53.
21base::Time GetDefaultTime();
22
Satoru Takabayashi5ebb4ce2018-08-16 10:28:13 +090023// Creates a file at |file_path| with |content|, with parent directories.
24// Returns true on success. If you want the test function to stop when the file
25// creation failed, wrap this function with ASSERT_TRUE().
26bool CreateFile(const base::FilePath& file_path, base::StringPiece content);
27
Satoru Takabayashi8ce6db82018-08-17 15:18:41 +090028// Configures |mock| so that RetrieveActiveSessions() returns |sessions|.
29void SetActiveSessions(org::chromium::SessionManagerInterfaceProxyMock* mock,
30 const std::map<std::string, std::string>& sessions);
31
Tim Zheng2d09b952019-03-08 16:20:59 -080032// Returns true if at least one file in this directory matches the pattern.
33// found_file_path is not assigned if found_file_path is nullptr.
34// Only the first found path is stored into found_file_path.
35bool DirectoryHasFileWithPattern(const base::FilePath& directory,
36 const std::string& pattern,
37 base::FilePath* found_file_path);
38
Chris Morin92419a72019-06-19 12:35:22 -070039// Return path to an input files used by unit tests.
40base::FilePath GetTestDataPath(const std::string& name);
41
Satoru Takabayashi5ebb4ce2018-08-16 10:28:13 +090042} // namespace test_util
43
44#endif // CRASH_REPORTER_TEST_UTIL_H_