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