1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/file_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
#include "base/values.h"
#include "chrome/browser/signin/signin_manager.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/signin/token_service.h"
#include "chrome/browser/signin/token_service_factory.h"
#include "chrome/browser/sync/glue/bookmark_data_type_controller.h"
#include "chrome/browser/sync/glue/data_type_controller.h"
#include "chrome/browser/sync/profile_sync_components_factory_mock.h"
#include "chrome/browser/sync/test_profile_sync_service.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_pref_service_syncable.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/test/test_browser_thread.h"
#include "google/cacheinvalidation/include/types.h"
#include "google_apis/gaia/gaia_constants.h"
#include "sync/js/js_arg_list.h"
#include "sync/js/js_event_details.h"
#include "sync/js/js_test_util.h"
#include "sync/notifier/fake_invalidation_handler.h"
#include "sync/notifier/invalidator.h"
#include "sync/notifier/invalidator_test_template.h"
#include "sync/notifier/object_id_invalidation_map_test_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
// TODO(akalin): Add tests here that exercise the whole
// ProfileSyncService/SyncBackendHost stack while mocking out as
// little as possible.
namespace browser_sync {
namespace {
using content::BrowserThread;
using testing::_;
using testing::AtLeast;
using testing::AtMost;
using testing::Mock;
using testing::Return;
using testing::StrictMock;
class ProfileSyncServiceTestHarness {
public:
ProfileSyncServiceTestHarness()
: ui_thread_(BrowserThread::UI, &ui_loop_),
db_thread_(BrowserThread::DB),
file_thread_(BrowserThread::FILE),
io_thread_(BrowserThread::IO) {}
~ProfileSyncServiceTestHarness() {}
void SetUp() {
file_thread_.Start();
io_thread_.StartIOThread();
profile.reset(new TestingProfile());
profile->CreateRequestContext();
}
void TearDown() {
// Kill the service before the profile.
if (service) {
service->Shutdown();
}
service.reset();
profile.reset();
// Pump messages posted by the sync thread (which may end up
// posting on the IO thread).
ui_loop_.RunUntilIdle();
io_thread_.Stop();
file_thread_.Stop();
// Ensure that the sync objects destruct to avoid memory leaks.
ui_loop_.RunUntilIdle();
}
// TODO(akalin): Refactor the StartSyncService*() functions below.
void StartSyncService() {
StartSyncServiceAndSetInitialSyncEnded(
true, true, false, true, syncer::STORAGE_IN_MEMORY);
}
void StartSyncServiceAndSetInitialSyncEnded(
bool set_initial_sync_ended,
bool issue_auth_token,
bool synchronous_sync_configuration,
bool sync_setup_completed,
syncer::StorageOption storage_option) {
if (!service) {
SigninManagerBase* signin =
SigninManagerFactory::GetForProfile(profile.get());
signin->SetAuthenticatedUsername("test");
ProfileSyncComponentsFactoryMock* factory =
new ProfileSyncComponentsFactoryMock();
service.reset(new TestProfileSyncService(
factory,
profile.get(),
signin,
ProfileSyncService::AUTO_START,
true));
if (!set_initial_sync_ended)
service->dont_set_initial_sync_ended_on_init();
if (synchronous_sync_configuration)
service->set_synchronous_sync_configuration();
service->set_storage_option(storage_option);
if (!sync_setup_completed)
profile->GetPrefs()->SetBoolean(prefs::kSyncHasSetupCompleted, false);
// Register the bookmark data type.
ON_CALL(*factory, CreateDataTypeManager(_, _, _, _, _, _)).
WillByDefault(ReturnNewDataTypeManager());
if (issue_auth_token) {
IssueTestTokens();
}
service->Initialize();
}
}
void IssueTestTokens() {
TokenService* token_service =
TokenServiceFactory::GetForProfile(profile.get());
token_service->IssueAuthTokenForTest(
GaiaConstants::kSyncService, "token1");
token_service->IssueAuthTokenForTest(
GaiaConstants::kGaiaOAuth2LoginRefreshToken, "token2");
}
scoped_ptr<TestProfileSyncService> service;
scoped_ptr<TestingProfile> profile;
private:
base::MessageLoop ui_loop_;
// Needed by |service|.
content::TestBrowserThread ui_thread_;
content::TestBrowserThread db_thread_;
// Needed by DisableAndEnableSyncTemporarily test case.
content::TestBrowserThread file_thread_;
// Needed by |service| and |profile|'s request context.
content::TestBrowserThread io_thread_;
};
class TestProfileSyncServiceObserver : public ProfileSyncServiceObserver {
public:
explicit TestProfileSyncServiceObserver(ProfileSyncService* service)
: service_(service), first_setup_in_progress_(false) {}
virtual void OnStateChanged() OVERRIDE {
first_setup_in_progress_ = service_->FirstSetupInProgress();
}
bool first_setup_in_progress() const { return first_setup_in_progress_; }
private:
ProfileSyncService* service_;
bool first_setup_in_progress_;
};
class ProfileSyncServiceTest : public testing::Test {
protected:
virtual void SetUp() {
harness_.SetUp();
}
virtual void TearDown() {
harness_.TearDown();
}
ProfileSyncServiceTestHarness harness_;
};
TEST_F(ProfileSyncServiceTest, InitialState) {
SigninManagerBase* signin =
SigninManagerFactory::GetForProfile(harness_.profile.get());
harness_.service.reset(new TestProfileSyncService(
new ProfileSyncComponentsFactoryMock(),
harness_.profile.get(),
signin,
ProfileSyncService::MANUAL_START,
true));
harness_.service->Initialize();
EXPECT_TRUE(
harness_.service->sync_service_url().spec() ==
ProfileSyncService::kSyncServerUrl ||
harness_.service->sync_service_url().spec() ==
ProfileSyncService::kDevServerUrl);
}
// Tests that the sync service doesn't forget to notify observers about
// setup state.
TEST(ProfileSyncServiceTestBasic, SetupInProgress) {
ProfileSyncService service(
NULL, NULL, NULL, ProfileSyncService::MANUAL_START);
TestProfileSyncServiceObserver observer(&service);
service.AddObserver(&observer);
service.SetSetupInProgress(true);
EXPECT_TRUE(observer.first_setup_in_progress());
service.SetSetupInProgress(false);
EXPECT_FALSE(observer.first_setup_in_progress());
service.RemoveObserver(&observer);
}
TEST_F(ProfileSyncServiceTest, DisabledByPolicy) {
harness_.profile->GetTestingPrefService()->SetManagedPref(
prefs::kSyncManaged,
Value::CreateBooleanValue(true));
SigninManagerBase* signin =
SigninManagerFactory::GetForProfile(harness_.profile.get());
harness_.service.reset(new TestProfileSyncService(
new ProfileSyncComponentsFactoryMock(),
harness_.profile.get(),
signin,
ProfileSyncService::MANUAL_START,
true));
harness_.service->Initialize();
EXPECT_TRUE(harness_.service->IsManaged());
}
TEST_F(ProfileSyncServiceTest, AbortedByShutdown) {
SigninManagerBase* signin =
SigninManagerFactory::GetForProfile(harness_.profile.get());
signin->SetAuthenticatedUsername("test");
ProfileSyncComponentsFactoryMock* factory =
new ProfileSyncComponentsFactoryMock();
harness_.service.reset(new TestProfileSyncService(
factory,
harness_.profile.get(),
signin,
ProfileSyncService::AUTO_START,
true));
EXPECT_CALL(*factory, CreateDataTypeManager(_, _, _, _, _, _)).Times(0);
EXPECT_CALL(*factory, CreateBookmarkSyncComponents(_, _)).
Times(0);
harness_.service->RegisterDataTypeController(
new BookmarkDataTypeController(harness_.service->factory(),
harness_.profile.get(),
harness_.service.get()));
harness_.service->Initialize();
harness_.service->Shutdown();
harness_.service.reset();
}
TEST_F(ProfileSyncServiceTest, DisableAndEnableSyncTemporarily) {
SigninManagerBase* signin =
SigninManagerFactory::GetForProfile(harness_.profile.get());
signin->SetAuthenticatedUsername("test");
ProfileSyncComponentsFactoryMock* factory =
new ProfileSyncComponentsFactoryMock();
harness_.service.reset(new TestProfileSyncService(
factory,
harness_.profile.get(),
signin,
ProfileSyncService::AUTO_START,
true));
// Register the bookmark data type.
EXPECT_CALL(*factory, CreateDataTypeManager(_, _, _, _, _, _)).
WillRepeatedly(ReturnNewDataTypeManager());
harness_.IssueTestTokens();
harness_.service->Initialize();
EXPECT_TRUE(harness_.service->sync_initialized());
EXPECT_TRUE(harness_.service->GetBackendForTest() != NULL);
EXPECT_FALSE(
harness_.profile->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart));
harness_.service->StopAndSuppress();
EXPECT_FALSE(harness_.service->sync_initialized());
EXPECT_TRUE(
harness_.profile->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart));
harness_.service->UnsuppressAndStart();
EXPECT_TRUE(harness_.service->sync_initialized());
EXPECT_FALSE(
harness_.profile->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart));
}
// Certain ProfileSyncService tests don't apply to Chrome OS, for example
// things that deal with concepts like "signing out" and policy.
#if !defined (OS_CHROMEOS)
TEST_F(ProfileSyncServiceTest, EnableSyncAndSignOut) {
SigninManager* signin =
SigninManagerFactory::GetForProfile(harness_.profile.get());
signin->SetAuthenticatedUsername("test@test.com");
ProfileSyncComponentsFactoryMock* factory =
new ProfileSyncComponentsFactoryMock();
harness_.service.reset(new TestProfileSyncService(
factory,
harness_.profile.get(),
signin,
ProfileSyncService::AUTO_START,
true));
// Register the bookmark data type.
EXPECT_CALL(*factory, CreateDataTypeManager(_, _, _, _, _, _)).
WillRepeatedly(ReturnNewDataTypeManager());
harness_.IssueTestTokens();
harness_.service->Initialize();
EXPECT_TRUE(harness_.service->sync_initialized());
EXPECT_TRUE(harness_.service->GetBackendForTest() != NULL);
EXPECT_FALSE(
harness_.profile->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart));
signin->SignOut();
EXPECT_FALSE(harness_.service->sync_initialized());
}
#endif // !defined(OS_CHROMEOS)
TEST_F(ProfileSyncServiceTest, JsControllerHandlersBasic) {
harness_.StartSyncService();
EXPECT_TRUE(harness_.service->sync_initialized());
EXPECT_TRUE(harness_.service->GetBackendForTest() != NULL);
base::WeakPtr<syncer::JsController> js_controller =
harness_.service->GetJsController();
StrictMock<syncer::MockJsEventHandler> event_handler;
js_controller->AddJsEventHandler(&event_handler);
js_controller->RemoveJsEventHandler(&event_handler);
}
TEST_F(ProfileSyncServiceTest,
JsControllerHandlersDelayedBackendInitialization) {
harness_.StartSyncServiceAndSetInitialSyncEnded(true, false, false, true,
syncer::STORAGE_IN_MEMORY);
StrictMock<syncer::MockJsEventHandler> event_handler;
EXPECT_CALL(event_handler, HandleJsEvent(_, _)).Times(AtLeast(1));
EXPECT_EQ(NULL, harness_.service->GetBackendForTest());
EXPECT_FALSE(harness_.service->sync_initialized());
base::WeakPtr<syncer::JsController> js_controller =
harness_.service->GetJsController();
js_controller->AddJsEventHandler(&event_handler);
// Since we're doing synchronous initialization, backend should be
// initialized by this call.
harness_.IssueTestTokens();
EXPECT_TRUE(harness_.service->sync_initialized());
js_controller->RemoveJsEventHandler(&event_handler);
}
TEST_F(ProfileSyncServiceTest, JsControllerProcessJsMessageBasic) {
harness_.StartSyncService();
StrictMock<syncer::MockJsReplyHandler> reply_handler;
ListValue arg_list1;
arg_list1.Append(Value::CreateStringValue("TRANSIENT_INVALIDATION_ERROR"));
syncer::JsArgList args1(&arg_list1);
EXPECT_CALL(reply_handler,
HandleJsReply("getNotificationState", HasArgs(args1)));
{
base::WeakPtr<syncer::JsController> js_controller =
harness_.service->GetJsController();
js_controller->ProcessJsMessage("getNotificationState", args1,
reply_handler.AsWeakHandle());
}
// This forces the sync thread to process the message and reply.
harness_.TearDown();
}
TEST_F(ProfileSyncServiceTest,
JsControllerProcessJsMessageBasicDelayedBackendInitialization) {
harness_.StartSyncServiceAndSetInitialSyncEnded(true, false, false, true,
syncer::STORAGE_IN_MEMORY);
StrictMock<syncer::MockJsReplyHandler> reply_handler;
ListValue arg_list1;
arg_list1.Append(Value::CreateStringValue("TRANSIENT_INVALIDATION_ERROR"));
syncer::JsArgList args1(&arg_list1);
EXPECT_CALL(reply_handler,
HandleJsReply("getNotificationState", HasArgs(args1)));
{
base::WeakPtr<syncer::JsController> js_controller =
harness_.service->GetJsController();
js_controller->ProcessJsMessage("getNotificationState",
args1, reply_handler.AsWeakHandle());
}
harness_.IssueTestTokens();
// This forces the sync thread to process the message and reply.
harness_.TearDown();
}
// Make sure that things still work if sync is not enabled, but some old sync
// databases are lingering in the "Sync Data" folder.
TEST_F(ProfileSyncServiceTest, TestStartupWithOldSyncData) {
const char* nonsense1 = "reginald";
const char* nonsense2 = "beartato";
const char* nonsense3 = "harrison";
base::FilePath temp_directory =
harness_.profile->GetPath().AppendASCII("Sync Data");
base::FilePath sync_file1 =
temp_directory.AppendASCII("BookmarkSyncSettings.sqlite3");
base::FilePath sync_file2 = temp_directory.AppendASCII("SyncData.sqlite3");
base::FilePath sync_file3 = temp_directory.AppendASCII("nonsense_file");
ASSERT_TRUE(file_util::CreateDirectory(temp_directory));
ASSERT_NE(-1,
file_util::WriteFile(sync_file1, nonsense1, strlen(nonsense1)));
ASSERT_NE(-1,
file_util::WriteFile(sync_file2, nonsense2, strlen(nonsense2)));
ASSERT_NE(-1,
file_util::WriteFile(sync_file3, nonsense3, strlen(nonsense3)));
harness_.StartSyncServiceAndSetInitialSyncEnded(true, false, true, false,
syncer::STORAGE_ON_DISK);
EXPECT_FALSE(harness_.service->HasSyncSetupCompleted());
EXPECT_FALSE(harness_.service->sync_initialized());
// Since we're doing synchronous initialization, backend should be
// initialized by this call.
harness_.IssueTestTokens();
// Stop the service so we can read the new Sync Data files that were
// created.
harness_.service->Shutdown();
harness_.service.reset();
// This file should have been deleted when the whole directory was nuked.
ASSERT_FALSE(file_util::PathExists(sync_file3));
ASSERT_FALSE(file_util::PathExists(sync_file1));
// This will still exist, but the text should have changed.
ASSERT_TRUE(file_util::PathExists(sync_file2));
std::string file2text;
ASSERT_TRUE(file_util::ReadFileToString(sync_file2, &file2text));
ASSERT_NE(file2text.compare(nonsense2), 0);
}
// Simulates a scenario where a database is corrupted and it is impossible to
// recreate it. This test is useful mainly when it is run under valgrind. Its
// expectations are not very interesting.
TEST_F(ProfileSyncServiceTest, FailToOpenDatabase) {
harness_.StartSyncServiceAndSetInitialSyncEnded(false, true, true, true,
syncer::STORAGE_INVALID);
// The backend is not ready. Ensure the PSS knows this.
EXPECT_FALSE(harness_.service->sync_initialized());
}
// This setup will allow the database to exist, but leave it empty. The attempt
// to download control types will silently fail (no downloads have any effect in
// these tests). The sync_backend_host will notice this and inform the profile
// sync service of the failure to initialize the backed.
TEST_F(ProfileSyncServiceTest, FailToDownloadControlTypes) {
harness_.StartSyncServiceAndSetInitialSyncEnded(false, true, true, true,
syncer::STORAGE_IN_MEMORY);
// The backend is not ready. Ensure the PSS knows this.
EXPECT_FALSE(harness_.service->sync_initialized());
}
// Register a handler with the ProfileSyncService, and disable and
// reenable sync. The handler should get notified of the state
// changes.
// Flaky on all platforms. http://crbug.com/154491
TEST_F(ProfileSyncServiceTest, DISABLED_DisableInvalidationsOnStop) {
harness_.StartSyncServiceAndSetInitialSyncEnded(
true, true, true, true, syncer::STORAGE_IN_MEMORY);
syncer::FakeInvalidationHandler handler;
harness_.service->RegisterInvalidationHandler(&handler);
SyncBackendHostForProfileSyncTest* const backend =
harness_.service->GetBackendForTest();
backend->EmitOnInvalidatorStateChange(syncer::INVALIDATIONS_ENABLED);
EXPECT_EQ(syncer::INVALIDATIONS_ENABLED, handler.GetInvalidatorState());
harness_.service->StopAndSuppress();
EXPECT_EQ(syncer::TRANSIENT_INVALIDATION_ERROR,
handler.GetInvalidatorState());
harness_.service->UnsuppressAndStart();
EXPECT_EQ(syncer::INVALIDATIONS_ENABLED, handler.GetInvalidatorState());
harness_.service->UnregisterInvalidationHandler(&handler);
}
// Register for some IDs with the ProfileSyncService, restart sync,
// and trigger some invalidation messages. They should still be
// received by the handler.
TEST_F(ProfileSyncServiceTest, UpdateRegisteredInvalidationIdsPersistence) {
harness_.StartSyncService();
syncer::ObjectIdSet ids;
ids.insert(invalidation::ObjectId(3, "id3"));
const syncer::ObjectIdInvalidationMap& states =
syncer::ObjectIdSetToInvalidationMap(ids, "payload");
syncer::FakeInvalidationHandler handler;
harness_.service->RegisterInvalidationHandler(&handler);
harness_.service->UpdateRegisteredInvalidationIds(&handler, ids);
harness_.service->StopAndSuppress();
harness_.service->UnsuppressAndStart();
SyncBackendHostForProfileSyncTest* const backend =
harness_.service->GetBackendForTest();
backend->EmitOnInvalidatorStateChange(syncer::INVALIDATIONS_ENABLED);
EXPECT_EQ(syncer::INVALIDATIONS_ENABLED, handler.GetInvalidatorState());
backend->EmitOnIncomingInvalidation(states);
EXPECT_THAT(states, Eq(handler.GetLastInvalidationMap()));
backend->EmitOnInvalidatorStateChange(syncer::TRANSIENT_INVALIDATION_ERROR);
EXPECT_EQ(syncer::TRANSIENT_INVALIDATION_ERROR,
handler.GetInvalidatorState());
harness_.service->UnregisterInvalidationHandler(&handler);
}
// Thin Invalidator wrapper around ProfileSyncService.
class ProfileSyncServiceInvalidator : public syncer::Invalidator {
public:
explicit ProfileSyncServiceInvalidator(ProfileSyncService* service)
: service_(service) {}
virtual ~ProfileSyncServiceInvalidator() {}
// Invalidator implementation.
virtual void RegisterHandler(syncer::InvalidationHandler* handler) OVERRIDE {
service_->RegisterInvalidationHandler(handler);
}
virtual void UpdateRegisteredIds(syncer::InvalidationHandler* handler,
const syncer::ObjectIdSet& ids) OVERRIDE {
service_->UpdateRegisteredInvalidationIds(handler, ids);
}
virtual void UnregisterHandler(
syncer::InvalidationHandler* handler) OVERRIDE {
service_->UnregisterInvalidationHandler(handler);
}
virtual void Acknowledge(const invalidation::ObjectId& id,
const syncer::AckHandle& ack_handle) OVERRIDE {
// Do nothing.
}
virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE {
return service_->GetInvalidatorState();
}
virtual void UpdateCredentials(
const std::string& email, const std::string& token) OVERRIDE {
// Do nothing.
}
virtual void SendInvalidation(
const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE {
// Do nothing.
}
private:
ProfileSyncService* const service_;
DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceInvalidator);
};
} // namespace
// ProfileSyncServiceInvalidatorTestDelegate has to be visible from
// the syncer namespace (where InvalidatorTest lives).
class ProfileSyncServiceInvalidatorTestDelegate {
public:
ProfileSyncServiceInvalidatorTestDelegate() {}
~ProfileSyncServiceInvalidatorTestDelegate() {
DestroyInvalidator();
}
void CreateInvalidator(
const std::string& invalidation_client_id,
const std::string& initial_state,
const base::WeakPtr<syncer::InvalidationStateTracker>&
invalidation_state_tracker) {
DCHECK(!invalidator_.get());
harness_.SetUp();
harness_.StartSyncService();
invalidator_.reset(
new ProfileSyncServiceInvalidator(harness_.service.get()));
}
ProfileSyncServiceInvalidator* GetInvalidator() {
return invalidator_.get();
}
void DestroyInvalidator() {
invalidator_.reset();
harness_.TearDown();
}
void WaitForInvalidator() {
// Do nothing.
}
void TriggerOnInvalidatorStateChange(syncer::InvalidatorState state) {
harness_.service->GetBackendForTest()->EmitOnInvalidatorStateChange(state);
}
void TriggerOnIncomingInvalidation(
const syncer::ObjectIdInvalidationMap& invalidation_map) {
harness_.service->GetBackendForTest()->EmitOnIncomingInvalidation(
invalidation_map);
}
private:
ProfileSyncServiceTestHarness harness_;
scoped_ptr<ProfileSyncServiceInvalidator> invalidator_;
};
} // namespace browser_sync
namespace syncer {
namespace {
// ProfileSyncService should behave just like an invalidator.
INSTANTIATE_TYPED_TEST_CASE_P(
ProfileSyncServiceInvalidatorTest, InvalidatorTest,
::browser_sync::ProfileSyncServiceInvalidatorTestDelegate);
} // namespace
} // namespace syncer
|