| Index: content/browser/service_worker/service_worker_job_unittest.cc
|
| diff --git a/content/browser/service_worker/service_worker_job_unittest.cc b/content/browser/service_worker/service_worker_job_unittest.cc
|
| index 24656a64e8751b102e60c4dacc5aaee0a94fbdd3..a458affba8bdeee2fbc49e1c0734e0fae6f9022c 100644
|
| --- a/content/browser/service_worker/service_worker_job_unittest.cc
|
| +++ b/content/browser/service_worker/service_worker_job_unittest.cc
|
| @@ -6,14 +6,10 @@
|
| #include "base/logging.h"
|
| #include "base/run_loop.h"
|
| #include "content/browser/browser_thread_impl.h"
|
| -#include "content/browser/service_worker/embedded_worker_registry.h"
|
| -#include "content/browser/service_worker/embedded_worker_test_helper.h"
|
| -#include "content/browser/service_worker/service_worker_context_core.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 "ipc/ipc_test_sink.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| // Unit tests for testing all job registration tasks.
|
| @@ -92,57 +88,38 @@
|
| class ServiceWorkerJobTest : public testing::Test {
|
| public:
|
| ServiceWorkerJobTest()
|
| - : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP),
|
| - render_process_id_(-1) {}
|
| + : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {}
|
|
|
| virtual void SetUp() OVERRIDE {
|
| - context_.reset(new ServiceWorkerContextCore(base::FilePath(), NULL));
|
| - helper_.reset(new EmbeddedWorkerTestHelper(context_.get()));
|
| -
|
| - scoped_ptr<EmbeddedWorkerInstance> worker =
|
| - context_->embedded_worker_registry()->CreateWorker();
|
| -
|
| - render_process_id_ = 88;
|
| - int embedded_worker_id = worker->embedded_worker_id();
|
| - helper_->SimulateAddProcess(embedded_worker_id, render_process_id_);
|
| + storage_.reset(new ServiceWorkerStorage(base::FilePath(), NULL));
|
| + job_coordinator_.reset(new ServiceWorkerJobCoordinator(storage_.get()));
|
| }
|
|
|
| - virtual void TearDown() OVERRIDE {
|
| - helper_.reset();
|
| - context_.reset();
|
| - }
|
| -
|
| - ServiceWorkerJobCoordinator* job_coordinator() const {
|
| - return context_->job_coordinator();
|
| - }
|
| - ServiceWorkerStorage* storage() const { return context_->storage(); }
|
| + virtual void TearDown() OVERRIDE { storage_.reset(); }
|
|
|
| protected:
|
| TestBrowserThreadBundle browser_thread_bundle_;
|
| - scoped_ptr<ServiceWorkerContextCore> context_;
|
| - scoped_ptr<EmbeddedWorkerTestHelper> helper_;
|
| -
|
| - int render_process_id_;
|
| + scoped_ptr<ServiceWorkerStorage> storage_;
|
| + scoped_ptr<ServiceWorkerJobCoordinator> job_coordinator_;
|
| };
|
|
|
| TEST_F(ServiceWorkerJobTest, SameDocumentSameRegistration) {
|
| scoped_refptr<ServiceWorkerRegistration> original_registration;
|
| bool called;
|
| - job_coordinator()->Register(
|
| + job_coordinator_->Register(
|
| GURL("http://www.example.com/*"),
|
| GURL("http://www.example.com/service_worker.js"),
|
| - render_process_id_,
|
| SaveRegistration(SERVICE_WORKER_OK, &called, &original_registration));
|
| EXPECT_FALSE(called);
|
| base::RunLoop().RunUntilIdle();
|
| EXPECT_TRUE(called);
|
|
|
| scoped_refptr<ServiceWorkerRegistration> registration1;
|
| - storage()->FindRegistrationForDocument(
|
| + storage_->FindRegistrationForDocument(
|
| GURL("http://www.example.com/"),
|
| SaveFoundRegistration(true, SERVICE_WORKER_OK, &called, ®istration1));
|
| scoped_refptr<ServiceWorkerRegistration> registration2;
|
| - storage()->FindRegistrationForDocument(
|
| + storage_->FindRegistrationForDocument(
|
| GURL("http://www.example.com/"),
|
| SaveFoundRegistration(true, SERVICE_WORKER_OK, &called, ®istration2));
|
|
|
| @@ -161,10 +138,9 @@
|
| TEST_F(ServiceWorkerJobTest, SameMatchSameRegistration) {
|
| bool called;
|
| scoped_refptr<ServiceWorkerRegistration> original_registration;
|
| - job_coordinator()->Register(
|
| + job_coordinator_->Register(
|
| GURL("http://www.example.com/*"),
|
| GURL("http://www.example.com/service_worker.js"),
|
| - render_process_id_,
|
| SaveRegistration(SERVICE_WORKER_OK, &called, &original_registration));
|
| EXPECT_FALSE(called);
|
| base::RunLoop().RunUntilIdle();
|
| @@ -173,7 +149,7 @@
|
| original_registration.get());
|
|
|
| scoped_refptr<ServiceWorkerRegistration> registration1;
|
| - storage()->FindRegistrationForDocument(
|
| + storage_->FindRegistrationForDocument(
|
| GURL("http://www.example.com/one"),
|
| SaveFoundRegistration(true, SERVICE_WORKER_OK, &called, ®istration1));
|
|
|
| @@ -182,7 +158,7 @@
|
| EXPECT_TRUE(called);
|
|
|
| scoped_refptr<ServiceWorkerRegistration> registration2;
|
| - storage()->FindRegistrationForDocument(
|
| + storage_->FindRegistrationForDocument(
|
| GURL("http://www.example.com/two"),
|
| SaveFoundRegistration(true, SERVICE_WORKER_OK, &called, ®istration2));
|
| EXPECT_FALSE(called);
|
| @@ -195,18 +171,16 @@
|
| TEST_F(ServiceWorkerJobTest, DifferentMatchDifferentRegistration) {
|
| bool called1;
|
| scoped_refptr<ServiceWorkerRegistration> original_registration1;
|
| - job_coordinator()->Register(
|
| + job_coordinator_->Register(
|
| GURL("http://www.example.com/one/*"),
|
| GURL("http://www.example.com/service_worker.js"),
|
| - render_process_id_,
|
| SaveRegistration(SERVICE_WORKER_OK, &called1, &original_registration1));
|
|
|
| bool called2;
|
| scoped_refptr<ServiceWorkerRegistration> original_registration2;
|
| - job_coordinator()->Register(
|
| + job_coordinator_->Register(
|
| GURL("http://www.example.com/two/*"),
|
| GURL("http://www.example.com/service_worker.js"),
|
| - render_process_id_,
|
| SaveRegistration(SERVICE_WORKER_OK, &called2, &original_registration2));
|
|
|
| EXPECT_FALSE(called1);
|
| @@ -216,11 +190,11 @@
|
| EXPECT_TRUE(called1);
|
|
|
| scoped_refptr<ServiceWorkerRegistration> registration1;
|
| - storage()->FindRegistrationForDocument(
|
| + storage_->FindRegistrationForDocument(
|
| GURL("http://www.example.com/one/"),
|
| SaveFoundRegistration(true, SERVICE_WORKER_OK, &called1, ®istration1));
|
| scoped_refptr<ServiceWorkerRegistration> registration2;
|
| - storage()->FindRegistrationForDocument(
|
| + storage_->FindRegistrationForDocument(
|
| GURL("http://www.example.com/two/"),
|
| SaveFoundRegistration(true, SERVICE_WORKER_OK, &called2, ®istration2));
|
|
|
| @@ -237,10 +211,9 @@
|
| TEST_F(ServiceWorkerJobTest, Register) {
|
| bool called = false;
|
| scoped_refptr<ServiceWorkerRegistration> registration;
|
| - job_coordinator()->Register(
|
| + job_coordinator_->Register(
|
| GURL("http://www.example.com/*"),
|
| GURL("http://www.example.com/service_worker.js"),
|
| - render_process_id_,
|
| SaveRegistration(SERVICE_WORKER_OK, &called, ®istration));
|
|
|
| ASSERT_FALSE(called);
|
| @@ -256,19 +229,17 @@
|
|
|
| bool called;
|
| scoped_refptr<ServiceWorkerRegistration> registration;
|
| - job_coordinator()->Register(
|
| - pattern,
|
| - GURL("http://www.example.com/service_worker.js"),
|
| - render_process_id_,
|
| + job_coordinator_->Register(
|
| + pattern,
|
| + GURL("http://www.example.com/service_worker.js"),
|
| SaveRegistration(SERVICE_WORKER_OK, &called, ®istration));
|
|
|
| ASSERT_FALSE(called);
|
| base::RunLoop().RunUntilIdle();
|
| ASSERT_TRUE(called);
|
|
|
| - job_coordinator()->Unregister(pattern,
|
| - render_process_id_,
|
| - SaveUnregistration(SERVICE_WORKER_OK, &called));
|
| + job_coordinator_->Unregister(pattern,
|
| + SaveUnregistration(SERVICE_WORKER_OK, &called));
|
|
|
| ASSERT_FALSE(called);
|
| base::RunLoop().RunUntilIdle();
|
| @@ -276,7 +247,7 @@
|
|
|
| ASSERT_TRUE(registration->HasOneRef());
|
|
|
| - storage()->FindRegistrationForPattern(
|
| + storage_->FindRegistrationForPattern(
|
| pattern,
|
| SaveFoundRegistration(false, SERVICE_WORKER_OK, &called, ®istration));
|
|
|
| @@ -294,10 +265,9 @@
|
|
|
| bool called;
|
| scoped_refptr<ServiceWorkerRegistration> old_registration;
|
| - job_coordinator()->Register(
|
| - pattern,
|
| - GURL("http://www.example.com/service_worker.js"),
|
| - render_process_id_,
|
| + job_coordinator_->Register(
|
| + pattern,
|
| + GURL("http://www.example.com/service_worker.js"),
|
| SaveRegistration(SERVICE_WORKER_OK, &called, &old_registration));
|
|
|
| ASSERT_FALSE(called);
|
| @@ -305,7 +275,7 @@
|
| ASSERT_TRUE(called);
|
|
|
| scoped_refptr<ServiceWorkerRegistration> old_registration_by_pattern;
|
| - storage()->FindRegistrationForPattern(
|
| + storage_->FindRegistrationForPattern(
|
| pattern,
|
| SaveFoundRegistration(
|
| true, SERVICE_WORKER_OK, &called, &old_registration_by_pattern));
|
| @@ -318,10 +288,9 @@
|
| old_registration_by_pattern = NULL;
|
|
|
| scoped_refptr<ServiceWorkerRegistration> new_registration;
|
| - job_coordinator()->Register(
|
| + job_coordinator_->Register(
|
| pattern,
|
| GURL("http://www.example.com/service_worker_new.js"),
|
| - render_process_id_,
|
| SaveRegistration(SERVICE_WORKER_OK, &called, &new_registration));
|
|
|
| ASSERT_FALSE(called);
|
| @@ -333,10 +302,10 @@
|
| ASSERT_NE(old_registration, new_registration);
|
|
|
| scoped_refptr<ServiceWorkerRegistration> new_registration_by_pattern;
|
| - storage()->FindRegistrationForPattern(
|
| - pattern,
|
| - SaveFoundRegistration(
|
| - true, SERVICE_WORKER_OK, &called, &new_registration));
|
| + storage_->FindRegistrationForPattern(
|
| + pattern,
|
| + SaveFoundRegistration(true, SERVICE_WORKER_OK, &called,
|
| + &new_registration));
|
|
|
| ASSERT_FALSE(called);
|
| base::RunLoop().RunUntilIdle();
|
| @@ -353,10 +322,9 @@
|
|
|
| bool called;
|
| scoped_refptr<ServiceWorkerRegistration> old_registration;
|
| - job_coordinator()->Register(
|
| + job_coordinator_->Register(
|
| pattern,
|
| script_url,
|
| - render_process_id_,
|
| SaveRegistration(SERVICE_WORKER_OK, &called, &old_registration));
|
|
|
| ASSERT_FALSE(called);
|
| @@ -364,7 +332,7 @@
|
| ASSERT_TRUE(called);
|
|
|
| scoped_refptr<ServiceWorkerRegistration> old_registration_by_pattern;
|
| - storage()->FindRegistrationForPattern(
|
| + storage_->FindRegistrationForPattern(
|
| pattern,
|
| SaveFoundRegistration(
|
| true, SERVICE_WORKER_OK, &called, &old_registration_by_pattern));
|
| @@ -375,10 +343,9 @@
|
| ASSERT_TRUE(old_registration_by_pattern);
|
|
|
| scoped_refptr<ServiceWorkerRegistration> new_registration;
|
| - job_coordinator()->Register(
|
| + job_coordinator_->Register(
|
| pattern,
|
| script_url,
|
| - render_process_id_,
|
| SaveRegistration(SERVICE_WORKER_OK, &called, &new_registration));
|
|
|
| ASSERT_FALSE(called);
|
| @@ -390,7 +357,7 @@
|
| ASSERT_FALSE(old_registration->HasOneRef());
|
|
|
| scoped_refptr<ServiceWorkerRegistration> new_registration_by_pattern;
|
| - storage()->FindRegistrationForPattern(
|
| + storage_->FindRegistrationForPattern(
|
| pattern,
|
| SaveFoundRegistration(
|
| true, SERVICE_WORKER_OK, &called, &new_registration_by_pattern));
|
| @@ -410,17 +377,14 @@
|
|
|
| bool registration_called = false;
|
| scoped_refptr<ServiceWorkerRegistration> registration;
|
| - job_coordinator()->Register(
|
| + job_coordinator_->Register(
|
| pattern,
|
| script_url,
|
| - render_process_id_,
|
| SaveRegistration(SERVICE_WORKER_OK, ®istration_called, ®istration));
|
|
|
| bool unregistration_called = false;
|
| - job_coordinator()->Unregister(
|
| - pattern,
|
| - render_process_id_,
|
| - SaveUnregistration(SERVICE_WORKER_OK, &unregistration_called));
|
| + job_coordinator_->Unregister(
|
| + pattern, SaveUnregistration(SERVICE_WORKER_OK, &unregistration_called));
|
|
|
| ASSERT_FALSE(registration_called);
|
| ASSERT_FALSE(unregistration_called);
|
| @@ -431,7 +395,7 @@
|
| ASSERT_TRUE(registration->is_shutdown());
|
|
|
| bool find_called = false;
|
| - storage()->FindRegistrationForPattern(
|
| + storage_->FindRegistrationForPattern(
|
| pattern,
|
| SaveFoundRegistration(
|
| false, SERVICE_WORKER_OK, &find_called, ®istration));
|
| @@ -450,22 +414,20 @@
|
| GURL script_url1("http://www.example.com/service_worker1.js");
|
| bool registration1_called = false;
|
| scoped_refptr<ServiceWorkerRegistration> registration1;
|
| - job_coordinator()->Register(
|
| + job_coordinator_->Register(
|
| pattern,
|
| script_url1,
|
| - render_process_id_,
|
| - SaveRegistration(
|
| - SERVICE_WORKER_OK, ®istration1_called, ®istration1));
|
| + SaveRegistration(SERVICE_WORKER_OK, ®istration1_called,
|
| + ®istration1));
|
|
|
| GURL script_url2("http://www.example.com/service_worker2.js");
|
| bool registration2_called = false;
|
| scoped_refptr<ServiceWorkerRegistration> registration2;
|
| - job_coordinator()->Register(
|
| + job_coordinator_->Register(
|
| pattern,
|
| script_url2,
|
| - render_process_id_,
|
| - SaveRegistration(
|
| - SERVICE_WORKER_OK, ®istration2_called, ®istration2));
|
| + SaveRegistration(SERVICE_WORKER_OK, ®istration2_called,
|
| + ®istration2));
|
|
|
| ASSERT_FALSE(registration1_called);
|
| ASSERT_FALSE(registration2_called);
|
| @@ -475,7 +437,7 @@
|
|
|
| scoped_refptr<ServiceWorkerRegistration> registration;
|
| bool find_called = false;
|
| - storage()->FindRegistrationForPattern(
|
| + storage_->FindRegistrationForPattern(
|
| pattern,
|
| SaveFoundRegistration(
|
| true, SERVICE_WORKER_OK, &find_called, ®istration));
|
| @@ -496,21 +458,19 @@
|
| GURL script_url("http://www.example.com/service_worker1.js");
|
| bool registration1_called = false;
|
| scoped_refptr<ServiceWorkerRegistration> registration1;
|
| - job_coordinator()->Register(
|
| + job_coordinator_->Register(
|
| pattern,
|
| script_url,
|
| - render_process_id_,
|
| - SaveRegistration(
|
| - SERVICE_WORKER_OK, ®istration1_called, ®istration1));
|
| + SaveRegistration(SERVICE_WORKER_OK, ®istration1_called,
|
| + ®istration1));
|
|
|
| bool registration2_called = false;
|
| scoped_refptr<ServiceWorkerRegistration> registration2;
|
| - job_coordinator()->Register(
|
| + job_coordinator_->Register(
|
| pattern,
|
| script_url,
|
| - render_process_id_,
|
| - SaveRegistration(
|
| - SERVICE_WORKER_OK, ®istration2_called, ®istration2));
|
| + SaveRegistration(SERVICE_WORKER_OK, ®istration2_called,
|
| + ®istration2));
|
|
|
| ASSERT_FALSE(registration1_called);
|
| ASSERT_FALSE(registration2_called);
|
| @@ -522,7 +482,7 @@
|
|
|
| scoped_refptr<ServiceWorkerRegistration> registration;
|
| bool find_called = false;
|
| - storage()->FindRegistrationForPattern(
|
| + storage_->FindRegistrationForPattern(
|
| pattern,
|
| SaveFoundRegistration(
|
| true, SERVICE_WORKER_OK, &find_called, ®istration));
|
| @@ -537,16 +497,12 @@
|
|
|
| GURL script_url("http://www.example.com/service_worker.js");
|
| bool unregistration1_called = false;
|
| - job_coordinator()->Unregister(
|
| - pattern,
|
| - render_process_id_,
|
| - SaveUnregistration(SERVICE_WORKER_OK, &unregistration1_called));
|
| + job_coordinator_->Unregister(
|
| + pattern, SaveUnregistration(SERVICE_WORKER_OK, &unregistration1_called));
|
|
|
| bool unregistration2_called = false;
|
| - job_coordinator()->Unregister(
|
| - pattern,
|
| - render_process_id_,
|
| - SaveUnregistration(SERVICE_WORKER_OK, &unregistration2_called));
|
| + job_coordinator_->Unregister(
|
| + pattern, SaveUnregistration(SERVICE_WORKER_OK, &unregistration2_called));
|
|
|
| ASSERT_FALSE(unregistration1_called);
|
| ASSERT_FALSE(unregistration2_called);
|
| @@ -559,7 +515,7 @@
|
| // crashing.
|
| scoped_refptr<ServiceWorkerRegistration> registration;
|
| bool find_called = false;
|
| - storage()->FindRegistrationForPattern(
|
| + storage_->FindRegistrationForPattern(
|
| pattern,
|
| SaveFoundRegistration(
|
| false, SERVICE_WORKER_OK, &find_called, ®istration));
|
|
|