1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/profile_resetter/automatic_profile_resetter.h"
10 #include "base/bind_helpers.h"
11 #include "base/metrics/field_trial.h"
12 #include "base/prefs/pref_registry_simple.h"
13 #include "base/prefs/testing_pref_service.h"
14 #include "base/run_loop.h"
15 #include "base/test/test_simple_task_runner.h"
16 #include "base/threading/sequenced_worker_pool.h"
17 #include "base/values.h"
18 #include "chrome/browser/profile_resetter/automatic_profile_resetter_delegate.h"
19 #include "chrome/browser/profile_resetter/automatic_profile_resetter_factory.h"
20 #include "chrome/browser/profile_resetter/automatic_profile_resetter_mementos.h"
21 #include "chrome/browser/profile_resetter/jtl_foundation.h"
22 #include "chrome/browser/profile_resetter/jtl_instructions.h"
23 #include "chrome/test/base/scoped_testing_local_state.h"
24 #include "chrome/test/base/testing_browser_process.h"
25 #include "chrome/test/base/testing_pref_service_syncable.h"
26 #include "chrome/test/base/testing_profile.h"
27 #include "components/pref_registry/pref_registry_syncable.h"
28 #include "components/variations/variations_associated_data.h"
29 #include "content/public/browser/browser_thread.h"
30 #include "content/public/test/test_browser_thread_bundle.h"
31 #include "testing/gmock/include/gmock/gmock.h"
32 #include "testing/gtest/include/gtest/gtest.h"
38 const char kAutomaticProfileResetStudyName
[] = "AutomaticProfileReset";
39 const char kStudyDisabledGroupName
[] = "Disabled";
40 const char kStudyDryRunGroupName
[] = "DryRun";
41 const char kStudyEnabledGroupName
[] = "Enabled";
43 const char kTestHashSeed
[] = "testing-hash-seed";
44 const char kTestMementoValue
[] = "01234567890123456789012345678901";
45 const char kTestInvalidMementoValue
[] = "12345678901234567890123456789012";
47 const char kTestPreferencePath
[] = "testing.preference";
48 const char kTestPreferenceValue
[] = "testing-preference-value";
50 const char kSearchURLAttributeKey
[] = "search_url";
51 const char kTestSearchURL
[] = "http://example.com/search?q={searchTerms}";
52 const char kTestSearchURL2
[] = "http://google.com/?q={searchTerms}";
54 const char kTestModuleDigest
[] = "01234567890123456789012345678901";
55 const char kTestModuleDigest2
[] = "12345678901234567890123456789012";
57 // Helpers ------------------------------------------------------------------
59 // A testing version of the AutomaticProfileResetter that differs from the real
60 // one only in that it has its statistics reporting mocked out for verification.
61 class AutomaticProfileResetterUnderTest
: public AutomaticProfileResetter
{
63 explicit AutomaticProfileResetterUnderTest(Profile
* profile
)
64 : AutomaticProfileResetter(profile
) {}
65 virtual ~AutomaticProfileResetterUnderTest() {}
67 MOCK_METHOD2(ReportStatistics
, void(uint32
, uint32
));
68 MOCK_METHOD1(ReportPromptResult
,
69 void(AutomaticProfileResetter::PromptResult
));
72 DISALLOW_COPY_AND_ASSIGN(AutomaticProfileResetterUnderTest
);
75 class MockProfileResetterDelegate
: public AutomaticProfileResetterDelegate
{
77 MockProfileResetterDelegate()
78 : emulated_is_default_search_provider_managed_(false) {}
79 virtual ~MockProfileResetterDelegate() {}
81 MOCK_METHOD0(EnumerateLoadedModulesIfNeeded
, void());
82 MOCK_CONST_METHOD1(RequestCallbackWhenLoadedModulesAreEnumerated
,
83 void(const base::Closure
&));
85 MOCK_METHOD0(LoadTemplateURLServiceIfNeeded
, void());
86 MOCK_CONST_METHOD1(RequestCallbackWhenTemplateURLServiceIsLoaded
,
87 void(const base::Closure
&));
89 MOCK_METHOD0(FetchBrandcodedDefaultSettingsIfNeeded
, void());
90 MOCK_CONST_METHOD1(RequestCallbackWhenBrandcodedDefaultsAreFetched
,
91 void(const base::Closure
&));
93 MOCK_CONST_METHOD0(OnGetLoadedModuleNameDigestsCalled
, void());
94 MOCK_CONST_METHOD0(OnGetDefaultSearchProviderDetailsCalled
, void());
95 MOCK_CONST_METHOD0(OnIsDefaultSearchProviderManagedCalled
, void());
96 MOCK_CONST_METHOD0(OnGetPrepopulatedSearchProvidersDetailsCalled
, void());
98 MOCK_METHOD0(TriggerPrompt
, bool());
99 MOCK_METHOD2(TriggerProfileSettingsReset
, void(bool, const base::Closure
&));
100 MOCK_METHOD0(DismissPrompt
, void());
102 virtual scoped_ptr
<base::ListValue
>
103 GetLoadedModuleNameDigests() const override
{
104 OnGetLoadedModuleNameDigestsCalled();
105 return scoped_ptr
<base::ListValue
>(
106 emulated_loaded_module_digests_
.DeepCopy());
109 virtual scoped_ptr
<base::DictionaryValue
>
110 GetDefaultSearchProviderDetails() const override
{
111 OnGetDefaultSearchProviderDetailsCalled();
112 return scoped_ptr
<base::DictionaryValue
>(
113 emulated_default_search_provider_details_
.DeepCopy());
116 virtual bool IsDefaultSearchProviderManaged() const override
{
117 OnIsDefaultSearchProviderManagedCalled();
118 return emulated_is_default_search_provider_managed_
;
121 virtual scoped_ptr
<base::ListValue
>
122 GetPrepopulatedSearchProvidersDetails() const override
{
123 OnGetPrepopulatedSearchProvidersDetailsCalled();
124 return scoped_ptr
<base::ListValue
>(
125 emulated_search_providers_details_
.DeepCopy());
128 static void ClosureInvoker(const base::Closure
& closure
) { closure
.Run(); }
130 void ExpectCallsToDependenciesSetUpMethods() {
131 EXPECT_CALL(*this, EnumerateLoadedModulesIfNeeded());
132 EXPECT_CALL(*this, LoadTemplateURLServiceIfNeeded());
133 EXPECT_CALL(*this, RequestCallbackWhenLoadedModulesAreEnumerated(_
))
134 .WillOnce(testing::Invoke(ClosureInvoker
));
135 EXPECT_CALL(*this, RequestCallbackWhenTemplateURLServiceIsLoaded(_
))
136 .WillOnce(testing::Invoke(ClosureInvoker
));
139 void ExpectCallsToGetterMethods() {
140 EXPECT_CALL(*this, OnGetLoadedModuleNameDigestsCalled());
141 EXPECT_CALL(*this, OnGetDefaultSearchProviderDetailsCalled());
142 EXPECT_CALL(*this, OnIsDefaultSearchProviderManagedCalled());
143 EXPECT_CALL(*this, OnGetPrepopulatedSearchProvidersDetailsCalled());
146 void ExpectCallToShowPrompt() {
147 EXPECT_CALL(*this, TriggerPrompt()).WillOnce(testing::Return(true));
148 EXPECT_CALL(*this, FetchBrandcodedDefaultSettingsIfNeeded());
151 void ExpectCallToTriggerReset(bool send_feedback
) {
152 EXPECT_CALL(*this, TriggerProfileSettingsReset(send_feedback
, _
))
153 .WillOnce(testing::SaveArg
<1>(&reset_completion_
));
156 base::DictionaryValue
& emulated_default_search_provider_details() {
157 return emulated_default_search_provider_details_
;
160 base::ListValue
& emulated_search_providers_details() {
161 return emulated_search_providers_details_
;
164 base::ListValue
& emulated_loaded_module_digests() {
165 return emulated_loaded_module_digests_
;
168 void set_emulated_is_default_search_provider_managed(bool value
) {
169 emulated_is_default_search_provider_managed_
= value
;
172 void EmulateProfileResetCompleted() {
173 reset_completion_
.Run();
177 base::DictionaryValue emulated_default_search_provider_details_
;
178 base::ListValue emulated_search_providers_details_
;
179 base::ListValue emulated_loaded_module_digests_
;
180 bool emulated_is_default_search_provider_managed_
;
181 base::Closure reset_completion_
;
183 DISALLOW_COPY_AND_ASSIGN(MockProfileResetterDelegate
);
186 class FileHostedPromptMementoSynchronous
: protected FileHostedPromptMemento
{
188 explicit FileHostedPromptMementoSynchronous(Profile
* profile
)
189 : FileHostedPromptMemento(profile
) {}
191 std::string
ReadValue() const {
193 FileHostedPromptMemento::ReadValue(base::Bind(&AssignArgumentTo
, &result
));
194 base::RunLoop().RunUntilIdle();
198 void StoreValue(const std::string
& value
) {
199 FileHostedPromptMemento::StoreValue(value
);
200 base::RunLoop().RunUntilIdle();
204 static void AssignArgumentTo(std::string
* target
, const std::string
& value
) {
208 DISALLOW_COPY_AND_ASSIGN(FileHostedPromptMementoSynchronous
);
211 std::string
GetHash(const std::string
& input
) {
212 return jtl_foundation::Hasher(kTestHashSeed
).GetHash(input
);
215 // Encodes a Boolean argument value into JTL bytecode.
216 std::string
EncodeBool(bool value
) { return value
? VALUE_TRUE
: VALUE_FALSE
; }
218 // Constructs a simple evaluation program to test that basic input/output works
219 // well. It will emulate a scenario in which the reset criteria are satisfied as
220 // prescribed by |emulate_satisfied_criterion_{1|2}|, and the reset is triggered
221 // when either of them is true. The bits in the combined status mask will be set
222 // according to whether or not the memento values received in the input were as
225 // More specifically, the output of the program will be as follows:
227 // "satisfied_criteria_mask_bit1": emulate_satisfied_criterion_1,
228 // "satisfied_criteria_mask_bit2": emulate_satisfied_criterion_2,
229 // "combined_status_mask_bit1":
230 // (emulate_satisfied_criterion_1 || emulate_satisfied_criterion_2),
231 // "combined_status_mask_bit2":
232 // (input["memento_value_in_prefs"] == kTestMementoValue),
233 // "combined_status_mask_bit3":
234 // (input["memento_value_in_local_state"] == kTestMementoValue),
235 // "combined_status_mask_bit4":
236 // (input["memento_value_in_file"] == kTestMementoValue),
238 // (emulate_satisfied_criterion_1 || emulate_satisfied_criterion_2),
239 // "had_prompted_already": <OR-combination of above three>,
240 // "memento_value_in_prefs": kTestMementoValue,
241 // "memento_value_in_local_state": kTestMementoValue,
242 // "memento_value_in_file": kTestMementoValue
244 std::string
ConstructProgram(bool emulate_satisfied_criterion_1
,
245 bool emulate_satisfied_criterion_2
) {
246 std::string bytecode
;
247 bytecode
+= OP_STORE_BOOL(GetHash("satisfied_criteria_mask_bit1"),
248 EncodeBool(emulate_satisfied_criterion_1
));
249 bytecode
+= OP_END_OF_SENTENCE
;
250 bytecode
+= OP_STORE_BOOL(GetHash("satisfied_criteria_mask_bit2"),
251 EncodeBool(emulate_satisfied_criterion_2
));
252 bytecode
+= OP_END_OF_SENTENCE
;
253 bytecode
+= OP_STORE_BOOL(GetHash("should_prompt"),
254 EncodeBool(emulate_satisfied_criterion_1
||
255 emulate_satisfied_criterion_2
));
256 bytecode
+= OP_END_OF_SENTENCE
;
257 bytecode
+= OP_STORE_BOOL(GetHash("combined_status_mask_bit1"),
258 EncodeBool(emulate_satisfied_criterion_1
||
259 emulate_satisfied_criterion_2
));
260 bytecode
+= OP_END_OF_SENTENCE
;
261 bytecode
+= OP_NAVIGATE(GetHash("memento_value_in_prefs"));
262 bytecode
+= OP_COMPARE_NODE_HASH(GetHash(kTestMementoValue
));
263 bytecode
+= OP_STORE_BOOL(GetHash("combined_status_mask_bit2"), VALUE_TRUE
);
264 bytecode
+= OP_STORE_BOOL(GetHash("had_prompted_already"), VALUE_TRUE
);
265 bytecode
+= OP_END_OF_SENTENCE
;
266 bytecode
+= OP_NAVIGATE(GetHash("memento_value_in_local_state"));
267 bytecode
+= OP_COMPARE_NODE_HASH(GetHash(kTestMementoValue
));
268 bytecode
+= OP_STORE_BOOL(GetHash("combined_status_mask_bit3"), VALUE_TRUE
);
269 bytecode
+= OP_STORE_BOOL(GetHash("had_prompted_already"), VALUE_TRUE
);
270 bytecode
+= OP_END_OF_SENTENCE
;
271 bytecode
+= OP_NAVIGATE(GetHash("memento_value_in_file"));
272 bytecode
+= OP_COMPARE_NODE_HASH(GetHash(kTestMementoValue
));
273 bytecode
+= OP_STORE_BOOL(GetHash("combined_status_mask_bit4"), VALUE_TRUE
);
274 bytecode
+= OP_STORE_BOOL(GetHash("had_prompted_already"), VALUE_TRUE
);
275 bytecode
+= OP_END_OF_SENTENCE
;
276 bytecode
+= OP_STORE_HASH(GetHash("memento_value_in_prefs"),
278 bytecode
+= OP_END_OF_SENTENCE
;
279 bytecode
+= OP_STORE_HASH(GetHash("memento_value_in_local_state"),
281 bytecode
+= OP_END_OF_SENTENCE
;
282 bytecode
+= OP_STORE_HASH(GetHash("memento_value_in_file"),
284 bytecode
+= OP_END_OF_SENTENCE
;
288 // Constructs another evaluation program to specifically test that bits of the
289 // "satisfied_criteria_mask" are correctly assigned, and so is "should_prompt";
290 // and that reset is triggered iff the latter is true, regardless of the bits
291 // in the mask (so as to allow for a non-disjunctive compound criterion).
293 // More specifically, the output of the program will be as follows:
295 // "satisfied_criteria_mask_bitN": emulate_satisfied_odd_criteria,
296 // "satisfied_criteria_mask_bitM": emulate_satisfied_even_criteria,
297 // "combined_status_mask_bit1": emulate_should_prompt,
298 // "should_prompt": emulate_should_prompt,
299 // "memento_value_in_prefs": kTestMementoValue,
300 // "memento_value_in_local_state": kTestMementoValue,
301 // "memento_value_in_file": kTestMementoValue
303 // ... such that N is {1,3,5} and M is {2,4}.
304 std::string
ConstructProgramToExerciseCriteria(
305 bool emulate_should_prompt
,
306 bool emulate_satisfied_odd_criteria
,
307 bool emulate_satisfied_even_criteria
) {
308 std::string bytecode
;
309 bytecode
+= OP_STORE_BOOL(GetHash("satisfied_criteria_mask_bit1"),
310 EncodeBool(emulate_satisfied_odd_criteria
));
311 bytecode
+= OP_END_OF_SENTENCE
;
312 bytecode
+= OP_STORE_BOOL(GetHash("satisfied_criteria_mask_bit3"),
313 EncodeBool(emulate_satisfied_odd_criteria
));
314 bytecode
+= OP_END_OF_SENTENCE
;
315 bytecode
+= OP_STORE_BOOL(GetHash("satisfied_criteria_mask_bit5"),
316 EncodeBool(emulate_satisfied_odd_criteria
));
317 bytecode
+= OP_END_OF_SENTENCE
;
318 bytecode
+= OP_STORE_BOOL(GetHash("satisfied_criteria_mask_bit2"),
319 EncodeBool(emulate_satisfied_even_criteria
));
320 bytecode
+= OP_END_OF_SENTENCE
;
321 bytecode
+= OP_STORE_BOOL(GetHash("satisfied_criteria_mask_bit4"),
322 EncodeBool(emulate_satisfied_even_criteria
));
323 bytecode
+= OP_END_OF_SENTENCE
;
324 bytecode
+= OP_STORE_BOOL(GetHash("should_prompt"),
325 EncodeBool(emulate_should_prompt
));
326 bytecode
+= OP_END_OF_SENTENCE
;
327 bytecode
+= OP_STORE_BOOL(GetHash("combined_status_mask_bit1"),
328 EncodeBool(emulate_should_prompt
));
329 bytecode
+= OP_END_OF_SENTENCE
;
330 bytecode
+= OP_STORE_HASH(GetHash("memento_value_in_prefs"),
332 bytecode
+= OP_END_OF_SENTENCE
;
333 bytecode
+= OP_STORE_HASH(GetHash("memento_value_in_local_state"),
335 bytecode
+= OP_END_OF_SENTENCE
;
336 bytecode
+= OP_STORE_HASH(GetHash("memento_value_in_file"),
338 bytecode
+= OP_END_OF_SENTENCE
;
342 // Constructs another evaluation program to specifically test that local state
343 // and user preference values are included in the input as expected. We will
344 // re-purpose the output bitmasks to channel out information about the outcome
347 // More specifically, the output of the program will be as follows:
349 // "combined_status_mask_bit1":
350 // (input["preferences.testing.preference"] == kTestPreferenceValue)
351 // "combined_status_mask_bit2":
352 // (input["local_state.testing.preference"] == kTestPreferenceValue)
353 // "combined_status_mask_bit3": input["preferences_iuc.testing.preference"]
354 // "combined_status_mask_bit4": input["local_state_iuc.testing.preference"]
356 std::string
ConstructProgramToCheckPreferences() {
357 std::string bytecode
;
358 bytecode
+= OP_NAVIGATE(GetHash("preferences"));
359 bytecode
+= OP_NAVIGATE(GetHash("testing"));
360 bytecode
+= OP_NAVIGATE(GetHash("preference"));
361 bytecode
+= OP_COMPARE_NODE_HASH(GetHash(kTestPreferenceValue
));
362 bytecode
+= OP_STORE_BOOL(GetHash("combined_status_mask_bit1"),
364 bytecode
+= OP_END_OF_SENTENCE
;
365 bytecode
+= OP_NAVIGATE(GetHash("local_state"));
366 bytecode
+= OP_NAVIGATE(GetHash("testing"));
367 bytecode
+= OP_NAVIGATE(GetHash("preference"));
368 bytecode
+= OP_COMPARE_NODE_HASH(GetHash(kTestPreferenceValue
));
369 bytecode
+= OP_STORE_BOOL(GetHash("combined_status_mask_bit2"),
371 bytecode
+= OP_END_OF_SENTENCE
;
372 bytecode
+= OP_NAVIGATE(GetHash("preferences_iuc"));
373 bytecode
+= OP_NAVIGATE(GetHash("testing"));
374 bytecode
+= OP_NAVIGATE(GetHash("preference"));
375 bytecode
+= OP_COMPARE_NODE_BOOL(EncodeBool(true));
376 bytecode
+= OP_STORE_BOOL(GetHash("combined_status_mask_bit3"),
378 bytecode
+= OP_END_OF_SENTENCE
;
379 bytecode
+= OP_NAVIGATE(GetHash("local_state_iuc"));
380 bytecode
+= OP_NAVIGATE(GetHash("testing"));
381 bytecode
+= OP_NAVIGATE(GetHash("preference"));
382 bytecode
+= OP_COMPARE_NODE_BOOL(EncodeBool(true));
383 bytecode
+= OP_STORE_BOOL(GetHash("combined_status_mask_bit4"),
385 bytecode
+= OP_END_OF_SENTENCE
;
389 // Legend for the bitmask returned by the above program.
390 enum CombinedStatusMaskLegendForCheckingPreferences
{
391 HAS_EXPECTED_USER_PREFERENCE
= 1 << 0,
392 HAS_EXPECTED_LOCAL_STATE_PREFERENCE
= 1 << 1,
393 USER_PREFERENCE_IS_USER_CONTROLLED
= 1 << 2,
394 LOCAL_STATE_IS_USER_CONTROLLED
= 1 << 3,
397 // Constructs yet another evaluation program to specifically test that default
398 // and pre-populated search engines are included in the input as expected. We
399 // will re-purpose the output bitmasks to channel out information about the
400 // outcome of the checks.
402 // More specifically, the output of the program will be as follows:
404 // "combined_status_mask_bit1":
405 // (input["default_search_provider.search_url"] == kTestSearchURL)
406 // "combined_status_mask_bit2": input["default_search_provider_iuc"]
407 // "combined_status_mask_bit3":
408 // (input["search_providers.*.search_url"] == kTestSearchURL)
409 // "combined_status_mask_bit4":
410 // (input["search_providers.*.search_url"] == kTestSearchURL2)
412 std::string
ConstructProgramToCheckSearchEngines() {
413 std::string bytecode
;
414 bytecode
+= OP_NAVIGATE(GetHash("default_search_provider"));
415 bytecode
+= OP_NAVIGATE(GetHash("search_url"));
416 bytecode
+= OP_COMPARE_NODE_HASH(GetHash(kTestSearchURL
));
417 bytecode
+= OP_STORE_BOOL(GetHash("combined_status_mask_bit1"),
419 bytecode
+= OP_END_OF_SENTENCE
;
420 bytecode
+= OP_NAVIGATE(GetHash("default_search_provider_iuc"));
421 bytecode
+= OP_COMPARE_NODE_BOOL(EncodeBool(true));
422 bytecode
+= OP_STORE_BOOL(GetHash("combined_status_mask_bit2"),
424 bytecode
+= OP_END_OF_SENTENCE
;
425 bytecode
+= OP_NAVIGATE(GetHash("search_providers"));
426 bytecode
+= OP_NAVIGATE_ANY
;
427 bytecode
+= OP_NAVIGATE(GetHash("search_url"));
428 bytecode
+= OP_COMPARE_NODE_HASH(GetHash(kTestSearchURL
));
429 bytecode
+= OP_STORE_BOOL(GetHash("combined_status_mask_bit3"),
431 bytecode
+= OP_END_OF_SENTENCE
;
432 bytecode
+= OP_NAVIGATE(GetHash("search_providers"));
433 bytecode
+= OP_NAVIGATE_ANY
;
434 bytecode
+= OP_NAVIGATE(GetHash("search_url"));
435 bytecode
+= OP_COMPARE_NODE_HASH(GetHash(kTestSearchURL2
));
436 bytecode
+= OP_STORE_BOOL(GetHash("combined_status_mask_bit4"),
438 bytecode
+= OP_END_OF_SENTENCE
;
442 // Legend for the bitmask returned by the above program.
443 enum CombinedStatusMaskLegendForCheckingSearchEngines
{
444 HAS_EXPECTED_DEFAULT_SEARCH_PROVIDER
= 1 << 0,
445 DEFAULT_SEARCH_PROVIDER_IS_USER_CONTROLLED
= 1 << 1,
446 HAS_EXPECTED_PREPOPULATED_SEARCH_PROVIDER_1
= 1 << 2,
447 HAS_EXPECTED_PREPOPULATED_SEARCH_PROVIDER_2
= 1 << 3,
450 // Constructs yet another evaluation program to specifically test that loaded
451 // module digests are included in the input as expected. We will re-purpose the
452 // output bitmasks to channel out information about the outcome of the checks.
454 // More specifically, the output of the program will be as follows:
456 // "combined_status_mask_bit1":
457 // (input["loaded_modules.*"] == kTestModuleDigest)
458 // "combined_status_mask_bit2":
459 // (input["loaded_modules.*"] == kTestModuleDigest2)
461 std::string
ConstructProgramToCheckLoadedModuleDigests() {
462 std::string bytecode
;
463 bytecode
+= OP_NAVIGATE(GetHash("loaded_modules"));
464 bytecode
+= OP_NAVIGATE_ANY
;
465 bytecode
+= OP_COMPARE_NODE_HASH(GetHash(kTestModuleDigest
));
466 bytecode
+= OP_STORE_BOOL(GetHash("combined_status_mask_bit1"),
468 bytecode
+= OP_END_OF_SENTENCE
;
469 bytecode
+= OP_NAVIGATE(GetHash("loaded_modules"));
470 bytecode
+= OP_NAVIGATE_ANY
;
471 bytecode
+= OP_COMPARE_NODE_HASH(GetHash(kTestModuleDigest2
));
472 bytecode
+= OP_STORE_BOOL(GetHash("combined_status_mask_bit2"),
474 bytecode
+= OP_END_OF_SENTENCE
;
478 // Legend for the bitmask returned by the above program.
479 enum CombinedStatusMaskLegendForCheckingLoadedModules
{
480 HAS_EXPECTED_MODULE_DIGEST_1
= 1 << 0,
481 HAS_EXPECTED_MODULE_DIGEST_2
= 1 << 1,
484 // Test fixtures -------------------------------------------------------------
486 class AutomaticProfileResetterTestBase
: public testing::Test
{
488 explicit AutomaticProfileResetterTestBase(
489 const std::string
& experiment_group_name
)
490 : waiting_task_runner_(new base::TestSimpleTaskRunner
),
491 local_state_(TestingBrowserProcess::GetGlobal()),
492 profile_(new TestingProfile()),
493 field_trials_(new base::FieldTrialList(NULL
)),
494 memento_in_prefs_(new PreferenceHostedPromptMemento(profile())),
495 memento_in_local_state_(new LocalStateHostedPromptMemento(profile())),
496 memento_in_file_(new FileHostedPromptMementoSynchronous(profile())),
497 experiment_group_name_(experiment_group_name
),
498 inject_data_through_variation_params_(false),
499 mock_delegate_(NULL
) {
500 // Make sure the factory is not optimized away, so whatever preferences it
501 // wants to register will actually get registered.
502 AutomaticProfileResetterFactory::GetInstance();
504 // Register some additional local state preferences for testing purposes.
505 PrefRegistrySimple
* local_state_registry
= local_state_
.Get()->registry();
506 DCHECK(local_state_registry
);
507 local_state_registry
->RegisterStringPref(kTestPreferencePath
, "");
509 // Register some additional user preferences for testing purposes.
510 user_prefs::PrefRegistrySyncable
* user_prefs_registry
=
511 profile_
->GetTestingPrefService()->registry();
512 DCHECK(user_prefs_registry
);
513 user_prefs_registry
->RegisterStringPref(
514 kTestPreferencePath
, std::string(),
515 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
518 virtual void SetUp() override
{
519 variations::testing::ClearAllVariationParams();
520 base::FieldTrialList::CreateFieldTrial(kAutomaticProfileResetStudyName
,
521 experiment_group_name_
);
523 new testing::StrictMock
<AutomaticProfileResetterUnderTest
>(profile()));
524 mock_delegate_owned_
.reset(
525 new testing::StrictMock
<MockProfileResetterDelegate
>());
526 mock_delegate_
= mock_delegate_owned_
.get();
528 ExpectAllMementoValuesEqualTo(std::string());
531 void SetTestingHashSeed(const std::string
& hash_seed
) {
532 testing_hash_seed_
= hash_seed
;
535 void SetTestingProgram(const std::string
& source_code
) {
536 testing_program_
= source_code
;
539 void AllowInjectingTestDataThroughVariationParams(bool value
) {
540 inject_data_through_variation_params_
= value
;
543 void ExpectAllMementoValuesEqualTo(const std::string
& value
) {
544 EXPECT_EQ(value
, memento_in_prefs_
->ReadValue());
545 EXPECT_EQ(value
, memento_in_local_state_
->ReadValue());
546 EXPECT_EQ(value
, memento_in_file_
->ReadValue());
549 void UnleashResetterAndWait() {
550 if (inject_data_through_variation_params_
) {
551 std::map
<std::string
, std::string
> variation_params
;
552 variation_params
["program"] = testing_program_
;
553 variation_params
["hash_seed"] = testing_hash_seed_
;
554 ASSERT_TRUE(variations::AssociateVariationParams(
555 kAutomaticProfileResetStudyName
,
556 experiment_group_name_
,
559 resetter_
->Initialize();
560 resetter_
->SetDelegateForTesting(mock_delegate_owned_
.Pass());
561 resetter_
->SetTaskRunnerForWaitingForTesting(waiting_task_runner_
);
562 if (!inject_data_through_variation_params_
) {
563 resetter_
->SetProgramForTesting(testing_program_
);
564 resetter_
->SetHashSeedForTesting(testing_hash_seed_
);
566 resetter_
->Activate();
568 if (waiting_task_runner_
->HasPendingTask()) {
569 ASSERT_EQ(base::TimeDelta::FromSeconds(55),
570 waiting_task_runner_
->NextPendingTaskDelay());
571 waiting_task_runner_
->RunPendingTasks();
573 base::RunLoop().RunUntilIdle();
574 content::BrowserThread::GetBlockingPool()->FlushForTesting();
575 base::RunLoop().RunUntilIdle();
578 // Goes through an evaluation flow such that the reset criteria are satisfied.
579 // Used to reduce boilerplate for tests that need to verify behavior during
580 // the reset prompt flow.
581 void OrchestrateThroughEvaluationFlow() {
582 SetTestingProgram(ConstructProgram(true, true));
583 SetTestingHashSeed(kTestHashSeed
);
585 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
586 mock_delegate().ExpectCallsToGetterMethods();
587 mock_delegate().ExpectCallToShowPrompt();
588 EXPECT_CALL(resetter(), ReportStatistics(0x03u
, 0x01u
));
590 UnleashResetterAndWait();
592 EXPECT_TRUE(resetter().ShouldShowResetBanner());
593 testing::Mock::VerifyAndClearExpectations(&resetter());
594 testing::Mock::VerifyAndClearExpectations(&mock_delegate());
597 // Explicitly shut down the service to double-check that nothing explodes, but
598 // first, verify expectations to make sure the service makes no more calls to
599 // any mocked functions during or after shutdown.
600 void VerifyExpectationsThenShutdownResetter() {
601 testing::Mock::VerifyAndClearExpectations(&resetter());
602 testing::Mock::VerifyAndClearExpectations(&mock_delegate());
604 resetter_
->Shutdown();
608 TestingProfile
* profile() { return profile_
.get(); }
609 TestingPrefServiceSimple
* local_state() { return local_state_
.Get(); }
611 PreferenceHostedPromptMemento
& memento_in_prefs() {
612 return *memento_in_prefs_
;
615 LocalStateHostedPromptMemento
& memento_in_local_state() {
616 return *memento_in_local_state_
;
619 FileHostedPromptMementoSynchronous
& memento_in_file() {
620 return *memento_in_file_
;
623 MockProfileResetterDelegate
& mock_delegate() { return *mock_delegate_
; }
624 AutomaticProfileResetterUnderTest
& resetter() { return *resetter_
; }
627 content::TestBrowserThreadBundle thread_bundle_
;
628 scoped_refptr
<base::TestSimpleTaskRunner
> waiting_task_runner_
;
629 ScopedTestingLocalState local_state_
;
630 scoped_ptr
<TestingProfile
> profile_
;
631 scoped_ptr
<base::FieldTrialList
> field_trials_
;
632 scoped_ptr
<PreferenceHostedPromptMemento
> memento_in_prefs_
;
633 scoped_ptr
<LocalStateHostedPromptMemento
> memento_in_local_state_
;
634 scoped_ptr
<FileHostedPromptMementoSynchronous
> memento_in_file_
;
636 std::string experiment_group_name_
;
637 std::string testing_program_
;
638 std::string testing_hash_seed_
;
639 bool inject_data_through_variation_params_
;
641 scoped_ptr
<AutomaticProfileResetterUnderTest
> resetter_
;
642 scoped_ptr
<MockProfileResetterDelegate
> mock_delegate_owned_
;
643 MockProfileResetterDelegate
* mock_delegate_
;
645 DISALLOW_COPY_AND_ASSIGN(AutomaticProfileResetterTestBase
);
648 class AutomaticProfileResetterTest
: public AutomaticProfileResetterTestBase
{
650 AutomaticProfileResetterTest()
651 : AutomaticProfileResetterTestBase(kStudyEnabledGroupName
) {}
654 class AutomaticProfileResetterTestDryRun
655 : public AutomaticProfileResetterTestBase
{
657 AutomaticProfileResetterTestDryRun()
658 : AutomaticProfileResetterTestBase(kStudyDryRunGroupName
) {}
661 class AutomaticProfileResetterTestDisabled
662 : public AutomaticProfileResetterTestBase
{
664 AutomaticProfileResetterTestDisabled()
665 : AutomaticProfileResetterTestBase(kStudyDisabledGroupName
) {}
668 // Tests ---------------------------------------------------------------------
670 TEST_F(AutomaticProfileResetterTestDisabled
, NothingIsDoneWhenDisabled
) {
671 SetTestingProgram(ConstructProgram(true, true));
672 SetTestingHashSeed(kTestHashSeed
);
674 // No calls are expected to the delegate.
676 UnleashResetterAndWait();
678 EXPECT_FALSE(resetter().ShouldShowResetBanner());
679 VerifyExpectationsThenShutdownResetter();
681 ExpectAllMementoValuesEqualTo(std::string());
684 TEST_F(AutomaticProfileResetterTestDryRun
, CriteriaNotSatisfied
) {
685 SetTestingProgram(ConstructProgramToExerciseCriteria(false, true, true));
686 SetTestingHashSeed(kTestHashSeed
);
688 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
689 mock_delegate().ExpectCallsToGetterMethods();
690 EXPECT_CALL(resetter(), ReportStatistics(0x1fu
, 0x00u
));
692 UnleashResetterAndWait();
694 EXPECT_FALSE(resetter().ShouldShowResetBanner());
695 VerifyExpectationsThenShutdownResetter();
697 ExpectAllMementoValuesEqualTo(std::string());
700 TEST_F(AutomaticProfileResetterTestDryRun
, OddCriteriaSatisfied
) {
701 SetTestingProgram(ConstructProgramToExerciseCriteria(true, true, false));
702 SetTestingHashSeed(kTestHashSeed
);
704 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
705 mock_delegate().ExpectCallsToGetterMethods();
706 EXPECT_CALL(resetter(), ReportStatistics(0x15u
, 0x01u
));
707 EXPECT_CALL(resetter(), ReportPromptResult(
708 AutomaticProfileResetter::PROMPT_NOT_TRIGGERED
));
710 UnleashResetterAndWait();
712 ExpectAllMementoValuesEqualTo(kTestMementoValue
);
713 EXPECT_FALSE(resetter().ShouldShowResetBanner());
714 VerifyExpectationsThenShutdownResetter();
717 TEST_F(AutomaticProfileResetterTestDryRun
, EvenCriteriaSatisfied
) {
718 SetTestingProgram(ConstructProgramToExerciseCriteria(true, false, true));
719 SetTestingHashSeed(kTestHashSeed
);
721 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
722 mock_delegate().ExpectCallsToGetterMethods();
723 EXPECT_CALL(resetter(), ReportStatistics(0x0au
, 0x01u
));
724 EXPECT_CALL(resetter(), ReportPromptResult(
725 AutomaticProfileResetter::PROMPT_NOT_TRIGGERED
));
727 UnleashResetterAndWait();
729 ExpectAllMementoValuesEqualTo(kTestMementoValue
);
730 EXPECT_FALSE(resetter().ShouldShowResetBanner());
731 VerifyExpectationsThenShutdownResetter();
734 #if defined(GOOGLE_CHROME_BUILD)
735 TEST_F(AutomaticProfileResetterTestDryRun
, ProgramSetThroughVariationParams
) {
736 SetTestingProgram(ConstructProgram(true, true));
737 SetTestingHashSeed(kTestHashSeed
);
738 AllowInjectingTestDataThroughVariationParams(true);
740 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
741 mock_delegate().ExpectCallsToGetterMethods();
742 EXPECT_CALL(resetter(), ReportStatistics(0x03u
, 0x01u
));
743 EXPECT_CALL(resetter(), ReportPromptResult(
744 AutomaticProfileResetter::PROMPT_NOT_TRIGGERED
));
746 UnleashResetterAndWait();
748 ExpectAllMementoValuesEqualTo(kTestMementoValue
);
749 EXPECT_FALSE(resetter().ShouldShowResetBanner());
750 VerifyExpectationsThenShutdownResetter();
754 TEST_F(AutomaticProfileResetterTestDryRun
,
755 ConditionsSatisfiedAndInvalidMementos
) {
756 memento_in_prefs().StoreValue(kTestInvalidMementoValue
);
757 memento_in_local_state().StoreValue(kTestInvalidMementoValue
);
758 memento_in_file().StoreValue(kTestInvalidMementoValue
);
760 SetTestingProgram(ConstructProgram(true, true));
761 SetTestingHashSeed(kTestHashSeed
);
763 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
764 mock_delegate().ExpectCallsToGetterMethods();
765 EXPECT_CALL(resetter(), ReportStatistics(0x03u
, 0x01u
));
766 EXPECT_CALL(resetter(), ReportPromptResult(
767 AutomaticProfileResetter::PROMPT_NOT_TRIGGERED
));
769 UnleashResetterAndWait();
771 ExpectAllMementoValuesEqualTo(kTestMementoValue
);
772 EXPECT_FALSE(resetter().ShouldShowResetBanner());
773 VerifyExpectationsThenShutdownResetter();
776 TEST_F(AutomaticProfileResetterTestDryRun
, AlreadyHadPrefHostedMemento
) {
777 memento_in_prefs().StoreValue(kTestMementoValue
);
779 SetTestingProgram(ConstructProgram(true, true));
780 SetTestingHashSeed(kTestHashSeed
);
782 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
783 mock_delegate().ExpectCallsToGetterMethods();
784 EXPECT_CALL(resetter(), ReportStatistics(0x03u
, 0x03u
));
786 UnleashResetterAndWait();
788 EXPECT_FALSE(resetter().ShouldShowResetBanner());
789 VerifyExpectationsThenShutdownResetter();
791 EXPECT_EQ(kTestMementoValue
, memento_in_prefs().ReadValue());
792 EXPECT_EQ(std::string(), memento_in_local_state().ReadValue());
793 EXPECT_EQ(std::string(), memento_in_file().ReadValue());
796 TEST_F(AutomaticProfileResetterTestDryRun
, AlreadyHadLocalStateHostedMemento
) {
797 memento_in_local_state().StoreValue(kTestMementoValue
);
799 SetTestingProgram(ConstructProgram(true, true));
800 SetTestingHashSeed(kTestHashSeed
);
802 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
803 mock_delegate().ExpectCallsToGetterMethods();
804 EXPECT_CALL(resetter(), ReportStatistics(0x03u
, 0x05u
));
806 UnleashResetterAndWait();
808 EXPECT_FALSE(resetter().ShouldShowResetBanner());
809 VerifyExpectationsThenShutdownResetter();
811 EXPECT_EQ(std::string(), memento_in_prefs().ReadValue());
812 EXPECT_EQ(kTestMementoValue
, memento_in_local_state().ReadValue());
813 EXPECT_EQ(std::string(), memento_in_file().ReadValue());
816 TEST_F(AutomaticProfileResetterTestDryRun
, AlreadyHadFileHostedMemento
) {
817 memento_in_file().StoreValue(kTestMementoValue
);
819 SetTestingProgram(ConstructProgram(true, true));
820 SetTestingHashSeed(kTestHashSeed
);
822 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
823 mock_delegate().ExpectCallsToGetterMethods();
824 EXPECT_CALL(resetter(), ReportStatistics(0x03u
, 0x09u
));
826 UnleashResetterAndWait();
828 EXPECT_FALSE(resetter().ShouldShowResetBanner());
829 VerifyExpectationsThenShutdownResetter();
831 EXPECT_EQ(std::string(), memento_in_prefs().ReadValue());
832 EXPECT_EQ(std::string(), memento_in_local_state().ReadValue());
833 EXPECT_EQ(kTestMementoValue
, memento_in_file().ReadValue());
836 TEST_F(AutomaticProfileResetterTestDryRun
, DoNothingWhenResourcesAreMissing
) {
837 SetTestingProgram(std::string());
838 SetTestingHashSeed(std::string());
840 // No calls are expected to the delegate.
842 UnleashResetterAndWait();
844 EXPECT_FALSE(resetter().ShouldShowResetBanner());
845 VerifyExpectationsThenShutdownResetter();
847 ExpectAllMementoValuesEqualTo(std::string());
850 TEST_F(AutomaticProfileResetterTest
, CriteriaNotSatisfied
) {
851 SetTestingProgram(ConstructProgramToExerciseCriteria(false, true, true));
852 SetTestingHashSeed(kTestHashSeed
);
854 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
855 mock_delegate().ExpectCallsToGetterMethods();
856 EXPECT_CALL(resetter(), ReportStatistics(0x1fu
, 0x00u
));
858 UnleashResetterAndWait();
860 EXPECT_FALSE(resetter().ShouldShowResetBanner());
861 VerifyExpectationsThenShutdownResetter();
863 ExpectAllMementoValuesEqualTo(std::string());
866 TEST_F(AutomaticProfileResetterTest
, OddCriteriaSatisfied
) {
867 SetTestingProgram(ConstructProgramToExerciseCriteria(true, true, false));
868 SetTestingHashSeed(kTestHashSeed
);
870 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
871 mock_delegate().ExpectCallsToGetterMethods();
872 mock_delegate().ExpectCallToShowPrompt();
873 EXPECT_CALL(resetter(), ReportStatistics(0x15u
, 0x01u
));
875 UnleashResetterAndWait();
877 EXPECT_TRUE(resetter().ShouldShowResetBanner());
878 VerifyExpectationsThenShutdownResetter();
881 TEST_F(AutomaticProfileResetterTest
, EvenCriteriaSatisfied
) {
882 SetTestingProgram(ConstructProgramToExerciseCriteria(true, false, true));
883 SetTestingHashSeed(kTestHashSeed
);
885 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
886 mock_delegate().ExpectCallsToGetterMethods();
887 mock_delegate().ExpectCallToShowPrompt();
888 EXPECT_CALL(resetter(), ReportStatistics(0x0au
, 0x01u
));
890 UnleashResetterAndWait();
892 EXPECT_TRUE(resetter().ShouldShowResetBanner());
893 VerifyExpectationsThenShutdownResetter();
896 #if defined(GOOGLE_CHROME_BUILD)
897 TEST_F(AutomaticProfileResetterTest
, ProgramSetThroughVariationParams
) {
898 SetTestingProgram(ConstructProgram(true, true));
899 SetTestingHashSeed(kTestHashSeed
);
900 AllowInjectingTestDataThroughVariationParams(true);
902 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
903 mock_delegate().ExpectCallsToGetterMethods();
904 mock_delegate().ExpectCallToShowPrompt();
905 EXPECT_CALL(resetter(), ReportStatistics(0x03u
, 0x01u
));
906 EXPECT_CALL(resetter(), ReportPromptResult(
907 AutomaticProfileResetter::PROMPT_SHOWN_BUBBLE
));
909 UnleashResetterAndWait();
910 resetter().NotifyDidShowResetBubble();
912 ExpectAllMementoValuesEqualTo(kTestMementoValue
);
913 EXPECT_TRUE(resetter().ShouldShowResetBanner());
914 VerifyExpectationsThenShutdownResetter();
918 TEST_F(AutomaticProfileResetterTest
, ConditionsSatisfiedAndInvalidMementos
) {
919 memento_in_prefs().StoreValue(kTestInvalidMementoValue
);
920 memento_in_local_state().StoreValue(kTestInvalidMementoValue
);
921 memento_in_file().StoreValue(kTestInvalidMementoValue
);
923 SetTestingProgram(ConstructProgram(true, true));
924 SetTestingHashSeed(kTestHashSeed
);
926 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
927 mock_delegate().ExpectCallsToGetterMethods();
928 mock_delegate().ExpectCallToShowPrompt();
929 EXPECT_CALL(resetter(), ReportStatistics(0x03u
, 0x01u
));
930 EXPECT_CALL(resetter(), ReportPromptResult(
931 AutomaticProfileResetter::PROMPT_SHOWN_BUBBLE
));
933 UnleashResetterAndWait();
934 resetter().NotifyDidShowResetBubble();
936 ExpectAllMementoValuesEqualTo(kTestMementoValue
);
937 EXPECT_TRUE(resetter().ShouldShowResetBanner());
938 VerifyExpectationsThenShutdownResetter();
941 TEST_F(AutomaticProfileResetterTest
, PrefHostedMementoPreventsPrompt
) {
942 memento_in_prefs().StoreValue(kTestMementoValue
);
944 SetTestingProgram(ConstructProgram(true, true));
945 SetTestingHashSeed(kTestHashSeed
);
947 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
948 mock_delegate().ExpectCallsToGetterMethods();
949 EXPECT_CALL(resetter(), ReportStatistics(0x03u
, 0x03u
));
951 UnleashResetterAndWait();
953 EXPECT_TRUE(resetter().ShouldShowResetBanner());
954 VerifyExpectationsThenShutdownResetter();
956 EXPECT_EQ(kTestMementoValue
, memento_in_prefs().ReadValue());
957 EXPECT_EQ(std::string(), memento_in_local_state().ReadValue());
958 EXPECT_EQ(std::string(), memento_in_file().ReadValue());
961 TEST_F(AutomaticProfileResetterTest
, LocalStateHostedMementoPreventsPrompt
) {
962 memento_in_local_state().StoreValue(kTestMementoValue
);
964 SetTestingProgram(ConstructProgram(true, true));
965 SetTestingHashSeed(kTestHashSeed
);
967 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
968 mock_delegate().ExpectCallsToGetterMethods();
969 EXPECT_CALL(resetter(), ReportStatistics(0x03u
, 0x05u
));
971 UnleashResetterAndWait();
973 EXPECT_TRUE(resetter().ShouldShowResetBanner());
974 VerifyExpectationsThenShutdownResetter();
976 EXPECT_EQ(std::string(), memento_in_prefs().ReadValue());
977 EXPECT_EQ(kTestMementoValue
, memento_in_local_state().ReadValue());
978 EXPECT_EQ(std::string(), memento_in_file().ReadValue());
981 TEST_F(AutomaticProfileResetterTest
, FileHostedMementoPreventsPrompt
) {
982 memento_in_file().StoreValue(kTestMementoValue
);
984 SetTestingProgram(ConstructProgram(true, true));
985 SetTestingHashSeed(kTestHashSeed
);
987 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
988 mock_delegate().ExpectCallsToGetterMethods();
989 EXPECT_CALL(resetter(), ReportStatistics(0x03u
, 0x09u
));
991 UnleashResetterAndWait();
993 EXPECT_TRUE(resetter().ShouldShowResetBanner());
994 VerifyExpectationsThenShutdownResetter();
996 EXPECT_EQ(std::string(), memento_in_prefs().ReadValue());
997 EXPECT_EQ(std::string(), memento_in_local_state().ReadValue());
998 EXPECT_EQ(kTestMementoValue
, memento_in_file().ReadValue());
1001 TEST_F(AutomaticProfileResetterTest
, DoNothingWhenResourcesAreMissing
) {
1002 SetTestingProgram(std::string());
1003 SetTestingHashSeed(std::string());
1005 // No calls are expected to the delegate.
1007 UnleashResetterAndWait();
1009 EXPECT_FALSE(resetter().ShouldShowResetBanner());
1010 VerifyExpectationsThenShutdownResetter();
1012 ExpectAllMementoValuesEqualTo(std::string());
1015 TEST_F(AutomaticProfileResetterTest
, PromptSuppressed
) {
1016 OrchestrateThroughEvaluationFlow();
1018 VerifyExpectationsThenShutdownResetter();
1020 ExpectAllMementoValuesEqualTo(std::string());
1023 TEST_F(AutomaticProfileResetterTest
, PromptNotSupported
) {
1024 SetTestingProgram(ConstructProgram(true, true));
1025 SetTestingHashSeed(kTestHashSeed
);
1027 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
1028 mock_delegate().ExpectCallsToGetterMethods();
1029 EXPECT_CALL(mock_delegate(), TriggerPrompt())
1030 .WillOnce(testing::Return(false));
1031 EXPECT_CALL(resetter(), ReportStatistics(0x03u
, 0x01u
));
1032 EXPECT_CALL(resetter(), ReportPromptResult(
1033 AutomaticProfileResetter::PROMPT_NOT_TRIGGERED
));
1035 UnleashResetterAndWait();
1037 ExpectAllMementoValuesEqualTo(kTestMementoValue
);
1038 EXPECT_TRUE(resetter().ShouldShowResetBanner());
1039 VerifyExpectationsThenShutdownResetter();
1042 TEST_F(AutomaticProfileResetterTest
, PromptIgnored
) {
1043 OrchestrateThroughEvaluationFlow();
1045 EXPECT_CALL(resetter(), ReportPromptResult(
1046 AutomaticProfileResetter::PROMPT_SHOWN_BUBBLE
));
1047 resetter().NotifyDidShowResetBubble();
1048 ExpectAllMementoValuesEqualTo(kTestMementoValue
);
1049 VerifyExpectationsThenShutdownResetter();
1052 TEST_F(AutomaticProfileResetterTest
, PromptActionReset
) {
1053 OrchestrateThroughEvaluationFlow();
1055 EXPECT_CALL(resetter(), ReportPromptResult(
1056 AutomaticProfileResetter::PROMPT_SHOWN_BUBBLE
));
1057 resetter().NotifyDidShowResetBubble();
1058 ExpectAllMementoValuesEqualTo(kTestMementoValue
);
1059 testing::Mock::VerifyAndClearExpectations(&resetter());
1061 mock_delegate().ExpectCallToTriggerReset(false);
1062 EXPECT_CALL(resetter(), ReportPromptResult(
1063 AutomaticProfileResetter::PROMPT_ACTION_RESET
));
1064 resetter().TriggerProfileReset(false /*send_feedback*/);
1065 testing::Mock::VerifyAndClearExpectations(&resetter());
1066 testing::Mock::VerifyAndClearExpectations(&mock_delegate());
1068 EXPECT_CALL(mock_delegate(), DismissPrompt());
1069 mock_delegate().EmulateProfileResetCompleted();
1070 EXPECT_FALSE(resetter().ShouldShowResetBanner());
1071 VerifyExpectationsThenShutdownResetter();
1074 TEST_F(AutomaticProfileResetterTest
, PromptActionResetWithFeedback
) {
1075 OrchestrateThroughEvaluationFlow();
1077 EXPECT_CALL(resetter(), ReportPromptResult(
1078 AutomaticProfileResetter::PROMPT_SHOWN_BUBBLE
));
1079 resetter().NotifyDidShowResetBubble();
1080 ExpectAllMementoValuesEqualTo(kTestMementoValue
);
1081 testing::Mock::VerifyAndClearExpectations(&resetter());
1083 mock_delegate().ExpectCallToTriggerReset(true);
1084 EXPECT_CALL(resetter(), ReportPromptResult(
1085 AutomaticProfileResetter::PROMPT_ACTION_RESET
));
1086 resetter().TriggerProfileReset(true /*send_feedback*/);
1087 testing::Mock::VerifyAndClearExpectations(&resetter());
1088 testing::Mock::VerifyAndClearExpectations(&mock_delegate());
1090 EXPECT_CALL(mock_delegate(), DismissPrompt());
1091 mock_delegate().EmulateProfileResetCompleted();
1092 EXPECT_FALSE(resetter().ShouldShowResetBanner());
1093 VerifyExpectationsThenShutdownResetter();
1096 TEST_F(AutomaticProfileResetterTest
, PromptActionNoReset
) {
1097 OrchestrateThroughEvaluationFlow();
1099 EXPECT_CALL(resetter(), ReportPromptResult(
1100 AutomaticProfileResetter::PROMPT_SHOWN_BUBBLE
));
1101 resetter().NotifyDidShowResetBubble();
1102 ExpectAllMementoValuesEqualTo(kTestMementoValue
);
1103 testing::Mock::VerifyAndClearExpectations(&resetter());
1105 EXPECT_CALL(mock_delegate(), DismissPrompt());
1106 EXPECT_CALL(resetter(), ReportPromptResult(
1107 AutomaticProfileResetter::PROMPT_ACTION_NO_RESET
));
1108 resetter().SkipProfileReset();
1109 EXPECT_FALSE(resetter().ShouldShowResetBanner());
1110 VerifyExpectationsThenShutdownResetter();
1113 TEST_F(AutomaticProfileResetterTest
, PromptFollowedByWebUIReset
) {
1114 OrchestrateThroughEvaluationFlow();
1116 EXPECT_CALL(resetter(), ReportPromptResult(
1117 AutomaticProfileResetter::PROMPT_SHOWN_BUBBLE
));
1118 resetter().NotifyDidShowResetBubble();
1119 ExpectAllMementoValuesEqualTo(kTestMementoValue
);
1120 testing::Mock::VerifyAndClearExpectations(&resetter());
1122 EXPECT_CALL(mock_delegate(), DismissPrompt());
1123 resetter().NotifyDidOpenWebUIResetDialog();
1124 testing::Mock::VerifyAndClearExpectations(&mock_delegate());
1126 EXPECT_CALL(resetter(), ReportPromptResult(
1127 AutomaticProfileResetter::PROMPT_FOLLOWED_BY_WEBUI_RESET
));
1128 resetter().NotifyDidCloseWebUIResetDialog(true);
1129 EXPECT_TRUE(resetter().ShouldShowResetBanner());
1130 VerifyExpectationsThenShutdownResetter();
1133 TEST_F(AutomaticProfileResetterTest
, PromptFollowedByWebUINoReset
) {
1134 OrchestrateThroughEvaluationFlow();
1136 EXPECT_CALL(resetter(), ReportPromptResult(
1137 AutomaticProfileResetter::PROMPT_SHOWN_BUBBLE
));
1138 resetter().NotifyDidShowResetBubble();
1139 ExpectAllMementoValuesEqualTo(kTestMementoValue
);
1140 testing::Mock::VerifyAndClearExpectations(&resetter());
1142 EXPECT_CALL(mock_delegate(), DismissPrompt());
1143 resetter().NotifyDidOpenWebUIResetDialog();
1144 testing::Mock::VerifyAndClearExpectations(&mock_delegate());
1146 EXPECT_CALL(resetter(), ReportPromptResult(
1147 AutomaticProfileResetter::PROMPT_FOLLOWED_BY_WEBUI_NO_RESET
));
1148 resetter().NotifyDidCloseWebUIResetDialog(false);
1149 EXPECT_TRUE(resetter().ShouldShowResetBanner());
1150 VerifyExpectationsThenShutdownResetter();
1153 TEST_F(AutomaticProfileResetterTest
, PromptFollowedByIncidentalWebUIReset
) {
1154 OrchestrateThroughEvaluationFlow();
1156 EXPECT_CALL(resetter(), ReportPromptResult(
1157 AutomaticProfileResetter::PROMPT_SHOWN_BUBBLE
));
1158 resetter().NotifyDidShowResetBubble();
1159 ExpectAllMementoValuesEqualTo(kTestMementoValue
);
1160 testing::Mock::VerifyAndClearExpectations(&resetter());
1162 // Missing NotifyDidOpenWebUIResetDialog().
1163 // This can arise if a settings page was already opened at the time the prompt
1164 // was triggered, and this already opened dialog was used to initiate a reset
1165 // after having dismissed the prompt.
1167 EXPECT_CALL(mock_delegate(), DismissPrompt());
1168 EXPECT_CALL(resetter(), ReportPromptResult(
1169 AutomaticProfileResetter::PROMPT_FOLLOWED_BY_WEBUI_RESET
));
1170 resetter().NotifyDidCloseWebUIResetDialog(true);
1171 EXPECT_TRUE(resetter().ShouldShowResetBanner());
1172 VerifyExpectationsThenShutdownResetter();
1175 TEST_F(AutomaticProfileResetterTest
, PromptSuppressedButHadWebUIReset
) {
1176 OrchestrateThroughEvaluationFlow();
1178 EXPECT_CALL(mock_delegate(), DismissPrompt());
1179 resetter().NotifyDidOpenWebUIResetDialog();
1180 testing::Mock::VerifyAndClearExpectations(&mock_delegate());
1182 EXPECT_CALL(resetter(), ReportPromptResult(
1183 AutomaticProfileResetter::PROMPT_NOT_SHOWN_BUBBLE_BUT_HAD_WEBUI_RESET
));
1184 resetter().NotifyDidCloseWebUIResetDialog(true);
1185 ExpectAllMementoValuesEqualTo(kTestMementoValue
);
1186 EXPECT_TRUE(resetter().ShouldShowResetBanner());
1187 VerifyExpectationsThenShutdownResetter();
1190 TEST_F(AutomaticProfileResetterTest
, PromptSuppressedButHadWebUINoReset
) {
1191 OrchestrateThroughEvaluationFlow();
1193 EXPECT_CALL(mock_delegate(), DismissPrompt());
1194 resetter().NotifyDidOpenWebUIResetDialog();
1195 testing::Mock::VerifyAndClearExpectations(&mock_delegate());
1197 EXPECT_CALL(resetter(), ReportPromptResult(AutomaticProfileResetter::
1198 PROMPT_NOT_SHOWN_BUBBLE_BUT_HAD_WEBUI_NO_RESET
));
1199 resetter().NotifyDidCloseWebUIResetDialog(false);
1200 ExpectAllMementoValuesEqualTo(kTestMementoValue
);
1201 EXPECT_TRUE(resetter().ShouldShowResetBanner());
1202 VerifyExpectationsThenShutdownResetter();
1205 TEST_F(AutomaticProfileResetterTest
, BannerDismissed
) {
1206 OrchestrateThroughEvaluationFlow();
1208 EXPECT_CALL(resetter(), ReportPromptResult(
1209 AutomaticProfileResetter::PROMPT_SHOWN_BUBBLE
));
1210 resetter().NotifyDidShowResetBubble();
1211 ExpectAllMementoValuesEqualTo(kTestMementoValue
);
1212 testing::Mock::VerifyAndClearExpectations(&resetter());
1214 resetter().NotifyDidCloseWebUIResetBanner();
1216 EXPECT_TRUE(resetter().IsResetPromptFlowActive());
1217 EXPECT_FALSE(resetter().ShouldShowResetBanner());
1219 // Note: we use strict mocks, so this also checks the bubble is not closed.
1220 VerifyExpectationsThenShutdownResetter();
1223 TEST_F(AutomaticProfileResetterTest
, BannerDismissedWhilePromptSuppressed
) {
1224 OrchestrateThroughEvaluationFlow();
1226 resetter().NotifyDidCloseWebUIResetBanner();
1228 EXPECT_TRUE(resetter().IsResetPromptFlowActive());
1229 EXPECT_FALSE(resetter().ShouldShowResetBanner());
1230 VerifyExpectationsThenShutdownResetter();
1232 ExpectAllMementoValuesEqualTo(std::string());
1235 // Please see comments above ConstructProgramToCheckPreferences() to understand
1236 // how the following tests work.
1238 TEST_F(AutomaticProfileResetterTest
, InputUserPreferencesCorrect
) {
1239 SetTestingProgram(ConstructProgramToCheckPreferences());
1240 SetTestingHashSeed(kTestHashSeed
);
1242 PrefService
* prefs
= profile()->GetPrefs();
1243 prefs
->SetString(kTestPreferencePath
, kTestPreferenceValue
);
1245 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
1246 mock_delegate().ExpectCallsToGetterMethods();
1247 uint32 expected_mask
= HAS_EXPECTED_USER_PREFERENCE
|
1248 USER_PREFERENCE_IS_USER_CONTROLLED
;
1249 EXPECT_CALL(resetter(), ReportStatistics(0x00u
, expected_mask
));
1251 UnleashResetterAndWait();
1254 TEST_F(AutomaticProfileResetterTest
, InputLocalStateCorrect
) {
1255 SetTestingProgram(ConstructProgramToCheckPreferences());
1256 SetTestingHashSeed(kTestHashSeed
);
1258 PrefService
* prefs
= local_state();
1259 prefs
->SetString(kTestPreferencePath
, kTestPreferenceValue
);
1261 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
1262 mock_delegate().ExpectCallsToGetterMethods();
1263 uint32 expected_mask
= HAS_EXPECTED_LOCAL_STATE_PREFERENCE
|
1264 LOCAL_STATE_IS_USER_CONTROLLED
;
1265 EXPECT_CALL(resetter(), ReportStatistics(0x00u
, expected_mask
));
1267 UnleashResetterAndWait();
1270 TEST_F(AutomaticProfileResetterTest
, InputManagedUserPreferencesCorrect
) {
1271 SetTestingProgram(ConstructProgramToCheckPreferences());
1272 SetTestingHashSeed(kTestHashSeed
);
1274 TestingPrefServiceSyncable
* prefs
= profile()->GetTestingPrefService();
1275 prefs
->SetManagedPref(kTestPreferencePath
,
1276 new base::StringValue(kTestPreferenceValue
));
1278 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
1279 mock_delegate().ExpectCallsToGetterMethods();
1280 uint32 expected_mask
= HAS_EXPECTED_USER_PREFERENCE
;
1281 EXPECT_CALL(resetter(), ReportStatistics(0x00u
, expected_mask
));
1283 UnleashResetterAndWait();
1286 TEST_F(AutomaticProfileResetterTest
, InputManagedLocalStateCorrect
) {
1287 SetTestingProgram(ConstructProgramToCheckPreferences());
1288 SetTestingHashSeed(kTestHashSeed
);
1290 TestingPrefServiceSimple
* prefs
= local_state();
1291 prefs
->SetManagedPref(kTestPreferencePath
,
1292 new base::StringValue(kTestPreferenceValue
));
1294 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
1295 mock_delegate().ExpectCallsToGetterMethods();
1296 uint32 expected_mask
= HAS_EXPECTED_LOCAL_STATE_PREFERENCE
;
1297 EXPECT_CALL(resetter(), ReportStatistics(0x00u
, expected_mask
));
1299 UnleashResetterAndWait();
1302 // Please see comments above ConstructProgramToCheckSearchEngines() to
1303 // understand how the following tests work.
1305 TEST_F(AutomaticProfileResetterTest
, InputDefaultSearchProviderCorrect
) {
1306 SetTestingProgram(ConstructProgramToCheckSearchEngines());
1307 SetTestingHashSeed(kTestHashSeed
);
1309 mock_delegate().emulated_default_search_provider_details().SetString(
1310 kSearchURLAttributeKey
, kTestSearchURL
);
1312 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
1313 mock_delegate().ExpectCallsToGetterMethods();
1314 uint32 expected_mask
= HAS_EXPECTED_DEFAULT_SEARCH_PROVIDER
|
1315 DEFAULT_SEARCH_PROVIDER_IS_USER_CONTROLLED
;
1316 EXPECT_CALL(resetter(), ReportStatistics(0x00u
, expected_mask
));
1318 UnleashResetterAndWait();
1321 TEST_F(AutomaticProfileResetterTest
, InputSearchProviderManagedCorrect
) {
1322 SetTestingProgram(ConstructProgramToCheckSearchEngines());
1323 SetTestingHashSeed(kTestHashSeed
);
1325 mock_delegate().emulated_default_search_provider_details().SetString(
1326 kSearchURLAttributeKey
, kTestSearchURL
);
1327 mock_delegate().set_emulated_is_default_search_provider_managed(true);
1329 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
1330 mock_delegate().ExpectCallsToGetterMethods();
1331 uint32 expected_mask
= HAS_EXPECTED_DEFAULT_SEARCH_PROVIDER
;
1332 EXPECT_CALL(resetter(), ReportStatistics(0x00u
, expected_mask
));
1334 UnleashResetterAndWait();
1337 TEST_F(AutomaticProfileResetterTest
, InputSearchProvidersCorrect
) {
1338 SetTestingProgram(ConstructProgramToCheckSearchEngines());
1339 SetTestingHashSeed(kTestHashSeed
);
1341 base::DictionaryValue
* search_provider_1
= new base::DictionaryValue
;
1342 base::DictionaryValue
* search_provider_2
= new base::DictionaryValue
;
1343 search_provider_1
->SetString(kSearchURLAttributeKey
, kTestSearchURL
);
1344 search_provider_2
->SetString(kSearchURLAttributeKey
, kTestSearchURL2
);
1345 mock_delegate().emulated_search_providers_details().Append(search_provider_1
);
1346 mock_delegate().emulated_search_providers_details().Append(search_provider_2
);
1348 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
1349 mock_delegate().ExpectCallsToGetterMethods();
1350 uint32 expected_mask
= DEFAULT_SEARCH_PROVIDER_IS_USER_CONTROLLED
|
1351 HAS_EXPECTED_PREPOPULATED_SEARCH_PROVIDER_1
|
1352 HAS_EXPECTED_PREPOPULATED_SEARCH_PROVIDER_2
;
1353 EXPECT_CALL(resetter(), ReportStatistics(0x00u
, expected_mask
));
1355 UnleashResetterAndWait();
1358 // Please see comments above ConstructProgramToCheckLoadedModuleDigests() to
1359 // understand how the following tests work.
1361 TEST_F(AutomaticProfileResetterTest
, InputModuleDigestsCorrect
) {
1362 SetTestingProgram(ConstructProgramToCheckLoadedModuleDigests());
1363 SetTestingHashSeed(kTestHashSeed
);
1365 mock_delegate().emulated_loaded_module_digests().AppendString(
1367 mock_delegate().emulated_loaded_module_digests().AppendString(
1368 kTestModuleDigest2
);
1370 mock_delegate().ExpectCallsToDependenciesSetUpMethods();
1371 mock_delegate().ExpectCallsToGetterMethods();
1372 uint32 expected_mask
=
1373 HAS_EXPECTED_MODULE_DIGEST_1
| HAS_EXPECTED_MODULE_DIGEST_2
;
1374 EXPECT_CALL(resetter(), ReportStatistics(0x00u
, expected_mask
));
1376 UnleashResetterAndWait();