Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Unified Diff: content/browser/service_worker/service_worker_dispatcher_host_unittest.cc

Issue 2638313002: Manage ServiceWorkerDispatcherHost in ServiceWorkerContextCore (Closed)
Patch Set: Remove a break line Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 638b46b1789ee1bbcbd7ee12f5770a5fecef090a..c92838a1516f950741a44657aff0d9ad375caf1b 100644
--- a/content/browser/service_worker/service_worker_dispatcher_host_unittest.cc
+++ b/content/browser/service_worker/service_worker_dispatcher_host_unittest.cc
@@ -61,9 +61,12 @@ class TestingServiceWorkerDispatcherHost : public ServiceWorkerDispatcherHost {
TestingServiceWorkerDispatcherHost(
int process_id,
ServiceWorkerContextWrapper* context_wrapper,
+ MessagePortMessageFilter* message_port_message_filter,
ResourceContext* resource_context,
EmbeddedWorkerTestHelper* helper)
- : ServiceWorkerDispatcherHost(process_id, nullptr, resource_context),
+ : ServiceWorkerDispatcherHost(process_id,
+ message_port_message_filter,
+ resource_context),
bad_messages_received_count_(0),
helper_(helper) {
Init(context_wrapper);
@@ -120,9 +123,14 @@ class ServiceWorkerDispatcherHostTest : public testing::Test {
void Initialize(std::unique_ptr<EmbeddedWorkerTestHelper> helper) {
helper_.reset(helper.release());
+ int process_id = helper_->mock_render_process_id();
+ // Inherit the message filter for message ports.
+ MessagePortMessageFilter* message_port_filter =
+ context()->GetDispatcherHost(process_id)->message_port_message_filter();
+ context()->RemoveDispatcherHost(process_id);
dispatcher_host_ = new TestingServiceWorkerDispatcherHost(
- helper_->mock_render_process_id(), context_wrapper(),
- &resource_context_, helper_.get());
+ process_id, context_wrapper(), message_port_filter, &resource_context_,
+ helper_.get());
}
void SetUpRegistration(const GURL& scope, const GURL& script_url) {
@@ -156,16 +164,16 @@ class ServiceWorkerDispatcherHostTest : public testing::Test {
void SendSetHostedVersionId(int provider_id,
int64_t version_id,
int embedded_worker_id) {
- dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_SetVersionId(
- provider_id, version_id, embedded_worker_id));
+ dispatcher_host_->OnSetHostedVersionId(provider_id, version_id,
+ embedded_worker_id);
}
void SendProviderCreated(ServiceWorkerProviderType type,
const GURL& pattern) {
const int64_t kProviderId = 99;
- dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated(
- kProviderId, MSG_ROUTING_NONE, type,
- true /* is_parent_frame_secure */));
+ ServiceWorkerProviderHostInfo info(kProviderId, MSG_ROUTING_NONE, type,
+ true);
+ dispatcher_host_->OnProviderCreated(std::move(info));
helper_->SimulateAddProcessToPattern(pattern,
helper_->mock_render_process_id());
provider_host_ = context()->GetProviderHost(
@@ -246,12 +254,11 @@ class ServiceWorkerDispatcherHostTest : public testing::Test {
sender_provider_host, callback);
}
- ServiceWorkerProviderHost* CreateServiceWorkerProviderHost(int provider_id) {
- return new ServiceWorkerProviderHost(
- helper_->mock_render_process_id(), kRenderFrameId, provider_id,
- SERVICE_WORKER_PROVIDER_FOR_WINDOW,
- ServiceWorkerProviderHost::FrameSecurityLevel::SECURE,
- context()->AsWeakPtr(), dispatcher_host_.get());
+ std::unique_ptr<ServiceWorkerProviderHost> CreateServiceWorkerProviderHost(
+ int provider_id) {
+ return CreateProviderHostWithDispatcherHost(
+ helper_->mock_render_process_id(), provider_id, context()->AsWeakPtr(),
+ kRenderFrameId, dispatcher_host_.get());
}
TestBrowserThreadBundle browser_thread_bundle_;
@@ -510,34 +517,32 @@ TEST_F(ServiceWorkerDispatcherHostTest, ProviderCreatedAndDestroyed) {
const int kProviderId = 1001;
int process_id = helper_->mock_render_process_id();
- dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated(
+ dispatcher_host_->OnProviderCreated(ServiceWorkerProviderHostInfo(
kProviderId, MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_WINDOW,
true /* is_parent_frame_secure */));
EXPECT_TRUE(context()->GetProviderHost(process_id, kProviderId));
// Two with the same ID should be seen as a bad message.
- dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated(
+ dispatcher_host_->OnProviderCreated(ServiceWorkerProviderHostInfo(
kProviderId, MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_WINDOW,
true /* is_parent_frame_secure */));
EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_);
- dispatcher_host_->OnMessageReceived(
- ServiceWorkerHostMsg_ProviderDestroyed(kProviderId));
+ dispatcher_host_->OnProviderDestroyed(kProviderId);
EXPECT_FALSE(context()->GetProviderHost(process_id, kProviderId));
// Destroying an ID that does not exist warrants a bad message.
- dispatcher_host_->OnMessageReceived(
- ServiceWorkerHostMsg_ProviderDestroyed(kProviderId));
+ dispatcher_host_->OnProviderDestroyed(kProviderId);
EXPECT_EQ(2, dispatcher_host_->bad_messages_received_count_);
// Deletion of the dispatcher_host should cause providers for that
// process to get deleted as well.
- dispatcher_host_->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated(
+ dispatcher_host_->OnProviderCreated(ServiceWorkerProviderHostInfo(
kProviderId, MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_WINDOW,
true /* is_parent_frame_secure */));
EXPECT_TRUE(context()->GetProviderHost(process_id, kProviderId));
EXPECT_TRUE(dispatcher_host_->HasOneRef());
- dispatcher_host_ = NULL;
+ dispatcher_host_ = nullptr;
EXPECT_FALSE(context()->GetProviderHost(process_id, kProviderId));
}
@@ -663,13 +668,14 @@ TEST_F(ServiceWorkerDispatcherHostTest, CleanupOnRendererCrash) {
// is not yet destroyed. This is what the browser does when reusing a crashed
// render process.
scoped_refptr<TestingServiceWorkerDispatcherHost> new_dispatcher_host(
- new TestingServiceWorkerDispatcherHost(
- process_id, context_wrapper(), &resource_context_, helper_.get()));
+ new TestingServiceWorkerDispatcherHost(process_id, context_wrapper(),
+ nullptr, &resource_context_,
+ helper_.get()));
// To show the new dispatcher can operate, simulate provider creation. Since
// the old dispatcher cleaned up the old provider host, the new one won't
// complain.
- new_dispatcher_host->OnMessageReceived(ServiceWorkerHostMsg_ProviderCreated(
+ new_dispatcher_host->OnProviderCreated(ServiceWorkerProviderHostInfo(
provider_id, MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_WINDOW,
true /* is_parent_frame_secure */));
EXPECT_EQ(0, new_dispatcher_host->bad_messages_received_count_);

Powered by Google App Engine
This is Rietveld 408576698