| 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 "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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 config_state_map, | 224 config_state_map, |
| 223 base::Bind(&SyncBackendHostTest::DownloadReady, | 225 base::Bind(&SyncBackendHostTest::DownloadReady, |
| 224 base::Unretained(this)), | 226 base::Unretained(this)), |
| 225 base::Bind(&SyncBackendHostTest::OnDownloadRetry, | 227 base::Bind(&SyncBackendHostTest::OnDownloadRetry, |
| 226 base::Unretained(this))); | 228 base::Unretained(this))); |
| 227 ui_loop_.PostDelayedTask(FROM_HERE, | 229 ui_loop_.PostDelayedTask(FROM_HERE, |
| 228 ui_loop_.QuitClosure(), TestTimeouts::action_timeout()); | 230 ui_loop_.QuitClosure(), TestTimeouts::action_timeout()); |
| 229 ui_loop_.Run(); | 231 ui_loop_.Run(); |
| 230 } | 232 } |
| 231 | 233 |
| 234 void IssueRefreshRequest(syncer::ModelTypeSet types) { |
| 235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 236 |
| 237 syncer::ModelTypeInvalidationMap invalidation_map( |
| 238 ModelTypeSetToInvalidationMap(types, std::string())); |
| 239 |
| 240 content::NotificationService::current()->Notify( |
| 241 chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, |
| 242 content::Source<Profile>(profile_.get()), |
| 243 content::Details<syncer::ModelTypeInvalidationMap>( |
| 244 &invalidation_map)); |
| 245 } |
| 246 |
| 232 protected: | 247 protected: |
| 233 void DownloadReady(syncer::ModelTypeSet types) { | 248 void DownloadReady(syncer::ModelTypeSet types) { |
| 234 MessageLoop::current()->Quit(); | 249 MessageLoop::current()->Quit(); |
| 235 } | 250 } |
| 236 | 251 |
| 237 void OnDownloadRetry() { | 252 void OnDownloadRetry() { |
| 238 NOTIMPLEMENTED(); | 253 NOTIMPLEMENTED(); |
| 239 } | 254 } |
| 240 | 255 |
| 241 MessageLoop ui_loop_; | 256 MessageLoop ui_loop_; |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 // should detect this condition and fail to initialize the backend. | 698 // should detect this condition and fail to initialize the backend. |
| 684 // | 699 // |
| 685 // The failure is "silent" in the sense that the GetUpdates request appears to | 700 // The failure is "silent" in the sense that the GetUpdates request appears to |
| 686 // be successful, but it returned no results. This means that the usual | 701 // be successful, but it returned no results. This means that the usual |
| 687 // download retry logic will not be invoked. | 702 // download retry logic will not be invoked. |
| 688 TEST_F(SyncBackendHostTest, SilentlyFailToDownloadControlTypes) { | 703 TEST_F(SyncBackendHostTest, SilentlyFailToDownloadControlTypes) { |
| 689 fake_manager_factory_.set_configure_fail_types(syncer::ModelTypeSet::All()); | 704 fake_manager_factory_.set_configure_fail_types(syncer::ModelTypeSet::All()); |
| 690 InitializeBackend(false); | 705 InitializeBackend(false); |
| 691 } | 706 } |
| 692 | 707 |
| 708 // Test that local refresh requests are delivered to sync. |
| 709 TEST_F(SyncBackendHostTest, ForwardLocalRefreshRequest) { |
| 710 InitializeBackend(true); |
| 711 |
| 712 syncer::ModelTypeSet set1 = syncer::ModelTypeSet::All(); |
| 713 IssueRefreshRequest(set1); |
| 714 fake_manager_->WaitForSyncThread(); |
| 715 EXPECT_TRUE(set1.Equals(fake_manager_->GetLastRefreshRequestTypes())); |
| 716 |
| 717 syncer::ModelTypeSet set2 = syncer::ModelTypeSet(syncer::SESSIONS); |
| 718 IssueRefreshRequest(set2); |
| 719 fake_manager_->WaitForSyncThread(); |
| 720 EXPECT_TRUE(set2.Equals(fake_manager_->GetLastRefreshRequestTypes())); |
| 721 } |
| 722 |
| 723 // Test that local invalidations issued before sync is initialized are ignored. |
| 724 TEST_F(SyncBackendHostTest, AttemptForwardLocalRefreshRequestEarly) { |
| 725 syncer::ModelTypeSet set1 = syncer::ModelTypeSet::All(); |
| 726 IssueRefreshRequest(set1); |
| 727 |
| 728 InitializeBackend(true); |
| 729 |
| 730 fake_manager_->WaitForSyncThread(); |
| 731 EXPECT_FALSE(set1.Equals(fake_manager_->GetLastRefreshRequestTypes())); |
| 732 } |
| 733 |
| 734 // Test that local invalidations issued while sync is shutting down are ignored. |
| 735 TEST_F(SyncBackendHostTest, AttemptForwardLocalRefreshRequestLate) { |
| 736 InitializeBackend(true); |
| 737 |
| 738 backend_->StopSyncingForShutdown(); |
| 739 |
| 740 syncer::ModelTypeSet types = syncer::ModelTypeSet::All(); |
| 741 IssueRefreshRequest(types); |
| 742 fake_manager_->WaitForSyncThread(); |
| 743 EXPECT_FALSE(types.Equals(fake_manager_->GetLastRefreshRequestTypes())); |
| 744 |
| 745 backend_->Shutdown(false); |
| 746 backend_.reset(); |
| 747 } |
| 748 |
| 693 } // namespace | 749 } // namespace |
| 694 | 750 |
| 695 } // namespace browser_sync | 751 } // namespace browser_sync |
| OLD | NEW |