Commit a11d775b authored by Hiroki Nakagawa's avatar Hiroki Nakagawa Committed by Commit Bot

ServiceWorker: Add the const qualifier to ServiceWorkerProviderHost::is_parent_frame_secure_

The field was non-const because one test lazily initialized it. This CL tweaks
the test setup routine and removes the lazy initialization.

Bug: n/a
Change-Id: Ib12ac76919dda20dfc7d708283e61d6ff1217b2c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1900519Reviewed-by: default avatarMakoto Shimazu <shimazu@chromium.org>
Commit-Queue: Hiroki Nakagawa <nhiroki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#712921}
parent 2c68ddb9
......@@ -89,12 +89,10 @@ class ServiceWorkerControlleeRequestHandlerTest : public testing::Test {
ServiceWorkerControlleeRequestHandlerTest()
: task_environment_(BrowserTaskEnvironment::IO_MAINLOOP) {}
void SetUp() override {
SetUpWithHelper(new EmbeddedWorkerTestHelper(base::FilePath()));
}
void SetUp() override { SetUpWithHelper(/*is_parent_frame_secure=*/true); }
void SetUpWithHelper(EmbeddedWorkerTestHelper* helper) {
helper_.reset(helper);
void SetUpWithHelper(bool is_parent_frame_secure) {
helper_.reset(new EmbeddedWorkerTestHelper(base::FilePath()));
// A new unstored registration/version.
scope_ = GURL("https://host/scope/");
......@@ -120,7 +118,7 @@ class ServiceWorkerControlleeRequestHandlerTest : public testing::Test {
// An empty host.
remote_endpoints_.emplace_back();
provider_host_ = CreateProviderHostForWindow(
helper_->mock_render_process_id(), true /* is_parent_frame_secure */,
helper_->mock_render_process_id(), is_parent_frame_secure,
helper_->context()->AsWeakPtr(), &remote_endpoints_.back());
}
......@@ -132,11 +130,6 @@ class ServiceWorkerControlleeRequestHandlerTest : public testing::Test {
ServiceWorkerContextCore* context() const { return helper_->context(); }
void SetProviderHostIsSecure(ServiceWorkerProviderHost* host,
bool is_secure) {
host->is_parent_frame_secure_ = is_secure;
}
protected:
BrowserTaskEnvironment task_environment_;
std::unique_ptr<EmbeddedWorkerTestHelper> helper_;
......@@ -285,6 +278,9 @@ TEST_F(ServiceWorkerControlleeRequestHandlerTest, DisallowServiceWorker) {
}
TEST_F(ServiceWorkerControlleeRequestHandlerTest, InsecureContext) {
// Reset the provider host as insecure.
SetUpWithHelper(/*is_parent_frame_secure=*/false);
// Store an activated worker.
version_->set_fetch_handler_existence(
ServiceWorkerVersion::FetchHandlerExistence::EXISTS);
......@@ -294,8 +290,6 @@ TEST_F(ServiceWorkerControlleeRequestHandlerTest, InsecureContext) {
base::DoNothing());
base::RunLoop().RunUntilIdle();
SetProviderHostIsSecure(provider_host_.get(), false);
// Conduct a main resource load.
ServiceWorkerRequestTestResources test_resources(
this, GURL("https://host/scope/doc"), ResourceType::kMainFrame);
......
......@@ -473,8 +473,6 @@ class CONTENT_EXPORT ServiceWorkerProviderHost
friend class LinkHeaderServiceWorkerTest;
friend class ServiceWorkerProviderHostTest;
friend class ServiceWorkerWriteToCacheJobTest;
friend class service_worker_controllee_request_handler_unittest::
ServiceWorkerControlleeRequestHandlerTest;
friend class service_worker_object_host_unittest::ServiceWorkerObjectHostTest;
FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWriteToCacheJobTest, Update_SameScript);
FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWriteToCacheJobTest,
......@@ -664,9 +662,7 @@ class CONTENT_EXPORT ServiceWorkerProviderHost
// whose scheme is granted an exception that allows bypassing the ancestor
// secure context check. If the provider is not created for a document, or the
// document does not have a parent frame, is_parent_frame_secure_| is true.
// TODO(leonhsl): make it be const, currently only some test code wants to
// change its value.
bool is_parent_frame_secure_;
const bool is_parent_frame_secure_;
// FrameTreeNode id if this is a service worker window client.
// Otherwise, |FrameTreeNode::kFrameTreeNodeInvalidId|.
......
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