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

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

Issue 12022041: Separate local and remote sync invalidations (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Respond to review comments Created 7 years, 10 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"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/synchronization/waitable_event.h" 12 #include "base/synchronization/waitable_event.h"
13 #include "base/test/test_timeouts.h" 13 #include "base/test/test_timeouts.h"
14 #include "chrome/browser/sync/glue/device_info.h" 14 #include "chrome/browser/sync/glue/device_info.h"
15 #include "chrome/browser/sync/glue/synced_device_tracker.h" 15 #include "chrome/browser/sync/glue/synced_device_tracker.h"
16 #include "chrome/browser/sync/invalidations/invalidator_storage.h" 16 #include "chrome/browser/sync/invalidations/invalidator_storage.h"
17 #include "chrome/browser/sync/sync_prefs.h" 17 #include "chrome/browser/sync/sync_prefs.h"
18 #include "chrome/common/chrome_notification_types.h"
18 #include "chrome/test/base/testing_profile.h" 19 #include "chrome/test/base/testing_profile.h"
20 #include "content/public/browser/notification_service.h"
19 #include "content/public/test/test_browser_thread.h" 21 #include "content/public/test/test_browser_thread.h"
20 #include "google/cacheinvalidation/include/types.h" 22 #include "google/cacheinvalidation/include/types.h"
21 #include "googleurl/src/gurl.h" 23 #include "googleurl/src/gurl.h"
22 #include "net/url_request/test_url_fetcher_factory.h" 24 #include "net/url_request/test_url_fetcher_factory.h"
23 #include "sync/internal_api/public/base/model_type.h" 25 #include "sync/internal_api/public/base/model_type.h"
24 #include "sync/internal_api/public/engine/model_safe_worker.h" 26 #include "sync/internal_api/public/engine/model_safe_worker.h"
25 #include "sync/internal_api/public/sync_manager_factory.h" 27 #include "sync/internal_api/public/sync_manager_factory.h"
26 #include "sync/internal_api/public/test/fake_sync_manager.h" 28 #include "sync/internal_api/public/test/fake_sync_manager.h"
27 #include "sync/internal_api/public/util/experiments.h" 29 #include "sync/internal_api/public/util/experiments.h"
28 #include "sync/notifier/invalidator_state.h" 30 #include "sync/notifier/invalidator_state.h"
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 types_to_remove, 218 types_to_remove,
217 base::Bind(&SyncBackendHostTest::DownloadReady, 219 base::Bind(&SyncBackendHostTest::DownloadReady,
218 base::Unretained(this)), 220 base::Unretained(this)),
219 base::Bind(&SyncBackendHostTest::OnDownloadRetry, 221 base::Bind(&SyncBackendHostTest::OnDownloadRetry,
220 base::Unretained(this))); 222 base::Unretained(this)));
221 ui_loop_.PostDelayedTask(FROM_HERE, 223 ui_loop_.PostDelayedTask(FROM_HERE,
222 ui_loop_.QuitClosure(), TestTimeouts::action_timeout()); 224 ui_loop_.QuitClosure(), TestTimeouts::action_timeout());
223 ui_loop_.Run(); 225 ui_loop_.Run();
224 } 226 }
225 227
228 void IssueRefreshRequest(syncer::ModelTypeSet types) {
229 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
230
231 syncer::ModelTypeInvalidationMap invalidation_map(
232 ModelTypeSetToInvalidationMap(types, std::string()));
233
234 content::NotificationService::current()->Notify(
235 chrome::NOTIFICATION_SYNC_REFRESH_LOCAL,
236 content::Source<Profile>(profile_.get()),
237 content::Details<syncer::ModelTypeInvalidationMap>(
238 &invalidation_map));
239 }
240
226 protected: 241 protected:
227 void DownloadReady(syncer::ModelTypeSet types) { 242 void DownloadReady(syncer::ModelTypeSet types) {
228 MessageLoop::current()->Quit(); 243 MessageLoop::current()->Quit();
229 } 244 }
230 245
231 void OnDownloadRetry() { 246 void OnDownloadRetry() {
232 NOTIMPLEMENTED(); 247 NOTIMPLEMENTED();
233 } 248 }
234 249
235 MessageLoop ui_loop_; 250 MessageLoop ui_loop_;
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 // should detect this condition and fail to initialize the backend. 692 // should detect this condition and fail to initialize the backend.
678 // 693 //
679 // The failure is "silent" in the sense that the GetUpdates request appears to 694 // The failure is "silent" in the sense that the GetUpdates request appears to
680 // be successful, but it returned no results. This means that the usual 695 // be successful, but it returned no results. This means that the usual
681 // download retry logic will not be invoked. 696 // download retry logic will not be invoked.
682 TEST_F(SyncBackendHostTest, SilentlyFailToDownloadControlTypes) { 697 TEST_F(SyncBackendHostTest, SilentlyFailToDownloadControlTypes) {
683 fake_manager_factory_.set_configure_fail_types(syncer::ModelTypeSet::All()); 698 fake_manager_factory_.set_configure_fail_types(syncer::ModelTypeSet::All());
684 InitializeBackend(false); 699 InitializeBackend(false);
685 } 700 }
686 701
702 // Test that local refresh requests are delivered to sync.
703 TEST_F(SyncBackendHostTest, ForwardLocalRefreshRequest) {
704 InitializeBackend(true);
705
706 syncer::ModelTypeSet set1 = syncer::ModelTypeSet::All();
707 IssueRefreshRequest(set1);
708 fake_manager_->WaitForSyncThread();
709 EXPECT_TRUE(set1.Equals(fake_manager_->GetLastRefreshRequestTypes()));
710
711 syncer::ModelTypeSet set2 = syncer::ModelTypeSet(syncer::SESSIONS);
712 IssueRefreshRequest(set2);
713 fake_manager_->WaitForSyncThread();
714 EXPECT_TRUE(set2.Equals(fake_manager_->GetLastRefreshRequestTypes()));
715 }
716
717 // Test that local invalidations issued before sync is initialized are ignored.
718 TEST_F(SyncBackendHostTest, AttemptForwardLocalRefreshRequestEarly) {
719 syncer::ModelTypeSet set1 = syncer::ModelTypeSet::All();
720 IssueRefreshRequest(set1);
721
722 InitializeBackend(true);
723
724 fake_manager_->WaitForSyncThread();
725 EXPECT_FALSE(set1.Equals(fake_manager_->GetLastRefreshRequestTypes()));
726 }
727
728 // Test that local invalidations issued while sync is shutting down are ignored.
729 TEST_F(SyncBackendHostTest, AttemptForwardLocalRefreshRequestLate) {
730 InitializeBackend(true);
731
732 backend_->StopSyncingForShutdown();
733
734 syncer::ModelTypeSet types = syncer::ModelTypeSet::All();
735 IssueRefreshRequest(types);
736 fake_manager_->WaitForSyncThread();
737 EXPECT_FALSE(types.Equals(fake_manager_->GetLastRefreshRequestTypes()));
738
739 backend_->Shutdown(false);
740 backend_.reset();
741 }
742
687 } // namespace 743 } // namespace
688 744
689 } // namespace browser_sync 745 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698