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

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

Issue 2779763004: Create ServiceWorkerProviderHost before starting worker (Closed)
Patch Set: Pass the param of BindWithProviderInfo by value instead of pointer Created 3 years, 6 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_instance_unittest.cc
diff --git a/content/browser/service_worker/embedded_worker_instance_unittest.cc b/content/browser/service_worker/embedded_worker_instance_unittest.cc
index 450fbeb3e1ab57d909f78b0c261d75f5f913a7b2..cbe3047edec30ff4f0d9f9658d06940608f877a0 100644
--- a/content/browser/service_worker/embedded_worker_instance_unittest.cc
+++ b/content/browser/service_worker/embedded_worker_instance_unittest.cc
@@ -44,6 +44,30 @@ void SaveStatusAndCall(ServiceWorkerStatusCode* out,
} // namespace
+class ProviderHostEndpoints : public mojom::ServiceWorkerProviderHost {
+ public:
+ ProviderHostEndpoints() : binding_(this) {}
+
+ ~ProviderHostEndpoints() override {}
+
+ mojom::ServiceWorkerProviderInfoForStartWorkerPtr CreateProviderInfoPtr() {
+ DCHECK(!binding_.is_bound());
+ DCHECK(!client_.is_bound());
+ // Just keep the endpoints.
+ mojom::ServiceWorkerProviderInfoForStartWorkerPtr provider_info =
+ mojom::ServiceWorkerProviderInfoForStartWorker::New();
+ binding_.Bind(mojo::MakeRequest(&provider_info->host_ptr_info));
+ provider_info->client_request = mojo::MakeRequest(&client_);
+ return provider_info;
+ }
+
+ private:
+ mojom::ServiceWorkerProviderAssociatedPtr client_;
+ mojo::AssociatedBinding<mojom::ServiceWorkerProviderHost> binding_;
+
+ DISALLOW_COPY_AND_ASSIGN(ProviderHostEndpoints);
+};
+
class EmbeddedWorkerInstanceTest : public testing::Test,
public EmbeddedWorkerInstance::Listener {
protected:
@@ -82,7 +106,7 @@ class EmbeddedWorkerInstanceTest : public testing::Test,
RecordEvent(DETACHED, old_status);
}
- bool OnMessageReceived(const IPC::Message& message) override { return false; }
+ bool OnMessageReceived(const IPC::Message&) override { return false; }
void SetUp() override {
helper_.reset(new EmbeddedWorkerTestHelper(base::FilePath()));
@@ -98,7 +122,7 @@ class EmbeddedWorkerInstanceTest : public testing::Test,
std::unique_ptr<EmbeddedWorkerStartParams> params =
CreateStartParams(id, pattern, url);
worker->Start(
- std::move(params), CreateEventDispatcher(),
+ std::move(params), CreateProviderInfoGetter(), CreateEventDispatcher(),
base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure()));
run_loop.Run();
return status;
@@ -116,6 +140,18 @@ class EmbeddedWorkerInstanceTest : public testing::Test,
return params;
}
+ mojom::ServiceWorkerProviderInfoForStartWorkerPtr CreateProviderInfo(
+ int /* process_id */) {
+ provider_host_endpoints_.emplace_back(
+ base::MakeUnique<ProviderHostEndpoints>());
+ return provider_host_endpoints_.back()->CreateProviderInfoPtr();
+ }
+
+ EmbeddedWorkerInstance::ProviderInfoGetter CreateProviderInfoGetter() {
+ return base::BindOnce(&EmbeddedWorkerInstanceTest::CreateProviderInfo,
+ base::Unretained(this));
+ }
+
mojom::ServiceWorkerEventDispatcherRequest CreateEventDispatcher() {
dispatchers_.emplace_back();
return mojo::MakeRequest(&dispatchers_.back());
@@ -137,6 +173,7 @@ class EmbeddedWorkerInstanceTest : public testing::Test,
}
std::vector<mojom::ServiceWorkerEventDispatcherPtr> dispatchers_;
+ std::vector<std::unique_ptr<ProviderHostEndpoints>> provider_host_endpoints_;
TestBrowserThreadBundle thread_bundle_;
std::unique_ptr<EmbeddedWorkerTestHelper> helper_;
@@ -153,14 +190,16 @@ class StalledInStartWorkerHelper : public EmbeddedWorkerTestHelper {
StalledInStartWorkerHelper() : EmbeddedWorkerTestHelper(base::FilePath()) {}
~StalledInStartWorkerHelper() override {}
- void OnStartWorker(int embedded_worker_id,
- int64_t service_worker_version_id,
- const GURL& scope,
- const GURL& script_url,
- bool pause_after_download,
- mojom::ServiceWorkerEventDispatcherRequest request,
- mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo
- instance_host) override {
+ void OnStartWorker(
+ int embedded_worker_id,
+ int64_t service_worker_version_id,
+ const GURL& scope,
+ const GURL& script_url,
+ bool pause_after_download,
+ mojom::ServiceWorkerEventDispatcherRequest request,
+ mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host,
+ mojom::ServiceWorkerProviderInfoForStartWorkerPtr provider_info)
+ override {
if (force_stall_in_start_) {
// Prepare for OnStopWorker().
instance_host_ptr_map_[embedded_worker_id].Bind(std::move(instance_host));
@@ -169,7 +208,8 @@ class StalledInStartWorkerHelper : public EmbeddedWorkerTestHelper {
}
EmbeddedWorkerTestHelper::OnStartWorker(
embedded_worker_id, service_worker_version_id, scope, script_url,
- pause_after_download, std::move(request), std::move(instance_host));
+ pause_after_download, std::move(request), std::move(instance_host),
+ std::move(provider_info));
}
void OnStopWorker(int embedded_worker_id) override {
@@ -214,7 +254,7 @@ TEST_F(EmbeddedWorkerInstanceTest, StartAndStop) {
std::unique_ptr<EmbeddedWorkerStartParams> params =
CreateStartParams(service_worker_version_id, pattern, url);
worker->Start(
- std::move(params), CreateEventDispatcher(),
+ std::move(params), CreateProviderInfoGetter(), CreateEventDispatcher(),
base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure()));
EXPECT_EQ(EmbeddedWorkerStatus::STARTING, worker->status());
run_loop.Run();
@@ -271,7 +311,7 @@ TEST_F(EmbeddedWorkerInstanceTest, ForceNewProcess) {
std::unique_ptr<EmbeddedWorkerStartParams> params =
CreateStartParams(service_worker_version_id, pattern, url);
worker->Start(
- std::move(params), CreateEventDispatcher(),
+ std::move(params), CreateProviderInfoGetter(), CreateEventDispatcher(),
base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure()));
run_loop.Run();
EXPECT_EQ(SERVICE_WORKER_OK, status);
@@ -296,7 +336,7 @@ TEST_F(EmbeddedWorkerInstanceTest, ForceNewProcess) {
std::unique_ptr<EmbeddedWorkerStartParams> params =
CreateStartParams(service_worker_version_id, pattern, url);
worker->Start(
- std::move(params), CreateEventDispatcher(),
+ std::move(params), CreateProviderInfoGetter(), CreateEventDispatcher(),
base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure()));
EXPECT_EQ(EmbeddedWorkerStatus::STARTING, worker->status());
run_loop.Run();
@@ -377,7 +417,7 @@ TEST_F(EmbeddedWorkerInstanceTest, RemoveWorkerInSharedProcess) {
std::unique_ptr<EmbeddedWorkerStartParams> params =
CreateStartParams(version_id1, pattern, url);
worker1->Start(
- std::move(params), CreateEventDispatcher(),
+ std::move(params), CreateProviderInfoGetter(), CreateEventDispatcher(),
base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure()));
run_loop.Run();
EXPECT_EQ(SERVICE_WORKER_OK, status);
@@ -390,7 +430,7 @@ TEST_F(EmbeddedWorkerInstanceTest, RemoveWorkerInSharedProcess) {
std::unique_ptr<EmbeddedWorkerStartParams> params =
CreateStartParams(version_id2, pattern, url);
worker2->Start(
- std::move(params), CreateEventDispatcher(),
+ std::move(params), CreateProviderInfoGetter(), CreateEventDispatcher(),
base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure()));
run_loop.Run();
EXPECT_EQ(SERVICE_WORKER_OK, status);
@@ -428,7 +468,7 @@ TEST_F(EmbeddedWorkerInstanceTest, DetachDuringProcessAllocation) {
std::unique_ptr<EmbeddedWorkerStartParams> params =
CreateStartParams(version_id, scope, url);
worker->Start(
- std::move(params), CreateEventDispatcher(),
+ std::move(params), CreateProviderInfoGetter(), CreateEventDispatcher(),
base::Bind(&SaveStatusAndCall, &status, base::Bind(&base::DoNothing)));
worker->Detach();
base::RunLoop().RunUntilIdle();
@@ -461,7 +501,7 @@ TEST_F(EmbeddedWorkerInstanceTest, DetachAfterSendingStartWorkerMessage) {
std::unique_ptr<EmbeddedWorkerStartParams> params =
CreateStartParams(version_id, scope, url);
worker->Start(
- std::move(params), CreateEventDispatcher(),
+ std::move(params), CreateProviderInfoGetter(), CreateEventDispatcher(),
base::Bind(&SaveStatusAndCall, &status, base::Bind(&base::DoNothing)));
base::RunLoop().RunUntilIdle();
@@ -501,7 +541,7 @@ TEST_F(EmbeddedWorkerInstanceTest, StopDuringProcessAllocation) {
std::unique_ptr<EmbeddedWorkerStartParams> params =
CreateStartParams(version_id, scope, url);
worker->Start(
- std::move(params), CreateEventDispatcher(),
+ std::move(params), CreateProviderInfoGetter(), CreateEventDispatcher(),
base::Bind(&SaveStatusAndCall, &status, base::Bind(&base::DoNothing)));
worker->Stop();
base::RunLoop().RunUntilIdle();
@@ -524,7 +564,7 @@ TEST_F(EmbeddedWorkerInstanceTest, StopDuringProcessAllocation) {
std::unique_ptr<base::RunLoop> run_loop(new base::RunLoop);
params = CreateStartParams(version_id, scope, url);
worker->Start(
- std::move(params), CreateEventDispatcher(),
+ std::move(params), CreateProviderInfoGetter(), CreateEventDispatcher(),
base::Bind(&SaveStatusAndCall, &status, run_loop->QuitClosure()));
run_loop->Run();
@@ -576,7 +616,7 @@ TEST_F(EmbeddedWorkerInstanceTest, StopDuringPausedAfterDownload) {
CreateStartParams(version_id, scope, url);
params->pause_after_download = true;
worker->Start(
- std::move(params), CreateEventDispatcher(),
+ std::move(params), CreateProviderInfoGetter(), CreateEventDispatcher(),
base::Bind(&SaveStatusAndCall, &status, base::Bind(&base::DoNothing)));
base::RunLoop().RunUntilIdle();
@@ -606,7 +646,7 @@ TEST_F(EmbeddedWorkerInstanceTest, StopAfterSendingStartWorkerMessage) {
std::unique_ptr<EmbeddedWorkerStartParams> params =
CreateStartParams(version_id, scope, url);
worker->Start(
- std::move(params), CreateEventDispatcher(),
+ std::move(params), CreateProviderInfoGetter(), CreateEventDispatcher(),
base::Bind(&SaveStatusAndCall, &status, base::Bind(&base::DoNothing)));
base::RunLoop().RunUntilIdle();
@@ -639,7 +679,7 @@ TEST_F(EmbeddedWorkerInstanceTest, StopAfterSendingStartWorkerMessage) {
params = CreateStartParams(version_id, scope, url);
worker->Start(
- std::move(params), CreateEventDispatcher(),
+ std::move(params), CreateProviderInfoGetter(), CreateEventDispatcher(),
base::Bind(&SaveStatusAndCall, &status, run_loop->QuitClosure()));
run_loop->Run();
@@ -670,7 +710,7 @@ TEST_F(EmbeddedWorkerInstanceTest, Detach) {
std::unique_ptr<EmbeddedWorkerStartParams> params =
CreateStartParams(version_id, pattern, url);
worker->Start(
- std::move(params), CreateEventDispatcher(),
+ std::move(params), CreateProviderInfoGetter(), CreateEventDispatcher(),
base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure()));
run_loop.Run();
@@ -704,7 +744,8 @@ TEST_F(EmbeddedWorkerInstanceTest, FailToSendStartIPC) {
// Attempt to start the worker.
std::unique_ptr<EmbeddedWorkerStartParams> params =
CreateStartParams(version_id, pattern, url);
- worker->Start(std::move(params), CreateEventDispatcher(),
+ worker->Start(std::move(params), CreateProviderInfoGetter(),
+ CreateEventDispatcher(),
base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
base::RunLoop().RunUntilIdle();
@@ -723,11 +764,10 @@ class FailEmbeddedWorkerInstanceClientImpl
: EmbeddedWorkerTestHelper::MockEmbeddedWorkerInstanceClient(helper) {}
private:
- void StartWorker(
- const EmbeddedWorkerStartParams& /* unused */,
- mojom::ServiceWorkerEventDispatcherRequest /* unused */,
- mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo /* unused */)
- override {
+ void StartWorker(const EmbeddedWorkerStartParams&,
+ mojom::ServiceWorkerEventDispatcherRequest,
+ mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo,
+ mojom::ServiceWorkerProviderInfoForStartWorkerPtr) override {
helper_->mock_instance_clients()->clear();
}
};
@@ -752,7 +792,8 @@ TEST_F(EmbeddedWorkerInstanceTest, RemoveRemoteInterface) {
// Attempt to start the worker.
std::unique_ptr<EmbeddedWorkerStartParams> params =
CreateStartParams(version_id, pattern, url);
- worker->Start(std::move(params), CreateEventDispatcher(),
+ worker->Start(std::move(params), CreateProviderInfoGetter(),
+ CreateEventDispatcher(),
base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
base::RunLoop().RunUntilIdle();
@@ -808,7 +849,8 @@ TEST_F(EmbeddedWorkerInstanceTest, AddMessageToConsole) {
std::make_pair(blink::WebConsoleMessage::kLevelVerbose, "");
std::unique_ptr<EmbeddedWorkerStartParams> params =
CreateStartParams(version_id, pattern, url);
- worker->Start(std::move(params), CreateEventDispatcher(),
+ worker->Start(std::move(params), CreateProviderInfoGetter(),
+ CreateEventDispatcher(),
base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
worker->AddMessageToConsole(test_message.first, test_message.second);
base::RunLoop().RunUntilIdle();

Powered by Google App Engine
This is Rietveld 408576698