| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/browser/background_sync/background_sync_service_impl.h" | 5 #include "content/browser/background_sync/background_sync_service_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/power_monitor/power_monitor.h" | 10 #include "base/power_monitor/power_monitor.h" |
| 11 #include "base/power_monitor/power_monitor_source.h" | 11 #include "base/power_monitor/power_monitor_source.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "content/browser/background_sync/background_sync_context_impl.h" | 13 #include "content/browser/background_sync/background_sync_context_impl.h" |
| 14 #include "content/browser/background_sync/background_sync_network_observer.h" | 14 #include "content/browser/background_sync/background_sync_network_observer.h" |
| 15 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 15 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
| 16 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 16 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/test/background_sync_test_util.h" |
| 18 #include "content/public/test/test_browser_thread_bundle.h" | 19 #include "content/public/test/test_browser_thread_bundle.h" |
| 19 #include "mojo/public/cpp/bindings/interface_ptr.h" | 20 #include "mojo/public/cpp/bindings/interface_ptr.h" |
| 20 #include "net/base/network_change_notifier.h" | 21 #include "net/base/network_change_notifier.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 23 |
| 23 namespace content { | 24 namespace content { |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 const char kServiceWorkerPattern[] = "https://example.com/a"; | 28 const char kServiceWorkerPattern[] = "https://example.com/a"; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 public: | 102 public: |
| 102 BackgroundSyncServiceImplTest() | 103 BackgroundSyncServiceImplTest() |
| 103 : thread_bundle_( | 104 : thread_bundle_( |
| 104 new TestBrowserThreadBundle(TestBrowserThreadBundle::IO_MAINLOOP)), | 105 new TestBrowserThreadBundle(TestBrowserThreadBundle::IO_MAINLOOP)), |
| 105 network_change_notifier_(net::NetworkChangeNotifier::CreateMock()) { | 106 network_change_notifier_(net::NetworkChangeNotifier::CreateMock()) { |
| 106 default_sync_registration_ = SyncRegistration::New(); | 107 default_sync_registration_ = SyncRegistration::New(); |
| 107 } | 108 } |
| 108 | 109 |
| 109 void SetUp() override { | 110 void SetUp() override { |
| 110 // Don't let the tests be confused by the real-world device connectivity | 111 // Don't let the tests be confused by the real-world device connectivity |
| 111 BackgroundSyncNetworkObserver::SetIgnoreNetworkChangeNotifierForTests(true); | 112 background_sync_test_util::SetIgnoreNetworkChangeNotifier(true); |
| 112 | 113 |
| 113 CreateTestHelper(); | 114 CreateTestHelper(); |
| 114 CreateBackgroundSyncContext(); | 115 CreateBackgroundSyncContext(); |
| 115 CreateServiceWorkerRegistration(); | 116 CreateServiceWorkerRegistration(); |
| 116 CreateBackgroundSyncServiceImpl(); | 117 CreateBackgroundSyncServiceImpl(); |
| 117 } | 118 } |
| 118 | 119 |
| 119 void TearDown() override { | 120 void TearDown() override { |
| 120 // This must be explicitly destroyed here to ensure that destruction | 121 // This must be explicitly destroyed here to ensure that destruction |
| 121 // of both the BackgroundSyncContext and the BackgroundSyncManager occurs on | 122 // of both the BackgroundSyncContext and the BackgroundSyncManager occurs on |
| 122 // the correct thread. | 123 // the correct thread. |
| 123 background_sync_context_->Shutdown(); | 124 background_sync_context_->Shutdown(); |
| 124 base::RunLoop().RunUntilIdle(); | 125 base::RunLoop().RunUntilIdle(); |
| 125 background_sync_context_ = nullptr; | 126 background_sync_context_ = nullptr; |
| 126 | 127 |
| 127 // Restore the network observer functionality for subsequent tests | 128 // Restore the network observer functionality for subsequent tests |
| 128 BackgroundSyncNetworkObserver::SetIgnoreNetworkChangeNotifierForTests( | 129 background_sync_test_util::SetIgnoreNetworkChangeNotifier(false); |
| 129 false); | |
| 130 } | 130 } |
| 131 | 131 |
| 132 // SetUp helper methods | 132 // SetUp helper methods |
| 133 void CreateTestHelper() { | 133 void CreateTestHelper() { |
| 134 embedded_worker_helper_.reset( | 134 embedded_worker_helper_.reset( |
| 135 new EmbeddedWorkerTestHelper(base::FilePath())); | 135 new EmbeddedWorkerTestHelper(base::FilePath())); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void CreateBackgroundSyncContext() { | 138 void CreateBackgroundSyncContext() { |
| 139 power_monitor_.reset( | 139 power_monitor_.reset( |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 | 446 |
| 447 NotifyWhenDone(reg->handle_id, | 447 NotifyWhenDone(reg->handle_id, |
| 448 base::Bind(&ErrorAndStateCallback, ¬ify_done_called, | 448 base::Bind(&ErrorAndStateCallback, ¬ify_done_called, |
| 449 ¬ify_done_error, ¬ify_done_sync_state)); | 449 ¬ify_done_error, ¬ify_done_sync_state)); |
| 450 EXPECT_TRUE(notify_done_called); | 450 EXPECT_TRUE(notify_done_called); |
| 451 EXPECT_EQ(BACKGROUND_SYNC_ERROR_NONE, notify_done_error); | 451 EXPECT_EQ(BACKGROUND_SYNC_ERROR_NONE, notify_done_error); |
| 452 EXPECT_EQ(BACKGROUND_SYNC_STATE_UNREGISTERED, notify_done_sync_state); | 452 EXPECT_EQ(BACKGROUND_SYNC_STATE_UNREGISTERED, notify_done_sync_state); |
| 453 } | 453 } |
| 454 | 454 |
| 455 } // namespace content | 455 } // namespace content |
| OLD | NEW |