blob: c359499866e6b489849c4b72fad64a9b11eca9e0 [file] [log] [blame]
Amin Hassani10c8c6c2020-04-06 12:28:59 -07001// 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 Hassanif2efc5a2020-05-25 21:22:57 -070010#include <vector>
Amin Hassani10c8c6c2020-04-06 12:28:59 -070011
12#include <base/files/file_path.h>
13#include <base/files/scoped_temp_dir.h>
Amin Hassani5698ce52020-06-10 10:40:14 -070014#include <base/test/simple_test_clock.h>
Amin Hassanif656f292020-06-08 16:20:01 -070015#include <brillo/message_loops/fake_message_loop.h>
Amin Hassani10c8c6c2020-04-06 12:28:59 -070016#include <dlcservice/proto_bindings/dlcservice.pb.h>
Amin Hassani10c8c6c2020-04-06 12:28:59 -070017#include <imageloader/dbus-proxy-mocks.h>
Amin Hassani759090b2020-04-13 12:31:10 -070018#include <session_manager/dbus-proxy-mocks.h>
Amin Hassanid488ced2020-04-07 15:33:56 -070019#include <update_engine/proto_bindings/update_engine.pb.h>
Amin Hassani10c8c6c2020-04-06 12:28:59 -070020#include <update_engine/dbus-proxy-mocks.h>
21
Jae Hoon Kim23c7f492020-06-26 10:30:09 -070022#include "dlcservice/boot/mock_boot_device.h"
Amin Hassani10c8c6c2020-04-06 12:28:59 -070023#include "dlcservice/dlc.h"
24#include "dlcservice/dlc_service.h"
Andrew0a534ed2020-05-06 09:59:17 -070025#include "dlcservice/mock_metrics.h"
Amin Hassani78a5ec82020-05-19 09:47:49 -070026#include "dlcservice/mock_state_change_reporter.h"
Jae Hoon Kim9318f342020-09-10 14:38:13 -070027#include "dlcservice/mock_system_properties.h"
Amin Hassani10c8c6c2020-04-06 12:28:59 -070028
29namespace dlcservice {
30
31extern const char kFirstDlc[];
32extern const char kSecondDlc[];
33extern const char kThirdDlc[];
34extern const char kPackage[];
35extern const char kDefaultOmahaUrl[];
36
Amin Hassani78a5ec82020-05-19 09:47:49 -070037MATCHER_P3(CheckDlcStateProto, state, progress, root_path, "") {
38 return arg.state() == state && arg.progress() == progress &&
39 arg.root_path() == root_path;
40};
41
Amin Hassanic0867b62020-04-16 09:44:34 -070042int64_t GetFileSize(const base::FilePath& path);
43
Amin Hassani10c8c6c2020-04-06 12:28:59 -070044class BaseTest : public testing::Test {
45 public:
46 BaseTest();
47
48 void SetUp() override;
49
50 void SetUpFilesAndDirectories();
51
Amin Hassani28ed9002020-05-28 12:37:01 -070052 // 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 Hassani10c8c6c2020-04-06 12:28:59 -070055
56 // Will create |path/|id|/|package|/dlc_[a|b]/dlc.img files.
Amin Hassanif2efc5a2020-05-25 21:22:57 -070057 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 Hassani10c8c6c2020-04-06 12:28:59 -070061
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 Hassanife63fc22020-04-07 11:34:34 -070073 base::FilePath prefs_path_;
Amin Hassanibfad7b82020-04-13 12:33:47 -070074 base::FilePath users_path_;
Amin Hassani10c8c6c2020-04-06 12:28:59 -070075 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 Hassani759090b2020-04-13 12:31:10 -070085 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 Kim23c7f492020-06-26 10:30:09 -070090 std::unique_ptr<MockBootDevice> mock_boot_device_;
91 MockBootDevice* mock_boot_device_ptr_;
Andrew4d454002020-05-06 09:59:17 -070092
Jae Hoon Kim23c7f492020-06-26 10:30:09 -070093 MockMetrics* mock_metrics_;
Jae Hoon Kim9318f342020-09-10 14:38:13 -070094 MockSystemProperties* mock_system_properties_;
Amin Hassani78a5ec82020-05-19 09:47:49 -070095 MockStateChangeReporter mock_state_change_reporter_;
96
Amin Hassani5698ce52020-06-10 10:40:14 -070097 base::SimpleTestClock clock_;
Amin Hassanif656f292020-06-08 16:20:01 -070098 brillo::FakeMessageLoop loop_{&clock_};
Amin Hassani5698ce52020-06-10 10:40:14 -070099
Amin Hassani10c8c6c2020-04-06 12:28:59 -0700100 private:
Amin Hassani6b010bf2020-06-04 17:26:58 -0700101 BaseTest(const BaseTest&) = delete;
102 BaseTest& operator=(const BaseTest&) = delete;
Amin Hassani10c8c6c2020-04-06 12:28:59 -0700103};
104
105} // namespace dlcservice
106
107#endif // DLCSERVICE_TEST_UTILS_H_