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

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

Issue 1445603003: Extension SW - add test for ServiceWorkerRegistration.sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move background_sync_test_util to content namespace Created 5 years, 1 month 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/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
11 #include "base/power_monitor/power_monitor.h" 11 #include "base/power_monitor/power_monitor.h"
12 #include "base/power_monitor/power_monitor_source.h" 12 #include "base/power_monitor/power_monitor_source.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
15 #include "base/test/mock_entropy_provider.h" 15 #include "base/test/mock_entropy_provider.h"
16 #include "base/test/simple_test_clock.h" 16 #include "base/test/simple_test_clock.h"
17 #include "base/thread_task_runner_handle.h" 17 #include "base/thread_task_runner_handle.h"
18 #include "content/browser/background_sync/background_sync_network_observer.h" 18 #include "content/browser/background_sync/background_sync_network_observer.h"
19 #include "content/browser/background_sync/background_sync_registration_handle.h" 19 #include "content/browser/background_sync/background_sync_registration_handle.h"
20 #include "content/browser/background_sync/background_sync_status.h" 20 #include "content/browser/background_sync/background_sync_status.h"
21 #include "content/browser/browser_thread_impl.h" 21 #include "content/browser/browser_thread_impl.h"
22 #include "content/browser/service_worker/embedded_worker_test_helper.h" 22 #include "content/browser/service_worker/embedded_worker_test_helper.h"
23 #include "content/browser/service_worker/service_worker_context_core.h" 23 #include "content/browser/service_worker/service_worker_context_core.h"
24 #include "content/browser/service_worker/service_worker_context_wrapper.h" 24 #include "content/browser/service_worker/service_worker_context_wrapper.h"
25 #include "content/browser/service_worker/service_worker_storage.h" 25 #include "content/browser/service_worker/service_worker_storage.h"
26 #include "content/browser/storage_partition_impl.h" 26 #include "content/browser/storage_partition_impl.h"
27 #include "content/public/browser/background_sync_controller.h" 27 #include "content/public/browser/background_sync_controller.h"
28 #include "content/public/test/background_sync_test_util.h"
28 #include "content/public/test/test_browser_context.h" 29 #include "content/public/test/test_browser_context.h"
29 #include "content/public/test/test_browser_thread_bundle.h" 30 #include "content/public/test/test_browser_thread_bundle.h"
30 #include "net/base/network_change_notifier.h" 31 #include "net/base/network_change_notifier.h"
31 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
32 33
33 namespace content { 34 namespace content {
34 35
35 namespace { 36 namespace {
36 37
37 const char kPattern1[] = "https://example.com/a"; 38 const char kPattern1[] = "https://example.com/a";
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 sync_options_1_.power_state = POWER_STATE_AUTO; 283 sync_options_1_.power_state = POWER_STATE_AUTO;
283 284
284 sync_options_2_.tag = "bar"; 285 sync_options_2_.tag = "bar";
285 sync_options_2_.periodicity = SYNC_ONE_SHOT; 286 sync_options_2_.periodicity = SYNC_ONE_SHOT;
286 sync_options_2_.network_state = NETWORK_STATE_ONLINE; 287 sync_options_2_.network_state = NETWORK_STATE_ONLINE;
287 sync_options_2_.power_state = POWER_STATE_AUTO; 288 sync_options_2_.power_state = POWER_STATE_AUTO;
288 } 289 }
289 290
290 void SetUp() override { 291 void SetUp() override {
291 // Don't let the tests be confused by the real-world device connectivity 292 // Don't let the tests be confused by the real-world device connectivity
292 BackgroundSyncNetworkObserver::SetIgnoreNetworkChangeNotifierForTests(true); 293 background_sync_test_util::SetIgnoreNetworkChangeNotifier(true);
293 294
294 // TODO(jkarlin): Create a new object with all of the necessary SW calls 295 // TODO(jkarlin): Create a new object with all of the necessary SW calls
295 // so that we can inject test versions instead of bringing up all of this 296 // so that we can inject test versions instead of bringing up all of this
296 // extra SW stuff. 297 // extra SW stuff.
297 helper_.reset(new EmbeddedWorkerTestHelper(base::FilePath())); 298 helper_.reset(new EmbeddedWorkerTestHelper(base::FilePath()));
298 299
299 // Create a StoragePartition with the correct BrowserContext so that the 300 // Create a StoragePartition with the correct BrowserContext so that the
300 // BackgroundSyncManager can find the BrowserContext through it. 301 // BackgroundSyncManager can find the BrowserContext through it.
301 storage_partition_impl_.reset(new StoragePartitionImpl( 302 storage_partition_impl_.reset(new StoragePartitionImpl(
302 helper_->browser_context(), base::FilePath(), nullptr, nullptr, nullptr, 303 helper_->browser_context(), base::FilePath(), nullptr, nullptr, nullptr,
(...skipping 18 matching lines...) Expand all
321 background_sync_controller.Pass()); 322 background_sync_controller.Pass());
322 323
323 // Wait for storage to finish initializing before registering service 324 // Wait for storage to finish initializing before registering service
324 // workers. 325 // workers.
325 base::RunLoop().RunUntilIdle(); 326 base::RunLoop().RunUntilIdle();
326 RegisterServiceWorkers(); 327 RegisterServiceWorkers();
327 } 328 }
328 329
329 void TearDown() override { 330 void TearDown() override {
330 // Restore the network observer functionality for subsequent tests 331 // Restore the network observer functionality for subsequent tests
331 BackgroundSyncNetworkObserver::SetIgnoreNetworkChangeNotifierForTests( 332 background_sync_test_util::SetIgnoreNetworkChangeNotifier(false);
332 false);
333 } 333 }
334 334
335 void RegisterServiceWorkers() { 335 void RegisterServiceWorkers() {
336 bool called_1 = false; 336 bool called_1 = false;
337 bool called_2 = false; 337 bool called_2 = false;
338 helper_->context()->RegisterServiceWorker( 338 helper_->context()->RegisterServiceWorker(
339 GURL(kPattern1), GURL(kScript1), NULL, 339 GURL(kPattern1), GURL(kScript1), NULL,
340 base::Bind(&RegisterServiceWorkerCallback, &called_1, 340 base::Bind(&RegisterServiceWorkerCallback, &called_1,
341 &sw_registration_id_1_)); 341 &sw_registration_id_1_));
342 342
(...skipping 1636 matching lines...) Expand 10 before | Expand all | Expand 10 after
1979 // Run it again. 1979 // Run it again.
1980 test_clock_->Advance(test_background_sync_manager_->delayed_task_delta()); 1980 test_clock_->Advance(test_background_sync_manager_->delayed_task_delta());
1981 test_background_sync_manager_->delayed_task().Run(); 1981 test_background_sync_manager_->delayed_task().Run();
1982 base::RunLoop().RunUntilIdle(); 1982 base::RunLoop().RunUntilIdle();
1983 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1983 EXPECT_FALSE(GetRegistration(sync_options_1_));
1984 EXPECT_EQ(BACKGROUND_SYNC_EVENT_LAST_CHANCE_IS_LAST_CHANCE, 1984 EXPECT_EQ(BACKGROUND_SYNC_EVENT_LAST_CHANCE_IS_LAST_CHANCE,
1985 test_background_sync_manager_->last_chance()); 1985 test_background_sync_manager_->last_chance());
1986 } 1986 }
1987 1987
1988 } // namespace content 1988 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698