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

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: 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"
11 #include "base/threading/sequenced_worker_pool.h" 13 #include "base/threading/sequenced_worker_pool.h"
12 #include "chrome/browser/profile_resetter/automatic_profile_resetter.h" 14 #include "chrome/browser/profile_resetter/automatic_profile_resetter.h"
15 #include "chrome/browser/profile_resetter/automatic_profile_resetter_delegate.h"
13 #include "chrome/browser/profile_resetter/automatic_profile_resetter_factory.h" 16 #include "chrome/browser/profile_resetter/automatic_profile_resetter_factory.h"
14 #include "chrome/browser/profile_resetter/automatic_profile_resetter_mementos.h" 17 #include "chrome/browser/profile_resetter/automatic_profile_resetter_mementos.h"
15 #include "chrome/browser/profile_resetter/jtl_foundation.h" 18 #include "chrome/browser/profile_resetter/jtl_foundation.h"
16 #include "chrome/browser/profile_resetter/jtl_instructions.h" 19 #include "chrome/browser/profile_resetter/jtl_instructions.h"
17 #include "chrome/test/base/scoped_testing_local_state.h" 20 #include "chrome/test/base/scoped_testing_local_state.h"
18 #include "chrome/test/base/testing_browser_process.h" 21 #include "chrome/test/base/testing_browser_process.h"
22 #include "chrome/test/base/testing_pref_service_syncable.h"
19 #include "chrome/test/base/testing_profile.h" 23 #include "chrome/test/base/testing_profile.h"
24 #include "components/user_prefs/pref_registry_syncable.h"
20 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
21 #include "content/public/test/test_browser_thread_bundle.h" 26 #include "content/public/test/test_browser_thread_bundle.h"
22 #include "testing/gmock/include/gmock/gmock.h" 27 #include "testing/gmock/include/gmock/gmock.h"
23 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
24 29
30 using testing::_;
31 using testing::Invoke;
32 using testing::Return;
33
25 namespace { 34 namespace {
26 35
27 const char kAutomaticProfileResetStudyName[] = "AutomaticProfileReset"; 36 const char kAutomaticProfileResetStudyName[] = "AutomaticProfileReset";
28 const char kStudyDisabledGroupName[] = "Disabled"; 37 const char kStudyDisabledGroupName[] = "Disabled";
29 const char kStudyDryRunGroupName[] = "DryRun"; 38 const char kStudyDryRunGroupName[] = "DryRun";
30 const char kStudyEnabledGroupName[] = "Enabled"; 39 const char kStudyEnabledGroupName[] = "Enabled";
31 40
32 const char kTestHashSeed[] = "testing-hash-seed"; 41 const char kTestHashSeed[] = "testing-hash-seed";
33 const char kTestMementoValue[] = "01234567890123456789012345678901"; 42 const char kTestMementoValue[] = "01234567890123456789012345678901";
34 const char kTestInvalidMementoValue[] = "12345678901234567890123456789012"; 43 const char kTestInvalidMementoValue[] = "12345678901234567890123456789012";
35 44
45 const char kTestPreferencePath[] = "testing.preference";
46 const char kTestPreferenceValue[] = "testing-preference-value";
47
48 const char kSearchURLAttributeKey[] = "search_url";
49 const char kTestSearchURL[] = "http://example.com/search?q={searchTerms}";
50 const char kTestSearchURL2[] = "http://google.com/?q={searchTerms}";
51
36 // Helpers ------------------------------------------------------------------ 52 // Helpers ------------------------------------------------------------------
37 53
38 class MockProfileResetterDelegate : public AutomaticProfileResetterDelegate { 54 class MockProfileResetterDelegate : public AutomaticProfileResetterDelegate {
39 public: 55 public:
40 MockProfileResetterDelegate() {} 56 MockProfileResetterDelegate()
57 : emulated_default_search_provider_is_managed_(false) {}
41 virtual ~MockProfileResetterDelegate() {} 58 virtual ~MockProfileResetterDelegate() {}
42 59
60 MOCK_METHOD0(LoadTemplateURLServiceIfNeeded, void());
61 MOCK_METHOD1(WaitOnTemplateURLService, void(const base::Closure&));
62
63 MOCK_CONST_METHOD0(GetDefaultSearchProviderDetails, base::DictionaryValue*());
64 MOCK_CONST_METHOD0(IsDefaultSearchProviderManaged, bool());
65 MOCK_CONST_METHOD0(GetPrepopulatedSearchProvidersDetails, base::ListValue*());
66
43 MOCK_METHOD0(ShowPrompt, void()); 67 MOCK_METHOD0(ShowPrompt, void());
44 MOCK_METHOD2(ReportStatistics, void(uint32, uint32)); 68 MOCK_METHOD2(ReportStatistics, void(uint32, uint32));
45 69
70 static void ClosureInvoker(const base::Closure& closure) { closure.Run(); }
71
72 void ExpectCallsToWaitingMethods() {
73 EXPECT_CALL(*this, WaitOnTemplateURLService(_))
74 .WillOnce(Invoke(ClosureInvoker));
75 EXPECT_CALL(*this, LoadTemplateURLServiceIfNeeded());
76 }
77
78 void ExpectCallsToGetterMethods() {
79 EXPECT_CALL(*this, GetDefaultSearchProviderDetails())
80 .WillRepeatedly(Invoke(&emulated_default_search_provider_details_,
81 &base::DictionaryValue::DeepCopy));
82 EXPECT_CALL(*this, IsDefaultSearchProviderManaged())
83 .WillRepeatedly(Return(emulated_default_search_provider_is_managed_));
84 EXPECT_CALL(*this, GetPrepopulatedSearchProvidersDetails())
85 .WillRepeatedly(Invoke(&emulated_search_providers_details_,
86 &base::ListValue::DeepCopy));
87 }
88
89 base::DictionaryValue& emulated_default_search_provider_details() {
90 return emulated_default_search_provider_details_;
91 }
92
93 base::ListValue& emulated_search_providers_details() {
94 return emulated_search_providers_details_;
95 }
96
97 void set_emulated_default_search_provider_is_managed(bool value) {
98 emulated_default_search_provider_is_managed_ = value;
99 }
100
46 private: 101 private:
102 base::DictionaryValue emulated_default_search_provider_details_;
103 bool emulated_default_search_provider_is_managed_;
104 base::ListValue emulated_search_providers_details_;
105
47 DISALLOW_COPY_AND_ASSIGN(MockProfileResetterDelegate); 106 DISALLOW_COPY_AND_ASSIGN(MockProfileResetterDelegate);
48 }; 107 };
49 108
50 class FileHostedPromptMementoSynchronous : protected FileHostedPromptMemento { 109 class FileHostedPromptMementoSynchronous : protected FileHostedPromptMemento {
51 public: 110 public:
52 explicit FileHostedPromptMementoSynchronous(Profile* profile) 111 explicit FileHostedPromptMementoSynchronous(Profile* profile)
53 : FileHostedPromptMemento(profile) {} 112 : FileHostedPromptMemento(profile) {}
54 113
55 std::string ReadValue() const { 114 std::string ReadValue() const {
56 std::string result; 115 std::string result;
(...skipping 15 matching lines...) Expand all
72 DISALLOW_COPY_AND_ASSIGN(FileHostedPromptMementoSynchronous); 131 DISALLOW_COPY_AND_ASSIGN(FileHostedPromptMementoSynchronous);
73 }; 132 };
74 133
75 std::string GetHash(const std::string& input) { 134 std::string GetHash(const std::string& input) {
76 return jtl_foundation::Hasher(kTestHashSeed).GetHash(input); 135 return jtl_foundation::Hasher(kTestHashSeed).GetHash(input);
77 } 136 }
78 137
79 // Encodes a Boolean argument value into JTL bytecode. 138 // Encodes a Boolean argument value into JTL bytecode.
80 std::string EncodeBool(bool value) { return value ? VALUE_TRUE : VALUE_FALSE; } 139 std::string EncodeBool(bool value) { return value ? VALUE_TRUE : VALUE_FALSE; }
81 140
82 // Constructs a simple evaluation program to test that input/output works well. 141 // 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 142 // 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 143 // 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 144 // combined status mask according to whether or not the memento values received
86 // in the input were as expected. 145 // in the input were as expected.
87 // 146 //
88 // More specifically, the output of the program will be as follows: 147 // More specifically, the output of the program will be as follows:
89 // { 148 // {
90 // "satisfied_criteria_mask_bit1": emulate_satisfied_criterion_1, 149 // "satisfied_criteria_mask_bit1": emulate_satisfied_criterion_1,
91 // "satisfied_criteria_mask_bit2": emulate_satisfied_criterion_2, 150 // "satisfied_criteria_mask_bit2": emulate_satisfied_criterion_2,
92 // "combined_status_mask_bit1": 151 // "combined_status_mask_bit1":
93 // (emulate_satisfied_criterion_1 || emulate_satisfied_criterion_2), 152 // (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; 194 bytecode += OP_END_OF_SENTENCE;
136 bytecode += OP_STORE_HASH(GetHash("memento_value_in_local_state"), 195 bytecode += OP_STORE_HASH(GetHash("memento_value_in_local_state"),
137 kTestMementoValue); 196 kTestMementoValue);
138 bytecode += OP_END_OF_SENTENCE; 197 bytecode += OP_END_OF_SENTENCE;
139 bytecode += OP_STORE_HASH(GetHash("memento_value_in_file"), 198 bytecode += OP_STORE_HASH(GetHash("memento_value_in_file"),
140 kTestMementoValue); 199 kTestMementoValue);
141 bytecode += OP_END_OF_SENTENCE; 200 bytecode += OP_END_OF_SENTENCE;
142 return bytecode; 201 return bytecode;
143 } 202 }
144 203
204 // Constructs another evaluation program to specifically test that local state
205 // and user preference values are included in the input as expected. We will
206 // re-purpose the output bitmasks to channel out information about the outcome
207 // of the checks.
208 //
209 // More specifically, the output of the program will be as follows:
210 // {
211 // "combined_status_mask_bit1":
212 // (input["preferences.testing.preference"] == kTestPreferenceValue)
213 // "combined_status_mask_bit2":
214 // (input["local_state.testing.preference"] == kTestPreferenceValue)
215 // "combined_status_mask_bit3": input["preferences_iuc.testing.preference"]
216 // "combined_status_mask_bit4": input["local_state_iuc.testing.preference"]
217 // }
218 std::string ConstructProgramToCheckPreferences() {
219 std::string bytecode;
220 bytecode += OP_NAVIGATE(GetHash("preferences"));
221 bytecode += OP_NAVIGATE(GetHash("testing"));
222 bytecode += OP_NAVIGATE(GetHash("preference"));
223 bytecode += OP_COMPARE_NODE_HASH(GetHash(kTestPreferenceValue));
224 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit1"),
225 EncodeBool(true));
226 bytecode += OP_END_OF_SENTENCE;
227 bytecode += OP_NAVIGATE(GetHash("local_state"));
228 bytecode += OP_NAVIGATE(GetHash("testing"));
229 bytecode += OP_NAVIGATE(GetHash("preference"));
230 bytecode += OP_COMPARE_NODE_HASH(GetHash(kTestPreferenceValue));
231 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit2"),
232 EncodeBool(true));
233 bytecode += OP_END_OF_SENTENCE;
234 bytecode += OP_NAVIGATE(GetHash("preferences_iuc"));
235 bytecode += OP_NAVIGATE(GetHash("testing"));
236 bytecode += OP_NAVIGATE(GetHash("preference"));
237 bytecode += OP_COMPARE_NODE_BOOL(EncodeBool(true));
238 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit3"),
239 EncodeBool(true));
240 bytecode += OP_END_OF_SENTENCE;
241 bytecode += OP_NAVIGATE(GetHash("local_state_iuc"));
242 bytecode += OP_NAVIGATE(GetHash("testing"));
243 bytecode += OP_NAVIGATE(GetHash("preference"));
244 bytecode += OP_COMPARE_NODE_BOOL(EncodeBool(true));
245 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit4"),
246 EncodeBool(true));
247 bytecode += OP_END_OF_SENTENCE;
248 return bytecode;
249 }
250
251 // Constructs yet another evaluation program to specifically test that default
252 // and pre-populated search engines are included in the input as expected.
253 //
254 // More specifically, the output of the program will be as follows:
255 // {
256 // "combined_status_mask_bit1":
257 // (input["default_search_provider.search_url"] == kTestSearchURL)
258 // "combined_status_mask_bit2": input["default_search_provider_iuc"]
259 // "combined_status_mask_bit3":
260 // (input["search_providers.*.search_url"] == kTestSearchURL)
261 // "combined_status_mask_bit4":
262 // (input["search_providers.*.search_url"] == kTestSearchURL2)
263 // }
264 std::string ConstructProgramToCheckSearchEngines() {
265 std::string bytecode;
266 bytecode += OP_NAVIGATE(GetHash("default_search_provider"));
267 bytecode += OP_NAVIGATE(GetHash("search_url"));
268 bytecode += OP_COMPARE_NODE_HASH(GetHash(kTestSearchURL));
269 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit1"),
270 EncodeBool(true));
271 bytecode += OP_END_OF_SENTENCE;
272 bytecode += OP_NAVIGATE(GetHash("default_search_provider_iuc"));
273 bytecode += OP_COMPARE_NODE_BOOL(EncodeBool(true));
274 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit2"),
275 EncodeBool(true));
276 bytecode += OP_END_OF_SENTENCE;
277 bytecode += OP_NAVIGATE(GetHash("search_providers"));
278 bytecode += OP_NAVIGATE_ANY;
279 bytecode += OP_NAVIGATE(GetHash("search_url"));
280 bytecode += OP_COMPARE_NODE_HASH(GetHash(kTestSearchURL));
281 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit3"),
282 EncodeBool(true));
283 bytecode += OP_END_OF_SENTENCE;
284 bytecode += OP_NAVIGATE(GetHash("search_providers"));
285 bytecode += OP_NAVIGATE_ANY;
286 bytecode += OP_NAVIGATE(GetHash("search_url"));
287 bytecode += OP_COMPARE_NODE_HASH(GetHash(kTestSearchURL2));
288 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit4"),
289 EncodeBool(true));
290 bytecode += OP_END_OF_SENTENCE;
291 return bytecode;
292 }
293
145 // Test fixtures ------------------------------------------------------------- 294 // Test fixtures -------------------------------------------------------------
146 295
147 class AutomaticProfileResetterTestBase : public testing::Test { 296 class AutomaticProfileResetterTestBase : public testing::Test {
148 protected: 297 protected:
149 explicit AutomaticProfileResetterTestBase( 298 explicit AutomaticProfileResetterTestBase(
150 const std::string& experiment_group_name) 299 const std::string& experiment_group_name)
151 : local_state_(TestingBrowserProcess::GetGlobal()), 300 : local_state_(TestingBrowserProcess::GetGlobal()),
301 profile_(new TestingProfile()),
152 experiment_group_name_(experiment_group_name), 302 experiment_group_name_(experiment_group_name),
153 mock_delegate_(NULL) { 303 mock_delegate_(NULL) {
154 // Make sure the factory is not optimized away, so prefs get registered. 304 // Make sure the factory is not optimized away, so whatever preferences it
305 // wants to register will actually get registered.
155 AutomaticProfileResetterFactory::GetInstance(); 306 AutomaticProfileResetterFactory::GetInstance();
307
308 // Register some additional local state preferences for testing purposes.
309 PrefRegistrySimple* local_state_registry = local_state_.Get()->registry();
310 DCHECK(local_state_registry);
311 local_state_registry->RegisterStringPref(kTestPreferencePath, "");
312
313 // Register some additional user preferences for testing purposes.
314 user_prefs::PrefRegistrySyncable* user_prefs_registry =
315 profile_->GetTestingPrefService()->registry();
316 DCHECK(user_prefs_registry);
317 user_prefs_registry->RegisterStringPref(
318 kTestPreferencePath,
319 "",
320 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
156 } 321 }
157 322
158 virtual void SetUp() OVERRIDE { 323 virtual void SetUp() OVERRIDE {
159 profile_.reset(new TestingProfile());
160 field_trials_.reset(new base::FieldTrialList(NULL)); 324 field_trials_.reset(new base::FieldTrialList(NULL));
161 base::FieldTrialList::CreateFieldTrial(kAutomaticProfileResetStudyName, 325 base::FieldTrialList::CreateFieldTrial(kAutomaticProfileResetStudyName,
162 experiment_group_name_); 326 experiment_group_name_);
163 mock_delegate_ = new testing::StrictMock<MockProfileResetterDelegate>(); 327 mock_delegate_ = new testing::StrictMock<MockProfileResetterDelegate>();
164 resetter_.reset(new AutomaticProfileResetter(profile_.get())); 328 resetter_.reset(new AutomaticProfileResetter(profile_.get()));
165 } 329 }
166 330
167 void SetTestingHashSeed(const std::string& hash_seed) { 331 void SetTestingHashSeed(const std::string& hash_seed) {
168 testing_hash_seed_ = hash_seed; 332 testing_hash_seed_ = hash_seed;
169 } 333 }
170 334
171 void SetTestingProgram(const std::string& source_code) { 335 void SetTestingProgram(const std::string& source_code) {
172 testing_program_ = source_code; 336 testing_program_ = source_code;
173 } 337 }
174 338
175 void UnleashResetterAndWait() { 339 void UnleashResetterAndWait() {
176 resetter_->Initialize();
177 resetter_->SetDelegateForTesting(mock_delegate_); // Takes ownership. 340 resetter_->SetDelegateForTesting(mock_delegate_); // Takes ownership.
178 resetter_->SetHashSeedForTesting(testing_hash_seed_); 341 resetter_->SetHashSeedForTesting(testing_hash_seed_);
179 resetter_->SetProgramForTesting(testing_program_); 342 resetter_->SetProgramForTesting(testing_program_);
343
344 resetter_->MaybeActivate();
180 base::RunLoop().RunUntilIdle(); 345 base::RunLoop().RunUntilIdle();
181 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 346 content::BrowserThread::GetBlockingPool()->FlushForTesting();
182 base::RunLoop().RunUntilIdle(); 347 base::RunLoop().RunUntilIdle();
183 } 348 }
184 349
185 TestingProfile* profile() { return profile_.get(); } 350 TestingProfile* profile() { return profile_.get(); }
351 TestingPrefServiceSimple* local_state() { return local_state_.Get(); }
186 352
187 MockProfileResetterDelegate& mock_delegate() { return *mock_delegate_; } 353 MockProfileResetterDelegate& mock_delegate() { return *mock_delegate_; }
188 AutomaticProfileResetter* resetter() { return resetter_.get(); } 354 AutomaticProfileResetter* resetter() { return resetter_.get(); }
189 355
190 private: 356 private:
191 content::TestBrowserThreadBundle thread_bundle_; 357 content::TestBrowserThreadBundle thread_bundle_;
192 ScopedTestingLocalState local_state_; 358 ScopedTestingLocalState local_state_;
193 scoped_ptr<TestingProfile> profile_; 359 scoped_ptr<TestingProfile> profile_;
194 scoped_ptr<base::FieldTrialList> field_trials_; 360 scoped_ptr<base::FieldTrialList> field_trials_;
195 std::string experiment_group_name_; 361 std::string experiment_group_name_;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 LocalStateHostedPromptMemento memento_in_local_state(profile()); 416 LocalStateHostedPromptMemento memento_in_local_state(profile());
251 FileHostedPromptMementoSynchronous memento_in_file(profile()); 417 FileHostedPromptMementoSynchronous memento_in_file(profile());
252 418
253 EXPECT_EQ("", memento_in_prefs.ReadValue()); 419 EXPECT_EQ("", memento_in_prefs.ReadValue());
254 EXPECT_EQ("", memento_in_local_state.ReadValue()); 420 EXPECT_EQ("", memento_in_local_state.ReadValue());
255 EXPECT_EQ("", memento_in_file.ReadValue()); 421 EXPECT_EQ("", memento_in_file.ReadValue());
256 422
257 SetTestingProgram(ConstructProgram(false, false)); 423 SetTestingProgram(ConstructProgram(false, false));
258 SetTestingHashSeed(kTestHashSeed); 424 SetTestingHashSeed(kTestHashSeed);
259 425
426 mock_delegate().ExpectCallsToWaitingMethods();
427 mock_delegate().ExpectCallsToGetterMethods();
260 EXPECT_CALL(mock_delegate(), ReportStatistics(0x00u, 0x00u)); 428 EXPECT_CALL(mock_delegate(), ReportStatistics(0x00u, 0x00u));
261 429
262 UnleashResetterAndWait(); 430 UnleashResetterAndWait();
263 431
264 EXPECT_EQ("", memento_in_prefs.ReadValue()); 432 EXPECT_EQ("", memento_in_prefs.ReadValue());
265 EXPECT_EQ("", memento_in_local_state.ReadValue()); 433 EXPECT_EQ("", memento_in_local_state.ReadValue());
266 EXPECT_EQ("", memento_in_file.ReadValue()); 434 EXPECT_EQ("", memento_in_file.ReadValue());
267 } 435 }
268 436
269 TEST_F(AutomaticProfileResetterTestDryRun, OneConditionSatisfied) { 437 TEST_F(AutomaticProfileResetterTestDryRun, OneConditionSatisfied) {
270 PreferenceHostedPromptMemento memento_in_prefs(profile()); 438 PreferenceHostedPromptMemento memento_in_prefs(profile());
271 LocalStateHostedPromptMemento memento_in_local_state(profile()); 439 LocalStateHostedPromptMemento memento_in_local_state(profile());
272 FileHostedPromptMementoSynchronous memento_in_file(profile()); 440 FileHostedPromptMementoSynchronous memento_in_file(profile());
273 441
274 EXPECT_EQ("", memento_in_prefs.ReadValue()); 442 EXPECT_EQ("", memento_in_prefs.ReadValue());
275 EXPECT_EQ("", memento_in_local_state.ReadValue()); 443 EXPECT_EQ("", memento_in_local_state.ReadValue());
276 EXPECT_EQ("", memento_in_file.ReadValue()); 444 EXPECT_EQ("", memento_in_file.ReadValue());
277 445
278 SetTestingProgram(ConstructProgram(true, false)); 446 SetTestingProgram(ConstructProgram(true, false));
279 SetTestingHashSeed(kTestHashSeed); 447 SetTestingHashSeed(kTestHashSeed);
280 448
449 mock_delegate().ExpectCallsToWaitingMethods();
450 mock_delegate().ExpectCallsToGetterMethods();
281 EXPECT_CALL(mock_delegate(), ReportStatistics(0x01u, 0x01u)); 451 EXPECT_CALL(mock_delegate(), ReportStatistics(0x01u, 0x01u));
282 452
283 UnleashResetterAndWait(); 453 UnleashResetterAndWait();
284 454
285 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); 455 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue());
286 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); 456 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue());
287 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); 457 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue());
288 } 458 }
289 459
290 TEST_F(AutomaticProfileResetterTestDryRun, OtherConditionSatisfied) { 460 TEST_F(AutomaticProfileResetterTestDryRun, OtherConditionSatisfied) {
291 PreferenceHostedPromptMemento memento_in_prefs(profile()); 461 PreferenceHostedPromptMemento memento_in_prefs(profile());
292 LocalStateHostedPromptMemento memento_in_local_state(profile()); 462 LocalStateHostedPromptMemento memento_in_local_state(profile());
293 FileHostedPromptMementoSynchronous memento_in_file(profile()); 463 FileHostedPromptMementoSynchronous memento_in_file(profile());
294 464
295 EXPECT_EQ("", memento_in_prefs.ReadValue()); 465 EXPECT_EQ("", memento_in_prefs.ReadValue());
296 EXPECT_EQ("", memento_in_local_state.ReadValue()); 466 EXPECT_EQ("", memento_in_local_state.ReadValue());
297 EXPECT_EQ("", memento_in_file.ReadValue()); 467 EXPECT_EQ("", memento_in_file.ReadValue());
298 468
299 SetTestingProgram(ConstructProgram(false, true)); 469 SetTestingProgram(ConstructProgram(false, true));
300 SetTestingHashSeed(kTestHashSeed); 470 SetTestingHashSeed(kTestHashSeed);
301 471
472 mock_delegate().ExpectCallsToWaitingMethods();
473 mock_delegate().ExpectCallsToGetterMethods();
302 EXPECT_CALL(mock_delegate(), ReportStatistics(0x02u, 0x01u)); 474 EXPECT_CALL(mock_delegate(), ReportStatistics(0x02u, 0x01u));
303 475
304 UnleashResetterAndWait(); 476 UnleashResetterAndWait();
305 477
306 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); 478 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue());
307 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); 479 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue());
308 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); 480 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue());
309 } 481 }
310 482
311 TEST_F(AutomaticProfileResetterTestDryRun, 483 TEST_F(AutomaticProfileResetterTestDryRun,
312 ConditionsSatisfiedAndInvalidMementos) { 484 ConditionsSatisfiedAndInvalidMementos) {
313 PreferenceHostedPromptMemento memento_in_prefs(profile()); 485 PreferenceHostedPromptMemento memento_in_prefs(profile());
314 LocalStateHostedPromptMemento memento_in_local_state(profile()); 486 LocalStateHostedPromptMemento memento_in_local_state(profile());
315 FileHostedPromptMementoSynchronous memento_in_file(profile()); 487 FileHostedPromptMementoSynchronous memento_in_file(profile());
316 488
317 memento_in_prefs.StoreValue(kTestInvalidMementoValue); 489 memento_in_prefs.StoreValue(kTestInvalidMementoValue);
318 memento_in_local_state.StoreValue(kTestInvalidMementoValue); 490 memento_in_local_state.StoreValue(kTestInvalidMementoValue);
319 memento_in_file.StoreValue(kTestInvalidMementoValue); 491 memento_in_file.StoreValue(kTestInvalidMementoValue);
320 492
321 SetTestingProgram(ConstructProgram(true, true)); 493 SetTestingProgram(ConstructProgram(true, true));
322 SetTestingHashSeed(kTestHashSeed); 494 SetTestingHashSeed(kTestHashSeed);
323 495
496 mock_delegate().ExpectCallsToWaitingMethods();
497 mock_delegate().ExpectCallsToGetterMethods();
324 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x01u)); 498 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x01u));
325 499
326 UnleashResetterAndWait(); 500 UnleashResetterAndWait();
327 501
328 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); 502 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue());
329 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); 503 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue());
330 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); 504 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue());
331 } 505 }
332 506
333 TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadPrefHostedMemento) { 507 TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadPrefHostedMemento) {
334 PreferenceHostedPromptMemento memento_in_prefs(profile()); 508 PreferenceHostedPromptMemento memento_in_prefs(profile());
335 LocalStateHostedPromptMemento memento_in_local_state(profile()); 509 LocalStateHostedPromptMemento memento_in_local_state(profile());
336 FileHostedPromptMementoSynchronous memento_in_file(profile()); 510 FileHostedPromptMementoSynchronous memento_in_file(profile());
337 511
338 memento_in_prefs.StoreValue(kTestMementoValue); 512 memento_in_prefs.StoreValue(kTestMementoValue);
339 513
340 SetTestingProgram(ConstructProgram(true, true)); 514 SetTestingProgram(ConstructProgram(true, true));
341 SetTestingHashSeed(kTestHashSeed); 515 SetTestingHashSeed(kTestHashSeed);
342 516
517 mock_delegate().ExpectCallsToWaitingMethods();
518 mock_delegate().ExpectCallsToGetterMethods();
343 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x03u)); 519 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x03u));
344 520
345 UnleashResetterAndWait(); 521 UnleashResetterAndWait();
346 522
347 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); 523 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue());
348 EXPECT_EQ("", memento_in_local_state.ReadValue()); 524 EXPECT_EQ("", memento_in_local_state.ReadValue());
349 EXPECT_EQ("", memento_in_file.ReadValue()); 525 EXPECT_EQ("", memento_in_file.ReadValue());
350 } 526 }
351 527
352 TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadLocalStateHostedMemento) { 528 TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadLocalStateHostedMemento) {
353 PreferenceHostedPromptMemento memento_in_prefs(profile()); 529 PreferenceHostedPromptMemento memento_in_prefs(profile());
354 LocalStateHostedPromptMemento memento_in_local_state(profile()); 530 LocalStateHostedPromptMemento memento_in_local_state(profile());
355 FileHostedPromptMementoSynchronous memento_in_file(profile()); 531 FileHostedPromptMementoSynchronous memento_in_file(profile());
356 532
357 memento_in_local_state.StoreValue(kTestMementoValue); 533 memento_in_local_state.StoreValue(kTestMementoValue);
358 534
359 SetTestingProgram(ConstructProgram(true, true)); 535 SetTestingProgram(ConstructProgram(true, true));
360 SetTestingHashSeed(kTestHashSeed); 536 SetTestingHashSeed(kTestHashSeed);
361 537
538 mock_delegate().ExpectCallsToWaitingMethods();
539 mock_delegate().ExpectCallsToGetterMethods();
362 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x05u)); 540 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x05u));
363 541
364 UnleashResetterAndWait(); 542 UnleashResetterAndWait();
365 543
366 EXPECT_EQ("", memento_in_prefs.ReadValue()); 544 EXPECT_EQ("", memento_in_prefs.ReadValue());
367 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); 545 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue());
368 EXPECT_EQ("", memento_in_file.ReadValue()); 546 EXPECT_EQ("", memento_in_file.ReadValue());
369 } 547 }
370 548
371 TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadFileHostedMemento) { 549 TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadFileHostedMemento) {
372 PreferenceHostedPromptMemento memento_in_prefs(profile()); 550 PreferenceHostedPromptMemento memento_in_prefs(profile());
373 LocalStateHostedPromptMemento memento_in_local_state(profile()); 551 LocalStateHostedPromptMemento memento_in_local_state(profile());
374 FileHostedPromptMementoSynchronous memento_in_file(profile()); 552 FileHostedPromptMementoSynchronous memento_in_file(profile());
375 553
376 memento_in_file.StoreValue(kTestMementoValue); 554 memento_in_file.StoreValue(kTestMementoValue);
377 555
378 SetTestingProgram(ConstructProgram(true, true)); 556 SetTestingProgram(ConstructProgram(true, true));
379 SetTestingHashSeed(kTestHashSeed); 557 SetTestingHashSeed(kTestHashSeed);
380 558
559 mock_delegate().ExpectCallsToWaitingMethods();
560 mock_delegate().ExpectCallsToGetterMethods();
381 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x09u)); 561 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x09u));
382 562
383 UnleashResetterAndWait(); 563 UnleashResetterAndWait();
384 564
385 EXPECT_EQ("", memento_in_prefs.ReadValue()); 565 EXPECT_EQ("", memento_in_prefs.ReadValue());
386 EXPECT_EQ("", memento_in_local_state.ReadValue()); 566 EXPECT_EQ("", memento_in_local_state.ReadValue());
387 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); 567 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue());
388 } 568 }
389 569
390 TEST_F(AutomaticProfileResetterTestDryRun, DoNothingWhenResourcesAreMissing) { 570 TEST_F(AutomaticProfileResetterTestDryRun, DoNothingWhenResourcesAreMissing) {
(...skipping 18 matching lines...) Expand all
409 LocalStateHostedPromptMemento memento_in_local_state(profile()); 589 LocalStateHostedPromptMemento memento_in_local_state(profile());
410 FileHostedPromptMementoSynchronous memento_in_file(profile()); 590 FileHostedPromptMementoSynchronous memento_in_file(profile());
411 591
412 EXPECT_EQ("", memento_in_prefs.ReadValue()); 592 EXPECT_EQ("", memento_in_prefs.ReadValue());
413 EXPECT_EQ("", memento_in_local_state.ReadValue()); 593 EXPECT_EQ("", memento_in_local_state.ReadValue());
414 EXPECT_EQ("", memento_in_file.ReadValue()); 594 EXPECT_EQ("", memento_in_file.ReadValue());
415 595
416 SetTestingProgram(ConstructProgram(false, false)); 596 SetTestingProgram(ConstructProgram(false, false));
417 SetTestingHashSeed(kTestHashSeed); 597 SetTestingHashSeed(kTestHashSeed);
418 598
599 mock_delegate().ExpectCallsToWaitingMethods();
600 mock_delegate().ExpectCallsToGetterMethods();
419 EXPECT_CALL(mock_delegate(), ReportStatistics(0x00u, 0x00u)); 601 EXPECT_CALL(mock_delegate(), ReportStatistics(0x00u, 0x00u));
420 602
421 UnleashResetterAndWait(); 603 UnleashResetterAndWait();
422 604
423 EXPECT_EQ("", memento_in_prefs.ReadValue()); 605 EXPECT_EQ("", memento_in_prefs.ReadValue());
424 EXPECT_EQ("", memento_in_local_state.ReadValue()); 606 EXPECT_EQ("", memento_in_local_state.ReadValue());
425 EXPECT_EQ("", memento_in_file.ReadValue()); 607 EXPECT_EQ("", memento_in_file.ReadValue());
426 } 608 }
427 609
428 TEST_F(AutomaticProfileResetterTest, OneConditionSatisfied) { 610 TEST_F(AutomaticProfileResetterTest, OneConditionSatisfied) {
429 PreferenceHostedPromptMemento memento_in_prefs(profile()); 611 PreferenceHostedPromptMemento memento_in_prefs(profile());
430 LocalStateHostedPromptMemento memento_in_local_state(profile()); 612 LocalStateHostedPromptMemento memento_in_local_state(profile());
431 FileHostedPromptMementoSynchronous memento_in_file(profile()); 613 FileHostedPromptMementoSynchronous memento_in_file(profile());
432 614
433 EXPECT_EQ("", memento_in_prefs.ReadValue()); 615 EXPECT_EQ("", memento_in_prefs.ReadValue());
434 EXPECT_EQ("", memento_in_local_state.ReadValue()); 616 EXPECT_EQ("", memento_in_local_state.ReadValue());
435 EXPECT_EQ("", memento_in_file.ReadValue()); 617 EXPECT_EQ("", memento_in_file.ReadValue());
436 618
437 SetTestingProgram(ConstructProgram(true, false)); 619 SetTestingProgram(ConstructProgram(true, false));
438 SetTestingHashSeed(kTestHashSeed); 620 SetTestingHashSeed(kTestHashSeed);
439 621
622 mock_delegate().ExpectCallsToWaitingMethods();
623 mock_delegate().ExpectCallsToGetterMethods();
440 EXPECT_CALL(mock_delegate(), ShowPrompt()); 624 EXPECT_CALL(mock_delegate(), ShowPrompt());
441 EXPECT_CALL(mock_delegate(), ReportStatistics(0x01u, 0x01u)); 625 EXPECT_CALL(mock_delegate(), ReportStatistics(0x01u, 0x01u));
442 626
443 UnleashResetterAndWait(); 627 UnleashResetterAndWait();
444 628
445 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); 629 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue());
446 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); 630 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue());
447 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); 631 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue());
448 } 632 }
449 633
450 TEST_F(AutomaticProfileResetterTest, OtherConditionSatisfied) { 634 TEST_F(AutomaticProfileResetterTest, OtherConditionSatisfied) {
451 PreferenceHostedPromptMemento memento_in_prefs(profile()); 635 PreferenceHostedPromptMemento memento_in_prefs(profile());
452 LocalStateHostedPromptMemento memento_in_local_state(profile()); 636 LocalStateHostedPromptMemento memento_in_local_state(profile());
453 FileHostedPromptMementoSynchronous memento_in_file(profile()); 637 FileHostedPromptMementoSynchronous memento_in_file(profile());
454 638
455 EXPECT_EQ("", memento_in_prefs.ReadValue()); 639 EXPECT_EQ("", memento_in_prefs.ReadValue());
456 EXPECT_EQ("", memento_in_local_state.ReadValue()); 640 EXPECT_EQ("", memento_in_local_state.ReadValue());
457 EXPECT_EQ("", memento_in_file.ReadValue()); 641 EXPECT_EQ("", memento_in_file.ReadValue());
458 642
459 SetTestingProgram(ConstructProgram(false, true)); 643 SetTestingProgram(ConstructProgram(false, true));
460 SetTestingHashSeed(kTestHashSeed); 644 SetTestingHashSeed(kTestHashSeed);
461 645
646 mock_delegate().ExpectCallsToWaitingMethods();
647 mock_delegate().ExpectCallsToGetterMethods();
462 EXPECT_CALL(mock_delegate(), ShowPrompt()); 648 EXPECT_CALL(mock_delegate(), ShowPrompt());
463 EXPECT_CALL(mock_delegate(), ReportStatistics(0x02u, 0x01u)); 649 EXPECT_CALL(mock_delegate(), ReportStatistics(0x02u, 0x01u));
464 650
465 UnleashResetterAndWait(); 651 UnleashResetterAndWait();
466 652
467 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); 653 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue());
468 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); 654 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue());
469 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); 655 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue());
470 } 656 }
471 657
472 TEST_F(AutomaticProfileResetterTest, ConditionsSatisfiedAndInvalidMementos) { 658 TEST_F(AutomaticProfileResetterTest, ConditionsSatisfiedAndInvalidMementos) {
473 PreferenceHostedPromptMemento memento_in_prefs(profile()); 659 PreferenceHostedPromptMemento memento_in_prefs(profile());
474 LocalStateHostedPromptMemento memento_in_local_state(profile()); 660 LocalStateHostedPromptMemento memento_in_local_state(profile());
475 FileHostedPromptMementoSynchronous memento_in_file(profile()); 661 FileHostedPromptMementoSynchronous memento_in_file(profile());
476 662
477 memento_in_prefs.StoreValue(kTestInvalidMementoValue); 663 memento_in_prefs.StoreValue(kTestInvalidMementoValue);
478 memento_in_local_state.StoreValue(kTestInvalidMementoValue); 664 memento_in_local_state.StoreValue(kTestInvalidMementoValue);
479 memento_in_file.StoreValue(kTestInvalidMementoValue); 665 memento_in_file.StoreValue(kTestInvalidMementoValue);
480 666
481 SetTestingProgram(ConstructProgram(true, true)); 667 SetTestingProgram(ConstructProgram(true, true));
482 SetTestingHashSeed(kTestHashSeed); 668 SetTestingHashSeed(kTestHashSeed);
483 669
670 mock_delegate().ExpectCallsToWaitingMethods();
671 mock_delegate().ExpectCallsToGetterMethods();
484 EXPECT_CALL(mock_delegate(), ShowPrompt()); 672 EXPECT_CALL(mock_delegate(), ShowPrompt());
485 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x01u)); 673 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x01u));
486 674
487 UnleashResetterAndWait(); 675 UnleashResetterAndWait();
488 676
489 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); 677 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue());
490 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); 678 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue());
491 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); 679 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue());
492 } 680 }
493 681
494 TEST_F(AutomaticProfileResetterTest, PrefHostedMementoPreventsPrompt) { 682 TEST_F(AutomaticProfileResetterTest, PrefHostedMementoPreventsPrompt) {
495 PreferenceHostedPromptMemento memento_in_prefs(profile()); 683 PreferenceHostedPromptMemento memento_in_prefs(profile());
496 LocalStateHostedPromptMemento memento_in_local_state(profile()); 684 LocalStateHostedPromptMemento memento_in_local_state(profile());
497 FileHostedPromptMementoSynchronous memento_in_file(profile()); 685 FileHostedPromptMementoSynchronous memento_in_file(profile());
498 686
499 memento_in_prefs.StoreValue(kTestMementoValue); 687 memento_in_prefs.StoreValue(kTestMementoValue);
500 688
501 SetTestingProgram(ConstructProgram(true, true)); 689 SetTestingProgram(ConstructProgram(true, true));
502 SetTestingHashSeed(kTestHashSeed); 690 SetTestingHashSeed(kTestHashSeed);
503 691
692 mock_delegate().ExpectCallsToWaitingMethods();
693 mock_delegate().ExpectCallsToGetterMethods();
504 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x03u)); 694 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x03u));
505 695
506 UnleashResetterAndWait(); 696 UnleashResetterAndWait();
507 697
508 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue()); 698 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue());
509 EXPECT_EQ("", memento_in_local_state.ReadValue()); 699 EXPECT_EQ("", memento_in_local_state.ReadValue());
510 EXPECT_EQ("", memento_in_file.ReadValue()); 700 EXPECT_EQ("", memento_in_file.ReadValue());
511 } 701 }
512 702
513 TEST_F(AutomaticProfileResetterTest, LocalStateHostedMementoPreventsPrompt) { 703 TEST_F(AutomaticProfileResetterTest, LocalStateHostedMementoPreventsPrompt) {
514 PreferenceHostedPromptMemento memento_in_prefs(profile()); 704 PreferenceHostedPromptMemento memento_in_prefs(profile());
515 LocalStateHostedPromptMemento memento_in_local_state(profile()); 705 LocalStateHostedPromptMemento memento_in_local_state(profile());
516 FileHostedPromptMementoSynchronous memento_in_file(profile()); 706 FileHostedPromptMementoSynchronous memento_in_file(profile());
517 707
518 memento_in_local_state.StoreValue(kTestMementoValue); 708 memento_in_local_state.StoreValue(kTestMementoValue);
519 709
520 SetTestingProgram(ConstructProgram(true, true)); 710 SetTestingProgram(ConstructProgram(true, true));
521 SetTestingHashSeed(kTestHashSeed); 711 SetTestingHashSeed(kTestHashSeed);
522 712
713 mock_delegate().ExpectCallsToWaitingMethods();
714 mock_delegate().ExpectCallsToGetterMethods();
523 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x05u)); 715 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x05u));
524 716
525 UnleashResetterAndWait(); 717 UnleashResetterAndWait();
526 718
527 EXPECT_EQ("", memento_in_prefs.ReadValue()); 719 EXPECT_EQ("", memento_in_prefs.ReadValue());
528 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue()); 720 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue());
529 EXPECT_EQ("", memento_in_file.ReadValue()); 721 EXPECT_EQ("", memento_in_file.ReadValue());
530 } 722 }
531 723
532 TEST_F(AutomaticProfileResetterTest, FileHostedMementoPreventsPrompt) { 724 TEST_F(AutomaticProfileResetterTest, FileHostedMementoPreventsPrompt) {
533 PreferenceHostedPromptMemento memento_in_prefs(profile()); 725 PreferenceHostedPromptMemento memento_in_prefs(profile());
534 LocalStateHostedPromptMemento memento_in_local_state(profile()); 726 LocalStateHostedPromptMemento memento_in_local_state(profile());
535 FileHostedPromptMementoSynchronous memento_in_file(profile()); 727 FileHostedPromptMementoSynchronous memento_in_file(profile());
536 728
537 memento_in_file.StoreValue(kTestMementoValue); 729 memento_in_file.StoreValue(kTestMementoValue);
538 730
539 SetTestingProgram(ConstructProgram(true, true)); 731 SetTestingProgram(ConstructProgram(true, true));
540 SetTestingHashSeed(kTestHashSeed); 732 SetTestingHashSeed(kTestHashSeed);
541 733
734 mock_delegate().ExpectCallsToWaitingMethods();
735 mock_delegate().ExpectCallsToGetterMethods();
542 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x09u)); 736 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x09u));
543 737
544 UnleashResetterAndWait(); 738 UnleashResetterAndWait();
545 739
546 EXPECT_EQ("", memento_in_prefs.ReadValue()); 740 EXPECT_EQ("", memento_in_prefs.ReadValue());
547 EXPECT_EQ("", memento_in_local_state.ReadValue()); 741 EXPECT_EQ("", memento_in_local_state.ReadValue());
548 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue()); 742 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue());
549 } 743 }
550 744
551 TEST_F(AutomaticProfileResetterTest, DoNothingWhenResourcesAreMissing) { 745 TEST_F(AutomaticProfileResetterTest, DoNothingWhenResourcesAreMissing) {
552 PreferenceHostedPromptMemento memento_in_prefs(profile()); 746 PreferenceHostedPromptMemento memento_in_prefs(profile());
553 LocalStateHostedPromptMemento memento_in_local_state(profile()); 747 LocalStateHostedPromptMemento memento_in_local_state(profile());
554 FileHostedPromptMementoSynchronous memento_in_file(profile()); 748 FileHostedPromptMementoSynchronous memento_in_file(profile());
555 749
556 SetTestingProgram(""); 750 SetTestingProgram("");
557 SetTestingHashSeed(""); 751 SetTestingHashSeed("");
558 752
559 // No calls are expected to the delegate. 753 // No calls are expected to the delegate.
560 754
561 UnleashResetterAndWait(); 755 UnleashResetterAndWait();
562 756
563 EXPECT_EQ("", memento_in_prefs.ReadValue()); 757 EXPECT_EQ("", memento_in_prefs.ReadValue());
564 EXPECT_EQ("", memento_in_local_state.ReadValue()); 758 EXPECT_EQ("", memento_in_local_state.ReadValue());
565 EXPECT_EQ("", memento_in_file.ReadValue()); 759 EXPECT_EQ("", memento_in_file.ReadValue());
566 } 760 }
567 761
762 // Please see comments above ConstructProgramToCheckPreferences() to understand
763 // how the following tests work.
764
765 TEST_F(AutomaticProfileResetterTest, InputUserPreferencesCorrect) {
766 SetTestingProgram(ConstructProgramToCheckPreferences());
767 SetTestingHashSeed(kTestHashSeed);
768
769 PrefService* prefs = profile()->GetPrefs();
770 prefs->SetString(kTestPreferencePath, kTestPreferenceValue);
771
772 mock_delegate().ExpectCallsToWaitingMethods();
773 mock_delegate().ExpectCallsToGetterMethods();
774 EXPECT_CALL(mock_delegate(), ReportStatistics(0x00u, 0x05u));
775
776 UnleashResetterAndWait();
777 }
778
779 TEST_F(AutomaticProfileResetterTest, InputLocalStateCorrect) {
780 SetTestingProgram(ConstructProgramToCheckPreferences());
781 SetTestingHashSeed(kTestHashSeed);
782
783 PrefService* prefs = local_state();
784 prefs->SetString(kTestPreferencePath, kTestPreferenceValue);
785
786 mock_delegate().ExpectCallsToWaitingMethods();
787 mock_delegate().ExpectCallsToGetterMethods();
788 EXPECT_CALL(mock_delegate(), ReportStatistics(0x00u, 0x0Au));
789
790 UnleashResetterAndWait();
791 }
792
793 TEST_F(AutomaticProfileResetterTest, InputManagedUserPreferencesCorrect) {
794 SetTestingProgram(ConstructProgramToCheckPreferences());
795 SetTestingHashSeed(kTestHashSeed);
796
797 TestingPrefServiceSyncable* prefs = profile()->GetTestingPrefService();
798 prefs->SetManagedPref(kTestPreferencePath,
799 new base::StringValue(kTestPreferenceValue));
800
801 mock_delegate().ExpectCallsToWaitingMethods();
802 mock_delegate().ExpectCallsToGetterMethods();
803 EXPECT_CALL(mock_delegate(), ReportStatistics(0x00u, 0x01u));
804
805 UnleashResetterAndWait();
806 }
807
808 TEST_F(AutomaticProfileResetterTest, InputManagedLocalStateCorrect) {
809 SetTestingProgram(ConstructProgramToCheckPreferences());
810 SetTestingHashSeed(kTestHashSeed);
811
812 TestingPrefServiceSimple* prefs = local_state();
813 prefs->SetManagedPref(kTestPreferencePath,
814 new base::StringValue(kTestPreferenceValue));
815
816 mock_delegate().ExpectCallsToWaitingMethods();
817 mock_delegate().ExpectCallsToGetterMethods();
818 EXPECT_CALL(mock_delegate(), ReportStatistics(0x00u, 0x02u));
819
820 UnleashResetterAndWait();
821 }
822
823 // Please see comments above ConstructProgramToCheckSearchEngines() to
824 // understand how the following tests work.
825
826 TEST_F(AutomaticProfileResetterTest, InputDefaultSearchProviderCorrect) {
827 SetTestingProgram(ConstructProgramToCheckSearchEngines());
828 SetTestingHashSeed(kTestHashSeed);
829
830 mock_delegate().emulated_default_search_provider_details().SetString(
831 kSearchURLAttributeKey, kTestSearchURL);
832
833 mock_delegate().ExpectCallsToWaitingMethods();
834 mock_delegate().ExpectCallsToGetterMethods();
835 EXPECT_CALL(mock_delegate(), ReportStatistics(0x00u, 0x03u));
836
837 UnleashResetterAndWait();
838 }
839
840 TEST_F(AutomaticProfileResetterTest, InputSearchProviderManagedCorrect) {
841 SetTestingProgram(ConstructProgramToCheckSearchEngines());
842 SetTestingHashSeed(kTestHashSeed);
843
844 mock_delegate().emulated_default_search_provider_details().SetString(
845 kSearchURLAttributeKey, kTestSearchURL);
846 mock_delegate().set_emulated_default_search_provider_is_managed(true);
847
848 mock_delegate().ExpectCallsToWaitingMethods();
849 mock_delegate().ExpectCallsToGetterMethods();
850 EXPECT_CALL(mock_delegate(), ReportStatistics(0x00u, 0x01u));
851
852 UnleashResetterAndWait();
853 }
854
855 TEST_F(AutomaticProfileResetterTest, InputSearchProvidersCorrect) {
856 SetTestingProgram(ConstructProgramToCheckSearchEngines());
857 SetTestingHashSeed(kTestHashSeed);
858
859 base::DictionaryValue* search_provider_1 = new base::DictionaryValue;
860 base::DictionaryValue* search_provider_2 = new base::DictionaryValue;
861 search_provider_1->SetString(kSearchURLAttributeKey, kTestSearchURL);
862 search_provider_2->SetString(kSearchURLAttributeKey, kTestSearchURL2);
863 mock_delegate().emulated_search_providers_details().Append(search_provider_1);
864 mock_delegate().emulated_search_providers_details().Append(search_provider_2);
865
866 mock_delegate().ExpectCallsToWaitingMethods();
867 mock_delegate().ExpectCallsToGetterMethods();
868 EXPECT_CALL(mock_delegate(), ReportStatistics(0x00u, 0x0Eu));
869
870 UnleashResetterAndWait();
871 }
872
568 } // namespace 873 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698