Index: content/browser/service_worker/service_worker_dispatcher_host_unittest.cc |
diff --git a/content/browser/service_worker/service_worker_dispatcher_host_unittest.cc b/content/browser/service_worker/service_worker_dispatcher_host_unittest.cc |
index fe4c2164c1116066c216e902e3d363114ce484ee..8d5b39d40e1284b26845c23dbaa96b7cee210ae1 100644 |
--- a/content/browser/service_worker/service_worker_dispatcher_host_unittest.cc |
+++ b/content/browser/service_worker/service_worker_dispatcher_host_unittest.cc |
@@ -8,20 +8,14 @@ |
#include "base/files/file_path.h" |
#include "base/run_loop.h" |
#include "content/browser/browser_thread_impl.h" |
-#include "content/browser/service_worker/embedded_worker_instance.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_context_wrapper.h" |
-#include "content/common/service_worker/embedded_worker_messages.h" |
#include "content/common/service_worker/service_worker_messages.h" |
#include "content/public/common/content_switches.h" |
#include "content/public/test/test_browser_thread_bundle.h" |
#include "testing/gtest/include/gtest/gtest.h" |
namespace content { |
- |
-static const int kRenderProcessId = 1; |
class ServiceWorkerDispatcherHostTest : public testing::Test { |
protected: |
@@ -31,13 +25,9 @@ |
virtual void SetUp() { |
context_wrapper_ = new ServiceWorkerContextWrapper; |
context_wrapper_->Init(base::FilePath(), NULL); |
- helper_.reset(new EmbeddedWorkerTestHelper(context())); |
- |
- helper_->SimulateCreateWorker(kRenderProcessId); |
} |
virtual void TearDown() { |
- helper_.reset(); |
if (context_wrapper_) { |
context_wrapper_->Shutdown(); |
context_wrapper_ = NULL; |
@@ -48,36 +38,33 @@ |
TestBrowserThreadBundle browser_thread_bundle_; |
scoped_refptr<ServiceWorkerContextWrapper> context_wrapper_; |
- scoped_ptr<EmbeddedWorkerTestHelper> helper_; |
}; |
+static const int kRenderProcessId = 1; |
class TestingServiceWorkerDispatcherHost : public ServiceWorkerDispatcherHost { |
public: |
TestingServiceWorkerDispatcherHost( |
int process_id, |
- ServiceWorkerContextWrapper* context_wrapper, |
- EmbeddedWorkerTestHelper* helper) |
+ ServiceWorkerContextWrapper* context_wrapper) |
: ServiceWorkerDispatcherHost(process_id), |
- bad_messages_received_count_(0), |
- helper_(helper) { |
+ bad_messages_received_count_(0) { |
Init(context_wrapper); |
} |
virtual bool Send(IPC::Message* message) OVERRIDE { |
- return helper_->Send(message); |
+ sent_messages_.push_back(message); |
+ return true; |
} |
- |
- IPC::TestSink* ipc_sink() { return helper_->ipc_sink(); } |
virtual void BadMessageReceived() OVERRIDE { |
++bad_messages_received_count_; |
} |
+ ScopedVector<IPC::Message> sent_messages_; |
int bad_messages_received_count_; |
protected: |
- EmbeddedWorkerTestHelper* helper_; |
virtual ~TestingServiceWorkerDispatcherHost() {} |
}; |
@@ -86,8 +73,8 @@ |
switches::kEnableServiceWorker)); |
scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host = |
- new TestingServiceWorkerDispatcherHost( |
- kRenderProcessId, context_wrapper_.get(), helper_.get()); |
+ new TestingServiceWorkerDispatcherHost(kRenderProcessId, |
+ context_wrapper_.get()); |
bool handled; |
dispatcher_host->OnMessageReceived( |
@@ -96,9 +83,10 @@ |
EXPECT_TRUE(handled); |
// TODO(alecflett): Pump the message loop when this becomes async. |
- ASSERT_EQ(1UL, dispatcher_host->ipc_sink()->message_count()); |
- EXPECT_TRUE(dispatcher_host->ipc_sink()->GetUniqueMessageMatching( |
- ServiceWorkerMsg_ServiceWorkerRegistrationError::ID)); |
+ ASSERT_EQ(1UL, dispatcher_host->sent_messages_.size()); |
+ EXPECT_EQ( |
+ static_cast<uint32>(ServiceWorkerMsg_ServiceWorkerRegistrationError::ID), |
+ dispatcher_host->sent_messages_[0]->type()); |
} |
TEST_F(ServiceWorkerDispatcherHostTest, Enabled) { |
@@ -108,8 +96,8 @@ |
switches::kEnableServiceWorker); |
scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host = |
- new TestingServiceWorkerDispatcherHost( |
- kRenderProcessId, context_wrapper_.get(), helper_.get()); |
+ new TestingServiceWorkerDispatcherHost(kRenderProcessId, |
+ context_wrapper_.get()); |
bool handled; |
dispatcher_host->OnMessageReceived( |
@@ -119,11 +107,9 @@ |
base::RunLoop().RunUntilIdle(); |
// TODO(alecflett): Pump the message loop when this becomes async. |
- ASSERT_EQ(2UL, dispatcher_host->ipc_sink()->message_count()); |
- EXPECT_TRUE(dispatcher_host->ipc_sink()->GetUniqueMessageMatching( |
- EmbeddedWorkerMsg_StartWorker::ID)); |
- EXPECT_TRUE(dispatcher_host->ipc_sink()->GetUniqueMessageMatching( |
- ServiceWorkerMsg_ServiceWorkerRegistered::ID)); |
+ ASSERT_EQ(1UL, dispatcher_host->sent_messages_.size()); |
+ EXPECT_EQ(static_cast<uint32>(ServiceWorkerMsg_ServiceWorkerRegistered::ID), |
+ dispatcher_host->sent_messages_[0]->type()); |
} |
TEST_F(ServiceWorkerDispatcherHostTest, EarlyContextDeletion) { |
@@ -133,8 +119,8 @@ |
switches::kEnableServiceWorker); |
scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host = |
- new TestingServiceWorkerDispatcherHost( |
- kRenderProcessId, context_wrapper_.get(), helper_.get()); |
+ new TestingServiceWorkerDispatcherHost(kRenderProcessId, |
+ context_wrapper_.get()); |
context_wrapper_->Shutdown(); |
context_wrapper_ = NULL; |
@@ -146,15 +132,16 @@ |
EXPECT_TRUE(handled); |
// TODO(alecflett): Pump the message loop when this becomes async. |
- ASSERT_EQ(1UL, dispatcher_host->ipc_sink()->message_count()); |
- EXPECT_TRUE(dispatcher_host->ipc_sink()->GetUniqueMessageMatching( |
- ServiceWorkerMsg_ServiceWorkerRegistrationError::ID)); |
+ ASSERT_EQ(1UL, dispatcher_host->sent_messages_.size()); |
+ EXPECT_EQ( |
+ static_cast<uint32>(ServiceWorkerMsg_ServiceWorkerRegistrationError::ID), |
+ dispatcher_host->sent_messages_[0]->type()); |
} |
TEST_F(ServiceWorkerDispatcherHostTest, ProviderCreatedAndDestroyed) { |
scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host = |
- new TestingServiceWorkerDispatcherHost( |
- kRenderProcessId, context_wrapper_.get(), helper_.get()); |
+ new TestingServiceWorkerDispatcherHost(kRenderProcessId, |
+ context_wrapper_.get()); |
const int kProviderId = 1001; // Test with a value != kRenderProcessId. |