| Index: content/browser/service_worker/service_worker_job_unittest.cc
|
| diff --git a/content/browser/service_worker/service_worker_storage_unittest.cc b/content/browser/service_worker/service_worker_job_unittest.cc
|
| similarity index 83%
|
| copy from content/browser/service_worker/service_worker_storage_unittest.cc
|
| copy to content/browser/service_worker/service_worker_job_unittest.cc
|
| index bd6d629eb80a16b124ce0d5aa064e0bb14d6b5e7..08966a6073e69762ddaa88e7e2ccd56ae8f9d665 100644
|
| --- a/content/browser/service_worker/service_worker_storage_unittest.cc
|
| +++ b/content/browser/service_worker/service_worker_job_unittest.cc
|
| @@ -2,16 +2,17 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "content/browser/service_worker/service_worker_storage.h"
|
| -
|
| #include "base/files/scoped_temp_dir.h"
|
| #include "base/logging.h"
|
| #include "base/run_loop.h"
|
| #include "content/browser/browser_thread_impl.h"
|
| +#include "content/browser/service_worker/service_worker_job_coordinator.h"
|
| #include "content/browser/service_worker/service_worker_registration.h"
|
| +#include "content/browser/service_worker/service_worker_registration_status.h"
|
| #include "content/public/test/test_browser_thread_bundle.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| +// Unit tests for testing all job registration tasks.
|
| namespace content {
|
|
|
| namespace {
|
| @@ -46,7 +47,7 @@ void SaveFoundRegistrationCallback(
|
| // it ensures that the resulting status matches the expectation.
|
| // 'called' is useful for making sure a sychronous callback is or
|
| // isn't called.
|
| -ServiceWorkerStorage::RegistrationCallback SaveRegistration(
|
| +ServiceWorkerJobCoordinator::RegistrationCallback SaveRegistration(
|
| ServiceWorkerRegistrationStatus expected_status,
|
| bool* called,
|
| scoped_refptr<ServiceWorkerRegistration>* registration) {
|
| @@ -75,7 +76,7 @@ void SaveUnregistrationCallback(ServiceWorkerRegistrationStatus expected_status,
|
| *called = true;
|
| }
|
|
|
| -ServiceWorkerStorage::UnregistrationCallback SaveUnregistration(
|
| +ServiceWorkerJobCoordinator::UnregistrationCallback SaveUnregistration(
|
| ServiceWorkerRegistrationStatus expected_status,
|
| bool* called) {
|
| *called = false;
|
| @@ -84,13 +85,15 @@ ServiceWorkerStorage::UnregistrationCallback SaveUnregistration(
|
|
|
| } // namespace
|
|
|
| -class ServiceWorkerStorageTest : public testing::Test {
|
| +class ServiceWorkerJobTest : public testing::Test {
|
| public:
|
| - ServiceWorkerStorageTest()
|
| + ServiceWorkerJobTest()
|
| : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {}
|
|
|
| virtual void SetUp() OVERRIDE {
|
| storage_.reset(new ServiceWorkerStorage(base::FilePath(), NULL));
|
| + job_coordinator_.reset(
|
| + new ServiceWorkerJobCoordinator(storage_->AsWeakPtr()));
|
| }
|
|
|
| virtual void TearDown() OVERRIDE { storage_.reset(); }
|
| @@ -98,31 +101,13 @@ class ServiceWorkerStorageTest : public testing::Test {
|
| protected:
|
| TestBrowserThreadBundle browser_thread_bundle_;
|
| scoped_ptr<ServiceWorkerStorage> storage_;
|
| + scoped_ptr<ServiceWorkerJobCoordinator> job_coordinator_;
|
| };
|
|
|
| -TEST_F(ServiceWorkerStorageTest, PatternMatches) {
|
| - ASSERT_TRUE(ServiceWorkerStorage::PatternMatches(
|
| - GURL("http://www.example.com/*"), GURL("http://www.example.com/")));
|
| - ASSERT_TRUE(ServiceWorkerStorage::PatternMatches(
|
| - GURL("http://www.example.com/*"),
|
| - GURL("http://www.example.com/page.html")));
|
| -
|
| - ASSERT_FALSE(ServiceWorkerStorage::PatternMatches(
|
| - GURL("http://www.example.com/*"), GURL("https://www.example.com/")));
|
| - ASSERT_FALSE(ServiceWorkerStorage::PatternMatches(
|
| - GURL("http://www.example.com/*"),
|
| - GURL("https://www.example.com/page.html")));
|
| -
|
| - ASSERT_FALSE(ServiceWorkerStorage::PatternMatches(
|
| - GURL("http://www.example.com/*"), GURL("http://www.foo.com/")));
|
| - ASSERT_FALSE(ServiceWorkerStorage::PatternMatches(
|
| - GURL("http://www.example.com/*"), GURL("https://www.foo.com/page.html")));
|
| -}
|
| -
|
| -TEST_F(ServiceWorkerStorageTest, SameDocumentSameRegistration) {
|
| +TEST_F(ServiceWorkerJobTest, SameDocumentSameRegistration) {
|
| scoped_refptr<ServiceWorkerRegistration> original_registration;
|
| bool called;
|
| - storage_->Register(
|
| + job_coordinator_->Register(
|
| GURL("http://www.example.com/*"),
|
| GURL("http://www.example.com/service_worker.js"),
|
| SaveRegistration(REGISTRATION_OK, &called, &original_registration));
|
| @@ -151,10 +136,10 @@ TEST_F(ServiceWorkerStorageTest, SameDocumentSameRegistration) {
|
| ASSERT_EQ(registration1, registration2);
|
| }
|
|
|
| -TEST_F(ServiceWorkerStorageTest, SameMatchSameRegistration) {
|
| +TEST_F(ServiceWorkerJobTest, SameMatchSameRegistration) {
|
| bool called;
|
| scoped_refptr<ServiceWorkerRegistration> original_registration;
|
| - storage_->Register(
|
| + job_coordinator_->Register(
|
| GURL("http://www.example.com/*"),
|
| GURL("http://www.example.com/service_worker.js"),
|
| SaveRegistration(REGISTRATION_OK, &called, &original_registration));
|
| @@ -184,17 +169,17 @@ TEST_F(ServiceWorkerStorageTest, SameMatchSameRegistration) {
|
| ASSERT_EQ(registration1, registration2);
|
| }
|
|
|
| -TEST_F(ServiceWorkerStorageTest, DifferentMatchDifferentRegistration) {
|
| +TEST_F(ServiceWorkerJobTest, DifferentMatchDifferentRegistration) {
|
| bool called1;
|
| scoped_refptr<ServiceWorkerRegistration> original_registration1;
|
| - storage_->Register(
|
| + job_coordinator_->Register(
|
| GURL("http://www.example.com/one/*"),
|
| GURL("http://www.example.com/service_worker.js"),
|
| SaveRegistration(REGISTRATION_OK, &called1, &original_registration1));
|
|
|
| bool called2;
|
| scoped_refptr<ServiceWorkerRegistration> original_registration2;
|
| - storage_->Register(
|
| + job_coordinator_->Register(
|
| GURL("http://www.example.com/two/*"),
|
| GURL("http://www.example.com/service_worker.js"),
|
| SaveRegistration(REGISTRATION_OK, &called2, &original_registration2));
|
| @@ -224,12 +209,13 @@ TEST_F(ServiceWorkerStorageTest, DifferentMatchDifferentRegistration) {
|
| }
|
|
|
| // Make sure basic registration is working.
|
| -TEST_F(ServiceWorkerStorageTest, Register) {
|
| +TEST_F(ServiceWorkerJobTest, Register) {
|
| bool called = false;
|
| scoped_refptr<ServiceWorkerRegistration> registration;
|
| - storage_->Register(GURL("http://www.example.com/*"),
|
| - GURL("http://www.example.com/service_worker.js"),
|
| - SaveRegistration(REGISTRATION_OK, &called, ®istration));
|
| + job_coordinator_->Register(
|
| + GURL("http://www.example.com/*"),
|
| + GURL("http://www.example.com/service_worker.js"),
|
| + SaveRegistration(REGISTRATION_OK, &called, ®istration));
|
|
|
| ASSERT_FALSE(called);
|
| base::RunLoop().RunUntilIdle();
|
| @@ -239,20 +225,22 @@ TEST_F(ServiceWorkerStorageTest, Register) {
|
| }
|
|
|
| // Make sure registrations are cleaned up when they are unregistered.
|
| -TEST_F(ServiceWorkerStorageTest, Unregister) {
|
| +TEST_F(ServiceWorkerJobTest, Unregister) {
|
| GURL pattern("http://www.example.com/*");
|
|
|
| bool called;
|
| scoped_refptr<ServiceWorkerRegistration> registration;
|
| - storage_->Register(pattern,
|
| - GURL("http://www.example.com/service_worker.js"),
|
| - SaveRegistration(REGISTRATION_OK, &called, ®istration));
|
| + job_coordinator_->Register(
|
| + pattern,
|
| + GURL("http://www.example.com/service_worker.js"),
|
| + SaveRegistration(REGISTRATION_OK, &called, ®istration));
|
|
|
| ASSERT_FALSE(called);
|
| base::RunLoop().RunUntilIdle();
|
| ASSERT_TRUE(called);
|
|
|
| - storage_->Unregister(pattern, SaveUnregistration(REGISTRATION_OK, &called));
|
| + job_coordinator_->Unregister(pattern,
|
| + SaveUnregistration(REGISTRATION_OK, &called));
|
|
|
| ASSERT_FALSE(called);
|
| base::RunLoop().RunUntilIdle();
|
| @@ -273,12 +261,12 @@ TEST_F(ServiceWorkerStorageTest, Unregister) {
|
|
|
| // Make sure that when a new registration replaces an existing
|
| // registration, that the old one is cleaned up.
|
| -TEST_F(ServiceWorkerStorageTest, RegisterNewScript) {
|
| +TEST_F(ServiceWorkerJobTest, RegisterNewScript) {
|
| GURL pattern("http://www.example.com/*");
|
|
|
| bool called;
|
| scoped_refptr<ServiceWorkerRegistration> old_registration;
|
| - storage_->Register(
|
| + job_coordinator_->Register(
|
| pattern,
|
| GURL("http://www.example.com/service_worker.js"),
|
| SaveRegistration(REGISTRATION_OK, &called, &old_registration));
|
| @@ -301,7 +289,7 @@ TEST_F(ServiceWorkerStorageTest, RegisterNewScript) {
|
| old_registration_by_pattern = NULL;
|
|
|
| scoped_refptr<ServiceWorkerRegistration> new_registration;
|
| - storage_->Register(
|
| + job_coordinator_->Register(
|
| pattern,
|
| GURL("http://www.example.com/service_worker_new.js"),
|
| SaveRegistration(REGISTRATION_OK, &called, &new_registration));
|
| @@ -328,13 +316,13 @@ TEST_F(ServiceWorkerStorageTest, RegisterNewScript) {
|
|
|
| // Make sure that when registering a duplicate pattern+script_url
|
| // combination, that the same registration is used.
|
| -TEST_F(ServiceWorkerStorageTest, RegisterDuplicateScript) {
|
| +TEST_F(ServiceWorkerJobTest, RegisterDuplicateScript) {
|
| GURL pattern("http://www.example.com/*");
|
| GURL script_url("http://www.example.com/service_worker.js");
|
|
|
| bool called;
|
| scoped_refptr<ServiceWorkerRegistration> old_registration;
|
| - storage_->Register(
|
| + job_coordinator_->Register(
|
| pattern,
|
| script_url,
|
| SaveRegistration(REGISTRATION_OK, &called, &old_registration));
|
| @@ -355,7 +343,7 @@ TEST_F(ServiceWorkerStorageTest, RegisterDuplicateScript) {
|
| ASSERT_TRUE(old_registration_by_pattern);
|
|
|
| scoped_refptr<ServiceWorkerRegistration> new_registration;
|
| - storage_->Register(
|
| + job_coordinator_->Register(
|
| pattern,
|
| script_url,
|
| SaveRegistration(REGISTRATION_OK, &called, &new_registration));
|
|
|