| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_impl.h" | 5 #include "chrome/browser/sync/glue/sync_backend_host_impl.h" |
| 6 | 6 |
| 7 #include <cstddef> | 7 #include <cstddef> |
| 8 | 8 |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
| 14 #include "base/test/test_timeouts.h" | 14 #include "base/test/test_timeouts.h" |
| 15 #include "base/time/time.h" |
| 15 #include "chrome/browser/chrome_notification_types.h" | 16 #include "chrome/browser/chrome_notification_types.h" |
| 16 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" | 17 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" |
| 17 #include "chrome/test/base/testing_browser_process.h" | 18 #include "chrome/test/base/testing_browser_process.h" |
| 18 #include "chrome/test/base/testing_profile.h" | 19 #include "chrome/test/base/testing_profile.h" |
| 19 #include "chrome/test/base/testing_profile_manager.h" | 20 #include "chrome/test/base/testing_profile_manager.h" |
| 20 #include "components/invalidation/impl/invalidator_storage.h" | 21 #include "components/invalidation/impl/invalidator_storage.h" |
| 21 #include "components/invalidation/impl/profile_invalidation_provider.h" | 22 #include "components/invalidation/impl/profile_invalidation_provider.h" |
| 22 #include "components/invalidation/public/invalidator_state.h" | 23 #include "components/invalidation/public/invalidator_state.h" |
| 23 #include "components/invalidation/public/object_id_invalidation_map.h" | 24 #include "components/invalidation/public/object_id_invalidation_map.h" |
| 24 #include "components/sync_driver/device_info.h" | 25 #include "components/sync_driver/device_info.h" |
| 25 #include "components/sync_driver/fake_sync_client.h" | 26 #include "components/sync_driver/fake_sync_client.h" |
| 26 #include "components/sync_driver/sync_frontend.h" | 27 #include "components/sync_driver/sync_frontend.h" |
| 27 #include "components/sync_driver/sync_prefs.h" | 28 #include "components/sync_driver/sync_prefs.h" |
| 28 #include "components/syncable_prefs/pref_service_syncable.h" | 29 #include "components/syncable_prefs/pref_service_syncable.h" |
| 29 #include "content/public/browser/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
| 30 #include "content/public/test/test_browser_thread_bundle.h" | 31 #include "content/public/test/test_browser_thread_bundle.h" |
| 31 #include "content/public/test/test_utils.h" | 32 #include "content/public/test/test_utils.h" |
| 32 #include "google/cacheinvalidation/include/types.h" | 33 #include "google/cacheinvalidation/include/types.h" |
| 33 #include "google_apis/gaia/gaia_constants.h" | 34 #include "google_apis/gaia/gaia_constants.h" |
| 34 #include "net/url_request/test_url_fetcher_factory.h" | 35 #include "net/url_request/test_url_fetcher_factory.h" |
| 36 #include "net/url_request/url_request_context_getter.h" |
| 35 #include "sync/internal_api/public/base/model_type.h" | 37 #include "sync/internal_api/public/base/model_type.h" |
| 36 #include "sync/internal_api/public/engine/model_safe_worker.h" | 38 #include "sync/internal_api/public/engine/model_safe_worker.h" |
| 37 #include "sync/internal_api/public/engine/passive_model_worker.h" | 39 #include "sync/internal_api/public/engine/passive_model_worker.h" |
| 38 #include "sync/internal_api/public/http_bridge_network_resources.h" | 40 #include "sync/internal_api/public/http_bridge_network_resources.h" |
| 39 #include "sync/internal_api/public/network_resources.h" | 41 #include "sync/internal_api/public/network_resources.h" |
| 40 #include "sync/internal_api/public/sessions/commit_counters.h" | 42 #include "sync/internal_api/public/sessions/commit_counters.h" |
| 41 #include "sync/internal_api/public/sessions/status_counters.h" | 43 #include "sync/internal_api/public/sessions/status_counters.h" |
| 42 #include "sync/internal_api/public/sessions/update_counters.h" | 44 #include "sync/internal_api/public/sessions/update_counters.h" |
| 43 #include "sync/internal_api/public/sync_manager_factory.h" | 45 #include "sync/internal_api/public/sync_manager_factory.h" |
| 44 #include "sync/internal_api/public/test/fake_sync_manager.h" | 46 #include "sync/internal_api/public/test/fake_sync_manager.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 68 FILE_PATH_LITERAL("sync-test"); | 70 FILE_PATH_LITERAL("sync-test"); |
| 69 | 71 |
| 70 ACTION_P(Signal, event) { | 72 ACTION_P(Signal, event) { |
| 71 event->Signal(); | 73 event->Signal(); |
| 72 } | 74 } |
| 73 | 75 |
| 74 void QuitMessageLoop() { | 76 void QuitMessageLoop() { |
| 75 base::MessageLoop::current()->QuitWhenIdle(); | 77 base::MessageLoop::current()->QuitWhenIdle(); |
| 76 } | 78 } |
| 77 | 79 |
| 80 void EmptyNetworkTimeUpdate(const base::Time&, |
| 81 const base::TimeDelta&, |
| 82 const base::TimeDelta&) {} |
| 83 |
| 78 class MockSyncFrontend : public sync_driver::SyncFrontend { | 84 class MockSyncFrontend : public sync_driver::SyncFrontend { |
| 79 public: | 85 public: |
| 80 virtual ~MockSyncFrontend() {} | 86 virtual ~MockSyncFrontend() {} |
| 81 | 87 |
| 82 MOCK_METHOD4( | 88 MOCK_METHOD4( |
| 83 OnBackendInitialized, | 89 OnBackendInitialized, |
| 84 void(const syncer::WeakHandle<syncer::JsBackend>&, | 90 void(const syncer::WeakHandle<syncer::JsBackend>&, |
| 85 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>&, | 91 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>&, |
| 86 const std::string&, | 92 const std::string&, |
| 87 bool)); | 93 bool)); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 base::RunLoop().RunUntilIdle(); | 226 base::RunLoop().RunUntilIdle(); |
| 221 content::RunAllPendingInMessageLoop(BrowserThread::IO); | 227 content::RunAllPendingInMessageLoop(BrowserThread::IO); |
| 222 // Pump any messages posted by the IO thread. | 228 // Pump any messages posted by the IO thread. |
| 223 base::RunLoop().RunUntilIdle(); | 229 base::RunLoop().RunUntilIdle(); |
| 224 } | 230 } |
| 225 | 231 |
| 226 // Synchronously initializes the backend. | 232 // Synchronously initializes the backend. |
| 227 void InitializeBackend(bool expect_success) { | 233 void InitializeBackend(bool expect_success) { |
| 228 EXPECT_CALL(mock_frontend_, OnBackendInitialized(_, _, _, expect_success)). | 234 EXPECT_CALL(mock_frontend_, OnBackendInitialized(_, _, _, expect_success)). |
| 229 WillOnce(InvokeWithoutArgs(QuitMessageLoop)); | 235 WillOnce(InvokeWithoutArgs(QuitMessageLoop)); |
| 236 SyncBackendHost::HttpPostProviderFactoryGetter |
| 237 get_http_post_provider_factory = |
| 238 base::Bind(&syncer::NetworkResources::GetHttpPostProviderFactory, |
| 239 base::Unretained(network_resources_.get()), |
| 240 make_scoped_refptr(profile_->GetRequestContext()), |
| 241 base::Bind(&EmptyNetworkTimeUpdate)); |
| 230 backend_->Initialize( | 242 backend_->Initialize( |
| 231 &mock_frontend_, scoped_ptr<base::Thread>(), | 243 &mock_frontend_, scoped_ptr<base::Thread>(), |
| 232 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), | 244 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), |
| 233 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), | 245 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), |
| 234 syncer::WeakHandle<syncer::JsEventHandler>(), GURL(std::string()), | 246 syncer::WeakHandle<syncer::JsEventHandler>(), GURL(std::string()), |
| 235 std::string(), credentials_, true, fake_manager_factory_.Pass(), | 247 std::string(), credentials_, true, fake_manager_factory_.Pass(), |
| 236 MakeWeakHandle(test_unrecoverable_error_handler_.GetWeakPtr()), | 248 MakeWeakHandle(test_unrecoverable_error_handler_.GetWeakPtr()), |
| 237 base::Closure(), network_resources_.get(), saved_nigori_state_.Pass()); | 249 base::Closure(), get_http_post_provider_factory, |
| 250 saved_nigori_state_.Pass()); |
| 238 base::RunLoop run_loop; | 251 base::RunLoop run_loop; |
| 239 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE, | 252 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE, |
| 240 run_loop.QuitClosure(), | 253 run_loop.QuitClosure(), |
| 241 TestTimeouts::action_timeout()); | 254 TestTimeouts::action_timeout()); |
| 242 run_loop.Run(); | 255 run_loop.Run(); |
| 243 // |fake_manager_factory_|'s fake_manager() is set on the sync | 256 // |fake_manager_factory_|'s fake_manager() is set on the sync |
| 244 // thread, but we can rely on the message loop barriers to | 257 // thread, but we can rely on the message loop barriers to |
| 245 // guarantee that we see the updated value. | 258 // guarantee that we see the updated value. |
| 246 DCHECK(fake_manager_); | 259 DCHECK(fake_manager_); |
| 247 } | 260 } |
| (...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 EXPECT_EQ(invalidation_versions.size(), | 895 EXPECT_EQ(invalidation_versions.size(), |
| 883 persisted_invalidation_versions.size()); | 896 persisted_invalidation_versions.size()); |
| 884 for (auto iter : persisted_invalidation_versions) { | 897 for (auto iter : persisted_invalidation_versions) { |
| 885 EXPECT_EQ(invalidation_versions[iter.first], iter.second); | 898 EXPECT_EQ(invalidation_versions[iter.first], iter.second); |
| 886 } | 899 } |
| 887 } | 900 } |
| 888 | 901 |
| 889 } // namespace | 902 } // namespace |
| 890 | 903 |
| 891 } // namespace browser_sync | 904 } // namespace browser_sync |
| OLD | NEW |