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_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/metrics/field_trial.h" |
10 #include "base/power_monitor/power_monitor.h" | 11 #include "base/power_monitor/power_monitor.h" |
11 #include "base/power_monitor/power_monitor_source.h" | 12 #include "base/power_monitor/power_monitor_source.h" |
12 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
13 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 15 #include "base/test/mock_entropy_provider.h" |
14 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
15 #include "content/browser/background_sync/background_sync_registration_handle.h" | 17 #include "content/browser/background_sync/background_sync_registration_handle.h" |
16 #include "content/browser/background_sync/background_sync_status.h" | 18 #include "content/browser/background_sync/background_sync_status.h" |
17 #include "content/browser/browser_thread_impl.h" | 19 #include "content/browser/browser_thread_impl.h" |
18 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 20 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
19 #include "content/browser/service_worker/service_worker_context_core.h" | 21 #include "content/browser/service_worker/service_worker_context_core.h" |
20 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 22 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
21 #include "content/browser/service_worker/service_worker_storage.h" | 23 #include "content/browser/service_worker/service_worker_storage.h" |
22 #include "content/public/test/test_browser_thread_bundle.h" | 24 #include "content/public/test/test_browser_thread_bundle.h" |
23 #include "net/base/network_change_notifier.h" | 25 #include "net/base/network_change_notifier.h" |
(...skipping 1484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1508 sync_options_1_)); | 1510 sync_options_1_)); |
1509 } | 1511 } |
1510 | 1512 |
1511 TEST_F(BackgroundSyncManagerTest, UnregisterSucceedsWithoutWindow) { | 1513 TEST_F(BackgroundSyncManagerTest, UnregisterSucceedsWithoutWindow) { |
1512 EXPECT_TRUE(Register(sync_options_1_)); | 1514 EXPECT_TRUE(Register(sync_options_1_)); |
1513 RemoveWindowClients(); | 1515 RemoveWindowClients(); |
1514 EXPECT_TRUE(Unregister(callback_registration_handle_.get())); | 1516 EXPECT_TRUE(Unregister(callback_registration_handle_.get())); |
1515 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 1517 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
1516 } | 1518 } |
1517 | 1519 |
| 1520 TEST_F(BackgroundSyncManagerTest, FieldTrialDisablesManager) { |
| 1521 EXPECT_TRUE(Register(sync_options_1_)); |
| 1522 |
| 1523 base::FieldTrialList field_trial_list(new base::MockEntropyProvider()); |
| 1524 base::FieldTrialList::CreateFieldTrial("BackgroundSync", |
| 1525 "ExperimentDisabled"); |
| 1526 |
| 1527 EXPECT_FALSE(Register(sync_options_2_)); |
| 1528 EXPECT_EQ(BACKGROUND_SYNC_STATUS_STORAGE_ERROR, callback_status_); |
| 1529 |
| 1530 // If the service worker is wiped and the manager is restarted, the manager |
| 1531 // should disable itself on init. |
| 1532 test_background_sync_manager_->set_corrupt_backend(false); |
| 1533 helper_->context()->ScheduleDeleteAndStartOver(); |
| 1534 base::RunLoop().RunUntilIdle(); |
| 1535 |
| 1536 RegisterServiceWorkers(); |
| 1537 |
| 1538 EXPECT_FALSE(GetRegistrations(SYNC_ONE_SHOT)); |
| 1539 EXPECT_EQ(BACKGROUND_SYNC_STATUS_STORAGE_ERROR, callback_status_); |
| 1540 } |
| 1541 |
1518 } // namespace content | 1542 } // namespace content |
OLD | NEW |