| 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") |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame] | 72 | .SetAppLogoURL("https://localhost/1/applogo/") |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 73 | .SetUseCUP(false) |
| Noah Rose Ledesma | d391ac33 | 2022-12-13 21:09:06 | [diff] [blame] | 74 | .SetInitialDelay(base::Seconds(123)) |
| 75 | .SetServerKeepAliveTime(base::Seconds(2)) |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 76 | .SetDictPolicies(dict_policies) |
| Joshua Pawlicki | e581259 | 2023-06-12 17:24:54 | [diff] [blame] | 77 | .SetOverinstallTimeout(base::Seconds(3)) |
| Xiaoling Bao | bea6946 | 2023-08-01 01:59:03 | [diff] [blame] | 78 | .SetIdleCheckPeriod(base::Seconds(4)) |
| Sorin Jianu | a4b3d38 | 2023-11-10 20:08:46 | [diff] [blame] | 79 | .SetMachineManaged(std::make_optional(true)) |
| Xiaoling Bao | 760b128a | 2024-10-02 23:17:15 | [diff] [blame] | 80 | .SetCecaConnectionTimeout(base::Seconds(7)); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 81 | EXPECT_TRUE(builder.Overwrite()); |
| 82 | |
| Joshua Pawlicki | 34aacc1 | 2021-08-24 21:22:21 | [diff] [blame] | 83 | scoped_refptr<ExternalConstantsOverrider> verifier = |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 84 | ExternalConstantsOverrider::FromDefaultJSONFile( |
| Joshua Pawlicki | 58a597ed | 2021-06-10 17:00:52 | [diff] [blame] | 85 | CreateDefaultExternalConstants()); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 86 | |
| 87 | EXPECT_FALSE(verifier->UseCUP()); |
| 88 | |
| 89 | std::vector<GURL> urls = verifier->UpdateURL(); |
| 90 | ASSERT_EQ(urls.size(), 1ul); |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame] | 91 | EXPECT_EQ(urls[0], GURL("https://localhost/1/www")); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 92 | |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame] | 93 | EXPECT_EQ(verifier->CrashUploadURL(), GURL("https://localhost/1/crash")); |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame] | 94 | EXPECT_EQ(verifier->AppLogoURL(), GURL("https://localhost/1/applogo/")); |
| Noah Rose Ledesma | d391ac33 | 2022-12-13 21:09:06 | [diff] [blame] | 95 | EXPECT_EQ(verifier->InitialDelay(), base::Seconds(123)); |
| 96 | EXPECT_EQ(verifier->ServerKeepAliveTime(), base::Seconds(2)); |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 97 | EXPECT_EQ(verifier->DictPolicies().size(), 2U); |
| Joshua Pawlicki | e581259 | 2023-06-12 17:24:54 | [diff] [blame] | 98 | EXPECT_EQ(verifier->OverinstallTimeout(), base::Seconds(3)); |
| 99 | EXPECT_EQ(verifier->IdleCheckPeriod(), base::Seconds(4)); |
| Xiaoling Bao | bea6946 | 2023-08-01 01:59:03 | [diff] [blame] | 100 | EXPECT_TRUE(verifier->IsMachineManaged().has_value()); |
| 101 | EXPECT_TRUE(verifier->IsMachineManaged().value()); |
| Xiaoling Bao | 760b128a | 2024-10-02 23:17:15 | [diff] [blame] | 102 | EXPECT_EQ(verifier->CecaConnectionTimeout(), base::Seconds(7)); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | TEST_F(ExternalConstantsBuilderTests, TestPartialOverrideWithMultipleURLs) { |
| 106 | ExternalConstantsBuilder builder; |
| 107 | EXPECT_TRUE(builder |
| 108 | .SetUpdateURL(std::vector<std::string>{ |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame] | 109 | "https://localhost/update", "https://localhost/update2"}) |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 110 | .Overwrite()); |
| 111 | |
| Joshua Pawlicki | 34aacc1 | 2021-08-24 21:22:21 | [diff] [blame] | 112 | scoped_refptr<ExternalConstantsOverrider> verifier = |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 113 | ExternalConstantsOverrider::FromDefaultJSONFile( |
| Joshua Pawlicki | 58a597ed | 2021-06-10 17:00:52 | [diff] [blame] | 114 | CreateDefaultExternalConstants()); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 115 | |
| 116 | EXPECT_TRUE(verifier->UseCUP()); |
| 117 | |
| 118 | std::vector<GURL> urls = verifier->UpdateURL(); |
| 119 | ASSERT_EQ(urls.size(), 2ul); |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame] | 120 | EXPECT_EQ(urls[0], GURL("https://localhost/update")); |
| 121 | EXPECT_EQ(urls[1], GURL("https://localhost/update2")); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 122 | |
| Xiaoling Bao | 616a535 | 2023-04-03 22:00:58 | [diff] [blame] | 123 | EXPECT_EQ(verifier->CrashUploadURL(), GURL(CRASH_UPLOAD_URL)); |
| S. Ganesh | 0f34f8b | 2024-03-13 21:08:44 | [diff] [blame] | 124 | EXPECT_EQ(verifier->AppLogoURL(), GURL(APP_LOGO_URL)); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 125 | EXPECT_EQ(verifier->InitialDelay(), kInitialDelay); |
| Noah Rose Ledesma | d391ac33 | 2022-12-13 21:09:06 | [diff] [blame] | 126 | EXPECT_EQ(verifier->ServerKeepAliveTime(), kServerKeepAliveTime); |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 127 | EXPECT_EQ(verifier->DictPolicies().size(), 0U); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | TEST_F(ExternalConstantsBuilderTests, TestClearedEverything) { |
| 131 | ExternalConstantsBuilder builder; |
| 132 | EXPECT_TRUE(builder |
| 133 | .SetUpdateURL(std::vector<std::string>{ |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame] | 134 | "https://localhost/1/localhost/update", "https://www"}) |
| 135 | .SetCrashUploadURL("https://localhost/1/crash") |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame] | 136 | .SetAppLogoURL("https://localhost/1/applogo/") |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 137 | .SetUseCUP(false) |
| Noah Rose Ledesma | d391ac33 | 2022-12-13 21:09:06 | [diff] [blame] | 138 | .SetInitialDelay(base::Seconds(123.4)) |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 139 | .ClearUpdateURL() |
| Xiaoling Bao | 616a535 | 2023-04-03 22:00:58 | [diff] [blame] | 140 | .ClearCrashUploadURL() |
| S. Ganesh | 0f34f8b | 2024-03-13 21:08:44 | [diff] [blame] | 141 | .ClearAppLogoURL() |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 142 | .ClearUseCUP() |
| 143 | .ClearInitialDelay() |
| Mila Green | 59389f1 | 2021-02-03 20:52:32 | [diff] [blame] | 144 | .ClearServerKeepAliveSeconds() |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 145 | .ClearDictPolicies() |
| Joshua Pawlicki | e581259 | 2023-06-12 17:24:54 | [diff] [blame] | 146 | .ClearOverinstallTimeout() |
| 147 | .ClearIdleCheckPeriod() |
| Xiaoling Bao | bea6946 | 2023-08-01 01:59:03 | [diff] [blame] | 148 | .ClearMachineManaged() |
| Xiaoling Bao | 760b128a | 2024-10-02 23:17:15 | [diff] [blame] | 149 | .ClearCecaConnectionTimeout() |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 150 | .Overwrite()); |
| 151 | |
| Joshua Pawlicki | 34aacc1 | 2021-08-24 21:22:21 | [diff] [blame] | 152 | scoped_refptr<ExternalConstantsOverrider> verifier = |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 153 | ExternalConstantsOverrider::FromDefaultJSONFile( |
| Joshua Pawlicki | 58a597ed | 2021-06-10 17:00:52 | [diff] [blame] | 154 | CreateDefaultExternalConstants()); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 155 | EXPECT_TRUE(verifier->UseCUP()); |
| 156 | |
| 157 | std::vector<GURL> urls = verifier->UpdateURL(); |
| 158 | ASSERT_EQ(urls.size(), 1ul); |
| 159 | EXPECT_EQ(urls[0], GURL(UPDATE_CHECK_URL)); |
| 160 | |
| Xiaoling Bao | 616a535 | 2023-04-03 22:00:58 | [diff] [blame] | 161 | EXPECT_EQ(verifier->CrashUploadURL(), GURL(CRASH_UPLOAD_URL)); |
| S. Ganesh | 0f34f8b | 2024-03-13 21:08:44 | [diff] [blame] | 162 | EXPECT_EQ(verifier->AppLogoURL(), GURL(APP_LOGO_URL)); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 163 | EXPECT_EQ(verifier->InitialDelay(), kInitialDelay); |
| Noah Rose Ledesma | d391ac33 | 2022-12-13 21:09:06 | [diff] [blame] | 164 | EXPECT_EQ(verifier->ServerKeepAliveTime(), kServerKeepAliveTime); |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 165 | EXPECT_EQ(verifier->DictPolicies().size(), 0U); |
| Xiaoling Bao | bea6946 | 2023-08-01 01:59:03 | [diff] [blame] | 166 | EXPECT_FALSE(verifier->IsMachineManaged().has_value()); |
| Xiaoling Bao | 760b128a | 2024-10-02 23:17:15 | [diff] [blame] | 167 | EXPECT_EQ(verifier->CecaConnectionTimeout(), kCecaConnectionTimeout); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | TEST_F(ExternalConstantsBuilderTests, TestOverSet) { |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 171 | base::Value::Dict dict_policies; |
| 172 | dict_policies.Set("a", 1); |
| S. Ganesh | 5b7c6a7 | 2022-05-21 01:20:56 | [diff] [blame] | 173 | |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 174 | EXPECT_TRUE( |
| 175 | ExternalConstantsBuilder() |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame] | 176 | .SetUpdateURL(std::vector<std::string>{"https://localhost/update"}) |
| 177 | .SetCrashUploadURL("https://localhost/crash") |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame] | 178 | .SetAppLogoURL("https://localhost/logo/") |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 179 | .SetUseCUP(true) |
| Noah Rose Ledesma | d391ac33 | 2022-12-13 21:09:06 | [diff] [blame] | 180 | .SetInitialDelay(base::Seconds(123.4)) |
| 181 | .SetServerKeepAliveTime(base::Seconds(2)) |
| Sorin Jianu | a4b3d38 | 2023-11-10 20:08:46 | [diff] [blame] | 182 | .SetMachineManaged(std::make_optional(true)) |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 183 | .SetDictPolicies(dict_policies) |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame] | 184 | .SetUpdateURL(std::vector<std::string>{"https://localhost/1/www"}) |
| 185 | .SetCrashUploadURL("https://localhost/1/crash") |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame] | 186 | .SetAppLogoURL("https://localhost/1/applogo/") |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 187 | .SetUseCUP(false) |
| Noah Rose Ledesma | d391ac33 | 2022-12-13 21:09:06 | [diff] [blame] | 188 | .SetInitialDelay(base::Seconds(937.6)) |
| 189 | .SetServerKeepAliveTime(base::Seconds(3)) |
| Sorin Jianu | a4b3d38 | 2023-11-10 20:08:46 | [diff] [blame] | 190 | .SetMachineManaged(std::make_optional(false)) |
| Xiaoling Bao | 760b128a | 2024-10-02 23:17:15 | [diff] [blame] | 191 | .SetCecaConnectionTimeout(base::Seconds(38)) |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 192 | .Overwrite()); |
| 193 | |
| 194 | // Only the second set of values should be observed. |
| Joshua Pawlicki | 34aacc1 | 2021-08-24 21:22:21 | [diff] [blame] | 195 | scoped_refptr<ExternalConstantsOverrider> verifier = |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 196 | ExternalConstantsOverrider::FromDefaultJSONFile( |
| Joshua Pawlicki | 58a597ed | 2021-06-10 17:00:52 | [diff] [blame] | 197 | CreateDefaultExternalConstants()); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 198 | EXPECT_FALSE(verifier->UseCUP()); |
| 199 | |
| 200 | std::vector<GURL> urls = verifier->UpdateURL(); |
| 201 | ASSERT_EQ(urls.size(), 1ul); |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame] | 202 | EXPECT_EQ(urls[0], GURL("https://localhost/1/www")); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 203 | |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame] | 204 | EXPECT_EQ(verifier->CrashUploadURL(), GURL("https://localhost/1/crash")); |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame] | 205 | EXPECT_EQ(verifier->AppLogoURL(), GURL("https://localhost/1/applogo/")); |
| Noah Rose Ledesma | d391ac33 | 2022-12-13 21:09:06 | [diff] [blame] | 206 | EXPECT_EQ(verifier->InitialDelay(), base::Seconds(937.6)); |
| 207 | EXPECT_EQ(verifier->ServerKeepAliveTime(), base::Seconds(3)); |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 208 | EXPECT_EQ(verifier->DictPolicies().size(), 1U); |
| Xiaoling Bao | bea6946 | 2023-08-01 01:59:03 | [diff] [blame] | 209 | EXPECT_TRUE(verifier->IsMachineManaged().has_value()); |
| 210 | EXPECT_FALSE(verifier->IsMachineManaged().value()); |
| Xiaoling Bao | 760b128a | 2024-10-02 23:17:15 | [diff] [blame] | 211 | EXPECT_EQ(verifier->CecaConnectionTimeout(), base::Seconds(38)); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | TEST_F(ExternalConstantsBuilderTests, TestReuseBuilder) { |
| 215 | ExternalConstantsBuilder builder; |
| S. Ganesh | 5b7c6a7 | 2022-05-21 01:20:56 | [diff] [blame] | 216 | |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 217 | base::Value::Dict dict_policies; |
| 218 | dict_policies.Set("a", 1); |
| 219 | dict_policies.Set("b", 2); |
| S. Ganesh | 5b7c6a7 | 2022-05-21 01:20:56 | [diff] [blame] | 220 | |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 221 | EXPECT_TRUE( |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame] | 222 | builder.SetUpdateURL(std::vector<std::string>{"https://localhost/update"}) |
| 223 | .SetCrashUploadURL("https://localhost/crash") |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame] | 224 | .SetAppLogoURL("https://localhost/logo/") |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 225 | .SetUseCUP(false) |
| Noah Rose Ledesma | d391ac33 | 2022-12-13 21:09:06 | [diff] [blame] | 226 | .SetInitialDelay(base::Seconds(123.4)) |
| 227 | .SetServerKeepAliveTime(base::Seconds(3)) |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame] | 228 | .SetUpdateURL(std::vector<std::string>{"https://localhost/1/www"}) |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 229 | .SetDictPolicies(dict_policies) |
| Sorin Jianu | a4b3d38 | 2023-11-10 20:08:46 | [diff] [blame] | 230 | .SetMachineManaged(std::make_optional(true)) |
| Xiaoling Bao | 760b128a | 2024-10-02 23:17:15 | [diff] [blame] | 231 | .SetCecaConnectionTimeout(base::Seconds(5)) |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 232 | .Overwrite()); |
| 233 | |
| Joshua Pawlicki | 34aacc1 | 2021-08-24 21:22:21 | [diff] [blame] | 234 | scoped_refptr<ExternalConstantsOverrider> verifier = |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 235 | ExternalConstantsOverrider::FromDefaultJSONFile( |
| Joshua Pawlicki | 58a597ed | 2021-06-10 17:00:52 | [diff] [blame] | 236 | CreateDefaultExternalConstants()); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 237 | |
| 238 | EXPECT_FALSE(verifier->UseCUP()); |
| 239 | |
| 240 | std::vector<GURL> urls = verifier->UpdateURL(); |
| 241 | ASSERT_EQ(urls.size(), 1ul); |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame] | 242 | EXPECT_EQ(urls[0], GURL("https://localhost/1/www")); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 243 | |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame] | 244 | EXPECT_EQ(verifier->CrashUploadURL(), GURL("https://localhost/crash")); |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame] | 245 | EXPECT_EQ(verifier->AppLogoURL(), GURL("https://localhost/logo/")); |
| Noah Rose Ledesma | d391ac33 | 2022-12-13 21:09:06 | [diff] [blame] | 246 | EXPECT_EQ(verifier->InitialDelay(), base::Seconds(123.4)); |
| 247 | EXPECT_EQ(verifier->ServerKeepAliveTime(), base::Seconds(3)); |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 248 | EXPECT_EQ(verifier->DictPolicies().size(), 2U); |
| Xiaoling Bao | bea6946 | 2023-08-01 01:59:03 | [diff] [blame] | 249 | EXPECT_TRUE(verifier->IsMachineManaged().has_value()); |
| 250 | EXPECT_TRUE(verifier->IsMachineManaged().value()); |
| Xiaoling Bao | 760b128a | 2024-10-02 23:17:15 | [diff] [blame] | 251 | EXPECT_EQ(verifier->CecaConnectionTimeout(), base::Seconds(5)); |
| S. Ganesh | 5b7c6a7 | 2022-05-21 01:20:56 | [diff] [blame] | 252 | |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 253 | base::Value::Dict dict_policies2; |
| 254 | dict_policies2.Set("b", 2); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 255 | |
| 256 | // But now we can use the builder again: |
| Noah Rose Ledesma | d391ac33 | 2022-12-13 21:09:06 | [diff] [blame] | 257 | EXPECT_TRUE(builder.SetInitialDelay(base::Seconds(92.3)) |
| 258 | .SetServerKeepAliveTime(base::Seconds(4)) |
| Mila Green | 59389f1 | 2021-02-03 20:52:32 | [diff] [blame] | 259 | .ClearUpdateURL() |
| Xiaoling Bao | 616a535 | 2023-04-03 22:00:58 | [diff] [blame] | 260 | .ClearCrashUploadURL() |
| S. Ganesh | 0f34f8b | 2024-03-13 21:08:44 | [diff] [blame] | 261 | .ClearAppLogoURL() |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 262 | .SetDictPolicies(dict_policies2) |
| Xiaoling Bao | bea6946 | 2023-08-01 01:59:03 | [diff] [blame] | 263 | .ClearMachineManaged() |
| Xiaoling Bao | 760b128a | 2024-10-02 23:17:15 | [diff] [blame] | 264 | .ClearCecaConnectionTimeout() |
| Mila Green | 59389f1 | 2021-02-03 20:52:32 | [diff] [blame] | 265 | .Overwrite()); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 266 | |
| 267 | // We need a new overrider to verify because it only loads once. |
| Joshua Pawlicki | 34aacc1 | 2021-08-24 21:22:21 | [diff] [blame] | 268 | scoped_refptr<ExternalConstantsOverrider> verifier2 = |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 269 | ExternalConstantsOverrider::FromDefaultJSONFile( |
| Joshua Pawlicki | 58a597ed | 2021-06-10 17:00:52 | [diff] [blame] | 270 | CreateDefaultExternalConstants()); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 271 | |
| 272 | EXPECT_FALSE(verifier2->UseCUP()); // Not updated, value should be retained. |
| 273 | |
| 274 | std::vector<GURL> urls2 = verifier2->UpdateURL(); |
| 275 | ASSERT_EQ(urls2.size(), 1ul); |
| 276 | EXPECT_EQ(urls2[0], GURL(UPDATE_CHECK_URL)); // Cleared; should be default. |
| 277 | |
| Xiaoling Bao | 616a535 | 2023-04-03 22:00:58 | [diff] [blame] | 278 | EXPECT_EQ(verifier2->CrashUploadURL(), GURL(CRASH_UPLOAD_URL)); |
| S. Ganesh | 0f34f8b | 2024-03-13 21:08:44 | [diff] [blame] | 279 | EXPECT_EQ(verifier2->AppLogoURL(), GURL(APP_LOGO_URL)); |
| Mila Green | 1cb2696 | 2021-01-21 01:00:00 | [diff] [blame] | 280 | EXPECT_EQ(verifier2->InitialDelay(), |
| Noah Rose Ledesma | d391ac33 | 2022-12-13 21:09:06 | [diff] [blame] | 281 | base::Seconds(92.3)); // Updated; update should be seen. |
| 282 | EXPECT_EQ(verifier2->ServerKeepAliveTime(), base::Seconds(4)); |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 283 | EXPECT_EQ(verifier2->DictPolicies().size(), 1U); |
| Xiaoling Bao | bea6946 | 2023-08-01 01:59:03 | [diff] [blame] | 284 | EXPECT_FALSE(verifier2->IsMachineManaged().has_value()); |
| Xiaoling Bao | 760b128a | 2024-10-02 23:17:15 | [diff] [blame] | 285 | EXPECT_EQ(verifier2->CecaConnectionTimeout(), kCecaConnectionTimeout); |
| S. Ganesh | 5b7c6a7 | 2022-05-21 01:20:56 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | TEST_F(ExternalConstantsBuilderTests, TestModify) { |
| 289 | ExternalConstantsBuilder builder; |
| 290 | |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 291 | base::Value::Dict dict_policies; |
| 292 | dict_policies.Set("a", 1); |
| 293 | dict_policies.Set("b", 2); |
| S. Ganesh | 5b7c6a7 | 2022-05-21 01:20:56 | [diff] [blame] | 294 | |
| 295 | EXPECT_TRUE( |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame] | 296 | builder.SetUpdateURL(std::vector<std::string>{"https://localhost/update"}) |
| 297 | .SetCrashUploadURL("https://localhost/crash") |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame] | 298 | .SetAppLogoURL("https://localhost/logo/") |
| S. Ganesh | 5b7c6a7 | 2022-05-21 01:20:56 | [diff] [blame] | 299 | .SetUseCUP(false) |
| Noah Rose Ledesma | d391ac33 | 2022-12-13 21:09:06 | [diff] [blame] | 300 | .SetInitialDelay(base::Seconds(123.4)) |
| 301 | .SetServerKeepAliveTime(base::Seconds(3)) |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame] | 302 | .SetUpdateURL(std::vector<std::string>{"https://localhost/1/www"}) |
| 303 | .SetCrashUploadURL("https://localhost/1/crash") |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame] | 304 | .SetAppLogoURL("https://localhost/1/applogo/") |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 305 | .SetDictPolicies(dict_policies) |
| Sorin Jianu | a4b3d38 | 2023-11-10 20:08:46 | [diff] [blame] | 306 | .SetMachineManaged(std::make_optional(false)) |
| Xiaoling Bao | 760b128a | 2024-10-02 23:17:15 | [diff] [blame] | 307 | .SetCecaConnectionTimeout(base::Seconds(55)) |
| S. Ganesh | 5b7c6a7 | 2022-05-21 01:20:56 | [diff] [blame] | 308 | .Overwrite()); |
| 309 | |
| 310 | scoped_refptr<ExternalConstantsOverrider> verifier = |
| 311 | ExternalConstantsOverrider::FromDefaultJSONFile( |
| 312 | CreateDefaultExternalConstants()); |
| 313 | |
| 314 | EXPECT_FALSE(verifier->UseCUP()); |
| 315 | |
| 316 | std::vector<GURL> urls = verifier->UpdateURL(); |
| 317 | ASSERT_EQ(urls.size(), 1ul); |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame] | 318 | EXPECT_EQ(urls[0], GURL("https://localhost/1/www")); |
| S. Ganesh | 5b7c6a7 | 2022-05-21 01:20:56 | [diff] [blame] | 319 | |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame] | 320 | EXPECT_EQ(verifier->CrashUploadURL(), GURL("https://localhost/1/crash")); |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame] | 321 | EXPECT_EQ(verifier->AppLogoURL(), GURL("https://localhost/1/applogo/")); |
| Noah Rose Ledesma | d391ac33 | 2022-12-13 21:09:06 | [diff] [blame] | 322 | EXPECT_EQ(verifier->InitialDelay(), base::Seconds(123.4)); |
| 323 | EXPECT_EQ(verifier->ServerKeepAliveTime(), base::Seconds(3)); |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 324 | EXPECT_EQ(verifier->DictPolicies().size(), 2U); |
| Xiaoling Bao | bea6946 | 2023-08-01 01:59:03 | [diff] [blame] | 325 | EXPECT_TRUE(verifier->IsMachineManaged().has_value()); |
| 326 | EXPECT_FALSE(verifier->IsMachineManaged().value()); |
| Xiaoling Bao | 760b128a | 2024-10-02 23:17:15 | [diff] [blame] | 327 | EXPECT_EQ(verifier->CecaConnectionTimeout(), base::Seconds(55)); |
| S. Ganesh | 5b7c6a7 | 2022-05-21 01:20:56 | [diff] [blame] | 328 | |
| 329 | // Now we use a new builder to modify just the group policies. |
| 330 | ExternalConstantsBuilder builder2; |
| 331 | |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 332 | base::Value::Dict dict_policies2; |
| 333 | dict_policies2.Set("b", 2); |
| S. Ganesh | 5b7c6a7 | 2022-05-21 01:20:56 | [diff] [blame] | 334 | |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 335 | EXPECT_TRUE(builder2.SetDictPolicies(dict_policies2).Modify()); |
| S. Ganesh | 5b7c6a7 | 2022-05-21 01:20:56 | [diff] [blame] | 336 | |
| 337 | // We need a new overrider to verify because it only loads once. |
| 338 | scoped_refptr<ExternalConstantsOverrider> verifier2 = |
| 339 | ExternalConstantsOverrider::FromDefaultJSONFile( |
| 340 | CreateDefaultExternalConstants()); |
| 341 | |
| 342 | // Only the group policies are different. |
| S. Ganesh | f0d3ab0 | 2025-01-18 04:02:42 | [diff] [blame] | 343 | EXPECT_EQ(verifier2->DictPolicies().size(), 1U); |
| S. Ganesh | 5b7c6a7 | 2022-05-21 01:20:56 | [diff] [blame] | 344 | |
| 345 | // All the values below are unchanged. |
| 346 | EXPECT_FALSE(verifier2->UseCUP()); |
| 347 | urls = verifier2->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")); |
| 350 | EXPECT_EQ(verifier2->CrashUploadURL(), GURL("https://localhost/1/crash")); |
| Joshua Pawlicki | 9154e5f06 | 2025-01-31 19:53:20 | [diff] [blame] | 351 | EXPECT_EQ(verifier2->AppLogoURL(), GURL("https://localhost/1/applogo/")); |
| Noah Rose Ledesma | d391ac33 | 2022-12-13 21:09:06 | [diff] [blame] | 352 | EXPECT_EQ(verifier2->InitialDelay(), base::Seconds(123.4)); |
| 353 | EXPECT_EQ(verifier2->ServerKeepAliveTime(), base::Seconds(3)); |
| Xiaoling Bao | bea6946 | 2023-08-01 01:59:03 | [diff] [blame] | 354 | EXPECT_TRUE(verifier2->IsMachineManaged().has_value()); |
| 355 | EXPECT_FALSE(verifier2->IsMachineManaged().value()); |
| Xiaoling Bao | 760b128a | 2024-10-02 23:17:15 | [diff] [blame] | 356 | EXPECT_EQ(verifier2->CecaConnectionTimeout(), base::Seconds(55)); |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 357 | } |
| Adam Norberg | c7ab1c5 | 2021-01-19 21:05:21 | [diff] [blame] | 358 | |
| 359 | } // namespace updater |