Joshua Pawlicki | bae1c6d235 | 2020-03-19 19:21:44 | [diff] [blame] | 1 | // Copyright 2020 The Chromium 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 | |
Mila Green | a3991ae | 2020-10-16 00:10:55 | [diff] [blame] | 5 | #include <stdint.h> |
Joshua Pawlicki | 6867d7c | 2021-01-06 15:51:09 | [diff] [blame] | 6 | #include <string> |
Adam Norberg | 14b66a1 | 2021-01-20 21:54:03 | [diff] [blame] | 7 | #include <vector> |
Mila Green | a3991ae | 2020-10-16 00:10:55 | [diff] [blame] | 8 | |
Joshua Pawlicki | bae1c6d235 | 2020-03-19 19:21:44 | [diff] [blame] | 9 | #include "base/command_line.h" |
| 10 | #include "base/files/file_path.h" |
| 11 | #include "base/files/file_util.h" |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 12 | #include "base/logging.h" |
Joshua Pawlicki | bae1c6d235 | 2020-03-19 19:21:44 | [diff] [blame] | 13 | #include "base/mac/foundation_util.h" |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 14 | #include "base/optional.h" |
Joshua Pawlicki | bae1c6d235 | 2020-03-19 19:21:44 | [diff] [blame] | 15 | #include "base/path_service.h" |
Joshua Pawlicki | cd6925c9 | 2020-12-15 15:07:50 | [diff] [blame] | 16 | #include "base/run_loop.h" |
| 17 | #include "base/strings/sys_string_conversions.h" |
| 18 | #include "base/test/bind.h" |
Mila Green | a3991ae | 2020-10-16 00:10:55 | [diff] [blame] | 19 | #include "base/version.h" |
Joshua Pawlicki | 8f755d38 | 2020-03-20 19:51:10 | [diff] [blame] | 20 | #include "chrome/common/mac/launchd.h" |
Mila Green | 8ddc4e0 | 2020-05-01 00:15:02 | [diff] [blame] | 21 | #include "chrome/updater/constants.h" |
Adam Norberg | 14b66a1 | 2021-01-20 21:54:03 | [diff] [blame] | 22 | #include "chrome/updater/external_constants_builder.h" |
Joshua Pawlicki | cd6925c9 | 2020-12-15 15:07:50 | [diff] [blame] | 23 | #include "chrome/updater/launchd_util.h" |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 24 | #import "chrome/updater/mac/mac_util.h" |
Joshua Pawlicki | 8f755d38 | 2020-03-20 19:51:10 | [diff] [blame] | 25 | #include "chrome/updater/mac/xpc_service_names.h" |
Mila Green | a3991ae | 2020-10-16 00:10:55 | [diff] [blame] | 26 | #include "chrome/updater/prefs.h" |
Joshua Pawlicki | 83d1d823 | 2020-10-23 20:13:31 | [diff] [blame] | 27 | #include "chrome/updater/test/integration_tests.h" |
Mila Green | 3e3058a | 2020-08-27 16:59:27 | [diff] [blame] | 28 | #include "chrome/updater/test/test_app/constants.h" |
| 29 | #include "chrome/updater/test/test_app/test_app_version.h" |
Mila Green | aff08690 | 2021-01-07 22:00:52 | [diff] [blame] | 30 | #include "chrome/updater/updater_branding.h" |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 31 | #include "chrome/updater/updater_scope.h" |
Joshua Pawlicki | 4abd132 | 2020-08-19 22:05:57 | [diff] [blame] | 32 | #include "chrome/updater/util.h" |
Joshua Pawlicki | bae1c6d235 | 2020-03-19 19:21:44 | [diff] [blame] | 33 | #include "testing/gtest/include/gtest/gtest.h" |
Joshua Pawlicki | 6867d7c | 2021-01-06 15:51:09 | [diff] [blame] | 34 | #include "url/gurl.h" |
Joshua Pawlicki | bae1c6d235 | 2020-03-19 19:21:44 | [diff] [blame] | 35 | |
| 36 | namespace updater { |
Joshua Pawlicki | bae1c6d235 | 2020-03-19 19:21:44 | [diff] [blame] | 37 | namespace test { |
| 38 | |
Joshua Pawlicki | bae1c6d235 | 2020-03-19 19:21:44 | [diff] [blame] | 39 | namespace { |
| 40 | |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 41 | Launchd::Domain LaunchdDomain(UpdaterScope scope) { |
| 42 | switch (scope) { |
| 43 | case UpdaterScope::kSystem: |
| 44 | return Launchd::Domain::Local; |
| 45 | case UpdaterScope::kUser: |
| 46 | return Launchd::Domain::User; |
| 47 | } |
| 48 | } |
Joshua Pawlicki | cd6925c9 | 2020-12-15 15:07:50 | [diff] [blame] | 49 | |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 50 | Launchd::Type LaunchdType(UpdaterScope scope) { |
| 51 | switch (scope) { |
| 52 | case UpdaterScope::kSystem: |
| 53 | return Launchd::Type::Daemon; |
| 54 | case UpdaterScope::kUser: |
| 55 | return Launchd::Type::Agent; |
| 56 | } |
Joshua Pawlicki | cd6925c9 | 2020-12-15 15:07:50 | [diff] [blame] | 57 | } |
| 58 | |
Joshua Pawlicki | bae1c6d235 | 2020-03-19 19:21:44 | [diff] [blame] | 59 | base::FilePath GetExecutablePath() { |
| 60 | base::FilePath test_executable; |
| 61 | if (!base::PathService::Get(base::FILE_EXE, &test_executable)) |
| 62 | return base::FilePath(); |
| 63 | return test_executable.DirName() |
Mila Green | a3991ae | 2020-10-16 00:10:55 | [diff] [blame] | 64 | .Append(FILE_PATH_LITERAL(PRODUCT_FULLNAME_STRING ".app")) |
Joshua Pawlicki | bae1c6d235 | 2020-03-19 19:21:44 | [diff] [blame] | 65 | .Append(FILE_PATH_LITERAL("Contents")) |
| 66 | .Append(FILE_PATH_LITERAL("MacOS")) |
| 67 | .Append(FILE_PATH_LITERAL(PRODUCT_FULLNAME_STRING)); |
| 68 | } |
| 69 | |
Mila Green | 3e3058a | 2020-08-27 16:59:27 | [diff] [blame] | 70 | base::FilePath GetTestAppExecutablePath() { |
| 71 | base::FilePath test_executable; |
| 72 | if (!base::PathService::Get(base::FILE_EXE, &test_executable)) |
| 73 | return base::FilePath(); |
| 74 | return test_executable.DirName() |
Mila Green | a3991ae | 2020-10-16 00:10:55 | [diff] [blame] | 75 | .Append(FILE_PATH_LITERAL(TEST_APP_FULLNAME_STRING ".app")) |
Mila Green | 3e3058a | 2020-08-27 16:59:27 | [diff] [blame] | 76 | .Append(FILE_PATH_LITERAL("Contents")) |
| 77 | .Append(FILE_PATH_LITERAL("MacOS")) |
| 78 | .Append(FILE_PATH_LITERAL(TEST_APP_FULLNAME_STRING)); |
| 79 | } |
| 80 | |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 81 | base::Optional<base::FilePath> GetProductPath(UpdaterScope scope) { |
| 82 | base::Optional<base::FilePath> path = GetLibraryFolderPath(scope); |
| 83 | if (!path) |
| 84 | return base::nullopt; |
| 85 | |
| 86 | return path->AppendASCII(COMPANY_SHORTNAME_STRING) |
Joshua Pawlicki | 8f755d38 | 2020-03-20 19:51:10 | [diff] [blame] | 87 | .AppendASCII(PRODUCT_FULLNAME_STRING); |
| 88 | } |
| 89 | |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 90 | base::Optional<base::FilePath> GetActiveFile(UpdaterScope scope, |
| 91 | const std::string& id) { |
| 92 | base::Optional<base::FilePath> path = GetLibraryFolderPath(scope); |
| 93 | if (!path) |
| 94 | return base::nullopt; |
| 95 | |
| 96 | return path->AppendASCII(COMPANY_SHORTNAME_STRING) |
Joshua Pawlicki | 6867d7c | 2021-01-06 15:51:09 | [diff] [blame] | 97 | .AppendASCII(COMPANY_SHORTNAME_STRING "SoftwareUpdate") |
| 98 | .AppendASCII("Actives") |
| 99 | .AppendASCII(id); |
| 100 | } |
| 101 | |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 102 | void ExpectServiceAbsent(UpdaterScope scope, const std::string& service) { |
| 103 | VLOG(0) << __func__ << " - scope: " << scope << ". service: " << service; |
Joshua Pawlicki | cd6925c9 | 2020-12-15 15:07:50 | [diff] [blame] | 104 | bool success = false; |
| 105 | base::RunLoop loop; |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 106 | PollLaunchctlList(scope, service, LaunchctlPresence::kAbsent, |
Joshua Pawlicki | cd6925c9 | 2020-12-15 15:07:50 | [diff] [blame] | 107 | base::TimeDelta::FromSeconds(7), |
| 108 | base::BindLambdaForTesting([&](bool result) { |
| 109 | success = result; |
| 110 | loop.QuitClosure().Run(); |
| 111 | })); |
| 112 | loop.Run(); |
| 113 | EXPECT_TRUE(success) << service << " is unexpectedly present."; |
| 114 | } |
| 115 | |
Joshua Pawlicki | 83d1d823 | 2020-10-23 20:13:31 | [diff] [blame] | 116 | } // namespace |
| 117 | |
Joshua Pawlicki | 6867d7c | 2021-01-06 15:51:09 | [diff] [blame] | 118 | void EnterTestMode(const GURL& url) { |
Adam Norberg | 14b66a1 | 2021-01-20 21:54:03 | [diff] [blame] | 119 | ASSERT_TRUE(ExternalConstantsBuilder() |
| 120 | .SetUpdateURL(std::vector<std::string>{url.spec()}) |
| 121 | .SetUseCUP(false) |
Mila Green | 1cb2696 | 2021-01-21 01:00:00 | [diff] [blame] | 122 | .SetInitialDelay(0.1) |
Mila Green | 59389f1 | 2021-02-03 20:52:32 | [diff] [blame] | 123 | .SetServerKeepAliveSeconds(1) |
Adam Norberg | 14b66a1 | 2021-01-20 21:54:03 | [diff] [blame] | 124 | .Overwrite()); |
Joshua Pawlicki | 6867d7c | 2021-01-06 15:51:09 | [diff] [blame] | 125 | } |
| 126 | |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 127 | base::Optional<base::FilePath> GetDataDirPath(UpdaterScope scope) { |
| 128 | base::Optional<base::FilePath> app_path = |
| 129 | GetApplicationSupportDirectory(scope); |
| 130 | if (!app_path) { |
| 131 | VLOG(1) << "Failed to get Application support path."; |
| 132 | return base::nullopt; |
| 133 | } |
Joshua Pawlicki | 6867d7c | 2021-01-06 15:51:09 | [diff] [blame] | 134 | |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 135 | return app_path->AppendASCII(COMPANY_SHORTNAME_STRING) |
Joshua Pawlicki | 9d1340fc | 2020-08-14 20:59:35 | [diff] [blame] | 136 | .AppendASCII(PRODUCT_FULLNAME_STRING); |
| 137 | } |
| 138 | |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 139 | void Clean(UpdaterScope scope) { |
| 140 | Launchd::Domain launchd_domain = LaunchdDomain(scope); |
| 141 | Launchd::Type launchd_type = LaunchdType(scope); |
| 142 | |
| 143 | base::Optional<base::FilePath> path = GetProductPath(scope); |
| 144 | EXPECT_TRUE(path); |
| 145 | if (path) |
| 146 | EXPECT_TRUE(base::DeletePathRecursively(*path)); |
Joshua Pawlicki | 8f755d38 | 2020-03-20 19:51:10 | [diff] [blame] | 147 | EXPECT_TRUE(Launchd::GetInstance()->DeletePlist( |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 148 | launchd_domain, launchd_type, updater::CopyWakeLaunchdName())); |
Joshua Pawlicki | 8f755d38 | 2020-03-20 19:51:10 | [diff] [blame] | 149 | EXPECT_TRUE(Launchd::GetInstance()->DeletePlist( |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 150 | launchd_domain, launchd_type, |
Mila Green | 8084564 | 2020-12-10 03:44:51 | [diff] [blame] | 151 | updater::CopyUpdateServiceInternalLaunchdName())); |
Mila Green | 7414a0ed | 2020-07-21 21:30:42 | [diff] [blame] | 152 | EXPECT_TRUE(Launchd::GetInstance()->DeletePlist( |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 153 | launchd_domain, launchd_type, updater::CopyUpdateServiceLaunchdName())); |
| 154 | |
| 155 | path = GetDataDirPath(scope); |
| 156 | EXPECT_TRUE(path); |
| 157 | if (path) |
| 158 | EXPECT_TRUE(base::DeletePathRecursively(*path)); |
Joshua Pawlicki | 3f64588 | 2020-08-21 20:36:17 | [diff] [blame] | 159 | |
| 160 | @autoreleasepool { |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 161 | RemoveJobFromLaunchd(scope, launchd_domain, launchd_type, |
Joshua Pawlicki | cd6925c9 | 2020-12-15 15:07:50 | [diff] [blame] | 162 | CopyUpdateServiceLaunchdName()); |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 163 | RemoveJobFromLaunchd(scope, launchd_domain, launchd_type, |
Joshua Pawlicki | cd6925c9 | 2020-12-15 15:07:50 | [diff] [blame] | 164 | CopyUpdateServiceInternalLaunchdName()); |
Joshua Pawlicki | 3f64588 | 2020-08-21 20:36:17 | [diff] [blame] | 165 | } |
Joshua Pawlicki | bae1c6d235 | 2020-03-19 19:21:44 | [diff] [blame] | 166 | } |
| 167 | |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 168 | void ExpectClean(UpdaterScope scope) { |
| 169 | Launchd::Domain launchd_domain = LaunchdDomain(scope); |
| 170 | Launchd::Type launchd_type = LaunchdType(scope); |
| 171 | |
Joshua Pawlicki | bae1c6d235 | 2020-03-19 19:21:44 | [diff] [blame] | 172 | // Files must not exist on the file system. |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 173 | base::Optional<base::FilePath> path = GetProductPath(scope); |
| 174 | EXPECT_TRUE(path); |
| 175 | if (path) |
| 176 | EXPECT_FALSE(base::PathExists(*path)); |
Joshua Pawlicki | 8f755d38 | 2020-03-20 19:51:10 | [diff] [blame] | 177 | EXPECT_FALSE(Launchd::GetInstance()->PlistExists( |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 178 | launchd_domain, launchd_type, updater::CopyWakeLaunchdName())); |
Mila Green | 8ddc4e0 | 2020-05-01 00:15:02 | [diff] [blame] | 179 | EXPECT_FALSE(Launchd::GetInstance()->PlistExists( |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 180 | launchd_domain, launchd_type, |
Mila Green | 8084564 | 2020-12-10 03:44:51 | [diff] [blame] | 181 | updater::CopyUpdateServiceInternalLaunchdName())); |
Mila Green | 7414a0ed | 2020-07-21 21:30:42 | [diff] [blame] | 182 | EXPECT_FALSE(Launchd::GetInstance()->PlistExists( |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 183 | launchd_domain, launchd_type, updater::CopyUpdateServiceLaunchdName())); |
| 184 | |
| 185 | path = GetDataDirPath(scope); |
| 186 | EXPECT_TRUE(path); |
| 187 | if (path) |
| 188 | EXPECT_FALSE(base::PathExists(*path)); |
| 189 | |
| 190 | ExpectServiceAbsent(scope, kUpdateServiceLaunchdName); |
| 191 | ExpectServiceAbsent(scope, kUpdateServiceInternalLaunchdName); |
Joshua Pawlicki | bae1c6d235 | 2020-03-19 19:21:44 | [diff] [blame] | 192 | } |
| 193 | |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 194 | void ExpectInstalled(UpdaterScope scope) { |
| 195 | Launchd::Domain launchd_domain = LaunchdDomain(scope); |
| 196 | Launchd::Type launchd_type = LaunchdType(scope); |
| 197 | |
| 198 | VLOG(0) << "Scope :" << scope |
| 199 | << "; GetProductPath(scope): " << GetProductPath(scope); |
Joshua Pawlicki | bae1c6d235 | 2020-03-19 19:21:44 | [diff] [blame] | 200 | // Files must exist on the file system. |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 201 | base::Optional<base::FilePath> path = GetProductPath(scope); |
| 202 | EXPECT_TRUE(path); |
| 203 | if (path) |
| 204 | EXPECT_TRUE(base::PathExists(*path)); |
| 205 | |
| 206 | EXPECT_TRUE(Launchd::GetInstance()->PlistExists(launchd_domain, launchd_type, |
Mila Green | 7414a0ed | 2020-07-21 21:30:42 | [diff] [blame] | 207 | CopyWakeLaunchdName())); |
Mila Green | 8084564 | 2020-12-10 03:44:51 | [diff] [blame] | 208 | EXPECT_TRUE(Launchd::GetInstance()->PlistExists( |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 209 | launchd_domain, launchd_type, CopyUpdateServiceInternalLaunchdName())); |
Joshua Pawlicki | bae1c6d235 | 2020-03-19 19:21:44 | [diff] [blame] | 210 | } |
| 211 | |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 212 | void Install(UpdaterScope scope) { |
Mila Green | 8ddc4e0 | 2020-05-01 00:15:02 | [diff] [blame] | 213 | const base::FilePath path = GetExecutablePath(); |
Joshua Pawlicki | bae1c6d235 | 2020-03-19 19:21:44 | [diff] [blame] | 214 | ASSERT_FALSE(path.empty()); |
Michael Chang | e4785a82 | 2020-03-26 20:55:01 | [diff] [blame] | 215 | base::CommandLine command_line(path); |
Joshua Pawlicki | 91ce318b | 2020-09-15 14:35:38 | [diff] [blame] | 216 | command_line.AppendSwitch(kInstallSwitch); |
Mila Green | 8ddc4e0 | 2020-05-01 00:15:02 | [diff] [blame] | 217 | int exit_code = -1; |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 218 | ASSERT_TRUE(Run(scope, command_line, &exit_code)); |
| 219 | EXPECT_EQ(exit_code, 0); |
Mila Green | 8ddc4e0 | 2020-05-01 00:15:02 | [diff] [blame] | 220 | } |
| 221 | |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 222 | void ExpectActiveUpdater(UpdaterScope scope) { |
| 223 | Launchd::Domain launchd_domain = LaunchdDomain(scope); |
| 224 | Launchd::Type launchd_type = LaunchdType(scope); |
| 225 | |
Mila Green | 8ddc4e0 | 2020-05-01 00:15:02 | [diff] [blame] | 226 | // Files must exist on the file system. |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 227 | base::Optional<base::FilePath> path = GetProductPath(scope); |
| 228 | EXPECT_TRUE(path); |
| 229 | if (path) |
| 230 | EXPECT_TRUE(base::PathExists(*path)); |
| 231 | |
Mila Green | 8084564 | 2020-12-10 03:44:51 | [diff] [blame] | 232 | EXPECT_TRUE(Launchd::GetInstance()->PlistExists( |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 233 | launchd_domain, launchd_type, CopyUpdateServiceLaunchdName())); |
Mila Green | 8ddc4e0 | 2020-05-01 00:15:02 | [diff] [blame] | 234 | } |
| 235 | |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 236 | void RegisterTestApp(UpdaterScope scope) { |
Mila Green | 3e3058a | 2020-08-27 16:59:27 | [diff] [blame] | 237 | const base::FilePath path = GetTestAppExecutablePath(); |
| 238 | ASSERT_FALSE(path.empty()); |
| 239 | base::CommandLine command_line(path); |
| 240 | command_line.AppendSwitch(kRegisterUpdaterSwitch); |
| 241 | int exit_code = -1; |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 242 | ASSERT_TRUE(Run(scope, command_line, &exit_code)); |
| 243 | EXPECT_EQ(exit_code, 0); |
Mila Green | 3e3058a | 2020-08-27 16:59:27 | [diff] [blame] | 244 | } |
| 245 | |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 246 | base::Optional<base::FilePath> GetInstalledExecutablePath(UpdaterScope scope) { |
| 247 | return GetUpdaterExecutablePath(scope); |
Mila Green | a3991ae | 2020-10-16 00:10:55 | [diff] [blame] | 248 | } |
| 249 | |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 250 | void ExpectCandidateUninstalled(UpdaterScope scope) { |
| 251 | Launchd::Domain launchd_domain = LaunchdDomain(scope); |
| 252 | Launchd::Type launchd_type = LaunchdType(scope); |
| 253 | |
| 254 | base::Optional<base::FilePath> versioned_folder_path = |
| 255 | GetVersionedUpdaterFolderPath(scope); |
| 256 | EXPECT_TRUE(versioned_folder_path); |
| 257 | if (versioned_folder_path) |
| 258 | EXPECT_FALSE(base::PathExists(*versioned_folder_path)); |
| 259 | |
| 260 | EXPECT_FALSE(Launchd::GetInstance()->PlistExists(launchd_domain, launchd_type, |
| 261 | CopyWakeLaunchdName())); |
Mila Green | a3991ae | 2020-10-16 00:10:55 | [diff] [blame] | 262 | EXPECT_FALSE(Launchd::GetInstance()->PlistExists( |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 263 | launchd_domain, launchd_type, CopyUpdateServiceInternalLaunchdName())); |
Joshua Pawlicki | 4abd132 | 2020-08-19 22:05:57 | [diff] [blame] | 264 | } |
| 265 | |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 266 | void Uninstall(UpdaterScope scope) { |
Joshua Pawlicki | 6867d7c | 2021-01-06 15:51:09 | [diff] [blame] | 267 | if (::testing::Test::HasFailure()) |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 268 | PrintLog(scope); |
adoneria | 1762dd7 | 2020-12-17 17:33:08 | [diff] [blame] | 269 | // Copy logs from GetDataDirPath() before updater uninstalls itself |
| 270 | // and deletes the path. |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 271 | base::Optional<base::FilePath> path = GetDataDirPath(scope); |
| 272 | EXPECT_TRUE(path); |
| 273 | if (path) |
| 274 | CopyLog(*path); |
adoneria | 1762dd7 | 2020-12-17 17:33:08 | [diff] [blame] | 275 | |
| 276 | // Uninstall the updater. |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 277 | path = GetExecutablePath(); |
| 278 | ASSERT_TRUE(path); |
| 279 | base::CommandLine command_line(*path); |
Mila Green | 8ddc4e0 | 2020-05-01 00:15:02 | [diff] [blame] | 280 | command_line.AppendSwitch(kUninstallSwitch); |
Joshua Pawlicki | bae1c6d235 | 2020-03-19 19:21:44 | [diff] [blame] | 281 | int exit_code = -1; |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 282 | ASSERT_TRUE(Run(scope, command_line, &exit_code)); |
| 283 | EXPECT_EQ(exit_code, 0); |
Joshua Pawlicki | bae1c6d235 | 2020-03-19 19:21:44 | [diff] [blame] | 284 | } |
| 285 | |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 286 | base::Optional<base::FilePath> GetFakeUpdaterInstallFolderPath( |
| 287 | UpdaterScope scope, |
| 288 | const base::Version& version) { |
| 289 | return GetExecutableFolderPathForVersion(scope, version); |
Mila Green | a3991ae | 2020-10-16 00:10:55 | [diff] [blame] | 290 | } |
| 291 | |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 292 | void SetActive(UpdaterScope scope, const std::string& app_id) { |
Joshua Pawlicki | 6867d7c | 2021-01-06 15:51:09 | [diff] [blame] | 293 | base::File::Error err = base::File::FILE_OK; |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 294 | base::Optional<base::FilePath> actives_file = GetActiveFile(scope, app_id); |
| 295 | ASSERT_TRUE(actives_file); |
| 296 | VLOG(0) << "Actives file: " << *actives_file; |
| 297 | VLOG(0) << "Actives file dir name: " << actives_file->DirName(); |
| 298 | EXPECT_TRUE(base::CreateDirectoryAndGetError(actives_file->DirName(), &err)) |
Joshua Pawlicki | 6867d7c | 2021-01-06 15:51:09 | [diff] [blame] | 299 | << "Error: " << err; |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 300 | EXPECT_TRUE(base::WriteFile(*actives_file, "")); |
Joshua Pawlicki | 6867d7c | 2021-01-06 15:51:09 | [diff] [blame] | 301 | } |
| 302 | |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 303 | void ExpectActive(UpdaterScope scope, const std::string& app_id) { |
| 304 | base::Optional<base::FilePath> path = GetActiveFile(scope, app_id); |
| 305 | ASSERT_TRUE(path); |
| 306 | EXPECT_TRUE(base::PathExists(*path)); |
| 307 | EXPECT_TRUE(base::PathIsWritable(*path)); |
Joshua Pawlicki | 6867d7c | 2021-01-06 15:51:09 | [diff] [blame] | 308 | } |
| 309 | |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame^] | 310 | void ExpectNotActive(UpdaterScope scope, const std::string& app_id) { |
| 311 | base::Optional<base::FilePath> path = GetActiveFile(scope, app_id); |
| 312 | ASSERT_TRUE(path); |
| 313 | EXPECT_FALSE(base::PathExists(*path)); |
| 314 | EXPECT_FALSE(base::PathIsWritable(*path)); |
Joshua Pawlicki | 6867d7c | 2021-01-06 15:51:09 | [diff] [blame] | 315 | } |
| 316 | |
Joshua Pawlicki | bae1c6d235 | 2020-03-19 19:21:44 | [diff] [blame] | 317 | } // namespace test |
Joshua Pawlicki | bae1c6d235 | 2020-03-19 19:21:44 | [diff] [blame] | 318 | } // namespace updater |