blob: 9baf52a198a58eedd05604e8cfc801db92832f9a [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>
14#include <dlcservice/proto_bindings/dlcservice.pb.h>
Amin Hassani10c8c6c2020-04-06 12:28:59 -070015#include <imageloader/dbus-proxy-mocks.h>
Amin Hassani759090b2020-04-13 12:31:10 -070016#include <session_manager/dbus-proxy-mocks.h>
Amin Hassanid488ced2020-04-07 15:33:56 -070017#include <update_engine/proto_bindings/update_engine.pb.h>
Amin Hassani10c8c6c2020-04-06 12:28:59 -070018#include <update_engine/dbus-proxy-mocks.h>
19
20#include "dlcservice/dlc.h"
21#include "dlcservice/dlc_service.h"
Amin Hassani78a5ec82020-05-19 09:47:49 -070022#include "dlcservice/mock_state_change_reporter.h"
Amin Hassani10c8c6c2020-04-06 12:28:59 -070023
24namespace dlcservice {
25
26extern const char kFirstDlc[];
27extern const char kSecondDlc[];
28extern const char kThirdDlc[];
29extern const char kPackage[];
30extern const char kDefaultOmahaUrl[];
31
Amin Hassani78a5ec82020-05-19 09:47:49 -070032MATCHER_P3(CheckDlcStateProto, state, progress, root_path, "") {
33 return arg.state() == state && arg.progress() == progress &&
34 arg.root_path() == root_path;
35};
36
Amin Hassanic0867b62020-04-16 09:44:34 -070037int64_t GetFileSize(const base::FilePath& path);
38
Amin Hassani10c8c6c2020-04-06 12:28:59 -070039class BaseTest : public testing::Test {
40 public:
41 BaseTest();
42
43 void SetUp() override;
44
45 void SetUpFilesAndDirectories();
46
Amin Hassani28ed9002020-05-28 12:37:01 -070047 // Will create |path|/|id|/|package|/dlc.img file. Will return the path to the
48 // generated preloaded image.
49 base::FilePath SetUpDlcPreloadedImage(const DlcId& id);
Amin Hassani10c8c6c2020-04-06 12:28:59 -070050
51 // Will create |path/|id|/|package|/dlc_[a|b]/dlc.img files.
Amin Hassanif2efc5a2020-05-25 21:22:57 -070052 void SetUpDlcWithSlots(const DlcId& id);
53
54 // Mimics an installation form update_engine on the current boot slot.
55 void InstallWithUpdateEngine(const std::vector<std::string>& ids);
Amin Hassani10c8c6c2020-04-06 12:28:59 -070056
57 void SetMountPath(const std::string& mount_path_expected);
58
59 protected:
60 brillo::ErrorPtr err_;
61
62 base::ScopedTempDir scoped_temp_dir_;
63
64 base::FilePath testdata_path_;
65 base::FilePath manifest_path_;
66 base::FilePath preloaded_content_path_;
67 base::FilePath content_path_;
Amin Hassanife63fc22020-04-07 11:34:34 -070068 base::FilePath prefs_path_;
Amin Hassanibfad7b82020-04-13 12:33:47 -070069 base::FilePath users_path_;
Amin Hassani10c8c6c2020-04-06 12:28:59 -070070 base::FilePath mount_path_;
71
72 using ImageLoaderProxyMock = org::chromium::ImageLoaderInterfaceProxyMock;
73 std::unique_ptr<ImageLoaderProxyMock> mock_image_loader_proxy_;
74 ImageLoaderProxyMock* mock_image_loader_proxy_ptr_;
75
76 using UpdateEngineProxyMock = org::chromium::UpdateEngineInterfaceProxyMock;
77 std::unique_ptr<UpdateEngineProxyMock> mock_update_engine_proxy_;
78 UpdateEngineProxyMock* mock_update_engine_proxy_ptr_;
79
Amin Hassani759090b2020-04-13 12:31:10 -070080 using SessionManagerProxyMock =
81 org::chromium::SessionManagerInterfaceProxyMock;
82 std::unique_ptr<SessionManagerProxyMock> mock_session_manager_proxy_;
83 SessionManagerProxyMock* mock_session_manager_proxy_ptr_;
84
Amin Hassani78a5ec82020-05-19 09:47:49 -070085 MockStateChangeReporter mock_state_change_reporter_;
86
Amin Hassani10c8c6c2020-04-06 12:28:59 -070087 private:
Amin Hassani6b010bf2020-06-04 17:26:58 -070088 BaseTest(const BaseTest&) = delete;
89 BaseTest& operator=(const BaseTest&) = delete;
Amin Hassani10c8c6c2020-04-06 12:28:59 -070090};
91
92} // namespace dlcservice
93
94#endif // DLCSERVICE_TEST_UTILS_H_