Commit 4d66facc authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

Add mechanism to allow layout test text dump with Element.innerText

Now that we have spec-conformant implementation of Element.innerText,
we should change layout test text dump to use it. To avoid an extra-
large patch rebaselining 10k+ at once, which is vulnerable to test
flakes, we will rebaseline progressively in a per-directory manner.

This patch adds mechanism that chooses which text dump implementation
to use based on the the test path. Actual rebaseline will be done in
follow up patches.

Bug: 887148
Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_layout_ng
Change-Id: I0fe248b20c6a924549aae424990374b18f070027
Reviewed-on: https://chromium-review.googlesource.com/1234874Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593821}
parent 8372329a
...@@ -66,7 +66,9 @@ std::string DumpLayout(WebLocalFrame* frame, ...@@ -66,7 +66,9 @@ std::string DumpLayout(WebLocalFrame* frame,
frame, WebFrameContentDumper::kLayoutAsTextPrinting) frame, WebFrameContentDumper::kLayoutAsTextPrinting)
.Utf8(); .Utf8();
} else { } else {
result += frame->GetDocument().ContentAsTextForTesting().Utf8(); result += frame->GetDocument()
.ContentAsTextForTesting(flags.should_use_inner_text_dump())
.Utf8();
} }
result += "\n"; result += "\n";
} else if (flags.dump_as_markup()) { } else if (flags.dump_as_markup()) {
......
...@@ -190,6 +190,11 @@ class TEST_RUNNER_EXPORT LayoutTestRuntimeFlags { ...@@ -190,6 +190,11 @@ class TEST_RUNNER_EXPORT LayoutTestRuntimeFlags {
// Contains text passed by the test to testRunner.setCustomTextOutput. // Contains text passed by the test to testRunner.setCustomTextOutput.
DEFINE_STRING_LAYOUT_TEST_RUNTIME_FLAG(custom_text_output) DEFINE_STRING_LAYOUT_TEST_RUNTIME_FLAG(custom_text_output)
// Controls which implementation to use for text dump, to help progressive
// rebaseline of layout test text dumps.
// TODO(xiaochengh): Remove this flag when rebaseline is complete.
DEFINE_BOOL_LAYOUT_TEST_RUNTIME_FLAG(should_use_inner_text_dump)
#undef DEFINE_BOOL_LAYOUT_TEST_RUNTIME_FLAG #undef DEFINE_BOOL_LAYOUT_TEST_RUNTIME_FLAG
#undef DEFINE_STRING_LAYOUT_TEST_RUNTIME_FLAG #undef DEFINE_STRING_LAYOUT_TEST_RUNTIME_FLAG
......
...@@ -25,6 +25,17 @@ ...@@ -25,6 +25,17 @@
namespace test_runner { namespace test_runner {
namespace {
bool ShouldUseInnerTextDump(const std::string& test_path) {
// We are switching the text dump implementation to spec-conformant
// Element.innerText. To avoid gigantic patch, we control the rebaseline
// progress here in a per-directory manner.
// TODO(xiaochengh): Progressively allow more tests to use innerText.
// Remove this function once rebaseline is complete.
return false;
}
} // namespace
TestInterfaces::TestInterfaces() TestInterfaces::TestInterfaces()
: gamepad_controller_(new GamepadController()), : gamepad_controller_(new GamepadController()),
test_runner_(new TestRunner(this)), test_runner_(new TestRunner(this)),
...@@ -114,6 +125,9 @@ void TestInterfaces::ConfigureForTestWithURL(const blink::WebURL& test_url, ...@@ -114,6 +125,9 @@ void TestInterfaces::ConfigureForTestWithURL(const blink::WebURL& test_url,
spec.find("/harness-tests/wpt/") != std::string::npos) spec.find("/harness-tests/wpt/") != std::string::npos)
test_runner_->set_is_web_platform_tests_mode(); test_runner_->set_is_web_platform_tests_mode();
const bool should_use_inner_text = ShouldUseInnerTextDump(spec);
test_runner_->SetShouldUseInnerTextDump(should_use_inner_text);
// The actions below should only be done *once* per test. // The actions below should only be done *once* per test.
if (!initial_configuration) if (!initial_configuration)
return; return;
......
...@@ -2437,6 +2437,11 @@ void TestRunner::SetShouldStayOnPageAfterHandlingBeforeUnload(bool value) { ...@@ -2437,6 +2437,11 @@ void TestRunner::SetShouldStayOnPageAfterHandlingBeforeUnload(bool value) {
OnLayoutTestRuntimeFlagsChanged(); OnLayoutTestRuntimeFlagsChanged();
} }
void TestRunner::SetShouldUseInnerTextDump(bool value) {
layout_test_runtime_flags_.set_should_use_inner_text_dump(value);
OnLayoutTestRuntimeFlagsChanged();
}
void TestRunner::SetWillSendRequestClearHeader(const std::string& header) { void TestRunner::SetWillSendRequestClearHeader(const std::string& header) {
if (!header.empty()) if (!header.empty())
http_headers_to_clear_.insert(header); http_headers_to_clear_.insert(header);
......
...@@ -168,6 +168,8 @@ class TestRunner : public WebTestRunner { ...@@ -168,6 +168,8 @@ class TestRunner : public WebTestRunner {
bool ShouldDumpJavaScriptDialogs() const; bool ShouldDumpJavaScriptDialogs() const;
void SetShouldUseInnerTextDump(bool value);
blink::WebEffectiveConnectionType effective_connection_type() const { blink::WebEffectiveConnectionType effective_connection_type() const {
return effective_connection_type_; return effective_connection_type_;
} }
......
...@@ -95,7 +95,13 @@ class WebDocument : public WebNode { ...@@ -95,7 +95,13 @@ class WebDocument : public WebNode {
BLINK_EXPORT WebElement Body() const; BLINK_EXPORT WebElement Body() const;
BLINK_EXPORT WebElement Head(); BLINK_EXPORT WebElement Head();
BLINK_EXPORT WebString Title() const; BLINK_EXPORT WebString Title() const;
BLINK_EXPORT WebString ContentAsTextForTesting() const;
// |use_inner_text| controls which implementation to use for text dump,
// spec-conformant Element.innerText or legacy, to help progressive
// rebaseline of layout test text dumps.
// TODO(xiaochengh): Remove this flag when rebaseline is complete.
BLINK_EXPORT WebString ContentAsTextForTesting(bool use_inner_text) const;
BLINK_EXPORT WebElementCollection All(); BLINK_EXPORT WebElementCollection All();
BLINK_EXPORT void Forms(WebVector<WebFormElement>&) const; BLINK_EXPORT void Forms(WebVector<WebFormElement>&) const;
BLINK_EXPORT WebURL CompleteURL(const WebString&) const; BLINK_EXPORT WebURL CompleteURL(const WebString&) const;
......
...@@ -152,10 +152,13 @@ WebString WebDocument::Title() const { ...@@ -152,10 +152,13 @@ WebString WebDocument::Title() const {
return WebString(ConstUnwrap<Document>()->title()); return WebString(ConstUnwrap<Document>()->title());
} }
WebString WebDocument::ContentAsTextForTesting() const { WebString WebDocument::ContentAsTextForTesting(bool use_inner_text) const {
Element* document_element = ConstUnwrap<Document>()->documentElement(); Element* document_element = ConstUnwrap<Document>()->documentElement();
if (!document_element) if (!document_element)
return WebString(); return WebString();
if (use_inner_text)
return document_element->innerText();
// TODO(editing-dev): We should use |Element::innerText()|. // TODO(editing-dev): We should use |Element::innerText()|.
const_cast<Document*>(ConstUnwrap<Document>()) const_cast<Document*>(ConstUnwrap<Document>())
->UpdateStyleAndLayoutIgnorePendingStylesheetsForNode(document_element); ->UpdateStyleAndLayoutIgnorePendingStylesheetsForNode(document_element);
......
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