Amin Hassani | 10c8c6c | 2020-04-06 12:28:59 -0700 | [diff] [blame] | 1 | // Copyright 2020 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 DLCSERVICE_TEST_UTILS_H_ |
| 6 | #define DLCSERVICE_TEST_UTILS_H_ |
| 7 | |
| 8 | #include <memory> |
| 9 | #include <string> |
Amin Hassani | f2efc5a | 2020-05-25 21:22:57 -0700 | [diff] [blame] | 10 | #include <vector> |
Amin Hassani | 10c8c6c | 2020-04-06 12:28:59 -0700 | [diff] [blame] | 11 | |
| 12 | #include <base/files/file_path.h> |
| 13 | #include <base/files/scoped_temp_dir.h> |
Amin Hassani | 5698ce5 | 2020-06-10 10:40:14 -0700 | [diff] [blame] | 14 | #include <base/test/simple_test_clock.h> |
Amin Hassani | f656f29 | 2020-06-08 16:20:01 -0700 | [diff] [blame] | 15 | #include <brillo/message_loops/fake_message_loop.h> |
Amin Hassani | 10c8c6c | 2020-04-06 12:28:59 -0700 | [diff] [blame] | 16 | #include <dlcservice/proto_bindings/dlcservice.pb.h> |
Amin Hassani | 10c8c6c | 2020-04-06 12:28:59 -0700 | [diff] [blame] | 17 | #include <imageloader/dbus-proxy-mocks.h> |
Amin Hassani | 759090b | 2020-04-13 12:31:10 -0700 | [diff] [blame] | 18 | #include <session_manager/dbus-proxy-mocks.h> |
Amin Hassani | d488ced | 2020-04-07 15:33:56 -0700 | [diff] [blame] | 19 | #include <update_engine/proto_bindings/update_engine.pb.h> |
Amin Hassani | 10c8c6c | 2020-04-06 12:28:59 -0700 | [diff] [blame] | 20 | #include <update_engine/dbus-proxy-mocks.h> |
| 21 | |
Jae Hoon Kim | 23c7f49 | 2020-06-26 10:30:09 -0700 | [diff] [blame] | 22 | #include "dlcservice/boot/mock_boot_device.h" |
Amin Hassani | 10c8c6c | 2020-04-06 12:28:59 -0700 | [diff] [blame] | 23 | #include "dlcservice/dlc.h" |
| 24 | #include "dlcservice/dlc_service.h" |
Andrew | 0a534ed | 2020-05-06 09:59:17 -0700 | [diff] [blame] | 25 | #include "dlcservice/mock_metrics.h" |
Amin Hassani | 78a5ec8 | 2020-05-19 09:47:49 -0700 | [diff] [blame] | 26 | #include "dlcservice/mock_state_change_reporter.h" |
Jae Hoon Kim | 9318f34 | 2020-09-10 14:38:13 -0700 | [diff] [blame] | 27 | #include "dlcservice/mock_system_properties.h" |
Amin Hassani | 10c8c6c | 2020-04-06 12:28:59 -0700 | [diff] [blame] | 28 | |
| 29 | namespace dlcservice { |
| 30 | |
| 31 | extern const char kFirstDlc[]; |
| 32 | extern const char kSecondDlc[]; |
| 33 | extern const char kThirdDlc[]; |
| 34 | extern const char kPackage[]; |
| 35 | extern const char kDefaultOmahaUrl[]; |
| 36 | |
Amin Hassani | 78a5ec8 | 2020-05-19 09:47:49 -0700 | [diff] [blame] | 37 | MATCHER_P3(CheckDlcStateProto, state, progress, root_path, "") { |
| 38 | return arg.state() == state && arg.progress() == progress && |
| 39 | arg.root_path() == root_path; |
| 40 | }; |
| 41 | |
Amin Hassani | c0867b6 | 2020-04-16 09:44:34 -0700 | [diff] [blame] | 42 | int64_t GetFileSize(const base::FilePath& path); |
| 43 | |
Amin Hassani | 10c8c6c | 2020-04-06 12:28:59 -0700 | [diff] [blame] | 44 | class BaseTest : public testing::Test { |
| 45 | public: |
| 46 | BaseTest(); |
| 47 | |
| 48 | void SetUp() override; |
| 49 | |
| 50 | void SetUpFilesAndDirectories(); |
| 51 | |
Amin Hassani | 28ed900 | 2020-05-28 12:37:01 -0700 | [diff] [blame] | 52 | // Will create |path|/|id|/|package|/dlc.img file. Will return the path to the |
| 53 | // generated preloaded image. |
| 54 | base::FilePath SetUpDlcPreloadedImage(const DlcId& id); |
Amin Hassani | 10c8c6c | 2020-04-06 12:28:59 -0700 | [diff] [blame] | 55 | |
| 56 | // Will create |path/|id|/|package|/dlc_[a|b]/dlc.img files. |
Amin Hassani | f2efc5a | 2020-05-25 21:22:57 -0700 | [diff] [blame] | 57 | void SetUpDlcWithSlots(const DlcId& id); |
| 58 | |
| 59 | // Mimics an installation form update_engine on the current boot slot. |
| 60 | void InstallWithUpdateEngine(const std::vector<std::string>& ids); |
Amin Hassani | 10c8c6c | 2020-04-06 12:28:59 -0700 | [diff] [blame] | 61 | |
| 62 | void SetMountPath(const std::string& mount_path_expected); |
| 63 | |
| 64 | protected: |
| 65 | brillo::ErrorPtr err_; |
| 66 | |
| 67 | base::ScopedTempDir scoped_temp_dir_; |
| 68 | |
| 69 | base::FilePath testdata_path_; |
| 70 | base::FilePath manifest_path_; |
| 71 | base::FilePath preloaded_content_path_; |
| 72 | base::FilePath content_path_; |
Amin Hassani | fe63fc2 | 2020-04-07 11:34:34 -0700 | [diff] [blame] | 73 | base::FilePath prefs_path_; |
Amin Hassani | bfad7b8 | 2020-04-13 12:33:47 -0700 | [diff] [blame] | 74 | base::FilePath users_path_; |
Amin Hassani | 10c8c6c | 2020-04-06 12:28:59 -0700 | [diff] [blame] | 75 | base::FilePath mount_path_; |
| 76 | |
| 77 | using ImageLoaderProxyMock = org::chromium::ImageLoaderInterfaceProxyMock; |
| 78 | std::unique_ptr<ImageLoaderProxyMock> mock_image_loader_proxy_; |
| 79 | ImageLoaderProxyMock* mock_image_loader_proxy_ptr_; |
| 80 | |
| 81 | using UpdateEngineProxyMock = org::chromium::UpdateEngineInterfaceProxyMock; |
| 82 | std::unique_ptr<UpdateEngineProxyMock> mock_update_engine_proxy_; |
| 83 | UpdateEngineProxyMock* mock_update_engine_proxy_ptr_; |
| 84 | |
Amin Hassani | 759090b | 2020-04-13 12:31:10 -0700 | [diff] [blame] | 85 | using SessionManagerProxyMock = |
| 86 | org::chromium::SessionManagerInterfaceProxyMock; |
| 87 | std::unique_ptr<SessionManagerProxyMock> mock_session_manager_proxy_; |
| 88 | SessionManagerProxyMock* mock_session_manager_proxy_ptr_; |
| 89 | |
Jae Hoon Kim | 23c7f49 | 2020-06-26 10:30:09 -0700 | [diff] [blame] | 90 | std::unique_ptr<MockBootDevice> mock_boot_device_; |
| 91 | MockBootDevice* mock_boot_device_ptr_; |
Andrew | 4d45400 | 2020-05-06 09:59:17 -0700 | [diff] [blame] | 92 | |
Jae Hoon Kim | 23c7f49 | 2020-06-26 10:30:09 -0700 | [diff] [blame] | 93 | MockMetrics* mock_metrics_; |
Jae Hoon Kim | 9318f34 | 2020-09-10 14:38:13 -0700 | [diff] [blame] | 94 | MockSystemProperties* mock_system_properties_; |
Amin Hassani | 78a5ec8 | 2020-05-19 09:47:49 -0700 | [diff] [blame] | 95 | MockStateChangeReporter mock_state_change_reporter_; |
| 96 | |
Amin Hassani | 5698ce5 | 2020-06-10 10:40:14 -0700 | [diff] [blame] | 97 | base::SimpleTestClock clock_; |
Amin Hassani | f656f29 | 2020-06-08 16:20:01 -0700 | [diff] [blame] | 98 | brillo::FakeMessageLoop loop_{&clock_}; |
Amin Hassani | 5698ce5 | 2020-06-10 10:40:14 -0700 | [diff] [blame] | 99 | |
Amin Hassani | 10c8c6c | 2020-04-06 12:28:59 -0700 | [diff] [blame] | 100 | private: |
Amin Hassani | 6b010bf | 2020-06-04 17:26:58 -0700 | [diff] [blame] | 101 | BaseTest(const BaseTest&) = delete; |
| 102 | BaseTest& operator=(const BaseTest&) = delete; |
Amin Hassani | 10c8c6c | 2020-04-06 12:28:59 -0700 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | } // namespace dlcservice |
| 106 | |
| 107 | #endif // DLCSERVICE_TEST_UTILS_H_ |