Commit 7eb361a7 authored by Aran Gilman's avatar Aran Gilman Committed by Commit Bot

Generate test HTML with GetArticleTemplateHtml() at runtime.

This ensures the test reflects changes to the HTML template. Using an
external test HTML file sometimes caused the test to fail after
unrelated changes to the page's JS that happened to reference
elements present in the template HTML but missing from the external
test file.

Currently, this change applies only to
DistillerPageWebContentsTest.TestPinch, but similar tests for other
JS functionality are planned.

Bug: 1027612
Change-Id: Icbfc59e765ac4e6245cb7836da097bce1b36a2d1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1965988
Commit-Queue: Aran Gilman <gilmanmh@google.com>
Reviewed-by: default avatarWei-Yin Chen (陳威尹) <wychen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#724721}
parent 611b5c15
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "content/public/common/isolated_world_ids.h" #include "content/public/common/isolated_world_ids.h"
#include "content/public/test/content_browser_test.h" #include "content/public/test/content_browser_test.h"
#include "content/shell/browser/shell.h" #include "content/shell/browser/shell.h"
#include "net/test/embedded_test_server/controllable_http_response.h"
#include "net/test/embedded_test_server/embedded_test_server.h" #include "net/test/embedded_test_server/embedded_test_server.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "third_party/dom_distiller_js/dom_distiller.pb.h" #include "third_party/dom_distiller_js/dom_distiller.pb.h"
...@@ -135,10 +136,15 @@ class DistillerPageWebContentsTest : public ContentBrowserTest { ...@@ -135,10 +136,15 @@ class DistillerPageWebContentsTest : public ContentBrowserTest {
void SetUpTestServer() { void SetUpTestServer() {
base::FilePath path; base::FilePath path;
base::PathService::Get(base::DIR_SOURCE_ROOT, &path); base::PathService::Get(base::DIR_SOURCE_ROOT, &path);
embedded_test_server()->ServeFilesFromDirectory( embedded_test_server()->ServeFilesFromDirectory(
path.AppendASCII("components/test/data/dom_distiller")); path.AppendASCII("components/test/data/dom_distiller"));
embedded_test_server()->ServeFilesFromDirectory( embedded_test_server()->ServeFilesFromDirectory(
path.AppendASCII("components/dom_distiller/core/javascript")); path.AppendASCII("components/dom_distiller/core/javascript"));
response_ = std::make_unique<net::test_server::ControllableHttpResponse>(
embedded_test_server(), "/pinch_tester.html");
ASSERT_TRUE(embedded_test_server()->Start()); ASSERT_TRUE(embedded_test_server()->Start());
} }
...@@ -150,6 +156,8 @@ class DistillerPageWebContentsTest : public ContentBrowserTest { ...@@ -150,6 +156,8 @@ class DistillerPageWebContentsTest : public ContentBrowserTest {
DistillerPageWebContents* distiller_page_; DistillerPageWebContents* distiller_page_;
std::unique_ptr<proto::DomDistillerResult> distiller_result_; std::unique_ptr<proto::DomDistillerResult> distiller_result_;
base::Value js_result_; base::Value js_result_;
std::unique_ptr<net::test_server::ControllableHttpResponse> response_;
}; };
// Use this class to be able to leak the WebContents, which is needed for when // Use this class to be able to leak the WebContents, which is needed for when
...@@ -527,6 +535,19 @@ IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, MAYBE_TestPinch) { ...@@ -527,6 +535,19 @@ IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, MAYBE_TestPinch) {
web_contents->GetController().LoadURL( web_contents->GetController().LoadURL(
embedded_test_server()->GetURL("/pinch_tester.html"), content::Referrer(), embedded_test_server()->GetURL("/pinch_tester.html"), content::Referrer(),
ui::PAGE_TRANSITION_TYPED, std::string()); ui::PAGE_TRANSITION_TYPED, std::string());
const std::string html_template = viewer::GetArticleTemplateHtml(
DistilledPagePrefs::THEME_LIGHT,
DistilledPagePrefs::FONT_FAMILY_SANS_SERIF);
const std::string scripts = R"(
<script src='dom_distiller_viewer.js'></script>
<script src='pinch_tester.js'></script>
)";
response_->WaitForRequest();
response_->Send(net::HTTP_OK, "text/html", html_template + scripts);
response_->Done();
url_loaded_runner.Run(); url_loaded_runner.Run();
// Execute the JS to run the tests, and wait until it has finished. // Execute the JS to run the tests, and wait until it has finished.
......
<html>
<head>
<meta name="theme-color" id="theme-color">
<title>Test Page for Pinch to Zoom</title>
</head>
<body>
<div id="contentWrap">
<p id="closeReaderView">Original</p>
</div>
<div id="feedbackContainer">
<div id="feedbackYes"></div>
<div id="feedbackNo"></div>
</div>
<script src="dom_distiller_viewer.js"></script>
<script src="pinch_tester.js"></script>
</body>
</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