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

Side by Side Diff: chrome/browser/sync/glue/sync_backend_host_unittest.cc

Issue 13197004: Draft: InvalidationService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Passes tests Created 7 years, 8 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 (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 "chrome/browser/sync/glue/sync_backend_host.h" 5 #include "chrome/browser/sync/glue/sync_backend_host.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 8
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 virtual void SetUp() OVERRIDE { 144 virtual void SetUp() OVERRIDE {
145 io_thread_.StartIOThread(); 145 io_thread_.StartIOThread();
146 profile_.reset(new TestingProfile()); 146 profile_.reset(new TestingProfile());
147 profile_->CreateRequestContext(); 147 profile_->CreateRequestContext();
148 sync_prefs_.reset(new SyncPrefs(profile_->GetPrefs())); 148 sync_prefs_.reset(new SyncPrefs(profile_->GetPrefs()));
149 invalidator_storage_.reset(new InvalidatorStorage( 149 invalidator_storage_.reset(new InvalidatorStorage(
150 profile_->GetPrefs())); 150 profile_->GetPrefs()));
151 backend_.reset(new SyncBackendHost( 151 backend_.reset(new SyncBackendHost(
152 profile_->GetDebugName(), 152 profile_->GetDebugName(),
153 profile_.get(), 153 profile_.get(),
154 sync_prefs_->AsWeakPtr(), 154 sync_prefs_->AsWeakPtr()));
155 invalidator_storage_->AsWeakPtr()));
156 credentials_.email = "user@example.com"; 155 credentials_.email = "user@example.com";
157 credentials_.sync_token = "sync_token"; 156 credentials_.sync_token = "sync_token";
158 157
159 // These types are always implicitly enabled. 158 // These types are always implicitly enabled.
160 enabled_types_.PutAll(syncer::ControlTypes()); 159 enabled_types_.PutAll(syncer::ControlTypes());
161 160
162 // NOTE: We can't include Passwords or Typed URLs due to the Sync Backend 161 // NOTE: We can't include Passwords or Typed URLs due to the Sync Backend
163 // Registrar removing them if it can't find their model workers. 162 // Registrar removing them if it can't find their model workers.
164 enabled_types_.Put(syncer::BOOKMARKS); 163 enabled_types_.Put(syncer::BOOKMARKS);
165 enabled_types_.Put(syncer::NIGORI); 164 enabled_types_.Put(syncer::NIGORI);
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals( 583 EXPECT_TRUE(fake_manager_->GetAndResetDownloadedTypes().Equals(
585 Union(new_types, partial_types))); 584 Union(new_types, partial_types)));
586 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(), 585 EXPECT_TRUE(Intersection(fake_manager_->GetAndResetCleanedTypes(),
587 enabled_types_).Empty()); 586 enabled_types_).Empty());
588 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_)); 587 EXPECT_TRUE(fake_manager_->InitialSyncEndedTypes().Equals(enabled_types_));
589 EXPECT_TRUE(fake_manager_->GetAndResetEnabledTypes().Equals(enabled_types_)); 588 EXPECT_TRUE(fake_manager_->GetAndResetEnabledTypes().Equals(enabled_types_));
590 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken( 589 EXPECT_TRUE(fake_manager_->GetTypesWithEmptyProgressMarkerToken(
591 enabled_types_).Empty()); 590 enabled_types_).Empty());
592 } 591 }
593 592
594 // Register for some IDs and trigger an invalidation. This should
595 // propagate all the way to the frontend.
596 TEST_F(SyncBackendHostTest, Invalidate) {
597 InitializeBackend(true);
598
599 syncer::ObjectIdSet ids;
600 ids.insert(invalidation::ObjectId(1, "id1"));
601 ids.insert(invalidation::ObjectId(2, "id2"));
602 const syncer::ObjectIdInvalidationMap& invalidation_map =
603 syncer::ObjectIdSetToInvalidationMap(ids, "payload");
604
605 EXPECT_CALL(
606 mock_frontend_,
607 OnIncomingInvalidation(invalidation_map))
608 .WillOnce(InvokeWithoutArgs(QuitMessageLoop));
609
610 backend_->UpdateRegisteredInvalidationIds(ids);
611 fake_manager_->Invalidate(invalidation_map);
612 ui_loop_.PostDelayedTask(
613 FROM_HERE, ui_loop_.QuitClosure(), TestTimeouts::action_timeout());
614 ui_loop_.Run();
615 }
616
617 // Register for some IDs and update the invalidator state. This
618 // should propagate all the way to the frontend.
619 TEST_F(SyncBackendHostTest, UpdateInvalidatorState) {
620 InitializeBackend(true);
621
622 EXPECT_CALL(mock_frontend_,
623 OnInvalidatorStateChange(syncer::INVALIDATIONS_ENABLED))
624 .WillOnce(InvokeWithoutArgs(QuitMessageLoop));
625
626 syncer::ObjectIdSet ids;
627 ids.insert(invalidation::ObjectId(3, "id3"));
628 backend_->UpdateRegisteredInvalidationIds(ids);
629 fake_manager_->UpdateInvalidatorState(syncer::INVALIDATIONS_ENABLED);
630 ui_loop_.PostDelayedTask(
631 FROM_HERE, ui_loop_.QuitClosure(), TestTimeouts::action_timeout());
632 ui_loop_.Run();
633 }
634
635 // Call StopSyncingForShutdown() on the backend and fire some invalidations
636 // before calling Shutdown(). Then start up and shut down the backend again.
637 // Those notifications shouldn't propagate to the frontend.
638 TEST_F(SyncBackendHostTest, InvalidationsAfterStopSyncingForShutdown) {
639 InitializeBackend(true);
640
641 syncer::ObjectIdSet ids;
642 ids.insert(invalidation::ObjectId(5, "id5"));
643 backend_->UpdateRegisteredInvalidationIds(ids);
644
645 backend_->StopSyncingForShutdown();
646
647 // Should not trigger anything.
648 fake_manager_->UpdateInvalidatorState(syncer::TRANSIENT_INVALIDATION_ERROR);
649 fake_manager_->UpdateInvalidatorState(syncer::INVALIDATIONS_ENABLED);
650 const syncer::ObjectIdInvalidationMap& invalidation_map =
651 syncer::ObjectIdSetToInvalidationMap(ids, "payload");
652 fake_manager_->Invalidate(invalidation_map);
653
654 // Make sure the above calls take effect before we continue.
655 fake_manager_->WaitForSyncThread();
656
657 backend_->Shutdown(false);
658 backend_.reset();
659
660 TearDown();
661 SetUp();
662 }
663
664 // Ensure the device info tracker is initialized properly on startup. 593 // Ensure the device info tracker is initialized properly on startup.
665 TEST_F(SyncBackendHostTest, InitializeDeviceInfo) { 594 TEST_F(SyncBackendHostTest, InitializeDeviceInfo) {
666 ASSERT_EQ(NULL, backend_->GetSyncedDeviceTracker()); 595 ASSERT_EQ(NULL, backend_->GetSyncedDeviceTracker());
667 596
668 InitializeBackend(true); 597 InitializeBackend(true);
669 const SyncedDeviceTracker* device_tracker = 598 const SyncedDeviceTracker* device_tracker =
670 backend_->GetSyncedDeviceTracker(); 599 backend_->GetSyncedDeviceTracker();
671 ASSERT_TRUE(device_tracker->ReadLocalDeviceInfo()); 600 ASSERT_TRUE(device_tracker->ReadLocalDeviceInfo());
672 } 601 }
673 602
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 fake_manager_->WaitForSyncThread(); 673 fake_manager_->WaitForSyncThread();
745 EXPECT_FALSE(types.Equals(fake_manager_->GetLastRefreshRequestTypes())); 674 EXPECT_FALSE(types.Equals(fake_manager_->GetLastRefreshRequestTypes()));
746 675
747 backend_->Shutdown(false); 676 backend_->Shutdown(false);
748 backend_.reset(); 677 backend_.reset();
749 } 678 }
750 679
751 } // namespace 680 } // namespace
752 681
753 } // namespace browser_sync 682 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698