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

Side by Side Diff: content/browser/background_sync/background_sync_manager_unittest.cc

Issue 1376563003: Revert of [BackgroundSync] Trigger Background Sync events when Chrome is backgrounded on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
OLDNEW
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_manager.h" 5 #include "content/browser/background_sync/background_sync_manager.h"
6 6
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/logging.h" 9 #include "base/logging.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 "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
14 #include "base/thread_task_runner_handle.h" 14 #include "base/thread_task_runner_handle.h"
15 #include "content/browser/background_sync/background_sync_network_observer.h"
16 #include "content/browser/background_sync/background_sync_registration_handle.h" 15 #include "content/browser/background_sync/background_sync_registration_handle.h"
17 #include "content/browser/background_sync/background_sync_status.h" 16 #include "content/browser/background_sync/background_sync_status.h"
18 #include "content/browser/browser_thread_impl.h" 17 #include "content/browser/browser_thread_impl.h"
19 #include "content/browser/service_worker/embedded_worker_test_helper.h" 18 #include "content/browser/service_worker/embedded_worker_test_helper.h"
20 #include "content/browser/service_worker/service_worker_context_core.h" 19 #include "content/browser/service_worker/service_worker_context_core.h"
21 #include "content/browser/service_worker/service_worker_context_wrapper.h" 20 #include "content/browser/service_worker/service_worker_context_wrapper.h"
22 #include "content/browser/service_worker/service_worker_storage.h" 21 #include "content/browser/service_worker/service_worker_storage.h"
23 #include "content/public/test/test_browser_thread_bundle.h" 22 #include "content/public/test/test_browser_thread_bundle.h"
24 #include "net/base/network_change_notifier.h" 23 #include "net/base/network_change_notifier.h"
25 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 sync_options_1_.network_state = NETWORK_STATE_ONLINE; 224 sync_options_1_.network_state = NETWORK_STATE_ONLINE;
226 sync_options_1_.power_state = POWER_STATE_AUTO; 225 sync_options_1_.power_state = POWER_STATE_AUTO;
227 226
228 sync_options_2_.tag = "bar"; 227 sync_options_2_.tag = "bar";
229 sync_options_2_.periodicity = SYNC_ONE_SHOT; 228 sync_options_2_.periodicity = SYNC_ONE_SHOT;
230 sync_options_2_.network_state = NETWORK_STATE_ONLINE; 229 sync_options_2_.network_state = NETWORK_STATE_ONLINE;
231 sync_options_2_.power_state = POWER_STATE_AUTO; 230 sync_options_2_.power_state = POWER_STATE_AUTO;
232 } 231 }
233 232
234 void SetUp() override { 233 void SetUp() override {
235 // Don't let the tests be confused by the real-world device connectivity
236 BackgroundSyncNetworkObserver::SetIgnoreNetworkChangeNotifierForTests(true);
237
238 helper_.reset( 234 helper_.reset(
239 new EmbeddedWorkerTestHelper(base::FilePath(), kRenderProcessId)); 235 new EmbeddedWorkerTestHelper(base::FilePath(), kRenderProcessId));
240 236
241 power_monitor_source_ = new TestPowerSource(); 237 power_monitor_source_ = new TestPowerSource();
242 // power_monitor_ takes ownership of power_monitor_source. 238 // power_monitor_ takes ownership of power_monitor_source.
243 power_monitor_.reset(new base::PowerMonitor( 239 power_monitor_.reset(new base::PowerMonitor(
244 scoped_ptr<base::PowerMonitorSource>(power_monitor_source_))); 240 scoped_ptr<base::PowerMonitorSource>(power_monitor_source_)));
245 241
246 SetOnBatteryPower(false); 242 SetOnBatteryPower(false);
247 243
248 SetupBackgroundSyncManager(); 244 SetupBackgroundSyncManager();
249 245
250 // Wait for storage to finish initializing before registering service 246 // Wait for storage to finish initializing before registering service
251 // workers. 247 // workers.
252 base::RunLoop().RunUntilIdle(); 248 base::RunLoop().RunUntilIdle();
253 RegisterServiceWorkers(); 249 RegisterServiceWorkers();
254 } 250 }
255 251
256 void TearDown() override {
257 // Restore the network observer functionality for subsequent tests
258 BackgroundSyncNetworkObserver::SetIgnoreNetworkChangeNotifierForTests(
259 false);
260 }
261
262 void RegisterServiceWorkers() { 252 void RegisterServiceWorkers() {
263 bool called_1 = false; 253 bool called_1 = false;
264 bool called_2 = false; 254 bool called_2 = false;
265 helper_->context()->RegisterServiceWorker( 255 helper_->context()->RegisterServiceWorker(
266 GURL(kPattern1), GURL(kScript1), NULL, 256 GURL(kPattern1), GURL(kScript1), NULL,
267 base::Bind(&RegisterServiceWorkerCallback, &called_1, 257 base::Bind(&RegisterServiceWorkerCallback, &called_1,
268 &sw_registration_id_1_)); 258 &sw_registration_id_1_));
269 259
270 helper_->context()->RegisterServiceWorker( 260 helper_->context()->RegisterServiceWorker(
271 GURL(kPattern2), GURL(kScript2), NULL, 261 GURL(kPattern2), GURL(kScript2), NULL,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 } 295 }
306 296
307 void RemoveWindowClients() { 297 void RemoveWindowClients() {
308 sw_registration_1_->active_version()->RemoveControllee(host_1_.get()); 298 sw_registration_1_->active_version()->RemoveControllee(host_1_.get());
309 sw_registration_2_->active_version()->RemoveControllee(host_2_.get()); 299 sw_registration_2_->active_version()->RemoveControllee(host_2_.get());
310 } 300 }
311 301
312 void SetNetwork(net::NetworkChangeNotifier::ConnectionType connection_type) { 302 void SetNetwork(net::NetworkChangeNotifier::ConnectionType connection_type) {
313 net::NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests( 303 net::NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests(
314 connection_type); 304 connection_type);
315 if (test_background_sync_manager_) { 305 base::RunLoop().RunUntilIdle();
316 BackgroundSyncNetworkObserver* network_observer =
317 test_background_sync_manager_->GetNetworkObserverForTesting();
318 network_observer->NotifyManagerIfNetworkChanged(connection_type);
319 base::RunLoop().RunUntilIdle();
320 }
321 } 306 }
322 307
323 void SetOnBatteryPower(bool on_battery_power) { 308 void SetOnBatteryPower(bool on_battery_power) {
324 power_monitor_source_->GeneratePowerStateEvent(on_battery_power); 309 power_monitor_source_->GeneratePowerStateEvent(on_battery_power);
325 base::RunLoop().RunUntilIdle(); 310 base::RunLoop().RunUntilIdle();
326 } 311 }
327 312
328 void StatusAndRegistrationCallback( 313 void StatusAndRegistrationCallback(
329 bool* was_called, 314 bool* was_called,
330 BackgroundSyncStatus status, 315 BackgroundSyncStatus status,
(...skipping 1291 matching lines...) Expand 10 before | Expand all | Expand 10 after
1622 } 1607 }
1623 1608
1624 TEST_F(BackgroundSyncManagerTest, UnregisterSucceedsWithoutWindow) { 1609 TEST_F(BackgroundSyncManagerTest, UnregisterSucceedsWithoutWindow) {
1625 EXPECT_TRUE(Register(sync_options_1_)); 1610 EXPECT_TRUE(Register(sync_options_1_));
1626 RemoveWindowClients(); 1611 RemoveWindowClients();
1627 EXPECT_TRUE(Unregister(callback_registration_handle_.get())); 1612 EXPECT_TRUE(Unregister(callback_registration_handle_.get()));
1628 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1613 EXPECT_FALSE(GetRegistration(sync_options_1_));
1629 } 1614 }
1630 1615
1631 } // namespace content 1616 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698