| 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 #include <string> |
| 6 |
| 5 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 6 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 7 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 8 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 9 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/extensions/component_loader.h" | 14 #include "chrome/browser/extensions/component_loader.h" |
| 13 #include "chrome/browser/first_run/first_run.h" | 15 #include "chrome/browser/first_run/first_run.h" |
| 14 #include "chrome/browser/importer/importer_list.h" | 16 #include "chrome/browser/importer/importer_list.h" |
| 17 #include "chrome/browser/prefs/chrome_pref_service_factory.h" |
| 15 #include "chrome/browser/profiles/profile_manager.h" | 18 #include "chrome/browser/profiles/profile_manager.h" |
| 16 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 18 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 19 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 20 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
| 21 #include "chrome/test/base/in_process_browser_test.h" | 24 #include "chrome/test/base/in_process_browser_test.h" |
| 22 #include "chrome/test/base/ui_test_utils.h" | 25 #include "chrome/test/base/ui_test_utils.h" |
| 23 #include "components/user_prefs/user_prefs.h" | 26 #include "components/user_prefs/user_prefs.h" |
| 24 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 // A test fixture that will run in a first run scenario with master_preferences | 243 // A test fixture that will run in a first run scenario with master_preferences |
| 241 // set to kWithTrackedPrefs. Parameterizable on the SettingsEnforcement | 244 // set to kWithTrackedPrefs. Parameterizable on the SettingsEnforcement |
| 242 // experiment to be forced. | 245 // experiment to be forced. |
| 243 class FirstRunMasterPrefsWithTrackedPreferences | 246 class FirstRunMasterPrefsWithTrackedPreferences |
| 244 : public FirstRunMasterPrefsBrowserTestT<kWithTrackedPrefs>, | 247 : public FirstRunMasterPrefsBrowserTestT<kWithTrackedPrefs>, |
| 245 public testing::WithParamInterface<std::string> { | 248 public testing::WithParamInterface<std::string> { |
| 246 public: | 249 public: |
| 247 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 250 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 248 FirstRunMasterPrefsBrowserTestT::SetUpCommandLine(command_line); | 251 FirstRunMasterPrefsBrowserTestT::SetUpCommandLine(command_line); |
| 249 command_line->AppendSwitchASCII( | 252 command_line->AppendSwitchASCII( |
| 250 switches::kForceFieldTrials, "SettingsEnforcement/" + GetParam() + "/"); | 253 switches::kForceFieldTrials, |
| 254 std::string(chrome_prefs::internals::kSettingsEnforcementTrialName) + |
| 255 "/" + GetParam() + "/"); |
| 251 } | 256 } |
| 252 }; | 257 }; |
| 253 | 258 |
| 254 // http://crbug.com/314221 | 259 // http://crbug.com/314221 |
| 255 #if defined(GOOGLE_CHROME_BUILD) && defined(OS_MACOSX) | 260 #if defined(GOOGLE_CHROME_BUILD) && defined(OS_MACOSX) |
| 256 #define MAYBE_TrackedPreferencesSurviveFirstRun \ | 261 #define MAYBE_TrackedPreferencesSurviveFirstRun \ |
| 257 DISABLED_TrackedPreferencesSurviveFirstRun | 262 DISABLED_TrackedPreferencesSurviveFirstRun |
| 258 #else | 263 #else |
| 259 #define MAYBE_TrackedPreferencesSurviveFirstRun \ | 264 #define MAYBE_TrackedPreferencesSurviveFirstRun \ |
| 260 TrackedPreferencesSurviveFirstRun | 265 TrackedPreferencesSurviveFirstRun |
| 261 #endif | 266 #endif |
| 262 IN_PROC_BROWSER_TEST_P(FirstRunMasterPrefsWithTrackedPreferences, | 267 IN_PROC_BROWSER_TEST_P(FirstRunMasterPrefsWithTrackedPreferences, |
| 263 MAYBE_TrackedPreferencesSurviveFirstRun) { | 268 MAYBE_TrackedPreferencesSurviveFirstRun) { |
| 264 const PrefService* user_prefs = browser()->profile()->GetPrefs(); | 269 const PrefService* user_prefs = browser()->profile()->GetPrefs(); |
| 265 EXPECT_EQ("example.com", user_prefs->GetString(prefs::kHomePage)); | 270 EXPECT_EQ("example.com", user_prefs->GetString(prefs::kHomePage)); |
| 266 EXPECT_FALSE(user_prefs->GetBoolean(prefs::kHomePageIsNewTabPage)); | 271 EXPECT_FALSE(user_prefs->GetBoolean(prefs::kHomePageIsNewTabPage)); |
| 267 | 272 |
| 268 // The test for kHomePageIsNewTabPage above relies on the fact that true is | 273 // The test for kHomePageIsNewTabPage above relies on the fact that true is |
| 269 // the default (hence false must be the user's pref); ensure this fact remains | 274 // the default (hence false must be the user's pref); ensure this fact remains |
| 270 // true. | 275 // true. |
| 271 const base::Value* default_homepage_is_ntp_value = | 276 const base::Value* default_homepage_is_ntp_value = |
| 272 user_prefs->GetDefaultPrefValue(prefs::kHomePageIsNewTabPage); | 277 user_prefs->GetDefaultPrefValue(prefs::kHomePageIsNewTabPage); |
| 273 ASSERT_TRUE(default_homepage_is_ntp_value != NULL); | 278 ASSERT_TRUE(default_homepage_is_ntp_value != NULL); |
| 274 bool default_homepage_is_ntp = false; | 279 bool default_homepage_is_ntp = false; |
| 275 EXPECT_TRUE( | 280 EXPECT_TRUE( |
| 276 default_homepage_is_ntp_value->GetAsBoolean(&default_homepage_is_ntp)); | 281 default_homepage_is_ntp_value->GetAsBoolean(&default_homepage_is_ntp)); |
| 277 EXPECT_TRUE(default_homepage_is_ntp); | 282 EXPECT_TRUE(default_homepage_is_ntp); |
| 278 } | 283 } |
| 279 | 284 |
| 280 INSTANTIATE_TEST_CASE_P(FirstRunMasterPrefsWithTrackedPreferencesInstance, | 285 INSTANTIATE_TEST_CASE_P( |
| 281 FirstRunMasterPrefsWithTrackedPreferences, | 286 FirstRunMasterPrefsWithTrackedPreferencesInstance, |
| 282 testing::Values("no_enforcement", | 287 FirstRunMasterPrefsWithTrackedPreferences, |
| 283 "enforce", | 288 testing::Values( |
| 284 "enforce_no_seeding", | 289 chrome_prefs::internals::kSettingsEnforcementGroupNoEnforcement, |
| 285 "enforce_no_seeding_no_migration")); | 290 chrome_prefs::internals::kSettingsEnforcementGroupEnforceOnload, |
| 291 chrome_prefs::internals::kSettingsEnforcementGroupEnforceAlways)); |
| 292 |
| 286 | 293 |
| 287 #endif // !defined(OS_CHROMEOS) | 294 #endif // !defined(OS_CHROMEOS) |
| OLD | NEW |