Update broken references to image assets
[chromium-blink-merge.git] / chrome / browser / profile_resetter / automatic_profile_resetter_unittest.cc
bloba81849437b160dce4a542f5829244f4bf269ea39
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
3 // found in the LICENSE file.
5 #include "chrome/browser/profile_resetter/automatic_profile_resetter.h"
7 #include <string>
9 #include "base/bind.h"
10 #include "base/bind_helpers.h"
11 #include "base/metrics/field_trial.h"
12 #include "base/prefs/pref_registry_simple.h"
13 #include "base/prefs/testing_pref_service.h"
14 #include "base/run_loop.h"
15 #include "base/test/test_simple_task_runner.h"
16 #include "base/threading/sequenced_worker_pool.h"
17 #include "base/values.h"
18 #include "chrome/browser/profile_resetter/automatic_profile_resetter_delegate.h"
19 #include "chrome/browser/profile_resetter/automatic_profile_resetter_factory.h"
20 #include "chrome/browser/profile_resetter/automatic_profile_resetter_mementos.h"
21 #include "chrome/browser/profile_resetter/jtl_foundation.h"
22 #include "chrome/browser/profile_resetter/jtl_instructions.h"
23 #include "chrome/test/base/scoped_testing_local_state.h"
24 #include "chrome/test/base/testing_browser_process.h"
25 #include "chrome/test/base/testing_pref_service_syncable.h"
26 #include "chrome/test/base/testing_profile.h"
27 #include "components/pref_registry/pref_registry_syncable.h"
28 #include "components/variations/variations_associated_data.h"
29 #include "content/public/browser/browser_thread.h"
30 #include "content/public/test/test_browser_thread_bundle.h"
31 #include "testing/gmock/include/gmock/gmock.h"
32 #include "testing/gtest/include/gtest/gtest.h"
34 using testing::_;
36 namespace {
38 const char kAutomaticProfileResetStudyName[] = "AutomaticProfileReset";
39 const char kStudyDisabledGroupName[] = "Disabled";
40 const char kStudyDryRunGroupName[] = "DryRun";
41 const char kStudyEnabledGroupName[] = "Enabled";
43 const char kTestHashSeed[] = "testing-hash-seed";
44 const char kTestMementoValue[] = "01234567890123456789012345678901";
45 const char kTestInvalidMementoValue[] = "12345678901234567890123456789012";
47 const char kTestPreferencePath[] = "testing.preference";
48 const char kTestPreferenceValue[] = "testing-preference-value";
50 const char kSearchURLAttributeKey[] = "search_url";
51 const char kTestSearchURL[] = "http://example.com/search?q={searchTerms}";
52 const char kTestSearchURL2[] = "http://google.com/?q={searchTerms}";
54 const char kTestModuleDigest[] = "01234567890123456789012345678901";
55 const char kTestModuleDigest2[] = "12345678901234567890123456789012";
57 // Helpers ------------------------------------------------------------------
59 // A testing version of the AutomaticProfileResetter that differs from the real
60 // one only in that it has its statistics reporting mocked out for verification.
61 class AutomaticProfileResetterUnderTest : public AutomaticProfileResetter {
62 public:
63 explicit AutomaticProfileResetterUnderTest(Profile* profile)
64 : AutomaticProfileResetter(profile) {}
65 ~AutomaticProfileResetterUnderTest() override {}
67 MOCK_METHOD2(ReportStatistics, void(uint32, uint32));
68 MOCK_METHOD1(ReportPromptResult,
69 void(AutomaticProfileResetter::PromptResult));
71 private:
72 DISALLOW_COPY_AND_ASSIGN(AutomaticProfileResetterUnderTest);
75 class MockProfileResetterDelegate : public AutomaticProfileResetterDelegate {
76 public:
77 MockProfileResetterDelegate()
78 : emulated_is_default_search_provider_managed_(false) {}
79 ~MockProfileResetterDelegate() override {}
81 MOCK_METHOD0(EnumerateLoadedModulesIfNeeded, void());
82 MOCK_CONST_METHOD1(RequestCallbackWhenLoadedModulesAreEnumerated,
83 void(const base::Closure&));
85 MOCK_METHOD0(LoadTemplateURLServiceIfNeeded, void());
86 MOCK_CONST_METHOD1(RequestCallbackWhenTemplateURLServiceIsLoaded,
87 void(const base::Closure&));
89 MOCK_METHOD0(FetchBrandcodedDefaultSettingsIfNeeded, void());
90 MOCK_CONST_METHOD1(RequestCallbackWhenBrandcodedDefaultsAreFetched,
91 void(const base::Closure&));
93 MOCK_CONST_METHOD0(OnGetLoadedModuleNameDigestsCalled, void());
94 MOCK_CONST_METHOD0(OnGetDefaultSearchProviderDetailsCalled, void());
95 MOCK_CONST_METHOD0(OnIsDefaultSearchProviderManagedCalled, void());
96 MOCK_CONST_METHOD0(OnGetPrepopulatedSearchProvidersDetailsCalled, void());
98 MOCK_METHOD0(TriggerPrompt, bool());
99 MOCK_METHOD2(TriggerProfileSettingsReset, void(bool, const base::Closure&));
100 MOCK_METHOD0(DismissPrompt, void());
102 scoped_ptr<base::ListValue> GetLoadedModuleNameDigests() const override {
103 OnGetLoadedModuleNameDigestsCalled();
104 return scoped_ptr<base::ListValue>(
105 emulated_loaded_module_digests_.DeepCopy());
108 scoped_ptr<base::DictionaryValue>
109 GetDefaultSearchProviderDetails() const override {
110 OnGetDefaultSearchProviderDetailsCalled();
111 return scoped_ptr<base::DictionaryValue>(
112 emulated_default_search_provider_details_.DeepCopy());
115 bool IsDefaultSearchProviderManaged() const override {
116 OnIsDefaultSearchProviderManagedCalled();
117 return emulated_is_default_search_provider_managed_;
120 scoped_ptr<base::ListValue>
121 GetPrepopulatedSearchProvidersDetails() const override {
122 OnGetPrepopulatedSearchProvidersDetailsCalled();
123 return scoped_ptr<base::ListValue>(
124 emulated_search_providers_details_.DeepCopy());
127 static void ClosureInvoker(const base::Closure& closure) { closure.Run(); }
129 void ExpectCallsToDependenciesSetUpMethods() {
130 EXPECT_CALL(*this, EnumerateLoadedModulesIfNeeded());
131 EXPECT_CALL(*this, LoadTemplateURLServiceIfNeeded());
132 EXPECT_CALL(*this, RequestCallbackWhenLoadedModulesAreEnumerated(_))
133 .WillOnce(testing::Invoke(ClosureInvoker));
134 EXPECT_CALL(*this, RequestCallbackWhenTemplateURLServiceIsLoaded(_))
135 .WillOnce(testing::Invoke(ClosureInvoker));
138 void ExpectCallsToGetterMethods() {
139 EXPECT_CALL(*this, OnGetLoadedModuleNameDigestsCalled());
140 EXPECT_CALL(*this, OnGetDefaultSearchProviderDetailsCalled());
141 EXPECT_CALL(*this, OnIsDefaultSearchProviderManagedCalled());
142 EXPECT_CALL(*this, OnGetPrepopulatedSearchProvidersDetailsCalled());
145 void ExpectCallToShowPrompt() {
146 EXPECT_CALL(*this, TriggerPrompt()).WillOnce(testing::Return(true));
147 EXPECT_CALL(*this, FetchBrandcodedDefaultSettingsIfNeeded());
150 void ExpectCallToTriggerReset(bool send_feedback) {
151 EXPECT_CALL(*this, TriggerProfileSettingsReset(send_feedback, _))
152 .WillOnce(testing::SaveArg<1>(&reset_completion_));
155 base::DictionaryValue& emulated_default_search_provider_details() {
156 return emulated_default_search_provider_details_;
159 base::ListValue& emulated_search_providers_details() {
160 return emulated_search_providers_details_;
163 base::ListValue& emulated_loaded_module_digests() {
164 return emulated_loaded_module_digests_;
167 void set_emulated_is_default_search_provider_managed(bool value) {
168 emulated_is_default_search_provider_managed_ = value;
171 void EmulateProfileResetCompleted() {
172 reset_completion_.Run();
175 private:
176 base::DictionaryValue emulated_default_search_provider_details_;
177 base::ListValue emulated_search_providers_details_;
178 base::ListValue emulated_loaded_module_digests_;
179 bool emulated_is_default_search_provider_managed_;
180 base::Closure reset_completion_;
182 DISALLOW_COPY_AND_ASSIGN(MockProfileResetterDelegate);
185 class FileHostedPromptMementoSynchronous : protected FileHostedPromptMemento {
186 public:
187 explicit FileHostedPromptMementoSynchronous(Profile* profile)
188 : FileHostedPromptMemento(profile) {}
190 std::string ReadValue() const {
191 std::string result;
192 FileHostedPromptMemento::ReadValue(base::Bind(&AssignArgumentTo, &result));
193 base::RunLoop().RunUntilIdle();
194 return result;
197 void StoreValue(const std::string& value) {
198 FileHostedPromptMemento::StoreValue(value);
199 base::RunLoop().RunUntilIdle();
202 private:
203 static void AssignArgumentTo(std::string* target, const std::string& value) {
204 *target = value;
207 DISALLOW_COPY_AND_ASSIGN(FileHostedPromptMementoSynchronous);
210 std::string GetHash(const std::string& input) {
211 return jtl_foundation::Hasher(kTestHashSeed).GetHash(input);
214 // Encodes a Boolean argument value into JTL bytecode.
215 std::string EncodeBool(bool value) { return value ? VALUE_TRUE : VALUE_FALSE; }
217 // Constructs a simple evaluation program to test that basic input/output works
218 // well. It will emulate a scenario in which the reset criteria are satisfied as
219 // prescribed by |emulate_satisfied_criterion_{1|2}|, and the reset is triggered
220 // when either of them is true. The bits in the combined status mask will be set
221 // according to whether or not the memento values received in the input were as
222 // expected.
224 // More specifically, the output of the program will be as follows:
225 // {
226 // "satisfied_criteria_mask_bit1": emulate_satisfied_criterion_1,
227 // "satisfied_criteria_mask_bit2": emulate_satisfied_criterion_2,
228 // "combined_status_mask_bit1":
229 // (emulate_satisfied_criterion_1 || emulate_satisfied_criterion_2),
230 // "combined_status_mask_bit2":
231 // (input["memento_value_in_prefs"] == kTestMementoValue),
232 // "combined_status_mask_bit3":
233 // (input["memento_value_in_local_state"] == kTestMementoValue),
234 // "combined_status_mask_bit4":
235 // (input["memento_value_in_file"] == kTestMementoValue),
236 // "should_prompt":
237 // (emulate_satisfied_criterion_1 || emulate_satisfied_criterion_2),
238 // "had_prompted_already": <OR-combination of above three>,
239 // "memento_value_in_prefs": kTestMementoValue,
240 // "memento_value_in_local_state": kTestMementoValue,
241 // "memento_value_in_file": kTestMementoValue
242 // }
243 std::string ConstructProgram(bool emulate_satisfied_criterion_1,
244 bool emulate_satisfied_criterion_2) {
245 std::string bytecode;
246 bytecode += OP_STORE_BOOL(GetHash("satisfied_criteria_mask_bit1"),
247 EncodeBool(emulate_satisfied_criterion_1));
248 bytecode += OP_END_OF_SENTENCE;
249 bytecode += OP_STORE_BOOL(GetHash("satisfied_criteria_mask_bit2"),
250 EncodeBool(emulate_satisfied_criterion_2));
251 bytecode += OP_END_OF_SENTENCE;
252 bytecode += OP_STORE_BOOL(GetHash("should_prompt"),
253 EncodeBool(emulate_satisfied_criterion_1 ||
254 emulate_satisfied_criterion_2));
255 bytecode += OP_END_OF_SENTENCE;
256 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit1"),
257 EncodeBool(emulate_satisfied_criterion_1 ||
258 emulate_satisfied_criterion_2));
259 bytecode += OP_END_OF_SENTENCE;
260 bytecode += OP_NAVIGATE(GetHash("memento_value_in_prefs"));
261 bytecode += OP_COMPARE_NODE_HASH(GetHash(kTestMementoValue));
262 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit2"), VALUE_TRUE);
263 bytecode += OP_STORE_BOOL(GetHash("had_prompted_already"), VALUE_TRUE);
264 bytecode += OP_END_OF_SENTENCE;
265 bytecode += OP_NAVIGATE(GetHash("memento_value_in_local_state"));
266 bytecode += OP_COMPARE_NODE_HASH(GetHash(kTestMementoValue));
267 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit3"), VALUE_TRUE);
268 bytecode += OP_STORE_BOOL(GetHash("had_prompted_already"), VALUE_TRUE);
269 bytecode += OP_END_OF_SENTENCE;
270 bytecode += OP_NAVIGATE(GetHash("memento_value_in_file"));
271 bytecode += OP_COMPARE_NODE_HASH(GetHash(kTestMementoValue));
272 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit4"), VALUE_TRUE);
273 bytecode += OP_STORE_BOOL(GetHash("had_prompted_already"), VALUE_TRUE);
274 bytecode += OP_END_OF_SENTENCE;
275 bytecode += OP_STORE_HASH(GetHash("memento_value_in_prefs"),
276 kTestMementoValue);
277 bytecode += OP_END_OF_SENTENCE;
278 bytecode += OP_STORE_HASH(GetHash("memento_value_in_local_state"),
279 kTestMementoValue);
280 bytecode += OP_END_OF_SENTENCE;
281 bytecode += OP_STORE_HASH(GetHash("memento_value_in_file"),
282 kTestMementoValue);
283 bytecode += OP_END_OF_SENTENCE;
284 return bytecode;
287 // Constructs another evaluation program to specifically test that bits of the
288 // "satisfied_criteria_mask" are correctly assigned, and so is "should_prompt";
289 // and that reset is triggered iff the latter is true, regardless of the bits
290 // in the mask (so as to allow for a non-disjunctive compound criterion).
292 // More specifically, the output of the program will be as follows:
293 // {
294 // "satisfied_criteria_mask_bitN": emulate_satisfied_odd_criteria,
295 // "satisfied_criteria_mask_bitM": emulate_satisfied_even_criteria,
296 // "combined_status_mask_bit1": emulate_should_prompt,
297 // "should_prompt": emulate_should_prompt,
298 // "memento_value_in_prefs": kTestMementoValue,
299 // "memento_value_in_local_state": kTestMementoValue,
300 // "memento_value_in_file": kTestMementoValue
301 // }
302 // ... such that N is {1,3,5} and M is {2,4}.
303 std::string ConstructProgramToExerciseCriteria(
304 bool emulate_should_prompt,
305 bool emulate_satisfied_odd_criteria,
306 bool emulate_satisfied_even_criteria) {
307 std::string bytecode;
308 bytecode += OP_STORE_BOOL(GetHash("satisfied_criteria_mask_bit1"),
309 EncodeBool(emulate_satisfied_odd_criteria));
310 bytecode += OP_END_OF_SENTENCE;
311 bytecode += OP_STORE_BOOL(GetHash("satisfied_criteria_mask_bit3"),
312 EncodeBool(emulate_satisfied_odd_criteria));
313 bytecode += OP_END_OF_SENTENCE;
314 bytecode += OP_STORE_BOOL(GetHash("satisfied_criteria_mask_bit5"),
315 EncodeBool(emulate_satisfied_odd_criteria));
316 bytecode += OP_END_OF_SENTENCE;
317 bytecode += OP_STORE_BOOL(GetHash("satisfied_criteria_mask_bit2"),
318 EncodeBool(emulate_satisfied_even_criteria));
319 bytecode += OP_END_OF_SENTENCE;
320 bytecode += OP_STORE_BOOL(GetHash("satisfied_criteria_mask_bit4"),
321 EncodeBool(emulate_satisfied_even_criteria));
322 bytecode += OP_END_OF_SENTENCE;
323 bytecode += OP_STORE_BOOL(GetHash("should_prompt"),
324 EncodeBool(emulate_should_prompt));
325 bytecode += OP_END_OF_SENTENCE;
326 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit1"),
327 EncodeBool(emulate_should_prompt));
328 bytecode += OP_END_OF_SENTENCE;
329 bytecode += OP_STORE_HASH(GetHash("memento_value_in_prefs"),
330 kTestMementoValue);
331 bytecode += OP_END_OF_SENTENCE;
332 bytecode += OP_STORE_HASH(GetHash("memento_value_in_local_state"),
333 kTestMementoValue);
334 bytecode += OP_END_OF_SENTENCE;
335 bytecode += OP_STORE_HASH(GetHash("memento_value_in_file"),
336 kTestMementoValue);
337 bytecode += OP_END_OF_SENTENCE;
338 return bytecode;
341 // Constructs another evaluation program to specifically test that local state
342 // and user preference values are included in the input as expected. We will
343 // re-purpose the output bitmasks to channel out information about the outcome
344 // of the checks.
346 // More specifically, the output of the program will be as follows:
347 // {
348 // "combined_status_mask_bit1":
349 // (input["preferences.testing.preference"] == kTestPreferenceValue)
350 // "combined_status_mask_bit2":
351 // (input["local_state.testing.preference"] == kTestPreferenceValue)
352 // "combined_status_mask_bit3": input["preferences_iuc.testing.preference"]
353 // "combined_status_mask_bit4": input["local_state_iuc.testing.preference"]
354 // }
355 std::string ConstructProgramToCheckPreferences() {
356 std::string bytecode;
357 bytecode += OP_NAVIGATE(GetHash("preferences"));
358 bytecode += OP_NAVIGATE(GetHash("testing"));
359 bytecode += OP_NAVIGATE(GetHash("preference"));
360 bytecode += OP_COMPARE_NODE_HASH(GetHash(kTestPreferenceValue));
361 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit1"),
362 EncodeBool(true));
363 bytecode += OP_END_OF_SENTENCE;
364 bytecode += OP_NAVIGATE(GetHash("local_state"));
365 bytecode += OP_NAVIGATE(GetHash("testing"));
366 bytecode += OP_NAVIGATE(GetHash("preference"));
367 bytecode += OP_COMPARE_NODE_HASH(GetHash(kTestPreferenceValue));
368 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit2"),
369 EncodeBool(true));
370 bytecode += OP_END_OF_SENTENCE;
371 bytecode += OP_NAVIGATE(GetHash("preferences_iuc"));
372 bytecode += OP_NAVIGATE(GetHash("testing"));
373 bytecode += OP_NAVIGATE(GetHash("preference"));
374 bytecode += OP_COMPARE_NODE_BOOL(EncodeBool(true));
375 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit3"),
376 EncodeBool(true));
377 bytecode += OP_END_OF_SENTENCE;
378 bytecode += OP_NAVIGATE(GetHash("local_state_iuc"));
379 bytecode += OP_NAVIGATE(GetHash("testing"));
380 bytecode += OP_NAVIGATE(GetHash("preference"));
381 bytecode += OP_COMPARE_NODE_BOOL(EncodeBool(true));
382 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit4"),
383 EncodeBool(true));
384 bytecode += OP_END_OF_SENTENCE;
385 return bytecode;
388 // Legend for the bitmask returned by the above program.
389 enum CombinedStatusMaskLegendForCheckingPreferences {
390 HAS_EXPECTED_USER_PREFERENCE = 1 << 0,
391 HAS_EXPECTED_LOCAL_STATE_PREFERENCE = 1 << 1,
392 USER_PREFERENCE_IS_USER_CONTROLLED = 1 << 2,
393 LOCAL_STATE_IS_USER_CONTROLLED = 1 << 3,
396 // Constructs yet another evaluation program to specifically test that default
397 // and pre-populated search engines are included in the input as expected. We
398 // will re-purpose the output bitmasks to channel out information about the
399 // outcome of the checks.
401 // More specifically, the output of the program will be as follows:
402 // {
403 // "combined_status_mask_bit1":
404 // (input["default_search_provider.search_url"] == kTestSearchURL)
405 // "combined_status_mask_bit2": input["default_search_provider_iuc"]
406 // "combined_status_mask_bit3":
407 // (input["search_providers.*.search_url"] == kTestSearchURL)
408 // "combined_status_mask_bit4":
409 // (input["search_providers.*.search_url"] == kTestSearchURL2)
410 // }
411 std::string ConstructProgramToCheckSearchEngines() {
412 std::string bytecode;
413 bytecode += OP_NAVIGATE(GetHash("default_search_provider"));
414 bytecode += OP_NAVIGATE(GetHash("search_url"));
415 bytecode += OP_COMPARE_NODE_HASH(GetHash(kTestSearchURL));
416 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit1"),
417 EncodeBool(true));
418 bytecode += OP_END_OF_SENTENCE;
419 bytecode += OP_NAVIGATE(GetHash("default_search_provider_iuc"));
420 bytecode += OP_COMPARE_NODE_BOOL(EncodeBool(true));
421 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit2"),
422 EncodeBool(true));
423 bytecode += OP_END_OF_SENTENCE;
424 bytecode += OP_NAVIGATE(GetHash("search_providers"));
425 bytecode += OP_NAVIGATE_ANY;
426 bytecode += OP_NAVIGATE(GetHash("search_url"));
427 bytecode += OP_COMPARE_NODE_HASH(GetHash(kTestSearchURL));
428 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit3"),
429 EncodeBool(true));
430 bytecode += OP_END_OF_SENTENCE;
431 bytecode += OP_NAVIGATE(GetHash("search_providers"));
432 bytecode += OP_NAVIGATE_ANY;
433 bytecode += OP_NAVIGATE(GetHash("search_url"));
434 bytecode += OP_COMPARE_NODE_HASH(GetHash(kTestSearchURL2));
435 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit4"),
436 EncodeBool(true));
437 bytecode += OP_END_OF_SENTENCE;
438 return bytecode;
441 // Legend for the bitmask returned by the above program.
442 enum CombinedStatusMaskLegendForCheckingSearchEngines {
443 HAS_EXPECTED_DEFAULT_SEARCH_PROVIDER = 1 << 0,
444 DEFAULT_SEARCH_PROVIDER_IS_USER_CONTROLLED = 1 << 1,
445 HAS_EXPECTED_PREPOPULATED_SEARCH_PROVIDER_1 = 1 << 2,
446 HAS_EXPECTED_PREPOPULATED_SEARCH_PROVIDER_2 = 1 << 3,
449 // Constructs yet another evaluation program to specifically test that loaded
450 // module digests are included in the input as expected. We will re-purpose the
451 // output bitmasks to channel out information about the outcome of the checks.
453 // More specifically, the output of the program will be as follows:
454 // {
455 // "combined_status_mask_bit1":
456 // (input["loaded_modules.*"] == kTestModuleDigest)
457 // "combined_status_mask_bit2":
458 // (input["loaded_modules.*"] == kTestModuleDigest2)
459 // }
460 std::string ConstructProgramToCheckLoadedModuleDigests() {
461 std::string bytecode;
462 bytecode += OP_NAVIGATE(GetHash("loaded_modules"));
463 bytecode += OP_NAVIGATE_ANY;
464 bytecode += OP_COMPARE_NODE_HASH(GetHash(kTestModuleDigest));
465 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit1"),
466 EncodeBool(true));
467 bytecode += OP_END_OF_SENTENCE;
468 bytecode += OP_NAVIGATE(GetHash("loaded_modules"));
469 bytecode += OP_NAVIGATE_ANY;
470 bytecode += OP_COMPARE_NODE_HASH(GetHash(kTestModuleDigest2));
471 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit2"),
472 EncodeBool(true));
473 bytecode += OP_END_OF_SENTENCE;
474 return bytecode;
477 // Legend for the bitmask returned by the above program.
478 enum CombinedStatusMaskLegendForCheckingLoadedModules {
479 HAS_EXPECTED_MODULE_DIGEST_1 = 1 << 0,
480 HAS_EXPECTED_MODULE_DIGEST_2 = 1 << 1,
483 // Test fixtures -------------------------------------------------------------
485 class AutomaticProfileResetterTestBase : public testing::Test {
486 protected:
487 explicit AutomaticProfileResetterTestBase(
488 const std::string& experiment_group_name)
489 : waiting_task_runner_(new base::TestSimpleTaskRunner),
490 local_state_(TestingBrowserProcess::GetGlobal()),
491 profile_(new TestingProfile()),
492 field_trials_(new base::FieldTrialList(NULL)),
493 memento_in_prefs_(new PreferenceHostedPromptMemento(profile())),
494 memento_in_local_state_(new LocalStateHostedPromptMemento(profile())),
495 memento_in_file_(new FileHostedPromptMementoSynchronous(profile())),
496 experiment_group_name_(experiment_group_name),
497 inject_data_through_variation_params_(false),
498 mock_delegate_(NULL) {
499 // Make sure the factory is not optimized away, so whatever preferences it
500 // wants to register will actually get registered.
501 AutomaticProfileResetterFactory::GetInstance();
503 // Register some additional local state preferences for testing purposes.
504 PrefRegistrySimple* local_state_registry = local_state_.Get()->registry();
505 DCHECK(local_state_registry);
506 local_state_registry->RegisterStringPref(kTestPreferencePath, "");
508 // Register some additional user preferences for testing purposes.
509 user_prefs::PrefRegistrySyncable* user_prefs_registry =
510 profile_->GetTestingPrefService()->registry();
511 DCHECK(user_prefs_registry);
512 user_prefs_registry->RegisterStringPref(kTestPreferencePath, std::string());
515 void SetUp() override {
516 variations::testing::ClearAllVariationParams();
517 base::FieldTrialList::CreateFieldTrial(kAutomaticProfileResetStudyName,
518 experiment_group_name_);
519 resetter_.reset(
520 new testing::StrictMock<AutomaticProfileResetterUnderTest>(profile()));
521 mock_delegate_owned_.reset(
522 new testing::StrictMock<MockProfileResetterDelegate>());
523 mock_delegate_ = mock_delegate_owned_.get();
525 ExpectAllMementoValuesEqualTo(std::string());
528 void SetTestingHashSeed(const std::string& hash_seed) {
529 testing_hash_seed_ = hash_seed;
532 void SetTestingProgram(const std::string& source_code) {
533 testing_program_ = source_code;
536 void AllowInjectingTestDataThroughVariationParams(bool value) {
537 inject_data_through_variation_params_ = value;
540 void ExpectAllMementoValuesEqualTo(const std::string& value) {
541 EXPECT_EQ(value, memento_in_prefs_->ReadValue());
542 EXPECT_EQ(value, memento_in_local_state_->ReadValue());
543 EXPECT_EQ(value, memento_in_file_->ReadValue());
546 void UnleashResetterAndWait() {
547 if (inject_data_through_variation_params_) {
548 std::map<std::string, std::string> variation_params;
549 variation_params["program"] = testing_program_;
550 variation_params["hash_seed"] = testing_hash_seed_;
551 ASSERT_TRUE(variations::AssociateVariationParams(
552 kAutomaticProfileResetStudyName,
553 experiment_group_name_,
554 variation_params));
556 resetter_->Initialize();
557 resetter_->SetDelegateForTesting(mock_delegate_owned_.Pass());
558 resetter_->SetTaskRunnerForWaitingForTesting(waiting_task_runner_);
559 if (!inject_data_through_variation_params_) {
560 resetter_->SetProgramForTesting(testing_program_);
561 resetter_->SetHashSeedForTesting(testing_hash_seed_);
563 resetter_->Activate();
565 if (waiting_task_runner_->HasPendingTask()) {
566 ASSERT_EQ(base::TimeDelta::FromSeconds(55),
567 waiting_task_runner_->NextPendingTaskDelay());
568 waiting_task_runner_->RunPendingTasks();
570 base::RunLoop().RunUntilIdle();
571 content::BrowserThread::GetBlockingPool()->FlushForTesting();
572 base::RunLoop().RunUntilIdle();
575 // Goes through an evaluation flow such that the reset criteria are satisfied.
576 // Used to reduce boilerplate for tests that need to verify behavior during
577 // the reset prompt flow.
578 void OrchestrateThroughEvaluationFlow() {
579 SetTestingProgram(ConstructProgram(true, true));
580 SetTestingHashSeed(kTestHashSeed);
582 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
583 mock_delegate().ExpectCallsToGetterMethods();
584 mock_delegate().ExpectCallToShowPrompt();
585 EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x01u));
587 UnleashResetterAndWait();
589 EXPECT_TRUE(resetter().ShouldShowResetBanner());
590 testing::Mock::VerifyAndClearExpectations(&resetter());
591 testing::Mock::VerifyAndClearExpectations(&mock_delegate());
594 // Explicitly shut down the service to double-check that nothing explodes, but
595 // first, verify expectations to make sure the service makes no more calls to
596 // any mocked functions during or after shutdown.
597 void VerifyExpectationsThenShutdownResetter() {
598 testing::Mock::VerifyAndClearExpectations(&resetter());
599 testing::Mock::VerifyAndClearExpectations(&mock_delegate());
601 resetter_->Shutdown();
602 resetter_.reset();
605 TestingProfile* profile() { return profile_.get(); }
606 TestingPrefServiceSimple* local_state() { return local_state_.Get(); }
608 PreferenceHostedPromptMemento& memento_in_prefs() {
609 return *memento_in_prefs_;
612 LocalStateHostedPromptMemento& memento_in_local_state() {
613 return *memento_in_local_state_;
616 FileHostedPromptMementoSynchronous& memento_in_file() {
617 return *memento_in_file_;
620 MockProfileResetterDelegate& mock_delegate() { return *mock_delegate_; }
621 AutomaticProfileResetterUnderTest& resetter() { return *resetter_; }
623 private:
624 content::TestBrowserThreadBundle thread_bundle_;
625 scoped_refptr<base::TestSimpleTaskRunner> waiting_task_runner_;
626 ScopedTestingLocalState local_state_;
627 scoped_ptr<TestingProfile> profile_;
628 scoped_ptr<base::FieldTrialList> field_trials_;
629 scoped_ptr<PreferenceHostedPromptMemento> memento_in_prefs_;
630 scoped_ptr<LocalStateHostedPromptMemento> memento_in_local_state_;
631 scoped_ptr<FileHostedPromptMementoSynchronous> memento_in_file_;
633 std::string experiment_group_name_;
634 std::string testing_program_;
635 std::string testing_hash_seed_;
636 bool inject_data_through_variation_params_;
638 scoped_ptr<AutomaticProfileResetterUnderTest> resetter_;
639 scoped_ptr<MockProfileResetterDelegate> mock_delegate_owned_;
640 MockProfileResetterDelegate* mock_delegate_;
642 DISALLOW_COPY_AND_ASSIGN(AutomaticProfileResetterTestBase);
645 class AutomaticProfileResetterTest : public AutomaticProfileResetterTestBase {
646 protected:
647 AutomaticProfileResetterTest()
648 : AutomaticProfileResetterTestBase(kStudyEnabledGroupName) {}
651 class AutomaticProfileResetterTestDryRun
652 : public AutomaticProfileResetterTestBase {
653 protected:
654 AutomaticProfileResetterTestDryRun()
655 : AutomaticProfileResetterTestBase(kStudyDryRunGroupName) {}
658 class AutomaticProfileResetterTestDisabled
659 : public AutomaticProfileResetterTestBase {
660 protected:
661 AutomaticProfileResetterTestDisabled()
662 : AutomaticProfileResetterTestBase(kStudyDisabledGroupName) {}
665 // Tests ---------------------------------------------------------------------
667 TEST_F(AutomaticProfileResetterTestDisabled, NothingIsDoneWhenDisabled) {
668 SetTestingProgram(ConstructProgram(true, true));
669 SetTestingHashSeed(kTestHashSeed);
671 // No calls are expected to the delegate.
673 UnleashResetterAndWait();
675 EXPECT_FALSE(resetter().ShouldShowResetBanner());
676 VerifyExpectationsThenShutdownResetter();
678 ExpectAllMementoValuesEqualTo(std::string());
681 TEST_F(AutomaticProfileResetterTestDryRun, CriteriaNotSatisfied) {
682 SetTestingProgram(ConstructProgramToExerciseCriteria(false, true, true));
683 SetTestingHashSeed(kTestHashSeed);
685 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
686 mock_delegate().ExpectCallsToGetterMethods();
687 EXPECT_CALL(resetter(), ReportStatistics(0x1fu, 0x00u));
689 UnleashResetterAndWait();
691 EXPECT_FALSE(resetter().ShouldShowResetBanner());
692 VerifyExpectationsThenShutdownResetter();
694 ExpectAllMementoValuesEqualTo(std::string());
697 TEST_F(AutomaticProfileResetterTestDryRun, OddCriteriaSatisfied) {
698 SetTestingProgram(ConstructProgramToExerciseCriteria(true, true, false));
699 SetTestingHashSeed(kTestHashSeed);
701 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
702 mock_delegate().ExpectCallsToGetterMethods();
703 EXPECT_CALL(resetter(), ReportStatistics(0x15u, 0x01u));
704 EXPECT_CALL(resetter(), ReportPromptResult(
705 AutomaticProfileResetter::PROMPT_NOT_TRIGGERED));
707 UnleashResetterAndWait();
709 ExpectAllMementoValuesEqualTo(kTestMementoValue);
710 EXPECT_FALSE(resetter().ShouldShowResetBanner());
711 VerifyExpectationsThenShutdownResetter();
714 TEST_F(AutomaticProfileResetterTestDryRun, EvenCriteriaSatisfied) {
715 SetTestingProgram(ConstructProgramToExerciseCriteria(true, false, true));
716 SetTestingHashSeed(kTestHashSeed);
718 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
719 mock_delegate().ExpectCallsToGetterMethods();
720 EXPECT_CALL(resetter(), ReportStatistics(0x0au, 0x01u));
721 EXPECT_CALL(resetter(), ReportPromptResult(
722 AutomaticProfileResetter::PROMPT_NOT_TRIGGERED));
724 UnleashResetterAndWait();
726 ExpectAllMementoValuesEqualTo(kTestMementoValue);
727 EXPECT_FALSE(resetter().ShouldShowResetBanner());
728 VerifyExpectationsThenShutdownResetter();
731 #if defined(GOOGLE_CHROME_BUILD)
732 TEST_F(AutomaticProfileResetterTestDryRun, ProgramSetThroughVariationParams) {
733 SetTestingProgram(ConstructProgram(true, true));
734 SetTestingHashSeed(kTestHashSeed);
735 AllowInjectingTestDataThroughVariationParams(true);
737 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
738 mock_delegate().ExpectCallsToGetterMethods();
739 EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x01u));
740 EXPECT_CALL(resetter(), ReportPromptResult(
741 AutomaticProfileResetter::PROMPT_NOT_TRIGGERED));
743 UnleashResetterAndWait();
745 ExpectAllMementoValuesEqualTo(kTestMementoValue);
746 EXPECT_FALSE(resetter().ShouldShowResetBanner());
747 VerifyExpectationsThenShutdownResetter();
749 #endif
751 TEST_F(AutomaticProfileResetterTestDryRun,
752 ConditionsSatisfiedAndInvalidMementos) {
753 memento_in_prefs().StoreValue(kTestInvalidMementoValue);
754 memento_in_local_state().StoreValue(kTestInvalidMementoValue);
755 memento_in_file().StoreValue(kTestInvalidMementoValue);
757 SetTestingProgram(ConstructProgram(true, true));
758 SetTestingHashSeed(kTestHashSeed);
760 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
761 mock_delegate().ExpectCallsToGetterMethods();
762 EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x01u));
763 EXPECT_CALL(resetter(), ReportPromptResult(
764 AutomaticProfileResetter::PROMPT_NOT_TRIGGERED));
766 UnleashResetterAndWait();
768 ExpectAllMementoValuesEqualTo(kTestMementoValue);
769 EXPECT_FALSE(resetter().ShouldShowResetBanner());
770 VerifyExpectationsThenShutdownResetter();
773 TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadPrefHostedMemento) {
774 memento_in_prefs().StoreValue(kTestMementoValue);
776 SetTestingProgram(ConstructProgram(true, true));
777 SetTestingHashSeed(kTestHashSeed);
779 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
780 mock_delegate().ExpectCallsToGetterMethods();
781 EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x03u));
783 UnleashResetterAndWait();
785 EXPECT_FALSE(resetter().ShouldShowResetBanner());
786 VerifyExpectationsThenShutdownResetter();
788 EXPECT_EQ(kTestMementoValue, memento_in_prefs().ReadValue());
789 EXPECT_EQ(std::string(), memento_in_local_state().ReadValue());
790 EXPECT_EQ(std::string(), memento_in_file().ReadValue());
793 TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadLocalStateHostedMemento) {
794 memento_in_local_state().StoreValue(kTestMementoValue);
796 SetTestingProgram(ConstructProgram(true, true));
797 SetTestingHashSeed(kTestHashSeed);
799 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
800 mock_delegate().ExpectCallsToGetterMethods();
801 EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x05u));
803 UnleashResetterAndWait();
805 EXPECT_FALSE(resetter().ShouldShowResetBanner());
806 VerifyExpectationsThenShutdownResetter();
808 EXPECT_EQ(std::string(), memento_in_prefs().ReadValue());
809 EXPECT_EQ(kTestMementoValue, memento_in_local_state().ReadValue());
810 EXPECT_EQ(std::string(), memento_in_file().ReadValue());
813 TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadFileHostedMemento) {
814 memento_in_file().StoreValue(kTestMementoValue);
816 SetTestingProgram(ConstructProgram(true, true));
817 SetTestingHashSeed(kTestHashSeed);
819 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
820 mock_delegate().ExpectCallsToGetterMethods();
821 EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x09u));
823 UnleashResetterAndWait();
825 EXPECT_FALSE(resetter().ShouldShowResetBanner());
826 VerifyExpectationsThenShutdownResetter();
828 EXPECT_EQ(std::string(), memento_in_prefs().ReadValue());
829 EXPECT_EQ(std::string(), memento_in_local_state().ReadValue());
830 EXPECT_EQ(kTestMementoValue, memento_in_file().ReadValue());
833 TEST_F(AutomaticProfileResetterTestDryRun, DoNothingWhenResourcesAreMissing) {
834 SetTestingProgram(std::string());
835 SetTestingHashSeed(std::string());
837 // No calls are expected to the delegate.
839 UnleashResetterAndWait();
841 EXPECT_FALSE(resetter().ShouldShowResetBanner());
842 VerifyExpectationsThenShutdownResetter();
844 ExpectAllMementoValuesEqualTo(std::string());
847 TEST_F(AutomaticProfileResetterTest, CriteriaNotSatisfied) {
848 SetTestingProgram(ConstructProgramToExerciseCriteria(false, true, true));
849 SetTestingHashSeed(kTestHashSeed);
851 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
852 mock_delegate().ExpectCallsToGetterMethods();
853 EXPECT_CALL(resetter(), ReportStatistics(0x1fu, 0x00u));
855 UnleashResetterAndWait();
857 EXPECT_FALSE(resetter().ShouldShowResetBanner());
858 VerifyExpectationsThenShutdownResetter();
860 ExpectAllMementoValuesEqualTo(std::string());
863 TEST_F(AutomaticProfileResetterTest, OddCriteriaSatisfied) {
864 SetTestingProgram(ConstructProgramToExerciseCriteria(true, true, false));
865 SetTestingHashSeed(kTestHashSeed);
867 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
868 mock_delegate().ExpectCallsToGetterMethods();
869 mock_delegate().ExpectCallToShowPrompt();
870 EXPECT_CALL(resetter(), ReportStatistics(0x15u, 0x01u));
872 UnleashResetterAndWait();
874 EXPECT_TRUE(resetter().ShouldShowResetBanner());
875 VerifyExpectationsThenShutdownResetter();
878 TEST_F(AutomaticProfileResetterTest, EvenCriteriaSatisfied) {
879 SetTestingProgram(ConstructProgramToExerciseCriteria(true, false, true));
880 SetTestingHashSeed(kTestHashSeed);
882 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
883 mock_delegate().ExpectCallsToGetterMethods();
884 mock_delegate().ExpectCallToShowPrompt();
885 EXPECT_CALL(resetter(), ReportStatistics(0x0au, 0x01u));
887 UnleashResetterAndWait();
889 EXPECT_TRUE(resetter().ShouldShowResetBanner());
890 VerifyExpectationsThenShutdownResetter();
893 #if defined(GOOGLE_CHROME_BUILD)
894 TEST_F(AutomaticProfileResetterTest, ProgramSetThroughVariationParams) {
895 SetTestingProgram(ConstructProgram(true, true));
896 SetTestingHashSeed(kTestHashSeed);
897 AllowInjectingTestDataThroughVariationParams(true);
899 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
900 mock_delegate().ExpectCallsToGetterMethods();
901 mock_delegate().ExpectCallToShowPrompt();
902 EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x01u));
903 EXPECT_CALL(resetter(), ReportPromptResult(
904 AutomaticProfileResetter::PROMPT_SHOWN_BUBBLE));
906 UnleashResetterAndWait();
907 resetter().NotifyDidShowResetBubble();
909 ExpectAllMementoValuesEqualTo(kTestMementoValue);
910 EXPECT_TRUE(resetter().ShouldShowResetBanner());
911 VerifyExpectationsThenShutdownResetter();
913 #endif
915 TEST_F(AutomaticProfileResetterTest, ConditionsSatisfiedAndInvalidMementos) {
916 memento_in_prefs().StoreValue(kTestInvalidMementoValue);
917 memento_in_local_state().StoreValue(kTestInvalidMementoValue);
918 memento_in_file().StoreValue(kTestInvalidMementoValue);
920 SetTestingProgram(ConstructProgram(true, true));
921 SetTestingHashSeed(kTestHashSeed);
923 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
924 mock_delegate().ExpectCallsToGetterMethods();
925 mock_delegate().ExpectCallToShowPrompt();
926 EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x01u));
927 EXPECT_CALL(resetter(), ReportPromptResult(
928 AutomaticProfileResetter::PROMPT_SHOWN_BUBBLE));
930 UnleashResetterAndWait();
931 resetter().NotifyDidShowResetBubble();
933 ExpectAllMementoValuesEqualTo(kTestMementoValue);
934 EXPECT_TRUE(resetter().ShouldShowResetBanner());
935 VerifyExpectationsThenShutdownResetter();
938 TEST_F(AutomaticProfileResetterTest, PrefHostedMementoPreventsPrompt) {
939 memento_in_prefs().StoreValue(kTestMementoValue);
941 SetTestingProgram(ConstructProgram(true, true));
942 SetTestingHashSeed(kTestHashSeed);
944 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
945 mock_delegate().ExpectCallsToGetterMethods();
946 EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x03u));
948 UnleashResetterAndWait();
950 EXPECT_TRUE(resetter().ShouldShowResetBanner());
951 VerifyExpectationsThenShutdownResetter();
953 EXPECT_EQ(kTestMementoValue, memento_in_prefs().ReadValue());
954 EXPECT_EQ(std::string(), memento_in_local_state().ReadValue());
955 EXPECT_EQ(std::string(), memento_in_file().ReadValue());
958 TEST_F(AutomaticProfileResetterTest, LocalStateHostedMementoPreventsPrompt) {
959 memento_in_local_state().StoreValue(kTestMementoValue);
961 SetTestingProgram(ConstructProgram(true, true));
962 SetTestingHashSeed(kTestHashSeed);
964 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
965 mock_delegate().ExpectCallsToGetterMethods();
966 EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x05u));
968 UnleashResetterAndWait();
970 EXPECT_TRUE(resetter().ShouldShowResetBanner());
971 VerifyExpectationsThenShutdownResetter();
973 EXPECT_EQ(std::string(), memento_in_prefs().ReadValue());
974 EXPECT_EQ(kTestMementoValue, memento_in_local_state().ReadValue());
975 EXPECT_EQ(std::string(), memento_in_file().ReadValue());
978 TEST_F(AutomaticProfileResetterTest, FileHostedMementoPreventsPrompt) {
979 memento_in_file().StoreValue(kTestMementoValue);
981 SetTestingProgram(ConstructProgram(true, true));
982 SetTestingHashSeed(kTestHashSeed);
984 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
985 mock_delegate().ExpectCallsToGetterMethods();
986 EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x09u));
988 UnleashResetterAndWait();
990 EXPECT_TRUE(resetter().ShouldShowResetBanner());
991 VerifyExpectationsThenShutdownResetter();
993 EXPECT_EQ(std::string(), memento_in_prefs().ReadValue());
994 EXPECT_EQ(std::string(), memento_in_local_state().ReadValue());
995 EXPECT_EQ(kTestMementoValue, memento_in_file().ReadValue());
998 TEST_F(AutomaticProfileResetterTest, DoNothingWhenResourcesAreMissing) {
999 SetTestingProgram(std::string());
1000 SetTestingHashSeed(std::string());
1002 // No calls are expected to the delegate.
1004 UnleashResetterAndWait();
1006 EXPECT_FALSE(resetter().ShouldShowResetBanner());
1007 VerifyExpectationsThenShutdownResetter();
1009 ExpectAllMementoValuesEqualTo(std::string());
1012 TEST_F(AutomaticProfileResetterTest, PromptSuppressed) {
1013 OrchestrateThroughEvaluationFlow();
1015 VerifyExpectationsThenShutdownResetter();
1017 ExpectAllMementoValuesEqualTo(std::string());
1020 TEST_F(AutomaticProfileResetterTest, PromptNotSupported) {
1021 SetTestingProgram(ConstructProgram(true, true));
1022 SetTestingHashSeed(kTestHashSeed);
1024 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
1025 mock_delegate().ExpectCallsToGetterMethods();
1026 EXPECT_CALL(mock_delegate(), TriggerPrompt())
1027 .WillOnce(testing::Return(false));
1028 EXPECT_CALL(resetter(), ReportStatistics(0x03u, 0x01u));
1029 EXPECT_CALL(resetter(), ReportPromptResult(
1030 AutomaticProfileResetter::PROMPT_NOT_TRIGGERED));
1032 UnleashResetterAndWait();
1034 ExpectAllMementoValuesEqualTo(kTestMementoValue);
1035 EXPECT_TRUE(resetter().ShouldShowResetBanner());
1036 VerifyExpectationsThenShutdownResetter();
1039 TEST_F(AutomaticProfileResetterTest, PromptIgnored) {
1040 OrchestrateThroughEvaluationFlow();
1042 EXPECT_CALL(resetter(), ReportPromptResult(
1043 AutomaticProfileResetter::PROMPT_SHOWN_BUBBLE));
1044 resetter().NotifyDidShowResetBubble();
1045 ExpectAllMementoValuesEqualTo(kTestMementoValue);
1046 VerifyExpectationsThenShutdownResetter();
1049 TEST_F(AutomaticProfileResetterTest, PromptActionReset) {
1050 OrchestrateThroughEvaluationFlow();
1052 EXPECT_CALL(resetter(), ReportPromptResult(
1053 AutomaticProfileResetter::PROMPT_SHOWN_BUBBLE));
1054 resetter().NotifyDidShowResetBubble();
1055 ExpectAllMementoValuesEqualTo(kTestMementoValue);
1056 testing::Mock::VerifyAndClearExpectations(&resetter());
1058 mock_delegate().ExpectCallToTriggerReset(false);
1059 EXPECT_CALL(resetter(), ReportPromptResult(
1060 AutomaticProfileResetter::PROMPT_ACTION_RESET));
1061 resetter().TriggerProfileReset(false /*send_feedback*/);
1062 testing::Mock::VerifyAndClearExpectations(&resetter());
1063 testing::Mock::VerifyAndClearExpectations(&mock_delegate());
1065 EXPECT_CALL(mock_delegate(), DismissPrompt());
1066 mock_delegate().EmulateProfileResetCompleted();
1067 EXPECT_FALSE(resetter().ShouldShowResetBanner());
1068 VerifyExpectationsThenShutdownResetter();
1071 TEST_F(AutomaticProfileResetterTest, PromptActionResetWithFeedback) {
1072 OrchestrateThroughEvaluationFlow();
1074 EXPECT_CALL(resetter(), ReportPromptResult(
1075 AutomaticProfileResetter::PROMPT_SHOWN_BUBBLE));
1076 resetter().NotifyDidShowResetBubble();
1077 ExpectAllMementoValuesEqualTo(kTestMementoValue);
1078 testing::Mock::VerifyAndClearExpectations(&resetter());
1080 mock_delegate().ExpectCallToTriggerReset(true);
1081 EXPECT_CALL(resetter(), ReportPromptResult(
1082 AutomaticProfileResetter::PROMPT_ACTION_RESET));
1083 resetter().TriggerProfileReset(true /*send_feedback*/);
1084 testing::Mock::VerifyAndClearExpectations(&resetter());
1085 testing::Mock::VerifyAndClearExpectations(&mock_delegate());
1087 EXPECT_CALL(mock_delegate(), DismissPrompt());
1088 mock_delegate().EmulateProfileResetCompleted();
1089 EXPECT_FALSE(resetter().ShouldShowResetBanner());
1090 VerifyExpectationsThenShutdownResetter();
1093 TEST_F(AutomaticProfileResetterTest, PromptActionNoReset) {
1094 OrchestrateThroughEvaluationFlow();
1096 EXPECT_CALL(resetter(), ReportPromptResult(
1097 AutomaticProfileResetter::PROMPT_SHOWN_BUBBLE));
1098 resetter().NotifyDidShowResetBubble();
1099 ExpectAllMementoValuesEqualTo(kTestMementoValue);
1100 testing::Mock::VerifyAndClearExpectations(&resetter());
1102 EXPECT_CALL(mock_delegate(), DismissPrompt());
1103 EXPECT_CALL(resetter(), ReportPromptResult(
1104 AutomaticProfileResetter::PROMPT_ACTION_NO_RESET));
1105 resetter().SkipProfileReset();
1106 EXPECT_FALSE(resetter().ShouldShowResetBanner());
1107 VerifyExpectationsThenShutdownResetter();
1110 TEST_F(AutomaticProfileResetterTest, PromptFollowedByWebUIReset) {
1111 OrchestrateThroughEvaluationFlow();
1113 EXPECT_CALL(resetter(), ReportPromptResult(
1114 AutomaticProfileResetter::PROMPT_SHOWN_BUBBLE));
1115 resetter().NotifyDidShowResetBubble();
1116 ExpectAllMementoValuesEqualTo(kTestMementoValue);
1117 testing::Mock::VerifyAndClearExpectations(&resetter());
1119 EXPECT_CALL(mock_delegate(), DismissPrompt());
1120 resetter().NotifyDidOpenWebUIResetDialog();
1121 testing::Mock::VerifyAndClearExpectations(&mock_delegate());
1123 EXPECT_CALL(resetter(), ReportPromptResult(
1124 AutomaticProfileResetter::PROMPT_FOLLOWED_BY_WEBUI_RESET));
1125 resetter().NotifyDidCloseWebUIResetDialog(true);
1126 EXPECT_TRUE(resetter().ShouldShowResetBanner());
1127 VerifyExpectationsThenShutdownResetter();
1130 TEST_F(AutomaticProfileResetterTest, PromptFollowedByWebUINoReset) {
1131 OrchestrateThroughEvaluationFlow();
1133 EXPECT_CALL(resetter(), ReportPromptResult(
1134 AutomaticProfileResetter::PROMPT_SHOWN_BUBBLE));
1135 resetter().NotifyDidShowResetBubble();
1136 ExpectAllMementoValuesEqualTo(kTestMementoValue);
1137 testing::Mock::VerifyAndClearExpectations(&resetter());
1139 EXPECT_CALL(mock_delegate(), DismissPrompt());
1140 resetter().NotifyDidOpenWebUIResetDialog();
1141 testing::Mock::VerifyAndClearExpectations(&mock_delegate());
1143 EXPECT_CALL(resetter(), ReportPromptResult(
1144 AutomaticProfileResetter::PROMPT_FOLLOWED_BY_WEBUI_NO_RESET));
1145 resetter().NotifyDidCloseWebUIResetDialog(false);
1146 EXPECT_TRUE(resetter().ShouldShowResetBanner());
1147 VerifyExpectationsThenShutdownResetter();
1150 TEST_F(AutomaticProfileResetterTest, PromptFollowedByIncidentalWebUIReset) {
1151 OrchestrateThroughEvaluationFlow();
1153 EXPECT_CALL(resetter(), ReportPromptResult(
1154 AutomaticProfileResetter::PROMPT_SHOWN_BUBBLE));
1155 resetter().NotifyDidShowResetBubble();
1156 ExpectAllMementoValuesEqualTo(kTestMementoValue);
1157 testing::Mock::VerifyAndClearExpectations(&resetter());
1159 // Missing NotifyDidOpenWebUIResetDialog().
1160 // This can arise if a settings page was already opened at the time the prompt
1161 // was triggered, and this already opened dialog was used to initiate a reset
1162 // after having dismissed the prompt.
1164 EXPECT_CALL(mock_delegate(), DismissPrompt());
1165 EXPECT_CALL(resetter(), ReportPromptResult(
1166 AutomaticProfileResetter::PROMPT_FOLLOWED_BY_WEBUI_RESET));
1167 resetter().NotifyDidCloseWebUIResetDialog(true);
1168 EXPECT_TRUE(resetter().ShouldShowResetBanner());
1169 VerifyExpectationsThenShutdownResetter();
1172 TEST_F(AutomaticProfileResetterTest, PromptSuppressedButHadWebUIReset) {
1173 OrchestrateThroughEvaluationFlow();
1175 EXPECT_CALL(mock_delegate(), DismissPrompt());
1176 resetter().NotifyDidOpenWebUIResetDialog();
1177 testing::Mock::VerifyAndClearExpectations(&mock_delegate());
1179 EXPECT_CALL(resetter(), ReportPromptResult(
1180 AutomaticProfileResetter::PROMPT_NOT_SHOWN_BUBBLE_BUT_HAD_WEBUI_RESET));
1181 resetter().NotifyDidCloseWebUIResetDialog(true);
1182 ExpectAllMementoValuesEqualTo(kTestMementoValue);
1183 EXPECT_TRUE(resetter().ShouldShowResetBanner());
1184 VerifyExpectationsThenShutdownResetter();
1187 TEST_F(AutomaticProfileResetterTest, PromptSuppressedButHadWebUINoReset) {
1188 OrchestrateThroughEvaluationFlow();
1190 EXPECT_CALL(mock_delegate(), DismissPrompt());
1191 resetter().NotifyDidOpenWebUIResetDialog();
1192 testing::Mock::VerifyAndClearExpectations(&mock_delegate());
1194 EXPECT_CALL(resetter(), ReportPromptResult(AutomaticProfileResetter::
1195 PROMPT_NOT_SHOWN_BUBBLE_BUT_HAD_WEBUI_NO_RESET));
1196 resetter().NotifyDidCloseWebUIResetDialog(false);
1197 ExpectAllMementoValuesEqualTo(kTestMementoValue);
1198 EXPECT_TRUE(resetter().ShouldShowResetBanner());
1199 VerifyExpectationsThenShutdownResetter();
1202 TEST_F(AutomaticProfileResetterTest, BannerDismissed) {
1203 OrchestrateThroughEvaluationFlow();
1205 EXPECT_CALL(resetter(), ReportPromptResult(
1206 AutomaticProfileResetter::PROMPT_SHOWN_BUBBLE));
1207 resetter().NotifyDidShowResetBubble();
1208 ExpectAllMementoValuesEqualTo(kTestMementoValue);
1209 testing::Mock::VerifyAndClearExpectations(&resetter());
1211 resetter().NotifyDidCloseWebUIResetBanner();
1213 EXPECT_TRUE(resetter().IsResetPromptFlowActive());
1214 EXPECT_FALSE(resetter().ShouldShowResetBanner());
1216 // Note: we use strict mocks, so this also checks the bubble is not closed.
1217 VerifyExpectationsThenShutdownResetter();
1220 TEST_F(AutomaticProfileResetterTest, BannerDismissedWhilePromptSuppressed) {
1221 OrchestrateThroughEvaluationFlow();
1223 resetter().NotifyDidCloseWebUIResetBanner();
1225 EXPECT_TRUE(resetter().IsResetPromptFlowActive());
1226 EXPECT_FALSE(resetter().ShouldShowResetBanner());
1227 VerifyExpectationsThenShutdownResetter();
1229 ExpectAllMementoValuesEqualTo(std::string());
1232 // Please see comments above ConstructProgramToCheckPreferences() to understand
1233 // how the following tests work.
1235 TEST_F(AutomaticProfileResetterTest, InputUserPreferencesCorrect) {
1236 SetTestingProgram(ConstructProgramToCheckPreferences());
1237 SetTestingHashSeed(kTestHashSeed);
1239 PrefService* prefs = profile()->GetPrefs();
1240 prefs->SetString(kTestPreferencePath, kTestPreferenceValue);
1242 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
1243 mock_delegate().ExpectCallsToGetterMethods();
1244 uint32 expected_mask = HAS_EXPECTED_USER_PREFERENCE |
1245 USER_PREFERENCE_IS_USER_CONTROLLED;
1246 EXPECT_CALL(resetter(), ReportStatistics(0x00u, expected_mask));
1248 UnleashResetterAndWait();
1251 TEST_F(AutomaticProfileResetterTest, InputLocalStateCorrect) {
1252 SetTestingProgram(ConstructProgramToCheckPreferences());
1253 SetTestingHashSeed(kTestHashSeed);
1255 PrefService* prefs = local_state();
1256 prefs->SetString(kTestPreferencePath, kTestPreferenceValue);
1258 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
1259 mock_delegate().ExpectCallsToGetterMethods();
1260 uint32 expected_mask = HAS_EXPECTED_LOCAL_STATE_PREFERENCE |
1261 LOCAL_STATE_IS_USER_CONTROLLED;
1262 EXPECT_CALL(resetter(), ReportStatistics(0x00u, expected_mask));
1264 UnleashResetterAndWait();
1267 TEST_F(AutomaticProfileResetterTest, InputManagedUserPreferencesCorrect) {
1268 SetTestingProgram(ConstructProgramToCheckPreferences());
1269 SetTestingHashSeed(kTestHashSeed);
1271 TestingPrefServiceSyncable* prefs = profile()->GetTestingPrefService();
1272 prefs->SetManagedPref(kTestPreferencePath,
1273 new base::StringValue(kTestPreferenceValue));
1275 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
1276 mock_delegate().ExpectCallsToGetterMethods();
1277 uint32 expected_mask = HAS_EXPECTED_USER_PREFERENCE;
1278 EXPECT_CALL(resetter(), ReportStatistics(0x00u, expected_mask));
1280 UnleashResetterAndWait();
1283 TEST_F(AutomaticProfileResetterTest, InputManagedLocalStateCorrect) {
1284 SetTestingProgram(ConstructProgramToCheckPreferences());
1285 SetTestingHashSeed(kTestHashSeed);
1287 TestingPrefServiceSimple* prefs = local_state();
1288 prefs->SetManagedPref(kTestPreferencePath,
1289 new base::StringValue(kTestPreferenceValue));
1291 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
1292 mock_delegate().ExpectCallsToGetterMethods();
1293 uint32 expected_mask = HAS_EXPECTED_LOCAL_STATE_PREFERENCE;
1294 EXPECT_CALL(resetter(), ReportStatistics(0x00u, expected_mask));
1296 UnleashResetterAndWait();
1299 // Please see comments above ConstructProgramToCheckSearchEngines() to
1300 // understand how the following tests work.
1302 TEST_F(AutomaticProfileResetterTest, InputDefaultSearchProviderCorrect) {
1303 SetTestingProgram(ConstructProgramToCheckSearchEngines());
1304 SetTestingHashSeed(kTestHashSeed);
1306 mock_delegate().emulated_default_search_provider_details().SetString(
1307 kSearchURLAttributeKey, kTestSearchURL);
1309 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
1310 mock_delegate().ExpectCallsToGetterMethods();
1311 uint32 expected_mask = HAS_EXPECTED_DEFAULT_SEARCH_PROVIDER |
1312 DEFAULT_SEARCH_PROVIDER_IS_USER_CONTROLLED;
1313 EXPECT_CALL(resetter(), ReportStatistics(0x00u, expected_mask));
1315 UnleashResetterAndWait();
1318 TEST_F(AutomaticProfileResetterTest, InputSearchProviderManagedCorrect) {
1319 SetTestingProgram(ConstructProgramToCheckSearchEngines());
1320 SetTestingHashSeed(kTestHashSeed);
1322 mock_delegate().emulated_default_search_provider_details().SetString(
1323 kSearchURLAttributeKey, kTestSearchURL);
1324 mock_delegate().set_emulated_is_default_search_provider_managed(true);
1326 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
1327 mock_delegate().ExpectCallsToGetterMethods();
1328 uint32 expected_mask = HAS_EXPECTED_DEFAULT_SEARCH_PROVIDER;
1329 EXPECT_CALL(resetter(), ReportStatistics(0x00u, expected_mask));
1331 UnleashResetterAndWait();
1334 TEST_F(AutomaticProfileResetterTest, InputSearchProvidersCorrect) {
1335 SetTestingProgram(ConstructProgramToCheckSearchEngines());
1336 SetTestingHashSeed(kTestHashSeed);
1338 base::DictionaryValue* search_provider_1 = new base::DictionaryValue;
1339 base::DictionaryValue* search_provider_2 = new base::DictionaryValue;
1340 search_provider_1->SetString(kSearchURLAttributeKey, kTestSearchURL);
1341 search_provider_2->SetString(kSearchURLAttributeKey, kTestSearchURL2);
1342 mock_delegate().emulated_search_providers_details().Append(search_provider_1);
1343 mock_delegate().emulated_search_providers_details().Append(search_provider_2);
1345 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
1346 mock_delegate().ExpectCallsToGetterMethods();
1347 uint32 expected_mask = DEFAULT_SEARCH_PROVIDER_IS_USER_CONTROLLED |
1348 HAS_EXPECTED_PREPOPULATED_SEARCH_PROVIDER_1 |
1349 HAS_EXPECTED_PREPOPULATED_SEARCH_PROVIDER_2;
1350 EXPECT_CALL(resetter(), ReportStatistics(0x00u, expected_mask));
1352 UnleashResetterAndWait();
1355 // Please see comments above ConstructProgramToCheckLoadedModuleDigests() to
1356 // understand how the following tests work.
1358 TEST_F(AutomaticProfileResetterTest, InputModuleDigestsCorrect) {
1359 SetTestingProgram(ConstructProgramToCheckLoadedModuleDigests());
1360 SetTestingHashSeed(kTestHashSeed);
1362 mock_delegate().emulated_loaded_module_digests().AppendString(
1363 kTestModuleDigest);
1364 mock_delegate().emulated_loaded_module_digests().AppendString(
1365 kTestModuleDigest2);
1367 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
1368 mock_delegate().ExpectCallsToGetterMethods();
1369 uint32 expected_mask =
1370 HAS_EXPECTED_MODULE_DIGEST_1 | HAS_EXPECTED_MODULE_DIGEST_2;
1371 EXPECT_CALL(resetter(), ReportStatistics(0x00u, expected_mask));
1373 UnleashResetterAndWait();
1376 } // namespace