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" |
Mila Green | 3c9375d | 2021-03-17 16:33:59 | [diff] [blame] | 27 | #include "chrome/updater/test/integration_tests_impl.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 | |
| 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) { |
Mila Green | 708bf0d9 | 2021-03-23 17:33:15 | [diff] [blame^] | 92 | const base::Optional<base::FilePath> path = |
| 93 | GetLibraryFolderPath(UpdaterScope::kUser); |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 94 | if (!path) |
| 95 | return base::nullopt; |
| 96 | |
| 97 | return path->AppendASCII(COMPANY_SHORTNAME_STRING) |
Joshua Pawlicki | 6867d7c | 2021-01-06 15:51:09 | [diff] [blame] | 98 | .AppendASCII(COMPANY_SHORTNAME_STRING "SoftwareUpdate") |
| 99 | .AppendASCII("Actives") |
| 100 | .AppendASCII(id); |
| 101 | } |
| 102 | |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 103 | void ExpectServiceAbsent(UpdaterScope scope, const std::string& service) { |
| 104 | VLOG(0) << __func__ << " - scope: " << scope << ". service: " << service; |
Joshua Pawlicki | cd6925c9 | 2020-12-15 15:07:50 | [diff] [blame] | 105 | bool success = false; |
| 106 | base::RunLoop loop; |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 107 | PollLaunchctlList(scope, service, LaunchctlPresence::kAbsent, |
Joshua Pawlicki | cd6925c9 | 2020-12-15 15:07:50 | [diff] [blame] | 108 | base::TimeDelta::FromSeconds(7), |
| 109 | base::BindLambdaForTesting([&](bool result) { |
| 110 | success = result; |
| 111 | loop.QuitClosure().Run(); |
| 112 | })); |
| 113 | loop.Run(); |
| 114 | EXPECT_TRUE(success) << service << " is unexpectedly present."; |
| 115 | } |
| 116 | |
Joshua Pawlicki | 83d1d823 | 2020-10-23 20:13:31 | [diff] [blame] | 117 | } // namespace |
| 118 | |
Joshua Pawlicki | 6867d7c | 2021-01-06 15:51:09 | [diff] [blame] | 119 | void EnterTestMode(const GURL& url) { |
Adam Norberg | 14b66a1 | 2021-01-20 21:54:03 | [diff] [blame] | 120 | ASSERT_TRUE(ExternalConstantsBuilder() |
| 121 | .SetUpdateURL(std::vector<std::string>{url.spec()}) |
| 122 | .SetUseCUP(false) |
Mila Green | 1cb2696 | 2021-01-21 01:00:00 | [diff] [blame] | 123 | .SetInitialDelay(0.1) |
Mila Green | 59389f1 | 2021-02-03 20:52:32 | [diff] [blame] | 124 | .SetServerKeepAliveSeconds(1) |
Adam Norberg | 14b66a1 | 2021-01-20 21:54:03 | [diff] [blame] | 125 | .Overwrite()); |
Joshua Pawlicki | 6867d7c | 2021-01-06 15:51:09 | [diff] [blame] | 126 | } |
| 127 | |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 128 | base::Optional<base::FilePath> GetDataDirPath(UpdaterScope scope) { |
| 129 | base::Optional<base::FilePath> app_path = |
| 130 | GetApplicationSupportDirectory(scope); |
| 131 | if (!app_path) { |
| 132 | VLOG(1) << "Failed to get Application support path."; |
| 133 | return base::nullopt; |
| 134 | } |
Joshua Pawlicki | 6867d7c | 2021-01-06 15:51:09 | [diff] [blame] | 135 | |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 136 | return app_path->AppendASCII(COMPANY_SHORTNAME_STRING) |
Joshua Pawlicki | 9d1340fc | 2020-08-14 20:59:35 | [diff] [blame] | 137 | .AppendASCII(PRODUCT_FULLNAME_STRING); |
| 138 | } |
| 139 | |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 140 | void Clean(UpdaterScope scope) { |
| 141 | Launchd::Domain launchd_domain = LaunchdDomain(scope); |
| 142 | Launchd::Type launchd_type = LaunchdType(scope); |
| 143 | |
| 144 | base::Optional<base::FilePath> path = GetProductPath(scope); |
| 145 | EXPECT_TRUE(path); |
| 146 | if (path) |
| 147 | EXPECT_TRUE(base::DeletePathRecursively(*path)); |
Joshua Pawlicki | 8f755d38 | 2020-03-20 19:51:10 | [diff] [blame] | 148 | EXPECT_TRUE(Launchd::GetInstance()->DeletePlist( |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 149 | launchd_domain, launchd_type, updater::CopyWakeLaunchdName())); |
Joshua Pawlicki | 8f755d38 | 2020-03-20 19:51:10 | [diff] [blame] | 150 | EXPECT_TRUE(Launchd::GetInstance()->DeletePlist( |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 151 | launchd_domain, launchd_type, |
Mila Green | 8084564 | 2020-12-10 03:44:51 | [diff] [blame] | 152 | updater::CopyUpdateServiceInternalLaunchdName())); |
Mila Green | 7414a0ed | 2020-07-21 21:30:42 | [diff] [blame] | 153 | EXPECT_TRUE(Launchd::GetInstance()->DeletePlist( |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 154 | launchd_domain, launchd_type, updater::CopyUpdateServiceLaunchdName())); |
| 155 | |
| 156 | path = GetDataDirPath(scope); |
| 157 | EXPECT_TRUE(path); |
| 158 | if (path) |
| 159 | EXPECT_TRUE(base::DeletePathRecursively(*path)); |
Joshua Pawlicki | 3f64588 | 2020-08-21 20:36:17 | [diff] [blame] | 160 | |
| 161 | @autoreleasepool { |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 162 | RemoveJobFromLaunchd(scope, launchd_domain, launchd_type, |
Mila Green | 3c9375d | 2021-03-17 16:33:59 | [diff] [blame] | 163 | CopyWakeLaunchdName()); |
| 164 | RemoveJobFromLaunchd(scope, launchd_domain, launchd_type, |
Joshua Pawlicki | cd6925c9 | 2020-12-15 15:07:50 | [diff] [blame] | 165 | CopyUpdateServiceLaunchdName()); |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 166 | RemoveJobFromLaunchd(scope, launchd_domain, launchd_type, |
Joshua Pawlicki | cd6925c9 | 2020-12-15 15:07:50 | [diff] [blame] | 167 | CopyUpdateServiceInternalLaunchdName()); |
Joshua Pawlicki | 3f64588 | 2020-08-21 20:36:17 | [diff] [blame] | 168 | } |
Joshua Pawlicki | bae1c6d235 | 2020-03-19 19:21:44 | [diff] [blame] | 169 | } |
| 170 | |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 171 | void ExpectClean(UpdaterScope scope) { |
| 172 | Launchd::Domain launchd_domain = LaunchdDomain(scope); |
| 173 | Launchd::Type launchd_type = LaunchdType(scope); |
| 174 | |
Joshua Pawlicki | bae1c6d235 | 2020-03-19 19:21:44 | [diff] [blame] | 175 | // Files must not exist on the file system. |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 176 | base::Optional<base::FilePath> path = GetProductPath(scope); |
| 177 | EXPECT_TRUE(path); |
| 178 | if (path) |
| 179 | EXPECT_FALSE(base::PathExists(*path)); |
Joshua Pawlicki | 8f755d38 | 2020-03-20 19:51:10 | [diff] [blame] | 180 | EXPECT_FALSE(Launchd::GetInstance()->PlistExists( |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 181 | launchd_domain, launchd_type, updater::CopyWakeLaunchdName())); |
Mila Green | 8ddc4e0 | 2020-05-01 00:15:02 | [diff] [blame] | 182 | EXPECT_FALSE(Launchd::GetInstance()->PlistExists( |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 183 | launchd_domain, launchd_type, |
Mila Green | 8084564 | 2020-12-10 03:44:51 | [diff] [blame] | 184 | updater::CopyUpdateServiceInternalLaunchdName())); |
Mila Green | 7414a0ed | 2020-07-21 21:30:42 | [diff] [blame] | 185 | EXPECT_FALSE(Launchd::GetInstance()->PlistExists( |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 186 | launchd_domain, launchd_type, updater::CopyUpdateServiceLaunchdName())); |
| 187 | |
| 188 | path = GetDataDirPath(scope); |
| 189 | EXPECT_TRUE(path); |
| 190 | if (path) |
| 191 | EXPECT_FALSE(base::PathExists(*path)); |
| 192 | |
| 193 | ExpectServiceAbsent(scope, kUpdateServiceLaunchdName); |
| 194 | ExpectServiceAbsent(scope, kUpdateServiceInternalLaunchdName); |
Joshua Pawlicki | bae1c6d235 | 2020-03-19 19:21:44 | [diff] [blame] | 195 | } |
| 196 | |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 197 | void ExpectInstalled(UpdaterScope scope) { |
| 198 | Launchd::Domain launchd_domain = LaunchdDomain(scope); |
| 199 | Launchd::Type launchd_type = LaunchdType(scope); |
| 200 | |
Joshua Pawlicki | bae1c6d235 | 2020-03-19 19:21:44 | [diff] [blame] | 201 | // Files must exist on the file system. |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 202 | base::Optional<base::FilePath> path = GetProductPath(scope); |
| 203 | EXPECT_TRUE(path); |
| 204 | if (path) |
| 205 | EXPECT_TRUE(base::PathExists(*path)); |
| 206 | |
| 207 | EXPECT_TRUE(Launchd::GetInstance()->PlistExists(launchd_domain, launchd_type, |
Mila Green | 7414a0ed | 2020-07-21 21:30:42 | [diff] [blame] | 208 | CopyWakeLaunchdName())); |
Mila Green | 8084564 | 2020-12-10 03:44:51 | [diff] [blame] | 209 | EXPECT_TRUE(Launchd::GetInstance()->PlistExists( |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 210 | launchd_domain, launchd_type, CopyUpdateServiceInternalLaunchdName())); |
Joshua Pawlicki | bae1c6d235 | 2020-03-19 19:21:44 | [diff] [blame] | 211 | } |
| 212 | |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 213 | void Install(UpdaterScope scope) { |
Mila Green | 8ddc4e0 | 2020-05-01 00:15:02 | [diff] [blame] | 214 | const base::FilePath path = GetExecutablePath(); |
Joshua Pawlicki | bae1c6d235 | 2020-03-19 19:21:44 | [diff] [blame] | 215 | ASSERT_FALSE(path.empty()); |
Michael Chang | e4785a82 | 2020-03-26 20:55:01 | [diff] [blame] | 216 | base::CommandLine command_line(path); |
Joshua Pawlicki | 91ce318b | 2020-09-15 14:35:38 | [diff] [blame] | 217 | command_line.AppendSwitch(kInstallSwitch); |
Mila Green | 8ddc4e0 | 2020-05-01 00:15:02 | [diff] [blame] | 218 | int exit_code = -1; |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 219 | ASSERT_TRUE(Run(scope, command_line, &exit_code)); |
| 220 | EXPECT_EQ(exit_code, 0); |
Mila Green | 8ddc4e0 | 2020-05-01 00:15:02 | [diff] [blame] | 221 | } |
| 222 | |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 223 | void ExpectActiveUpdater(UpdaterScope scope) { |
| 224 | Launchd::Domain launchd_domain = LaunchdDomain(scope); |
| 225 | Launchd::Type launchd_type = LaunchdType(scope); |
| 226 | |
Mila Green | 8ddc4e0 | 2020-05-01 00:15:02 | [diff] [blame] | 227 | // Files must exist on the file system. |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 228 | base::Optional<base::FilePath> path = GetProductPath(scope); |
| 229 | EXPECT_TRUE(path); |
| 230 | if (path) |
| 231 | EXPECT_TRUE(base::PathExists(*path)); |
| 232 | |
Mila Green | 8084564 | 2020-12-10 03:44:51 | [diff] [blame] | 233 | EXPECT_TRUE(Launchd::GetInstance()->PlistExists( |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 234 | launchd_domain, launchd_type, CopyUpdateServiceLaunchdName())); |
Mila Green | 8ddc4e0 | 2020-05-01 00:15:02 | [diff] [blame] | 235 | } |
| 236 | |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 237 | void RegisterTestApp(UpdaterScope scope) { |
Mila Green | 3e3058a | 2020-08-27 16:59:27 | [diff] [blame] | 238 | const base::FilePath path = GetTestAppExecutablePath(); |
| 239 | ASSERT_FALSE(path.empty()); |
| 240 | base::CommandLine command_line(path); |
| 241 | command_line.AppendSwitch(kRegisterUpdaterSwitch); |
| 242 | int exit_code = -1; |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 243 | ASSERT_TRUE(Run(scope, command_line, &exit_code)); |
| 244 | EXPECT_EQ(exit_code, 0); |
Mila Green | 3e3058a | 2020-08-27 16:59:27 | [diff] [blame] | 245 | } |
| 246 | |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 247 | base::Optional<base::FilePath> GetInstalledExecutablePath(UpdaterScope scope) { |
| 248 | return GetUpdaterExecutablePath(scope); |
Mila Green | a3991ae | 2020-10-16 00:10:55 | [diff] [blame] | 249 | } |
| 250 | |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 251 | void ExpectCandidateUninstalled(UpdaterScope scope) { |
| 252 | Launchd::Domain launchd_domain = LaunchdDomain(scope); |
| 253 | Launchd::Type launchd_type = LaunchdType(scope); |
| 254 | |
| 255 | base::Optional<base::FilePath> versioned_folder_path = |
| 256 | GetVersionedUpdaterFolderPath(scope); |
| 257 | EXPECT_TRUE(versioned_folder_path); |
| 258 | if (versioned_folder_path) |
| 259 | EXPECT_FALSE(base::PathExists(*versioned_folder_path)); |
| 260 | |
| 261 | EXPECT_FALSE(Launchd::GetInstance()->PlistExists(launchd_domain, launchd_type, |
| 262 | CopyWakeLaunchdName())); |
Mila Green | a3991ae | 2020-10-16 00:10:55 | [diff] [blame] | 263 | EXPECT_FALSE(Launchd::GetInstance()->PlistExists( |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 264 | launchd_domain, launchd_type, CopyUpdateServiceInternalLaunchdName())); |
Joshua Pawlicki | 4abd132 | 2020-08-19 22:05:57 | [diff] [blame] | 265 | } |
| 266 | |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 267 | void Uninstall(UpdaterScope scope) { |
Joshua Pawlicki | 6867d7c | 2021-01-06 15:51:09 | [diff] [blame] | 268 | if (::testing::Test::HasFailure()) |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 269 | PrintLog(scope); |
adoneria | 1762dd7 | 2020-12-17 17:33:08 | [diff] [blame] | 270 | // Copy logs from GetDataDirPath() before updater uninstalls itself |
| 271 | // and deletes the path. |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 272 | base::Optional<base::FilePath> path = GetDataDirPath(scope); |
| 273 | EXPECT_TRUE(path); |
| 274 | if (path) |
| 275 | CopyLog(*path); |
adoneria | 1762dd7 | 2020-12-17 17:33:08 | [diff] [blame] | 276 | |
| 277 | // Uninstall the updater. |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 278 | path = GetExecutablePath(); |
| 279 | ASSERT_TRUE(path); |
| 280 | base::CommandLine command_line(*path); |
Mila Green | 8ddc4e0 | 2020-05-01 00:15:02 | [diff] [blame] | 281 | command_line.AppendSwitch(kUninstallSwitch); |
Joshua Pawlicki | bae1c6d235 | 2020-03-19 19:21:44 | [diff] [blame] | 282 | int exit_code = -1; |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 283 | ASSERT_TRUE(Run(scope, command_line, &exit_code)); |
| 284 | EXPECT_EQ(exit_code, 0); |
Joshua Pawlicki | bae1c6d235 | 2020-03-19 19:21:44 | [diff] [blame] | 285 | } |
| 286 | |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 287 | base::Optional<base::FilePath> GetFakeUpdaterInstallFolderPath( |
| 288 | UpdaterScope scope, |
| 289 | const base::Version& version) { |
| 290 | return GetExecutableFolderPathForVersion(scope, version); |
Mila Green | a3991ae | 2020-10-16 00:10:55 | [diff] [blame] | 291 | } |
| 292 | |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 293 | void SetActive(UpdaterScope scope, const std::string& app_id) { |
Mila Green | 708bf0d9 | 2021-03-23 17:33:15 | [diff] [blame^] | 294 | const base::Optional<base::FilePath> path = GetActiveFile(scope, app_id); |
| 295 | ASSERT_TRUE(path); |
| 296 | VLOG(0) << "Actives file: " << *path; |
Joshua Pawlicki | 6867d7c | 2021-01-06 15:51:09 | [diff] [blame] | 297 | base::File::Error err = base::File::FILE_OK; |
Mila Green | 708bf0d9 | 2021-03-23 17:33:15 | [diff] [blame^] | 298 | EXPECT_TRUE(base::CreateDirectoryAndGetError(path->DirName(), &err)) |
Joshua Pawlicki | 6867d7c | 2021-01-06 15:51:09 | [diff] [blame] | 299 | << "Error: " << err; |
Mila Green | 708bf0d9 | 2021-03-23 17:33:15 | [diff] [blame^] | 300 | EXPECT_TRUE(base::WriteFile(*path, "")); |
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) { |
Mila Green | 708bf0d9 | 2021-03-23 17:33:15 | [diff] [blame^] | 304 | const base::Optional<base::FilePath> path = GetActiveFile(scope, app_id); |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 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) { |
Mila Green | 708bf0d9 | 2021-03-23 17:33:15 | [diff] [blame^] | 311 | const base::Optional<base::FilePath> path = GetActiveFile(scope, app_id); |
Mila Green | f6d82f8 | 2021-03-05 22:14:29 | [diff] [blame] | 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 |