Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: chrome/browser/profile_resetter/automatic_profile_resetter_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698