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 "chrome/browser/profile_resetter/automatic_profile_resetter.h" | 5 #include "chrome/browser/profile_resetter/automatic_profile_resetter.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "chrome/test/base/testing_pref_service_syncable.h" | 25 #include "chrome/test/base/testing_pref_service_syncable.h" |
26 #include "chrome/test/base/testing_profile.h" | 26 #include "chrome/test/base/testing_profile.h" |
27 #include "components/user_prefs/pref_registry_syncable.h" | 27 #include "components/user_prefs/pref_registry_syncable.h" |
28 #include "components/variations/variations_associated_data.h" | 28 #include "components/variations/variations_associated_data.h" |
29 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
30 #include "content/public/test/test_browser_thread_bundle.h" | 30 #include "content/public/test/test_browser_thread_bundle.h" |
31 #include "testing/gmock/include/gmock/gmock.h" | 31 #include "testing/gmock/include/gmock/gmock.h" |
32 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
33 | 33 |
34 using testing::_; | 34 using testing::_; |
35 using testing::Invoke; | |
36 | 35 |
37 namespace { | 36 namespace { |
38 | 37 |
39 const char kAutomaticProfileResetStudyName[] = "AutomaticProfileReset"; | 38 const char kAutomaticProfileResetStudyName[] = "AutomaticProfileReset"; |
40 const char kStudyDisabledGroupName[] = "Disabled"; | 39 const char kStudyDisabledGroupName[] = "Disabled"; |
41 const char kStudyDryRunGroupName[] = "DryRun"; | 40 const char kStudyDryRunGroupName[] = "DryRun"; |
42 const char kStudyEnabledGroupName[] = "Enabled"; | 41 const char kStudyEnabledGroupName[] = "Enabled"; |
43 | 42 |
44 const char kTestHashSeed[] = "testing-hash-seed"; | 43 const char kTestHashSeed[] = "testing-hash-seed"; |
45 const char kTestMementoValue[] = "01234567890123456789012345678901"; | 44 const char kTestMementoValue[] = "01234567890123456789012345678901"; |
(...skipping 13 matching lines...) Expand all Loading... |
59 | 58 |
60 // A testing version of the AutomaticProfileResetter that differs from the real | 59 // A testing version of the AutomaticProfileResetter that differs from the real |
61 // one only in that it has its statistics reporting mocked out for verification. | 60 // one only in that it has its statistics reporting mocked out for verification. |
62 class AutomaticProfileResetterUnderTest : public AutomaticProfileResetter { | 61 class AutomaticProfileResetterUnderTest : public AutomaticProfileResetter { |
63 public: | 62 public: |
64 explicit AutomaticProfileResetterUnderTest(Profile* profile) | 63 explicit AutomaticProfileResetterUnderTest(Profile* profile) |
65 : AutomaticProfileResetter(profile) {} | 64 : AutomaticProfileResetter(profile) {} |
66 virtual ~AutomaticProfileResetterUnderTest() {} | 65 virtual ~AutomaticProfileResetterUnderTest() {} |
67 | 66 |
68 MOCK_METHOD2(ReportStatistics, void(uint32, uint32)); | 67 MOCK_METHOD2(ReportStatistics, void(uint32, uint32)); |
| 68 MOCK_METHOD1(ReportPromptResult, |
| 69 void(AutomaticProfileResetter::PromptResult)); |
69 | 70 |
70 private: | 71 private: |
71 DISALLOW_COPY_AND_ASSIGN(AutomaticProfileResetterUnderTest); | 72 DISALLOW_COPY_AND_ASSIGN(AutomaticProfileResetterUnderTest); |
72 }; | 73 }; |
73 | 74 |
74 class MockProfileResetterDelegate : public AutomaticProfileResetterDelegate { | 75 class MockProfileResetterDelegate : public AutomaticProfileResetterDelegate { |
75 public: | 76 public: |
76 MockProfileResetterDelegate() | 77 MockProfileResetterDelegate() |
77 : emulated_default_search_provider_is_managed_(false) {} | 78 : emulated_is_default_search_provider_managed_(false) {} |
78 virtual ~MockProfileResetterDelegate() {} | 79 virtual ~MockProfileResetterDelegate() {} |
79 | 80 |
80 MOCK_METHOD0(EnumerateLoadedModulesIfNeeded, void()); | 81 MOCK_METHOD0(EnumerateLoadedModulesIfNeeded, void()); |
81 MOCK_CONST_METHOD1(RequestCallbackWhenLoadedModulesAreEnumerated, | 82 MOCK_CONST_METHOD1(RequestCallbackWhenLoadedModulesAreEnumerated, |
82 void(const base::Closure&)); | 83 void(const base::Closure&)); |
83 | 84 |
84 MOCK_METHOD0(LoadTemplateURLServiceIfNeeded, void()); | 85 MOCK_METHOD0(LoadTemplateURLServiceIfNeeded, void()); |
85 MOCK_CONST_METHOD1(RequestCallbackWhenTemplateURLServiceIsLoaded, | 86 MOCK_CONST_METHOD1(RequestCallbackWhenTemplateURLServiceIsLoaded, |
86 void(const base::Closure&)); | 87 void(const base::Closure&)); |
87 | 88 |
| 89 MOCK_METHOD0(FetchBrandcodedDefaultSettingsIfNeeded, void()); |
| 90 MOCK_CONST_METHOD1(RequestCallbackWhenBrandcodedDefaultsAreFetched, |
| 91 void(const base::Closure&)); |
| 92 |
88 MOCK_CONST_METHOD0(OnGetLoadedModuleNameDigestsCalled, void()); | 93 MOCK_CONST_METHOD0(OnGetLoadedModuleNameDigestsCalled, void()); |
89 MOCK_CONST_METHOD0(OnGetDefaultSearchProviderDetailsCalled, void()); | 94 MOCK_CONST_METHOD0(OnGetDefaultSearchProviderDetailsCalled, void()); |
90 MOCK_CONST_METHOD0(OnIsDefaultSearchProviderManagedCalled, void()); | 95 MOCK_CONST_METHOD0(OnIsDefaultSearchProviderManagedCalled, void()); |
91 MOCK_CONST_METHOD0(OnGetPrepopulatedSearchProvidersDetailsCalled, void()); | 96 MOCK_CONST_METHOD0(OnGetPrepopulatedSearchProvidersDetailsCalled, void()); |
92 | 97 |
93 MOCK_METHOD0(ShowPrompt, void()); | 98 MOCK_METHOD0(TriggerPrompt, bool()); |
| 99 MOCK_METHOD2(TriggerProfileSettingsReset, void(bool, const base::Closure&)); |
| 100 MOCK_METHOD0(DismissPrompt, void()); |
94 | 101 |
95 virtual scoped_ptr<base::ListValue> | 102 virtual scoped_ptr<base::ListValue> |
96 GetLoadedModuleNameDigests() const OVERRIDE { | 103 GetLoadedModuleNameDigests() const OVERRIDE { |
97 OnGetLoadedModuleNameDigestsCalled(); | 104 OnGetLoadedModuleNameDigestsCalled(); |
98 return scoped_ptr<base::ListValue>( | 105 return scoped_ptr<base::ListValue>( |
99 emulated_loaded_module_digests_.DeepCopy()); | 106 emulated_loaded_module_digests_.DeepCopy()); |
100 } | 107 } |
101 | 108 |
102 virtual scoped_ptr<base::DictionaryValue> | 109 virtual scoped_ptr<base::DictionaryValue> |
103 GetDefaultSearchProviderDetails() const OVERRIDE { | 110 GetDefaultSearchProviderDetails() const OVERRIDE { |
104 OnGetDefaultSearchProviderDetailsCalled(); | 111 OnGetDefaultSearchProviderDetailsCalled(); |
105 return scoped_ptr<base::DictionaryValue>( | 112 return scoped_ptr<base::DictionaryValue>( |
106 emulated_default_search_provider_details_.DeepCopy()); | 113 emulated_default_search_provider_details_.DeepCopy()); |
107 } | 114 } |
108 | 115 |
109 virtual bool IsDefaultSearchProviderManaged() const OVERRIDE { | 116 virtual bool IsDefaultSearchProviderManaged() const OVERRIDE { |
110 OnIsDefaultSearchProviderManagedCalled(); | 117 OnIsDefaultSearchProviderManagedCalled(); |
111 return emulated_default_search_provider_is_managed_; | 118 return emulated_is_default_search_provider_managed_; |
112 } | 119 } |
113 | 120 |
114 virtual scoped_ptr<base::ListValue> | 121 virtual scoped_ptr<base::ListValue> |
115 GetPrepopulatedSearchProvidersDetails() const OVERRIDE { | 122 GetPrepopulatedSearchProvidersDetails() const OVERRIDE { |
116 OnGetPrepopulatedSearchProvidersDetailsCalled(); | 123 OnGetPrepopulatedSearchProvidersDetailsCalled(); |
117 return scoped_ptr<base::ListValue>( | 124 return scoped_ptr<base::ListValue>( |
118 emulated_search_providers_details_.DeepCopy()); | 125 emulated_search_providers_details_.DeepCopy()); |
119 } | 126 } |
120 | 127 |
121 static void ClosureInvoker(const base::Closure& closure) { closure.Run(); } | 128 static void ClosureInvoker(const base::Closure& closure) { closure.Run(); } |
122 | 129 |
123 void ExpectCallsToDependenciesSetUpMethods() { | 130 void ExpectCallsToDependenciesSetUpMethods() { |
124 EXPECT_CALL(*this, EnumerateLoadedModulesIfNeeded()); | 131 EXPECT_CALL(*this, EnumerateLoadedModulesIfNeeded()); |
125 EXPECT_CALL(*this, LoadTemplateURLServiceIfNeeded()); | 132 EXPECT_CALL(*this, LoadTemplateURLServiceIfNeeded()); |
126 EXPECT_CALL(*this, RequestCallbackWhenLoadedModulesAreEnumerated(_)) | 133 EXPECT_CALL(*this, RequestCallbackWhenLoadedModulesAreEnumerated(_)) |
127 .WillOnce(Invoke(ClosureInvoker)); | 134 .WillOnce(testing::Invoke(ClosureInvoker)); |
128 EXPECT_CALL(*this, RequestCallbackWhenTemplateURLServiceIsLoaded(_)) | 135 EXPECT_CALL(*this, RequestCallbackWhenTemplateURLServiceIsLoaded(_)) |
129 .WillOnce(Invoke(ClosureInvoker)); | 136 .WillOnce(testing::Invoke(ClosureInvoker)); |
130 } | 137 } |
131 | 138 |
132 void ExpectCallsToGetterMethods() { | 139 void ExpectCallsToGetterMethods() { |
133 EXPECT_CALL(*this, OnGetLoadedModuleNameDigestsCalled()); | 140 EXPECT_CALL(*this, OnGetLoadedModuleNameDigestsCalled()); |
134 EXPECT_CALL(*this, OnGetDefaultSearchProviderDetailsCalled()); | 141 EXPECT_CALL(*this, OnGetDefaultSearchProviderDetailsCalled()); |
135 EXPECT_CALL(*this, OnIsDefaultSearchProviderManagedCalled()); | 142 EXPECT_CALL(*this, OnIsDefaultSearchProviderManagedCalled()); |
136 EXPECT_CALL(*this, OnGetPrepopulatedSearchProvidersDetailsCalled()); | 143 EXPECT_CALL(*this, OnGetPrepopulatedSearchProvidersDetailsCalled()); |
137 } | 144 } |
138 | 145 |
| 146 void ExpectCallToShowPrompt() { |
| 147 EXPECT_CALL(*this, TriggerPrompt()).WillOnce(testing::Return(true)); |
| 148 EXPECT_CALL(*this, FetchBrandcodedDefaultSettingsIfNeeded()); |
| 149 } |
| 150 |
| 151 void ExpectCallToTriggerReset(bool send_feedback) { |
| 152 EXPECT_CALL(*this, TriggerProfileSettingsReset(send_feedback, _)) |
| 153 .WillOnce(testing::SaveArg<1>(&reset_completion_)); |
| 154 } |
| 155 |
139 base::DictionaryValue& emulated_default_search_provider_details() { | 156 base::DictionaryValue& emulated_default_search_provider_details() { |
140 return emulated_default_search_provider_details_; | 157 return emulated_default_search_provider_details_; |
141 } | 158 } |
142 | 159 |
143 base::ListValue& emulated_search_providers_details() { | 160 base::ListValue& emulated_search_providers_details() { |
144 return emulated_search_providers_details_; | 161 return emulated_search_providers_details_; |
145 } | 162 } |
146 | 163 |
147 base::ListValue& emulated_loaded_module_digests() { | 164 base::ListValue& emulated_loaded_module_digests() { |
148 return emulated_loaded_module_digests_; | 165 return emulated_loaded_module_digests_; |
149 } | 166 } |
150 | 167 |
151 void set_emulated_default_search_provider_is_managed(bool value) { | 168 void set_emulated_is_default_search_provider_managed(bool value) { |
152 emulated_default_search_provider_is_managed_ = value; | 169 emulated_is_default_search_provider_managed_ = value; |
| 170 } |
| 171 |
| 172 void EmulateProfileResetCompleted() { |
| 173 reset_completion_.Run(); |
153 } | 174 } |
154 | 175 |
155 private: | 176 private: |
156 base::DictionaryValue emulated_default_search_provider_details_; | 177 base::DictionaryValue emulated_default_search_provider_details_; |
157 base::ListValue emulated_search_providers_details_; | 178 base::ListValue emulated_search_providers_details_; |
158 base::ListValue emulated_loaded_module_digests_; | 179 base::ListValue emulated_loaded_module_digests_; |
159 bool emulated_default_search_provider_is_managed_; | 180 bool emulated_is_default_search_provider_managed_; |
| 181 base::Closure reset_completion_; |
160 | 182 |
161 DISALLOW_COPY_AND_ASSIGN(MockProfileResetterDelegate); | 183 DISALLOW_COPY_AND_ASSIGN(MockProfileResetterDelegate); |
162 }; | 184 }; |
163 | 185 |
164 class FileHostedPromptMementoSynchronous : protected FileHostedPromptMemento { | 186 class FileHostedPromptMementoSynchronous : protected FileHostedPromptMemento { |
165 public: | 187 public: |
166 explicit FileHostedPromptMementoSynchronous(Profile* profile) | 188 explicit FileHostedPromptMementoSynchronous(Profile* profile) |
167 : FileHostedPromptMemento(profile) {} | 189 : FileHostedPromptMemento(profile) {} |
168 | 190 |
169 std::string ReadValue() const { | 191 std::string ReadValue() const { |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 | 422 |
401 // Test fixtures ------------------------------------------------------------- | 423 // Test fixtures ------------------------------------------------------------- |
402 | 424 |
403 class AutomaticProfileResetterTestBase : public testing::Test { | 425 class AutomaticProfileResetterTestBase : public testing::Test { |
404 protected: | 426 protected: |
405 explicit AutomaticProfileResetterTestBase( | 427 explicit AutomaticProfileResetterTestBase( |
406 const std::string& experiment_group_name) | 428 const std::string& experiment_group_name) |
407 : waiting_task_runner_(new base::TestSimpleTaskRunner), | 429 : waiting_task_runner_(new base::TestSimpleTaskRunner), |
408 local_state_(TestingBrowserProcess::GetGlobal()), | 430 local_state_(TestingBrowserProcess::GetGlobal()), |
409 profile_(new TestingProfile()), | 431 profile_(new TestingProfile()), |
| 432 field_trials_(new base::FieldTrialList(NULL)), |
| 433 memento_in_prefs_(new PreferenceHostedPromptMemento(profile())), |
| 434 memento_in_local_state_(new LocalStateHostedPromptMemento(profile())), |
| 435 memento_in_file_(new FileHostedPromptMementoSynchronous(profile())), |
410 experiment_group_name_(experiment_group_name), | 436 experiment_group_name_(experiment_group_name), |
411 inject_data_through_variation_params_(false), | 437 inject_data_through_variation_params_(false), |
412 mock_delegate_(NULL) { | 438 mock_delegate_(NULL) { |
413 // Make sure the factory is not optimized away, so whatever preferences it | 439 // Make sure the factory is not optimized away, so whatever preferences it |
414 // wants to register will actually get registered. | 440 // wants to register will actually get registered. |
415 AutomaticProfileResetterFactory::GetInstance(); | 441 AutomaticProfileResetterFactory::GetInstance(); |
416 | 442 |
417 // Register some additional local state preferences for testing purposes. | 443 // Register some additional local state preferences for testing purposes. |
418 PrefRegistrySimple* local_state_registry = local_state_.Get()->registry(); | 444 PrefRegistrySimple* local_state_registry = local_state_.Get()->registry(); |
419 DCHECK(local_state_registry); | 445 DCHECK(local_state_registry); |
420 local_state_registry->RegisterStringPref(kTestPreferencePath, ""); | 446 local_state_registry->RegisterStringPref(kTestPreferencePath, ""); |
421 | 447 |
422 // Register some additional user preferences for testing purposes. | 448 // Register some additional user preferences for testing purposes. |
423 user_prefs::PrefRegistrySyncable* user_prefs_registry = | 449 user_prefs::PrefRegistrySyncable* user_prefs_registry = |
424 profile_->GetTestingPrefService()->registry(); | 450 profile_->GetTestingPrefService()->registry(); |
425 DCHECK(user_prefs_registry); | 451 DCHECK(user_prefs_registry); |
426 user_prefs_registry->RegisterStringPref( | 452 user_prefs_registry->RegisterStringPref( |
427 kTestPreferencePath, | 453 kTestPreferencePath, std::string(), |
428 "", | |
429 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 454 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
430 } | 455 } |
431 | 456 |
432 virtual void SetUp() OVERRIDE { | 457 virtual void SetUp() OVERRIDE { |
433 field_trials_.reset(new base::FieldTrialList(NULL)); | |
434 chrome_variations::testing::ClearAllVariationParams(); | 458 chrome_variations::testing::ClearAllVariationParams(); |
435 base::FieldTrialList::CreateFieldTrial(kAutomaticProfileResetStudyName, | 459 base::FieldTrialList::CreateFieldTrial(kAutomaticProfileResetStudyName, |
436 experiment_group_name_); | 460 experiment_group_name_); |
437 resetter_.reset( | 461 resetter_.reset( |
438 new testing::StrictMock<AutomaticProfileResetterUnderTest>(profile())); | 462 new testing::StrictMock<AutomaticProfileResetterUnderTest>(profile())); |
439 mock_delegate_owned_.reset( | 463 mock_delegate_owned_.reset( |
440 new testing::StrictMock<MockProfileResetterDelegate>()); | 464 new testing::StrictMock<MockProfileResetterDelegate>()); |
441 mock_delegate_ = mock_delegate_owned_.get(); | 465 mock_delegate_ = mock_delegate_owned_.get(); |
| 466 |
| 467 ExpectAllMementoValuesEqualTo(std::string()); |
442 } | 468 } |
443 | 469 |
444 void SetTestingHashSeed(const std::string& hash_seed) { | 470 void SetTestingHashSeed(const std::string& hash_seed) { |
445 testing_hash_seed_ = hash_seed; | 471 testing_hash_seed_ = hash_seed; |
446 } | 472 } |
447 | 473 |
448 void SetTestingProgram(const std::string& source_code) { | 474 void SetTestingProgram(const std::string& source_code) { |
449 testing_program_ = source_code; | 475 testing_program_ = source_code; |
450 } | 476 } |
451 | 477 |
452 void AllowInjectingTestDataThroughVariationParams(bool value) { | 478 void AllowInjectingTestDataThroughVariationParams(bool value) { |
453 inject_data_through_variation_params_ = value; | 479 inject_data_through_variation_params_ = value; |
454 } | 480 } |
455 | 481 |
| 482 void ExpectAllMementoValuesEqualTo(const std::string& value) { |
| 483 EXPECT_EQ(value, memento_in_prefs_->ReadValue()); |
| 484 EXPECT_EQ(value, memento_in_local_state_->ReadValue()); |
| 485 EXPECT_EQ(value, memento_in_file_->ReadValue()); |
| 486 } |
| 487 |
456 void UnleashResetterAndWait() { | 488 void UnleashResetterAndWait() { |
457 if (inject_data_through_variation_params_) { | 489 if (inject_data_through_variation_params_) { |
458 std::map<std::string, std::string> variation_params; | 490 std::map<std::string, std::string> variation_params; |
459 variation_params["program"] = testing_program_; | 491 variation_params["program"] = testing_program_; |
460 variation_params["hash_seed"] = testing_hash_seed_; | 492 variation_params["hash_seed"] = testing_hash_seed_; |
461 ASSERT_TRUE(chrome_variations::AssociateVariationParams( | 493 ASSERT_TRUE(chrome_variations::AssociateVariationParams( |
462 kAutomaticProfileResetStudyName, | 494 kAutomaticProfileResetStudyName, |
463 experiment_group_name_, | 495 experiment_group_name_, |
464 variation_params)); | 496 variation_params)); |
465 } | 497 } |
(...skipping 10 matching lines...) Expand all Loading... |
476 if (waiting_task_runner_->HasPendingTask()) { | 508 if (waiting_task_runner_->HasPendingTask()) { |
477 ASSERT_EQ(base::TimeDelta::FromSeconds(55), | 509 ASSERT_EQ(base::TimeDelta::FromSeconds(55), |
478 waiting_task_runner_->NextPendingTaskDelay()); | 510 waiting_task_runner_->NextPendingTaskDelay()); |
479 waiting_task_runner_->RunPendingTasks(); | 511 waiting_task_runner_->RunPendingTasks(); |
480 } | 512 } |
481 base::RunLoop().RunUntilIdle(); | 513 base::RunLoop().RunUntilIdle(); |
482 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 514 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
483 base::RunLoop().RunUntilIdle(); | 515 base::RunLoop().RunUntilIdle(); |
484 } | 516 } |
485 | 517 |
| 518 // Goes through an evaluation flow such that the reset criteria are satisfied. |
| 519 // Used to reduce boilerplate for tests that need to verify behavior during |
| 520 // the reset prompt flow. |
| 521 void OrchestrateThroughEvaluationFlow() { |
| 522 SetTestingProgram(ConstructProgram(true, true)); |
| 523 SetTestingHashSeed(kTestHashSeed); |
| 524 |
| 525 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); |
| 526 mock_delegate().ExpectCallsToGetterMethods(); |
| 527 mock_delegate().ExpectCallToShowPrompt(); |
| 528 EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x01u)); |
| 529 |
| 530 UnleashResetterAndWait(); |
| 531 |
| 532 testing::Mock::VerifyAndClearExpectations(&resetter()); |
| 533 testing::Mock::VerifyAndClearExpectations(&mock_delegate()); |
| 534 } |
| 535 |
| 536 // Explicitly shut down the service to double-check that nothing explodes, but |
| 537 // first, verify expectations to make sure the service makes no more calls to |
| 538 // any mocked functions during or after shutdown. |
| 539 void VerifyExpectationsThenShutdownResetter() { |
| 540 testing::Mock::VerifyAndClearExpectations(&resetter()); |
| 541 testing::Mock::VerifyAndClearExpectations(&mock_delegate()); |
| 542 |
| 543 resetter_->Shutdown(); |
| 544 resetter_.reset(); |
| 545 } |
| 546 |
486 TestingProfile* profile() { return profile_.get(); } | 547 TestingProfile* profile() { return profile_.get(); } |
487 TestingPrefServiceSimple* local_state() { return local_state_.Get(); } | 548 TestingPrefServiceSimple* local_state() { return local_state_.Get(); } |
488 | 549 |
| 550 PreferenceHostedPromptMemento& memento_in_prefs() { |
| 551 return *memento_in_prefs_; |
| 552 } |
| 553 |
| 554 LocalStateHostedPromptMemento& memento_in_local_state() { |
| 555 return *memento_in_local_state_; |
| 556 } |
| 557 |
| 558 FileHostedPromptMementoSynchronous& memento_in_file() { |
| 559 return *memento_in_file_; |
| 560 } |
| 561 |
489 MockProfileResetterDelegate& mock_delegate() { return *mock_delegate_; } | 562 MockProfileResetterDelegate& mock_delegate() { return *mock_delegate_; } |
490 AutomaticProfileResetterUnderTest& resetter() { return *resetter_; } | 563 AutomaticProfileResetterUnderTest& resetter() { return *resetter_; } |
491 | 564 |
492 private: | 565 private: |
493 content::TestBrowserThreadBundle thread_bundle_; | 566 content::TestBrowserThreadBundle thread_bundle_; |
494 scoped_refptr<base::TestSimpleTaskRunner> waiting_task_runner_; | 567 scoped_refptr<base::TestSimpleTaskRunner> waiting_task_runner_; |
495 ScopedTestingLocalState local_state_; | 568 ScopedTestingLocalState local_state_; |
496 scoped_ptr<TestingProfile> profile_; | 569 scoped_ptr<TestingProfile> profile_; |
497 scoped_ptr<base::FieldTrialList> field_trials_; | 570 scoped_ptr<base::FieldTrialList> field_trials_; |
| 571 scoped_ptr<PreferenceHostedPromptMemento> memento_in_prefs_; |
| 572 scoped_ptr<LocalStateHostedPromptMemento> memento_in_local_state_; |
| 573 scoped_ptr<FileHostedPromptMementoSynchronous> memento_in_file_; |
| 574 |
498 std::string experiment_group_name_; | 575 std::string experiment_group_name_; |
499 std::string testing_program_; | 576 std::string testing_program_; |
500 std::string testing_hash_seed_; | 577 std::string testing_hash_seed_; |
501 bool inject_data_through_variation_params_; | 578 bool inject_data_through_variation_params_; |
502 | 579 |
503 scoped_ptr<AutomaticProfileResetterUnderTest> resetter_; | 580 scoped_ptr<AutomaticProfileResetterUnderTest> resetter_; |
504 scoped_ptr<MockProfileResetterDelegate> mock_delegate_owned_; | 581 scoped_ptr<MockProfileResetterDelegate> mock_delegate_owned_; |
505 MockProfileResetterDelegate* mock_delegate_; | 582 MockProfileResetterDelegate* mock_delegate_; |
506 | 583 |
507 DISALLOW_COPY_AND_ASSIGN(AutomaticProfileResetterTestBase); | 584 DISALLOW_COPY_AND_ASSIGN(AutomaticProfileResetterTestBase); |
(...skipping 15 matching lines...) Expand all Loading... |
523 class AutomaticProfileResetterTestDisabled | 600 class AutomaticProfileResetterTestDisabled |
524 : public AutomaticProfileResetterTestBase { | 601 : public AutomaticProfileResetterTestBase { |
525 protected: | 602 protected: |
526 AutomaticProfileResetterTestDisabled() | 603 AutomaticProfileResetterTestDisabled() |
527 : AutomaticProfileResetterTestBase(kStudyDisabledGroupName) {} | 604 : AutomaticProfileResetterTestBase(kStudyDisabledGroupName) {} |
528 }; | 605 }; |
529 | 606 |
530 // Tests --------------------------------------------------------------------- | 607 // Tests --------------------------------------------------------------------- |
531 | 608 |
532 TEST_F(AutomaticProfileResetterTestDisabled, NothingIsDoneWhenDisabled) { | 609 TEST_F(AutomaticProfileResetterTestDisabled, NothingIsDoneWhenDisabled) { |
533 PreferenceHostedPromptMemento memento_in_prefs(profile()); | |
534 LocalStateHostedPromptMemento memento_in_local_state(profile()); | |
535 FileHostedPromptMementoSynchronous memento_in_file(profile()); | |
536 | |
537 EXPECT_EQ("", memento_in_prefs.ReadValue()); | |
538 EXPECT_EQ("", memento_in_local_state.ReadValue()); | |
539 EXPECT_EQ("", memento_in_file.ReadValue()); | |
540 | |
541 SetTestingProgram(ConstructProgram(true, true)); | 610 SetTestingProgram(ConstructProgram(true, true)); |
542 SetTestingHashSeed(kTestHashSeed); | 611 SetTestingHashSeed(kTestHashSeed); |
543 | 612 |
544 // No calls are expected to the delegate. | 613 // No calls are expected to the delegate. |
545 | 614 |
546 UnleashResetterAndWait(); | 615 UnleashResetterAndWait(); |
| 616 VerifyExpectationsThenShutdownResetter(); |
547 | 617 |
548 EXPECT_EQ("", memento_in_prefs.ReadValue()); | 618 ExpectAllMementoValuesEqualTo(std::string()); |
549 EXPECT_EQ("", memento_in_local_state.ReadValue()); | |
550 EXPECT_EQ("", memento_in_file.ReadValue()); | |
551 } | 619 } |
552 | 620 |
553 TEST_F(AutomaticProfileResetterTestDryRun, ConditionsNotSatisfied) { | 621 TEST_F(AutomaticProfileResetterTestDryRun, ConditionsNotSatisfied) { |
554 PreferenceHostedPromptMemento memento_in_prefs(profile()); | |
555 LocalStateHostedPromptMemento memento_in_local_state(profile()); | |
556 FileHostedPromptMementoSynchronous memento_in_file(profile()); | |
557 | |
558 EXPECT_EQ("", memento_in_prefs.ReadValue()); | |
559 EXPECT_EQ("", memento_in_local_state.ReadValue()); | |
560 EXPECT_EQ("", memento_in_file.ReadValue()); | |
561 | |
562 SetTestingProgram(ConstructProgram(false, false)); | 622 SetTestingProgram(ConstructProgram(false, false)); |
563 SetTestingHashSeed(kTestHashSeed); | 623 SetTestingHashSeed(kTestHashSeed); |
564 | 624 |
565 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); | 625 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); |
566 mock_delegate().ExpectCallsToGetterMethods(); | 626 mock_delegate().ExpectCallsToGetterMethods(); |
567 EXPECT_CALL(resetter(), ReportStatistics(0x00u, 0x00u)); | 627 EXPECT_CALL(resetter(), ReportStatistics(0x00u, 0x00u)); |
568 | 628 |
569 UnleashResetterAndWait(); | 629 UnleashResetterAndWait(); |
| 630 VerifyExpectationsThenShutdownResetter(); |
570 | 631 |
571 EXPECT_EQ("", memento_in_prefs.ReadValue()); | 632 ExpectAllMementoValuesEqualTo(std::string()); |
572 EXPECT_EQ("", memento_in_local_state.ReadValue()); | |
573 EXPECT_EQ("", memento_in_file.ReadValue()); | |
574 } | 633 } |
575 | 634 |
576 TEST_F(AutomaticProfileResetterTestDryRun, OneConditionSatisfied) { | 635 TEST_F(AutomaticProfileResetterTestDryRun, OneConditionSatisfied) { |
577 PreferenceHostedPromptMemento memento_in_prefs(profile()); | |
578 LocalStateHostedPromptMemento memento_in_local_state(profile()); | |
579 FileHostedPromptMementoSynchronous memento_in_file(profile()); | |
580 | |
581 EXPECT_EQ("", memento_in_prefs.ReadValue()); | |
582 EXPECT_EQ("", memento_in_local_state.ReadValue()); | |
583 EXPECT_EQ("", memento_in_file.ReadValue()); | |
584 | |
585 SetTestingProgram(ConstructProgram(true, false)); | 636 SetTestingProgram(ConstructProgram(true, false)); |
586 SetTestingHashSeed(kTestHashSeed); | 637 SetTestingHashSeed(kTestHashSeed); |
587 | 638 |
588 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); | 639 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); |
589 mock_delegate().ExpectCallsToGetterMethods(); | 640 mock_delegate().ExpectCallsToGetterMethods(); |
590 EXPECT_CALL(resetter(), ReportStatistics(0x01u, 0x01u)); | 641 EXPECT_CALL(resetter(), ReportStatistics(0x01u, 0x01u)); |
| 642 EXPECT_CALL(resetter(), ReportPromptResult( |
| 643 AutomaticProfileResetter::PROMPT_NOT_TRIGGERED)); |
591 | 644 |
592 UnleashResetterAndWait(); | 645 UnleashResetterAndWait(); |
593 | 646 |
594 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); | 647 ExpectAllMementoValuesEqualTo(kTestMementoValue); |
595 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); | 648 VerifyExpectationsThenShutdownResetter(); |
596 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); | |
597 } | 649 } |
598 | 650 |
599 TEST_F(AutomaticProfileResetterTestDryRun, OtherConditionSatisfied) { | 651 TEST_F(AutomaticProfileResetterTestDryRun, OtherConditionSatisfied) { |
600 PreferenceHostedPromptMemento memento_in_prefs(profile()); | |
601 LocalStateHostedPromptMemento memento_in_local_state(profile()); | |
602 FileHostedPromptMementoSynchronous memento_in_file(profile()); | |
603 | |
604 EXPECT_EQ("", memento_in_prefs.ReadValue()); | |
605 EXPECT_EQ("", memento_in_local_state.ReadValue()); | |
606 EXPECT_EQ("", memento_in_file.ReadValue()); | |
607 | |
608 SetTestingProgram(ConstructProgram(false, true)); | 652 SetTestingProgram(ConstructProgram(false, true)); |
609 SetTestingHashSeed(kTestHashSeed); | 653 SetTestingHashSeed(kTestHashSeed); |
610 | 654 |
611 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); | 655 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); |
612 mock_delegate().ExpectCallsToGetterMethods(); | 656 mock_delegate().ExpectCallsToGetterMethods(); |
613 EXPECT_CALL(resetter(), ReportStatistics(0x02u, 0x01u)); | 657 EXPECT_CALL(resetter(), ReportStatistics(0x02u, 0x01u)); |
| 658 EXPECT_CALL(resetter(), ReportPromptResult( |
| 659 AutomaticProfileResetter::PROMPT_NOT_TRIGGERED)); |
614 | 660 |
615 UnleashResetterAndWait(); | 661 UnleashResetterAndWait(); |
616 | 662 |
617 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); | 663 ExpectAllMementoValuesEqualTo(kTestMementoValue); |
618 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); | 664 VerifyExpectationsThenShutdownResetter(); |
619 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); | |
620 } | 665 } |
621 | 666 |
622 #if defined(GOOGLE_CHROME_BUILD) | 667 #if defined(GOOGLE_CHROME_BUILD) |
623 TEST_F(AutomaticProfileResetterTestDryRun, ProgramSetThroughVariationParams) { | 668 TEST_F(AutomaticProfileResetterTestDryRun, ProgramSetThroughVariationParams) { |
624 PreferenceHostedPromptMemento memento_in_prefs(profile()); | |
625 LocalStateHostedPromptMemento memento_in_local_state(profile()); | |
626 FileHostedPromptMementoSynchronous memento_in_file(profile()); | |
627 | |
628 EXPECT_EQ("", memento_in_prefs.ReadValue()); | |
629 EXPECT_EQ("", memento_in_local_state.ReadValue()); | |
630 EXPECT_EQ("", memento_in_file.ReadValue()); | |
631 | |
632 SetTestingProgram(ConstructProgram(true, true)); | 669 SetTestingProgram(ConstructProgram(true, true)); |
633 SetTestingHashSeed(kTestHashSeed); | 670 SetTestingHashSeed(kTestHashSeed); |
634 AllowInjectingTestDataThroughVariationParams(true); | 671 AllowInjectingTestDataThroughVariationParams(true); |
635 | 672 |
636 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); | 673 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); |
637 mock_delegate().ExpectCallsToGetterMethods(); | 674 mock_delegate().ExpectCallsToGetterMethods(); |
638 EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x01u)); | 675 EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x01u)); |
| 676 EXPECT_CALL(resetter(), ReportPromptResult( |
| 677 AutomaticProfileResetter::PROMPT_NOT_TRIGGERED)); |
639 | 678 |
640 UnleashResetterAndWait(); | 679 UnleashResetterAndWait(); |
641 | 680 |
642 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); | 681 ExpectAllMementoValuesEqualTo(kTestMementoValue); |
643 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); | 682 VerifyExpectationsThenShutdownResetter(); |
644 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); | |
645 } | 683 } |
646 #endif | 684 #endif |
647 | 685 |
648 TEST_F(AutomaticProfileResetterTestDryRun, | 686 TEST_F(AutomaticProfileResetterTestDryRun, |
649 ConditionsSatisfiedAndInvalidMementos) { | 687 ConditionsSatisfiedAndInvalidMementos) { |
650 PreferenceHostedPromptMemento memento_in_prefs(profile()); | 688 memento_in_prefs().StoreValue(kTestInvalidMementoValue); |
651 LocalStateHostedPromptMemento memento_in_local_state(profile()); | 689 memento_in_local_state().StoreValue(kTestInvalidMementoValue); |
652 FileHostedPromptMementoSynchronous memento_in_file(profile()); | 690 memento_in_file().StoreValue(kTestInvalidMementoValue); |
653 | |
654 memento_in_prefs.StoreValue(kTestInvalidMementoValue); | |
655 memento_in_local_state.StoreValue(kTestInvalidMementoValue); | |
656 memento_in_file.StoreValue(kTestInvalidMementoValue); | |
657 | 691 |
658 SetTestingProgram(ConstructProgram(true, true)); | 692 SetTestingProgram(ConstructProgram(true, true)); |
659 SetTestingHashSeed(kTestHashSeed); | 693 SetTestingHashSeed(kTestHashSeed); |
660 | 694 |
661 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); | 695 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); |
662 mock_delegate().ExpectCallsToGetterMethods(); | 696 mock_delegate().ExpectCallsToGetterMethods(); |
663 EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x01u)); | 697 EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x01u)); |
| 698 EXPECT_CALL(resetter(), ReportPromptResult( |
| 699 AutomaticProfileResetter::PROMPT_NOT_TRIGGERED)); |
664 | 700 |
665 UnleashResetterAndWait(); | 701 UnleashResetterAndWait(); |
666 | 702 |
667 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); | 703 ExpectAllMementoValuesEqualTo(kTestMementoValue); |
668 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); | 704 VerifyExpectationsThenShutdownResetter(); |
669 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); | |
670 } | 705 } |
671 | 706 |
672 TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadPrefHostedMemento) { | 707 TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadPrefHostedMemento) { |
673 PreferenceHostedPromptMemento memento_in_prefs(profile()); | 708 memento_in_prefs().StoreValue(kTestMementoValue); |
674 LocalStateHostedPromptMemento memento_in_local_state(profile()); | |
675 FileHostedPromptMementoSynchronous memento_in_file(profile()); | |
676 | |
677 memento_in_prefs.StoreValue(kTestMementoValue); | |
678 | 709 |
679 SetTestingProgram(ConstructProgram(true, true)); | 710 SetTestingProgram(ConstructProgram(true, true)); |
680 SetTestingHashSeed(kTestHashSeed); | 711 SetTestingHashSeed(kTestHashSeed); |
681 | 712 |
682 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); | 713 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); |
683 mock_delegate().ExpectCallsToGetterMethods(); | 714 mock_delegate().ExpectCallsToGetterMethods(); |
684 EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x03u)); | 715 EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x03u)); |
685 | 716 |
686 UnleashResetterAndWait(); | 717 UnleashResetterAndWait(); |
| 718 VerifyExpectationsThenShutdownResetter(); |
687 | 719 |
688 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); | 720 EXPECT_EQ(kTestMementoValue, memento_in_prefs().ReadValue()); |
689 EXPECT_EQ("", memento_in_local_state.ReadValue()); | 721 EXPECT_EQ(std::string(), memento_in_local_state().ReadValue()); |
690 EXPECT_EQ("", memento_in_file.ReadValue()); | 722 EXPECT_EQ(std::string(), memento_in_file().ReadValue()); |
691 } | 723 } |
692 | 724 |
693 TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadLocalStateHostedMemento) { | 725 TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadLocalStateHostedMemento) { |
694 PreferenceHostedPromptMemento memento_in_prefs(profile()); | 726 memento_in_local_state().StoreValue(kTestMementoValue); |
695 LocalStateHostedPromptMemento memento_in_local_state(profile()); | |
696 FileHostedPromptMementoSynchronous memento_in_file(profile()); | |
697 | |
698 memento_in_local_state.StoreValue(kTestMementoValue); | |
699 | 727 |
700 SetTestingProgram(ConstructProgram(true, true)); | 728 SetTestingProgram(ConstructProgram(true, true)); |
701 SetTestingHashSeed(kTestHashSeed); | 729 SetTestingHashSeed(kTestHashSeed); |
702 | 730 |
703 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); | 731 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); |
704 mock_delegate().ExpectCallsToGetterMethods(); | 732 mock_delegate().ExpectCallsToGetterMethods(); |
705 EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x05u)); | 733 EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x05u)); |
706 | 734 |
707 UnleashResetterAndWait(); | 735 UnleashResetterAndWait(); |
| 736 VerifyExpectationsThenShutdownResetter(); |
708 | 737 |
709 EXPECT_EQ("", memento_in_prefs.ReadValue()); | 738 EXPECT_EQ(std::string(), memento_in_prefs().ReadValue()); |
710 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); | 739 EXPECT_EQ(kTestMementoValue, memento_in_local_state().ReadValue()); |
711 EXPECT_EQ("", memento_in_file.ReadValue()); | 740 EXPECT_EQ(std::string(), memento_in_file().ReadValue()); |
712 } | 741 } |
713 | 742 |
714 TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadFileHostedMemento) { | 743 TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadFileHostedMemento) { |
715 PreferenceHostedPromptMemento memento_in_prefs(profile()); | 744 memento_in_file().StoreValue(kTestMementoValue); |
716 LocalStateHostedPromptMemento memento_in_local_state(profile()); | |
717 FileHostedPromptMementoSynchronous memento_in_file(profile()); | |
718 | |
719 memento_in_file.StoreValue(kTestMementoValue); | |
720 | 745 |
721 SetTestingProgram(ConstructProgram(true, true)); | 746 SetTestingProgram(ConstructProgram(true, true)); |
722 SetTestingHashSeed(kTestHashSeed); | 747 SetTestingHashSeed(kTestHashSeed); |
723 | 748 |
724 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); | 749 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); |
725 mock_delegate().ExpectCallsToGetterMethods(); | 750 mock_delegate().ExpectCallsToGetterMethods(); |
726 EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x09u)); | 751 EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x09u)); |
727 | 752 |
728 UnleashResetterAndWait(); | 753 UnleashResetterAndWait(); |
| 754 VerifyExpectationsThenShutdownResetter(); |
729 | 755 |
730 EXPECT_EQ("", memento_in_prefs.ReadValue()); | 756 EXPECT_EQ(std::string(), memento_in_prefs().ReadValue()); |
731 EXPECT_EQ("", memento_in_local_state.ReadValue()); | 757 EXPECT_EQ(std::string(), memento_in_local_state().ReadValue()); |
732 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); | 758 EXPECT_EQ(kTestMementoValue, memento_in_file().ReadValue()); |
733 } | 759 } |
734 | 760 |
735 TEST_F(AutomaticProfileResetterTestDryRun, DoNothingWhenResourcesAreMissing) { | 761 TEST_F(AutomaticProfileResetterTestDryRun, DoNothingWhenResourcesAreMissing) { |
736 PreferenceHostedPromptMemento memento_in_prefs(profile()); | 762 SetTestingProgram(std::string()); |
737 LocalStateHostedPromptMemento memento_in_local_state(profile()); | 763 SetTestingHashSeed(std::string()); |
738 FileHostedPromptMementoSynchronous memento_in_file(profile()); | |
739 | |
740 SetTestingProgram(""); | |
741 SetTestingHashSeed(""); | |
742 | 764 |
743 // No calls are expected to the delegate. | 765 // No calls are expected to the delegate. |
744 | 766 |
745 UnleashResetterAndWait(); | 767 UnleashResetterAndWait(); |
| 768 VerifyExpectationsThenShutdownResetter(); |
746 | 769 |
747 EXPECT_EQ("", memento_in_prefs.ReadValue()); | 770 ExpectAllMementoValuesEqualTo(std::string()); |
748 EXPECT_EQ("", memento_in_local_state.ReadValue()); | |
749 EXPECT_EQ("", memento_in_file.ReadValue()); | |
750 } | 771 } |
751 | 772 |
752 TEST_F(AutomaticProfileResetterTest, ConditionsNotSatisfied) { | 773 TEST_F(AutomaticProfileResetterTest, ConditionsNotSatisfied) { |
753 PreferenceHostedPromptMemento memento_in_prefs(profile()); | |
754 LocalStateHostedPromptMemento memento_in_local_state(profile()); | |
755 FileHostedPromptMementoSynchronous memento_in_file(profile()); | |
756 | |
757 EXPECT_EQ("", memento_in_prefs.ReadValue()); | |
758 EXPECT_EQ("", memento_in_local_state.ReadValue()); | |
759 EXPECT_EQ("", memento_in_file.ReadValue()); | |
760 | |
761 SetTestingProgram(ConstructProgram(false, false)); | 774 SetTestingProgram(ConstructProgram(false, false)); |
762 SetTestingHashSeed(kTestHashSeed); | 775 SetTestingHashSeed(kTestHashSeed); |
763 | 776 |
764 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); | 777 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); |
765 mock_delegate().ExpectCallsToGetterMethods(); | 778 mock_delegate().ExpectCallsToGetterMethods(); |
766 EXPECT_CALL(resetter(), ReportStatistics(0x00u, 0x00u)); | 779 EXPECT_CALL(resetter(), ReportStatistics(0x00u, 0x00u)); |
767 | 780 |
768 UnleashResetterAndWait(); | 781 UnleashResetterAndWait(); |
| 782 VerifyExpectationsThenShutdownResetter(); |
769 | 783 |
770 EXPECT_EQ("", memento_in_prefs.ReadValue()); | 784 ExpectAllMementoValuesEqualTo(std::string()); |
771 EXPECT_EQ("", memento_in_local_state.ReadValue()); | |
772 EXPECT_EQ("", memento_in_file.ReadValue()); | |
773 } | 785 } |
774 | 786 |
775 TEST_F(AutomaticProfileResetterTest, OneConditionSatisfied) { | 787 TEST_F(AutomaticProfileResetterTest, OneConditionSatisfied) { |
776 PreferenceHostedPromptMemento memento_in_prefs(profile()); | |
777 LocalStateHostedPromptMemento memento_in_local_state(profile()); | |
778 FileHostedPromptMementoSynchronous memento_in_file(profile()); | |
779 | |
780 EXPECT_EQ("", memento_in_prefs.ReadValue()); | |
781 EXPECT_EQ("", memento_in_local_state.ReadValue()); | |
782 EXPECT_EQ("", memento_in_file.ReadValue()); | |
783 | |
784 SetTestingProgram(ConstructProgram(true, false)); | 788 SetTestingProgram(ConstructProgram(true, false)); |
785 SetTestingHashSeed(kTestHashSeed); | 789 SetTestingHashSeed(kTestHashSeed); |
786 | 790 |
787 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); | 791 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); |
788 mock_delegate().ExpectCallsToGetterMethods(); | 792 mock_delegate().ExpectCallsToGetterMethods(); |
789 EXPECT_CALL(mock_delegate(), ShowPrompt()); | 793 mock_delegate().ExpectCallToShowPrompt(); |
790 EXPECT_CALL(resetter(), ReportStatistics(0x01u, 0x01u)); | 794 EXPECT_CALL(resetter(), ReportStatistics(0x01u, 0x01u)); |
791 | 795 |
792 UnleashResetterAndWait(); | 796 UnleashResetterAndWait(); |
793 | 797 |
794 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); | 798 VerifyExpectationsThenShutdownResetter(); |
795 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); | |
796 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); | |
797 } | 799 } |
798 | 800 |
799 TEST_F(AutomaticProfileResetterTest, OtherConditionSatisfied) { | 801 TEST_F(AutomaticProfileResetterTest, OtherConditionSatisfied) { |
800 PreferenceHostedPromptMemento memento_in_prefs(profile()); | |
801 LocalStateHostedPromptMemento memento_in_local_state(profile()); | |
802 FileHostedPromptMementoSynchronous memento_in_file(profile()); | |
803 | |
804 EXPECT_EQ("", memento_in_prefs.ReadValue()); | |
805 EXPECT_EQ("", memento_in_local_state.ReadValue()); | |
806 EXPECT_EQ("", memento_in_file.ReadValue()); | |
807 | |
808 SetTestingProgram(ConstructProgram(false, true)); | 802 SetTestingProgram(ConstructProgram(false, true)); |
809 SetTestingHashSeed(kTestHashSeed); | 803 SetTestingHashSeed(kTestHashSeed); |
810 | 804 |
811 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); | 805 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); |
812 mock_delegate().ExpectCallsToGetterMethods(); | 806 mock_delegate().ExpectCallsToGetterMethods(); |
813 EXPECT_CALL(mock_delegate(), ShowPrompt()); | 807 mock_delegate().ExpectCallToShowPrompt(); |
814 EXPECT_CALL(resetter(), ReportStatistics(0x02u, 0x01u)); | 808 EXPECT_CALL(resetter(), ReportStatistics(0x02u, 0x01u)); |
815 | 809 |
816 UnleashResetterAndWait(); | 810 UnleashResetterAndWait(); |
817 | 811 |
818 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); | 812 VerifyExpectationsThenShutdownResetter(); |
819 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); | |
820 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); | |
821 } | 813 } |
822 | 814 |
823 #if defined(GOOGLE_CHROME_BUILD) | 815 #if defined(GOOGLE_CHROME_BUILD) |
824 TEST_F(AutomaticProfileResetterTest, ProgramSetThroughVariationParams) { | 816 TEST_F(AutomaticProfileResetterTest, ProgramSetThroughVariationParams) { |
825 PreferenceHostedPromptMemento memento_in_prefs(profile()); | |
826 LocalStateHostedPromptMemento memento_in_local_state(profile()); | |
827 FileHostedPromptMementoSynchronous memento_in_file(profile()); | |
828 | |
829 EXPECT_EQ("", memento_in_prefs.ReadValue()); | |
830 EXPECT_EQ("", memento_in_local_state.ReadValue()); | |
831 EXPECT_EQ("", memento_in_file.ReadValue()); | |
832 | |
833 SetTestingProgram(ConstructProgram(true, true)); | 817 SetTestingProgram(ConstructProgram(true, true)); |
834 SetTestingHashSeed(kTestHashSeed); | 818 SetTestingHashSeed(kTestHashSeed); |
835 AllowInjectingTestDataThroughVariationParams(true); | 819 AllowInjectingTestDataThroughVariationParams(true); |
836 | 820 |
837 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); | 821 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); |
838 mock_delegate().ExpectCallsToGetterMethods(); | 822 mock_delegate().ExpectCallsToGetterMethods(); |
839 EXPECT_CALL(mock_delegate(), ShowPrompt()); | 823 mock_delegate().ExpectCallToShowPrompt(); |
840 EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x01u)); | 824 EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x01u)); |
| 825 EXPECT_CALL(resetter(), ReportPromptResult( |
| 826 AutomaticProfileResetter::PROMPT_SHOWN_BUBBLE)); |
841 | 827 |
842 UnleashResetterAndWait(); | 828 UnleashResetterAndWait(); |
| 829 resetter().NotifyDidShowResetBubble(); |
843 | 830 |
844 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); | 831 ExpectAllMementoValuesEqualTo(kTestMementoValue); |
845 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); | 832 VerifyExpectationsThenShutdownResetter(); |
846 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); | |
847 } | 833 } |
848 #endif | 834 #endif |
849 | 835 |
850 TEST_F(AutomaticProfileResetterTest, ConditionsSatisfiedAndInvalidMementos) { | 836 TEST_F(AutomaticProfileResetterTest, ConditionsSatisfiedAndInvalidMementos) { |
851 PreferenceHostedPromptMemento memento_in_prefs(profile()); | 837 memento_in_prefs().StoreValue(kTestInvalidMementoValue); |
852 LocalStateHostedPromptMemento memento_in_local_state(profile()); | 838 memento_in_local_state().StoreValue(kTestInvalidMementoValue); |
853 FileHostedPromptMementoSynchronous memento_in_file(profile()); | 839 memento_in_file().StoreValue(kTestInvalidMementoValue); |
854 | |
855 memento_in_prefs.StoreValue(kTestInvalidMementoValue); | |
856 memento_in_local_state.StoreValue(kTestInvalidMementoValue); | |
857 memento_in_file.StoreValue(kTestInvalidMementoValue); | |
858 | 840 |
859 SetTestingProgram(ConstructProgram(true, true)); | 841 SetTestingProgram(ConstructProgram(true, true)); |
860 SetTestingHashSeed(kTestHashSeed); | 842 SetTestingHashSeed(kTestHashSeed); |
861 | 843 |
862 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); | 844 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); |
863 mock_delegate().ExpectCallsToGetterMethods(); | 845 mock_delegate().ExpectCallsToGetterMethods(); |
864 EXPECT_CALL(mock_delegate(), ShowPrompt()); | 846 mock_delegate().ExpectCallToShowPrompt(); |
865 EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x01u)); | 847 EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x01u)); |
| 848 EXPECT_CALL(resetter(), ReportPromptResult( |
| 849 AutomaticProfileResetter::PROMPT_SHOWN_BUBBLE)); |
866 | 850 |
867 UnleashResetterAndWait(); | 851 UnleashResetterAndWait(); |
| 852 resetter().NotifyDidShowResetBubble(); |
868 | 853 |
869 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); | 854 ExpectAllMementoValuesEqualTo(kTestMementoValue); |
870 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); | 855 VerifyExpectationsThenShutdownResetter(); |
871 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); | |
872 } | 856 } |
873 | 857 |
874 TEST_F(AutomaticProfileResetterTest, PrefHostedMementoPreventsPrompt) { | 858 TEST_F(AutomaticProfileResetterTest, PrefHostedMementoPreventsPrompt) { |
875 PreferenceHostedPromptMemento memento_in_prefs(profile()); | 859 memento_in_prefs().StoreValue(kTestMementoValue); |
876 LocalStateHostedPromptMemento memento_in_local_state(profile()); | |
877 FileHostedPromptMementoSynchronous memento_in_file(profile()); | |
878 | |
879 memento_in_prefs.StoreValue(kTestMementoValue); | |
880 | 860 |
881 SetTestingProgram(ConstructProgram(true, true)); | 861 SetTestingProgram(ConstructProgram(true, true)); |
882 SetTestingHashSeed(kTestHashSeed); | 862 SetTestingHashSeed(kTestHashSeed); |
883 | 863 |
884 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); | 864 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); |
885 mock_delegate().ExpectCallsToGetterMethods(); | 865 mock_delegate().ExpectCallsToGetterMethods(); |
886 EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x03u)); | 866 EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x03u)); |
887 | 867 |
888 UnleashResetterAndWait(); | 868 UnleashResetterAndWait(); |
| 869 VerifyExpectationsThenShutdownResetter(); |
889 | 870 |
890 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); | 871 EXPECT_EQ(kTestMementoValue, memento_in_prefs().ReadValue()); |
891 EXPECT_EQ("", memento_in_local_state.ReadValue()); | 872 EXPECT_EQ(std::string(), memento_in_local_state().ReadValue()); |
892 EXPECT_EQ("", memento_in_file.ReadValue()); | 873 EXPECT_EQ(std::string(), memento_in_file().ReadValue()); |
893 } | 874 } |
894 | 875 |
895 TEST_F(AutomaticProfileResetterTest, LocalStateHostedMementoPreventsPrompt) { | 876 TEST_F(AutomaticProfileResetterTest, LocalStateHostedMementoPreventsPrompt) { |
896 PreferenceHostedPromptMemento memento_in_prefs(profile()); | 877 memento_in_local_state().StoreValue(kTestMementoValue); |
897 LocalStateHostedPromptMemento memento_in_local_state(profile()); | |
898 FileHostedPromptMementoSynchronous memento_in_file(profile()); | |
899 | |
900 memento_in_local_state.StoreValue(kTestMementoValue); | |
901 | 878 |
902 SetTestingProgram(ConstructProgram(true, true)); | 879 SetTestingProgram(ConstructProgram(true, true)); |
903 SetTestingHashSeed(kTestHashSeed); | 880 SetTestingHashSeed(kTestHashSeed); |
904 | 881 |
905 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); | 882 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); |
906 mock_delegate().ExpectCallsToGetterMethods(); | 883 mock_delegate().ExpectCallsToGetterMethods(); |
907 EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x05u)); | 884 EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x05u)); |
908 | 885 |
909 UnleashResetterAndWait(); | 886 UnleashResetterAndWait(); |
| 887 VerifyExpectationsThenShutdownResetter(); |
910 | 888 |
911 EXPECT_EQ("", memento_in_prefs.ReadValue()); | 889 EXPECT_EQ(std::string(), memento_in_prefs().ReadValue()); |
912 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); | 890 EXPECT_EQ(kTestMementoValue, memento_in_local_state().ReadValue()); |
913 EXPECT_EQ("", memento_in_file.ReadValue()); | 891 EXPECT_EQ(std::string(), memento_in_file().ReadValue()); |
914 } | 892 } |
915 | 893 |
916 TEST_F(AutomaticProfileResetterTest, FileHostedMementoPreventsPrompt) { | 894 TEST_F(AutomaticProfileResetterTest, FileHostedMementoPreventsPrompt) { |
917 PreferenceHostedPromptMemento memento_in_prefs(profile()); | 895 memento_in_file().StoreValue(kTestMementoValue); |
918 LocalStateHostedPromptMemento memento_in_local_state(profile()); | |
919 FileHostedPromptMementoSynchronous memento_in_file(profile()); | |
920 | |
921 memento_in_file.StoreValue(kTestMementoValue); | |
922 | 896 |
923 SetTestingProgram(ConstructProgram(true, true)); | 897 SetTestingProgram(ConstructProgram(true, true)); |
924 SetTestingHashSeed(kTestHashSeed); | 898 SetTestingHashSeed(kTestHashSeed); |
925 | 899 |
926 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); | 900 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); |
927 mock_delegate().ExpectCallsToGetterMethods(); | 901 mock_delegate().ExpectCallsToGetterMethods(); |
928 EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x09u)); | 902 EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x09u)); |
929 | 903 |
930 UnleashResetterAndWait(); | 904 UnleashResetterAndWait(); |
931 | 905 VerifyExpectationsThenShutdownResetter(); |
932 EXPECT_EQ("", memento_in_prefs.ReadValue()); | 906 |
933 EXPECT_EQ("", memento_in_local_state.ReadValue()); | 907 EXPECT_EQ(std::string(), memento_in_prefs().ReadValue()); |
934 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); | 908 EXPECT_EQ(std::string(), memento_in_local_state().ReadValue()); |
| 909 EXPECT_EQ(kTestMementoValue, memento_in_file().ReadValue()); |
935 } | 910 } |
936 | 911 |
937 TEST_F(AutomaticProfileResetterTest, DoNothingWhenResourcesAreMissing) { | 912 TEST_F(AutomaticProfileResetterTest, DoNothingWhenResourcesAreMissing) { |
938 PreferenceHostedPromptMemento memento_in_prefs(profile()); | 913 SetTestingProgram(std::string()); |
939 LocalStateHostedPromptMemento memento_in_local_state(profile()); | 914 SetTestingHashSeed(std::string()); |
940 FileHostedPromptMementoSynchronous memento_in_file(profile()); | |
941 | |
942 SetTestingProgram(""); | |
943 SetTestingHashSeed(""); | |
944 | 915 |
945 // No calls are expected to the delegate. | 916 // No calls are expected to the delegate. |
946 | 917 |
947 UnleashResetterAndWait(); | 918 UnleashResetterAndWait(); |
948 | 919 VerifyExpectationsThenShutdownResetter(); |
949 EXPECT_EQ("", memento_in_prefs.ReadValue()); | 920 |
950 EXPECT_EQ("", memento_in_local_state.ReadValue()); | 921 ExpectAllMementoValuesEqualTo(std::string()); |
951 EXPECT_EQ("", memento_in_file.ReadValue()); | 922 } |
| 923 |
| 924 TEST_F(AutomaticProfileResetterTest, PromptSuppressed) { |
| 925 OrchestrateThroughEvaluationFlow(); |
| 926 |
| 927 VerifyExpectationsThenShutdownResetter(); |
| 928 |
| 929 ExpectAllMementoValuesEqualTo(std::string()); |
| 930 } |
| 931 |
| 932 TEST_F(AutomaticProfileResetterTest, PromptNotSupported) { |
| 933 SetTestingProgram(ConstructProgram(true, true)); |
| 934 SetTestingHashSeed(kTestHashSeed); |
| 935 |
| 936 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); |
| 937 mock_delegate().ExpectCallsToGetterMethods(); |
| 938 EXPECT_CALL(mock_delegate(), TriggerPrompt()) |
| 939 .WillOnce(testing::Return(false)); |
| 940 EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x01u)); |
| 941 EXPECT_CALL(resetter(), ReportPromptResult( |
| 942 AutomaticProfileResetter::PROMPT_NOT_TRIGGERED)); |
| 943 |
| 944 UnleashResetterAndWait(); |
| 945 |
| 946 ExpectAllMementoValuesEqualTo(kTestMementoValue); |
| 947 VerifyExpectationsThenShutdownResetter(); |
| 948 } |
| 949 |
| 950 TEST_F(AutomaticProfileResetterTest, PromptIgnored) { |
| 951 OrchestrateThroughEvaluationFlow(); |
| 952 |
| 953 EXPECT_CALL(resetter(), ReportPromptResult( |
| 954 AutomaticProfileResetter::PROMPT_SHOWN_BUBBLE)); |
| 955 resetter().NotifyDidShowResetBubble(); |
| 956 ExpectAllMementoValuesEqualTo(kTestMementoValue); |
| 957 VerifyExpectationsThenShutdownResetter(); |
| 958 } |
| 959 |
| 960 TEST_F(AutomaticProfileResetterTest, PromptActionReset) { |
| 961 OrchestrateThroughEvaluationFlow(); |
| 962 |
| 963 EXPECT_CALL(resetter(), ReportPromptResult( |
| 964 AutomaticProfileResetter::PROMPT_SHOWN_BUBBLE)); |
| 965 resetter().NotifyDidShowResetBubble(); |
| 966 ExpectAllMementoValuesEqualTo(kTestMementoValue); |
| 967 testing::Mock::VerifyAndClearExpectations(&resetter()); |
| 968 |
| 969 mock_delegate().ExpectCallToTriggerReset(false); |
| 970 EXPECT_CALL(resetter(), ReportPromptResult( |
| 971 AutomaticProfileResetter::PROMPT_ACTION_RESET)); |
| 972 resetter().TriggerProfileReset(false /*send_feedback*/); |
| 973 testing::Mock::VerifyAndClearExpectations(&resetter()); |
| 974 testing::Mock::VerifyAndClearExpectations(&mock_delegate()); |
| 975 |
| 976 EXPECT_CALL(mock_delegate(), DismissPrompt()); |
| 977 mock_delegate().EmulateProfileResetCompleted(); |
| 978 VerifyExpectationsThenShutdownResetter(); |
| 979 } |
| 980 |
| 981 TEST_F(AutomaticProfileResetterTest, PromptActionResetWithFeedback) { |
| 982 OrchestrateThroughEvaluationFlow(); |
| 983 |
| 984 EXPECT_CALL(resetter(), ReportPromptResult( |
| 985 AutomaticProfileResetter::PROMPT_SHOWN_BUBBLE)); |
| 986 resetter().NotifyDidShowResetBubble(); |
| 987 ExpectAllMementoValuesEqualTo(kTestMementoValue); |
| 988 testing::Mock::VerifyAndClearExpectations(&resetter()); |
| 989 |
| 990 mock_delegate().ExpectCallToTriggerReset(true); |
| 991 EXPECT_CALL(resetter(), ReportPromptResult( |
| 992 AutomaticProfileResetter::PROMPT_ACTION_RESET)); |
| 993 resetter().TriggerProfileReset(true /*send_feedback*/); |
| 994 testing::Mock::VerifyAndClearExpectations(&resetter()); |
| 995 testing::Mock::VerifyAndClearExpectations(&mock_delegate()); |
| 996 |
| 997 EXPECT_CALL(mock_delegate(), DismissPrompt()); |
| 998 mock_delegate().EmulateProfileResetCompleted(); |
| 999 VerifyExpectationsThenShutdownResetter(); |
| 1000 } |
| 1001 |
| 1002 TEST_F(AutomaticProfileResetterTest, PromptActionNoReset) { |
| 1003 OrchestrateThroughEvaluationFlow(); |
| 1004 |
| 1005 EXPECT_CALL(resetter(), ReportPromptResult( |
| 1006 AutomaticProfileResetter::PROMPT_SHOWN_BUBBLE)); |
| 1007 resetter().NotifyDidShowResetBubble(); |
| 1008 ExpectAllMementoValuesEqualTo(kTestMementoValue); |
| 1009 testing::Mock::VerifyAndClearExpectations(&resetter()); |
| 1010 |
| 1011 EXPECT_CALL(mock_delegate(), DismissPrompt()); |
| 1012 EXPECT_CALL(resetter(), ReportPromptResult( |
| 1013 AutomaticProfileResetter::PROMPT_ACTION_NO_RESET)); |
| 1014 resetter().SkipProfileReset(); |
| 1015 VerifyExpectationsThenShutdownResetter(); |
| 1016 } |
| 1017 |
| 1018 TEST_F(AutomaticProfileResetterTest, PromptFollowedByWebUIReset) { |
| 1019 OrchestrateThroughEvaluationFlow(); |
| 1020 |
| 1021 EXPECT_CALL(resetter(), ReportPromptResult( |
| 1022 AutomaticProfileResetter::PROMPT_SHOWN_BUBBLE)); |
| 1023 resetter().NotifyDidShowResetBubble(); |
| 1024 ExpectAllMementoValuesEqualTo(kTestMementoValue); |
| 1025 testing::Mock::VerifyAndClearExpectations(&resetter()); |
| 1026 |
| 1027 EXPECT_CALL(mock_delegate(), DismissPrompt()); |
| 1028 resetter().NotifyDidOpenWebUIResetDialog(); |
| 1029 testing::Mock::VerifyAndClearExpectations(&mock_delegate()); |
| 1030 |
| 1031 EXPECT_CALL(resetter(), ReportPromptResult( |
| 1032 AutomaticProfileResetter::PROMPT_FOLLOWED_BY_WEBUI_RESET)); |
| 1033 resetter().NotifyDidCloseWebUIResetDialog(true); |
| 1034 VerifyExpectationsThenShutdownResetter(); |
| 1035 } |
| 1036 |
| 1037 TEST_F(AutomaticProfileResetterTest, PromptFollowedByWebUINoReset) { |
| 1038 OrchestrateThroughEvaluationFlow(); |
| 1039 |
| 1040 EXPECT_CALL(resetter(), ReportPromptResult( |
| 1041 AutomaticProfileResetter::PROMPT_SHOWN_BUBBLE)); |
| 1042 resetter().NotifyDidShowResetBubble(); |
| 1043 ExpectAllMementoValuesEqualTo(kTestMementoValue); |
| 1044 testing::Mock::VerifyAndClearExpectations(&resetter()); |
| 1045 |
| 1046 EXPECT_CALL(mock_delegate(), DismissPrompt()); |
| 1047 resetter().NotifyDidOpenWebUIResetDialog(); |
| 1048 testing::Mock::VerifyAndClearExpectations(&mock_delegate()); |
| 1049 |
| 1050 EXPECT_CALL(resetter(), ReportPromptResult( |
| 1051 AutomaticProfileResetter::PROMPT_FOLLOWED_BY_WEBUI_NO_RESET)); |
| 1052 resetter().NotifyDidCloseWebUIResetDialog(false); |
| 1053 VerifyExpectationsThenShutdownResetter(); |
| 1054 } |
| 1055 |
| 1056 TEST_F(AutomaticProfileResetterTest, PromptFollowedByIncidentalWebUIReset) { |
| 1057 OrchestrateThroughEvaluationFlow(); |
| 1058 |
| 1059 EXPECT_CALL(resetter(), ReportPromptResult( |
| 1060 AutomaticProfileResetter::PROMPT_SHOWN_BUBBLE)); |
| 1061 resetter().NotifyDidShowResetBubble(); |
| 1062 ExpectAllMementoValuesEqualTo(kTestMementoValue); |
| 1063 testing::Mock::VerifyAndClearExpectations(&resetter()); |
| 1064 |
| 1065 // Missing NotifyDidOpenWebUIResetDialog(). |
| 1066 // This can arise if a settings page was already opened at the time the prompt |
| 1067 // was triggered, and it used to initiate reset after dismissing the prompt. |
| 1068 |
| 1069 EXPECT_CALL(mock_delegate(), DismissPrompt()); |
| 1070 EXPECT_CALL(resetter(), ReportPromptResult( |
| 1071 AutomaticProfileResetter::PROMPT_FOLLOWED_BY_WEBUI_RESET)); |
| 1072 resetter().NotifyDidCloseWebUIResetDialog(true); |
| 1073 VerifyExpectationsThenShutdownResetter(); |
| 1074 } |
| 1075 |
| 1076 TEST_F(AutomaticProfileResetterTest, PromptSuppressedButHadWebUIReset) { |
| 1077 OrchestrateThroughEvaluationFlow(); |
| 1078 |
| 1079 EXPECT_CALL(mock_delegate(), DismissPrompt()); |
| 1080 resetter().NotifyDidOpenWebUIResetDialog(); |
| 1081 testing::Mock::VerifyAndClearExpectations(&mock_delegate()); |
| 1082 |
| 1083 EXPECT_CALL(resetter(), ReportPromptResult( |
| 1084 AutomaticProfileResetter::PROMPT_NOT_SHOWN_BUBBLE_BUT_HAD_WEBUI_RESET)); |
| 1085 resetter().NotifyDidCloseWebUIResetDialog(true); |
| 1086 ExpectAllMementoValuesEqualTo(kTestMementoValue); |
| 1087 VerifyExpectationsThenShutdownResetter(); |
| 1088 } |
| 1089 |
| 1090 TEST_F(AutomaticProfileResetterTest, PromptSuppressedButHadWebUINoReset) { |
| 1091 OrchestrateThroughEvaluationFlow(); |
| 1092 |
| 1093 EXPECT_CALL(mock_delegate(), DismissPrompt()); |
| 1094 resetter().NotifyDidOpenWebUIResetDialog(); |
| 1095 testing::Mock::VerifyAndClearExpectations(&mock_delegate()); |
| 1096 |
| 1097 EXPECT_CALL(resetter(), ReportPromptResult(AutomaticProfileResetter:: |
| 1098 PROMPT_NOT_SHOWN_BUBBLE_BUT_HAD_WEBUI_NO_RESET)); |
| 1099 resetter().NotifyDidCloseWebUIResetDialog(false); |
| 1100 ExpectAllMementoValuesEqualTo(kTestMementoValue); |
| 1101 VerifyExpectationsThenShutdownResetter(); |
952 } | 1102 } |
953 | 1103 |
954 // Please see comments above ConstructProgramToCheckPreferences() to understand | 1104 // Please see comments above ConstructProgramToCheckPreferences() to understand |
955 // how the following tests work. | 1105 // how the following tests work. |
956 | 1106 |
957 TEST_F(AutomaticProfileResetterTest, InputUserPreferencesCorrect) { | 1107 TEST_F(AutomaticProfileResetterTest, InputUserPreferencesCorrect) { |
958 SetTestingProgram(ConstructProgramToCheckPreferences()); | 1108 SetTestingProgram(ConstructProgramToCheckPreferences()); |
959 SetTestingHashSeed(kTestHashSeed); | 1109 SetTestingHashSeed(kTestHashSeed); |
960 | 1110 |
961 PrefService* prefs = profile()->GetPrefs(); | 1111 PrefService* prefs = profile()->GetPrefs(); |
962 prefs->SetString(kTestPreferencePath, kTestPreferenceValue); | 1112 prefs->SetString(kTestPreferencePath, kTestPreferenceValue); |
963 | 1113 |
964 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); | 1114 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); |
965 mock_delegate().ExpectCallsToGetterMethods(); | 1115 mock_delegate().ExpectCallsToGetterMethods(); |
966 uint32 expected_mask = | 1116 uint32 expected_mask = HAS_EXPECTED_USER_PREFERENCE | |
967 HAS_EXPECTED_USER_PREFERENCE | USER_PREFERENCE_IS_USER_CONTROLLED; | 1117 USER_PREFERENCE_IS_USER_CONTROLLED; |
968 EXPECT_CALL(resetter(), ReportStatistics(0x00u, expected_mask)); | 1118 EXPECT_CALL(resetter(), ReportStatistics(0x00u, expected_mask)); |
969 | 1119 |
970 UnleashResetterAndWait(); | 1120 UnleashResetterAndWait(); |
971 } | 1121 } |
972 | 1122 |
973 TEST_F(AutomaticProfileResetterTest, InputLocalStateCorrect) { | 1123 TEST_F(AutomaticProfileResetterTest, InputLocalStateCorrect) { |
974 SetTestingProgram(ConstructProgramToCheckPreferences()); | 1124 SetTestingProgram(ConstructProgramToCheckPreferences()); |
975 SetTestingHashSeed(kTestHashSeed); | 1125 SetTestingHashSeed(kTestHashSeed); |
976 | 1126 |
977 PrefService* prefs = local_state(); | 1127 PrefService* prefs = local_state(); |
978 prefs->SetString(kTestPreferencePath, kTestPreferenceValue); | 1128 prefs->SetString(kTestPreferencePath, kTestPreferenceValue); |
979 | 1129 |
980 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); | 1130 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); |
981 mock_delegate().ExpectCallsToGetterMethods(); | 1131 mock_delegate().ExpectCallsToGetterMethods(); |
982 uint32 expected_mask = | 1132 uint32 expected_mask = HAS_EXPECTED_LOCAL_STATE_PREFERENCE | |
983 HAS_EXPECTED_LOCAL_STATE_PREFERENCE | LOCAL_STATE_IS_USER_CONTROLLED; | 1133 LOCAL_STATE_IS_USER_CONTROLLED; |
984 EXPECT_CALL(resetter(), ReportStatistics(0x00u, expected_mask)); | 1134 EXPECT_CALL(resetter(), ReportStatistics(0x00u, expected_mask)); |
985 | 1135 |
986 UnleashResetterAndWait(); | 1136 UnleashResetterAndWait(); |
987 } | 1137 } |
988 | 1138 |
989 TEST_F(AutomaticProfileResetterTest, InputManagedUserPreferencesCorrect) { | 1139 TEST_F(AutomaticProfileResetterTest, InputManagedUserPreferencesCorrect) { |
990 SetTestingProgram(ConstructProgramToCheckPreferences()); | 1140 SetTestingProgram(ConstructProgramToCheckPreferences()); |
991 SetTestingHashSeed(kTestHashSeed); | 1141 SetTestingHashSeed(kTestHashSeed); |
992 | 1142 |
993 TestingPrefServiceSyncable* prefs = profile()->GetTestingPrefService(); | 1143 TestingPrefServiceSyncable* prefs = profile()->GetTestingPrefService(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1036 | 1186 |
1037 UnleashResetterAndWait(); | 1187 UnleashResetterAndWait(); |
1038 } | 1188 } |
1039 | 1189 |
1040 TEST_F(AutomaticProfileResetterTest, InputSearchProviderManagedCorrect) { | 1190 TEST_F(AutomaticProfileResetterTest, InputSearchProviderManagedCorrect) { |
1041 SetTestingProgram(ConstructProgramToCheckSearchEngines()); | 1191 SetTestingProgram(ConstructProgramToCheckSearchEngines()); |
1042 SetTestingHashSeed(kTestHashSeed); | 1192 SetTestingHashSeed(kTestHashSeed); |
1043 | 1193 |
1044 mock_delegate().emulated_default_search_provider_details().SetString( | 1194 mock_delegate().emulated_default_search_provider_details().SetString( |
1045 kSearchURLAttributeKey, kTestSearchURL); | 1195 kSearchURLAttributeKey, kTestSearchURL); |
1046 mock_delegate().set_emulated_default_search_provider_is_managed(true); | 1196 mock_delegate().set_emulated_is_default_search_provider_managed(true); |
1047 | 1197 |
1048 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); | 1198 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); |
1049 mock_delegate().ExpectCallsToGetterMethods(); | 1199 mock_delegate().ExpectCallsToGetterMethods(); |
1050 uint32 expected_mask = HAS_EXPECTED_DEFAULT_SEARCH_PROVIDER; | 1200 uint32 expected_mask = HAS_EXPECTED_DEFAULT_SEARCH_PROVIDER; |
1051 EXPECT_CALL(resetter(), ReportStatistics(0x00u, expected_mask)); | 1201 EXPECT_CALL(resetter(), ReportStatistics(0x00u, expected_mask)); |
1052 | 1202 |
1053 UnleashResetterAndWait(); | 1203 UnleashResetterAndWait(); |
1054 } | 1204 } |
1055 | 1205 |
1056 TEST_F(AutomaticProfileResetterTest, InputSearchProvidersCorrect) { | 1206 TEST_F(AutomaticProfileResetterTest, InputSearchProvidersCorrect) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1089 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); | 1239 mock_delegate().ExpectCallsToDependenciesSetUpMethods(); |
1090 mock_delegate().ExpectCallsToGetterMethods(); | 1240 mock_delegate().ExpectCallsToGetterMethods(); |
1091 uint32 expected_mask = | 1241 uint32 expected_mask = |
1092 HAS_EXPECTED_MODULE_DIGEST_1 | HAS_EXPECTED_MODULE_DIGEST_2; | 1242 HAS_EXPECTED_MODULE_DIGEST_1 | HAS_EXPECTED_MODULE_DIGEST_2; |
1093 EXPECT_CALL(resetter(), ReportStatistics(0x00u, expected_mask)); | 1243 EXPECT_CALL(resetter(), ReportStatistics(0x00u, expected_mask)); |
1094 | 1244 |
1095 UnleashResetterAndWait(); | 1245 UnleashResetterAndWait(); |
1096 } | 1246 } |
1097 | 1247 |
1098 } // namespace | 1248 } // namespace |
OLD | NEW |