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

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

Issue 24533002: Added the AutomaticProfileResetter service. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Final touches on unittests. 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
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <string>
6
7 #include "base/basictypes.h"
8 #include "base/bind_helpers.h"
9 #include "base/metrics/field_trial.h"
10 #include "base/run_loop.h"
11 #include "base/threading/sequenced_worker_pool.h"
12 #include "chrome/browser/profile_resetter/automatic_profile_resetter.h"
13 #include "chrome/browser/profile_resetter/automatic_profile_resetter_factory.h"
14 #include "chrome/browser/profile_resetter/automatic_profile_resetter_mementos.h"
15 #include "chrome/browser/profile_resetter/jtl_foundation.h"
16 #include "chrome/browser/profile_resetter/jtl_instructions.h"
17 #include "chrome/test/base/scoped_testing_local_state.h"
18 #include "chrome/test/base/testing_browser_process.h"
19 #include "chrome/test/base/testing_profile.h"
20 #include "content/public/browser/browser_thread.h"
21 #include "content/public/test/test_browser_thread_bundle.h"
22 #include "testing/gmock/include/gmock/gmock.h"
23 #include "testing/gtest/include/gtest/gtest.h"
24
25 namespace {
26
27 const char kAutomaticProfileResetStudyName[] = "AutomaticProfileReset";
28 const char kStudyDisabledGroupName[] = "Disabled";
29 const char kStudyDryRunGroupName[] = "DryRun";
30 const char kStudyEnabledGroupName[] = "Enabled";
31
32 const char kTestHashSeed[] = "testing-hash-seed";
33 const char kTestMementoValue[] = "01234567890123456789012345678901";
34 const char kTestInvalidMementoValue[] = "12345678901234567890123456789012";
35
36 // Helpers ------------------------------------------------------------------
37
38 class MockProfileResetterDelegate : public AutomaticProfileResetterDelegate {
39 public:
40 MockProfileResetterDelegate() {}
41 virtual ~MockProfileResetterDelegate() {}
42
43 MOCK_METHOD0(ShowPrompt, void());
44 MOCK_METHOD2(ReportStatistics, void(uint32, uint32));
45
46 private:
47 DISALLOW_COPY_AND_ASSIGN(MockProfileResetterDelegate);
48 };
49
50 class FileHostedPromptMementoSynchronous : protected FileHostedPromptMemento {
51 public:
52 explicit FileHostedPromptMementoSynchronous(Profile* profile)
53 : FileHostedPromptMemento(profile) {}
54
55 std::string ReadValue() const {
56 std::string result;
57 FileHostedPromptMemento::ReadValue(base::Bind(&AssignArgumentTo, &result));
58 base::RunLoop().RunUntilIdle();
59 return result;
60 }
61
62 void StoreValue(const std::string& value) {
63 FileHostedPromptMemento::StoreValue(value);
64 base::RunLoop().RunUntilIdle();
65 }
66
67 private:
68 static void AssignArgumentTo(std::string* target, const std::string& value) {
69 *target = value;
70 }
71
72 DISALLOW_COPY_AND_ASSIGN(FileHostedPromptMementoSynchronous);
73 };
74
75 std::string GetHash(const std::string& input) {
76 return jtl_foundation::Hasher(kTestHashSeed).GetHash(input);
77 }
78
79 // Encodes a Boolean argument value into JTL bytecode.
80 std::string EncodeBool(bool value) { return value ? VALUE_TRUE : VALUE_FALSE; }
81
82 // Constructs a simple evaluation program to test that input/output works well.
83 // 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
85 // combined status mask according to whether or not the memento values received
86 // in the input were as expected.
87 //
88 // More specifically, the output of the program will be as follows:
89 // {
90 // "satisfied_criteria_mask_bit1": emulate_satisfied_criterion_1,
91 // "satisfied_criteria_mask_bit2": emulate_satisfied_criterion_2,
92 // "combined_status_mask_bit1":
93 // (emulate_satisfied_criterion_1 || emulate_satisfied_criterion_2),
94 // "combined_status_mask_bit2":
95 // (input["memento_value_in_prefs"] == kTestMementoValue),
96 // "combined_status_mask_bit3":
97 // (input["memento_value_in_local_state"] == kTestMementoValue),
98 // "combined_status_mask_bit4":
99 // (input["memento_value_in_file"] == kTestMementoValue),
100 // "had_prompted_already": <OR-combination of above three>,
101 // "memento_value_in_prefs": kTestMementoValue,
102 // "memento_value_in_local_state": kTestMementoValue,
103 // "memento_value_in_file": kTestMementoValue
104 // }
105 std::string ConstructProgram(bool emulate_satisfied_criterion_1,
106 bool emulate_satisfied_criterion_2) {
107 std::string bytecode;
108 bytecode += OP_STORE_BOOL(GetHash("satisfied_criteria_mask_bit1"),
109 EncodeBool(emulate_satisfied_criterion_1));
110 bytecode += OP_END_OF_SENTENCE;
111 bytecode += OP_STORE_BOOL(GetHash("satisfied_criteria_mask_bit2"),
112 EncodeBool(emulate_satisfied_criterion_2));
113 bytecode += OP_END_OF_SENTENCE;
114 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit1"),
115 EncodeBool(emulate_satisfied_criterion_1 ||
116 emulate_satisfied_criterion_2));
117 bytecode += OP_END_OF_SENTENCE;
118 bytecode += OP_NAVIGATE(GetHash("memento_value_in_prefs"));
119 bytecode += OP_COMPARE_NODE_HASH(GetHash(kTestMementoValue));
120 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit2"), VALUE_TRUE);
121 bytecode += OP_STORE_BOOL(GetHash("had_prompted_already"), VALUE_TRUE);
122 bytecode += OP_END_OF_SENTENCE;
123 bytecode += OP_NAVIGATE(GetHash("memento_value_in_local_state"));
124 bytecode += OP_COMPARE_NODE_HASH(GetHash(kTestMementoValue));
125 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit3"), VALUE_TRUE);
126 bytecode += OP_STORE_BOOL(GetHash("had_prompted_already"), VALUE_TRUE);
127 bytecode += OP_END_OF_SENTENCE;
128 bytecode += OP_NAVIGATE(GetHash("memento_value_in_file"));
129 bytecode += OP_COMPARE_NODE_HASH(GetHash(kTestMementoValue));
130 bytecode += OP_STORE_BOOL(GetHash("combined_status_mask_bit4"), VALUE_TRUE);
131 bytecode += OP_STORE_BOOL(GetHash("had_prompted_already"), VALUE_TRUE);
132 bytecode += OP_END_OF_SENTENCE;
133 bytecode += OP_STORE_HASH(GetHash("memento_value_in_prefs"),
134 kTestMementoValue);
135 bytecode += OP_END_OF_SENTENCE;
136 bytecode += OP_STORE_HASH(GetHash("memento_value_in_local_state"),
137 kTestMementoValue);
138 bytecode += OP_END_OF_SENTENCE;
139 bytecode += OP_STORE_HASH(GetHash("memento_value_in_file"),
140 kTestMementoValue);
141 bytecode += OP_END_OF_SENTENCE;
142 return bytecode;
143 }
144
145 // Test fixtures -------------------------------------------------------------
146
147 class AutomaticProfileResetterTestBase : public testing::Test {
148 protected:
149 explicit AutomaticProfileResetterTestBase(
150 const std::string& experiment_group_name)
151 : local_state_(TestingBrowserProcess::GetGlobal()),
152 experiment_group_name_(experiment_group_name),
153 mock_delegate_(NULL) {
154 // Make sure the factory is not optimized away, so prefs get registered.
155 AutomaticProfileResetterFactory::GetInstance();
156 }
157
158 virtual void SetUp() OVERRIDE {
159 profile_.reset(new TestingProfile());
160 field_trials_.reset(new base::FieldTrialList(NULL));
161 base::FieldTrialList::CreateFieldTrial(kAutomaticProfileResetStudyName,
162 experiment_group_name_);
163 mock_delegate_ = new testing::StrictMock<MockProfileResetterDelegate>();
164 resetter_.reset(new AutomaticProfileResetter(profile_.get()));
165 }
166
167 void SetTestingHashSeed(const std::string& hash_seed) {
168 testing_hash_seed_ = hash_seed;
169 }
170
171 void SetTestingProgram(const std::string& source_code) {
172 testing_program_ = source_code;
173 }
174
175 void UnleashResetterAndWait() {
176 resetter_->Initialize();
177 resetter_->SetDelegateForTesting(mock_delegate_); // Takes ownership.
178 resetter_->SetHashSeedForTesting(testing_hash_seed_);
179 resetter_->SetProgramForTesting(testing_program_);
180 base::RunLoop().RunUntilIdle();
181 content::BrowserThread::GetBlockingPool()->FlushForTesting();
182 base::RunLoop().RunUntilIdle();
183 }
184
185 TestingProfile* profile() { return profile_.get(); }
186
187 MockProfileResetterDelegate& mock_delegate() { return *mock_delegate_; }
188 AutomaticProfileResetter* resetter() { return resetter_.get(); }
189
190 private:
191 content::TestBrowserThreadBundle thread_bundle_;
192 ScopedTestingLocalState local_state_;
193 scoped_ptr<TestingProfile> profile_;
194 scoped_ptr<base::FieldTrialList> field_trials_;
195 std::string experiment_group_name_;
196 std::string testing_program_;
197 std::string testing_hash_seed_;
198
199 scoped_ptr<AutomaticProfileResetter> resetter_;
200 MockProfileResetterDelegate* mock_delegate_;
201
202 DISALLOW_COPY_AND_ASSIGN(AutomaticProfileResetterTestBase);
203 };
204
205 class AutomaticProfileResetterTest : public AutomaticProfileResetterTestBase {
206 protected:
207 AutomaticProfileResetterTest()
208 : AutomaticProfileResetterTestBase(kStudyEnabledGroupName) {}
209 };
210
211 class AutomaticProfileResetterTestDryRun
212 : public AutomaticProfileResetterTestBase {
213 protected:
214 AutomaticProfileResetterTestDryRun()
215 : AutomaticProfileResetterTestBase(kStudyDryRunGroupName) {}
216 };
217
218 class AutomaticProfileResetterTestDisabled
219 : public AutomaticProfileResetterTestBase {
220 protected:
221 AutomaticProfileResetterTestDisabled()
222 : AutomaticProfileResetterTestBase(kStudyDisabledGroupName) {}
223 };
224
225 // Tests ---------------------------------------------------------------------
226
227 TEST_F(AutomaticProfileResetterTestDisabled, NothingIsDoneWhenDisabled) {
228 PreferenceHostedPromptMemento memento_in_prefs(profile());
229 LocalStateHostedPromptMemento memento_in_local_state(profile());
230 FileHostedPromptMementoSynchronous memento_in_file(profile());
231
232 EXPECT_EQ("", memento_in_prefs.ReadValue());
233 EXPECT_EQ("", memento_in_local_state.ReadValue());
234 EXPECT_EQ("", memento_in_file.ReadValue());
235
236 SetTestingProgram(ConstructProgram(true, true));
237 SetTestingHashSeed(kTestHashSeed);
238
239 // No calls are expected to the delegate.
240
241 UnleashResetterAndWait();
242
243 EXPECT_EQ("", memento_in_prefs.ReadValue());
244 EXPECT_EQ("", memento_in_local_state.ReadValue());
245 EXPECT_EQ("", memento_in_file.ReadValue());
246 }
247
248 TEST_F(AutomaticProfileResetterTestDryRun, ConditionsNotSatisfied) {
249 PreferenceHostedPromptMemento memento_in_prefs(profile());
250 LocalStateHostedPromptMemento memento_in_local_state(profile());
251 FileHostedPromptMementoSynchronous memento_in_file(profile());
252
253 EXPECT_EQ("", memento_in_prefs.ReadValue());
254 EXPECT_EQ("", memento_in_local_state.ReadValue());
255 EXPECT_EQ("", memento_in_file.ReadValue());
256
257 SetTestingProgram(ConstructProgram(false, false));
258 SetTestingHashSeed(kTestHashSeed);
259
260 EXPECT_CALL(mock_delegate(), ReportStatistics(0x00u, 0x00u));
261
262 UnleashResetterAndWait();
263
264 EXPECT_EQ("", memento_in_prefs.ReadValue());
265 EXPECT_EQ("", memento_in_local_state.ReadValue());
266 EXPECT_EQ("", memento_in_file.ReadValue());
267 }
268
269 TEST_F(AutomaticProfileResetterTestDryRun, OneConditionSatisfied) {
270 PreferenceHostedPromptMemento memento_in_prefs(profile());
271 LocalStateHostedPromptMemento memento_in_local_state(profile());
272 FileHostedPromptMementoSynchronous memento_in_file(profile());
273
274 EXPECT_EQ("", memento_in_prefs.ReadValue());
275 EXPECT_EQ("", memento_in_local_state.ReadValue());
276 EXPECT_EQ("", memento_in_file.ReadValue());
277
278 SetTestingProgram(ConstructProgram(true, false));
279 SetTestingHashSeed(kTestHashSeed);
280
281 EXPECT_CALL(mock_delegate(), ReportStatistics(0x01u, 0x01u));
282
283 UnleashResetterAndWait();
284
285 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue());
286 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue());
287 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue());
288 }
289
290 TEST_F(AutomaticProfileResetterTestDryRun, OtherConditionSatisfied) {
291 PreferenceHostedPromptMemento memento_in_prefs(profile());
292 LocalStateHostedPromptMemento memento_in_local_state(profile());
293 FileHostedPromptMementoSynchronous memento_in_file(profile());
294
295 EXPECT_EQ("", memento_in_prefs.ReadValue());
296 EXPECT_EQ("", memento_in_local_state.ReadValue());
297 EXPECT_EQ("", memento_in_file.ReadValue());
298
299 SetTestingProgram(ConstructProgram(false, true));
300 SetTestingHashSeed(kTestHashSeed);
301
302 EXPECT_CALL(mock_delegate(), ReportStatistics(0x02u, 0x01u));
303
304 UnleashResetterAndWait();
305
306 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue());
307 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue());
308 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue());
309 }
310
311 TEST_F(AutomaticProfileResetterTestDryRun,
312 ConditionsSatisfiedAndInvalidMementos) {
313 PreferenceHostedPromptMemento memento_in_prefs(profile());
314 LocalStateHostedPromptMemento memento_in_local_state(profile());
315 FileHostedPromptMementoSynchronous memento_in_file(profile());
316
317 memento_in_prefs.StoreValue(kTestInvalidMementoValue);
318 memento_in_local_state.StoreValue(kTestInvalidMementoValue);
319 memento_in_file.StoreValue(kTestInvalidMementoValue);
320
321 SetTestingProgram(ConstructProgram(true, true));
322 SetTestingHashSeed(kTestHashSeed);
323
324 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x01u));
325
326 UnleashResetterAndWait();
327
328 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue());
329 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue());
330 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue());
331 }
332
333 TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadPrefHostedMemento) {
334 PreferenceHostedPromptMemento memento_in_prefs(profile());
335 LocalStateHostedPromptMemento memento_in_local_state(profile());
336 FileHostedPromptMementoSynchronous memento_in_file(profile());
337
338 memento_in_prefs.StoreValue(kTestMementoValue);
339
340 SetTestingProgram(ConstructProgram(true, true));
341 SetTestingHashSeed(kTestHashSeed);
342
343 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x03u));
344
345 UnleashResetterAndWait();
346
347 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue());
348 EXPECT_EQ("", memento_in_local_state.ReadValue());
349 EXPECT_EQ("", memento_in_file.ReadValue());
350 }
351
352 TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadLocalStateHostedMemento) {
353 PreferenceHostedPromptMemento memento_in_prefs(profile());
354 LocalStateHostedPromptMemento memento_in_local_state(profile());
355 FileHostedPromptMementoSynchronous memento_in_file(profile());
356
357 memento_in_local_state.StoreValue(kTestMementoValue);
358
359 SetTestingProgram(ConstructProgram(true, true));
360 SetTestingHashSeed(kTestHashSeed);
361
362 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x05u));
363
364 UnleashResetterAndWait();
365
366 EXPECT_EQ("", memento_in_prefs.ReadValue());
367 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue());
368 EXPECT_EQ("", memento_in_file.ReadValue());
369 }
370
371 TEST_F(AutomaticProfileResetterTestDryRun, AlreadyHadFileHostedMemento) {
372 PreferenceHostedPromptMemento memento_in_prefs(profile());
373 LocalStateHostedPromptMemento memento_in_local_state(profile());
374 FileHostedPromptMementoSynchronous memento_in_file(profile());
375
376 memento_in_file.StoreValue(kTestMementoValue);
377
378 SetTestingProgram(ConstructProgram(true, true));
379 SetTestingHashSeed(kTestHashSeed);
380
381 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x09u));
382
383 UnleashResetterAndWait();
384
385 EXPECT_EQ("", memento_in_prefs.ReadValue());
386 EXPECT_EQ("", memento_in_local_state.ReadValue());
387 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue());
388 }
389
390 TEST_F(AutomaticProfileResetterTestDryRun, DoNothingWhenResourcesAreMissing) {
391 PreferenceHostedPromptMemento memento_in_prefs(profile());
392 LocalStateHostedPromptMemento memento_in_local_state(profile());
393 FileHostedPromptMementoSynchronous memento_in_file(profile());
394
395 SetTestingProgram("");
396 SetTestingHashSeed("");
397
398 // No calls are expected to the delegate.
399
400 UnleashResetterAndWait();
401
402 EXPECT_EQ("", memento_in_prefs.ReadValue());
403 EXPECT_EQ("", memento_in_local_state.ReadValue());
404 EXPECT_EQ("", memento_in_file.ReadValue());
405 }
406
407 TEST_F(AutomaticProfileResetterTest, ConditionsNotSatisfied) {
408 PreferenceHostedPromptMemento memento_in_prefs(profile());
409 LocalStateHostedPromptMemento memento_in_local_state(profile());
410 FileHostedPromptMementoSynchronous memento_in_file(profile());
411
412 EXPECT_EQ("", memento_in_prefs.ReadValue());
413 EXPECT_EQ("", memento_in_local_state.ReadValue());
414 EXPECT_EQ("", memento_in_file.ReadValue());
415
416 SetTestingProgram(ConstructProgram(false, false));
417 SetTestingHashSeed(kTestHashSeed);
418
419 EXPECT_CALL(mock_delegate(), ReportStatistics(0x00u, 0x00u));
420
421 UnleashResetterAndWait();
422
423 EXPECT_EQ("", memento_in_prefs.ReadValue());
424 EXPECT_EQ("", memento_in_local_state.ReadValue());
425 EXPECT_EQ("", memento_in_file.ReadValue());
426 }
427
428 TEST_F(AutomaticProfileResetterTest, OneConditionSatisfied) {
429 PreferenceHostedPromptMemento memento_in_prefs(profile());
430 LocalStateHostedPromptMemento memento_in_local_state(profile());
431 FileHostedPromptMementoSynchronous memento_in_file(profile());
432
433 EXPECT_EQ("", memento_in_prefs.ReadValue());
434 EXPECT_EQ("", memento_in_local_state.ReadValue());
435 EXPECT_EQ("", memento_in_file.ReadValue());
436
437 SetTestingProgram(ConstructProgram(true, false));
438 SetTestingHashSeed(kTestHashSeed);
439
440 EXPECT_CALL(mock_delegate(), ShowPrompt());
441 EXPECT_CALL(mock_delegate(), ReportStatistics(0x01u, 0x01u));
442
443 UnleashResetterAndWait();
444
445 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue());
446 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue());
447 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue());
448 }
449
450 TEST_F(AutomaticProfileResetterTest, OtherConditionSatisfied) {
451 PreferenceHostedPromptMemento memento_in_prefs(profile());
452 LocalStateHostedPromptMemento memento_in_local_state(profile());
453 FileHostedPromptMementoSynchronous memento_in_file(profile());
454
455 EXPECT_EQ("", memento_in_prefs.ReadValue());
456 EXPECT_EQ("", memento_in_local_state.ReadValue());
457 EXPECT_EQ("", memento_in_file.ReadValue());
458
459 SetTestingProgram(ConstructProgram(false, true));
460 SetTestingHashSeed(kTestHashSeed);
461
462 EXPECT_CALL(mock_delegate(), ShowPrompt());
463 EXPECT_CALL(mock_delegate(), ReportStatistics(0x02u, 0x01u));
464
465 UnleashResetterAndWait();
466
467 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue());
468 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue());
469 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue());
470 }
471
472 TEST_F(AutomaticProfileResetterTest, ConditionsSatisfiedAndInvalidMementos) {
473 PreferenceHostedPromptMemento memento_in_prefs(profile());
474 LocalStateHostedPromptMemento memento_in_local_state(profile());
475 FileHostedPromptMementoSynchronous memento_in_file(profile());
476
477 memento_in_prefs.StoreValue(kTestInvalidMementoValue);
478 memento_in_local_state.StoreValue(kTestInvalidMementoValue);
479 memento_in_file.StoreValue(kTestInvalidMementoValue);
480
481 SetTestingProgram(ConstructProgram(true, true));
482 SetTestingHashSeed(kTestHashSeed);
483
484 EXPECT_CALL(mock_delegate(), ShowPrompt());
485 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x01u));
486
487 UnleashResetterAndWait();
488
489 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue());
490 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue());
491 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue());
492 }
493
494 TEST_F(AutomaticProfileResetterTest, PrefHostedMementoPreventsPrompt) {
495 PreferenceHostedPromptMemento memento_in_prefs(profile());
496 LocalStateHostedPromptMemento memento_in_local_state(profile());
497 FileHostedPromptMementoSynchronous memento_in_file(profile());
498
499 memento_in_prefs.StoreValue(kTestMementoValue);
500
501 SetTestingProgram(ConstructProgram(true, true));
502 SetTestingHashSeed(kTestHashSeed);
503
504 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x03u));
505
506 UnleashResetterAndWait();
507
508 EXPECT_EQ(kTestMementoValue, memento_in_prefs.ReadValue());
509 EXPECT_EQ("", memento_in_local_state.ReadValue());
510 EXPECT_EQ("", memento_in_file.ReadValue());
511 }
512
513 TEST_F(AutomaticProfileResetterTest, LocalStateHostedMementoPreventsPrompt) {
514 PreferenceHostedPromptMemento memento_in_prefs(profile());
515 LocalStateHostedPromptMemento memento_in_local_state(profile());
516 FileHostedPromptMementoSynchronous memento_in_file(profile());
517
518 memento_in_local_state.StoreValue(kTestMementoValue);
519
520 SetTestingProgram(ConstructProgram(true, true));
521 SetTestingHashSeed(kTestHashSeed);
522
523 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x05u));
524
525 UnleashResetterAndWait();
526
527 EXPECT_EQ("", memento_in_prefs.ReadValue());
528 EXPECT_EQ(kTestMementoValue, memento_in_local_state.ReadValue());
529 EXPECT_EQ("", memento_in_file.ReadValue());
530 }
531
532 TEST_F(AutomaticProfileResetterTest, FileHostedMementoPreventsPrompt) {
533 PreferenceHostedPromptMemento memento_in_prefs(profile());
534 LocalStateHostedPromptMemento memento_in_local_state(profile());
535 FileHostedPromptMementoSynchronous memento_in_file(profile());
536
537 memento_in_file.StoreValue(kTestMementoValue);
538
539 SetTestingProgram(ConstructProgram(true, true));
540 SetTestingHashSeed(kTestHashSeed);
541
542 EXPECT_CALL(mock_delegate(), ReportStatistics(0x03u, 0x09u));
543
544 UnleashResetterAndWait();
545
546 EXPECT_EQ("", memento_in_prefs.ReadValue());
547 EXPECT_EQ("", memento_in_local_state.ReadValue());
548 EXPECT_EQ(kTestMementoValue, memento_in_file.ReadValue());
549 }
550
551 TEST_F(AutomaticProfileResetterTest, DoNothingWhenResourcesAreMissing) {
552 PreferenceHostedPromptMemento memento_in_prefs(profile());
553 LocalStateHostedPromptMemento memento_in_local_state(profile());
554 FileHostedPromptMementoSynchronous memento_in_file(profile());
555
556 SetTestingProgram("");
557 SetTestingHashSeed("");
558
559 // No calls are expected to the delegate.
560
561 UnleashResetterAndWait();
562
563 EXPECT_EQ("", memento_in_prefs.ReadValue());
564 EXPECT_EQ("", memento_in_local_state.ReadValue());
565 EXPECT_EQ("", memento_in_file.ReadValue());
566 }
567
568 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698