OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/signin/signin_manager.h" | 9 #include "chrome/browser/signin/signin_manager.h" |
10 #include "chrome/browser/signin/signin_manager_factory.h" | 10 #include "chrome/browser/signin/signin_manager_factory.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 namespace { | 39 namespace { |
40 | 40 |
41 using content::BrowserThread; | 41 using content::BrowserThread; |
42 using testing::_; | 42 using testing::_; |
43 using testing::AtLeast; | 43 using testing::AtLeast; |
44 using testing::AtMost; | 44 using testing::AtMost; |
45 using testing::Mock; | 45 using testing::Mock; |
46 using testing::Return; | 46 using testing::Return; |
47 using testing::StrictMock; | 47 using testing::StrictMock; |
48 | 48 |
| 49 const char kHandlerName[] = "MockObserver"; |
| 50 |
49 class ProfileSyncServiceTest : public testing::Test { | 51 class ProfileSyncServiceTest : public testing::Test { |
50 protected: | 52 protected: |
51 ProfileSyncServiceTest() | 53 ProfileSyncServiceTest() |
52 : ui_thread_(BrowserThread::UI, &ui_loop_), | 54 : ui_thread_(BrowserThread::UI, &ui_loop_), |
53 db_thread_(BrowserThread::DB), | 55 db_thread_(BrowserThread::DB), |
54 file_thread_(BrowserThread::FILE), | 56 file_thread_(BrowserThread::FILE), |
55 io_thread_(BrowserThread::IO) {} | 57 io_thread_(BrowserThread::IO) {} |
56 | 58 |
57 virtual ~ProfileSyncServiceTest() {} | 59 virtual ~ProfileSyncServiceTest() {} |
58 | 60 |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 const syncer::ObjectIdPayloadMap& payloads = | 384 const syncer::ObjectIdPayloadMap& payloads = |
383 syncer::ObjectIdSetToPayloadMap(ids, "payload"); | 385 syncer::ObjectIdSetToPayloadMap(ids, "payload"); |
384 | 386 |
385 StrictMock<syncer::MockSyncNotifierObserver> observer; | 387 StrictMock<syncer::MockSyncNotifierObserver> observer; |
386 EXPECT_CALL(observer, OnNotificationsEnabled()); | 388 EXPECT_CALL(observer, OnNotificationsEnabled()); |
387 EXPECT_CALL(observer, OnNotificationsDisabled( | 389 EXPECT_CALL(observer, OnNotificationsDisabled( |
388 syncer::TRANSIENT_NOTIFICATION_ERROR)); | 390 syncer::TRANSIENT_NOTIFICATION_ERROR)); |
389 EXPECT_CALL(observer, OnIncomingNotification( | 391 EXPECT_CALL(observer, OnIncomingNotification( |
390 payloads, syncer::REMOTE_NOTIFICATION)); | 392 payloads, syncer::REMOTE_NOTIFICATION)); |
391 | 393 |
392 service_->UpdateRegisteredInvalidationIds(&observer, ids); | 394 service_->SetInvalidationHandler(kHandlerName, &observer); |
| 395 service_->UpdateRegisteredInvalidationIds(kHandlerName, ids); |
393 | 396 |
394 SyncBackendHostForProfileSyncTest* const backend = | 397 SyncBackendHostForProfileSyncTest* const backend = |
395 service_->GetBackendForTest(); | 398 service_->GetBackendForTest(); |
396 | 399 |
397 backend->EmitOnNotificationsEnabled(); | 400 backend->EmitOnNotificationsEnabled(); |
398 backend->EmitOnNotificationsDisabled(syncer::TRANSIENT_NOTIFICATION_ERROR); | 401 backend->EmitOnNotificationsDisabled(syncer::TRANSIENT_NOTIFICATION_ERROR); |
399 backend->EmitOnIncomingNotification(payloads, syncer::REMOTE_NOTIFICATION); | 402 backend->EmitOnIncomingNotification(payloads, syncer::REMOTE_NOTIFICATION); |
400 | 403 |
401 Mock::VerifyAndClearExpectations(&observer); | 404 Mock::VerifyAndClearExpectations(&observer); |
402 | 405 |
403 service_->UpdateRegisteredInvalidationIds(&observer, syncer::ObjectIdSet()); | 406 service_->SetInvalidationHandler(kHandlerName, NULL); |
404 | 407 |
405 backend->EmitOnNotificationsEnabled(); | 408 backend->EmitOnNotificationsEnabled(); |
406 backend->EmitOnNotificationsDisabled(syncer::TRANSIENT_NOTIFICATION_ERROR); | 409 backend->EmitOnNotificationsDisabled(syncer::TRANSIENT_NOTIFICATION_ERROR); |
407 backend->EmitOnIncomingNotification(payloads, syncer::REMOTE_NOTIFICATION); | 410 backend->EmitOnIncomingNotification(payloads, syncer::REMOTE_NOTIFICATION); |
408 } | 411 } |
409 | 412 |
410 // Register for some IDs with the ProfileSyncService, restart sync, | 413 // Register for some IDs with the ProfileSyncService, restart sync, |
411 // and trigger some invalidation messages. They should still be | 414 // and trigger some invalidation messages. They should still be |
412 // received by the observer. | 415 // received by the observer. |
413 TEST_F(ProfileSyncServiceTest, UpdateRegisteredInvalidationIdsPersistence) { | 416 TEST_F(ProfileSyncServiceTest, UpdateRegisteredInvalidationIdsPersistence) { |
414 StartSyncService(); | 417 StartSyncService(); |
415 | 418 |
416 StrictMock<syncer::MockSyncNotifierObserver> observer; | 419 StrictMock<syncer::MockSyncNotifierObserver> observer; |
417 EXPECT_CALL(observer, OnNotificationsEnabled()); | 420 EXPECT_CALL(observer, OnNotificationsEnabled()); |
418 | 421 |
419 syncer::ObjectIdSet ids; | 422 syncer::ObjectIdSet ids; |
420 ids.insert(invalidation::ObjectId(3, "id3")); | 423 ids.insert(invalidation::ObjectId(3, "id3")); |
421 service_->UpdateRegisteredInvalidationIds(&observer, ids); | 424 service_->SetInvalidationHandler(kHandlerName, &observer); |
| 425 service_->UpdateRegisteredInvalidationIds(kHandlerName, ids); |
422 | 426 |
423 service_->StopAndSuppress(); | 427 service_->StopAndSuppress(); |
424 service_->UnsuppressAndStart(); | 428 service_->UnsuppressAndStart(); |
425 | 429 |
426 service_->GetBackendForTest()->EmitOnNotificationsEnabled(); | 430 service_->GetBackendForTest()->EmitOnNotificationsEnabled(); |
427 } | 431 } |
428 | 432 |
429 } // namespace | 433 } // namespace |
430 } // namespace browser_sync | 434 } // namespace browser_sync |
OLD | NEW |