Commit 55e0d390 authored by Jason Chase's avatar Jason Chase Committed by Commit Bot

Remove workaround for Web Components v0 trial for headless clients

In [1], we implemented a workaround to re-enable WebComponents V0 in
headless, regardless if any valid origin trial tokens are present. That
workaround has been merged to M80. In [2], we implemented a fix so that
origin trials are properly supported in headless (that is intended for
merge to M81).

This CL removes the workaround, as it is no longer needed. It also
implements a basic test to verify that trials are working in headless,
and specifically the WebComponents V0 trial.

[1] https://chromium-review.googlesource.com/c/chromium/src/+/2039601
[2] https://chromium-review.googlesource.com/c/chromium/src/+/2042382

Bug: 1049126
Change-Id: Ie118f2d53a535ff8cb8f9f1644b866298e57f036
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2042689Reviewed-by: default avatarJason Chase <chasej@chromium.org>
Reviewed-by: default avatarJohannes Henkel <johannes@chromium.org>
Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Reviewed-by: default avatarMason Freed <masonfreed@chromium.org>
Commit-Queue: Jason Chase <chasej@chromium.org>
Cr-Commit-Position: refs/heads/master@{#741632}
parent 7157ac80
......@@ -624,6 +624,7 @@ test("headless_browsertests") {
"lib/headless_browser_browsertest.cc",
"lib/headless_browser_context_browsertest.cc",
"lib/headless_devtools_client_browsertest.cc",
"lib/headless_origin_trials_browsertest.cc",
"lib/headless_web_contents_browsertest.cc",
"test/headless_browser_test.cc",
"test/headless_browser_test.h",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/strings/strcat.h"
#include "base/test/bind_test_util.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/url_loader_interceptor.h"
#include "headless/public/headless_browser.h"
#include "headless/public/headless_web_contents.h"
#include "headless/test/headless_browser_test.h"
using content::URLLoaderInterceptor;
namespace {
constexpr char kBaseDataDir[] = "headless/test/data/";
} // namespace
namespace headless {
class HeadlessOriginTrialsBrowserTest : public HeadlessBrowserTest {
public:
HeadlessOriginTrialsBrowserTest() = default;
~HeadlessOriginTrialsBrowserTest() override = default;
void SetUpOnMainThread() override {
HeadlessBrowserTest::SetUpOnMainThread();
// We use a URLLoaderInterceptor, rather than the EmbeddedTestServer, since
// the origin trial token in the response is associated with a fixed
// origin, whereas EmbeddedTestServer serves content on a random port.
url_loader_interceptor_ =
std::make_unique<URLLoaderInterceptor>(base::BindLambdaForTesting(
[&](URLLoaderInterceptor::RequestParams* params) -> bool {
URLLoaderInterceptor::WriteResponse(
base::StrCat(
{kBaseDataDir, params->url_request.url.path_piece()}),
params->client.get());
return true;
}));
}
void TearDownOnMainThread() override {
url_loader_interceptor_.reset();
HeadlessBrowserTest::TearDownOnMainThread();
}
private:
std::unique_ptr<URLLoaderInterceptor> url_loader_interceptor_;
DISALLOW_COPY_AND_ASSIGN(HeadlessOriginTrialsBrowserTest);
};
IN_PROC_BROWSER_TEST_F(HeadlessOriginTrialsBrowserTest, TrialsCanBeEnabled) {
HeadlessBrowserContext* browser_context =
browser()->CreateBrowserContextBuilder().Build();
// TODO(crbug.com/1050190): Implement a permanent, sample trial so this test
// doesn't rely on WebComponents V0, which will eventually go away.
HeadlessWebContents* web_contents =
browser_context->CreateWebContentsBuilder()
.SetInitialURL(
GURL("https://example.test/origin_trial_webcomponentsv0.html"))
.Build();
EXPECT_TRUE(WaitForLoad(web_contents));
// Ensure we can call createShadowRoot(), which is only available when the
// WebComponents V0 origin trial is enabled.
EXPECT_TRUE(EvaluateScript(web_contents,
"document.createElement('div').createShadowRoot() "
"instanceof ShadowRoot")
->GetResult()
->GetValue()
->GetBool());
}
IN_PROC_BROWSER_TEST_F(HeadlessOriginTrialsBrowserTest,
TrialsDisabledByDefault) {
HeadlessBrowserContext* browser_context =
browser()->CreateBrowserContextBuilder().Build();
HeadlessWebContents* web_contents =
browser_context->CreateWebContentsBuilder()
.SetInitialURL(GURL("https://example.test/no_origin_trial.html"))
.Build();
EXPECT_TRUE(WaitForLoad(web_contents));
// Ensures that createShadowRoot() is not defined, as no token is provided to
// enable the WebComponents V0 origin trial.
// TODO(crbug.com/1050190): Implement a permanent, sample trial so this test
// doesn't rely on WebComponents V0, which will eventually go away.
EXPECT_FALSE(
EvaluateScript(web_contents,
"'createShadowRoot' in document.createElement('div')")
->GetResult()
->GetValue()
->GetBool());
}
IN_PROC_BROWSER_TEST_F(HeadlessOriginTrialsBrowserTest,
WebComponentsV0CustomElements) {
HeadlessBrowserContext* browser_context =
browser()->CreateBrowserContextBuilder().Build();
HeadlessWebContents* web_contents =
browser_context->CreateWebContentsBuilder()
.SetInitialURL(
GURL("https://example.test/origin_trial_webcomponentsv0.html"))
.Build();
EXPECT_TRUE(WaitForLoad(web_contents));
// Ensure we can call registerElement(), which is only available when the
// WebComponents V0 origin trial is enabled.
EXPECT_EQ(
"function",
EvaluateScript(web_contents, "typeof document.registerElement('my-tag')")
->GetResult()
->GetValue()
->GetString());
}
} // namespace headless
......@@ -19,12 +19,6 @@ HeadlessContentRendererClient::HeadlessContentRendererClient() = default;
HeadlessContentRendererClient::~HeadlessContentRendererClient() = default;
bool HeadlessContentRendererClient::RequiresWebComponentsV0(const GURL& url) {
// TODO(1049126): Headless clients do not (yet) support origin trials.
// In the meantime, re-enable Web Components v0 on all headless clients.
return true;
}
void HeadlessContentRendererClient::RenderFrameCreated(
content::RenderFrame* render_frame) {
#if BUILDFLAG(ENABLE_PRINTING)
......
......@@ -14,8 +14,6 @@ class HeadlessContentRendererClient : public content::ContentRendererClient {
HeadlessContentRendererClient();
~HeadlessContentRendererClient() override;
bool RequiresWebComponentsV0(const GURL& url) override;
private:
void RenderFrameCreated(content::RenderFrame* render_frame) override;
......
<!doctype html>
<html>
<head>
<title>No origin trial token test</title>
</head>
</html>
<!doctype html>
<html>
<head>
<!-- TODO(chasej): Remove this test when the WebComponents V0 trial is removed
from the codebase.
This is a prod token, obtained from the OT dashboard:
- origin: https://example.test
- expires: Feb 1, 2021
-->
<meta http-equiv="origin-trial"
content="Ai7WRBi2kKZ7ig5P2N0g/IsnbnLi9YYmacJUKGhTTd+NMOVqrNSVJi5LbbGA6UfwaPftCYw+8z2rAEaScC+BiQ0AAABVeyJvcmlnaW4iOiJodHRwczovL2V4YW1wbGUudGVzdDo0NDMiLCJmZWF0dXJlIjoiV2ViQ29tcG9uZW50c1YwIiwiZXhwaXJ5IjoxNjEyMjIzOTk5fQ==">
</head>
</html>
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