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