Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(314)

Unified Diff: content/shell/test_runner/test_runner.cc

Issue 2729863004: Support reftest-wait in web-platform-tests (Closed)
Patch Set: Add TestExpectations entry Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/TestExpectations » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/shell/test_runner/test_runner.cc
diff --git a/content/shell/test_runner/test_runner.cc b/content/shell/test_runner/test_runner.cc
index bbee54dc0d5d1e32cb6e5fbc1e300168c2db5677..1a02826ac7e5f1aaf33d2a38c6ff4b5bb01a2af3 100644
--- a/content/shell/test_runner/test_runner.cc
+++ b/content/shell/test_runner/test_runner.cc
@@ -99,7 +99,8 @@ class TestRunnerBindings : public gin::Wrappable<TestRunnerBindings> {
static void Install(base::WeakPtr<TestRunner> test_runner,
base::WeakPtr<TestRunnerForSpecificView> view_test_runner,
- WebLocalFrame* frame);
+ WebLocalFrame* frame,
+ bool is_web_platform_tests_mode);
private:
explicit TestRunnerBindings(
@@ -304,7 +305,8 @@ gin::WrapperInfo TestRunnerBindings::kWrapperInfo = {gin::kEmbedderNativeGin};
void TestRunnerBindings::Install(
base::WeakPtr<TestRunner> test_runner,
base::WeakPtr<TestRunnerForSpecificView> view_test_runner,
- WebLocalFrame* frame) {
+ WebLocalFrame* frame,
+ bool is_web_platform_tests_mode) {
v8::Isolate* isolate = blink::mainThreadIsolate();
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Context> context = frame->mainWorldScriptContext();
@@ -327,6 +329,35 @@ void TestRunnerBindings::Install(
names.push_back("layoutTestController");
for (size_t i = 0; i < names.size(); ++i)
global->Set(gin::StringToV8(isolate, names[i].c_str()), v8_bindings);
+
+ // The web-platform-tests suite require that reference comparison is delayed
+ // for any test with a 'reftest-wait' class on the root element, until that
+ // class attribute is removed. To support this approach, we inject some
+ // JavaScript that implements the same behavior using TestRunner.
+ //
+ // See http://web-platform-tests.org/writing-tests/reftests.html for more
+ // details about reference tests in the web-platform-tests suite.
+ if (is_web_platform_tests_mode) {
+ frame->executeScript(blink::WebString(
+ R"(window.addEventListener('load', function() {
+ if (!window.testRunner) {
+ return;
+ }
+ const target = document.documentElement;
+ if (target != null && target.classList.contains('reftest-wait')) {
+ window.testRunner.waitUntilDone();
+ const observer = new MutationObserver(function(mutations) {
+ mutations.forEach(function(mutation) {
+ if (!target.classList.contains('reftest-wait')) {
+ window.testRunner.notifyDone();
+ }
+ });
+ });
+ const config = {attributes: true};
+ observer.observe(target, config);
+ }
+ });)"));
+ }
}
TestRunnerBindings::TestRunnerBindings(
@@ -1626,7 +1657,7 @@ void TestRunner::Install(
WebLocalFrame* frame,
base::WeakPtr<TestRunnerForSpecificView> view_test_runner) {
TestRunnerBindings::Install(weak_factory_.GetWeakPtr(), view_test_runner,
- frame);
+ frame, is_web_platform_tests_mode());
}
void TestRunner::SetDelegate(WebTestDelegate* delegate) {
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/TestExpectations » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698