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 | #ifndef CRASH_REPORTER_TEST_UTIL_H_ |
| 6 | #define CRASH_REPORTER_TEST_UTIL_H_ |
| 7 | |
Satoru Takabayashi | 8ce6db8 | 2018-08-17 15:18:41 +0900 | [diff] [blame] | 8 | #include <map> |
| 9 | #include <string> |
| 10 | |
Satoru Takabayashi | 5ebb4ce | 2018-08-16 10:28:13 +0900 | [diff] [blame] | 11 | #include <base/files/file_path.h> |
| 12 | #include <base/strings/string_piece.h> |
| 13 | |
Satoru Takabayashi | 8ce6db8 | 2018-08-17 15:18:41 +0900 | [diff] [blame] | 14 | #include <session_manager/dbus-proxy-mocks.h> |
| 15 | |
Satoru Takabayashi | 5ebb4ce | 2018-08-16 10:28:13 +0900 | [diff] [blame] | 16 | namespace test_util { |
| 17 | |
| 18 | // Creates a file at |file_path| with |content|, with parent directories. |
| 19 | // Returns true on success. If you want the test function to stop when the file |
| 20 | // creation failed, wrap this function with ASSERT_TRUE(). |
| 21 | bool CreateFile(const base::FilePath& file_path, base::StringPiece content); |
| 22 | |
Satoru Takabayashi | 8ce6db8 | 2018-08-17 15:18:41 +0900 | [diff] [blame] | 23 | // Configures |mock| so that RetrieveActiveSessions() returns |sessions|. |
| 24 | void SetActiveSessions(org::chromium::SessionManagerInterfaceProxyMock* mock, |
| 25 | const std::map<std::string, std::string>& sessions); |
| 26 | |
Tim Zheng | 2d09b95 | 2019-03-08 16:20:59 -0800 | [diff] [blame] | 27 | // Returns true if at least one file in this directory matches the pattern. |
| 28 | // found_file_path is not assigned if found_file_path is nullptr. |
| 29 | // Only the first found path is stored into found_file_path. |
| 30 | bool DirectoryHasFileWithPattern(const base::FilePath& directory, |
| 31 | const std::string& pattern, |
| 32 | base::FilePath* found_file_path); |
| 33 | |
Chris Morin | 92419a7 | 2019-06-19 12:35:22 -0700 | [diff] [blame^] | 34 | // Return path to an input files used by unit tests. |
| 35 | base::FilePath GetTestDataPath(const std::string& name); |
| 36 | |
Satoru Takabayashi | 5ebb4ce | 2018-08-16 10:28:13 +0900 | [diff] [blame] | 37 | } // namespace test_util |
| 38 | |
| 39 | #endif // CRASH_REPORTER_TEST_UTIL_H_ |