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

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

Issue 1264333002: First step to refactor ServiceWorkerVersion to make event dispatching more modular. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rockot nits Created 4 years, 11 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/embedded_worker_test_helper.cc
diff --git a/content/browser/service_worker/embedded_worker_test_helper.cc b/content/browser/service_worker/embedded_worker_test_helper.cc
index e8cbe2df76b7c6e1dc0c545501092361eb8c516c..3f57292339134cf458818b82d30770576d69569f 100644
--- a/content/browser/service_worker/embedded_worker_test_helper.cc
+++ b/content/browser/service_worker/embedded_worker_test_helper.cc
@@ -18,9 +18,11 @@
#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/embedded_worker_setup.mojom.h"
#include "content/common/service_worker/service_worker_messages.h"
#include "content/public/test/mock_render_process_host.h"
#include "content/public/test/test_browser_context.h"
+#include "mojo/public/cpp/bindings/strong_binding.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace content {
@@ -47,6 +49,33 @@ class MockMessagePortMessageFilter : public MessagePortMessageFilter {
} // namespace
+class EmbeddedWorkerTestHelper::MockEmbeddedWorkerSetup
+ : public EmbeddedWorkerSetup {
+ public:
+ static void Create(const base::WeakPtr<EmbeddedWorkerTestHelper>& helper,
+ mojo::InterfaceRequest<EmbeddedWorkerSetup> request) {
+ new MockEmbeddedWorkerSetup(helper, std::move(request));
+ }
+
+ void ExchangeServiceProviders(
+ int32_t thread_id,
+ mojo::InterfaceRequest<mojo::ServiceProvider> services,
+ mojo::ServiceProviderPtr exposed_services) override {
+ if (!helper_)
+ return;
+ helper_->OnSetupMojoStub(thread_id, std::move(services),
+ std::move(exposed_services));
+ }
+
+ private:
+ MockEmbeddedWorkerSetup(const base::WeakPtr<EmbeddedWorkerTestHelper>& helper,
+ mojo::InterfaceRequest<EmbeddedWorkerSetup> request)
+ : helper_(helper), binding_(this, std::move(request)) {}
+
+ base::WeakPtr<EmbeddedWorkerTestHelper> helper_;
+ mojo::StrongBinding<EmbeddedWorkerSetup> binding_;
+};
+
EmbeddedWorkerTestHelper::EmbeddedWorkerTestHelper(
const base::FilePath& user_data_directory)
: browser_context_(new TestBrowserContext),
@@ -63,6 +92,16 @@ EmbeddedWorkerTestHelper::EmbeddedWorkerTestHelper(
wrapper_->process_manager()->SetProcessIdForTest(mock_render_process_id_);
registry()->AddChildProcessSender(mock_render_process_id_, this,
NewMessagePortMessageFilter());
+
+ // Setup process level mojo service registry pair.
+ scoped_ptr<ServiceRegistryImpl> host_service_registry(
+ new ServiceRegistryImpl);
+ render_process_service_registry_.ServiceRegistry::AddService(
+ base::Bind(&MockEmbeddedWorkerSetup::Create, weak_factory_.GetWeakPtr()));
+ mojo::ServiceProviderPtr services;
+ render_process_service_registry_.Bind(mojo::GetProxy(&services));
+ host_service_registry->BindRemoteServiceProvider(std::move(services));
+ render_process_host_->SetServiceRegistry(std::move(host_service_registry));
}
EmbeddedWorkerTestHelper::~EmbeddedWorkerTestHelper() {
@@ -148,6 +187,8 @@ bool EmbeddedWorkerTestHelper::OnMessageToWorker(
return handled;
}
+void EmbeddedWorkerTestHelper::OnSetupMojo(ServiceRegistry* service_registry) {}
+
void EmbeddedWorkerTestHelper::OnActivateEvent(int embedded_worker_id,
int request_id) {
SimulateSend(
@@ -337,6 +378,17 @@ void EmbeddedWorkerTestHelper::OnPushEventStub(int request_id,
current_embedded_worker_id_, request_id, data));
}
+void EmbeddedWorkerTestHelper::OnSetupMojoStub(
+ int thread_id,
+ mojo::InterfaceRequest<mojo::ServiceProvider> services,
+ mojo::ServiceProviderPtr exposed_services) {
+ scoped_ptr<ServiceRegistryImpl> new_registry(new ServiceRegistryImpl);
+ new_registry->Bind(std::move(services));
+ new_registry->BindRemoteServiceProvider(std::move(exposed_services));
+ OnSetupMojo(new_registry.get());
+ thread_id_service_registry_map_.add(thread_id, std::move(new_registry));
+}
+
EmbeddedWorkerRegistry* EmbeddedWorkerTestHelper::registry() {
DCHECK(context());
return context()->embedded_worker_registry();
« no previous file with comments | « content/browser/service_worker/embedded_worker_test_helper.h ('k') | content/browser/service_worker/service_worker_metrics.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698