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

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

Issue 2490623005: Remove InterfaceRegistry/Provider from service workers (Closed)
Patch Set: rebase/fix comment Created 4 years, 1 month 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 1ded6ee740fbf9e4d2a1c41773e6016a81c18f38..c2b19c72c5cdd5a48319e2fce72ab0aa6b25c96c 100644
--- a/content/browser/service_worker/embedded_worker_instance_unittest.cc
+++ b/content/browser/service_worker/embedded_worker_instance_unittest.cc
@@ -21,6 +21,7 @@
#include "content/common/service_worker/embedded_worker.mojom.h"
#include "content/common/service_worker/embedded_worker_messages.h"
#include "content/common/service_worker/embedded_worker_start_params.h"
+#include "content/common/service_worker/service_worker_event_dispatcher.mojom.h"
#include "content/common/service_worker/service_worker_utils.h"
#include "content/public/common/child_process_host.h"
#include "content/public/common/content_switches.h"
@@ -40,18 +41,6 @@ void SaveStatusAndCall(ServiceWorkerStatusCode* out,
callback.Run();
}
-std::unique_ptr<EmbeddedWorkerStartParams>
-CreateStartParams(int version_id, const GURL& scope, const GURL& script_url) {
- std::unique_ptr<EmbeddedWorkerStartParams> params(
- new EmbeddedWorkerStartParams);
- params->service_worker_version_id = version_id;
- params->scope = scope;
- params->script_url = script_url;
- params->pause_after_download = false;
- params->is_installed = false;
- return params;
-}
-
} // namespace
class EmbeddedWorkerInstanceTest : public testing::Test,
@@ -107,12 +96,30 @@ class EmbeddedWorkerInstanceTest : public testing::Test,
base::RunLoop run_loop;
std::unique_ptr<EmbeddedWorkerStartParams> params =
CreateStartParams(id, pattern, url);
- worker->Start(std::move(params), base::Bind(&SaveStatusAndCall, &status,
- run_loop.QuitClosure()));
+ worker->Start(
+ std::move(params), CreateEventDispatcher(),
+ base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure()));
run_loop.Run();
return status;
}
+ std::unique_ptr<EmbeddedWorkerStartParams>
+ CreateStartParams(int version_id, const GURL& scope, const GURL& script_url) {
+ std::unique_ptr<EmbeddedWorkerStartParams> params =
+ base::MakeUnique<EmbeddedWorkerStartParams>();
+ params->service_worker_version_id = version_id;
+ params->scope = scope;
+ params->script_url = script_url;
+ params->pause_after_download = false;
+ params->is_installed = false;
+ return params;
+ }
+
+ mojom::ServiceWorkerEventDispatcherRequest CreateEventDispatcher() {
+ dispatchers_.emplace_back();
+ return mojo::GetProxy(&dispatchers_.back());
+ }
+
ServiceWorkerContextCore* context() { return helper_->context(); }
EmbeddedWorkerRegistry* embedded_worker_registry() {
@@ -128,6 +135,8 @@ class EmbeddedWorkerInstanceTest : public testing::Test,
return helper_->mock_instance_clients();
}
+ std::vector<mojom::ServiceWorkerEventDispatcherPtr> dispatchers_;
+
TestBrowserThreadBundle thread_bundle_;
std::unique_ptr<EmbeddedWorkerTestHelper> helper_;
std::vector<EventLog> events_;
@@ -198,8 +207,9 @@ TEST_P(EmbeddedWorkerInstanceTestP, StartAndStop) {
base::RunLoop run_loop;
std::unique_ptr<EmbeddedWorkerStartParams> params =
CreateStartParams(service_worker_version_id, pattern, url);
- worker->Start(std::move(params), base::Bind(&SaveStatusAndCall, &status,
- run_loop.QuitClosure()));
+ worker->Start(
+ std::move(params), CreateEventDispatcher(),
+ base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure()));
EXPECT_EQ(EmbeddedWorkerStatus::STARTING, worker->status());
run_loop.Run();
EXPECT_EQ(SERVICE_WORKER_OK, status);
@@ -261,10 +271,11 @@ TEST_P(EmbeddedWorkerInstanceTestP, ForceNewProcess) {
// Start once normally.
ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE;
base::RunLoop run_loop;
- std::unique_ptr<EmbeddedWorkerStartParams> params(
- CreateStartParams(service_worker_version_id, pattern, url));
- worker->Start(std::move(params), base::Bind(&SaveStatusAndCall, &status,
- run_loop.QuitClosure()));
+ std::unique_ptr<EmbeddedWorkerStartParams> params =
+ CreateStartParams(service_worker_version_id, pattern, url);
+ worker->Start(
+ std::move(params), CreateEventDispatcher(),
+ base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure()));
run_loop.Run();
EXPECT_EQ(SERVICE_WORKER_OK, status);
EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, worker->status());
@@ -285,10 +296,11 @@ TEST_P(EmbeddedWorkerInstanceTestP, ForceNewProcess) {
// Start again.
ServiceWorkerStatusCode status;
base::RunLoop run_loop;
- std::unique_ptr<EmbeddedWorkerStartParams> params(
- CreateStartParams(service_worker_version_id, pattern, url));
- worker->Start(std::move(params), base::Bind(&SaveStatusAndCall, &status,
- run_loop.QuitClosure()));
+ std::unique_ptr<EmbeddedWorkerStartParams> params =
+ CreateStartParams(service_worker_version_id, pattern, url);
+ worker->Start(
+ std::move(params), CreateEventDispatcher(),
+ base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure()));
EXPECT_EQ(EmbeddedWorkerStatus::STARTING, worker->status());
run_loop.Run();
EXPECT_EQ(SERVICE_WORKER_OK, status);
@@ -365,10 +377,11 @@ TEST_P(EmbeddedWorkerInstanceTestP, RemoveWorkerInSharedProcess) {
// Start worker1.
ServiceWorkerStatusCode status;
base::RunLoop run_loop;
- std::unique_ptr<EmbeddedWorkerStartParams> params(
- CreateStartParams(version_id1, pattern, url));
- worker1->Start(std::move(params), base::Bind(&SaveStatusAndCall, &status,
- run_loop.QuitClosure()));
+ std::unique_ptr<EmbeddedWorkerStartParams> params =
+ CreateStartParams(version_id1, pattern, url);
+ worker1->Start(
+ std::move(params), CreateEventDispatcher(),
+ base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure()));
run_loop.Run();
EXPECT_EQ(SERVICE_WORKER_OK, status);
}
@@ -377,10 +390,11 @@ TEST_P(EmbeddedWorkerInstanceTestP, RemoveWorkerInSharedProcess) {
// Start worker2.
ServiceWorkerStatusCode status;
base::RunLoop run_loop;
- std::unique_ptr<EmbeddedWorkerStartParams> params(
- CreateStartParams(version_id2, pattern, url));
- worker2->Start(std::move(params), base::Bind(&SaveStatusAndCall, &status,
- run_loop.QuitClosure()));
+ std::unique_ptr<EmbeddedWorkerStartParams> params =
+ CreateStartParams(version_id2, pattern, url);
+ worker2->Start(
+ std::move(params), CreateEventDispatcher(),
+ base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure()));
run_loop.Run();
EXPECT_EQ(SERVICE_WORKER_OK, status);
}
@@ -414,10 +428,11 @@ TEST_P(EmbeddedWorkerInstanceTestP, DetachDuringProcessAllocation) {
// Run the start worker sequence and detach during process allocation.
ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE;
- std::unique_ptr<EmbeddedWorkerStartParams> params(
- CreateStartParams(version_id, scope, url));
- worker->Start(std::move(params), base::Bind(&SaveStatusAndCall, &status,
- base::Bind(&base::DoNothing)));
+ std::unique_ptr<EmbeddedWorkerStartParams> params =
+ CreateStartParams(version_id, scope, url);
+ worker->Start(
+ std::move(params), CreateEventDispatcher(),
+ base::Bind(&SaveStatusAndCall, &status, base::Bind(&base::DoNothing)));
worker->Detach();
base::RunLoop().RunUntilIdle();
@@ -446,10 +461,11 @@ TEST_P(EmbeddedWorkerInstanceTestP, DetachAfterSendingStartWorkerMessage) {
// Run the start worker sequence until a start worker message is sent.
ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE;
- std::unique_ptr<EmbeddedWorkerStartParams> params(
- CreateStartParams(version_id, scope, url));
- worker->Start(std::move(params), base::Bind(&SaveStatusAndCall, &status,
- base::Bind(&base::DoNothing)));
+ std::unique_ptr<EmbeddedWorkerStartParams> params =
+ CreateStartParams(version_id, scope, url);
+ worker->Start(
+ std::move(params), CreateEventDispatcher(),
+ base::Bind(&SaveStatusAndCall, &status, base::Bind(&base::DoNothing)));
base::RunLoop().RunUntilIdle();
ASSERT_EQ(2u, events_.size());
@@ -485,10 +501,11 @@ TEST_P(EmbeddedWorkerInstanceTestP, StopDuringProcessAllocation) {
// Stop the start worker sequence before a process is allocated.
ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE;
- std::unique_ptr<EmbeddedWorkerStartParams> params(
- CreateStartParams(version_id, scope, url));
- worker->Start(std::move(params), base::Bind(&SaveStatusAndCall, &status,
- base::Bind(&base::DoNothing)));
+ std::unique_ptr<EmbeddedWorkerStartParams> params =
+ CreateStartParams(version_id, scope, url);
+ worker->Start(
+ std::move(params), CreateEventDispatcher(),
+ base::Bind(&SaveStatusAndCall, &status, base::Bind(&base::DoNothing)));
worker->Stop();
base::RunLoop().RunUntilIdle();
@@ -515,8 +532,9 @@ TEST_P(EmbeddedWorkerInstanceTestP, StopDuringProcessAllocation) {
status = SERVICE_WORKER_ERROR_MAX_VALUE;
std::unique_ptr<base::RunLoop> run_loop(new base::RunLoop);
params = CreateStartParams(version_id, scope, url);
- worker->Start(std::move(params), base::Bind(&SaveStatusAndCall, &status,
- run_loop->QuitClosure()));
+ worker->Start(
+ std::move(params), CreateEventDispatcher(),
+ base::Bind(&SaveStatusAndCall, &status, run_loop->QuitClosure()));
run_loop->Run();
EXPECT_EQ(SERVICE_WORKER_OK, status);
@@ -541,11 +559,12 @@ TEST_P(EmbeddedWorkerInstanceTestP, StopDuringPausedAfterDownload) {
// Run the start worker sequence until pause after download.
ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE;
- std::unique_ptr<EmbeddedWorkerStartParams> params(
- CreateStartParams(version_id, scope, url));
+ std::unique_ptr<EmbeddedWorkerStartParams> params =
+ CreateStartParams(version_id, scope, url);
params->pause_after_download = true;
- worker->Start(std::move(params), base::Bind(&SaveStatusAndCall, &status,
- base::Bind(&base::DoNothing)));
+ worker->Start(
+ std::move(params), CreateEventDispatcher(),
+ base::Bind(&SaveStatusAndCall, &status, base::Bind(&base::DoNothing)));
base::RunLoop().RunUntilIdle();
// Make the worker stopping and attempt to send a resume after download
@@ -572,10 +591,11 @@ TEST_P(EmbeddedWorkerInstanceTestP, StopAfterSendingStartWorkerMessage) {
// Run the start worker sequence until a start worker message is sent.
ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE;
- std::unique_ptr<EmbeddedWorkerStartParams> params(
- CreateStartParams(version_id, scope, url));
- worker->Start(std::move(params), base::Bind(&SaveStatusAndCall, &status,
- base::Bind(&base::DoNothing)));
+ std::unique_ptr<EmbeddedWorkerStartParams> params =
+ CreateStartParams(version_id, scope, url);
+ worker->Start(
+ std::move(params), CreateEventDispatcher(),
+ base::Bind(&SaveStatusAndCall, &status, base::Bind(&base::DoNothing)));
base::RunLoop().RunUntilIdle();
ASSERT_EQ(2u, events_.size());
@@ -606,8 +626,9 @@ TEST_P(EmbeddedWorkerInstanceTestP, StopAfterSendingStartWorkerMessage) {
std::unique_ptr<base::RunLoop> run_loop(new base::RunLoop);
params = CreateStartParams(version_id, scope, url);
- worker->Start(std::move(params), base::Bind(&SaveStatusAndCall, &status,
- run_loop->QuitClosure()));
+ worker->Start(
+ std::move(params), CreateEventDispatcher(),
+ base::Bind(&SaveStatusAndCall, &status, run_loop->QuitClosure()));
run_loop->Run();
// The worker should be started.
@@ -634,10 +655,11 @@ TEST_P(EmbeddedWorkerInstanceTestP, Detach) {
// Start the worker.
base::RunLoop run_loop;
- std::unique_ptr<EmbeddedWorkerStartParams> params(
- CreateStartParams(version_id, pattern, url));
- worker->Start(std::move(params), base::Bind(&SaveStatusAndCall, &status,
- run_loop.QuitClosure()));
+ std::unique_ptr<EmbeddedWorkerStartParams> params =
+ CreateStartParams(version_id, pattern, url);
+ worker->Start(
+ std::move(params), CreateEventDispatcher(),
+ base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure()));
run_loop.Run();
// Detach.
@@ -673,16 +695,17 @@ TEST_P(EmbeddedWorkerInstanceTestP, FailToSendStartIPC) {
worker->AddListener(this);
// Attempt to start the worker.
- std::unique_ptr<EmbeddedWorkerStartParams> params(
- CreateStartParams(version_id, pattern, url));
+ std::unique_ptr<EmbeddedWorkerStartParams> params =
+ CreateStartParams(version_id, pattern, url);
if (is_mojo_enabled()) {
- worker->Start(std::move(params),
+ worker->Start(std::move(params), CreateEventDispatcher(),
base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
base::RunLoop().RunUntilIdle();
} else {
base::RunLoop run_loop;
- worker->Start(std::move(params), base::Bind(&SaveStatusAndCall, &status,
- run_loop.QuitClosure()));
+ worker->Start(
+ std::move(params), CreateEventDispatcher(),
+ base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure()));
run_loop.Run();
}
@@ -714,8 +737,7 @@ class FailEmbeddedWorkerInstanceClientImpl
private:
void StartWorker(
const EmbeddedWorkerStartParams& /* unused */,
- service_manager::mojom::InterfaceProviderPtr /* unused */,
- service_manager::mojom::InterfaceProviderRequest /* unused */) override {
+ mojom::ServiceWorkerEventDispatcherRequest /* unused */) override {
helper_->mock_instance_clients()->clear();
}
};
@@ -741,9 +763,9 @@ TEST_P(EmbeddedWorkerInstanceTestP, RemoveRemoteInterface) {
worker->AddListener(this);
// Attempt to start the worker.
- std::unique_ptr<EmbeddedWorkerStartParams> params(
- CreateStartParams(version_id, pattern, url));
- worker->Start(std::move(params),
+ std::unique_ptr<EmbeddedWorkerStartParams> params =
+ CreateStartParams(version_id, pattern, url);
+ worker->Start(std::move(params), CreateEventDispatcher(),
base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
base::RunLoop().RunUntilIdle();

Powered by Google App Engine
This is Rietveld 408576698