| Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2020 The Chromium Authors |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| Sorin Jianu | 6badd00 | 2024-01-11 17:29:02 | [diff] [blame] | 5 | #include "chrome/updater/external_constants_builder.h" |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 6 | |
| Sorin Jianu | a4b3d38 | 2023-11-10 20:08:46 | [diff] [blame] | 7 | #include <optional> |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
| 11 | #include "base/files/file_path.h" |
| Joshua Pawlicki | 34aacc1 | 2021-08-24 21:22:21 | [diff] [blame] | 12 | #include "base/memory/scoped_refptr.h" |
| Xiaoling Bao | 760b128a | 2024-10-02 23:17:15 | [diff] [blame] | 13 | #include "base/time/time.h" |
| S. Ganesh | 5b7c6a7 | 2022-05-21 01:20:56 | [diff] [blame] | 14 | #include "base/values.h" |
| Noah Rose Ledesma | 38b7be1 | 2022-09-26 19:15:34 | [diff] [blame] | 15 | #include "build/build_config.h" |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 16 | #include "chrome/updater/constants.h" |
| 17 | #include "chrome/updater/external_constants.h" |
| Joshua Pawlicki | 58a597ed | 2021-06-10 17:00:52 | [diff] [blame] | 18 | #include "chrome/updater/external_constants_default.h" |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 19 | #include "chrome/updater/external_constants_override.h" |
| Sorin Jianu | a961b61 | 2024-05-02 22:07:57 | [diff] [blame] | 20 | #include "chrome/updater/test/test_scope.h" |
| 21 | #include "chrome/updater/test/unit_test_util.h" |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 22 | #include "chrome/updater/updater_branding.h" |
| Noah Rose Ledesma | fc9b365 | 2022-11-12 02:10:49 | [diff] [blame] | 23 | #include "chrome/updater/util/util.h" |
| Sorin Jianu | 6badd00 | 2024-01-11 17:29:02 | [diff] [blame] | 24 | #include "testing/gtest/include/gtest/gtest.h" |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 25 | #include "url/gurl.h" |
| 26 | |
| 27 | namespace updater { |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 28 | |
| 29 | class ExternalConstantsBuilderTests : public ::testing::Test { |
| 30 | protected: |
| Sorin Jianu | 86d1ef6 | 2022-10-06 22:16:02 | [diff] [blame] | 31 | void SetUp() override { |
| 32 | EXPECT_TRUE( |
| 33 | test::DeleteFileAndEmptyParentDirectories(overrides_file_path_)); |
| 34 | } |
| 35 | void TearDown() override { |
| 36 | EXPECT_TRUE( |
| 37 | test::DeleteFileAndEmptyParentDirectories(overrides_file_path_)); |
| 38 | } |
| 39 | |
| 40 | private: |
| 41 | // This test runs non-elevated. |
| Sorin Jianu | a4b3d38 | 2023-11-10 20:08:46 | [diff] [blame] | 42 | const std::optional<base::FilePath> overrides_file_path_ = |
| Joshua Pawlicki | 3185e6a | 2023-02-07 19:32:31 | [diff] [blame] | 43 | GetOverrideFilePath(UpdaterScope::kUser); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 44 | }; |
| 45 | |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 46 | TEST_F(ExternalConstantsBuilderTests, TestOverridingNothing) { |
| 47 | EXPECT_TRUE(ExternalConstantsBuilder().Overwrite()); |
| 48 | |
| Joshua Pawlicki | 34aacc1 | 2021-08-24 21:22:21 | [diff] [blame] | 49 | scoped_refptr<ExternalConstantsOverrider> verifier = |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 50 | ExternalConstantsOverrider::FromDefaultJSONFile( |
| Joshua Pawlicki | 58a597ed | 2021-06-10 17:00:52 | [diff] [blame] | 51 | CreateDefaultExternalConstants()); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 52 | |
| 53 | EXPECT_TRUE(verifier->UseCUP()); |
| 54 | |
| 55 | std::vector<GURL> urls = verifier->UpdateURL(); |
| 56 | ASSERT_EQ(urls.size(), 1ul); |
| 57 | EXPECT_EQ(urls[0], GURL(UPDATE_CHECK_URL)); |
| 58 | |
| 59 | EXPECT_EQ(verifier->InitialDelay(), kInitialDelay); |
| Noah Rose Ledesma | d391ac33 | 2022-12-13 21:09:06 | [diff] [blame] | 60 | EXPECT_EQ(verifier->ServerKeepAliveTime(), kServerKeepAliveTime); |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 61 | EXPECT_EQ(verifier->DictPolicies().size(), 0U); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | TEST_F(ExternalConstantsBuilderTests, TestOverridingEverything) { |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 65 | base::Value::Dict dict_policies; |
| 66 | dict_policies.Set("a", 1); |
| 67 | dict_policies.Set("b", 2); |
| S. Ganesh | 5b7c6a7 | 2022-05-21 01:20:56 | [diff] [blame] | 68 | |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 69 | ExternalConstantsBuilder builder; |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame^] | 70 | builder.SetUpdateURL(std::vector<std::string>{"https://localhost/1/www"}) |
| 71 | .SetCrashUploadURL("https://localhost/1/crash") |
| 72 | .SetDeviceManagementURL("https://localhost/1/dm") |
| 73 | .SetAppLogoURL("https://localhost/1/applogo/") |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 74 | .SetUseCUP(false) |
| Noah Rose Ledesma | d391ac33 | 2022-12-13 21:09:06 | [diff] [blame] | 75 | .SetInitialDelay(base::Seconds(123)) |
| 76 | .SetServerKeepAliveTime(base::Seconds(2)) |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 77 | .SetDictPolicies(dict_policies) |
| Joshua Pawlicki | e581259 | 2023-06-12 17:24:54 | [diff] [blame] | 78 | .SetOverinstallTimeout(base::Seconds(3)) |
| Xiaoling Bao | bea6946 | 2023-08-01 01:59:03 | [diff] [blame] | 79 | .SetIdleCheckPeriod(base::Seconds(4)) |
| Sorin Jianu | a4b3d38 | 2023-11-10 20:08:46 | [diff] [blame] | 80 | .SetMachineManaged(std::make_optional(true)) |
| Xiaoling Bao | 760b128a | 2024-10-02 23:17:15 | [diff] [blame] | 81 | .SetEnableDiffUpdates(true) |
| 82 | .SetCecaConnectionTimeout(base::Seconds(7)); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 83 | EXPECT_TRUE(builder.Overwrite()); |
| 84 | |
| Joshua Pawlicki | 34aacc1 | 2021-08-24 21:22:21 | [diff] [blame] | 85 | scoped_refptr<ExternalConstantsOverrider> verifier = |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 86 | ExternalConstantsOverrider::FromDefaultJSONFile( |
| Joshua Pawlicki | 58a597ed | 2021-06-10 17:00:52 | [diff] [blame] | 87 | CreateDefaultExternalConstants()); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 88 | |
| 89 | EXPECT_FALSE(verifier->UseCUP()); |
| 90 | |
| 91 | std::vector<GURL> urls = verifier->UpdateURL(); |
| 92 | ASSERT_EQ(urls.size(), 1ul); |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame^] | 93 | EXPECT_EQ(urls[0], GURL("https://localhost/1/www")); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 94 | |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame^] | 95 | EXPECT_EQ(verifier->CrashUploadURL(), GURL("https://localhost/1/crash")); |
| 96 | EXPECT_EQ(verifier->DeviceManagementURL(), GURL("https://localhost/1/dm")); |
| 97 | EXPECT_EQ(verifier->AppLogoURL(), GURL("https://localhost/1/applogo/")); |
| Noah Rose Ledesma | d391ac33 | 2022-12-13 21:09:06 | [diff] [blame] | 98 | EXPECT_EQ(verifier->InitialDelay(), base::Seconds(123)); |
| 99 | EXPECT_EQ(verifier->ServerKeepAliveTime(), base::Seconds(2)); |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 100 | EXPECT_EQ(verifier->DictPolicies().size(), 2U); |
| Joshua Pawlicki | e581259 | 2023-06-12 17:24:54 | [diff] [blame] | 101 | EXPECT_EQ(verifier->OverinstallTimeout(), base::Seconds(3)); |
| 102 | EXPECT_EQ(verifier->IdleCheckPeriod(), base::Seconds(4)); |
| Xiaoling Bao | bea6946 | 2023-08-01 01:59:03 | [diff] [blame] | 103 | EXPECT_TRUE(verifier->IsMachineManaged().has_value()); |
| 104 | EXPECT_TRUE(verifier->IsMachineManaged().value()); |
| Adam Norberg | e158b07 | 2023-10-19 18:55:43 | [diff] [blame] | 105 | EXPECT_TRUE(verifier->EnableDiffUpdates()); |
| Xiaoling Bao | 760b128a | 2024-10-02 23:17:15 | [diff] [blame] | 106 | EXPECT_EQ(verifier->CecaConnectionTimeout(), base::Seconds(7)); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | TEST_F(ExternalConstantsBuilderTests, TestPartialOverrideWithMultipleURLs) { |
| 110 | ExternalConstantsBuilder builder; |
| 111 | EXPECT_TRUE(builder |
| 112 | .SetUpdateURL(std::vector<std::string>{ |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame^] | 113 | "https://localhost/update", "https://localhost/update2"}) |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 114 | .Overwrite()); |
| 115 | |
| Joshua Pawlicki | 34aacc1 | 2021-08-24 21:22:21 | [diff] [blame] | 116 | scoped_refptr<ExternalConstantsOverrider> verifier = |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 117 | ExternalConstantsOverrider::FromDefaultJSONFile( |
| Joshua Pawlicki | 58a597ed | 2021-06-10 17:00:52 | [diff] [blame] | 118 | CreateDefaultExternalConstants()); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 119 | |
| 120 | EXPECT_TRUE(verifier->UseCUP()); |
| 121 | |
| 122 | std::vector<GURL> urls = verifier->UpdateURL(); |
| 123 | ASSERT_EQ(urls.size(), 2ul); |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame^] | 124 | EXPECT_EQ(urls[0], GURL("https://localhost/update")); |
| 125 | EXPECT_EQ(urls[1], GURL("https://localhost/update2")); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 126 | |
| Xiaoling Bao | 616a535 | 2023-04-03 22:00:58 | [diff] [blame] | 127 | EXPECT_EQ(verifier->CrashUploadURL(), GURL(CRASH_UPLOAD_URL)); |
| 128 | EXPECT_EQ(verifier->DeviceManagementURL(), |
| 129 | GURL(DEVICE_MANAGEMENT_SERVER_URL)); |
| S. Ganesh | 0f34f8b | 2024-03-13 21:08:44 | [diff] [blame] | 130 | EXPECT_EQ(verifier->AppLogoURL(), GURL(APP_LOGO_URL)); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 131 | EXPECT_EQ(verifier->InitialDelay(), kInitialDelay); |
| Noah Rose Ledesma | d391ac33 | 2022-12-13 21:09:06 | [diff] [blame] | 132 | EXPECT_EQ(verifier->ServerKeepAliveTime(), kServerKeepAliveTime); |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 133 | EXPECT_EQ(verifier->DictPolicies().size(), 0U); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | TEST_F(ExternalConstantsBuilderTests, TestClearedEverything) { |
| 137 | ExternalConstantsBuilder builder; |
| 138 | EXPECT_TRUE(builder |
| 139 | .SetUpdateURL(std::vector<std::string>{ |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame^] | 140 | "https://localhost/1/localhost/update", "https://www"}) |
| 141 | .SetCrashUploadURL("https://localhost/1/crash") |
| 142 | .SetDeviceManagementURL("https://localhost/1/dm") |
| 143 | .SetAppLogoURL("https://localhost/1/applogo/") |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 144 | .SetUseCUP(false) |
| Noah Rose Ledesma | d391ac33 | 2022-12-13 21:09:06 | [diff] [blame] | 145 | .SetInitialDelay(base::Seconds(123.4)) |
| Adam Norberg | e158b07 | 2023-10-19 18:55:43 | [diff] [blame] | 146 | .SetEnableDiffUpdates(true) |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 147 | .ClearUpdateURL() |
| Xiaoling Bao | 616a535 | 2023-04-03 22:00:58 | [diff] [blame] | 148 | .ClearCrashUploadURL() |
| 149 | .ClearDeviceManagementURL() |
| S. Ganesh | 0f34f8b | 2024-03-13 21:08:44 | [diff] [blame] | 150 | .ClearAppLogoURL() |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 151 | .ClearUseCUP() |
| 152 | .ClearInitialDelay() |
| Mila Green | 59389f1 | 2021-02-03 20:52:32 | [diff] [blame] | 153 | .ClearServerKeepAliveSeconds() |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 154 | .ClearDictPolicies() |
| Joshua Pawlicki | e581259 | 2023-06-12 17:24:54 | [diff] [blame] | 155 | .ClearOverinstallTimeout() |
| 156 | .ClearIdleCheckPeriod() |
| Xiaoling Bao | bea6946 | 2023-08-01 01:59:03 | [diff] [blame] | 157 | .ClearMachineManaged() |
| Adam Norberg | e158b07 | 2023-10-19 18:55:43 | [diff] [blame] | 158 | .ClearEnableDiffUpdates() |
| Xiaoling Bao | 760b128a | 2024-10-02 23:17:15 | [diff] [blame] | 159 | .ClearCecaConnectionTimeout() |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 160 | .Overwrite()); |
| 161 | |
| Joshua Pawlicki | 34aacc1 | 2021-08-24 21:22:21 | [diff] [blame] | 162 | scoped_refptr<ExternalConstantsOverrider> verifier = |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 163 | ExternalConstantsOverrider::FromDefaultJSONFile( |
| Joshua Pawlicki | 58a597ed | 2021-06-10 17:00:52 | [diff] [blame] | 164 | CreateDefaultExternalConstants()); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 165 | EXPECT_TRUE(verifier->UseCUP()); |
| 166 | |
| 167 | std::vector<GURL> urls = verifier->UpdateURL(); |
| 168 | ASSERT_EQ(urls.size(), 1ul); |
| 169 | EXPECT_EQ(urls[0], GURL(UPDATE_CHECK_URL)); |
| 170 | |
| Xiaoling Bao | 616a535 | 2023-04-03 22:00:58 | [diff] [blame] | 171 | EXPECT_EQ(verifier->CrashUploadURL(), GURL(CRASH_UPLOAD_URL)); |
| 172 | EXPECT_EQ(verifier->DeviceManagementURL(), |
| 173 | GURL(DEVICE_MANAGEMENT_SERVER_URL)); |
| S. Ganesh | 0f34f8b | 2024-03-13 21:08:44 | [diff] [blame] | 174 | EXPECT_EQ(verifier->AppLogoURL(), GURL(APP_LOGO_URL)); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 175 | EXPECT_EQ(verifier->InitialDelay(), kInitialDelay); |
| Noah Rose Ledesma | d391ac33 | 2022-12-13 21:09:06 | [diff] [blame] | 176 | EXPECT_EQ(verifier->ServerKeepAliveTime(), kServerKeepAliveTime); |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 177 | EXPECT_EQ(verifier->DictPolicies().size(), 0U); |
| Xiaoling Bao | bea6946 | 2023-08-01 01:59:03 | [diff] [blame] | 178 | EXPECT_FALSE(verifier->IsMachineManaged().has_value()); |
| Adam Norberg | e158b07 | 2023-10-19 18:55:43 | [diff] [blame] | 179 | EXPECT_FALSE(verifier->EnableDiffUpdates()); |
| Xiaoling Bao | 760b128a | 2024-10-02 23:17:15 | [diff] [blame] | 180 | EXPECT_EQ(verifier->CecaConnectionTimeout(), kCecaConnectionTimeout); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | TEST_F(ExternalConstantsBuilderTests, TestOverSet) { |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 184 | base::Value::Dict dict_policies; |
| 185 | dict_policies.Set("a", 1); |
| S. Ganesh | 5b7c6a7 | 2022-05-21 01:20:56 | [diff] [blame] | 186 | |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 187 | EXPECT_TRUE( |
| 188 | ExternalConstantsBuilder() |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame^] | 189 | .SetUpdateURL(std::vector<std::string>{"https://localhost/update"}) |
| 190 | .SetCrashUploadURL("https://localhost/crash") |
| 191 | .SetDeviceManagementURL("https://localhost/dm") |
| 192 | .SetAppLogoURL("https://localhost/logo/") |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 193 | .SetUseCUP(true) |
| Noah Rose Ledesma | d391ac33 | 2022-12-13 21:09:06 | [diff] [blame] | 194 | .SetInitialDelay(base::Seconds(123.4)) |
| 195 | .SetServerKeepAliveTime(base::Seconds(2)) |
| Sorin Jianu | a4b3d38 | 2023-11-10 20:08:46 | [diff] [blame] | 196 | .SetMachineManaged(std::make_optional(true)) |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 197 | .SetDictPolicies(dict_policies) |
| Adam Norberg | e158b07 | 2023-10-19 18:55:43 | [diff] [blame] | 198 | .SetEnableDiffUpdates(false) |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame^] | 199 | .SetUpdateURL(std::vector<std::string>{"https://localhost/1/www"}) |
| 200 | .SetCrashUploadURL("https://localhost/1/crash") |
| 201 | .SetDeviceManagementURL("https://localhost/1/dm") |
| 202 | .SetAppLogoURL("https://localhost/1/applogo/") |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 203 | .SetUseCUP(false) |
| Noah Rose Ledesma | d391ac33 | 2022-12-13 21:09:06 | [diff] [blame] | 204 | .SetInitialDelay(base::Seconds(937.6)) |
| 205 | .SetServerKeepAliveTime(base::Seconds(3)) |
| Sorin Jianu | a4b3d38 | 2023-11-10 20:08:46 | [diff] [blame] | 206 | .SetMachineManaged(std::make_optional(false)) |
| Adam Norberg | e158b07 | 2023-10-19 18:55:43 | [diff] [blame] | 207 | .SetEnableDiffUpdates(true) |
| Xiaoling Bao | 760b128a | 2024-10-02 23:17:15 | [diff] [blame] | 208 | .SetCecaConnectionTimeout(base::Seconds(38)) |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 209 | .Overwrite()); |
| 210 | |
| 211 | // Only the second set of values should be observed. |
| Joshua Pawlicki | 34aacc1 | 2021-08-24 21:22:21 | [diff] [blame] | 212 | scoped_refptr<ExternalConstantsOverrider> verifier = |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 213 | ExternalConstantsOverrider::FromDefaultJSONFile( |
| Joshua Pawlicki | 58a597ed | 2021-06-10 17:00:52 | [diff] [blame] | 214 | CreateDefaultExternalConstants()); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 215 | EXPECT_FALSE(verifier->UseCUP()); |
| 216 | |
| 217 | std::vector<GURL> urls = verifier->UpdateURL(); |
| 218 | ASSERT_EQ(urls.size(), 1ul); |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame^] | 219 | EXPECT_EQ(urls[0], GURL("https://localhost/1/www")); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 220 | |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame^] | 221 | EXPECT_EQ(verifier->CrashUploadURL(), GURL("https://localhost/1/crash")); |
| 222 | EXPECT_EQ(verifier->DeviceManagementURL(), GURL("https://localhost/1/dm")); |
| 223 | EXPECT_EQ(verifier->AppLogoURL(), GURL("https://localhost/1/applogo/")); |
| Noah Rose Ledesma | d391ac33 | 2022-12-13 21:09:06 | [diff] [blame] | 224 | EXPECT_EQ(verifier->InitialDelay(), base::Seconds(937.6)); |
| 225 | EXPECT_EQ(verifier->ServerKeepAliveTime(), base::Seconds(3)); |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 226 | EXPECT_EQ(verifier->DictPolicies().size(), 1U); |
| Xiaoling Bao | bea6946 | 2023-08-01 01:59:03 | [diff] [blame] | 227 | EXPECT_TRUE(verifier->IsMachineManaged().has_value()); |
| 228 | EXPECT_FALSE(verifier->IsMachineManaged().value()); |
| Adam Norberg | e158b07 | 2023-10-19 18:55:43 | [diff] [blame] | 229 | EXPECT_TRUE(verifier->EnableDiffUpdates()); |
| Xiaoling Bao | 760b128a | 2024-10-02 23:17:15 | [diff] [blame] | 230 | EXPECT_EQ(verifier->CecaConnectionTimeout(), base::Seconds(38)); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | TEST_F(ExternalConstantsBuilderTests, TestReuseBuilder) { |
| 234 | ExternalConstantsBuilder builder; |
| S. Ganesh | 5b7c6a7 | 2022-05-21 01:20:56 | [diff] [blame] | 235 | |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 236 | base::Value::Dict dict_policies; |
| 237 | dict_policies.Set("a", 1); |
| 238 | dict_policies.Set("b", 2); |
| S. Ganesh | 5b7c6a7 | 2022-05-21 01:20:56 | [diff] [blame] | 239 | |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 240 | EXPECT_TRUE( |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame^] | 241 | builder.SetUpdateURL(std::vector<std::string>{"https://localhost/update"}) |
| 242 | .SetCrashUploadURL("https://localhost/crash") |
| 243 | .SetDeviceManagementURL("https://localhost/dm") |
| 244 | .SetAppLogoURL("https://localhost/logo/") |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 245 | .SetUseCUP(false) |
| Noah Rose Ledesma | d391ac33 | 2022-12-13 21:09:06 | [diff] [blame] | 246 | .SetInitialDelay(base::Seconds(123.4)) |
| 247 | .SetServerKeepAliveTime(base::Seconds(3)) |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame^] | 248 | .SetUpdateURL(std::vector<std::string>{"https://localhost/1/www"}) |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 249 | .SetDictPolicies(dict_policies) |
| Sorin Jianu | a4b3d38 | 2023-11-10 20:08:46 | [diff] [blame] | 250 | .SetMachineManaged(std::make_optional(true)) |
| Adam Norberg | e158b07 | 2023-10-19 18:55:43 | [diff] [blame] | 251 | .SetEnableDiffUpdates(true) |
| Xiaoling Bao | 760b128a | 2024-10-02 23:17:15 | [diff] [blame] | 252 | .SetCecaConnectionTimeout(base::Seconds(5)) |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 253 | .Overwrite()); |
| 254 | |
| Joshua Pawlicki | 34aacc1 | 2021-08-24 21:22:21 | [diff] [blame] | 255 | scoped_refptr<ExternalConstantsOverrider> verifier = |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 256 | ExternalConstantsOverrider::FromDefaultJSONFile( |
| Joshua Pawlicki | 58a597ed | 2021-06-10 17:00:52 | [diff] [blame] | 257 | CreateDefaultExternalConstants()); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 258 | |
| 259 | EXPECT_FALSE(verifier->UseCUP()); |
| 260 | |
| 261 | std::vector<GURL> urls = verifier->UpdateURL(); |
| 262 | ASSERT_EQ(urls.size(), 1ul); |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame^] | 263 | EXPECT_EQ(urls[0], GURL("https://localhost/1/www")); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 264 | |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame^] | 265 | EXPECT_EQ(verifier->CrashUploadURL(), GURL("https://localhost/crash")); |
| 266 | EXPECT_EQ(verifier->DeviceManagementURL(), GURL("https://localhost/dm")); |
| 267 | EXPECT_EQ(verifier->AppLogoURL(), GURL("https://localhost/logo/")); |
| Noah Rose Ledesma | d391ac33 | 2022-12-13 21:09:06 | [diff] [blame] | 268 | EXPECT_EQ(verifier->InitialDelay(), base::Seconds(123.4)); |
| 269 | EXPECT_EQ(verifier->ServerKeepAliveTime(), base::Seconds(3)); |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 270 | EXPECT_EQ(verifier->DictPolicies().size(), 2U); |
| Xiaoling Bao | bea6946 | 2023-08-01 01:59:03 | [diff] [blame] | 271 | EXPECT_TRUE(verifier->IsMachineManaged().has_value()); |
| 272 | EXPECT_TRUE(verifier->IsMachineManaged().value()); |
| Adam Norberg | e158b07 | 2023-10-19 18:55:43 | [diff] [blame] | 273 | EXPECT_TRUE(verifier->EnableDiffUpdates()); |
| Xiaoling Bao | 760b128a | 2024-10-02 23:17:15 | [diff] [blame] | 274 | EXPECT_EQ(verifier->CecaConnectionTimeout(), base::Seconds(5)); |
| S. Ganesh | 5b7c6a7 | 2022-05-21 01:20:56 | [diff] [blame] | 275 | |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 276 | base::Value::Dict dict_policies2; |
| 277 | dict_policies2.Set("b", 2); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 278 | |
| 279 | // But now we can use the builder again: |
| Noah Rose Ledesma | d391ac33 | 2022-12-13 21:09:06 | [diff] [blame] | 280 | EXPECT_TRUE(builder.SetInitialDelay(base::Seconds(92.3)) |
| 281 | .SetServerKeepAliveTime(base::Seconds(4)) |
| Mila Green | 59389f1 | 2021-02-03 20:52:32 | [diff] [blame] | 282 | .ClearUpdateURL() |
| Xiaoling Bao | 616a535 | 2023-04-03 22:00:58 | [diff] [blame] | 283 | .ClearCrashUploadURL() |
| 284 | .ClearDeviceManagementURL() |
| S. Ganesh | 0f34f8b | 2024-03-13 21:08:44 | [diff] [blame] | 285 | .ClearAppLogoURL() |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 286 | .SetDictPolicies(dict_policies2) |
| Xiaoling Bao | bea6946 | 2023-08-01 01:59:03 | [diff] [blame] | 287 | .ClearMachineManaged() |
| Adam Norberg | e158b07 | 2023-10-19 18:55:43 | [diff] [blame] | 288 | .SetEnableDiffUpdates(false) |
| Xiaoling Bao | 760b128a | 2024-10-02 23:17:15 | [diff] [blame] | 289 | .ClearCecaConnectionTimeout() |
| Mila Green | 59389f1 | 2021-02-03 20:52:32 | [diff] [blame] | 290 | .Overwrite()); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 291 | |
| 292 | // We need a new overrider to verify because it only loads once. |
| Joshua Pawlicki | 34aacc1 | 2021-08-24 21:22:21 | [diff] [blame] | 293 | scoped_refptr<ExternalConstantsOverrider> verifier2 = |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 294 | ExternalConstantsOverrider::FromDefaultJSONFile( |
| Joshua Pawlicki | 58a597ed | 2021-06-10 17:00:52 | [diff] [blame] | 295 | CreateDefaultExternalConstants()); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 296 | |
| 297 | EXPECT_FALSE(verifier2->UseCUP()); // Not updated, value should be retained. |
| 298 | |
| 299 | std::vector<GURL> urls2 = verifier2->UpdateURL(); |
| 300 | ASSERT_EQ(urls2.size(), 1ul); |
| 301 | EXPECT_EQ(urls2[0], GURL(UPDATE_CHECK_URL)); // Cleared; should be default. |
| 302 | |
| Xiaoling Bao | 616a535 | 2023-04-03 22:00:58 | [diff] [blame] | 303 | EXPECT_EQ(verifier2->CrashUploadURL(), GURL(CRASH_UPLOAD_URL)); |
| 304 | EXPECT_EQ(verifier2->DeviceManagementURL(), |
| 305 | GURL(DEVICE_MANAGEMENT_SERVER_URL)); |
| S. Ganesh | 0f34f8b | 2024-03-13 21:08:44 | [diff] [blame] | 306 | EXPECT_EQ(verifier2->AppLogoURL(), GURL(APP_LOGO_URL)); |
| Mila Green | 1cb2696 | 2021-01-21 01:00:00 | [diff] [blame] | 307 | EXPECT_EQ(verifier2->InitialDelay(), |
| Noah Rose Ledesma | d391ac33 | 2022-12-13 21:09:06 | [diff] [blame] | 308 | base::Seconds(92.3)); // Updated; update should be seen. |
| 309 | EXPECT_EQ(verifier2->ServerKeepAliveTime(), base::Seconds(4)); |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 310 | EXPECT_EQ(verifier2->DictPolicies().size(), 1U); |
| Xiaoling Bao | bea6946 | 2023-08-01 01:59:03 | [diff] [blame] | 311 | EXPECT_FALSE(verifier2->IsMachineManaged().has_value()); |
| Adam Norberg | e158b07 | 2023-10-19 18:55:43 | [diff] [blame] | 312 | EXPECT_FALSE(verifier2->EnableDiffUpdates()); |
| Xiaoling Bao | 760b128a | 2024-10-02 23:17:15 | [diff] [blame] | 313 | EXPECT_EQ(verifier2->CecaConnectionTimeout(), kCecaConnectionTimeout); |
| S. Ganesh | 5b7c6a7 | 2022-05-21 01:20:56 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | TEST_F(ExternalConstantsBuilderTests, TestModify) { |
| 317 | ExternalConstantsBuilder builder; |
| 318 | |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 319 | base::Value::Dict dict_policies; |
| 320 | dict_policies.Set("a", 1); |
| 321 | dict_policies.Set("b", 2); |
| S. Ganesh | 5b7c6a7 | 2022-05-21 01:20:56 | [diff] [blame] | 322 | |
| 323 | EXPECT_TRUE( |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame^] | 324 | builder.SetUpdateURL(std::vector<std::string>{"https://localhost/update"}) |
| 325 | .SetCrashUploadURL("https://localhost/crash") |
| 326 | .SetDeviceManagementURL("https://localhost/dm") |
| 327 | .SetAppLogoURL("https://localhost/logo/") |
| S. Ganesh | 5b7c6a7 | 2022-05-21 01:20:56 | [diff] [blame] | 328 | .SetUseCUP(false) |
| Noah Rose Ledesma | d391ac33 | 2022-12-13 21:09:06 | [diff] [blame] | 329 | .SetInitialDelay(base::Seconds(123.4)) |
| 330 | .SetServerKeepAliveTime(base::Seconds(3)) |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame^] | 331 | .SetUpdateURL(std::vector<std::string>{"https://localhost/1/www"}) |
| 332 | .SetCrashUploadURL("https://localhost/1/crash") |
| 333 | .SetDeviceManagementURL("https://localhost/1/dm") |
| 334 | .SetAppLogoURL("https://localhost/1/applogo/") |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 335 | .SetDictPolicies(dict_policies) |
| Sorin Jianu | a4b3d38 | 2023-11-10 20:08:46 | [diff] [blame] | 336 | .SetMachineManaged(std::make_optional(false)) |
| Adam Norberg | e158b07 | 2023-10-19 18:55:43 | [diff] [blame] | 337 | .SetEnableDiffUpdates(true) |
| Xiaoling Bao | 760b128a | 2024-10-02 23:17:15 | [diff] [blame] | 338 | .SetCecaConnectionTimeout(base::Seconds(55)) |
| S. Ganesh | 5b7c6a7 | 2022-05-21 01:20:56 | [diff] [blame] | 339 | .Overwrite()); |
| 340 | |
| 341 | scoped_refptr<ExternalConstantsOverrider> verifier = |
| 342 | ExternalConstantsOverrider::FromDefaultJSONFile( |
| 343 | CreateDefaultExternalConstants()); |
| 344 | |
| 345 | EXPECT_FALSE(verifier->UseCUP()); |
| 346 | |
| 347 | std::vector<GURL> urls = verifier->UpdateURL(); |
| 348 | ASSERT_EQ(urls.size(), 1ul); |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame^] | 349 | EXPECT_EQ(urls[0], GURL("https://localhost/1/www")); |
| S. Ganesh | 5b7c6a7 | 2022-05-21 01:20:56 | [diff] [blame] | 350 | |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame^] | 351 | EXPECT_EQ(verifier->CrashUploadURL(), GURL("https://localhost/1/crash")); |
| 352 | EXPECT_EQ(verifier->DeviceManagementURL(), GURL("https://localhost/1/dm")); |
| 353 | EXPECT_EQ(verifier->AppLogoURL(), GURL("https://localhost/1/applogo/")); |
| Noah Rose Ledesma | d391ac33 | 2022-12-13 21:09:06 | [diff] [blame] | 354 | EXPECT_EQ(verifier->InitialDelay(), base::Seconds(123.4)); |
| 355 | EXPECT_EQ(verifier->ServerKeepAliveTime(), base::Seconds(3)); |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 356 | EXPECT_EQ(verifier->DictPolicies().size(), 2U); |
| Xiaoling Bao | bea6946 | 2023-08-01 01:59:03 | [diff] [blame] | 357 | EXPECT_TRUE(verifier->IsMachineManaged().has_value()); |
| 358 | EXPECT_FALSE(verifier->IsMachineManaged().value()); |
| Adam Norberg | e158b07 | 2023-10-19 18:55:43 | [diff] [blame] | 359 | EXPECT_TRUE(verifier->EnableDiffUpdates()); |
| Xiaoling Bao | 760b128a | 2024-10-02 23:17:15 | [diff] [blame] | 360 | EXPECT_EQ(verifier->CecaConnectionTimeout(), base::Seconds(55)); |
| S. Ganesh | 5b7c6a7 | 2022-05-21 01:20:56 | [diff] [blame] | 361 | |
| 362 | // Now we use a new builder to modify just the group policies. |
| 363 | ExternalConstantsBuilder builder2; |
| 364 | |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 365 | base::Value::Dict dict_policies2; |
| 366 | dict_policies2.Set("b", 2); |
| S. Ganesh | 5b7c6a7 | 2022-05-21 01:20:56 | [diff] [blame] | 367 | |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 368 | EXPECT_TRUE(builder2.SetDictPolicies(dict_policies2).Modify()); |
| S. Ganesh | 5b7c6a7 | 2022-05-21 01:20:56 | [diff] [blame] | 369 | |
| 370 | // We need a new overrider to verify because it only loads once. |
| 371 | scoped_refptr<ExternalConstantsOverrider> verifier2 = |
| 372 | ExternalConstantsOverrider::FromDefaultJSONFile( |
| 373 | CreateDefaultExternalConstants()); |
| 374 | |
| 375 | // Only the group policies are different. |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 376 | EXPECT_EQ(verifier2->DictPolicies().size(), 1U); |
| S. Ganesh | 5b7c6a7 | 2022-05-21 01:20:56 | [diff] [blame] | 377 | |
| 378 | // All the values below are unchanged. |
| 379 | EXPECT_FALSE(verifier2->UseCUP()); |
| 380 | urls = verifier2->UpdateURL(); |
| 381 | ASSERT_EQ(urls.size(), 1ul); |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame^] | 382 | EXPECT_EQ(urls[0], GURL("https://localhost/1/www")); |
| 383 | EXPECT_EQ(verifier2->CrashUploadURL(), GURL("https://localhost/1/crash")); |
| 384 | EXPECT_EQ(verifier2->DeviceManagementURL(), GURL("https://localhost/1/dm")); |
| 385 | EXPECT_EQ(verifier2->AppLogoURL(), GURL("https://localhost/1/applogo/")); |
| Noah Rose Ledesma | d391ac33 | 2022-12-13 21:09:06 | [diff] [blame] | 386 | EXPECT_EQ(verifier2->InitialDelay(), base::Seconds(123.4)); |
| 387 | EXPECT_EQ(verifier2->ServerKeepAliveTime(), base::Seconds(3)); |
| Xiaoling Bao | bea6946 | 2023-08-01 01:59:03 | [diff] [blame] | 388 | EXPECT_TRUE(verifier2->IsMachineManaged().has_value()); |
| 389 | EXPECT_FALSE(verifier2->IsMachineManaged().value()); |
| Adam Norberg | e158b07 | 2023-10-19 18:55:43 | [diff] [blame] | 390 | EXPECT_TRUE(verifier2->EnableDiffUpdates()); |
| Xiaoling Bao | 760b128a | 2024-10-02 23:17:15 | [diff] [blame] | 391 | EXPECT_EQ(verifier2->CecaConnectionTimeout(), base::Seconds(55)); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 392 | } |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 393 | |
| 394 | } // namespace updater |