Commit 387a6b29 authored by shimazu's avatar shimazu Committed by Commit Bot

ServiceWorker: use the id assigned to the provider host in unittests

In several tests, currently provider's id is assigned to a variable which is
initialized by some random value at the beginning of the test, the provider host
instance is created by using the id, and some other objects are also initialized
by the id. After browser-side SWProviderHost creation, it'll be problematic
because the id will be assigned internally. This patch is to fix the tests by
getting the id from ServiceWorkerProviderHost::provider_id() directly.

This is split off from https://crrev.com/2779763004/ .

BUG=629701, 676983, 668633

Review-Url: https://codereview.chromium.org/2932273002
Cr-Commit-Position: refs/heads/master@{#478560}
parent c3065567
...@@ -146,7 +146,7 @@ class ForeignFetchRequestHandlerTest : public testing::Test { ...@@ -146,7 +146,7 @@ class ForeignFetchRequestHandlerTest : public testing::Test {
request_->set_initiator(url::Origin(GURL(initiator))); request_->set_initiator(url::Origin(GURL(initiator)));
ForeignFetchRequestHandler::InitializeHandler( ForeignFetchRequestHandler::InitializeHandler(
request_.get(), context_wrapper(), &blob_storage_context_, request_.get(), context_wrapper(), &blob_storage_context_,
helper_->mock_render_process_id(), kMockProviderId, helper_->mock_render_process_id(), provider_host()->provider_id(),
ServiceWorkerMode::ALL, FETCH_REQUEST_MODE_CORS, ServiceWorkerMode::ALL, FETCH_REQUEST_MODE_CORS,
FETCH_CREDENTIALS_MODE_OMIT, FetchRedirectMode::FOLLOW_MODE, FETCH_CREDENTIALS_MODE_OMIT, FetchRedirectMode::FOLLOW_MODE,
resource_type, REQUEST_CONTEXT_TYPE_FETCH, resource_type, REQUEST_CONTEXT_TYPE_FETCH,
......
...@@ -94,7 +94,7 @@ class ServiceWorkerRegistrationTest : public testing::Test { ...@@ -94,7 +94,7 @@ class ServiceWorkerRegistrationTest : public testing::Test {
ServiceWorkerRegistrationInfo observed_info_; ServiceWorkerRegistrationInfo observed_info_;
}; };
private: protected:
std::unique_ptr<EmbeddedWorkerTestHelper> helper_; std::unique_ptr<EmbeddedWorkerTestHelper> helper_;
TestBrowserThreadBundle thread_bundle_; TestBrowserThreadBundle thread_bundle_;
}; };
...@@ -257,7 +257,7 @@ class ServiceWorkerActivationTest : public ServiceWorkerRegistrationTest { ...@@ -257,7 +257,7 @@ class ServiceWorkerActivationTest : public ServiceWorkerRegistrationTest {
// Give the active version a controllee. // Give the active version a controllee.
host_ = CreateProviderHostForWindow( host_ = CreateProviderHostForWindow(
33 /* dummy render process id */, 1 /* dummy provider_id */, helper_->mock_render_process_id(), 1 /* dummy provider_id */,
true /* is_parent_frame_secure */, context()->AsWeakPtr(), true /* is_parent_frame_secure */, context()->AsWeakPtr(),
&remote_endpoint_); &remote_endpoint_);
version_1->AddControllee(host_.get()); version_1->AddControllee(host_.get());
......
...@@ -286,7 +286,7 @@ class ServiceWorkerWriteToCacheJobTest : public testing::Test { ...@@ -286,7 +286,7 @@ class ServiceWorkerWriteToCacheJobTest : public testing::Test {
mock_protocol_handler_(nullptr) {} mock_protocol_handler_(nullptr) {}
~ServiceWorkerWriteToCacheJobTest() override {} ~ServiceWorkerWriteToCacheJobTest() override {}
void CreateHostForVersion( base::WeakPtr<ServiceWorkerProviderHost> CreateHostForVersion(
int process_id, int process_id,
int provider_id, int provider_id,
const scoped_refptr<ServiceWorkerVersion>& version) { const scoped_refptr<ServiceWorkerVersion>& version) {
...@@ -297,6 +297,7 @@ class ServiceWorkerWriteToCacheJobTest : public testing::Test { ...@@ -297,6 +297,7 @@ class ServiceWorkerWriteToCacheJobTest : public testing::Test {
base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr(); base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr();
context()->AddProviderHost(std::move(host)); context()->AddProviderHost(std::move(host));
provider_host->running_hosted_version_ = version; provider_host->running_hosted_version_ = version;
return provider_host;
} }
void SetUpScriptRequest(int process_id, int provider_id) { void SetUpScriptRequest(int process_id, int provider_id) {
...@@ -339,9 +340,10 @@ class ServiceWorkerWriteToCacheJobTest : public testing::Test { ...@@ -339,9 +340,10 @@ class ServiceWorkerWriteToCacheJobTest : public testing::Test {
version_ = version_ =
new ServiceWorkerVersion(registration_.get(), script_url_, new ServiceWorkerVersion(registration_.get(), script_url_,
NextVersionId(), context()->AsWeakPtr()); NextVersionId(), context()->AsWeakPtr());
CreateHostForVersion(helper_->mock_render_process_id(), provider_id, base::WeakPtr<ServiceWorkerProviderHost> host = CreateHostForVersion(
version_); helper_->mock_render_process_id(), provider_id, version_);
SetUpScriptRequest(helper_->mock_render_process_id(), provider_id); ASSERT_TRUE(host);
SetUpScriptRequest(helper_->mock_render_process_id(), host->provider_id());
context()->storage()->LazyInitialize(base::Bind(&EmptyCallback)); context()->storage()->LazyInitialize(base::Bind(&EmptyCallback));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -394,10 +396,10 @@ class ServiceWorkerWriteToCacheJobTest : public testing::Test { ...@@ -394,10 +396,10 @@ class ServiceWorkerWriteToCacheJobTest : public testing::Test {
new ServiceWorkerVersion(registration_.get(), script_url_, new ServiceWorkerVersion(registration_.get(), script_url_,
NextVersionId(), context()->AsWeakPtr()); NextVersionId(), context()->AsWeakPtr());
new_version->set_pause_after_download(true); new_version->set_pause_after_download(true);
CreateHostForVersion(helper_->mock_render_process_id(), provider_id, base::WeakPtr<ServiceWorkerProviderHost> host = CreateHostForVersion(
new_version); helper_->mock_render_process_id(), provider_id, new_version);
SetUpScriptRequest(helper_->mock_render_process_id(), provider_id); SetUpScriptRequest(helper_->mock_render_process_id(), host->provider_id());
mock_protocol_handler_->SetCreateJobCallback( mock_protocol_handler_->SetCreateJobCallback(
base::Bind(&CreateResponseJob, response)); base::Bind(&CreateResponseJob, response));
request_->Start(); request_->Start();
......
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