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 |
| 52 const char kTestModuleDigest[] = "01234567890123456789012345678901"; |
| 53 const char kTestModuleDigest2[] = "12345678901234567890123456789012"; |
| 54 |
36 // Helpers ------------------------------------------------------------------ | 55 // Helpers ------------------------------------------------------------------ |
37 | 56 |
38 class MockProfileResetterDelegate : public AutomaticProfileResetterDelegate { | 57 class MockProfileResetterDelegate : public AutomaticProfileResetterDelegate { |
39 public: | 58 public: |
40 MockProfileResetterDelegate() {} | 59 MockProfileResetterDelegate() |
| 60 : emulated_default_search_provider_is_managed_(false) {} |
41 virtual ~MockProfileResetterDelegate() {} | 61 virtual ~MockProfileResetterDelegate() {} |
42 | 62 |
| 63 MOCK_METHOD0(EnumerateLoadedModulesIfNeeded, void()); |
| 64 MOCK_CONST_METHOD1(WaitOnEnumerationOfLoadedModules, |
| 65 void(const base::Closure&)); |
| 66 |
| 67 MOCK_METHOD0(LoadTemplateURLServiceIfNeeded, void()); |
| 68 MOCK_CONST_METHOD1(WaitOnTemplateURLService, void(const base::Closure&)); |
| 69 |
| 70 MOCK_CONST_METHOD0(GetLoadedModuleNameDigests, base::ListValue*()); |
| 71 |
| 72 MOCK_CONST_METHOD0(GetDefaultSearchProviderDetails, base::DictionaryValue*()); |
| 73 MOCK_CONST_METHOD0(IsDefaultSearchProviderManaged, bool()); |
| 74 MOCK_CONST_METHOD0(GetPrepopulatedSearchProvidersDetails, base::ListValue*()); |
| 75 |
43 MOCK_METHOD0(ShowPrompt, void()); | 76 MOCK_METHOD0(ShowPrompt, void()); |
44 MOCK_METHOD2(ReportStatistics, void(uint32, uint32)); | 77 MOCK_METHOD2(ReportStatistics, void(uint32, uint32)); |
45 | 78 |
| 79 static void ClosureInvoker(const base::Closure& closure) { closure.Run(); } |
| 80 |
| 81 void ExpectCallsToWaitingMethods() { |
| 82 EXPECT_CALL(*this, EnumerateLoadedModulesIfNeeded()); |
| 83 EXPECT_CALL(*this, LoadTemplateURLServiceIfNeeded()); |
| 84 EXPECT_CALL(*this, WaitOnEnumerationOfLoadedModules(_)) |
| 85 .WillOnce(Invoke(ClosureInvoker)); |
| 86 EXPECT_CALL(*this, WaitOnTemplateURLService(_)) |
| 87 .WillOnce(Invoke(ClosureInvoker)); |
| 88 } |
| 89 |
| 90 void ExpectCallsToGetterMethods() { |
| 91 EXPECT_CALL(*this, GetDefaultSearchProviderDetails()) |
| 92 .WillRepeatedly(Invoke(&emulated_default_search_provider_details_, |
| 93 &base::DictionaryValue::DeepCopy)); |
| 94 EXPECT_CALL(*this, IsDefaultSearchProviderManaged()) |
| 95 .WillRepeatedly(Return(emulated_default_search_provider_is_managed_)); |
| 96 EXPECT_CALL(*this, GetPrepopulatedSearchProvidersDetails()) |
| 97 .WillRepeatedly(Invoke(&emulated_search_providers_details_, |
| 98 &base::ListValue::DeepCopy)); |
| 99 EXPECT_CALL(*this, GetLoadedModuleNameDigests()).WillRepeatedly( |
| 100 Invoke(&emulated_loaded_module_digests_, &base::ListValue::DeepCopy)); |
| 101 } |
| 102 |
| 103 base::DictionaryValue& emulated_default_search_provider_details() { |
| 104 return emulated_default_search_provider_details_; |
| 105 } |
| 106 |
| 107 base::ListValue& emulated_search_providers_details() { |
| 108 return emulated_search_providers_details_; |
| 109 } |
| 110 |
| 111 base::ListValue& emulated_loaded_module_digests() { |
| 112 return emulated_loaded_module_digests_; |
| 113 } |
| 114 |
| 115 void set_emulated_default_search_provider_is_managed(bool value) { |
| 116 emulated_default_search_provider_is_managed_ = value; |
| 117 } |
| 118 |
46 private: | 119 private: |
| 120 base::DictionaryValue emulated_default_search_provider_details_; |
| 121 base::ListValue emulated_search_providers_details_; |
| 122 base::ListValue emulated_loaded_module_digests_; |
| 123 bool emulated_default_search_provider_is_managed_; |
| 124 |
47 DISALLOW_COPY_AND_ASSIGN(MockProfileResetterDelegate); | 125 DISALLOW_COPY_AND_ASSIGN(MockProfileResetterDelegate); |
48 }; | 126 }; |
49 | 127 |
50 class FileHostedPromptMementoSynchronous : protected FileHostedPromptMemento { | 128 class FileHostedPromptMementoSynchronous : protected FileHostedPromptMemento { |
51 public: | 129 public: |
52 explicit FileHostedPromptMementoSynchronous(Profile* profile) | 130 explicit FileHostedPromptMementoSynchronous(Profile* profile) |
53 : FileHostedPromptMemento(profile) {} | 131 : FileHostedPromptMemento(profile) {} |
54 | 132 |
55 std::string ReadValue() const { | 133 std::string ReadValue() const { |
56 std::string result; | 134 std::string result; |
(...skipping 15 matching lines...) Expand all Loading... |
72 DISALLOW_COPY_AND_ASSIGN(FileHostedPromptMementoSynchronous); | 150 DISALLOW_COPY_AND_ASSIGN(FileHostedPromptMementoSynchronous); |
73 }; | 151 }; |
74 | 152 |
75 std::string GetHash(const std::string& input) { | 153 std::string GetHash(const std::string& input) { |
76 return jtl_foundation::Hasher(kTestHashSeed).GetHash(input); | 154 return jtl_foundation::Hasher(kTestHashSeed).GetHash(input); |
77 } | 155 } |
78 | 156 |
79 // Encodes a Boolean argument value into JTL bytecode. | 157 // Encodes a Boolean argument value into JTL bytecode. |
80 std::string EncodeBool(bool value) { return value ? VALUE_TRUE : VALUE_FALSE; } | 158 std::string EncodeBool(bool value) { return value ? VALUE_TRUE : VALUE_FALSE; } |
81 | 159 |
82 // Constructs a simple evaluation program to test that input/output works well. | 160 // 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 | 161 // 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 | 162 // 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 | 163 // combined status mask according to whether or not the memento values received |
86 // in the input were as expected. | 164 // in the input were as expected. |
87 // | 165 // |
88 // More specifically, the output of the program will be as follows: | 166 // More specifically, the output of the program will be as follows: |
89 // { | 167 // { |
90 // "satisfied_criteria_mask_bit1": emulate_satisfied_criterion_1, | 168 // "satisfied_criteria_mask_bit1": emulate_satisfied_criterion_1, |
91 // "satisfied_criteria_mask_bit2": emulate_satisfied_criterion_2, | 169 // "satisfied_criteria_mask_bit2": emulate_satisfied_criterion_2, |
92 // "combined_status_mask_bit1": | 170 // "combined_status_mask_bit1": |
93 // (emulate_satisfied_criterion_1 || emulate_satisfied_criterion_2), | 171 // (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; | 213 bytecode += OP_END_OF_SENTENCE; |
136 bytecode += OP_STORE_HASH(GetHash("memento_value_in_local_state"), | 214 bytecode += OP_STORE_HASH(GetHash("memento_value_in_local_state"), |
137 kTestMementoValue); | 215 kTestMementoValue); |
138 bytecode += OP_END_OF_SENTENCE; | 216 bytecode += OP_END_OF_SENTENCE; |
139 bytecode += OP_STORE_HASH(GetHash("memento_value_in_file"), | 217 bytecode += OP_STORE_HASH(GetHash("memento_value_in_file"), |
140 kTestMementoValue); | 218 kTestMementoValue); |
141 bytecode += OP_END_OF_SENTENCE; | 219 bytecode += OP_END_OF_SENTENCE; |
142 return bytecode; | 220 return bytecode; |
143 } | 221 } |
144 | 222 |
| 223 // Constructs another evaluation program to specifically test that local state |
| 224 // and user preference values are included in the input as expected. We will |
| 225 // re-purpose the output bitmasks to channel out information about the outcome |
| 226 // of the checks. |
| 227 // |
| 228 // More specifically, the output of the program will be as follows: |
| 229 // { |
| 230 // "combined_status_mask_bit1": |
| 231 // (input["preferences.testing.preference"] == kTestPreferenceValue) |
| 232 // "combined_status_mask_bit2": |
| 233 // (input["local_state.testing.preference"] == kTestPreferenceValue) |
| 234 // "combined_status_mask_bit3": input["preferences_iuc.testing.preference"] |
| 235 // "combined_status_mask_bit4": input["local_state_iuc.testing.preference"] |
| 236 // } |
| 237 std::string ConstructProgramToCheckPreferences() { |
| 238 std::string bytecode; |
| 239 bytecode += OP_NAVIGATE(GetHash("preferences")); |
| 240 bytecode += OP_NAVIGATE(GetHash("testing")); |
| 241 bytecode += OP_NAVIGATE(GetHash("preference")); |
| 242 bytecode += OP_COMPARE_NODE_HASH(GetHash(kTestPreferenceValue)); |
| 243 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit1"), |
| 244 EncodeBool(true)); |
| 245 bytecode += OP_END_OF_SENTENCE; |
| 246 bytecode += OP_NAVIGATE(GetHash("local_state")); |
| 247 bytecode += OP_NAVIGATE(GetHash("testing")); |
| 248 bytecode += OP_NAVIGATE(GetHash("preference")); |
| 249 bytecode += OP_COMPARE_NODE_HASH(GetHash(kTestPreferenceValue)); |
| 250 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit2"), |
| 251 EncodeBool(true)); |
| 252 bytecode += OP_END_OF_SENTENCE; |
| 253 bytecode += OP_NAVIGATE(GetHash("preferences_iuc")); |
| 254 bytecode += OP_NAVIGATE(GetHash("testing")); |
| 255 bytecode += OP_NAVIGATE(GetHash("preference")); |
| 256 bytecode += OP_COMPARE_NODE_BOOL(EncodeBool(true)); |
| 257 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit3"), |
| 258 EncodeBool(true)); |
| 259 bytecode += OP_END_OF_SENTENCE; |
| 260 bytecode += OP_NAVIGATE(GetHash("local_state_iuc")); |
| 261 bytecode += OP_NAVIGATE(GetHash("testing")); |
| 262 bytecode += OP_NAVIGATE(GetHash("preference")); |
| 263 bytecode += OP_COMPARE_NODE_BOOL(EncodeBool(true)); |
| 264 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit4"), |
| 265 EncodeBool(true)); |
| 266 bytecode += OP_END_OF_SENTENCE; |
| 267 return bytecode; |
| 268 } |
| 269 |
| 270 // Legend for the bitmask returned by the above program. |
| 271 enum CombinedStatusMaskLegendForCheckingPreferences { |
| 272 HAS_EXPECTED_USER_PREFERENCE = 1 << 0, |
| 273 HAS_EXPECTED_LOCAL_STATE_PREFERENCE = 1 << 1, |
| 274 USER_PREFERENCE_IS_USER_CONTROLLED = 1 << 2, |
| 275 LOCAL_STATE_IS_USER_CONTROLLED = 1 << 3, |
| 276 }; |
| 277 |
| 278 // Constructs yet another evaluation program to specifically test that default |
| 279 // and pre-populated search engines are included in the input as expected. We |
| 280 // will re-purpose the output bitmasks to channel out information about the |
| 281 // outcome of the checks. |
| 282 // |
| 283 // More specifically, the output of the program will be as follows: |
| 284 // { |
| 285 // "combined_status_mask_bit1": |
| 286 // (input["default_search_provider.search_url"] == kTestSearchURL) |
| 287 // "combined_status_mask_bit2": input["default_search_provider_iuc"] |
| 288 // "combined_status_mask_bit3": |
| 289 // (input["search_providers.*.search_url"] == kTestSearchURL) |
| 290 // "combined_status_mask_bit4": |
| 291 // (input["search_providers.*.search_url"] == kTestSearchURL2) |
| 292 // } |
| 293 std::string ConstructProgramToCheckSearchEngines() { |
| 294 std::string bytecode; |
| 295 bytecode += OP_NAVIGATE(GetHash("default_search_provider")); |
| 296 bytecode += OP_NAVIGATE(GetHash("search_url")); |
| 297 bytecode += OP_COMPARE_NODE_HASH(GetHash(kTestSearchURL)); |
| 298 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit1"), |
| 299 EncodeBool(true)); |
| 300 bytecode += OP_END_OF_SENTENCE; |
| 301 bytecode += OP_NAVIGATE(GetHash("default_search_provider_iuc")); |
| 302 bytecode += OP_COMPARE_NODE_BOOL(EncodeBool(true)); |
| 303 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit2"), |
| 304 EncodeBool(true)); |
| 305 bytecode += OP_END_OF_SENTENCE; |
| 306 bytecode += OP_NAVIGATE(GetHash("search_providers")); |
| 307 bytecode += OP_NAVIGATE_ANY; |
| 308 bytecode += OP_NAVIGATE(GetHash("search_url")); |
| 309 bytecode += OP_COMPARE_NODE_HASH(GetHash(kTestSearchURL)); |
| 310 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit3"), |
| 311 EncodeBool(true)); |
| 312 bytecode += OP_END_OF_SENTENCE; |
| 313 bytecode += OP_NAVIGATE(GetHash("search_providers")); |
| 314 bytecode += OP_NAVIGATE_ANY; |
| 315 bytecode += OP_NAVIGATE(GetHash("search_url")); |
| 316 bytecode += OP_COMPARE_NODE_HASH(GetHash(kTestSearchURL2)); |
| 317 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit4"), |
| 318 EncodeBool(true)); |
| 319 bytecode += OP_END_OF_SENTENCE; |
| 320 return bytecode; |
| 321 } |
| 322 |
| 323 // Legend for the bitmask returned by the above program. |
| 324 enum CombinedStatusMaskLegendForCheckingSearchEngines { |
| 325 HAS_EXPECTED_DEFAULT_SEARCH_PROVIDER = 1 << 0, |
| 326 DEFAULT_SEARCH_PROVIDER_IS_USER_CONTROLLED = 1 << 1, |
| 327 HAS_EXPECTED_PREPOPULATED_SEARCH_PROVIDER_1 = 1 << 2, |
| 328 HAS_EXPECTED_PREPOPULATED_SEARCH_PROVIDER_2 = 1 << 3, |
| 329 }; |
| 330 |
| 331 // Constructs yet another evaluation program to specifically test that loaded |
| 332 // module digests are included in the input as expected. We will re-purpose the |
| 333 // output bitmasks to channel out information about the outcome of the checks. |
| 334 // |
| 335 // More specifically, the output of the program will be as follows: |
| 336 // { |
| 337 // "combined_status_mask_bit1": |
| 338 // (input["loaded_modules.*"] == kTestModuleDigest) |
| 339 // "combined_status_mask_bit2": |
| 340 // (input["loaded_modules.*"] == kTestModuleDigest2) |
| 341 // } |
| 342 std::string ConstructProgramToCheckLoadedModuleDigests() { |
| 343 std::string bytecode; |
| 344 bytecode += OP_NAVIGATE(GetHash("loaded_modules")); |
| 345 bytecode += OP_NAVIGATE_ANY; |
| 346 bytecode += OP_COMPARE_NODE_HASH(GetHash(kTestModuleDigest)); |
| 347 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit1"), |
| 348 EncodeBool(true)); |
| 349 bytecode += OP_END_OF_SENTENCE; |
| 350 bytecode += OP_NAVIGATE(GetHash("loaded_modules")); |
| 351 bytecode += OP_NAVIGATE_ANY; |
| 352 bytecode += OP_COMPARE_NODE_HASH(GetHash(kTestModuleDigest2)); |
| 353 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit2"), |
| 354 EncodeBool(true)); |
| 355 bytecode += OP_END_OF_SENTENCE; |
| 356 return bytecode; |
| 357 } |
| 358 |
| 359 // Legend for the bitmask returned by the above program. |
| 360 enum CombinedStatusMaskLegendForCheckingLoadedModules { |
| 361 HAS_EXPECTED_MODULE_DIGEST_1 = 1 << 0, |
| 362 HAS_EXPECTED_MODULE_DIGEST_2 = 1 << 1, |
| 363 }; |
| 364 |
145 // Test fixtures ------------------------------------------------------------- | 365 // Test fixtures ------------------------------------------------------------- |
146 | 366 |
147 class AutomaticProfileResetterTestBase : public testing::Test { | 367 class AutomaticProfileResetterTestBase : public testing::Test { |
148 protected: | 368 protected: |
149 explicit AutomaticProfileResetterTestBase( | 369 explicit AutomaticProfileResetterTestBase( |
150 const std::string& experiment_group_name) | 370 const std::string& experiment_group_name) |
151 : local_state_(TestingBrowserProcess::GetGlobal()), | 371 : local_state_(TestingBrowserProcess::GetGlobal()), |
| 372 profile_(new TestingProfile()), |
152 experiment_group_name_(experiment_group_name), | 373 experiment_group_name_(experiment_group_name), |
153 mock_delegate_(NULL) { | 374 mock_delegate_(NULL) { |
154 // Make sure the factory is not optimized away, so prefs get registered. | 375 // Make sure the factory is not optimized away, so whatever preferences it |
| 376 // wants to register will actually get registered. |
155 AutomaticProfileResetterFactory::GetInstance(); | 377 AutomaticProfileResetterFactory::GetInstance(); |
| 378 |
| 379 // Register some additional local state preferences for testing purposes. |
| 380 PrefRegistrySimple* local_state_registry = local_state_.Get()->registry(); |
| 381 DCHECK(local_state_registry); |
| 382 local_state_registry->RegisterStringPref(kTestPreferencePath, ""); |
| 383 |
| 384 // Register some additional user preferences for testing purposes. |
| 385 user_prefs::PrefRegistrySyncable* user_prefs_registry = |
| 386 profile_->GetTestingPrefService()->registry(); |
| 387 DCHECK(user_prefs_registry); |
| 388 user_prefs_registry->RegisterStringPref( |
| 389 kTestPreferencePath, |
| 390 "", |
| 391 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
156 } | 392 } |
157 | 393 |
158 virtual void SetUp() OVERRIDE { | 394 virtual void SetUp() OVERRIDE { |
159 profile_.reset(new TestingProfile()); | |
160 field_trials_.reset(new base::FieldTrialList(NULL)); | 395 field_trials_.reset(new base::FieldTrialList(NULL)); |
161 base::FieldTrialList::CreateFieldTrial(kAutomaticProfileResetStudyName, | 396 base::FieldTrialList::CreateFieldTrial(kAutomaticProfileResetStudyName, |
162 experiment_group_name_); | 397 experiment_group_name_); |
163 mock_delegate_ = new testing::StrictMock<MockProfileResetterDelegate>(); | 398 mock_delegate_ = new testing::StrictMock<MockProfileResetterDelegate>(); |
164 resetter_.reset(new AutomaticProfileResetter(profile_.get())); | 399 resetter_.reset(new AutomaticProfileResetter(profile_.get())); |
165 } | 400 } |
166 | 401 |
167 void SetTestingHashSeed(const std::string& hash_seed) { | 402 void SetTestingHashSeed(const std::string& hash_seed) { |
168 testing_hash_seed_ = hash_seed; | 403 testing_hash_seed_ = hash_seed; |
169 } | 404 } |
170 | 405 |
171 void SetTestingProgram(const std::string& source_code) { | 406 void SetTestingProgram(const std::string& source_code) { |
172 testing_program_ = source_code; | 407 testing_program_ = source_code; |
173 } | 408 } |
174 | 409 |
175 void UnleashResetterAndWait() { | 410 void UnleashResetterAndWait() { |
176 resetter_->Initialize(); | |
177 resetter_->SetDelegateForTesting(mock_delegate_); // Takes ownership. | 411 resetter_->SetDelegateForTesting(mock_delegate_); // Takes ownership. |
178 resetter_->SetHashSeedForTesting(testing_hash_seed_); | 412 resetter_->SetHashSeedForTesting(testing_hash_seed_); |
179 resetter_->SetProgramForTesting(testing_program_); | 413 resetter_->SetProgramForTesting(testing_program_); |
| 414 |
| 415 resetter_->Activate(); |
180 base::RunLoop().RunUntilIdle(); | 416 base::RunLoop().RunUntilIdle(); |
181 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 417 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
182 base::RunLoop().RunUntilIdle(); | 418 base::RunLoop().RunUntilIdle(); |
183 } | 419 } |
184 | 420 |
185 TestingProfile* profile() { return profile_.get(); } | 421 TestingProfile* profile() { return profile_.get(); } |
| 422 TestingPrefServiceSimple* local_state() { return local_state_.Get(); } |
186 | 423 |
187 MockProfileResetterDelegate& mock_delegate() { return *mock_delegate_; } | 424 MockProfileResetterDelegate& mock_delegate() { return *mock_delegate_; } |
188 AutomaticProfileResetter* resetter() { return resetter_.get(); } | 425 AutomaticProfileResetter* resetter() { return resetter_.get(); } |
189 | 426 |
190 private: | 427 private: |
191 content::TestBrowserThreadBundle thread_bundle_; | 428 content::TestBrowserThreadBundle thread_bundle_; |
192 ScopedTestingLocalState local_state_; | 429 ScopedTestingLocalState local_state_; |
193 scoped_ptr<TestingProfile> profile_; | 430 scoped_ptr<TestingProfile> profile_; |
194 scoped_ptr<base::FieldTrialList> field_trials_; | 431 scoped_ptr<base::FieldTrialList> field_trials_; |
195 std::string experiment_group_name_; | 432 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()); | 487 LocalStateHostedPromptMemento memento_in_local_state(profile()); |
251 FileHostedPromptMementoSynchronous memento_in_file(profile()); | 488 FileHostedPromptMementoSynchronous memento_in_file(profile()); |
252 | 489 |
253 EXPECT_EQ("", memento_in_prefs.ReadValue()); | 490 EXPECT_EQ("", memento_in_prefs.ReadValue()); |
254 EXPECT_EQ("", memento_in_local_state.ReadValue()); | 491 EXPECT_EQ("", memento_in_local_state.ReadValue()); |
255 EXPECT_EQ("", memento_in_file.ReadValue()); | 492 EXPECT_EQ("", memento_in_file.ReadValue()); |
256 | 493 |
257 SetTestingProgram(ConstructProgram(false, false)); | 494 SetTestingProgram(ConstructProgram(false, false)); |
258 SetTestingHashSeed(kTestHashSeed); | 495 SetTestingHashSeed(kTestHashSeed); |
259 | 496 |
| 497 mock_delegate().ExpectCallsToWaitingMethods(); |
| 498 mock_delegate().ExpectCallsToGetterMethods(); |
260 EXPECT_CALL(mock_delegate(), ReportStatistics(0x00u, 0x00u)); | 499 EXPECT_CALL(mock_delegate(), ReportStatistics(0x00u, 0x00u)); |
261 | 500 |
262 UnleashResetterAndWait(); | 501 UnleashResetterAndWait(); |
263 | 502 |
264 EXPECT_EQ("", memento_in_prefs.ReadValue()); | 503 EXPECT_EQ("", memento_in_prefs.ReadValue()); |
265 EXPECT_EQ("", memento_in_local_state.ReadValue()); | 504 EXPECT_EQ("", memento_in_local_state.ReadValue()); |
266 EXPECT_EQ("", memento_in_file.ReadValue()); | 505 EXPECT_EQ("", memento_in_file.ReadValue()); |
267 } | 506 } |
268 | 507 |
269 TEST_F(AutomaticProfileResetterTestDryRun, OneConditionSatisfied) { | 508 TEST_F(AutomaticProfileResetterTestDryRun, OneConditionSatisfied) { |
270 PreferenceHostedPromptMemento memento_in_prefs(profile()); | 509 PreferenceHostedPromptMemento memento_in_prefs(profile()); |
271 LocalStateHostedPromptMemento memento_in_local_state(profile()); | 510 LocalStateHostedPromptMemento memento_in_local_state(profile()); |
272 FileHostedPromptMementoSynchronous memento_in_file(profile()); | 511 FileHostedPromptMementoSynchronous memento_in_file(profile()); |
273 | 512 |
274 EXPECT_EQ("", memento_in_prefs.ReadValue()); | 513 EXPECT_EQ("", memento_in_prefs.ReadValue()); |
275 EXPECT_EQ("", memento_in_local_state.ReadValue()); | 514 EXPECT_EQ("", memento_in_local_state.ReadValue()); |
276 EXPECT_EQ("", memento_in_file.ReadValue()); | 515 EXPECT_EQ("", memento_in_file.ReadValue()); |
277 | 516 |
278 SetTestingProgram(ConstructProgram(true, false)); | 517 SetTestingProgram(ConstructProgram(true, false)); |
279 SetTestingHashSeed(kTestHashSeed); | 518 SetTestingHashSeed(kTestHashSeed); |
280 | 519 |
| 520 mock_delegate().ExpectCallsToWaitingMethods(); |
| 521 mock_delegate().ExpectCallsToGetterMethods(); |
281 EXPECT_CALL(mock_delegate(), ReportStatistics(0x01u, 0x01u)); | 522 EXPECT_CALL(mock_delegate(), ReportStatistics(0x01u, 0x01u)); |
282 | 523 |
283 UnleashResetterAndWait(); | 524 UnleashResetterAndWait(); |
284 | 525 |
285 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); | 526 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); |
286 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); | 527 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); |
287 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); | 528 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); |
288 } | 529 } |
289 | 530 |
290 TEST_F(AutomaticProfileResetterTestDryRun, OtherConditionSatisfied) { | 531 TEST_F(AutomaticProfileResetterTestDryRun, OtherConditionSatisfied) { |
291 PreferenceHostedPromptMemento memento_in_prefs(profile()); | 532 PreferenceHostedPromptMemento memento_in_prefs(profile()); |
292 LocalStateHostedPromptMemento memento_in_local_state(profile()); | 533 LocalStateHostedPromptMemento memento_in_local_state(profile()); |
293 FileHostedPromptMementoSynchronous memento_in_file(profile()); | 534 FileHostedPromptMementoSynchronous memento_in_file(profile()); |
294 | 535 |
295 EXPECT_EQ("", memento_in_prefs.ReadValue()); | 536 EXPECT_EQ("", memento_in_prefs.ReadValue()); |
296 EXPECT_EQ("", memento_in_local_state.ReadValue()); | 537 EXPECT_EQ("", memento_in_local_state.ReadValue()); |
297 EXPECT_EQ("", memento_in_file.ReadValue()); | 538 EXPECT_EQ("", memento_in_file.ReadValue()); |
298 | 539 |
299 SetTestingProgram(ConstructProgram(false, true)); | 540 SetTestingProgram(ConstructProgram(false, true)); |
300 SetTestingHashSeed(kTestHashSeed); | 541 SetTestingHashSeed(kTestHashSeed); |
301 | 542 |
| 543 mock_delegate().ExpectCallsToWaitingMethods(); |
| 544 mock_delegate().ExpectCallsToGetterMethods(); |
302 EXPECT_CALL(mock_delegate(), ReportStatistics(0x02u, 0x01u)); | 545 EXPECT_CALL(mock_delegate(), ReportStatistics(0x02u, 0x01u)); |
303 | 546 |
304 UnleashResetterAndWait(); | 547 UnleashResetterAndWait(); |
305 | 548 |
306 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); | 549 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); |
307 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); | 550 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); |
308 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); | 551 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); |
309 } | 552 } |
310 | 553 |
311 TEST_F(AutomaticProfileResetterTestDryRun, | 554 TEST_F(AutomaticProfileResetterTestDryRun, |
312 ConditionsSatisfiedAndInvalidMementos) { | 555 ConditionsSatisfiedAndInvalidMementos) { |
313 PreferenceHostedPromptMemento memento_in_prefs(profile()); | 556 PreferenceHostedPromptMemento memento_in_prefs(profile()); |
314 LocalStateHostedPromptMemento memento_in_local_state(profile()); | 557 LocalStateHostedPromptMemento memento_in_local_state(profile()); |
315 FileHostedPromptMementoSynchronous memento_in_file(profile()); | 558 FileHostedPromptMementoSynchronous memento_in_file(profile()); |
316 | 559 |
317 memento_in_prefs.StoreValue(kTestInvalidMementoValue); | 560 memento_in_prefs.StoreValue(kTestInvalidMementoValue); |
318 memento_in_local_state.StoreValue(kTestInvalidMementoValue); | 561 memento_in_local_state.StoreValue(kTestInvalidMementoValue); |
319 memento_in_file.StoreValue(kTestInvalidMementoValue); | 562 memento_in_file.StoreValue(kTestInvalidMementoValue); |
320 | 563 |
321 SetTestingProgram(ConstructProgram(true, true)); | 564 SetTestingProgram(ConstructProgram(true, true)); |
322 SetTestingHashSeed(kTestHashSeed); | 565 SetTestingHashSeed(kTestHashSeed); |
323 | 566 |
| 567 mock_delegate().ExpectCallsToWaitingMethods(); |
| 568 mock_delegate().ExpectCallsToGetterMethods(); |
324 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x01u)); | 569 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x01u)); |
325 | 570 |
326 UnleashResetterAndWait(); | 571 UnleashResetterAndWait(); |
327 | 572 |
328 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); | 573 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); |
329 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); | 574 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); |
330 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); | 575 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); |
331 } | 576 } |
332 | 577 |
333 TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadPrefHostedMemento) { | 578 TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadPrefHostedMemento) { |
334 PreferenceHostedPromptMemento memento_in_prefs(profile()); | 579 PreferenceHostedPromptMemento memento_in_prefs(profile()); |
335 LocalStateHostedPromptMemento memento_in_local_state(profile()); | 580 LocalStateHostedPromptMemento memento_in_local_state(profile()); |
336 FileHostedPromptMementoSynchronous memento_in_file(profile()); | 581 FileHostedPromptMementoSynchronous memento_in_file(profile()); |
337 | 582 |
338 memento_in_prefs.StoreValue(kTestMementoValue); | 583 memento_in_prefs.StoreValue(kTestMementoValue); |
339 | 584 |
340 SetTestingProgram(ConstructProgram(true, true)); | 585 SetTestingProgram(ConstructProgram(true, true)); |
341 SetTestingHashSeed(kTestHashSeed); | 586 SetTestingHashSeed(kTestHashSeed); |
342 | 587 |
| 588 mock_delegate().ExpectCallsToWaitingMethods(); |
| 589 mock_delegate().ExpectCallsToGetterMethods(); |
343 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x03u)); | 590 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x03u)); |
344 | 591 |
345 UnleashResetterAndWait(); | 592 UnleashResetterAndWait(); |
346 | 593 |
347 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); | 594 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); |
348 EXPECT_EQ("", memento_in_local_state.ReadValue()); | 595 EXPECT_EQ("", memento_in_local_state.ReadValue()); |
349 EXPECT_EQ("", memento_in_file.ReadValue()); | 596 EXPECT_EQ("", memento_in_file.ReadValue()); |
350 } | 597 } |
351 | 598 |
352 TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadLocalStateHostedMemento) { | 599 TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadLocalStateHostedMemento) { |
353 PreferenceHostedPromptMemento memento_in_prefs(profile()); | 600 PreferenceHostedPromptMemento memento_in_prefs(profile()); |
354 LocalStateHostedPromptMemento memento_in_local_state(profile()); | 601 LocalStateHostedPromptMemento memento_in_local_state(profile()); |
355 FileHostedPromptMementoSynchronous memento_in_file(profile()); | 602 FileHostedPromptMementoSynchronous memento_in_file(profile()); |
356 | 603 |
357 memento_in_local_state.StoreValue(kTestMementoValue); | 604 memento_in_local_state.StoreValue(kTestMementoValue); |
358 | 605 |
359 SetTestingProgram(ConstructProgram(true, true)); | 606 SetTestingProgram(ConstructProgram(true, true)); |
360 SetTestingHashSeed(kTestHashSeed); | 607 SetTestingHashSeed(kTestHashSeed); |
361 | 608 |
| 609 mock_delegate().ExpectCallsToWaitingMethods(); |
| 610 mock_delegate().ExpectCallsToGetterMethods(); |
362 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x05u)); | 611 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x05u)); |
363 | 612 |
364 UnleashResetterAndWait(); | 613 UnleashResetterAndWait(); |
365 | 614 |
366 EXPECT_EQ("", memento_in_prefs.ReadValue()); | 615 EXPECT_EQ("", memento_in_prefs.ReadValue()); |
367 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); | 616 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); |
368 EXPECT_EQ("", memento_in_file.ReadValue()); | 617 EXPECT_EQ("", memento_in_file.ReadValue()); |
369 } | 618 } |
370 | 619 |
371 TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadFileHostedMemento) { | 620 TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadFileHostedMemento) { |
372 PreferenceHostedPromptMemento memento_in_prefs(profile()); | 621 PreferenceHostedPromptMemento memento_in_prefs(profile()); |
373 LocalStateHostedPromptMemento memento_in_local_state(profile()); | 622 LocalStateHostedPromptMemento memento_in_local_state(profile()); |
374 FileHostedPromptMementoSynchronous memento_in_file(profile()); | 623 FileHostedPromptMementoSynchronous memento_in_file(profile()); |
375 | 624 |
376 memento_in_file.StoreValue(kTestMementoValue); | 625 memento_in_file.StoreValue(kTestMementoValue); |
377 | 626 |
378 SetTestingProgram(ConstructProgram(true, true)); | 627 SetTestingProgram(ConstructProgram(true, true)); |
379 SetTestingHashSeed(kTestHashSeed); | 628 SetTestingHashSeed(kTestHashSeed); |
380 | 629 |
| 630 mock_delegate().ExpectCallsToWaitingMethods(); |
| 631 mock_delegate().ExpectCallsToGetterMethods(); |
381 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x09u)); | 632 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x09u)); |
382 | 633 |
383 UnleashResetterAndWait(); | 634 UnleashResetterAndWait(); |
384 | 635 |
385 EXPECT_EQ("", memento_in_prefs.ReadValue()); | 636 EXPECT_EQ("", memento_in_prefs.ReadValue()); |
386 EXPECT_EQ("", memento_in_local_state.ReadValue()); | 637 EXPECT_EQ("", memento_in_local_state.ReadValue()); |
387 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); | 638 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); |
388 } | 639 } |
389 | 640 |
390 TEST_F(AutomaticProfileResetterTestDryRun, DoNothingWhenResourcesAreMissing) { | 641 TEST_F(AutomaticProfileResetterTestDryRun, DoNothingWhenResourcesAreMissing) { |
(...skipping 18 matching lines...) Expand all Loading... |
409 LocalStateHostedPromptMemento memento_in_local_state(profile()); | 660 LocalStateHostedPromptMemento memento_in_local_state(profile()); |
410 FileHostedPromptMementoSynchronous memento_in_file(profile()); | 661 FileHostedPromptMementoSynchronous memento_in_file(profile()); |
411 | 662 |
412 EXPECT_EQ("", memento_in_prefs.ReadValue()); | 663 EXPECT_EQ("", memento_in_prefs.ReadValue()); |
413 EXPECT_EQ("", memento_in_local_state.ReadValue()); | 664 EXPECT_EQ("", memento_in_local_state.ReadValue()); |
414 EXPECT_EQ("", memento_in_file.ReadValue()); | 665 EXPECT_EQ("", memento_in_file.ReadValue()); |
415 | 666 |
416 SetTestingProgram(ConstructProgram(false, false)); | 667 SetTestingProgram(ConstructProgram(false, false)); |
417 SetTestingHashSeed(kTestHashSeed); | 668 SetTestingHashSeed(kTestHashSeed); |
418 | 669 |
| 670 mock_delegate().ExpectCallsToWaitingMethods(); |
| 671 mock_delegate().ExpectCallsToGetterMethods(); |
419 EXPECT_CALL(mock_delegate(), ReportStatistics(0x00u, 0x00u)); | 672 EXPECT_CALL(mock_delegate(), ReportStatistics(0x00u, 0x00u)); |
420 | 673 |
421 UnleashResetterAndWait(); | 674 UnleashResetterAndWait(); |
422 | 675 |
423 EXPECT_EQ("", memento_in_prefs.ReadValue()); | 676 EXPECT_EQ("", memento_in_prefs.ReadValue()); |
424 EXPECT_EQ("", memento_in_local_state.ReadValue()); | 677 EXPECT_EQ("", memento_in_local_state.ReadValue()); |
425 EXPECT_EQ("", memento_in_file.ReadValue()); | 678 EXPECT_EQ("", memento_in_file.ReadValue()); |
426 } | 679 } |
427 | 680 |
428 TEST_F(AutomaticProfileResetterTest, OneConditionSatisfied) { | 681 TEST_F(AutomaticProfileResetterTest, OneConditionSatisfied) { |
429 PreferenceHostedPromptMemento memento_in_prefs(profile()); | 682 PreferenceHostedPromptMemento memento_in_prefs(profile()); |
430 LocalStateHostedPromptMemento memento_in_local_state(profile()); | 683 LocalStateHostedPromptMemento memento_in_local_state(profile()); |
431 FileHostedPromptMementoSynchronous memento_in_file(profile()); | 684 FileHostedPromptMementoSynchronous memento_in_file(profile()); |
432 | 685 |
433 EXPECT_EQ("", memento_in_prefs.ReadValue()); | 686 EXPECT_EQ("", memento_in_prefs.ReadValue()); |
434 EXPECT_EQ("", memento_in_local_state.ReadValue()); | 687 EXPECT_EQ("", memento_in_local_state.ReadValue()); |
435 EXPECT_EQ("", memento_in_file.ReadValue()); | 688 EXPECT_EQ("", memento_in_file.ReadValue()); |
436 | 689 |
437 SetTestingProgram(ConstructProgram(true, false)); | 690 SetTestingProgram(ConstructProgram(true, false)); |
438 SetTestingHashSeed(kTestHashSeed); | 691 SetTestingHashSeed(kTestHashSeed); |
439 | 692 |
| 693 mock_delegate().ExpectCallsToWaitingMethods(); |
| 694 mock_delegate().ExpectCallsToGetterMethods(); |
440 EXPECT_CALL(mock_delegate(), ShowPrompt()); | 695 EXPECT_CALL(mock_delegate(), ShowPrompt()); |
441 EXPECT_CALL(mock_delegate(), ReportStatistics(0x01u, 0x01u)); | 696 EXPECT_CALL(mock_delegate(), ReportStatistics(0x01u, 0x01u)); |
442 | 697 |
443 UnleashResetterAndWait(); | 698 UnleashResetterAndWait(); |
444 | 699 |
445 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); | 700 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); |
446 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); | 701 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); |
447 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); | 702 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); |
448 } | 703 } |
449 | 704 |
450 TEST_F(AutomaticProfileResetterTest, OtherConditionSatisfied) { | 705 TEST_F(AutomaticProfileResetterTest, OtherConditionSatisfied) { |
451 PreferenceHostedPromptMemento memento_in_prefs(profile()); | 706 PreferenceHostedPromptMemento memento_in_prefs(profile()); |
452 LocalStateHostedPromptMemento memento_in_local_state(profile()); | 707 LocalStateHostedPromptMemento memento_in_local_state(profile()); |
453 FileHostedPromptMementoSynchronous memento_in_file(profile()); | 708 FileHostedPromptMementoSynchronous memento_in_file(profile()); |
454 | 709 |
455 EXPECT_EQ("", memento_in_prefs.ReadValue()); | 710 EXPECT_EQ("", memento_in_prefs.ReadValue()); |
456 EXPECT_EQ("", memento_in_local_state.ReadValue()); | 711 EXPECT_EQ("", memento_in_local_state.ReadValue()); |
457 EXPECT_EQ("", memento_in_file.ReadValue()); | 712 EXPECT_EQ("", memento_in_file.ReadValue()); |
458 | 713 |
459 SetTestingProgram(ConstructProgram(false, true)); | 714 SetTestingProgram(ConstructProgram(false, true)); |
460 SetTestingHashSeed(kTestHashSeed); | 715 SetTestingHashSeed(kTestHashSeed); |
461 | 716 |
| 717 mock_delegate().ExpectCallsToWaitingMethods(); |
| 718 mock_delegate().ExpectCallsToGetterMethods(); |
462 EXPECT_CALL(mock_delegate(), ShowPrompt()); | 719 EXPECT_CALL(mock_delegate(), ShowPrompt()); |
463 EXPECT_CALL(mock_delegate(), ReportStatistics(0x02u, 0x01u)); | 720 EXPECT_CALL(mock_delegate(), ReportStatistics(0x02u, 0x01u)); |
464 | 721 |
465 UnleashResetterAndWait(); | 722 UnleashResetterAndWait(); |
466 | 723 |
467 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); | 724 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); |
468 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); | 725 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); |
469 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); | 726 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); |
470 } | 727 } |
471 | 728 |
472 TEST_F(AutomaticProfileResetterTest, ConditionsSatisfiedAndInvalidMementos) { | 729 TEST_F(AutomaticProfileResetterTest, ConditionsSatisfiedAndInvalidMementos) { |
473 PreferenceHostedPromptMemento memento_in_prefs(profile()); | 730 PreferenceHostedPromptMemento memento_in_prefs(profile()); |
474 LocalStateHostedPromptMemento memento_in_local_state(profile()); | 731 LocalStateHostedPromptMemento memento_in_local_state(profile()); |
475 FileHostedPromptMementoSynchronous memento_in_file(profile()); | 732 FileHostedPromptMementoSynchronous memento_in_file(profile()); |
476 | 733 |
477 memento_in_prefs.StoreValue(kTestInvalidMementoValue); | 734 memento_in_prefs.StoreValue(kTestInvalidMementoValue); |
478 memento_in_local_state.StoreValue(kTestInvalidMementoValue); | 735 memento_in_local_state.StoreValue(kTestInvalidMementoValue); |
479 memento_in_file.StoreValue(kTestInvalidMementoValue); | 736 memento_in_file.StoreValue(kTestInvalidMementoValue); |
480 | 737 |
481 SetTestingProgram(ConstructProgram(true, true)); | 738 SetTestingProgram(ConstructProgram(true, true)); |
482 SetTestingHashSeed(kTestHashSeed); | 739 SetTestingHashSeed(kTestHashSeed); |
483 | 740 |
| 741 mock_delegate().ExpectCallsToWaitingMethods(); |
| 742 mock_delegate().ExpectCallsToGetterMethods(); |
484 EXPECT_CALL(mock_delegate(), ShowPrompt()); | 743 EXPECT_CALL(mock_delegate(), ShowPrompt()); |
485 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x01u)); | 744 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x01u)); |
486 | 745 |
487 UnleashResetterAndWait(); | 746 UnleashResetterAndWait(); |
488 | 747 |
489 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); | 748 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); |
490 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); | 749 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); |
491 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); | 750 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); |
492 } | 751 } |
493 | 752 |
494 TEST_F(AutomaticProfileResetterTest, PrefHostedMementoPreventsPrompt) { | 753 TEST_F(AutomaticProfileResetterTest, PrefHostedMementoPreventsPrompt) { |
495 PreferenceHostedPromptMemento memento_in_prefs(profile()); | 754 PreferenceHostedPromptMemento memento_in_prefs(profile()); |
496 LocalStateHostedPromptMemento memento_in_local_state(profile()); | 755 LocalStateHostedPromptMemento memento_in_local_state(profile()); |
497 FileHostedPromptMementoSynchronous memento_in_file(profile()); | 756 FileHostedPromptMementoSynchronous memento_in_file(profile()); |
498 | 757 |
499 memento_in_prefs.StoreValue(kTestMementoValue); | 758 memento_in_prefs.StoreValue(kTestMementoValue); |
500 | 759 |
501 SetTestingProgram(ConstructProgram(true, true)); | 760 SetTestingProgram(ConstructProgram(true, true)); |
502 SetTestingHashSeed(kTestHashSeed); | 761 SetTestingHashSeed(kTestHashSeed); |
503 | 762 |
| 763 mock_delegate().ExpectCallsToWaitingMethods(); |
| 764 mock_delegate().ExpectCallsToGetterMethods(); |
504 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x03u)); | 765 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x03u)); |
505 | 766 |
506 UnleashResetterAndWait(); | 767 UnleashResetterAndWait(); |
507 | 768 |
508 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); | 769 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); |
509 EXPECT_EQ("", memento_in_local_state.ReadValue()); | 770 EXPECT_EQ("", memento_in_local_state.ReadValue()); |
510 EXPECT_EQ("", memento_in_file.ReadValue()); | 771 EXPECT_EQ("", memento_in_file.ReadValue()); |
511 } | 772 } |
512 | 773 |
513 TEST_F(AutomaticProfileResetterTest, LocalStateHostedMementoPreventsPrompt) { | 774 TEST_F(AutomaticProfileResetterTest, LocalStateHostedMementoPreventsPrompt) { |
514 PreferenceHostedPromptMemento memento_in_prefs(profile()); | 775 PreferenceHostedPromptMemento memento_in_prefs(profile()); |
515 LocalStateHostedPromptMemento memento_in_local_state(profile()); | 776 LocalStateHostedPromptMemento memento_in_local_state(profile()); |
516 FileHostedPromptMementoSynchronous memento_in_file(profile()); | 777 FileHostedPromptMementoSynchronous memento_in_file(profile()); |
517 | 778 |
518 memento_in_local_state.StoreValue(kTestMementoValue); | 779 memento_in_local_state.StoreValue(kTestMementoValue); |
519 | 780 |
520 SetTestingProgram(ConstructProgram(true, true)); | 781 SetTestingProgram(ConstructProgram(true, true)); |
521 SetTestingHashSeed(kTestHashSeed); | 782 SetTestingHashSeed(kTestHashSeed); |
522 | 783 |
| 784 mock_delegate().ExpectCallsToWaitingMethods(); |
| 785 mock_delegate().ExpectCallsToGetterMethods(); |
523 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x05u)); | 786 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x05u)); |
524 | 787 |
525 UnleashResetterAndWait(); | 788 UnleashResetterAndWait(); |
526 | 789 |
527 EXPECT_EQ("", memento_in_prefs.ReadValue()); | 790 EXPECT_EQ("", memento_in_prefs.ReadValue()); |
528 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); | 791 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); |
529 EXPECT_EQ("", memento_in_file.ReadValue()); | 792 EXPECT_EQ("", memento_in_file.ReadValue()); |
530 } | 793 } |
531 | 794 |
532 TEST_F(AutomaticProfileResetterTest, FileHostedMementoPreventsPrompt) { | 795 TEST_F(AutomaticProfileResetterTest, FileHostedMementoPreventsPrompt) { |
533 PreferenceHostedPromptMemento memento_in_prefs(profile()); | 796 PreferenceHostedPromptMemento memento_in_prefs(profile()); |
534 LocalStateHostedPromptMemento memento_in_local_state(profile()); | 797 LocalStateHostedPromptMemento memento_in_local_state(profile()); |
535 FileHostedPromptMementoSynchronous memento_in_file(profile()); | 798 FileHostedPromptMementoSynchronous memento_in_file(profile()); |
536 | 799 |
537 memento_in_file.StoreValue(kTestMementoValue); | 800 memento_in_file.StoreValue(kTestMementoValue); |
538 | 801 |
539 SetTestingProgram(ConstructProgram(true, true)); | 802 SetTestingProgram(ConstructProgram(true, true)); |
540 SetTestingHashSeed(kTestHashSeed); | 803 SetTestingHashSeed(kTestHashSeed); |
541 | 804 |
| 805 mock_delegate().ExpectCallsToWaitingMethods(); |
| 806 mock_delegate().ExpectCallsToGetterMethods(); |
542 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x09u)); | 807 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x09u)); |
543 | 808 |
544 UnleashResetterAndWait(); | 809 UnleashResetterAndWait(); |
545 | 810 |
546 EXPECT_EQ("", memento_in_prefs.ReadValue()); | 811 EXPECT_EQ("", memento_in_prefs.ReadValue()); |
547 EXPECT_EQ("", memento_in_local_state.ReadValue()); | 812 EXPECT_EQ("", memento_in_local_state.ReadValue()); |
548 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); | 813 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); |
549 } | 814 } |
550 | 815 |
551 TEST_F(AutomaticProfileResetterTest, DoNothingWhenResourcesAreMissing) { | 816 TEST_F(AutomaticProfileResetterTest, DoNothingWhenResourcesAreMissing) { |
552 PreferenceHostedPromptMemento memento_in_prefs(profile()); | 817 PreferenceHostedPromptMemento memento_in_prefs(profile()); |
553 LocalStateHostedPromptMemento memento_in_local_state(profile()); | 818 LocalStateHostedPromptMemento memento_in_local_state(profile()); |
554 FileHostedPromptMementoSynchronous memento_in_file(profile()); | 819 FileHostedPromptMementoSynchronous memento_in_file(profile()); |
555 | 820 |
556 SetTestingProgram(""); | 821 SetTestingProgram(""); |
557 SetTestingHashSeed(""); | 822 SetTestingHashSeed(""); |
558 | 823 |
559 // No calls are expected to the delegate. | 824 // No calls are expected to the delegate. |
560 | 825 |
561 UnleashResetterAndWait(); | 826 UnleashResetterAndWait(); |
562 | 827 |
563 EXPECT_EQ("", memento_in_prefs.ReadValue()); | 828 EXPECT_EQ("", memento_in_prefs.ReadValue()); |
564 EXPECT_EQ("", memento_in_local_state.ReadValue()); | 829 EXPECT_EQ("", memento_in_local_state.ReadValue()); |
565 EXPECT_EQ("", memento_in_file.ReadValue()); | 830 EXPECT_EQ("", memento_in_file.ReadValue()); |
566 } | 831 } |
567 | 832 |
| 833 // Please see comments above ConstructProgramToCheckPreferences() to understand |
| 834 // how the following tests work. |
| 835 |
| 836 TEST_F(AutomaticProfileResetterTest, InputUserPreferencesCorrect) { |
| 837 SetTestingProgram(ConstructProgramToCheckPreferences()); |
| 838 SetTestingHashSeed(kTestHashSeed); |
| 839 |
| 840 PrefService* prefs = profile()->GetPrefs(); |
| 841 prefs->SetString(kTestPreferencePath, kTestPreferenceValue); |
| 842 |
| 843 mock_delegate().ExpectCallsToWaitingMethods(); |
| 844 mock_delegate().ExpectCallsToGetterMethods(); |
| 845 uint32 expected_mask = |
| 846 HAS_EXPECTED_USER_PREFERENCE | USER_PREFERENCE_IS_USER_CONTROLLED; |
| 847 EXPECT_CALL(mock_delegate(), ReportStatistics(0x00u, expected_mask)); |
| 848 |
| 849 UnleashResetterAndWait(); |
| 850 } |
| 851 |
| 852 TEST_F(AutomaticProfileResetterTest, InputLocalStateCorrect) { |
| 853 SetTestingProgram(ConstructProgramToCheckPreferences()); |
| 854 SetTestingHashSeed(kTestHashSeed); |
| 855 |
| 856 PrefService* prefs = local_state(); |
| 857 prefs->SetString(kTestPreferencePath, kTestPreferenceValue); |
| 858 |
| 859 mock_delegate().ExpectCallsToWaitingMethods(); |
| 860 mock_delegate().ExpectCallsToGetterMethods(); |
| 861 uint32 expected_mask = |
| 862 HAS_EXPECTED_LOCAL_STATE_PREFERENCE | LOCAL_STATE_IS_USER_CONTROLLED; |
| 863 EXPECT_CALL(mock_delegate(), ReportStatistics(0x00u, expected_mask)); |
| 864 |
| 865 UnleashResetterAndWait(); |
| 866 } |
| 867 |
| 868 TEST_F(AutomaticProfileResetterTest, InputManagedUserPreferencesCorrect) { |
| 869 SetTestingProgram(ConstructProgramToCheckPreferences()); |
| 870 SetTestingHashSeed(kTestHashSeed); |
| 871 |
| 872 TestingPrefServiceSyncable* prefs = profile()->GetTestingPrefService(); |
| 873 prefs->SetManagedPref(kTestPreferencePath, |
| 874 new base::StringValue(kTestPreferenceValue)); |
| 875 |
| 876 mock_delegate().ExpectCallsToWaitingMethods(); |
| 877 mock_delegate().ExpectCallsToGetterMethods(); |
| 878 uint32 expected_mask = HAS_EXPECTED_USER_PREFERENCE; |
| 879 EXPECT_CALL(mock_delegate(), ReportStatistics(0x00u, expected_mask)); |
| 880 |
| 881 UnleashResetterAndWait(); |
| 882 } |
| 883 |
| 884 TEST_F(AutomaticProfileResetterTest, InputManagedLocalStateCorrect) { |
| 885 SetTestingProgram(ConstructProgramToCheckPreferences()); |
| 886 SetTestingHashSeed(kTestHashSeed); |
| 887 |
| 888 TestingPrefServiceSimple* prefs = local_state(); |
| 889 prefs->SetManagedPref(kTestPreferencePath, |
| 890 new base::StringValue(kTestPreferenceValue)); |
| 891 |
| 892 mock_delegate().ExpectCallsToWaitingMethods(); |
| 893 mock_delegate().ExpectCallsToGetterMethods(); |
| 894 uint32 expected_mask = HAS_EXPECTED_LOCAL_STATE_PREFERENCE; |
| 895 EXPECT_CALL(mock_delegate(), ReportStatistics(0x00u, expected_mask)); |
| 896 |
| 897 UnleashResetterAndWait(); |
| 898 } |
| 899 |
| 900 // Please see comments above ConstructProgramToCheckSearchEngines() to |
| 901 // understand how the following tests work. |
| 902 |
| 903 TEST_F(AutomaticProfileResetterTest, InputDefaultSearchProviderCorrect) { |
| 904 SetTestingProgram(ConstructProgramToCheckSearchEngines()); |
| 905 SetTestingHashSeed(kTestHashSeed); |
| 906 |
| 907 mock_delegate().emulated_default_search_provider_details().SetString( |
| 908 kSearchURLAttributeKey, kTestSearchURL); |
| 909 |
| 910 mock_delegate().ExpectCallsToWaitingMethods(); |
| 911 mock_delegate().ExpectCallsToGetterMethods(); |
| 912 uint32 expected_mask = HAS_EXPECTED_DEFAULT_SEARCH_PROVIDER | |
| 913 DEFAULT_SEARCH_PROVIDER_IS_USER_CONTROLLED; |
| 914 EXPECT_CALL(mock_delegate(), ReportStatistics(0x00u, expected_mask)); |
| 915 |
| 916 UnleashResetterAndWait(); |
| 917 } |
| 918 |
| 919 TEST_F(AutomaticProfileResetterTest, InputSearchProviderManagedCorrect) { |
| 920 SetTestingProgram(ConstructProgramToCheckSearchEngines()); |
| 921 SetTestingHashSeed(kTestHashSeed); |
| 922 |
| 923 mock_delegate().emulated_default_search_provider_details().SetString( |
| 924 kSearchURLAttributeKey, kTestSearchURL); |
| 925 mock_delegate().set_emulated_default_search_provider_is_managed(true); |
| 926 |
| 927 mock_delegate().ExpectCallsToWaitingMethods(); |
| 928 mock_delegate().ExpectCallsToGetterMethods(); |
| 929 uint32 expected_mask = HAS_EXPECTED_DEFAULT_SEARCH_PROVIDER; |
| 930 EXPECT_CALL(mock_delegate(), ReportStatistics(0x00u, expected_mask)); |
| 931 |
| 932 UnleashResetterAndWait(); |
| 933 } |
| 934 |
| 935 TEST_F(AutomaticProfileResetterTest, InputSearchProvidersCorrect) { |
| 936 SetTestingProgram(ConstructProgramToCheckSearchEngines()); |
| 937 SetTestingHashSeed(kTestHashSeed); |
| 938 |
| 939 base::DictionaryValue* search_provider_1 = new base::DictionaryValue; |
| 940 base::DictionaryValue* search_provider_2 = new base::DictionaryValue; |
| 941 search_provider_1->SetString(kSearchURLAttributeKey, kTestSearchURL); |
| 942 search_provider_2->SetString(kSearchURLAttributeKey, kTestSearchURL2); |
| 943 mock_delegate().emulated_search_providers_details().Append(search_provider_1); |
| 944 mock_delegate().emulated_search_providers_details().Append(search_provider_2); |
| 945 |
| 946 mock_delegate().ExpectCallsToWaitingMethods(); |
| 947 mock_delegate().ExpectCallsToGetterMethods(); |
| 948 uint32 expected_mask = DEFAULT_SEARCH_PROVIDER_IS_USER_CONTROLLED | |
| 949 HAS_EXPECTED_PREPOPULATED_SEARCH_PROVIDER_1 | |
| 950 HAS_EXPECTED_PREPOPULATED_SEARCH_PROVIDER_2; |
| 951 EXPECT_CALL(mock_delegate(), ReportStatistics(0x00u, expected_mask)); |
| 952 |
| 953 UnleashResetterAndWait(); |
| 954 } |
| 955 |
| 956 // Please see comments above ConstructProgramToCheckLoadedModuleDigests() to |
| 957 // understand how the following tests work. |
| 958 |
| 959 TEST_F(AutomaticProfileResetterTest, InputModuleDigestsCorrect) { |
| 960 SetTestingProgram(ConstructProgramToCheckLoadedModuleDigests()); |
| 961 SetTestingHashSeed(kTestHashSeed); |
| 962 |
| 963 mock_delegate().emulated_loaded_module_digests().AppendString( |
| 964 kTestModuleDigest); |
| 965 mock_delegate().emulated_loaded_module_digests().AppendString( |
| 966 kTestModuleDigest2); |
| 967 |
| 968 mock_delegate().ExpectCallsToWaitingMethods(); |
| 969 mock_delegate().ExpectCallsToGetterMethods(); |
| 970 uint32 expected_mask = |
| 971 HAS_EXPECTED_MODULE_DIGEST_1 | HAS_EXPECTED_MODULE_DIGEST_2; |
| 972 EXPECT_CALL(mock_delegate(), ReportStatistics(0x00u, expected_mask)); |
| 973 |
| 974 UnleashResetterAndWait(); |
| 975 } |
| 976 |
568 } // namespace | 977 } // namespace |
OLD | NEW |