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..c1700534dc8ccf13c3a63d8e091fd873f274ce9f 100644 |
--- a/content/browser/service_worker/embedded_worker_instance_unittest.cc |
+++ b/content/browser/service_worker/embedded_worker_instance_unittest.cc |
@@ -44,6 +44,39 @@ void SaveStatusAndCall(ServiceWorkerStatusCode* out, |
} // namespace |
+class MockServiceWorkerProviderHost : public ServiceWorkerProviderHost { |
+ public: |
+ MockServiceWorkerProviderHost(base::WeakPtr<ServiceWorkerContextCore> context) |
+ : ServiceWorkerProviderHost(ChildProcessHost::kInvalidUniqueID, |
+ ServiceWorkerProviderHostInfo( |
+ kInvalidServiceWorkerProviderId, |
+ MSG_ROUTING_NONE, |
+ SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, |
+ false), |
+ context, |
+ nullptr), |
+ binding_(this) {} |
+ |
+ ~MockServiceWorkerProviderHost() override {} |
+ |
+ void CompleteStartWorkerPreparation(int process_id, |
+ mojom::ServiceWorkerProviderClientInfoPtr* |
+ provider_client_info) override { |
+ // Nothing to do. |
+ DCHECK(!binding_.is_bound()); |
+ DCHECK(!client_.is_bound()); |
+ auto* host_ptr_info_ptr = &(*provider_client_info)->host_ptr_info; |
+ binding_.Bind(mojo::MakeRequest(host_ptr_info_ptr)); |
+ (*provider_client_info)->client_request = mojo::MakeRequest(&client_); |
+ } |
+ |
+ private: |
+ mojom::ServiceWorkerProviderAssociatedPtr client_; |
+ mojo::AssociatedBinding<mojom::ServiceWorkerProviderHost> binding_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(MockServiceWorkerProviderHost); |
+}; |
+ |
class EmbeddedWorkerInstanceTest : public testing::Test, |
public EmbeddedWorkerInstance::Listener { |
protected: |
@@ -82,7 +115,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 +131,7 @@ class EmbeddedWorkerInstanceTest : public testing::Test, |
std::unique_ptr<EmbeddedWorkerStartParams> params = |
CreateStartParams(id, pattern, url); |
worker->Start( |
- std::move(params), CreateEventDispatcher(), |
+ std::move(params), CreateMockProvider(), CreateEventDispatcher(), |
base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure())); |
run_loop.Run(); |
return status; |
@@ -116,6 +149,13 @@ class EmbeddedWorkerInstanceTest : public testing::Test, |
return params; |
} |
+ base::WeakPtr<ServiceWorkerProviderHost> CreateMockProvider() { |
+ mock_providers_.emplace_back( |
+ base::MakeUnique<MockServiceWorkerProviderHost>( |
+ helper_->context()->AsWeakPtr())); |
+ return mock_providers_.back()->AsWeakPtr(); |
+ } |
+ |
mojom::ServiceWorkerEventDispatcherRequest CreateEventDispatcher() { |
dispatchers_.emplace_back(); |
return mojo::MakeRequest(&dispatchers_.back()); |
@@ -137,6 +177,7 @@ class EmbeddedWorkerInstanceTest : public testing::Test, |
} |
std::vector<mojom::ServiceWorkerEventDispatcherPtr> dispatchers_; |
+ std::vector<std::unique_ptr<MockServiceWorkerProviderHost>> mock_providers_; |
TestBrowserThreadBundle thread_bundle_; |
std::unique_ptr<EmbeddedWorkerTestHelper> helper_; |
@@ -153,14 +194,15 @@ 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::ServiceWorkerProviderClientInfoPtr provider_client_info) override { |
if (force_stall_in_start_) { |
// Prepare for OnStopWorker(). |
instance_host_ptr_map_[embedded_worker_id].Bind(std::move(instance_host)); |
@@ -169,7 +211,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_client_info)); |
} |
void OnStopWorker(int embedded_worker_id) override { |
@@ -214,7 +257,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), CreateMockProvider(), CreateEventDispatcher(), |
base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure())); |
EXPECT_EQ(EmbeddedWorkerStatus::STARTING, worker->status()); |
run_loop.Run(); |
@@ -271,7 +314,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), CreateMockProvider(), CreateEventDispatcher(), |
base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure())); |
run_loop.Run(); |
EXPECT_EQ(SERVICE_WORKER_OK, status); |
@@ -296,7 +339,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), CreateMockProvider(), CreateEventDispatcher(), |
base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure())); |
EXPECT_EQ(EmbeddedWorkerStatus::STARTING, worker->status()); |
run_loop.Run(); |
@@ -377,7 +420,7 @@ TEST_F(EmbeddedWorkerInstanceTest, RemoveWorkerInSharedProcess) { |
std::unique_ptr<EmbeddedWorkerStartParams> params = |
CreateStartParams(version_id1, pattern, url); |
worker1->Start( |
- std::move(params), CreateEventDispatcher(), |
+ std::move(params), CreateMockProvider(), CreateEventDispatcher(), |
base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure())); |
run_loop.Run(); |
EXPECT_EQ(SERVICE_WORKER_OK, status); |
@@ -390,7 +433,7 @@ TEST_F(EmbeddedWorkerInstanceTest, RemoveWorkerInSharedProcess) { |
std::unique_ptr<EmbeddedWorkerStartParams> params = |
CreateStartParams(version_id2, pattern, url); |
worker2->Start( |
- std::move(params), CreateEventDispatcher(), |
+ std::move(params), CreateMockProvider(), CreateEventDispatcher(), |
base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure())); |
run_loop.Run(); |
EXPECT_EQ(SERVICE_WORKER_OK, status); |
@@ -428,7 +471,7 @@ TEST_F(EmbeddedWorkerInstanceTest, DetachDuringProcessAllocation) { |
std::unique_ptr<EmbeddedWorkerStartParams> params = |
CreateStartParams(version_id, scope, url); |
worker->Start( |
- std::move(params), CreateEventDispatcher(), |
+ std::move(params), CreateMockProvider(), CreateEventDispatcher(), |
base::Bind(&SaveStatusAndCall, &status, base::Bind(&base::DoNothing))); |
worker->Detach(); |
base::RunLoop().RunUntilIdle(); |
@@ -461,7 +504,7 @@ TEST_F(EmbeddedWorkerInstanceTest, DetachAfterSendingStartWorkerMessage) { |
std::unique_ptr<EmbeddedWorkerStartParams> params = |
CreateStartParams(version_id, scope, url); |
worker->Start( |
- std::move(params), CreateEventDispatcher(), |
+ std::move(params), CreateMockProvider(), CreateEventDispatcher(), |
base::Bind(&SaveStatusAndCall, &status, base::Bind(&base::DoNothing))); |
base::RunLoop().RunUntilIdle(); |
@@ -501,7 +544,7 @@ TEST_F(EmbeddedWorkerInstanceTest, StopDuringProcessAllocation) { |
std::unique_ptr<EmbeddedWorkerStartParams> params = |
CreateStartParams(version_id, scope, url); |
worker->Start( |
- std::move(params), CreateEventDispatcher(), |
+ std::move(params), CreateMockProvider(), CreateEventDispatcher(), |
base::Bind(&SaveStatusAndCall, &status, base::Bind(&base::DoNothing))); |
worker->Stop(); |
base::RunLoop().RunUntilIdle(); |
@@ -524,7 +567,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), CreateMockProvider(), CreateEventDispatcher(), |
base::Bind(&SaveStatusAndCall, &status, run_loop->QuitClosure())); |
run_loop->Run(); |
@@ -576,7 +619,7 @@ TEST_F(EmbeddedWorkerInstanceTest, StopDuringPausedAfterDownload) { |
CreateStartParams(version_id, scope, url); |
params->pause_after_download = true; |
worker->Start( |
- std::move(params), CreateEventDispatcher(), |
+ std::move(params), CreateMockProvider(), CreateEventDispatcher(), |
base::Bind(&SaveStatusAndCall, &status, base::Bind(&base::DoNothing))); |
base::RunLoop().RunUntilIdle(); |
@@ -606,7 +649,7 @@ TEST_F(EmbeddedWorkerInstanceTest, StopAfterSendingStartWorkerMessage) { |
std::unique_ptr<EmbeddedWorkerStartParams> params = |
CreateStartParams(version_id, scope, url); |
worker->Start( |
- std::move(params), CreateEventDispatcher(), |
+ std::move(params), CreateMockProvider(), CreateEventDispatcher(), |
base::Bind(&SaveStatusAndCall, &status, base::Bind(&base::DoNothing))); |
base::RunLoop().RunUntilIdle(); |
@@ -639,7 +682,7 @@ TEST_F(EmbeddedWorkerInstanceTest, StopAfterSendingStartWorkerMessage) { |
params = CreateStartParams(version_id, scope, url); |
worker->Start( |
- std::move(params), CreateEventDispatcher(), |
+ std::move(params), CreateMockProvider(), CreateEventDispatcher(), |
base::Bind(&SaveStatusAndCall, &status, run_loop->QuitClosure())); |
run_loop->Run(); |
@@ -670,7 +713,7 @@ TEST_F(EmbeddedWorkerInstanceTest, Detach) { |
std::unique_ptr<EmbeddedWorkerStartParams> params = |
CreateStartParams(version_id, pattern, url); |
worker->Start( |
- std::move(params), CreateEventDispatcher(), |
+ std::move(params), CreateMockProvider(), CreateEventDispatcher(), |
base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure())); |
run_loop.Run(); |
@@ -704,7 +747,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), CreateMockProvider(), |
+ CreateEventDispatcher(), |
base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
base::RunLoop().RunUntilIdle(); |
@@ -723,11 +767,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::ServiceWorkerProviderClientInfoPtr) override { |
helper_->mock_instance_clients()->clear(); |
} |
}; |
@@ -752,7 +795,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), CreateMockProvider(), |
+ CreateEventDispatcher(), |
base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
base::RunLoop().RunUntilIdle(); |
@@ -808,7 +852,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), CreateMockProvider(), |
+ CreateEventDispatcher(), |
base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
worker->AddMessageToConsole(test_message.first, test_message.second); |
base::RunLoop().RunUntilIdle(); |