Commit 5aa9a5b1 authored by Wei Wang's avatar Wei Wang Committed by Commit Bot

Replace RunUntilIdle() with a quit callback in ServiceWorkerJobTest

This patch replaces the base::RunLoop().RunUntilIde() with base::RunLoop loop,
which will reduce the time delay and make those unit tests deterministic.

Bug: 973005
Change-Id: I3fa718ef0926b38385c53f0af9d6ce8865a87660
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1760670
Commit-Queue: Makoto Shimazu <shimazu@chromium.org>
Reviewed-by: default avatarMakoto Shimazu <shimazu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#691968}
parent 92abd22a
...@@ -957,6 +957,7 @@ Wanming Lin <wanming.lin@intel.com> ...@@ -957,6 +957,7 @@ Wanming Lin <wanming.lin@intel.com>
Wei Li <wei.c.li@intel.com> Wei Li <wei.c.li@intel.com>
WenSheng He <wensheng.he@samsung.com> WenSheng He <wensheng.he@samsung.com>
Wesley Lancel <wesleylancel@gmail.com> Wesley Lancel <wesleylancel@gmail.com>
Wei Wang <wei4.wang@intel.com>
Wesley Wigham <wwigham@gmail.com> Wesley Wigham <wwigham@gmail.com>
Will Hirsch <chromium@willhirsch.co.uk> Will Hirsch <chromium@willhirsch.co.uk>
Will Shackleton <w.shackleton@gmail.com> Will Shackleton <w.shackleton@gmail.com>
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <stdint.h> #include <stdint.h>
#include <tuple> #include <tuple>
#include "base/barrier_closure.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/files/scoped_temp_dir.h" #include "base/files/scoped_temp_dir.h"
...@@ -57,63 +58,59 @@ namespace { ...@@ -57,63 +58,59 @@ namespace {
void SaveRegistrationCallback( void SaveRegistrationCallback(
blink::ServiceWorkerStatusCode expected_status, blink::ServiceWorkerStatusCode expected_status,
bool* called,
scoped_refptr<ServiceWorkerRegistration>* registration_out, scoped_refptr<ServiceWorkerRegistration>* registration_out,
base::OnceClosure quit_closure,
blink::ServiceWorkerStatusCode status, blink::ServiceWorkerStatusCode status,
const std::string& status_message, const std::string& status_message,
ServiceWorkerRegistration* registration) { ServiceWorkerRegistration* registration) {
EXPECT_EQ(expected_status, status); EXPECT_EQ(expected_status, status);
*called = true;
*registration_out = registration; *registration_out = registration;
std::move(quit_closure).Run();
} }
void SaveFoundRegistrationCallback( void SaveFoundRegistrationCallback(
blink::ServiceWorkerStatusCode expected_status, blink::ServiceWorkerStatusCode expected_status,
bool* called,
scoped_refptr<ServiceWorkerRegistration>* registration, scoped_refptr<ServiceWorkerRegistration>* registration,
base::OnceClosure quit_closure,
blink::ServiceWorkerStatusCode status, blink::ServiceWorkerStatusCode status,
scoped_refptr<ServiceWorkerRegistration> result) { scoped_refptr<ServiceWorkerRegistration> result) {
EXPECT_EQ(expected_status, status); EXPECT_EQ(expected_status, status);
*called = true;
*registration = std::move(result); *registration = std::move(result);
std::move(quit_closure).Run();
} }
// Creates a callback which both keeps track of if it's been called, // Creates a callback which keeps track of the resulting registration.
// as well as the resulting registration. Whent the callback is fired, // When the callback is fired, it ensures that the resulting status
// it ensures that the resulting status matches the expectation. // matches the expectation.
// 'called' is useful for making sure a sychronous callback is or
// isn't called.
ServiceWorkerRegisterJob::RegistrationCallback SaveRegistration( ServiceWorkerRegisterJob::RegistrationCallback SaveRegistration(
blink::ServiceWorkerStatusCode expected_status, blink::ServiceWorkerStatusCode expected_status,
bool* called, scoped_refptr<ServiceWorkerRegistration>* registration,
scoped_refptr<ServiceWorkerRegistration>* registration) { base::OnceClosure quit_closure) {
*called = false; return base::BindOnce(&SaveRegistrationCallback, expected_status,
return base::BindOnce(&SaveRegistrationCallback, expected_status, called, registration, std::move(quit_closure));
registration);
} }
ServiceWorkerStorage::FindRegistrationCallback SaveFoundRegistration( ServiceWorkerStorage::FindRegistrationCallback SaveFoundRegistration(
blink::ServiceWorkerStatusCode expected_status, blink::ServiceWorkerStatusCode expected_status,
bool* called, scoped_refptr<ServiceWorkerRegistration>* registration,
scoped_refptr<ServiceWorkerRegistration>* registration) { base::OnceClosure quit_closure) {
*called = false; return base::BindOnce(&SaveFoundRegistrationCallback, expected_status,
return base::BindOnce(&SaveFoundRegistrationCallback, expected_status, called, registration, std::move(quit_closure));
registration);
} }
void SaveUnregistrationCallback(blink::ServiceWorkerStatusCode expected_status, void SaveUnregistrationCallback(blink::ServiceWorkerStatusCode expected_status,
bool* called, base::OnceClosure quit_closure,
int64_t registration_id, int64_t registration_id,
blink::ServiceWorkerStatusCode status) { blink::ServiceWorkerStatusCode status) {
EXPECT_EQ(expected_status, status); EXPECT_EQ(expected_status, status);
*called = true; std::move(quit_closure).Run();
} }
ServiceWorkerUnregisterJob::UnregistrationCallback SaveUnregistration( ServiceWorkerUnregisterJob::UnregistrationCallback SaveUnregistration(
blink::ServiceWorkerStatusCode expected_status, blink::ServiceWorkerStatusCode expected_status,
bool* called) { base::OnceClosure quit_closure) {
*called = false; return base::BindOnce(&SaveUnregistrationCallback, expected_status,
return base::BindOnce(&SaveUnregistrationCallback, expected_status, called); std::move(quit_closure));
} }
void RequestTermination( void RequestTermination(
...@@ -168,39 +165,33 @@ scoped_refptr<ServiceWorkerRegistration> ServiceWorkerJobTest::RunRegisterJob( ...@@ -168,39 +165,33 @@ scoped_refptr<ServiceWorkerRegistration> ServiceWorkerJobTest::RunRegisterJob(
const blink::mojom::ServiceWorkerRegistrationOptions& options, const blink::mojom::ServiceWorkerRegistrationOptions& options,
blink::ServiceWorkerStatusCode expected_status) { blink::ServiceWorkerStatusCode expected_status) {
scoped_refptr<ServiceWorkerRegistration> registration; scoped_refptr<ServiceWorkerRegistration> registration;
bool called; base::RunLoop run_loop;
job_coordinator()->Register( job_coordinator()->Register(
script_url, options, script_url, options,
SaveRegistration(expected_status, &called, &registration)); SaveRegistration(expected_status, &registration, run_loop.QuitClosure()));
EXPECT_FALSE(called); run_loop.Run();
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(called);
return registration; return registration;
} }
void ServiceWorkerJobTest::RunUnregisterJob( void ServiceWorkerJobTest::RunUnregisterJob(
const GURL& scope, const GURL& scope,
blink::ServiceWorkerStatusCode expected_status) { blink::ServiceWorkerStatusCode expected_status) {
bool called; base::RunLoop run_loop;
job_coordinator()->Unregister(scope, job_coordinator()->Unregister(
SaveUnregistration(expected_status, &called)); scope, SaveUnregistration(expected_status, run_loop.QuitClosure()));
EXPECT_FALSE(called); run_loop.Run();
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(called);
} }
scoped_refptr<ServiceWorkerRegistration> scoped_refptr<ServiceWorkerRegistration>
ServiceWorkerJobTest::FindRegistrationForScope( ServiceWorkerJobTest::FindRegistrationForScope(
const GURL& scope, const GURL& scope,
blink::ServiceWorkerStatusCode expected_status) { blink::ServiceWorkerStatusCode expected_status) {
bool called;
scoped_refptr<ServiceWorkerRegistration> registration; scoped_refptr<ServiceWorkerRegistration> registration;
base::RunLoop run_loop;
storage()->FindRegistrationForScope( storage()->FindRegistrationForScope(
scope, SaveFoundRegistration(expected_status, &called, &registration)); scope, SaveFoundRegistration(expected_status, &registration,
run_loop.QuitClosure()));
EXPECT_FALSE(called); run_loop.Run();
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(called);
return registration; return registration;
} }
...@@ -219,26 +210,26 @@ TEST_F(ServiceWorkerJobTest, SameDocumentSameRegistration) { ...@@ -219,26 +210,26 @@ TEST_F(ServiceWorkerJobTest, SameDocumentSameRegistration) {
scoped_refptr<ServiceWorkerRegistration> original_registration = scoped_refptr<ServiceWorkerRegistration> original_registration =
RunRegisterJob(GURL("https://www.example.com/service_worker.js"), RunRegisterJob(GURL("https://www.example.com/service_worker.js"),
options); options);
bool called;
scoped_refptr<ServiceWorkerRegistration> registration1; scoped_refptr<ServiceWorkerRegistration> registration1;
base::RunLoop run_loop;
base::RepeatingClosure barrier_closure =
base::BarrierClosure(2, run_loop.QuitClosure());
storage()->FindRegistrationForDocument( storage()->FindRegistrationForDocument(
GURL("https://www.example.com/"), GURL("https://www.example.com/"),
SaveFoundRegistration(blink::ServiceWorkerStatusCode::kOk, &called, SaveFoundRegistration(blink::ServiceWorkerStatusCode::kOk, &registration1,
&registration1)); barrier_closure));
scoped_refptr<ServiceWorkerRegistration> registration2; scoped_refptr<ServiceWorkerRegistration> registration2;
storage()->FindRegistrationForDocument( storage()->FindRegistrationForDocument(
GURL("https://www.example.com/"), GURL("https://www.example.com/"),
SaveFoundRegistration(blink::ServiceWorkerStatusCode::kOk, &called, SaveFoundRegistration(blink::ServiceWorkerStatusCode::kOk, &registration2,
&registration2)); barrier_closure));
base::RunLoop().RunUntilIdle(); run_loop.Run();
EXPECT_TRUE(called);
ASSERT_TRUE(registration1.get()); ASSERT_TRUE(registration1.get());
ASSERT_EQ(registration1, original_registration); ASSERT_EQ(registration1, original_registration);
ASSERT_EQ(registration1, registration2); ASSERT_EQ(registration1, registration2);
} }
TEST_F(ServiceWorkerJobTest, SameMatchSameRegistration) { TEST_F(ServiceWorkerJobTest, SameMatchSameRegistration) {
bool called;
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = GURL("https://www.example.com/"); options.scope = GURL("https://www.example.com/");
scoped_refptr<ServiceWorkerRegistration> original_registration = scoped_refptr<ServiceWorkerRegistration> original_registration =
...@@ -248,63 +239,49 @@ TEST_F(ServiceWorkerJobTest, SameMatchSameRegistration) { ...@@ -248,63 +239,49 @@ TEST_F(ServiceWorkerJobTest, SameMatchSameRegistration) {
original_registration.get()); original_registration.get());
scoped_refptr<ServiceWorkerRegistration> registration1; scoped_refptr<ServiceWorkerRegistration> registration1;
base::RunLoop run_loop;
base::RepeatingClosure barrier_closure =
base::BarrierClosure(2, run_loop.QuitClosure());
storage()->FindRegistrationForDocument( storage()->FindRegistrationForDocument(
GURL("https://www.example.com/one"), GURL("https://www.example.com/one"),
SaveFoundRegistration(blink::ServiceWorkerStatusCode::kOk, &called, SaveFoundRegistration(blink::ServiceWorkerStatusCode::kOk, &registration1,
&registration1)); barrier_closure));
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(called);
scoped_refptr<ServiceWorkerRegistration> registration2; scoped_refptr<ServiceWorkerRegistration> registration2;
storage()->FindRegistrationForDocument( storage()->FindRegistrationForDocument(
GURL("https://www.example.com/two"), GURL("https://www.example.com/two"),
SaveFoundRegistration(blink::ServiceWorkerStatusCode::kOk, &called, SaveFoundRegistration(blink::ServiceWorkerStatusCode::kOk, &registration2,
&registration2)); barrier_closure));
base::RunLoop().RunUntilIdle(); run_loop.Run();
EXPECT_TRUE(called);
ASSERT_EQ(registration1, original_registration); ASSERT_EQ(registration1, original_registration);
ASSERT_EQ(registration1, registration2); ASSERT_EQ(registration1, registration2);
} }
TEST_F(ServiceWorkerJobTest, DifferentMatchDifferentRegistration) { TEST_F(ServiceWorkerJobTest, DifferentMatchDifferentRegistration) {
bool called1; const GURL scope1("https://www.example.com/one");
const GURL scope2("https://www.example.com/two");
const GURL script_url("https://www.example.com/service_worker.js");
blink::mojom::ServiceWorkerRegistrationOptions options1; blink::mojom::ServiceWorkerRegistrationOptions options1;
options1.scope = GURL("https://www.example.com/one/"); options1.scope = scope1;
scoped_refptr<ServiceWorkerRegistration> original_registration1;
job_coordinator()->Register(
GURL("https://www.example.com/service_worker.js"), options1,
SaveRegistration(blink::ServiceWorkerStatusCode::kOk, &called1,
&original_registration1));
bool called2;
blink::mojom::ServiceWorkerRegistrationOptions options2; blink::mojom::ServiceWorkerRegistrationOptions options2;
options2.scope = GURL("https://www.example.com/two/"); options2.scope = scope2;
scoped_refptr<ServiceWorkerRegistration> original_registration2;
job_coordinator()->Register(
GURL("https://www.example.com/service_worker.js"), options2,
SaveRegistration(blink::ServiceWorkerStatusCode::kOk, &called2,
&original_registration2));
EXPECT_FALSE(called1); RunRegisterJob(script_url, options1);
EXPECT_FALSE(called2); RunRegisterJob(script_url, options2);
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(called2);
EXPECT_TRUE(called1);
scoped_refptr<ServiceWorkerRegistration> registration1; scoped_refptr<ServiceWorkerRegistration> registration1;
base::RunLoop run_loop;
base::RepeatingClosure barrier_closure =
base::BarrierClosure(2, run_loop.QuitClosure());
storage()->FindRegistrationForDocument( storage()->FindRegistrationForDocument(
GURL("https://www.example.com/one/"), scope1, SaveFoundRegistration(blink::ServiceWorkerStatusCode::kOk,
SaveFoundRegistration(blink::ServiceWorkerStatusCode::kOk, &called1, &registration1, barrier_closure));
&registration1));
scoped_refptr<ServiceWorkerRegistration> registration2; scoped_refptr<ServiceWorkerRegistration> registration2;
storage()->FindRegistrationForDocument( storage()->FindRegistrationForDocument(
GURL("https://www.example.com/two/"), scope2, SaveFoundRegistration(blink::ServiceWorkerStatusCode::kOk,
SaveFoundRegistration(blink::ServiceWorkerStatusCode::kOk, &called2, &registration2, barrier_closure));
&registration2));
base::RunLoop().RunUntilIdle(); run_loop.Run();
EXPECT_TRUE(called2);
EXPECT_TRUE(called1);
ASSERT_NE(registration1, registration2); ASSERT_NE(registration1, registration2);
} }
...@@ -345,6 +322,8 @@ TEST_F(ServiceWorkerJobTest, Register) { ...@@ -345,6 +322,8 @@ TEST_F(ServiceWorkerJobTest, Register) {
helper_.get()); helper_.get());
scoped_refptr<ServiceWorkerRegistration> registration = RunRegisterJob( scoped_refptr<ServiceWorkerRegistration> registration = RunRegisterJob(
GURL("https://www.example.com/service_worker.js"), options); GURL("https://www.example.com/service_worker.js"), options);
// Wait until the worker becomes active.
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(registration); EXPECT_TRUE(registration);
ASSERT_EQ(2u, worker->events().size()); ASSERT_EQ(2u, worker->events().size());
...@@ -358,6 +337,8 @@ TEST_F(ServiceWorkerJobTest, Unregister) { ...@@ -358,6 +337,8 @@ TEST_F(ServiceWorkerJobTest, Unregister) {
options.scope = GURL("https://www.example.com/"); options.scope = GURL("https://www.example.com/");
scoped_refptr<ServiceWorkerRegistration> registration = RunRegisterJob( scoped_refptr<ServiceWorkerRegistration> registration = RunRegisterJob(
GURL("https://www.example.com/service_worker.js"), options); GURL("https://www.example.com/service_worker.js"), options);
// Wait until the worker becomes active.
base::RunLoop().RunUntilIdle();
scoped_refptr<ServiceWorkerVersion> version = registration->active_version(); scoped_refptr<ServiceWorkerVersion> version = registration->active_version();
ServiceWorkerProviderHost* provider_host = ServiceWorkerProviderHost* provider_host =
...@@ -371,6 +352,8 @@ TEST_F(ServiceWorkerJobTest, Unregister) { ...@@ -371,6 +352,8 @@ TEST_F(ServiceWorkerJobTest, Unregister) {
EXPECT_EQ(1UL, provider_host->service_worker_object_hosts_.size()); EXPECT_EQ(1UL, provider_host->service_worker_object_hosts_.size());
RunUnregisterJob(options.scope); RunUnregisterJob(options.scope);
// Wait until the worker becomes redundant.
base::RunLoop().RunUntilIdle();
// The service worker registration object host and service worker object host // The service worker registration object host and service worker object host
// have been destroyed together with |provider_host| by the above // have been destroyed together with |provider_host| by the above
...@@ -401,6 +384,8 @@ TEST_F(ServiceWorkerJobTest, RegisterNewScript) { ...@@ -401,6 +384,8 @@ TEST_F(ServiceWorkerJobTest, RegisterNewScript) {
scoped_refptr<ServiceWorkerRegistration> old_registration = RunRegisterJob( scoped_refptr<ServiceWorkerRegistration> old_registration = RunRegisterJob(
GURL("https://www.example.com/service_worker.js"), options); GURL("https://www.example.com/service_worker.js"), options);
// Wait until the worker becomes active.
base::RunLoop().RunUntilIdle();
scoped_refptr<ServiceWorkerRegistration> old_registration_by_scope = scoped_refptr<ServiceWorkerRegistration> old_registration_by_scope =
FindRegistrationForScope(options.scope); FindRegistrationForScope(options.scope);
...@@ -428,6 +413,8 @@ TEST_F(ServiceWorkerJobTest, RegisterDuplicateScript) { ...@@ -428,6 +413,8 @@ TEST_F(ServiceWorkerJobTest, RegisterDuplicateScript) {
scoped_refptr<ServiceWorkerRegistration> old_registration = scoped_refptr<ServiceWorkerRegistration> old_registration =
RunRegisterJob(script_url, options); RunRegisterJob(script_url, options);
// Wait until the worker becomes active.
base::RunLoop().RunUntilIdle();
// During the above registration, a service worker registration object host // During the above registration, a service worker registration object host
// for ServiceWorkerGlobalScope#registration has been created/added into // for ServiceWorkerGlobalScope#registration has been created/added into
...@@ -493,24 +480,10 @@ TEST_F(ServiceWorkerJobTest, ParallelRegUnreg) { ...@@ -493,24 +480,10 @@ TEST_F(ServiceWorkerJobTest, ParallelRegUnreg) {
GURL script_url("https://www.example.com/service_worker.js"); GURL script_url("https://www.example.com/service_worker.js");
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = GURL("https://www.example.com/"); options.scope = GURL("https://www.example.com/");
scoped_refptr<ServiceWorkerRegistration> registration =
RunRegisterJob(script_url, options);
bool registration_called = false; RunUnregisterJob(options.scope);
scoped_refptr<ServiceWorkerRegistration> registration;
job_coordinator()->Register(
script_url, options,
SaveRegistration(blink::ServiceWorkerStatusCode::kOk,
&registration_called, &registration));
bool unregistration_called = false;
job_coordinator()->Unregister(
options.scope, SaveUnregistration(blink::ServiceWorkerStatusCode::kOk,
&unregistration_called));
ASSERT_FALSE(registration_called);
ASSERT_FALSE(unregistration_called);
base::RunLoop().RunUntilIdle();
ASSERT_TRUE(registration_called);
ASSERT_TRUE(unregistration_called);
registration = FindRegistrationForScope( registration = FindRegistrationForScope(
options.scope, blink::ServiceWorkerStatusCode::kErrorNotFound); options.scope, blink::ServiceWorkerStatusCode::kErrorNotFound);
...@@ -525,32 +498,16 @@ TEST_F(ServiceWorkerJobTest, ParallelRegNewScript) { ...@@ -525,32 +498,16 @@ TEST_F(ServiceWorkerJobTest, ParallelRegNewScript) {
GURL scope("https://www.example.com/"); GURL scope("https://www.example.com/");
GURL script_url1("https://www.example.com/service_worker1.js"); GURL script_url1("https://www.example.com/service_worker1.js");
bool registration1_called = false; scoped_refptr<ServiceWorkerRegistration> registration1 = RunRegisterJob(
scoped_refptr<ServiceWorkerRegistration> registration1; script_url1, blink::mojom::ServiceWorkerRegistrationOptions(
job_coordinator()->Register( scope, blink::mojom::ScriptType::kClassic,
script_url1, blink::mojom::ServiceWorkerUpdateViaCache::kNone));
blink::mojom::ServiceWorkerRegistrationOptions(
scope, blink::mojom::ScriptType::kClassic,
blink::mojom::ServiceWorkerUpdateViaCache::kNone),
SaveRegistration(blink::ServiceWorkerStatusCode::kOk,
&registration1_called, &registration1));
GURL script_url2("https://www.example.com/service_worker2.js"); GURL script_url2("https://www.example.com/service_worker2.js");
bool registration2_called = false; scoped_refptr<ServiceWorkerRegistration> registration2 = RunRegisterJob(
scoped_refptr<ServiceWorkerRegistration> registration2; script_url2, blink::mojom::ServiceWorkerRegistrationOptions(
job_coordinator()->Register( scope, blink::mojom::ScriptType::kClassic,
script_url2, blink::mojom::ServiceWorkerUpdateViaCache::kAll));
blink::mojom::ServiceWorkerRegistrationOptions(
scope, blink::mojom::ScriptType::kClassic,
blink::mojom::ServiceWorkerUpdateViaCache::kAll),
SaveRegistration(blink::ServiceWorkerStatusCode::kOk,
&registration2_called, &registration2));
ASSERT_FALSE(registration1_called);
ASSERT_FALSE(registration2_called);
base::RunLoop().RunUntilIdle();
ASSERT_TRUE(registration1_called);
ASSERT_TRUE(registration2_called);
scoped_refptr<ServiceWorkerRegistration> registration = scoped_refptr<ServiceWorkerRegistration> registration =
FindRegistrationForScope(scope); FindRegistrationForScope(scope);
...@@ -566,25 +523,11 @@ TEST_F(ServiceWorkerJobTest, ParallelRegSameScript) { ...@@ -566,25 +523,11 @@ TEST_F(ServiceWorkerJobTest, ParallelRegSameScript) {
options.scope = GURL("https://www.example.com/"); options.scope = GURL("https://www.example.com/");
GURL script_url("https://www.example.com/service_worker1.js"); GURL script_url("https://www.example.com/service_worker1.js");
bool registration1_called = false; scoped_refptr<ServiceWorkerRegistration> registration1 =
scoped_refptr<ServiceWorkerRegistration> registration1; RunRegisterJob(script_url, options);
job_coordinator()->Register(
script_url, options,
SaveRegistration(blink::ServiceWorkerStatusCode::kOk,
&registration1_called, &registration1));
bool registration2_called = false;
scoped_refptr<ServiceWorkerRegistration> registration2;
job_coordinator()->Register(
script_url, options,
SaveRegistration(blink::ServiceWorkerStatusCode::kOk,
&registration2_called, &registration2));
ASSERT_FALSE(registration1_called); scoped_refptr<ServiceWorkerRegistration> registration2 =
ASSERT_FALSE(registration2_called); RunRegisterJob(script_url, options);
base::RunLoop().RunUntilIdle();
ASSERT_TRUE(registration1_called);
ASSERT_TRUE(registration2_called);
ASSERT_EQ(registration1, registration2); ASSERT_EQ(registration1, registration2);
...@@ -599,21 +542,9 @@ TEST_F(ServiceWorkerJobTest, ParallelUnreg) { ...@@ -599,21 +542,9 @@ TEST_F(ServiceWorkerJobTest, ParallelUnreg) {
GURL scope("https://www.example.com/"); GURL scope("https://www.example.com/");
GURL script_url("https://www.example.com/service_worker.js"); GURL script_url("https://www.example.com/service_worker.js");
bool unregistration1_called = false; RunUnregisterJob(scope, blink::ServiceWorkerStatusCode::kErrorNotFound);
job_coordinator()->Unregister(
scope, SaveUnregistration(blink::ServiceWorkerStatusCode::kErrorNotFound,
&unregistration1_called));
bool unregistration2_called = false;
job_coordinator()->Unregister(
scope, SaveUnregistration(blink::ServiceWorkerStatusCode::kErrorNotFound,
&unregistration2_called));
ASSERT_FALSE(unregistration1_called); RunUnregisterJob(scope, blink::ServiceWorkerStatusCode::kErrorNotFound);
ASSERT_FALSE(unregistration2_called);
base::RunLoop().RunUntilIdle();
ASSERT_TRUE(unregistration1_called);
ASSERT_TRUE(unregistration2_called);
// There isn't really a way to test that they are being coalesced, // There isn't really a way to test that they are being coalesced,
// but we can make sure they can exist simultaneously without // but we can make sure they can exist simultaneously without
...@@ -634,43 +565,31 @@ TEST_F(ServiceWorkerJobTest, AbortAll_Register) { ...@@ -634,43 +565,31 @@ TEST_F(ServiceWorkerJobTest, AbortAll_Register) {
blink::mojom::ServiceWorkerRegistrationOptions options2; blink::mojom::ServiceWorkerRegistrationOptions options2;
options2.scope = GURL("https://www2.example.com/"); options2.scope = GURL("https://www2.example.com/");
bool registration_called1 = false;
scoped_refptr<ServiceWorkerRegistration> registration1; scoped_refptr<ServiceWorkerRegistration> registration1;
base::RunLoop run_loop;
base::RepeatingClosure barrier_closure =
base::BarrierClosure(2, run_loop.QuitClosure());
job_coordinator()->Register( job_coordinator()->Register(
script_url1, options1, script_url1, options1,
SaveRegistration(blink::ServiceWorkerStatusCode::kErrorAbort, SaveRegistration(blink::ServiceWorkerStatusCode::kErrorAbort,
&registration_called1, &registration1)); &registration1, barrier_closure));
bool registration_called2 = false;
scoped_refptr<ServiceWorkerRegistration> registration2; scoped_refptr<ServiceWorkerRegistration> registration2;
job_coordinator()->Register( job_coordinator()->Register(
script_url2, options2, script_url2, options2,
SaveRegistration(blink::ServiceWorkerStatusCode::kErrorAbort, SaveRegistration(blink::ServiceWorkerStatusCode::kErrorAbort,
&registration_called2, &registration2)); &registration2, barrier_closure));
ASSERT_FALSE(registration_called1);
ASSERT_FALSE(registration_called2);
job_coordinator()->AbortAll(); job_coordinator()->AbortAll();
base::RunLoop().RunUntilIdle(); run_loop.Run();
ASSERT_TRUE(registration_called1);
ASSERT_TRUE(registration_called2);
bool find_called1 = false; registration1 = FindRegistrationForScope(
storage()->FindRegistrationForScope( options1.scope, blink::ServiceWorkerStatusCode::kErrorNotFound);
options1.scope,
SaveFoundRegistration(blink::ServiceWorkerStatusCode::kErrorNotFound,
&find_called1, &registration1));
bool find_called2 = false; registration2 = FindRegistrationForScope(
storage()->FindRegistrationForScope( options2.scope, blink::ServiceWorkerStatusCode::kErrorNotFound);
options2.scope,
SaveFoundRegistration(blink::ServiceWorkerStatusCode::kErrorNotFound,
&find_called2, &registration2));
base::RunLoop().RunUntilIdle();
ASSERT_TRUE(find_called1);
ASSERT_TRUE(find_called2);
EXPECT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration1); EXPECT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration1);
EXPECT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration2); EXPECT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration2);
} }
...@@ -679,24 +598,21 @@ TEST_F(ServiceWorkerJobTest, AbortAll_Unregister) { ...@@ -679,24 +598,21 @@ TEST_F(ServiceWorkerJobTest, AbortAll_Unregister) {
GURL scope1("https://www1.example.com/"); GURL scope1("https://www1.example.com/");
GURL scope2("https://www2.example.com/"); GURL scope2("https://www2.example.com/");
bool unregistration_called1 = false;
scoped_refptr<ServiceWorkerRegistration> registration1; scoped_refptr<ServiceWorkerRegistration> registration1;
base::RunLoop run_loop;
base::RepeatingClosure barrier_closure =
base::BarrierClosure(2, run_loop.QuitClosure());
job_coordinator()->Unregister( job_coordinator()->Unregister(
scope1, SaveUnregistration(blink::ServiceWorkerStatusCode::kErrorAbort, scope1, SaveUnregistration(blink::ServiceWorkerStatusCode::kErrorAbort,
&unregistration_called1)); barrier_closure));
bool unregistration_called2 = false;
job_coordinator()->Unregister( job_coordinator()->Unregister(
scope2, SaveUnregistration(blink::ServiceWorkerStatusCode::kErrorAbort, scope2, SaveUnregistration(blink::ServiceWorkerStatusCode::kErrorAbort,
&unregistration_called2)); barrier_closure));
ASSERT_FALSE(unregistration_called1);
ASSERT_FALSE(unregistration_called2);
job_coordinator()->AbortAll(); job_coordinator()->AbortAll();
base::RunLoop().RunUntilIdle(); run_loop.Run();
ASSERT_TRUE(unregistration_called1);
ASSERT_TRUE(unregistration_called2);
} }
TEST_F(ServiceWorkerJobTest, AbortAll_RegUnreg) { TEST_F(ServiceWorkerJobTest, AbortAll_RegUnreg) {
...@@ -704,26 +620,23 @@ TEST_F(ServiceWorkerJobTest, AbortAll_RegUnreg) { ...@@ -704,26 +620,23 @@ TEST_F(ServiceWorkerJobTest, AbortAll_RegUnreg) {
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = GURL("https://www.example.com/"); options.scope = GURL("https://www.example.com/");
bool registration_called = false;
scoped_refptr<ServiceWorkerRegistration> registration; scoped_refptr<ServiceWorkerRegistration> registration;
base::RunLoop run_loop;
base::RepeatingClosure barrier_closure =
base::BarrierClosure(2, run_loop.QuitClosure());
job_coordinator()->Register( job_coordinator()->Register(
script_url, options, script_url, options,
SaveRegistration(blink::ServiceWorkerStatusCode::kErrorAbort, SaveRegistration(blink::ServiceWorkerStatusCode::kErrorAbort,
&registration_called, &registration)); &registration, barrier_closure));
bool unregistration_called = false;
job_coordinator()->Unregister( job_coordinator()->Unregister(
options.scope, options.scope,
SaveUnregistration(blink::ServiceWorkerStatusCode::kErrorAbort, SaveUnregistration(blink::ServiceWorkerStatusCode::kErrorAbort,
&unregistration_called)); barrier_closure));
ASSERT_FALSE(registration_called);
ASSERT_FALSE(unregistration_called);
job_coordinator()->AbortAll(); job_coordinator()->AbortAll();
base::RunLoop().RunUntilIdle(); run_loop.Run();
ASSERT_TRUE(registration_called);
ASSERT_TRUE(unregistration_called);
registration = FindRegistrationForScope( registration = FindRegistrationForScope(
options.scope, blink::ServiceWorkerStatusCode::kErrorNotFound); options.scope, blink::ServiceWorkerStatusCode::kErrorNotFound);
...@@ -738,27 +651,24 @@ TEST_F(ServiceWorkerJobTest, AbortScope) { ...@@ -738,27 +651,24 @@ TEST_F(ServiceWorkerJobTest, AbortScope) {
blink::mojom::ServiceWorkerRegistrationOptions options2; blink::mojom::ServiceWorkerRegistrationOptions options2;
options2.scope = GURL("https://www.example.com/2"); options2.scope = GURL("https://www.example.com/2");
bool registration1_called = false;
scoped_refptr<ServiceWorkerRegistration> registration1; scoped_refptr<ServiceWorkerRegistration> registration1;
base::RunLoop run_loop;
base::RepeatingClosure barrier_closure =
base::BarrierClosure(2, run_loop.QuitClosure());
job_coordinator()->Register( job_coordinator()->Register(
script_url, options1, script_url, options1,
SaveRegistration(blink::ServiceWorkerStatusCode::kErrorAbort, SaveRegistration(blink::ServiceWorkerStatusCode::kErrorAbort,
&registration1_called, &registration1)); &registration1, barrier_closure));
bool registration2_called = false;
scoped_refptr<ServiceWorkerRegistration> registration2; scoped_refptr<ServiceWorkerRegistration> registration2;
job_coordinator()->Register( job_coordinator()->Register(
script_url, options2, script_url, options2,
SaveRegistration(blink::ServiceWorkerStatusCode::kOk, SaveRegistration(blink::ServiceWorkerStatusCode::kOk, &registration2,
&registration2_called, &registration2)); barrier_closure));
ASSERT_FALSE(registration1_called);
ASSERT_FALSE(registration2_called);
job_coordinator()->Abort(options1.scope); job_coordinator()->Abort(options1.scope);
base::RunLoop().RunUntilIdle(); run_loop.Run();
ASSERT_TRUE(registration1_called);
ASSERT_TRUE(registration2_called);
registration1 = FindRegistrationForScope( registration1 = FindRegistrationForScope(
options1.scope, blink::ServiceWorkerStatusCode::kErrorNotFound); options1.scope, blink::ServiceWorkerStatusCode::kErrorNotFound);
...@@ -800,6 +710,8 @@ TEST_F(ServiceWorkerJobTest, UnregisterWaitingSetsRedundant) { ...@@ -800,6 +710,8 @@ TEST_F(ServiceWorkerJobTest, UnregisterWaitingSetsRedundant) {
EXPECT_EQ(ServiceWorkerVersion::INSTALLED, version->status()); EXPECT_EQ(ServiceWorkerVersion::INSTALLED, version->status());
RunUnregisterJob(GURL("https://www.example.com/")); RunUnregisterJob(GURL("https://www.example.com/"));
// Wait until the worker becomes redundant.
base::RunLoop().RunUntilIdle();
// The version should be stopped since there is no controllee after // The version should be stopped since there is no controllee after
// unregistration. // unregistration.
...@@ -814,6 +726,8 @@ TEST_F(ServiceWorkerJobTest, UnregisterActiveSetsRedundant) { ...@@ -814,6 +726,8 @@ TEST_F(ServiceWorkerJobTest, UnregisterActiveSetsRedundant) {
options.scope = GURL("https://www.example.com/"); options.scope = GURL("https://www.example.com/");
scoped_refptr<ServiceWorkerRegistration> registration = RunRegisterJob( scoped_refptr<ServiceWorkerRegistration> registration = RunRegisterJob(
GURL("https://www.example.com/service_worker.js"), options); GURL("https://www.example.com/service_worker.js"), options);
// Wait until the worker becomes active.
base::RunLoop().RunUntilIdle();
ASSERT_TRUE(registration.get()); ASSERT_TRUE(registration.get());
scoped_refptr<ServiceWorkerVersion> version = registration->active_version(); scoped_refptr<ServiceWorkerVersion> version = registration->active_version();
...@@ -821,6 +735,8 @@ TEST_F(ServiceWorkerJobTest, UnregisterActiveSetsRedundant) { ...@@ -821,6 +735,8 @@ TEST_F(ServiceWorkerJobTest, UnregisterActiveSetsRedundant) {
EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status()); EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status());
RunUnregisterJob(GURL("https://www.example.com/")); RunUnregisterJob(GURL("https://www.example.com/"));
// Wait until the worker becomes redundant.
base::RunLoop().RunUntilIdle();
// The version should be stopped since there is no controllee after // The version should be stopped since there is no controllee after
// unregistration. // unregistration.
...@@ -836,6 +752,8 @@ TEST_F(ServiceWorkerJobTest, ...@@ -836,6 +752,8 @@ TEST_F(ServiceWorkerJobTest,
options.scope = GURL("https://www.example.com/"); options.scope = GURL("https://www.example.com/");
scoped_refptr<ServiceWorkerRegistration> registration = RunRegisterJob( scoped_refptr<ServiceWorkerRegistration> registration = RunRegisterJob(
GURL("https://www.example.com/service_worker.js"), options); GURL("https://www.example.com/service_worker.js"), options);
// Wait until the worker becomes active.
base::RunLoop().RunUntilIdle();
ASSERT_TRUE(registration.get()); ASSERT_TRUE(registration.get());
ServiceWorkerProviderHost* host = CreateControllee(); ServiceWorkerProviderHost* host = CreateControllee();
...@@ -852,6 +770,7 @@ TEST_F(ServiceWorkerJobTest, ...@@ -852,6 +770,7 @@ TEST_F(ServiceWorkerJobTest,
EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status()); EXPECT_EQ(ServiceWorkerVersion::ACTIVATED, version->status());
registration->active_version()->RemoveControllee(host->client_uuid()); registration->active_version()->RemoveControllee(host->client_uuid());
// Wait until the worker becomes redundant.
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
// The version should be stopped since there is no controllee. // The version should be stopped since there is no controllee.
...@@ -870,6 +789,8 @@ TEST_F(ServiceWorkerJobTest, RegisterWhileUninstalling) { ...@@ -870,6 +789,8 @@ TEST_F(ServiceWorkerJobTest, RegisterWhileUninstalling) {
helper_.get()); helper_.get());
scoped_refptr<ServiceWorkerRegistration> registration = scoped_refptr<ServiceWorkerRegistration> registration =
RunRegisterJob(script1, options); RunRegisterJob(script1, options);
// Wait until the worker becomes active.
base::RunLoop().RunUntilIdle();
auto runner = base::MakeRefCounted<base::TestSimpleTaskRunner>(); auto runner = base::MakeRefCounted<base::TestSimpleTaskRunner>();
registration->SetTaskRunnerForTest(runner); registration->SetTaskRunnerForTest(runner);
...@@ -882,6 +803,8 @@ TEST_F(ServiceWorkerJobTest, RegisterWhileUninstalling) { ...@@ -882,6 +803,8 @@ TEST_F(ServiceWorkerJobTest, RegisterWhileUninstalling) {
// Register another script. // Register another script.
EXPECT_EQ(registration, RunRegisterJob(script2, options)); EXPECT_EQ(registration, RunRegisterJob(script2, options));
// Wait until the worker becomes installed.
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(registration->is_uninstalling()); EXPECT_FALSE(registration->is_uninstalling());
EXPECT_EQ(old_version, registration->active_version()); EXPECT_EQ(old_version, registration->active_version());
...@@ -919,6 +842,8 @@ TEST_F(ServiceWorkerJobTest, RegisterAndUnregisterWhileUninstalling) { ...@@ -919,6 +842,8 @@ TEST_F(ServiceWorkerJobTest, RegisterAndUnregisterWhileUninstalling) {
scoped_refptr<ServiceWorkerRegistration> registration = scoped_refptr<ServiceWorkerRegistration> registration =
RunRegisterJob(script1, options); RunRegisterJob(script1, options);
// Wait until the worker becomes active.
base::RunLoop().RunUntilIdle();
// Add a controllee and queue an unregister to force the uninstalling state. // Add a controllee and queue an unregister to force the uninstalling state.
ServiceWorkerProviderHost* host = CreateControllee(); ServiceWorkerProviderHost* host = CreateControllee();
...@@ -928,6 +853,8 @@ TEST_F(ServiceWorkerJobTest, RegisterAndUnregisterWhileUninstalling) { ...@@ -928,6 +853,8 @@ TEST_F(ServiceWorkerJobTest, RegisterAndUnregisterWhileUninstalling) {
RunUnregisterJob(options.scope); RunUnregisterJob(options.scope);
EXPECT_EQ(registration, RunRegisterJob(script2, options)); EXPECT_EQ(registration, RunRegisterJob(script2, options));
// Wait until the worker becomes installed.
base::RunLoop().RunUntilIdle();
EXPECT_EQ(registration, FindRegistrationForScope(options.scope)); EXPECT_EQ(registration, FindRegistrationForScope(options.scope));
scoped_refptr<ServiceWorkerVersion> new_version = scoped_refptr<ServiceWorkerVersion> new_version =
...@@ -951,6 +878,7 @@ TEST_F(ServiceWorkerJobTest, RegisterAndUnregisterWhileUninstalling) { ...@@ -951,6 +878,7 @@ TEST_F(ServiceWorkerJobTest, RegisterAndUnregisterWhileUninstalling) {
EXPECT_EQ(ServiceWorkerVersion::INSTALLED, new_version->status()); EXPECT_EQ(ServiceWorkerVersion::INSTALLED, new_version->status());
old_version->RemoveControllee(host->client_uuid()); old_version->RemoveControllee(host->client_uuid());
// Wait until the worker becomes redundant.
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_FALSE(registration->is_uninstalling()); EXPECT_FALSE(registration->is_uninstalling());
...@@ -973,6 +901,8 @@ TEST_F(ServiceWorkerJobTest, RegisterSameScriptMultipleTimesWhileUninstalling) { ...@@ -973,6 +901,8 @@ TEST_F(ServiceWorkerJobTest, RegisterSameScriptMultipleTimesWhileUninstalling) {
helper_.get()); helper_.get());
scoped_refptr<ServiceWorkerRegistration> registration = scoped_refptr<ServiceWorkerRegistration> registration =
RunRegisterJob(script1, options); RunRegisterJob(script1, options);
// Wait until the worker becomes active.
base::RunLoop().RunUntilIdle();
auto runner = base::MakeRefCounted<base::TestSimpleTaskRunner>(); auto runner = base::MakeRefCounted<base::TestSimpleTaskRunner>();
registration->SetTaskRunnerForTest(runner); registration->SetTaskRunnerForTest(runner);
...@@ -984,6 +914,8 @@ TEST_F(ServiceWorkerJobTest, RegisterSameScriptMultipleTimesWhileUninstalling) { ...@@ -984,6 +914,8 @@ TEST_F(ServiceWorkerJobTest, RegisterSameScriptMultipleTimesWhileUninstalling) {
RunUnregisterJob(options.scope); RunUnregisterJob(options.scope);
EXPECT_EQ(registration, RunRegisterJob(script2, options)); EXPECT_EQ(registration, RunRegisterJob(script2, options));
// Wait until the worker becomes installed.
base::RunLoop().RunUntilIdle();
scoped_refptr<ServiceWorkerVersion> new_version = scoped_refptr<ServiceWorkerVersion> new_version =
registration->waiting_version(); registration->waiting_version();
...@@ -1046,6 +978,8 @@ TEST_F(ServiceWorkerJobTest, HasFetchHandler) { ...@@ -1046,6 +978,8 @@ TEST_F(ServiceWorkerJobTest, HasFetchHandler) {
helper_->AddNewPendingServiceWorker<FetchHandlerWorker>(helper_.get()); helper_->AddNewPendingServiceWorker<FetchHandlerWorker>(helper_.get());
fetch_handler_worker->set_has_fetch_handler(true); fetch_handler_worker->set_has_fetch_handler(true);
RunRegisterJob(script, options); RunRegisterJob(script, options);
// Wait until the worker becomes active.
base::RunLoop().RunUntilIdle();
registration = FindRegistrationForScope(options.scope); registration = FindRegistrationForScope(options.scope);
EXPECT_EQ(ServiceWorkerVersion::FetchHandlerExistence::EXISTS, EXPECT_EQ(ServiceWorkerVersion::FetchHandlerExistence::EXISTS,
registration->active_version()->fetch_handler_existence()); registration->active_version()->fetch_handler_existence());
...@@ -1055,6 +989,8 @@ TEST_F(ServiceWorkerJobTest, HasFetchHandler) { ...@@ -1055,6 +989,8 @@ TEST_F(ServiceWorkerJobTest, HasFetchHandler) {
helper_->AddNewPendingServiceWorker<FetchHandlerWorker>(helper_.get()); helper_->AddNewPendingServiceWorker<FetchHandlerWorker>(helper_.get());
no_fetch_handler_worker->set_has_fetch_handler(false); no_fetch_handler_worker->set_has_fetch_handler(false);
RunRegisterJob(script, options); RunRegisterJob(script, options);
// Wait until the worker becomes active.
base::RunLoop().RunUntilIdle();
registration = FindRegistrationForScope(options.scope); registration = FindRegistrationForScope(options.scope);
EXPECT_EQ(ServiceWorkerVersion::FetchHandlerExistence::DOES_NOT_EXIST, EXPECT_EQ(ServiceWorkerVersion::FetchHandlerExistence::DOES_NOT_EXIST,
registration->active_version()->fetch_handler_existence()); registration->active_version()->fetch_handler_existence());
...@@ -1224,18 +1160,18 @@ class UpdateJobTestHelper : public EmbeddedWorkerTestHelper, ...@@ -1224,18 +1160,18 @@ class UpdateJobTestHelper : public EmbeddedWorkerTestHelper,
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = test_origin.Resolve(kScope); options.scope = test_origin.Resolve(kScope);
scoped_refptr<ServiceWorkerRegistration> registration; scoped_refptr<ServiceWorkerRegistration> registration;
bool called = false;
auto client = std::make_unique<UpdateJobEmbeddedWorkerInstanceClient>(this); auto client = std::make_unique<UpdateJobEmbeddedWorkerInstanceClient>(this);
initial_embedded_worker_instance_client_ = client.get(); initial_embedded_worker_instance_client_ = client.get();
AddPendingInstanceClient(std::move(client)); AddPendingInstanceClient(std::move(client));
base::RunLoop run_loop;
job_coordinator()->Register( job_coordinator()->Register(
test_origin.Resolve(kScript), options, test_origin.Resolve(kScript), options,
SaveRegistration(blink::ServiceWorkerStatusCode::kOk, &called, SaveRegistration(blink::ServiceWorkerStatusCode::kOk, &registration,
&registration)); run_loop.QuitClosure()));
run_loop.Run();
// Wait until the worker becomes active.
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_TRUE(called);
EXPECT_TRUE(registration.get()); EXPECT_TRUE(registration.get());
EXPECT_TRUE(registration->active_version()); EXPECT_TRUE(registration->active_version());
EXPECT_FALSE(registration->installing_version()); EXPECT_FALSE(registration->installing_version());
...@@ -1389,6 +1325,8 @@ TEST_P(ServiceWorkerUpdateJobTest, RegisterWithDifferentUpdateViaCache) { ...@@ -1389,6 +1325,8 @@ TEST_P(ServiceWorkerUpdateJobTest, RegisterWithDifferentUpdateViaCache) {
scoped_refptr<ServiceWorkerRegistration> old_registration = scoped_refptr<ServiceWorkerRegistration> old_registration =
RunRegisterJob(script_url, options); RunRegisterJob(script_url, options);
// Wait until the worker becomes active.
base::RunLoop().RunUntilIdle();
EXPECT_EQ(blink::mojom::ServiceWorkerUpdateViaCache::kImports, EXPECT_EQ(blink::mojom::ServiceWorkerUpdateViaCache::kImports,
old_registration->update_via_cache()); old_registration->update_via_cache());
...@@ -1759,6 +1697,8 @@ TEST_P(ServiceWorkerUpdateJobTest, Update_ScriptUrlChanged) { ...@@ -1759,6 +1697,8 @@ TEST_P(ServiceWorkerUpdateJobTest, Update_ScriptUrlChanged) {
} }
scoped_refptr<ServiceWorkerRegistration> registration = scoped_refptr<ServiceWorkerRegistration> registration =
RunRegisterJob(old_script, options); RunRegisterJob(old_script, options);
// Wait until the worker becomes active.
base::RunLoop().RunUntilIdle();
auto runner = base::MakeRefCounted<base::TestSimpleTaskRunner>(); auto runner = base::MakeRefCounted<base::TestSimpleTaskRunner>();
registration->SetTaskRunnerForTest(runner); registration->SetTaskRunnerForTest(runner);
...@@ -1850,24 +1790,25 @@ TEST_P(ServiceWorkerUpdateJobTest, Update_EvictedIncumbent) { ...@@ -1850,24 +1790,25 @@ TEST_P(ServiceWorkerUpdateJobTest, Update_EvictedIncumbent) {
TEST_P(ServiceWorkerUpdateJobTest, Update_UninstallingRegistration) { TEST_P(ServiceWorkerUpdateJobTest, Update_UninstallingRegistration) {
blink::mojom::ServiceWorkerRegistrationOptions options; blink::mojom::ServiceWorkerRegistrationOptions options;
options.scope = GURL("https://www.example.com/one/"); options.scope = GURL("https://www.example.com/one/");
bool called;
scoped_refptr<ServiceWorkerRegistration> registration = RunRegisterJob( scoped_refptr<ServiceWorkerRegistration> registration = RunRegisterJob(
GURL("https://www.example.com/service_worker.js"), options); GURL("https://www.example.com/service_worker.js"), options);
// Wait until the worker becomes active.
base::RunLoop().RunUntilIdle();
// Add a controllee and queue an unregister to force the uninstalling state. // Add a controllee and queue an unregister to force the uninstalling state.
ServiceWorkerProviderHost* host = CreateControllee(); ServiceWorkerProviderHost* host = CreateControllee();
ServiceWorkerVersion* active_version = registration->active_version(); ServiceWorkerVersion* active_version = registration->active_version();
active_version->AddControllee(host); active_version->AddControllee(host);
base::RunLoop run_loop;
job_coordinator()->Unregister( job_coordinator()->Unregister(
GURL("https://www.example.com/one/"), GURL("https://www.example.com/one/"),
SaveUnregistration(blink::ServiceWorkerStatusCode::kOk, &called)); SaveUnregistration(blink::ServiceWorkerStatusCode::kOk,
run_loop.QuitClosure()));
// Update should abort after it starts and sees uninstalling. // Update should abort after it starts and sees uninstalling.
job_coordinator()->Update(registration.get(), false); job_coordinator()->Update(registration.get(), false);
EXPECT_FALSE(called); run_loop.Run();
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(called);
// Verify the registration was not modified by the Update. // Verify the registration was not modified by the Update.
EXPECT_TRUE(registration->is_uninstalling()); EXPECT_TRUE(registration->is_uninstalling());
...@@ -1888,6 +1829,8 @@ TEST_P(ServiceWorkerUpdateJobTest, RegisterMultipleTimesWhileUninstalling) { ...@@ -1888,6 +1829,8 @@ TEST_P(ServiceWorkerUpdateJobTest, RegisterMultipleTimesWhileUninstalling) {
helper_.get()); helper_.get());
scoped_refptr<ServiceWorkerRegistration> registration = scoped_refptr<ServiceWorkerRegistration> registration =
RunRegisterJob(script1, options); RunRegisterJob(script1, options);
// Wait until the worker becomes actvie.
base::RunLoop().RunUntilIdle();
auto runner = base::MakeRefCounted<base::TestSimpleTaskRunner>(); auto runner = base::MakeRefCounted<base::TestSimpleTaskRunner>();
registration->SetTaskRunnerForTest(runner); registration->SetTaskRunnerForTest(runner);
...@@ -1899,6 +1842,8 @@ TEST_P(ServiceWorkerUpdateJobTest, RegisterMultipleTimesWhileUninstalling) { ...@@ -1899,6 +1842,8 @@ TEST_P(ServiceWorkerUpdateJobTest, RegisterMultipleTimesWhileUninstalling) {
RunUnregisterJob(options.scope); RunUnregisterJob(options.scope);
EXPECT_EQ(registration, RunRegisterJob(script2, options)); EXPECT_EQ(registration, RunRegisterJob(script2, options));
// Wait until the worker becomes installed.
base::RunLoop().RunUntilIdle();
scoped_refptr<ServiceWorkerVersion> second_version = scoped_refptr<ServiceWorkerVersion> second_version =
registration->waiting_version(); registration->waiting_version();
...@@ -1909,6 +1854,8 @@ TEST_P(ServiceWorkerUpdateJobTest, RegisterMultipleTimesWhileUninstalling) { ...@@ -1909,6 +1854,8 @@ TEST_P(ServiceWorkerUpdateJobTest, RegisterMultipleTimesWhileUninstalling) {
EXPECT_TRUE(registration->is_uninstalling()); EXPECT_TRUE(registration->is_uninstalling());
EXPECT_EQ(registration, RunRegisterJob(script3, options)); EXPECT_EQ(registration, RunRegisterJob(script3, options));
// Wait until the worker becomes redundant.
base::RunLoop().RunUntilIdle();
scoped_refptr<ServiceWorkerVersion> third_version = scoped_refptr<ServiceWorkerVersion> third_version =
registration->waiting_version(); registration->waiting_version();
...@@ -1999,6 +1946,8 @@ TEST_P(ServiceWorkerUpdateJobTest, ActivateCancelsOnShutdown) { ...@@ -1999,6 +1946,8 @@ TEST_P(ServiceWorkerUpdateJobTest, ActivateCancelsOnShutdown) {
helper_.get()); helper_.get());
scoped_refptr<ServiceWorkerRegistration> registration = scoped_refptr<ServiceWorkerRegistration> registration =
RunRegisterJob(script, options); RunRegisterJob(script, options);
// Wait until the worker becomes active.
base::RunLoop().RunUntilIdle();
auto runner = base::MakeRefCounted<base::TestSimpleTaskRunner>(); auto runner = base::MakeRefCounted<base::TestSimpleTaskRunner>();
registration->SetTaskRunnerForTest(runner); registration->SetTaskRunnerForTest(runner);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment