| 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> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 | 76 |
| 77 // A generic test class to be subclassed by test classes testing specific | 77 // A generic test class to be subclassed by test classes testing specific |
| 78 // master_preferences. All subclasses must call SetMasterPreferencesForTest() | 78 // master_preferences. All subclasses must call SetMasterPreferencesForTest() |
| 79 // from their SetUp() method before deferring the remainder of Setup() to this | 79 // from their SetUp() method before deferring the remainder of Setup() to this |
| 80 // class. | 80 // class. |
| 81 class FirstRunMasterPrefsBrowserTestBase : public InProcessBrowserTest { | 81 class FirstRunMasterPrefsBrowserTestBase : public InProcessBrowserTest { |
| 82 public: | 82 public: |
| 83 FirstRunMasterPrefsBrowserTestBase() {} | 83 FirstRunMasterPrefsBrowserTestBase() {} |
| 84 | 84 |
| 85 protected: | 85 protected: |
| 86 virtual void SetUp() OVERRIDE { | 86 virtual void SetUp() override { |
| 87 // All users of this test class need to call SetMasterPreferencesForTest() | 87 // All users of this test class need to call SetMasterPreferencesForTest() |
| 88 // before this class' SetUp() is invoked. | 88 // before this class' SetUp() is invoked. |
| 89 ASSERT_TRUE(text_.get()); | 89 ASSERT_TRUE(text_.get()); |
| 90 | 90 |
| 91 ASSERT_TRUE(base::CreateTemporaryFile(&prefs_file_)); | 91 ASSERT_TRUE(base::CreateTemporaryFile(&prefs_file_)); |
| 92 EXPECT_TRUE(base::WriteFile(prefs_file_, text_->c_str(), text_->size())); | 92 EXPECT_TRUE(base::WriteFile(prefs_file_, text_->c_str(), text_->size())); |
| 93 first_run::SetMasterPrefsPathForTesting(prefs_file_); | 93 first_run::SetMasterPrefsPathForTesting(prefs_file_); |
| 94 | 94 |
| 95 // This invokes BrowserMain, and does the import, so must be done last. | 95 // This invokes BrowserMain, and does the import, so must be done last. |
| 96 InProcessBrowserTest::SetUp(); | 96 InProcessBrowserTest::SetUp(); |
| 97 } | 97 } |
| 98 | 98 |
| 99 virtual void TearDown() OVERRIDE { | 99 virtual void TearDown() override { |
| 100 EXPECT_TRUE(base::DeleteFile(prefs_file_, false)); | 100 EXPECT_TRUE(base::DeleteFile(prefs_file_, false)); |
| 101 InProcessBrowserTest::TearDown(); | 101 InProcessBrowserTest::TearDown(); |
| 102 } | 102 } |
| 103 | 103 |
| 104 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 104 virtual void SetUpCommandLine(CommandLine* command_line) override { |
| 105 InProcessBrowserTest::SetUpCommandLine(command_line); | 105 InProcessBrowserTest::SetUpCommandLine(command_line); |
| 106 command_line->AppendSwitch(switches::kForceFirstRun); | 106 command_line->AppendSwitch(switches::kForceFirstRun); |
| 107 EXPECT_EQ(first_run::AUTO_IMPORT_NONE, first_run::auto_import_state()); | 107 EXPECT_EQ(first_run::AUTO_IMPORT_NONE, first_run::auto_import_state()); |
| 108 | 108 |
| 109 extensions::ComponentLoader::EnableBackgroundExtensionsForTesting(); | 109 extensions::ComponentLoader::EnableBackgroundExtensionsForTesting(); |
| 110 } | 110 } |
| 111 | 111 |
| 112 void SetMasterPreferencesForTest(const char text[]) { | 112 void SetMasterPreferencesForTest(const char text[]) { |
| 113 text_.reset(new std::string(text)); | 113 text_.reset(new std::string(text)); |
| 114 } | 114 } |
| 115 | 115 |
| 116 private: | 116 private: |
| 117 base::FilePath prefs_file_; | 117 base::FilePath prefs_file_; |
| 118 scoped_ptr<std::string> text_; | 118 scoped_ptr<std::string> text_; |
| 119 | 119 |
| 120 DISALLOW_COPY_AND_ASSIGN(FirstRunMasterPrefsBrowserTestBase); | 120 DISALLOW_COPY_AND_ASSIGN(FirstRunMasterPrefsBrowserTestBase); |
| 121 }; | 121 }; |
| 122 | 122 |
| 123 template<const char Text[]> | 123 template<const char Text[]> |
| 124 class FirstRunMasterPrefsBrowserTestT | 124 class FirstRunMasterPrefsBrowserTestT |
| 125 : public FirstRunMasterPrefsBrowserTestBase { | 125 : public FirstRunMasterPrefsBrowserTestBase { |
| 126 public: | 126 public: |
| 127 FirstRunMasterPrefsBrowserTestT() {} | 127 FirstRunMasterPrefsBrowserTestT() {} |
| 128 | 128 |
| 129 protected: | 129 protected: |
| 130 virtual void SetUp() OVERRIDE { | 130 virtual void SetUp() override { |
| 131 SetMasterPreferencesForTest(Text); | 131 SetMasterPreferencesForTest(Text); |
| 132 FirstRunMasterPrefsBrowserTestBase::SetUp(); | 132 FirstRunMasterPrefsBrowserTestBase::SetUp(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 private: | 135 private: |
| 136 DISALLOW_COPY_AND_ASSIGN(FirstRunMasterPrefsBrowserTestT); | 136 DISALLOW_COPY_AND_ASSIGN(FirstRunMasterPrefsBrowserTestT); |
| 137 }; | 137 }; |
| 138 | 138 |
| 139 // Returns the true expected import state, derived from the original | 139 // Returns the true expected import state, derived from the original |
| 140 // |expected_import_state|, for the current test machine's configuration. Some | 140 // |expected_import_state|, for the current test machine's configuration. Some |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 " \"homepage\": \"example.com\",\n" | 242 " \"homepage\": \"example.com\",\n" |
| 243 " \"homepage_is_newtabpage\": false\n" | 243 " \"homepage_is_newtabpage\": false\n" |
| 244 "}\n"; | 244 "}\n"; |
| 245 // A test fixture that will run in a first run scenario with master_preferences | 245 // A test fixture that will run in a first run scenario with master_preferences |
| 246 // set to kWithTrackedPrefs. Parameterizable on the SettingsEnforcement | 246 // set to kWithTrackedPrefs. Parameterizable on the SettingsEnforcement |
| 247 // experiment to be forced. | 247 // experiment to be forced. |
| 248 class FirstRunMasterPrefsWithTrackedPreferences | 248 class FirstRunMasterPrefsWithTrackedPreferences |
| 249 : public FirstRunMasterPrefsBrowserTestT<kWithTrackedPrefs>, | 249 : public FirstRunMasterPrefsBrowserTestT<kWithTrackedPrefs>, |
| 250 public testing::WithParamInterface<std::string> { | 250 public testing::WithParamInterface<std::string> { |
| 251 public: | 251 public: |
| 252 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 252 virtual void SetUpCommandLine(CommandLine* command_line) override { |
| 253 FirstRunMasterPrefsBrowserTestT::SetUpCommandLine(command_line); | 253 FirstRunMasterPrefsBrowserTestT::SetUpCommandLine(command_line); |
| 254 command_line->AppendSwitchASCII( | 254 command_line->AppendSwitchASCII( |
| 255 switches::kForceFieldTrials, | 255 switches::kForceFieldTrials, |
| 256 std::string(chrome_prefs::internals::kSettingsEnforcementTrialName) + | 256 std::string(chrome_prefs::internals::kSettingsEnforcementTrialName) + |
| 257 "/" + GetParam() + "/"); | 257 "/" + GetParam() + "/"); |
| 258 } | 258 } |
| 259 }; | 259 }; |
| 260 | 260 |
| 261 // http://crbug.com/314221 | 261 // http://crbug.com/314221 |
| 262 #if defined(GOOGLE_CHROME_BUILD) && (defined(OS_MACOSX) || defined(OS_LINUX)) | 262 #if defined(GOOGLE_CHROME_BUILD) && (defined(OS_MACOSX) || defined(OS_LINUX)) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 289 FirstRunMasterPrefsWithTrackedPreferences, | 289 FirstRunMasterPrefsWithTrackedPreferences, |
| 290 testing::Values( | 290 testing::Values( |
| 291 chrome_prefs::internals::kSettingsEnforcementGroupNoEnforcement, | 291 chrome_prefs::internals::kSettingsEnforcementGroupNoEnforcement, |
| 292 chrome_prefs::internals::kSettingsEnforcementGroupEnforceAlways, | 292 chrome_prefs::internals::kSettingsEnforcementGroupEnforceAlways, |
| 293 chrome_prefs::internals:: | 293 chrome_prefs::internals:: |
| 294 kSettingsEnforcementGroupEnforceAlwaysWithDSE, | 294 kSettingsEnforcementGroupEnforceAlwaysWithDSE, |
| 295 chrome_prefs::internals:: | 295 chrome_prefs::internals:: |
| 296 kSettingsEnforcementGroupEnforceAlwaysWithExtensionsAndDSE)); | 296 kSettingsEnforcementGroupEnforceAlwaysWithExtensionsAndDSE)); |
| 297 | 297 |
| 298 #endif // !defined(OS_CHROMEOS) | 298 #endif // !defined(OS_CHROMEOS) |
| OLD | NEW |