| Index: chrome/browser/sync/profile_sync_service_unittest.cc
|
| diff --git a/chrome/browser/sync/profile_sync_service_unittest.cc b/chrome/browser/sync/profile_sync_service_unittest.cc
|
| index a6f692f2d3f7250d7b279389de7db3ccbd9d05c7..01d0a758be515ca8df0b6032d4dd4b64fc0af1ee 100644
|
| --- a/chrome/browser/sync/profile_sync_service_unittest.cc
|
| +++ b/chrome/browser/sync/profile_sync_service_unittest.cc
|
| @@ -21,9 +21,11 @@
|
| #include "chrome/test/base/testing_profile.h"
|
| #include "content/public/common/content_client.h"
|
| #include "content/public/test/test_browser_thread.h"
|
| +#include "google/cacheinvalidation/include/types.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/mock_sync_notifier_observer.h"
|
| #include "testing/gmock/include/gmock/gmock.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "webkit/glue/webkit_glue.h"
|
| @@ -40,6 +42,7 @@ using content::BrowserThread;
|
| using testing::_;
|
| using testing::AtLeast;
|
| using testing::AtMost;
|
| +using testing::Mock;
|
| using testing::Return;
|
| using testing::StrictMock;
|
|
|
| @@ -82,7 +85,7 @@ class ProfileSyncServiceTest : public testing::Test {
|
|
|
| void StartSyncService() {
|
| StartSyncServiceAndSetInitialSyncEnded(
|
| - true, true, false, true, true, false);
|
| + true, true, false, true, 1, false);
|
| }
|
|
|
| void StartSyncServiceAndSetInitialSyncEnded(
|
| @@ -90,7 +93,7 @@ class ProfileSyncServiceTest : public testing::Test {
|
| bool issue_auth_token,
|
| bool synchronous_sync_configuration,
|
| bool sync_setup_completed,
|
| - bool expect_create_dtm,
|
| + int expected_create_dtm_calls,
|
| bool use_real_database) {
|
| if (!service_.get()) {
|
| SigninManager* signin =
|
| @@ -114,14 +117,10 @@ class ProfileSyncServiceTest : public testing::Test {
|
| if (!sync_setup_completed)
|
| profile_->GetPrefs()->SetBoolean(prefs::kSyncHasSetupCompleted, false);
|
|
|
| - if (expect_create_dtm) {
|
| - // Register the bookmark data type.
|
| - EXPECT_CALL(*factory, CreateDataTypeManager(_, _)).
|
| - WillOnce(ReturnNewDataTypeManager());
|
| - } else {
|
| - EXPECT_CALL(*factory, CreateDataTypeManager(_, _)).
|
| - Times(0);
|
| - }
|
| + // Register the bookmark data type.
|
| + EXPECT_CALL(*factory, CreateDataTypeManager(_, _)).
|
| + Times(expected_create_dtm_calls).
|
| + WillRepeatedly(ReturnNewDataTypeManager());
|
|
|
| if (issue_auth_token) {
|
| IssueTestTokens();
|
| @@ -253,7 +252,7 @@ TEST_F(ProfileSyncServiceTest, JsControllerHandlersBasic) {
|
|
|
| TEST_F(ProfileSyncServiceTest,
|
| JsControllerHandlersDelayedBackendInitialization) {
|
| - StartSyncServiceAndSetInitialSyncEnded(true, false, false, true, true, false);
|
| + StartSyncServiceAndSetInitialSyncEnded(true, false, false, true, 1, false);
|
|
|
| StrictMock<syncer::MockJsEventHandler> event_handler;
|
| EXPECT_CALL(event_handler, HandleJsEvent(_, _)).Times(AtLeast(1));
|
| @@ -294,7 +293,7 @@ TEST_F(ProfileSyncServiceTest, JsControllerProcessJsMessageBasic) {
|
|
|
| TEST_F(ProfileSyncServiceTest,
|
| JsControllerProcessJsMessageBasicDelayedBackendInitialization) {
|
| - StartSyncServiceAndSetInitialSyncEnded(true, false, false, true, true, false);
|
| + StartSyncServiceAndSetInitialSyncEnded(true, false, false, true, 1, false);
|
|
|
| StrictMock<syncer::MockJsReplyHandler> reply_handler;
|
|
|
| @@ -336,7 +335,7 @@ TEST_F(ProfileSyncServiceTest, TestStartupWithOldSyncData) {
|
| ASSERT_NE(-1,
|
| file_util::WriteFile(sync_file3, nonsense3, strlen(nonsense3)));
|
|
|
| - StartSyncServiceAndSetInitialSyncEnded(false, false, true, false, true, true);
|
| + StartSyncServiceAndSetInitialSyncEnded(false, false, true, false, 1, true);
|
| EXPECT_FALSE(service_->HasSyncSetupCompleted());
|
| EXPECT_FALSE(service_->sync_initialized());
|
|
|
| @@ -373,7 +372,7 @@ TEST_F(ProfileSyncServiceTest, DISABLED_CorruptDatabase) {
|
| // Initialize with HasSyncSetupCompleted() set to true and InitialSyncEnded
|
| // false. This is to model the scenario that would result when opening the
|
| // sync database fails.
|
| - StartSyncServiceAndSetInitialSyncEnded(false, true, true, true, false, true);
|
| + StartSyncServiceAndSetInitialSyncEnded(false, true, true, true, 0, true);
|
|
|
| // The backend is not ready. Ensure the PSS knows this.
|
| EXPECT_FALSE(service_->sync_initialized());
|
| @@ -382,6 +381,63 @@ TEST_F(ProfileSyncServiceTest, DISABLED_CorruptDatabase) {
|
| EXPECT_FALSE(service_->HasSyncSetupCompleted());
|
| }
|
|
|
| +// Register for some IDs with the ProfileSyncService and trigger some
|
| +// invalidation messages. They should be received by the observer.
|
| +// Then unregister and trigger the invalidation messages again. Those
|
| +// shouldn't be received by the observer.
|
| +TEST_F(ProfileSyncServiceTest, UpdateRegisteredIds) {
|
| + StartSyncService();
|
| +
|
| + syncer::ObjectIdSet ids;
|
| + ids.insert(invalidation::ObjectId(1, "id1"));
|
| + ids.insert(invalidation::ObjectId(2, "id2"));
|
| + const syncer::ObjectIdPayloadMap& payloads =
|
| + syncer::ObjectIdSetToPayloadMap(ids, "payload");
|
| +
|
| + StrictMock<syncer::MockSyncNotifierObserver> observer;
|
| + EXPECT_CALL(observer, OnNotificationsEnabled());
|
| + EXPECT_CALL(observer, OnNotificationsDisabled(
|
| + syncer::TRANSIENT_NOTIFICATION_ERROR));
|
| + EXPECT_CALL(observer, OnIncomingNotification(
|
| + payloads, syncer::REMOTE_NOTIFICATION));
|
| +
|
| + service_->UpdateRegisteredIds(&observer, ids);
|
| +
|
| + SyncBackendHostForProfileSyncTest* const backend =
|
| + service_->GetBackendForTest();
|
| +
|
| + backend->EmitOnNotificationsEnabled();
|
| + backend->EmitOnNotificationsDisabled(syncer::TRANSIENT_NOTIFICATION_ERROR);
|
| + backend->EmitOnIncomingNotification(payloads, syncer::REMOTE_NOTIFICATION);
|
| +
|
| + Mock::VerifyAndClearExpectations(&observer);
|
| +
|
| + service_->UpdateRegisteredIds(&observer, syncer::ObjectIdSet());
|
| +
|
| + backend->EmitOnNotificationsEnabled();
|
| + backend->EmitOnNotificationsDisabled(syncer::TRANSIENT_NOTIFICATION_ERROR);
|
| + backend->EmitOnIncomingNotification(payloads, syncer::REMOTE_NOTIFICATION);
|
| +}
|
| +
|
| +// Register for some IDs with the ProfileSyncService, restart sync,
|
| +// and trigger some invalidation messages. They should still be
|
| +// received by the observer.
|
| +TEST_F(ProfileSyncServiceTest, UpdateRegisteredIdsPersistence) {
|
| + StartSyncServiceAndSetInitialSyncEnded(true, true, false, true, 2, false);
|
| +
|
| + StrictMock<syncer::MockSyncNotifierObserver> observer;
|
| + EXPECT_CALL(observer, OnNotificationsEnabled());
|
| +
|
| + syncer::ObjectIdSet ids;
|
| + ids.insert(invalidation::ObjectId(3, "id3"));
|
| + service_->UpdateRegisteredIds(&observer, ids);
|
| +
|
| + service_->StopAndSuppress();
|
| + service_->UnsuppressAndStart();
|
| +
|
| + service_->GetBackendForTest()->EmitOnNotificationsEnabled();
|
| +}
|
| +
|
| } // namespace
|
|
|
| } // namespace browser_sync
|
|
|