| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // Unit tests for master preferences related methods. | 5 // Unit tests for master preferences related methods. |
| 6 | 6 |
| 7 #include "chrome/installer/util/master_preferences.h" | 7 #include "chrome/installer/util/master_preferences.h" |
| 8 | 8 |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 | 10 |
| 11 #include <memory> | 11 #include <memory> |
| 12 | 12 |
| 13 #include "base/environment.h" | 13 #include "base/environment.h" |
| 14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "chrome/common/chrome_paths.h" | 18 #include "chrome/common/chrome_paths.h" |
| 19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 20 #include "chrome/installer/util/master_preferences_constants.h" | 20 #include "chrome/installer/util/master_preferences_constants.h" |
| 21 #include "chrome/installer/util/util_constants.h" | 21 #include "chrome/installer/util/util_constants.h" |
| 22 #include "rlz/features/features.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 // A helper class to set the "GoogleUpdateIsMachine" environment variable. | 27 // A helper class to set the "GoogleUpdateIsMachine" environment variable. |
| 27 class ScopedGoogleUpdateIsMachine { | 28 class ScopedGoogleUpdateIsMachine { |
| 28 public: | 29 public: |
| 29 explicit ScopedGoogleUpdateIsMachine(const char* value) | 30 explicit ScopedGoogleUpdateIsMachine(const char* value) |
| 30 : env_(base::Environment::Create()) { | 31 : env_(base::Environment::Create()) { |
| 31 env_->SetVar("GoogleUpdateIsMachine", value); | 32 env_->SetVar("GoogleUpdateIsMachine", value); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 " \"welcome_page_on_os_upgrade_enabled\": true,\n" | 83 " \"welcome_page_on_os_upgrade_enabled\": true,\n" |
| 83 " \"do_not_create_any_shortcuts\": true,\n" | 84 " \"do_not_create_any_shortcuts\": true,\n" |
| 84 " \"do_not_create_desktop_shortcut\": true,\n" | 85 " \"do_not_create_desktop_shortcut\": true,\n" |
| 85 " \"do_not_create_quick_launch_shortcut\": true,\n" | 86 " \"do_not_create_quick_launch_shortcut\": true,\n" |
| 86 " \"do_not_create_taskbar_shortcut\": true,\n" | 87 " \"do_not_create_taskbar_shortcut\": true,\n" |
| 87 " \"do_not_launch_chrome\": true,\n" | 88 " \"do_not_launch_chrome\": true,\n" |
| 88 " \"make_chrome_default\": true,\n" | 89 " \"make_chrome_default\": true,\n" |
| 89 " \"make_chrome_default_for_user\": true,\n" | 90 " \"make_chrome_default_for_user\": true,\n" |
| 90 " \"system_level\": true,\n" | 91 " \"system_level\": true,\n" |
| 91 " \"verbose_logging\": true,\n" | 92 " \"verbose_logging\": true,\n" |
| 92 " \"require_eula\": true,\n" | 93 " \"require_eula\": true\n" |
| 93 " \"ping_delay\": 40\n" | |
| 94 " },\n" | 94 " },\n" |
| 95 " \"blah\": {\n" | 95 " \"blah\": {\n" |
| 96 " \"import_history\": false\n" | 96 " \"import_history\": false\n" |
| 97 " }\n" | 97 " }\n" |
| 98 "} \n"; | 98 "} \n"; |
| 99 | 99 |
| 100 EXPECT_TRUE(base::WriteFile(prefs_file(), text, | 100 EXPECT_TRUE(base::WriteFile(prefs_file(), text, |
| 101 static_cast<int>(strlen(text)))); | 101 static_cast<int>(strlen(text)))); |
| 102 installer::MasterPreferences prefs(prefs_file()); | 102 installer::MasterPreferences prefs(prefs_file()); |
| 103 EXPECT_TRUE(prefs.read_from_file()); | 103 EXPECT_TRUE(prefs.read_from_file()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 124 bool value = false; | 124 bool value = false; |
| 125 EXPECT_TRUE(prefs.GetBool(expected_true[i], &value)); | 125 EXPECT_TRUE(prefs.GetBool(expected_true[i], &value)); |
| 126 EXPECT_TRUE(value) << expected_true[i]; | 126 EXPECT_TRUE(value) << expected_true[i]; |
| 127 } | 127 } |
| 128 | 128 |
| 129 std::string str_value; | 129 std::string str_value; |
| 130 EXPECT_TRUE(prefs.GetString( | 130 EXPECT_TRUE(prefs.GetString( |
| 131 installer::master_preferences::kDistroImportBookmarksFromFilePref, | 131 installer::master_preferences::kDistroImportBookmarksFromFilePref, |
| 132 &str_value)); | 132 &str_value)); |
| 133 EXPECT_STREQ("c:\\foo", str_value.c_str()); | 133 EXPECT_STREQ("c:\\foo", str_value.c_str()); |
| 134 | |
| 135 int ping_delay = 90; | |
| 136 EXPECT_TRUE(prefs.GetInt(installer::master_preferences::kDistroPingDelay, | |
| 137 &ping_delay)); | |
| 138 EXPECT_EQ(ping_delay, 40); | |
| 139 } | 134 } |
| 140 | 135 |
| 141 TEST_F(MasterPreferencesTest, ParseMissingDistroParams) { | 136 TEST_F(MasterPreferencesTest, ParseMissingDistroParams) { |
| 142 const char text[] = | 137 const char text[] = |
| 143 "{ \n" | 138 "{ \n" |
| 144 " \"distribution\": { \n" | 139 " \"distribution\": { \n" |
| 145 " \"import_search_engine\": true,\n" | 140 " \"import_search_engine\": true,\n" |
| 146 " \"import_bookmarks\": false,\n" | 141 " \"import_bookmarks\": false,\n" |
| 147 " \"import_bookmarks_from_file\": \"\",\n" | 142 " \"import_bookmarks_from_file\": \"\",\n" |
| 148 " \"do_not_create_desktop_shortcut\": true,\n" | 143 " \"do_not_create_desktop_shortcut\": true,\n" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 179 }; | 174 }; |
| 180 | 175 |
| 181 for (size_t i = 0; i < arraysize(missing_bools); ++i) { | 176 for (size_t i = 0; i < arraysize(missing_bools); ++i) { |
| 182 EXPECT_FALSE(prefs.GetBool(missing_bools[i], &value)) << missing_bools[i]; | 177 EXPECT_FALSE(prefs.GetBool(missing_bools[i], &value)) << missing_bools[i]; |
| 183 } | 178 } |
| 184 | 179 |
| 185 std::string str_value; | 180 std::string str_value; |
| 186 EXPECT_FALSE(prefs.GetString( | 181 EXPECT_FALSE(prefs.GetString( |
| 187 installer::master_preferences::kDistroImportBookmarksFromFilePref, | 182 installer::master_preferences::kDistroImportBookmarksFromFilePref, |
| 188 &str_value)); | 183 &str_value)); |
| 189 | |
| 190 int ping_delay = 90; | |
| 191 EXPECT_FALSE(prefs.GetInt( | |
| 192 installer::master_preferences::kDistroPingDelay, &ping_delay)); | |
| 193 EXPECT_EQ(ping_delay, 90); | |
| 194 } | 184 } |
| 195 | 185 |
| 196 TEST_F(MasterPreferencesTest, FirstRunTabs) { | 186 TEST_F(MasterPreferencesTest, FirstRunTabs) { |
| 197 const char text[] = | 187 const char text[] = |
| 198 "{ \n" | 188 "{ \n" |
| 199 " \"distribution\": { \n" | 189 " \"distribution\": { \n" |
| 200 " \"something here\": true\n" | 190 " \"something here\": true\n" |
| 201 " },\n" | 191 " },\n" |
| 202 " \"first_run_tabs\": [\n" | 192 " \"first_run_tabs\": [\n" |
| 203 " \"http://google.com/f1\",\n" | 193 " \"http://google.com/f1\",\n" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 TEST_F(MasterPreferencesTest, TestDefaultInstallConfig) { | 306 TEST_F(MasterPreferencesTest, TestDefaultInstallConfig) { |
| 317 std::wstringstream chrome_cmd; | 307 std::wstringstream chrome_cmd; |
| 318 chrome_cmd << "setup.exe"; | 308 chrome_cmd << "setup.exe"; |
| 319 | 309 |
| 320 base::CommandLine chrome_install( | 310 base::CommandLine chrome_install( |
| 321 base::CommandLine::FromString(chrome_cmd.str())); | 311 base::CommandLine::FromString(chrome_cmd.str())); |
| 322 | 312 |
| 323 installer::MasterPreferences pref_chrome(chrome_install); | 313 installer::MasterPreferences pref_chrome(chrome_install); |
| 324 } | 314 } |
| 325 | 315 |
| 326 TEST_F(MasterPreferencesTest, EnforceLegacyCreateAllShortcutsFalse) { | 316 TEST_F(MasterPreferencesTest, EnforceLegacyPreferences) { |
| 327 static const char kCreateAllShortcutsFalsePrefs[] = | 317 static const char kLegacyPrefs[] = |
| 328 "{" | 318 "{" |
| 329 " \"distribution\": {" | 319 " \"distribution\": {" |
| 330 " \"create_all_shortcuts\": false" | 320 " \"create_all_shortcuts\": false,\n" |
| 321 " \"ping_delay\": 40\n" |
| 331 " }" | 322 " }" |
| 332 "}"; | 323 "}"; |
| 333 | 324 |
| 334 installer::MasterPreferences prefs(kCreateAllShortcutsFalsePrefs); | 325 installer::MasterPreferences prefs(kLegacyPrefs); |
| 335 | 326 |
| 336 bool do_not_create_desktop_shortcut = false; | 327 bool do_not_create_desktop_shortcut = false; |
| 337 bool do_not_create_quick_launch_shortcut = false; | 328 bool do_not_create_quick_launch_shortcut = false; |
| 338 bool do_not_create_taskbar_shortcut = false; | 329 bool do_not_create_taskbar_shortcut = false; |
| 339 prefs.GetBool( | 330 prefs.GetBool(installer::master_preferences::kDoNotCreateDesktopShortcut, |
| 340 installer::master_preferences::kDoNotCreateDesktopShortcut, | 331 &do_not_create_desktop_shortcut); |
| 341 &do_not_create_desktop_shortcut); | 332 prefs.GetBool(installer::master_preferences::kDoNotCreateQuickLaunchShortcut, |
| 342 prefs.GetBool( | 333 &do_not_create_quick_launch_shortcut); |
| 343 installer::master_preferences::kDoNotCreateQuickLaunchShortcut, | 334 prefs.GetBool(installer::master_preferences::kDoNotCreateTaskbarShortcut, |
| 344 &do_not_create_quick_launch_shortcut); | 335 &do_not_create_taskbar_shortcut); |
| 345 prefs.GetBool( | 336 // create_all_shortcuts is a legacy preference that should only enforce |
| 346 installer::master_preferences::kDoNotCreateTaskbarShortcut, | 337 // do_not_create_desktop_shortcut and do_not_create_quick_launch_shortcut |
| 347 &do_not_create_taskbar_shortcut); | 338 // when set to false. |
| 348 // create_all_shortcuts is a legacy preference that should only enforce | 339 EXPECT_TRUE(do_not_create_desktop_shortcut); |
| 349 // do_not_create_desktop_shortcut and do_not_create_quick_launch_shortcut | 340 EXPECT_TRUE(do_not_create_quick_launch_shortcut); |
| 350 // when set to false. | 341 EXPECT_FALSE(do_not_create_taskbar_shortcut); |
| 351 EXPECT_TRUE(do_not_create_desktop_shortcut); | 342 |
| 352 EXPECT_TRUE(do_not_create_quick_launch_shortcut); | 343 #if BUILDFLAG(ENABLE_RLZ) |
| 353 EXPECT_FALSE(do_not_create_taskbar_shortcut); | 344 int rlz_ping_delay = 0; |
| 345 EXPECT_TRUE(prefs.master_dictionary().GetInteger(prefs::kRlzPingDelaySeconds, |
| 346 &rlz_ping_delay)); |
| 347 EXPECT_EQ(40, rlz_ping_delay); |
| 348 #endif // BUILDFLAG(ENABLE_RLZ) |
| 354 } | 349 } |
| 355 | 350 |
| 356 TEST_F(MasterPreferencesTest, DontEnforceLegacyCreateAllShortcutsTrue) { | 351 TEST_F(MasterPreferencesTest, DontEnforceLegacyCreateAllShortcutsTrue) { |
| 357 static const char kCreateAllShortcutsFalsePrefs[] = | 352 static const char kCreateAllShortcutsFalsePrefs[] = |
| 358 "{" | 353 "{" |
| 359 " \"distribution\": {" | 354 " \"distribution\": {" |
| 360 " \"create_all_shortcuts\": true" | 355 " \"create_all_shortcuts\": true" |
| 361 " }" | 356 " }" |
| 362 "}"; | 357 "}"; |
| 363 | 358 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 } | 429 } |
| 435 { | 430 { |
| 436 ScopedGoogleUpdateIsMachine env_setter("2"); | 431 ScopedGoogleUpdateIsMachine env_setter("2"); |
| 437 installer::MasterPreferences prefs( | 432 installer::MasterPreferences prefs( |
| 438 base::CommandLine(base::FilePath(FILE_PATH_LITERAL("setup.exe")))); | 433 base::CommandLine(base::FilePath(FILE_PATH_LITERAL("setup.exe")))); |
| 439 bool value = false; | 434 bool value = false; |
| 440 prefs.GetBool(installer::master_preferences::kSystemLevel, &value); | 435 prefs.GetBool(installer::master_preferences::kSystemLevel, &value); |
| 441 EXPECT_FALSE(value); | 436 EXPECT_FALSE(value); |
| 442 } | 437 } |
| 443 } | 438 } |
| OLD | NEW |