Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/basictypes.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/prefs/pref_registry_simple.h" | |
| 11 #include "base/prefs/testing_pref_service.h" | |
| 10 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 11 #include "base/threading/sequenced_worker_pool.h" | 13 #include "base/threading/sequenced_worker_pool.h" |
| 12 #include "chrome/browser/profile_resetter/automatic_profile_resetter.h" | 14 #include "chrome/browser/profile_resetter/automatic_profile_resetter.h" |
| 15 #include "chrome/browser/profile_resetter/automatic_profile_resetter_delegate.h" | |
| 13 #include "chrome/browser/profile_resetter/automatic_profile_resetter_factory.h" | 16 #include "chrome/browser/profile_resetter/automatic_profile_resetter_factory.h" |
| 14 #include "chrome/browser/profile_resetter/automatic_profile_resetter_mementos.h" | 17 #include "chrome/browser/profile_resetter/automatic_profile_resetter_mementos.h" |
| 15 #include "chrome/browser/profile_resetter/jtl_foundation.h" | 18 #include "chrome/browser/profile_resetter/jtl_foundation.h" |
| 16 #include "chrome/browser/profile_resetter/jtl_instructions.h" | 19 #include "chrome/browser/profile_resetter/jtl_instructions.h" |
| 17 #include "chrome/test/base/scoped_testing_local_state.h" | 20 #include "chrome/test/base/scoped_testing_local_state.h" |
| 18 #include "chrome/test/base/testing_browser_process.h" | 21 #include "chrome/test/base/testing_browser_process.h" |
| 22 #include "chrome/test/base/testing_pref_service_syncable.h" | |
| 19 #include "chrome/test/base/testing_profile.h" | 23 #include "chrome/test/base/testing_profile.h" |
| 24 #include "components/user_prefs/pref_registry_syncable.h" | |
| 20 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/test/test_browser_thread_bundle.h" | 26 #include "content/public/test/test_browser_thread_bundle.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 29 |
| 30 using testing::_; | |
| 31 using testing::Invoke; | |
| 32 using testing::Return; | |
| 33 | |
| 25 namespace { | 34 namespace { |
| 26 | 35 |
| 27 const char kAutomaticProfileResetStudyName[] = "AutomaticProfileReset"; | 36 const char kAutomaticProfileResetStudyName[] = "AutomaticProfileReset"; |
| 28 const char kStudyDisabledGroupName[] = "Disabled"; | 37 const char kStudyDisabledGroupName[] = "Disabled"; |
| 29 const char kStudyDryRunGroupName[] = "DryRun"; | 38 const char kStudyDryRunGroupName[] = "DryRun"; |
| 30 const char kStudyEnabledGroupName[] = "Enabled"; | 39 const char kStudyEnabledGroupName[] = "Enabled"; |
| 31 | 40 |
| 32 const char kTestHashSeed[] = "testing-hash-seed"; | 41 const char kTestHashSeed[] = "testing-hash-seed"; |
| 33 const char kTestMementoValue[] = "01234567890123456789012345678901"; | 42 const char kTestMementoValue[] = "01234567890123456789012345678901"; |
| 34 const char kTestInvalidMementoValue[] = "12345678901234567890123456789012"; | 43 const char kTestInvalidMementoValue[] = "12345678901234567890123456789012"; |
| 35 | 44 |
| 45 const char kTestPreferencePath[] = "testing.preference"; | |
| 46 const char kTestPreferenceValue[] = "testing-preference-value"; | |
| 47 | |
| 48 const char kSearchURLAttributeKey[] = "search_url"; | |
| 49 const char kTestSearchURL[] = "http://example.com/search?q={searchTerms}"; | |
| 50 const char kTestSearchURL2[] = "http://google.com/?q={searchTerms}"; | |
| 51 | |
| 36 // Helpers ------------------------------------------------------------------ | 52 // Helpers ------------------------------------------------------------------ |
| 37 | 53 |
| 38 class MockProfileResetterDelegate : public AutomaticProfileResetterDelegate { | 54 class MockProfileResetterDelegate : public AutomaticProfileResetterDelegate { |
| 39 public: | 55 public: |
| 40 MockProfileResetterDelegate() {} | 56 MockProfileResetterDelegate() |
| 57 : emulated_default_search_provider_is_managed_(false) {} | |
| 41 virtual ~MockProfileResetterDelegate() {} | 58 virtual ~MockProfileResetterDelegate() {} |
| 42 | 59 |
| 60 MOCK_METHOD0(LoadTemplateURLServiceIfNeeded, void()); | |
| 61 MOCK_METHOD1(WaitOnTemplateURLService, void(const base::Closure&)); | |
| 62 | |
| 63 MOCK_CONST_METHOD0(GetDefaultSearchProviderDetails, base::DictionaryValue*()); | |
| 64 MOCK_CONST_METHOD0(IsDefaultSearchProviderManaged, bool()); | |
| 65 MOCK_CONST_METHOD0(GetPrepopulatedSearchProvidersDetails, base::ListValue*()); | |
| 66 | |
| 43 MOCK_METHOD0(ShowPrompt, void()); | 67 MOCK_METHOD0(ShowPrompt, void()); |
| 44 MOCK_METHOD2(ReportStatistics, void(uint32, uint32)); | 68 MOCK_METHOD2(ReportStatistics, void(uint32, uint32)); |
| 45 | 69 |
| 70 static void ClosureInvoker(const base::Closure& closure) { closure.Run(); } | |
| 71 | |
| 72 void ExpectCallsToWaitingMethods() { | |
| 73 EXPECT_CALL(*this, WaitOnTemplateURLService(_)) | |
| 74 .WillOnce(Invoke(ClosureInvoker)); | |
| 75 EXPECT_CALL(*this, LoadTemplateURLServiceIfNeeded()); | |
| 76 } | |
| 77 | |
| 78 void ExpectCallsToGetterMethods() { | |
| 79 EXPECT_CALL(*this, GetDefaultSearchProviderDetails()) | |
| 80 .WillRepeatedly(Invoke(&emulated_default_search_provider_details_, | |
| 81 &base::DictionaryValue::DeepCopy)); | |
| 82 EXPECT_CALL(*this, IsDefaultSearchProviderManaged()) | |
| 83 .WillRepeatedly(Return(emulated_default_search_provider_is_managed_)); | |
| 84 EXPECT_CALL(*this, GetPrepopulatedSearchProvidersDetails()) | |
| 85 .WillRepeatedly(Invoke(&emulated_search_providers_details_, | |
| 86 &base::ListValue::DeepCopy)); | |
| 87 } | |
| 88 | |
| 89 base::DictionaryValue& emulated_default_search_provider_details() { | |
| 90 return emulated_default_search_provider_details_; | |
| 91 } | |
| 92 | |
| 93 base::ListValue& emulated_search_providers_details() { | |
| 94 return emulated_search_providers_details_; | |
| 95 } | |
| 96 | |
| 97 void set_emulated_default_search_provider_is_managed(bool value) { | |
| 98 emulated_default_search_provider_is_managed_ = value; | |
| 99 } | |
| 100 | |
| 46 private: | 101 private: |
| 102 base::DictionaryValue emulated_default_search_provider_details_; | |
| 103 bool emulated_default_search_provider_is_managed_; | |
| 104 base::ListValue emulated_search_providers_details_; | |
| 105 | |
| 47 DISALLOW_COPY_AND_ASSIGN(MockProfileResetterDelegate); | 106 DISALLOW_COPY_AND_ASSIGN(MockProfileResetterDelegate); |
| 48 }; | 107 }; |
| 49 | 108 |
| 50 class FileHostedPromptMementoSynchronous : protected FileHostedPromptMemento { | 109 class FileHostedPromptMementoSynchronous : protected FileHostedPromptMemento { |
| 51 public: | 110 public: |
| 52 explicit FileHostedPromptMementoSynchronous(Profile* profile) | 111 explicit FileHostedPromptMementoSynchronous(Profile* profile) |
| 53 : FileHostedPromptMemento(profile) {} | 112 : FileHostedPromptMemento(profile) {} |
| 54 | 113 |
| 55 std::string ReadValue() const { | 114 std::string ReadValue() const { |
| 56 std::string result; | 115 std::string result; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 72 DISALLOW_COPY_AND_ASSIGN(FileHostedPromptMementoSynchronous); | 131 DISALLOW_COPY_AND_ASSIGN(FileHostedPromptMementoSynchronous); |
| 73 }; | 132 }; |
| 74 | 133 |
| 75 std::string GetHash(const std::string& input) { | 134 std::string GetHash(const std::string& input) { |
| 76 return jtl_foundation::Hasher(kTestHashSeed).GetHash(input); | 135 return jtl_foundation::Hasher(kTestHashSeed).GetHash(input); |
| 77 } | 136 } |
| 78 | 137 |
| 79 // Encodes a Boolean argument value into JTL bytecode. | 138 // Encodes a Boolean argument value into JTL bytecode. |
| 80 std::string EncodeBool(bool value) { return value ? VALUE_TRUE : VALUE_FALSE; } | 139 std::string EncodeBool(bool value) { return value ? VALUE_TRUE : VALUE_FALSE; } |
| 81 | 140 |
| 82 // Constructs a simple evaluation program to test that input/output works well. | 141 // Constructs a simple evaluation program to test that basic input/output works |
| 83 // It will emulate a scenario in which the reset criteria are satisfied as | 142 // well. It will emulate a scenario in which the reset criteria are satisfied as |
| 84 // prescribed by |emulate_satisfied_criterion_{1|2}|, and will set bits in the | 143 // prescribed by |emulate_satisfied_criterion_{1|2}|, and will set bits in the |
| 85 // combined status mask according to whether or not the memento values received | 144 // combined status mask according to whether or not the memento values received |
| 86 // in the input were as expected. | 145 // in the input were as expected. |
| 87 // | 146 // |
| 88 // More specifically, the output of the program will be as follows: | 147 // More specifically, the output of the program will be as follows: |
| 89 // { | 148 // { |
| 90 // "satisfied_criteria_mask_bit1": emulate_satisfied_criterion_1, | 149 // "satisfied_criteria_mask_bit1": emulate_satisfied_criterion_1, |
| 91 // "satisfied_criteria_mask_bit2": emulate_satisfied_criterion_2, | 150 // "satisfied_criteria_mask_bit2": emulate_satisfied_criterion_2, |
| 92 // "combined_status_mask_bit1": | 151 // "combined_status_mask_bit1": |
| 93 // (emulate_satisfied_criterion_1 || emulate_satisfied_criterion_2), | 152 // (emulate_satisfied_criterion_1 || emulate_satisfied_criterion_2), |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 bytecode += OP_END_OF_SENTENCE; | 194 bytecode += OP_END_OF_SENTENCE; |
| 136 bytecode += OP_STORE_HASH(GetHash("memento_value_in_local_state"), | 195 bytecode += OP_STORE_HASH(GetHash("memento_value_in_local_state"), |
| 137 kTestMementoValue); | 196 kTestMementoValue); |
| 138 bytecode += OP_END_OF_SENTENCE; | 197 bytecode += OP_END_OF_SENTENCE; |
| 139 bytecode += OP_STORE_HASH(GetHash("memento_value_in_file"), | 198 bytecode += OP_STORE_HASH(GetHash("memento_value_in_file"), |
| 140 kTestMementoValue); | 199 kTestMementoValue); |
| 141 bytecode += OP_END_OF_SENTENCE; | 200 bytecode += OP_END_OF_SENTENCE; |
| 142 return bytecode; | 201 return bytecode; |
| 143 } | 202 } |
| 144 | 203 |
| 204 // Constructs another evaluation program to specifically test that local state | |
| 205 // and user preference values are included in the input as expected. We will | |
| 206 // re-purpose the output bitmasks to channel out information about the outcome | |
| 207 // of the checks. | |
| 208 // | |
| 209 // More specifically, the output of the program will be as follows: | |
| 210 // { | |
| 211 // "combined_status_mask_bit1": | |
| 212 // (input["preferences.testing.preference"] == kTestPreferenceValue) | |
| 213 // "combined_status_mask_bit2": | |
| 214 // (input["local_state.testing.preference"] == kTestPreferenceValue) | |
| 215 // "combined_status_mask_bit3": input["preferences_iuc.testing.preference"] | |
| 216 // "combined_status_mask_bit4": input["local_state_iuc.testing.preference"] | |
| 217 // } | |
| 218 std::string ConstructProgramToCheckPreferences() { | |
| 219 std::string bytecode; | |
| 220 bytecode += OP_NAVIGATE(GetHash("preferences")); | |
| 221 bytecode += OP_NAVIGATE(GetHash("testing")); | |
| 222 bytecode += OP_NAVIGATE(GetHash("preference")); | |
| 223 bytecode += OP_COMPARE_NODE_HASH(GetHash(kTestPreferenceValue)); | |
| 224 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit1"), | |
| 225 EncodeBool(true)); | |
| 226 bytecode += OP_END_OF_SENTENCE; | |
| 227 bytecode += OP_NAVIGATE(GetHash("local_state")); | |
| 228 bytecode += OP_NAVIGATE(GetHash("testing")); | |
| 229 bytecode += OP_NAVIGATE(GetHash("preference")); | |
| 230 bytecode += OP_COMPARE_NODE_HASH(GetHash(kTestPreferenceValue)); | |
| 231 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit2"), | |
| 232 EncodeBool(true)); | |
| 233 bytecode += OP_END_OF_SENTENCE; | |
| 234 bytecode += OP_NAVIGATE(GetHash("preferences_iuc")); | |
| 235 bytecode += OP_NAVIGATE(GetHash("testing")); | |
| 236 bytecode += OP_NAVIGATE(GetHash("preference")); | |
| 237 bytecode += OP_COMPARE_NODE_BOOL(EncodeBool(true)); | |
| 238 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit3"), | |
| 239 EncodeBool(true)); | |
| 240 bytecode += OP_END_OF_SENTENCE; | |
| 241 bytecode += OP_NAVIGATE(GetHash("local_state_iuc")); | |
| 242 bytecode += OP_NAVIGATE(GetHash("testing")); | |
| 243 bytecode += OP_NAVIGATE(GetHash("preference")); | |
| 244 bytecode += OP_COMPARE_NODE_BOOL(EncodeBool(true)); | |
| 245 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit4"), | |
| 246 EncodeBool(true)); | |
| 247 bytecode += OP_END_OF_SENTENCE; | |
| 248 return bytecode; | |
| 249 } | |
| 250 | |
| 251 // Legend for the bitmask returned by the above program. | |
| 252 enum CombinedStatusMaskLegendForCheckingPreferences { | |
| 253 HasExpectedUserPreference = 1 << 0, | |
| 254 HasExpectedLocalStatePreference = 1 << 1, | |
| 255 UserPreferenceIsUserControlled = 1 << 2, | |
| 256 LocalStateIsUserControlled = 1 << 3, | |
| 257 }; | |
| 258 | |
| 259 // Constructs yet another evaluation program to specifically test that default | |
| 260 // and pre-populated search engines are included in the input as expected. We | |
| 261 // will re-purpose the output bitmasks to channel out information about the | |
| 262 // outcome of the checks. | |
| 263 // | |
| 264 // More specifically, the output of the program will be as follows: | |
| 265 // { | |
| 266 // "combined_status_mask_bit1": | |
| 267 // (input["default_search_provider.search_url"] == kTestSearchURL) | |
| 268 // "combined_status_mask_bit2": input["default_search_provider_iuc"] | |
| 269 // "combined_status_mask_bit3": | |
| 270 // (input["search_providers.*.search_url"] == kTestSearchURL) | |
| 271 // "combined_status_mask_bit4": | |
| 272 // (input["search_providers.*.search_url"] == kTestSearchURL2) | |
| 273 // } | |
| 274 std::string ConstructProgramToCheckSearchEngines() { | |
| 275 std::string bytecode; | |
| 276 bytecode += OP_NAVIGATE(GetHash("default_search_provider")); | |
| 277 bytecode += OP_NAVIGATE(GetHash("search_url")); | |
| 278 bytecode += OP_COMPARE_NODE_HASH(GetHash(kTestSearchURL)); | |
| 279 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit1"), | |
| 280 EncodeBool(true)); | |
| 281 bytecode += OP_END_OF_SENTENCE; | |
| 282 bytecode += OP_NAVIGATE(GetHash("default_search_provider_iuc")); | |
| 283 bytecode += OP_COMPARE_NODE_BOOL(EncodeBool(true)); | |
| 284 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit2"), | |
| 285 EncodeBool(true)); | |
| 286 bytecode += OP_END_OF_SENTENCE; | |
| 287 bytecode += OP_NAVIGATE(GetHash("search_providers")); | |
| 288 bytecode += OP_NAVIGATE_ANY; | |
| 289 bytecode += OP_NAVIGATE(GetHash("search_url")); | |
| 290 bytecode += OP_COMPARE_NODE_HASH(GetHash(kTestSearchURL)); | |
| 291 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit3"), | |
| 292 EncodeBool(true)); | |
| 293 bytecode += OP_END_OF_SENTENCE; | |
| 294 bytecode += OP_NAVIGATE(GetHash("search_providers")); | |
| 295 bytecode += OP_NAVIGATE_ANY; | |
| 296 bytecode += OP_NAVIGATE(GetHash("search_url")); | |
| 297 bytecode += OP_COMPARE_NODE_HASH(GetHash(kTestSearchURL2)); | |
| 298 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit4"), | |
| 299 EncodeBool(true)); | |
| 300 bytecode += OP_END_OF_SENTENCE; | |
| 301 return bytecode; | |
| 302 } | |
| 303 | |
| 304 // Legend for the bitmask returned by the above program. | |
| 305 enum CombinedStatusMaskLegendForCheckingSearchEngines { | |
| 306 HasExpectedDefaultSearchProvider = 1 << 0, | |
|
battre
2013/10/11 16:48:25
Nit: Enums are supposed to be ALL_CAPS_STYLE.
engedy
2013/10/11 16:55:14
Done.
| |
| 307 DefaultSearchProviderIsUserControlled = 1 << 1, | |
| 308 HasExpectedPrepopulatedSearchProvider1 = 1 << 2, | |
| 309 HasExpectedPrepopulatedSearchProvider2 = 1 << 3, | |
| 310 }; | |
| 311 | |
| 145 // Test fixtures ------------------------------------------------------------- | 312 // Test fixtures ------------------------------------------------------------- |
| 146 | 313 |
| 147 class AutomaticProfileResetterTestBase : public testing::Test { | 314 class AutomaticProfileResetterTestBase : public testing::Test { |
| 148 protected: | 315 protected: |
| 149 explicit AutomaticProfileResetterTestBase( | 316 explicit AutomaticProfileResetterTestBase( |
| 150 const std::string& experiment_group_name) | 317 const std::string& experiment_group_name) |
| 151 : local_state_(TestingBrowserProcess::GetGlobal()), | 318 : local_state_(TestingBrowserProcess::GetGlobal()), |
| 319 profile_(new TestingProfile()), | |
| 152 experiment_group_name_(experiment_group_name), | 320 experiment_group_name_(experiment_group_name), |
| 153 mock_delegate_(NULL) { | 321 mock_delegate_(NULL) { |
| 154 // Make sure the factory is not optimized away, so prefs get registered. | 322 // Make sure the factory is not optimized away, so whatever preferences it |
| 323 // wants to register will actually get registered. | |
| 155 AutomaticProfileResetterFactory::GetInstance(); | 324 AutomaticProfileResetterFactory::GetInstance(); |
| 325 | |
| 326 // Register some additional local state preferences for testing purposes. | |
| 327 PrefRegistrySimple* local_state_registry = local_state_.Get()->registry(); | |
| 328 DCHECK(local_state_registry); | |
| 329 local_state_registry->RegisterStringPref(kTestPreferencePath, ""); | |
| 330 | |
| 331 // Register some additional user preferences for testing purposes. | |
| 332 user_prefs::PrefRegistrySyncable* user_prefs_registry = | |
| 333 profile_->GetTestingPrefService()->registry(); | |
| 334 DCHECK(user_prefs_registry); | |
| 335 user_prefs_registry->RegisterStringPref( | |
| 336 kTestPreferencePath, | |
| 337 "", | |
| 338 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 156 } | 339 } |
| 157 | 340 |
| 158 virtual void SetUp() OVERRIDE { | 341 virtual void SetUp() OVERRIDE { |
| 159 profile_.reset(new TestingProfile()); | |
| 160 field_trials_.reset(new base::FieldTrialList(NULL)); | 342 field_trials_.reset(new base::FieldTrialList(NULL)); |
| 161 base::FieldTrialList::CreateFieldTrial(kAutomaticProfileResetStudyName, | 343 base::FieldTrialList::CreateFieldTrial(kAutomaticProfileResetStudyName, |
| 162 experiment_group_name_); | 344 experiment_group_name_); |
| 163 mock_delegate_ = new testing::StrictMock<MockProfileResetterDelegate>(); | 345 mock_delegate_ = new testing::StrictMock<MockProfileResetterDelegate>(); |
| 164 resetter_.reset(new AutomaticProfileResetter(profile_.get())); | 346 resetter_.reset(new AutomaticProfileResetter(profile_.get())); |
| 165 } | 347 } |
| 166 | 348 |
| 167 void SetTestingHashSeed(const std::string& hash_seed) { | 349 void SetTestingHashSeed(const std::string& hash_seed) { |
| 168 testing_hash_seed_ = hash_seed; | 350 testing_hash_seed_ = hash_seed; |
| 169 } | 351 } |
| 170 | 352 |
| 171 void SetTestingProgram(const std::string& source_code) { | 353 void SetTestingProgram(const std::string& source_code) { |
| 172 testing_program_ = source_code; | 354 testing_program_ = source_code; |
| 173 } | 355 } |
| 174 | 356 |
| 175 void UnleashResetterAndWait() { | 357 void UnleashResetterAndWait() { |
| 176 resetter_->Initialize(); | |
| 177 resetter_->SetDelegateForTesting(mock_delegate_); // Takes ownership. | 358 resetter_->SetDelegateForTesting(mock_delegate_); // Takes ownership. |
| 178 resetter_->SetHashSeedForTesting(testing_hash_seed_); | 359 resetter_->SetHashSeedForTesting(testing_hash_seed_); |
| 179 resetter_->SetProgramForTesting(testing_program_); | 360 resetter_->SetProgramForTesting(testing_program_); |
| 361 | |
| 362 resetter_->Activate(); | |
| 180 base::RunLoop().RunUntilIdle(); | 363 base::RunLoop().RunUntilIdle(); |
| 181 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 364 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 182 base::RunLoop().RunUntilIdle(); | 365 base::RunLoop().RunUntilIdle(); |
| 183 } | 366 } |
| 184 | 367 |
| 185 TestingProfile* profile() { return profile_.get(); } | 368 TestingProfile* profile() { return profile_.get(); } |
| 369 TestingPrefServiceSimple* local_state() { return local_state_.Get(); } | |
| 186 | 370 |
| 187 MockProfileResetterDelegate& mock_delegate() { return *mock_delegate_; } | 371 MockProfileResetterDelegate& mock_delegate() { return *mock_delegate_; } |
| 188 AutomaticProfileResetter* resetter() { return resetter_.get(); } | 372 AutomaticProfileResetter* resetter() { return resetter_.get(); } |
| 189 | 373 |
| 190 private: | 374 private: |
| 191 content::TestBrowserThreadBundle thread_bundle_; | 375 content::TestBrowserThreadBundle thread_bundle_; |
| 192 ScopedTestingLocalState local_state_; | 376 ScopedTestingLocalState local_state_; |
| 193 scoped_ptr<TestingProfile> profile_; | 377 scoped_ptr<TestingProfile> profile_; |
| 194 scoped_ptr<base::FieldTrialList> field_trials_; | 378 scoped_ptr<base::FieldTrialList> field_trials_; |
| 195 std::string experiment_group_name_; | 379 std::string experiment_group_name_; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 LocalStateHostedPromptMemento memento_in_local_state(profile()); | 434 LocalStateHostedPromptMemento memento_in_local_state(profile()); |
| 251 FileHostedPromptMementoSynchronous memento_in_file(profile()); | 435 FileHostedPromptMementoSynchronous memento_in_file(profile()); |
| 252 | 436 |
| 253 EXPECT_EQ("", memento_in_prefs.ReadValue()); | 437 EXPECT_EQ("", memento_in_prefs.ReadValue()); |
| 254 EXPECT_EQ("", memento_in_local_state.ReadValue()); | 438 EXPECT_EQ("", memento_in_local_state.ReadValue()); |
| 255 EXPECT_EQ("", memento_in_file.ReadValue()); | 439 EXPECT_EQ("", memento_in_file.ReadValue()); |
| 256 | 440 |
| 257 SetTestingProgram(ConstructProgram(false, false)); | 441 SetTestingProgram(ConstructProgram(false, false)); |
| 258 SetTestingHashSeed(kTestHashSeed); | 442 SetTestingHashSeed(kTestHashSeed); |
| 259 | 443 |
| 444 mock_delegate().ExpectCallsToWaitingMethods(); | |
| 445 mock_delegate().ExpectCallsToGetterMethods(); | |
| 260 EXPECT_CALL(mock_delegate(), ReportStatistics(0x00u, 0x00u)); | 446 EXPECT_CALL(mock_delegate(), ReportStatistics(0x00u, 0x00u)); |
| 261 | 447 |
| 262 UnleashResetterAndWait(); | 448 UnleashResetterAndWait(); |
| 263 | 449 |
| 264 EXPECT_EQ("", memento_in_prefs.ReadValue()); | 450 EXPECT_EQ("", memento_in_prefs.ReadValue()); |
| 265 EXPECT_EQ("", memento_in_local_state.ReadValue()); | 451 EXPECT_EQ("", memento_in_local_state.ReadValue()); |
| 266 EXPECT_EQ("", memento_in_file.ReadValue()); | 452 EXPECT_EQ("", memento_in_file.ReadValue()); |
| 267 } | 453 } |
| 268 | 454 |
| 269 TEST_F(AutomaticProfileResetterTestDryRun, OneConditionSatisfied) { | 455 TEST_F(AutomaticProfileResetterTestDryRun, OneConditionSatisfied) { |
| 270 PreferenceHostedPromptMemento memento_in_prefs(profile()); | 456 PreferenceHostedPromptMemento memento_in_prefs(profile()); |
| 271 LocalStateHostedPromptMemento memento_in_local_state(profile()); | 457 LocalStateHostedPromptMemento memento_in_local_state(profile()); |
| 272 FileHostedPromptMementoSynchronous memento_in_file(profile()); | 458 FileHostedPromptMementoSynchronous memento_in_file(profile()); |
| 273 | 459 |
| 274 EXPECT_EQ("", memento_in_prefs.ReadValue()); | 460 EXPECT_EQ("", memento_in_prefs.ReadValue()); |
| 275 EXPECT_EQ("", memento_in_local_state.ReadValue()); | 461 EXPECT_EQ("", memento_in_local_state.ReadValue()); |
| 276 EXPECT_EQ("", memento_in_file.ReadValue()); | 462 EXPECT_EQ("", memento_in_file.ReadValue()); |
| 277 | 463 |
| 278 SetTestingProgram(ConstructProgram(true, false)); | 464 SetTestingProgram(ConstructProgram(true, false)); |
| 279 SetTestingHashSeed(kTestHashSeed); | 465 SetTestingHashSeed(kTestHashSeed); |
| 280 | 466 |
| 467 mock_delegate().ExpectCallsToWaitingMethods(); | |
| 468 mock_delegate().ExpectCallsToGetterMethods(); | |
| 281 EXPECT_CALL(mock_delegate(), ReportStatistics(0x01u, 0x01u)); | 469 EXPECT_CALL(mock_delegate(), ReportStatistics(0x01u, 0x01u)); |
| 282 | 470 |
| 283 UnleashResetterAndWait(); | 471 UnleashResetterAndWait(); |
| 284 | 472 |
| 285 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); | 473 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); |
| 286 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); | 474 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); |
| 287 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); | 475 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); |
| 288 } | 476 } |
| 289 | 477 |
| 290 TEST_F(AutomaticProfileResetterTestDryRun, OtherConditionSatisfied) { | 478 TEST_F(AutomaticProfileResetterTestDryRun, OtherConditionSatisfied) { |
| 291 PreferenceHostedPromptMemento memento_in_prefs(profile()); | 479 PreferenceHostedPromptMemento memento_in_prefs(profile()); |
| 292 LocalStateHostedPromptMemento memento_in_local_state(profile()); | 480 LocalStateHostedPromptMemento memento_in_local_state(profile()); |
| 293 FileHostedPromptMementoSynchronous memento_in_file(profile()); | 481 FileHostedPromptMementoSynchronous memento_in_file(profile()); |
| 294 | 482 |
| 295 EXPECT_EQ("", memento_in_prefs.ReadValue()); | 483 EXPECT_EQ("", memento_in_prefs.ReadValue()); |
| 296 EXPECT_EQ("", memento_in_local_state.ReadValue()); | 484 EXPECT_EQ("", memento_in_local_state.ReadValue()); |
| 297 EXPECT_EQ("", memento_in_file.ReadValue()); | 485 EXPECT_EQ("", memento_in_file.ReadValue()); |
| 298 | 486 |
| 299 SetTestingProgram(ConstructProgram(false, true)); | 487 SetTestingProgram(ConstructProgram(false, true)); |
| 300 SetTestingHashSeed(kTestHashSeed); | 488 SetTestingHashSeed(kTestHashSeed); |
| 301 | 489 |
| 490 mock_delegate().ExpectCallsToWaitingMethods(); | |
| 491 mock_delegate().ExpectCallsToGetterMethods(); | |
| 302 EXPECT_CALL(mock_delegate(), ReportStatistics(0x02u, 0x01u)); | 492 EXPECT_CALL(mock_delegate(), ReportStatistics(0x02u, 0x01u)); |
| 303 | 493 |
| 304 UnleashResetterAndWait(); | 494 UnleashResetterAndWait(); |
| 305 | 495 |
| 306 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); | 496 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); |
| 307 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); | 497 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); |
| 308 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); | 498 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); |
| 309 } | 499 } |
| 310 | 500 |
| 311 TEST_F(AutomaticProfileResetterTestDryRun, | 501 TEST_F(AutomaticProfileResetterTestDryRun, |
| 312 ConditionsSatisfiedAndInvalidMementos) { | 502 ConditionsSatisfiedAndInvalidMementos) { |
| 313 PreferenceHostedPromptMemento memento_in_prefs(profile()); | 503 PreferenceHostedPromptMemento memento_in_prefs(profile()); |
| 314 LocalStateHostedPromptMemento memento_in_local_state(profile()); | 504 LocalStateHostedPromptMemento memento_in_local_state(profile()); |
| 315 FileHostedPromptMementoSynchronous memento_in_file(profile()); | 505 FileHostedPromptMementoSynchronous memento_in_file(profile()); |
| 316 | 506 |
| 317 memento_in_prefs.StoreValue(kTestInvalidMementoValue); | 507 memento_in_prefs.StoreValue(kTestInvalidMementoValue); |
| 318 memento_in_local_state.StoreValue(kTestInvalidMementoValue); | 508 memento_in_local_state.StoreValue(kTestInvalidMementoValue); |
| 319 memento_in_file.StoreValue(kTestInvalidMementoValue); | 509 memento_in_file.StoreValue(kTestInvalidMementoValue); |
| 320 | 510 |
| 321 SetTestingProgram(ConstructProgram(true, true)); | 511 SetTestingProgram(ConstructProgram(true, true)); |
| 322 SetTestingHashSeed(kTestHashSeed); | 512 SetTestingHashSeed(kTestHashSeed); |
| 323 | 513 |
| 514 mock_delegate().ExpectCallsToWaitingMethods(); | |
| 515 mock_delegate().ExpectCallsToGetterMethods(); | |
| 324 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x01u)); | 516 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x01u)); |
| 325 | 517 |
| 326 UnleashResetterAndWait(); | 518 UnleashResetterAndWait(); |
| 327 | 519 |
| 328 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); | 520 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); |
| 329 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); | 521 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); |
| 330 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); | 522 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); |
| 331 } | 523 } |
| 332 | 524 |
| 333 TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadPrefHostedMemento) { | 525 TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadPrefHostedMemento) { |
| 334 PreferenceHostedPromptMemento memento_in_prefs(profile()); | 526 PreferenceHostedPromptMemento memento_in_prefs(profile()); |
| 335 LocalStateHostedPromptMemento memento_in_local_state(profile()); | 527 LocalStateHostedPromptMemento memento_in_local_state(profile()); |
| 336 FileHostedPromptMementoSynchronous memento_in_file(profile()); | 528 FileHostedPromptMementoSynchronous memento_in_file(profile()); |
| 337 | 529 |
| 338 memento_in_prefs.StoreValue(kTestMementoValue); | 530 memento_in_prefs.StoreValue(kTestMementoValue); |
| 339 | 531 |
| 340 SetTestingProgram(ConstructProgram(true, true)); | 532 SetTestingProgram(ConstructProgram(true, true)); |
| 341 SetTestingHashSeed(kTestHashSeed); | 533 SetTestingHashSeed(kTestHashSeed); |
| 342 | 534 |
| 535 mock_delegate().ExpectCallsToWaitingMethods(); | |
| 536 mock_delegate().ExpectCallsToGetterMethods(); | |
| 343 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x03u)); | 537 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x03u)); |
| 344 | 538 |
| 345 UnleashResetterAndWait(); | 539 UnleashResetterAndWait(); |
| 346 | 540 |
| 347 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); | 541 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); |
| 348 EXPECT_EQ("", memento_in_local_state.ReadValue()); | 542 EXPECT_EQ("", memento_in_local_state.ReadValue()); |
| 349 EXPECT_EQ("", memento_in_file.ReadValue()); | 543 EXPECT_EQ("", memento_in_file.ReadValue()); |
| 350 } | 544 } |
| 351 | 545 |
| 352 TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadLocalStateHostedMemento) { | 546 TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadLocalStateHostedMemento) { |
| 353 PreferenceHostedPromptMemento memento_in_prefs(profile()); | 547 PreferenceHostedPromptMemento memento_in_prefs(profile()); |
| 354 LocalStateHostedPromptMemento memento_in_local_state(profile()); | 548 LocalStateHostedPromptMemento memento_in_local_state(profile()); |
| 355 FileHostedPromptMementoSynchronous memento_in_file(profile()); | 549 FileHostedPromptMementoSynchronous memento_in_file(profile()); |
| 356 | 550 |
| 357 memento_in_local_state.StoreValue(kTestMementoValue); | 551 memento_in_local_state.StoreValue(kTestMementoValue); |
| 358 | 552 |
| 359 SetTestingProgram(ConstructProgram(true, true)); | 553 SetTestingProgram(ConstructProgram(true, true)); |
| 360 SetTestingHashSeed(kTestHashSeed); | 554 SetTestingHashSeed(kTestHashSeed); |
| 361 | 555 |
| 556 mock_delegate().ExpectCallsToWaitingMethods(); | |
| 557 mock_delegate().ExpectCallsToGetterMethods(); | |
| 362 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x05u)); | 558 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x05u)); |
| 363 | 559 |
| 364 UnleashResetterAndWait(); | 560 UnleashResetterAndWait(); |
| 365 | 561 |
| 366 EXPECT_EQ("", memento_in_prefs.ReadValue()); | 562 EXPECT_EQ("", memento_in_prefs.ReadValue()); |
| 367 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); | 563 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); |
| 368 EXPECT_EQ("", memento_in_file.ReadValue()); | 564 EXPECT_EQ("", memento_in_file.ReadValue()); |
| 369 } | 565 } |
| 370 | 566 |
| 371 TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadFileHostedMemento) { | 567 TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadFileHostedMemento) { |
| 372 PreferenceHostedPromptMemento memento_in_prefs(profile()); | 568 PreferenceHostedPromptMemento memento_in_prefs(profile()); |
| 373 LocalStateHostedPromptMemento memento_in_local_state(profile()); | 569 LocalStateHostedPromptMemento memento_in_local_state(profile()); |
| 374 FileHostedPromptMementoSynchronous memento_in_file(profile()); | 570 FileHostedPromptMementoSynchronous memento_in_file(profile()); |
| 375 | 571 |
| 376 memento_in_file.StoreValue(kTestMementoValue); | 572 memento_in_file.StoreValue(kTestMementoValue); |
| 377 | 573 |
| 378 SetTestingProgram(ConstructProgram(true, true)); | 574 SetTestingProgram(ConstructProgram(true, true)); |
| 379 SetTestingHashSeed(kTestHashSeed); | 575 SetTestingHashSeed(kTestHashSeed); |
| 380 | 576 |
| 577 mock_delegate().ExpectCallsToWaitingMethods(); | |
| 578 mock_delegate().ExpectCallsToGetterMethods(); | |
| 381 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x09u)); | 579 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x09u)); |
| 382 | 580 |
| 383 UnleashResetterAndWait(); | 581 UnleashResetterAndWait(); |
| 384 | 582 |
| 385 EXPECT_EQ("", memento_in_prefs.ReadValue()); | 583 EXPECT_EQ("", memento_in_prefs.ReadValue()); |
| 386 EXPECT_EQ("", memento_in_local_state.ReadValue()); | 584 EXPECT_EQ("", memento_in_local_state.ReadValue()); |
| 387 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); | 585 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); |
| 388 } | 586 } |
| 389 | 587 |
| 390 TEST_F(AutomaticProfileResetterTestDryRun, DoNothingWhenResourcesAreMissing) { | 588 TEST_F(AutomaticProfileResetterTestDryRun, DoNothingWhenResourcesAreMissing) { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 409 LocalStateHostedPromptMemento memento_in_local_state(profile()); | 607 LocalStateHostedPromptMemento memento_in_local_state(profile()); |
| 410 FileHostedPromptMementoSynchronous memento_in_file(profile()); | 608 FileHostedPromptMementoSynchronous memento_in_file(profile()); |
| 411 | 609 |
| 412 EXPECT_EQ("", memento_in_prefs.ReadValue()); | 610 EXPECT_EQ("", memento_in_prefs.ReadValue()); |
| 413 EXPECT_EQ("", memento_in_local_state.ReadValue()); | 611 EXPECT_EQ("", memento_in_local_state.ReadValue()); |
| 414 EXPECT_EQ("", memento_in_file.ReadValue()); | 612 EXPECT_EQ("", memento_in_file.ReadValue()); |
| 415 | 613 |
| 416 SetTestingProgram(ConstructProgram(false, false)); | 614 SetTestingProgram(ConstructProgram(false, false)); |
| 417 SetTestingHashSeed(kTestHashSeed); | 615 SetTestingHashSeed(kTestHashSeed); |
| 418 | 616 |
| 617 mock_delegate().ExpectCallsToWaitingMethods(); | |
| 618 mock_delegate().ExpectCallsToGetterMethods(); | |
| 419 EXPECT_CALL(mock_delegate(), ReportStatistics(0x00u, 0x00u)); | 619 EXPECT_CALL(mock_delegate(), ReportStatistics(0x00u, 0x00u)); |
| 420 | 620 |
| 421 UnleashResetterAndWait(); | 621 UnleashResetterAndWait(); |
| 422 | 622 |
| 423 EXPECT_EQ("", memento_in_prefs.ReadValue()); | 623 EXPECT_EQ("", memento_in_prefs.ReadValue()); |
| 424 EXPECT_EQ("", memento_in_local_state.ReadValue()); | 624 EXPECT_EQ("", memento_in_local_state.ReadValue()); |
| 425 EXPECT_EQ("", memento_in_file.ReadValue()); | 625 EXPECT_EQ("", memento_in_file.ReadValue()); |
| 426 } | 626 } |
| 427 | 627 |
| 428 TEST_F(AutomaticProfileResetterTest, OneConditionSatisfied) { | 628 TEST_F(AutomaticProfileResetterTest, OneConditionSatisfied) { |
| 429 PreferenceHostedPromptMemento memento_in_prefs(profile()); | 629 PreferenceHostedPromptMemento memento_in_prefs(profile()); |
| 430 LocalStateHostedPromptMemento memento_in_local_state(profile()); | 630 LocalStateHostedPromptMemento memento_in_local_state(profile()); |
| 431 FileHostedPromptMementoSynchronous memento_in_file(profile()); | 631 FileHostedPromptMementoSynchronous memento_in_file(profile()); |
| 432 | 632 |
| 433 EXPECT_EQ("", memento_in_prefs.ReadValue()); | 633 EXPECT_EQ("", memento_in_prefs.ReadValue()); |
| 434 EXPECT_EQ("", memento_in_local_state.ReadValue()); | 634 EXPECT_EQ("", memento_in_local_state.ReadValue()); |
| 435 EXPECT_EQ("", memento_in_file.ReadValue()); | 635 EXPECT_EQ("", memento_in_file.ReadValue()); |
| 436 | 636 |
| 437 SetTestingProgram(ConstructProgram(true, false)); | 637 SetTestingProgram(ConstructProgram(true, false)); |
| 438 SetTestingHashSeed(kTestHashSeed); | 638 SetTestingHashSeed(kTestHashSeed); |
| 439 | 639 |
| 640 mock_delegate().ExpectCallsToWaitingMethods(); | |
| 641 mock_delegate().ExpectCallsToGetterMethods(); | |
| 440 EXPECT_CALL(mock_delegate(), ShowPrompt()); | 642 EXPECT_CALL(mock_delegate(), ShowPrompt()); |
| 441 EXPECT_CALL(mock_delegate(), ReportStatistics(0x01u, 0x01u)); | 643 EXPECT_CALL(mock_delegate(), ReportStatistics(0x01u, 0x01u)); |
| 442 | 644 |
| 443 UnleashResetterAndWait(); | 645 UnleashResetterAndWait(); |
| 444 | 646 |
| 445 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); | 647 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); |
| 446 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); | 648 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); |
| 447 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); | 649 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); |
| 448 } | 650 } |
| 449 | 651 |
| 450 TEST_F(AutomaticProfileResetterTest, OtherConditionSatisfied) { | 652 TEST_F(AutomaticProfileResetterTest, OtherConditionSatisfied) { |
| 451 PreferenceHostedPromptMemento memento_in_prefs(profile()); | 653 PreferenceHostedPromptMemento memento_in_prefs(profile()); |
| 452 LocalStateHostedPromptMemento memento_in_local_state(profile()); | 654 LocalStateHostedPromptMemento memento_in_local_state(profile()); |
| 453 FileHostedPromptMementoSynchronous memento_in_file(profile()); | 655 FileHostedPromptMementoSynchronous memento_in_file(profile()); |
| 454 | 656 |
| 455 EXPECT_EQ("", memento_in_prefs.ReadValue()); | 657 EXPECT_EQ("", memento_in_prefs.ReadValue()); |
| 456 EXPECT_EQ("", memento_in_local_state.ReadValue()); | 658 EXPECT_EQ("", memento_in_local_state.ReadValue()); |
| 457 EXPECT_EQ("", memento_in_file.ReadValue()); | 659 EXPECT_EQ("", memento_in_file.ReadValue()); |
| 458 | 660 |
| 459 SetTestingProgram(ConstructProgram(false, true)); | 661 SetTestingProgram(ConstructProgram(false, true)); |
| 460 SetTestingHashSeed(kTestHashSeed); | 662 SetTestingHashSeed(kTestHashSeed); |
| 461 | 663 |
| 664 mock_delegate().ExpectCallsToWaitingMethods(); | |
| 665 mock_delegate().ExpectCallsToGetterMethods(); | |
| 462 EXPECT_CALL(mock_delegate(), ShowPrompt()); | 666 EXPECT_CALL(mock_delegate(), ShowPrompt()); |
| 463 EXPECT_CALL(mock_delegate(), ReportStatistics(0x02u, 0x01u)); | 667 EXPECT_CALL(mock_delegate(), ReportStatistics(0x02u, 0x01u)); |
| 464 | 668 |
| 465 UnleashResetterAndWait(); | 669 UnleashResetterAndWait(); |
| 466 | 670 |
| 467 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); | 671 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); |
| 468 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); | 672 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); |
| 469 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); | 673 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); |
| 470 } | 674 } |
| 471 | 675 |
| 472 TEST_F(AutomaticProfileResetterTest, ConditionsSatisfiedAndInvalidMementos) { | 676 TEST_F(AutomaticProfileResetterTest, ConditionsSatisfiedAndInvalidMementos) { |
| 473 PreferenceHostedPromptMemento memento_in_prefs(profile()); | 677 PreferenceHostedPromptMemento memento_in_prefs(profile()); |
| 474 LocalStateHostedPromptMemento memento_in_local_state(profile()); | 678 LocalStateHostedPromptMemento memento_in_local_state(profile()); |
| 475 FileHostedPromptMementoSynchronous memento_in_file(profile()); | 679 FileHostedPromptMementoSynchronous memento_in_file(profile()); |
| 476 | 680 |
| 477 memento_in_prefs.StoreValue(kTestInvalidMementoValue); | 681 memento_in_prefs.StoreValue(kTestInvalidMementoValue); |
| 478 memento_in_local_state.StoreValue(kTestInvalidMementoValue); | 682 memento_in_local_state.StoreValue(kTestInvalidMementoValue); |
| 479 memento_in_file.StoreValue(kTestInvalidMementoValue); | 683 memento_in_file.StoreValue(kTestInvalidMementoValue); |
| 480 | 684 |
| 481 SetTestingProgram(ConstructProgram(true, true)); | 685 SetTestingProgram(ConstructProgram(true, true)); |
| 482 SetTestingHashSeed(kTestHashSeed); | 686 SetTestingHashSeed(kTestHashSeed); |
| 483 | 687 |
| 688 mock_delegate().ExpectCallsToWaitingMethods(); | |
| 689 mock_delegate().ExpectCallsToGetterMethods(); | |
| 484 EXPECT_CALL(mock_delegate(), ShowPrompt()); | 690 EXPECT_CALL(mock_delegate(), ShowPrompt()); |
| 485 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x01u)); | 691 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x01u)); |
| 486 | 692 |
| 487 UnleashResetterAndWait(); | 693 UnleashResetterAndWait(); |
| 488 | 694 |
| 489 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); | 695 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); |
| 490 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); | 696 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); |
| 491 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); | 697 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); |
| 492 } | 698 } |
| 493 | 699 |
| 494 TEST_F(AutomaticProfileResetterTest, PrefHostedMementoPreventsPrompt) { | 700 TEST_F(AutomaticProfileResetterTest, PrefHostedMementoPreventsPrompt) { |
| 495 PreferenceHostedPromptMemento memento_in_prefs(profile()); | 701 PreferenceHostedPromptMemento memento_in_prefs(profile()); |
| 496 LocalStateHostedPromptMemento memento_in_local_state(profile()); | 702 LocalStateHostedPromptMemento memento_in_local_state(profile()); |
| 497 FileHostedPromptMementoSynchronous memento_in_file(profile()); | 703 FileHostedPromptMementoSynchronous memento_in_file(profile()); |
| 498 | 704 |
| 499 memento_in_prefs.StoreValue(kTestMementoValue); | 705 memento_in_prefs.StoreValue(kTestMementoValue); |
| 500 | 706 |
| 501 SetTestingProgram(ConstructProgram(true, true)); | 707 SetTestingProgram(ConstructProgram(true, true)); |
| 502 SetTestingHashSeed(kTestHashSeed); | 708 SetTestingHashSeed(kTestHashSeed); |
| 503 | 709 |
| 710 mock_delegate().ExpectCallsToWaitingMethods(); | |
| 711 mock_delegate().ExpectCallsToGetterMethods(); | |
| 504 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x03u)); | 712 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x03u)); |
| 505 | 713 |
| 506 UnleashResetterAndWait(); | 714 UnleashResetterAndWait(); |
| 507 | 715 |
| 508 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); | 716 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); |
| 509 EXPECT_EQ("", memento_in_local_state.ReadValue()); | 717 EXPECT_EQ("", memento_in_local_state.ReadValue()); |
| 510 EXPECT_EQ("", memento_in_file.ReadValue()); | 718 EXPECT_EQ("", memento_in_file.ReadValue()); |
| 511 } | 719 } |
| 512 | 720 |
| 513 TEST_F(AutomaticProfileResetterTest, LocalStateHostedMementoPreventsPrompt) { | 721 TEST_F(AutomaticProfileResetterTest, LocalStateHostedMementoPreventsPrompt) { |
| 514 PreferenceHostedPromptMemento memento_in_prefs(profile()); | 722 PreferenceHostedPromptMemento memento_in_prefs(profile()); |
| 515 LocalStateHostedPromptMemento memento_in_local_state(profile()); | 723 LocalStateHostedPromptMemento memento_in_local_state(profile()); |
| 516 FileHostedPromptMementoSynchronous memento_in_file(profile()); | 724 FileHostedPromptMementoSynchronous memento_in_file(profile()); |
| 517 | 725 |
| 518 memento_in_local_state.StoreValue(kTestMementoValue); | 726 memento_in_local_state.StoreValue(kTestMementoValue); |
| 519 | 727 |
| 520 SetTestingProgram(ConstructProgram(true, true)); | 728 SetTestingProgram(ConstructProgram(true, true)); |
| 521 SetTestingHashSeed(kTestHashSeed); | 729 SetTestingHashSeed(kTestHashSeed); |
| 522 | 730 |
| 731 mock_delegate().ExpectCallsToWaitingMethods(); | |
| 732 mock_delegate().ExpectCallsToGetterMethods(); | |
| 523 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x05u)); | 733 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x05u)); |
| 524 | 734 |
| 525 UnleashResetterAndWait(); | 735 UnleashResetterAndWait(); |
| 526 | 736 |
| 527 EXPECT_EQ("", memento_in_prefs.ReadValue()); | 737 EXPECT_EQ("", memento_in_prefs.ReadValue()); |
| 528 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); | 738 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); |
| 529 EXPECT_EQ("", memento_in_file.ReadValue()); | 739 EXPECT_EQ("", memento_in_file.ReadValue()); |
| 530 } | 740 } |
| 531 | 741 |
| 532 TEST_F(AutomaticProfileResetterTest, FileHostedMementoPreventsPrompt) { | 742 TEST_F(AutomaticProfileResetterTest, FileHostedMementoPreventsPrompt) { |
| 533 PreferenceHostedPromptMemento memento_in_prefs(profile()); | 743 PreferenceHostedPromptMemento memento_in_prefs(profile()); |
| 534 LocalStateHostedPromptMemento memento_in_local_state(profile()); | 744 LocalStateHostedPromptMemento memento_in_local_state(profile()); |
| 535 FileHostedPromptMementoSynchronous memento_in_file(profile()); | 745 FileHostedPromptMementoSynchronous memento_in_file(profile()); |
| 536 | 746 |
| 537 memento_in_file.StoreValue(kTestMementoValue); | 747 memento_in_file.StoreValue(kTestMementoValue); |
| 538 | 748 |
| 539 SetTestingProgram(ConstructProgram(true, true)); | 749 SetTestingProgram(ConstructProgram(true, true)); |
| 540 SetTestingHashSeed(kTestHashSeed); | 750 SetTestingHashSeed(kTestHashSeed); |
| 541 | 751 |
| 752 mock_delegate().ExpectCallsToWaitingMethods(); | |
| 753 mock_delegate().ExpectCallsToGetterMethods(); | |
| 542 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x09u)); | 754 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x09u)); |
| 543 | 755 |
| 544 UnleashResetterAndWait(); | 756 UnleashResetterAndWait(); |
| 545 | 757 |
| 546 EXPECT_EQ("", memento_in_prefs.ReadValue()); | 758 EXPECT_EQ("", memento_in_prefs.ReadValue()); |
| 547 EXPECT_EQ("", memento_in_local_state.ReadValue()); | 759 EXPECT_EQ("", memento_in_local_state.ReadValue()); |
| 548 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); | 760 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); |
| 549 } | 761 } |
| 550 | 762 |
| 551 TEST_F(AutomaticProfileResetterTest, DoNothingWhenResourcesAreMissing) { | 763 TEST_F(AutomaticProfileResetterTest, DoNothingWhenResourcesAreMissing) { |
| 552 PreferenceHostedPromptMemento memento_in_prefs(profile()); | 764 PreferenceHostedPromptMemento memento_in_prefs(profile()); |
| 553 LocalStateHostedPromptMemento memento_in_local_state(profile()); | 765 LocalStateHostedPromptMemento memento_in_local_state(profile()); |
| 554 FileHostedPromptMementoSynchronous memento_in_file(profile()); | 766 FileHostedPromptMementoSynchronous memento_in_file(profile()); |
| 555 | 767 |
| 556 SetTestingProgram(""); | 768 SetTestingProgram(""); |
| 557 SetTestingHashSeed(""); | 769 SetTestingHashSeed(""); |
| 558 | 770 |
| 559 // No calls are expected to the delegate. | 771 // No calls are expected to the delegate. |
| 560 | 772 |
| 561 UnleashResetterAndWait(); | 773 UnleashResetterAndWait(); |
| 562 | 774 |
| 563 EXPECT_EQ("", memento_in_prefs.ReadValue()); | 775 EXPECT_EQ("", memento_in_prefs.ReadValue()); |
| 564 EXPECT_EQ("", memento_in_local_state.ReadValue()); | 776 EXPECT_EQ("", memento_in_local_state.ReadValue()); |
| 565 EXPECT_EQ("", memento_in_file.ReadValue()); | 777 EXPECT_EQ("", memento_in_file.ReadValue()); |
| 566 } | 778 } |
| 567 | 779 |
| 780 // Please see comments above ConstructProgramToCheckPreferences() to understand | |
| 781 // how the following tests work. | |
| 782 | |
| 783 TEST_F(AutomaticProfileResetterTest, InputUserPreferencesCorrect) { | |
| 784 SetTestingProgram(ConstructProgramToCheckPreferences()); | |
| 785 SetTestingHashSeed(kTestHashSeed); | |
| 786 | |
| 787 PrefService* prefs = profile()->GetPrefs(); | |
| 788 prefs->SetString(kTestPreferencePath, kTestPreferenceValue); | |
| 789 | |
| 790 mock_delegate().ExpectCallsToWaitingMethods(); | |
| 791 mock_delegate().ExpectCallsToGetterMethods(); | |
| 792 uint32 expected_mask = | |
| 793 HasExpectedUserPreference | UserPreferenceIsUserControlled; | |
| 794 EXPECT_CALL(mock_delegate(), ReportStatistics(0x00u, expected_mask)); | |
| 795 | |
| 796 UnleashResetterAndWait(); | |
| 797 } | |
| 798 | |
| 799 TEST_F(AutomaticProfileResetterTest, InputLocalStateCorrect) { | |
| 800 SetTestingProgram(ConstructProgramToCheckPreferences()); | |
| 801 SetTestingHashSeed(kTestHashSeed); | |
| 802 | |
| 803 PrefService* prefs = local_state(); | |
| 804 prefs->SetString(kTestPreferencePath, kTestPreferenceValue); | |
| 805 | |
| 806 mock_delegate().ExpectCallsToWaitingMethods(); | |
| 807 mock_delegate().ExpectCallsToGetterMethods(); | |
| 808 uint32 expected_mask = | |
| 809 HasExpectedLocalStatePreference | LocalStateIsUserControlled; | |
| 810 EXPECT_CALL(mock_delegate(), ReportStatistics(0x00u, expected_mask)); | |
| 811 | |
| 812 UnleashResetterAndWait(); | |
| 813 } | |
| 814 | |
| 815 TEST_F(AutomaticProfileResetterTest, InputManagedUserPreferencesCorrect) { | |
| 816 SetTestingProgram(ConstructProgramToCheckPreferences()); | |
| 817 SetTestingHashSeed(kTestHashSeed); | |
| 818 | |
| 819 TestingPrefServiceSyncable* prefs = profile()->GetTestingPrefService(); | |
| 820 prefs->SetManagedPref(kTestPreferencePath, | |
| 821 new base::StringValue(kTestPreferenceValue)); | |
| 822 | |
| 823 mock_delegate().ExpectCallsToWaitingMethods(); | |
| 824 mock_delegate().ExpectCallsToGetterMethods(); | |
| 825 uint32 expected_mask = HasExpectedUserPreference; | |
| 826 EXPECT_CALL(mock_delegate(), ReportStatistics(0x00u, expected_mask)); | |
| 827 | |
| 828 UnleashResetterAndWait(); | |
| 829 } | |
| 830 | |
| 831 TEST_F(AutomaticProfileResetterTest, InputManagedLocalStateCorrect) { | |
| 832 SetTestingProgram(ConstructProgramToCheckPreferences()); | |
| 833 SetTestingHashSeed(kTestHashSeed); | |
| 834 | |
| 835 TestingPrefServiceSimple* prefs = local_state(); | |
| 836 prefs->SetManagedPref(kTestPreferencePath, | |
| 837 new base::StringValue(kTestPreferenceValue)); | |
| 838 | |
| 839 mock_delegate().ExpectCallsToWaitingMethods(); | |
| 840 mock_delegate().ExpectCallsToGetterMethods(); | |
| 841 uint32 expected_mask = HasExpectedLocalStatePreference; | |
| 842 EXPECT_CALL(mock_delegate(), ReportStatistics(0x00u, expected_mask)); | |
| 843 | |
| 844 UnleashResetterAndWait(); | |
| 845 } | |
| 846 | |
| 847 // Please see comments above ConstructProgramToCheckSearchEngines() to | |
| 848 // understand how the following tests work. | |
| 849 | |
| 850 TEST_F(AutomaticProfileResetterTest, InputDefaultSearchProviderCorrect) { | |
| 851 SetTestingProgram(ConstructProgramToCheckSearchEngines()); | |
| 852 SetTestingHashSeed(kTestHashSeed); | |
| 853 | |
| 854 mock_delegate().emulated_default_search_provider_details().SetString( | |
| 855 kSearchURLAttributeKey, kTestSearchURL); | |
| 856 | |
| 857 mock_delegate().ExpectCallsToWaitingMethods(); | |
| 858 mock_delegate().ExpectCallsToGetterMethods(); | |
| 859 uint32 expected_mask = | |
| 860 HasExpectedDefaultSearchProvider | DefaultSearchProviderIsUserControlled; | |
| 861 EXPECT_CALL(mock_delegate(), ReportStatistics(0x00u, expected_mask)); | |
| 862 | |
| 863 UnleashResetterAndWait(); | |
| 864 } | |
| 865 | |
| 866 TEST_F(AutomaticProfileResetterTest, InputSearchProviderManagedCorrect) { | |
| 867 SetTestingProgram(ConstructProgramToCheckSearchEngines()); | |
| 868 SetTestingHashSeed(kTestHashSeed); | |
| 869 | |
| 870 mock_delegate().emulated_default_search_provider_details().SetString( | |
| 871 kSearchURLAttributeKey, kTestSearchURL); | |
| 872 mock_delegate().set_emulated_default_search_provider_is_managed(true); | |
| 873 | |
| 874 mock_delegate().ExpectCallsToWaitingMethods(); | |
| 875 mock_delegate().ExpectCallsToGetterMethods(); | |
| 876 uint32 expected_mask = HasExpectedDefaultSearchProvider; | |
| 877 EXPECT_CALL(mock_delegate(), ReportStatistics(0x00u, expected_mask)); | |
| 878 | |
| 879 UnleashResetterAndWait(); | |
| 880 } | |
| 881 | |
| 882 TEST_F(AutomaticProfileResetterTest, InputSearchProvidersCorrect) { | |
| 883 SetTestingProgram(ConstructProgramToCheckSearchEngines()); | |
| 884 SetTestingHashSeed(kTestHashSeed); | |
| 885 | |
| 886 base::DictionaryValue* search_provider_1 = new base::DictionaryValue; | |
| 887 base::DictionaryValue* search_provider_2 = new base::DictionaryValue; | |
| 888 search_provider_1->SetString(kSearchURLAttributeKey, kTestSearchURL); | |
| 889 search_provider_2->SetString(kSearchURLAttributeKey, kTestSearchURL2); | |
| 890 mock_delegate().emulated_search_providers_details().Append(search_provider_1); | |
| 891 mock_delegate().emulated_search_providers_details().Append(search_provider_2); | |
| 892 | |
| 893 mock_delegate().ExpectCallsToWaitingMethods(); | |
| 894 mock_delegate().ExpectCallsToGetterMethods(); | |
| 895 uint32 expected_mask = DefaultSearchProviderIsUserControlled | | |
| 896 HasExpectedPrepopulatedSearchProvider1 | | |
| 897 HasExpectedPrepopulatedSearchProvider2; | |
| 898 EXPECT_CALL(mock_delegate(), ReportStatistics(0x00u, expected_mask)); | |
| 899 | |
| 900 UnleashResetterAndWait(); | |
| 901 } | |
| 902 | |
| 568 } // namespace | 903 } // namespace |
| OLD | NEW |