Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / content / browser / service_worker / service_worker_context_unittest.cc
index 56f5218..c4d8a64 100644 (file)
@@ -8,6 +8,8 @@
 #include "base/logging.h"
 #include "base/message_loop/message_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_registration.h"
 #include "content/public/test/test_browser_thread_bundle.h"
@@ -46,17 +48,25 @@ ServiceWorkerContextCore::UnregistrationCallback MakeUnregisteredCallback(
 class ServiceWorkerContextTest : public testing::Test {
  public:
   ServiceWorkerContextTest()
-      : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {}
+      : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP),
+        render_process_id_(99) {}
 
   virtual void SetUp() OVERRIDE {
     context_.reset(new ServiceWorkerContextCore(base::FilePath(), NULL));
+    helper_.reset(new EmbeddedWorkerTestHelper(
+        context_.get(), render_process_id_));
   }
 
-  virtual void TearDown() OVERRIDE { context_.reset(); }
+  virtual void TearDown() OVERRIDE {
+    helper_.reset();
+    context_.reset();
+  }
 
  protected:
   TestBrowserThreadBundle browser_thread_bundle_;
   scoped_ptr<ServiceWorkerContextCore> context_;
+  scoped_ptr<EmbeddedWorkerTestHelper> helper_;
+  const int render_process_id_;
 };
 
 void RegistrationCallback(
@@ -72,13 +82,15 @@ TEST_F(ServiceWorkerContextTest, Register) {
   context_->RegisterServiceWorker(
       GURL("http://www.example.com/*"),
       GURL("http://www.example.com/service_worker.js"),
+      render_process_id_,
       MakeRegisteredCallback(&called, &registration_id));
 
   ASSERT_FALSE(called);
   base::RunLoop().RunUntilIdle();
-  ASSERT_TRUE(called);
+  EXPECT_TRUE(called);
 
-  ASSERT_NE(-1L, registration_id);
+  EXPECT_EQ(1UL, helper_->ipc_sink()->message_count());
+  EXPECT_NE(-1L, registration_id);
 }
 
 // Make sure registrations are cleaned up when they are unregistered.
@@ -90,6 +102,7 @@ TEST_F(ServiceWorkerContextTest, Unregister) {
   context_->RegisterServiceWorker(
       pattern,
       GURL("http://www.example.com/service_worker.js"),
+      render_process_id_,
       MakeRegisteredCallback(&called, &registration_id));
 
   ASSERT_FALSE(called);
@@ -97,7 +110,8 @@ TEST_F(ServiceWorkerContextTest, Unregister) {
   ASSERT_TRUE(called);
 
   called = false;
-  context_->UnregisterServiceWorker(pattern, MakeUnregisteredCallback(&called));
+  context_->UnregisterServiceWorker(
+      pattern, render_process_id_, MakeUnregisteredCallback(&called));
 
   ASSERT_FALSE(called);
   base::RunLoop().RunUntilIdle();
@@ -114,6 +128,7 @@ TEST_F(ServiceWorkerContextTest, RegisterNewScript) {
   context_->RegisterServiceWorker(
       pattern,
       GURL("http://www.example.com/service_worker.js"),
+      render_process_id_,
       MakeRegisteredCallback(&called, &old_registration_id));
 
   ASSERT_FALSE(called);
@@ -125,6 +140,7 @@ TEST_F(ServiceWorkerContextTest, RegisterNewScript) {
   context_->RegisterServiceWorker(
       pattern,
       GURL("http://www.example.com/service_worker_new.js"),
+      render_process_id_,
       MakeRegisteredCallback(&called, &new_registration_id));
 
   ASSERT_FALSE(called);
@@ -145,6 +161,7 @@ TEST_F(ServiceWorkerContextTest, RegisterDuplicateScript) {
   context_->RegisterServiceWorker(
       pattern,
       script_url,
+      render_process_id_,
       MakeRegisteredCallback(&called, &old_registration_id));
 
   ASSERT_FALSE(called);
@@ -156,6 +173,7 @@ TEST_F(ServiceWorkerContextTest, RegisterDuplicateScript) {
   context_->RegisterServiceWorker(
       pattern,
       script_url,
+      render_process_id_,
       MakeRegisteredCallback(&called, &new_registration_id));
 
   ASSERT_FALSE(called);