#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.
class ServiceWorkerJobTest : public testing::Test {
public:
ServiceWorkerJobTest()
- : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {}
+ : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP),
+ render_process_id_(88) {}
virtual void SetUp() OVERRIDE {
- storage_.reset(new ServiceWorkerStorage(base::FilePath(), NULL));
- job_coordinator_.reset(new ServiceWorkerJobCoordinator(storage_.get()));
+ context_.reset(new ServiceWorkerContextCore(base::FilePath(), NULL));
+ helper_.reset(new EmbeddedWorkerTestHelper(context_.get(),
+ render_process_id_));
}
- virtual void TearDown() OVERRIDE { storage_.reset(); }
+ virtual void TearDown() OVERRIDE {
+ helper_.reset();
+ context_.reset();
+ }
+
+ ServiceWorkerJobCoordinator* job_coordinator() const {
+ return context_->job_coordinator();
+ }
+ ServiceWorkerStorage* storage() const { return context_->storage(); }
protected:
TestBrowserThreadBundle browser_thread_bundle_;
- scoped_ptr<ServiceWorkerStorage> storage_;
- scoped_ptr<ServiceWorkerJobCoordinator> job_coordinator_;
+ scoped_ptr<ServiceWorkerContextCore> context_;
+ scoped_ptr<EmbeddedWorkerTestHelper> helper_;
+
+ int render_process_id_;
};
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));
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();
original_registration.get());
scoped_refptr<ServiceWorkerRegistration> registration1;
- storage_->FindRegistrationForDocument(
+ storage()->FindRegistrationForDocument(
GURL("http://www.example.com/one"),
SaveFoundRegistration(true, SERVICE_WORKER_OK, &called, ®istration1));
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);
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);
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));
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);
bool called;
scoped_refptr<ServiceWorkerRegistration> registration;
- job_coordinator_->Register(
+ job_coordinator()->Register(
pattern,
GURL("http://www.example.com/service_worker.js"),
+ render_process_id_,
SaveRegistration(SERVICE_WORKER_OK, &called, ®istration));
ASSERT_FALSE(called);
base::RunLoop().RunUntilIdle();
ASSERT_TRUE(called);
- job_coordinator_->Unregister(pattern,
- SaveUnregistration(SERVICE_WORKER_OK, &called));
+ job_coordinator()->Unregister(pattern,
+ render_process_id_,
+ SaveUnregistration(SERVICE_WORKER_OK, &called));
ASSERT_FALSE(called);
base::RunLoop().RunUntilIdle();
ASSERT_TRUE(registration->HasOneRef());
- storage_->FindRegistrationForPattern(
+ storage()->FindRegistrationForPattern(
pattern,
SaveFoundRegistration(false, SERVICE_WORKER_OK, &called, ®istration));
bool called;
scoped_refptr<ServiceWorkerRegistration> old_registration;
- job_coordinator_->Register(
+ job_coordinator()->Register(
pattern,
GURL("http://www.example.com/service_worker.js"),
+ render_process_id_,
SaveRegistration(SERVICE_WORKER_OK, &called, &old_registration));
ASSERT_FALSE(called);
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));
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);
ASSERT_NE(old_registration, new_registration);
scoped_refptr<ServiceWorkerRegistration> new_registration_by_pattern;
- storage_->FindRegistrationForPattern(
+ storage()->FindRegistrationForPattern(
pattern,
- SaveFoundRegistration(true, SERVICE_WORKER_OK, &called,
- &new_registration));
+ SaveFoundRegistration(
+ true, SERVICE_WORKER_OK, &called, &new_registration));
ASSERT_FALSE(called);
base::RunLoop().RunUntilIdle();
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);
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));
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);
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));
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, SaveUnregistration(SERVICE_WORKER_OK, &unregistration_called));
+ job_coordinator()->Unregister(
+ pattern,
+ render_process_id_,
+ SaveUnregistration(SERVICE_WORKER_OK, &unregistration_called));
ASSERT_FALSE(registration_called);
ASSERT_FALSE(unregistration_called);
ASSERT_TRUE(registration->is_shutdown());
bool find_called = false;
- storage_->FindRegistrationForPattern(
+ storage()->FindRegistrationForPattern(
pattern,
SaveFoundRegistration(
false, SERVICE_WORKER_OK, &find_called, ®istration));
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,
- SaveRegistration(SERVICE_WORKER_OK, ®istration1_called,
- ®istration1));
+ render_process_id_,
+ 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,
- SaveRegistration(SERVICE_WORKER_OK, ®istration2_called,
- ®istration2));
+ render_process_id_,
+ SaveRegistration(
+ SERVICE_WORKER_OK, ®istration2_called, ®istration2));
ASSERT_FALSE(registration1_called);
ASSERT_FALSE(registration2_called);
scoped_refptr<ServiceWorkerRegistration> registration;
bool find_called = false;
- storage_->FindRegistrationForPattern(
+ storage()->FindRegistrationForPattern(
pattern,
SaveFoundRegistration(
true, SERVICE_WORKER_OK, &find_called, ®istration));
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,
- SaveRegistration(SERVICE_WORKER_OK, ®istration1_called,
- ®istration1));
+ render_process_id_,
+ SaveRegistration(
+ SERVICE_WORKER_OK, ®istration1_called, ®istration1));
bool registration2_called = false;
scoped_refptr<ServiceWorkerRegistration> registration2;
- job_coordinator_->Register(
+ job_coordinator()->Register(
pattern,
script_url,
- SaveRegistration(SERVICE_WORKER_OK, ®istration2_called,
- ®istration2));
+ render_process_id_,
+ SaveRegistration(
+ SERVICE_WORKER_OK, ®istration2_called, ®istration2));
ASSERT_FALSE(registration1_called);
ASSERT_FALSE(registration2_called);
scoped_refptr<ServiceWorkerRegistration> registration;
bool find_called = false;
- storage_->FindRegistrationForPattern(
+ storage()->FindRegistrationForPattern(
pattern,
SaveFoundRegistration(
true, SERVICE_WORKER_OK, &find_called, ®istration));
GURL script_url("http://www.example.com/service_worker.js");
bool unregistration1_called = false;
- job_coordinator_->Unregister(
- pattern, SaveUnregistration(SERVICE_WORKER_OK, &unregistration1_called));
+ job_coordinator()->Unregister(
+ pattern,
+ render_process_id_,
+ SaveUnregistration(SERVICE_WORKER_OK, &unregistration1_called));
bool unregistration2_called = false;
- job_coordinator_->Unregister(
- pattern, SaveUnregistration(SERVICE_WORKER_OK, &unregistration2_called));
+ job_coordinator()->Unregister(
+ pattern,
+ render_process_id_,
+ SaveUnregistration(SERVICE_WORKER_OK, &unregistration2_called));
ASSERT_FALSE(unregistration1_called);
ASSERT_FALSE(unregistration2_called);
// crashing.
scoped_refptr<ServiceWorkerRegistration> registration;
bool find_called = false;
- storage_->FindRegistrationForPattern(
+ storage()->FindRegistrationForPattern(
pattern,
SaveFoundRegistration(
false, SERVICE_WORKER_OK, &find_called, ®istration));