Skip to content

Commit

Permalink
Fix lazy test result printing.
Browse files Browse the repository at this point in the history
Previously, description() and isSuccessfullyParsed() would add their
results to the top of the document immediately, even if
setPrintTestResultsLazily() was used.  This caused problems for
async tests that relied on precise document offset measurements
(such as the IntersectionObserver tests).

With this change, setPrintTestResultsLazily() will cause *all* test
output to be delayed until finishJSTest().

BUG=540528
R=ojan@chromium.org,esprehn@chromium.org

Review URL: https://codereview.chromium.org/1648123004

Cr-Commit-Position: refs/heads/master@{#372902}
  • Loading branch information
szager-chromium authored and Commit bot committed Feb 2, 2016
1 parent 06c4702 commit 34c8bfd
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CONSOLE ERROR: line 258: Uncaught EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".
CONSOLE ERROR: line 265: Uncaught EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'unsafe-inline'".

CONSOLE ERROR: Refused to load the image 'http://127.0.0.1:8000/security/resources/abe.png' because it violates the following Content Security Policy directive: "img-src 'none'".

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@
// enough to screw with frame offsets that are measured by the test. Delay all that
// jazz until the actual test code is finished.
setPrintTestResultsLazily();
var delayDescription = description;
var descriptionString = "";
var delayIsSuccessfullyParsed = isSuccessfullyParsed;
var isSuccessfullyParsed = function() {}
var description = function(msg) { descriptionString = msg }

if (window.testRunner)
testRunner.waitUntilDone();
self.jsTestIsAsync = true;

function rectToString(rect) {
return "[" + rect.left + ", " + rect.right + ", " + rect.top + ", " + rect.bottom + "]";
Expand All @@ -26,12 +19,3 @@ function entryToString(entry) {
"target=" + entry.target + "\n" +
"time=" + entry.time);
}

function finishTest() {
if (descriptionString)
delayDescription(descriptionString);
delayIsSuccessfullyParsed();
finishJSTest();
if (window.testRunner)
testRunner.notifyDone();
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
shouldBeEqualToNumber("entries[1].rootBounds.top", 0);
shouldBeEqualToNumber("entries[1].rootBounds.bottom", 600);
shouldEvaluateToSameObject("entries[1].target", target);
finishTest();
finishJSTest();
document.scrollingElement.scrollTop = 0;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
shouldBeEqualToNumber("entries[1].rootBounds.top", 608);
shouldBeEqualToNumber("entries[1].rootBounds.bottom", 808);
shouldEvaluateToSameObject("entries[1].target", target);
finishTest();
finishJSTest();
document.scrollingElement.scrollTop = 0;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
shouldBeEqualToNumber("entries[6].rootBounds.top", 0);
shouldBeEqualToNumber("entries[6].rootBounds.bottom", 600);
shouldEvaluateToSameObject("entries[6].target", target);
finishTest();
finishJSTest();
document.scrollingElement.scrollTop = 0;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
shouldBeEqualToNumber("entries[1].rootBounds.bottom", 819);
shouldEvaluateToSameObject("entries[1].target", target);

finishTest();
finishJSTest();
document.scrollingElement.scrollLeft = 0;
document.scrollingElement.scrollTop = 0;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
shouldBeEqualToNumber("entries[1].rootBounds.top", 0);
shouldBeEqualToNumber("entries[1].rootBounds.bottom", 600);
shouldEvaluateToSameObject("entries[1].target", target);
finishTest();
finishJSTest();
document.scrollingElement.scrollTop = 0;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
shouldBeEqualToNumber("entries[2].rootBounds.top", 708);
shouldBeEqualToNumber("entries[2].rootBounds.bottom", 908);
shouldEvaluateToSameObject("entries[2].target", target);
finishTest();
finishJSTest();
});
}

Expand Down
30 changes: 17 additions & 13 deletions third_party/WebKit/LayoutTests/resources/js-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// results once at the end of the test instead of building them up. To enable
// this option, call setPrintTestResultsLazily() before running any tests.
var _lazyTestResults; // Set by setPrintTestResultsLazily().
var _lazyDescription; // Set by description() after setPrintTestResultsLazily().

// svg/dynamic-updates tests set enablePixelTesting=true, as we want to dump text + pixel results
if (self.testRunner) {
Expand All @@ -13,15 +14,15 @@ if (self.testRunner) {

var isJsTest = true;

var description, debug, successfullyParsed;
var description, debug, successfullyParsed, getOrCreateTestElement;

var expectingError; // set by shouldHaveError()
var expectedErrorMessage; // set by onerror when expectingError is true
var unexpectedErrorMessage; // set by onerror when expectingError is not true

(function() {

function getOrCreate(id, tagName)
getOrCreateTestElement = function(id, tagName)
{
var element = document.getElementById(id);
if (element)
Expand All @@ -32,7 +33,7 @@ var unexpectedErrorMessage; // set by onerror when expectingError is not true
var refNode;
var parent = document.body || document.documentElement;
if (id == "description")
refNode = getOrCreate("console", "div");
refNode = getOrCreateTestElement("console", "div");
else
refNode = parent.firstChild;

Expand All @@ -49,7 +50,12 @@ var unexpectedErrorMessage; // set by onerror when expectingError is not true
else
span.innerHTML = '<p>' + msg + '</p><p>On success, you will see a series of "<span class="pass">PASS</span>" messages, followed by "<span class="pass">TEST COMPLETE</span>".</p>';

var description = getOrCreate("description", "p");
if (_lazyTestResults) {
_lazyDescription = span;
return;
}

var description = getOrCreateTestElement("description", "p");
if (description.firstChild)
description.replaceChild(span, description.firstChild);
else
Expand All @@ -62,7 +68,8 @@ var unexpectedErrorMessage; // set by onerror when expectingError is not true
self._lazyTestResults.push(msg);
} else {
var span = document.createElement("span");
getOrCreate("console", "div").appendChild(span); // insert it first so XHTML knows the namespace
// insert it first so XHTML knows the namespace;
getOrCreateTestElement("console", "div").appendChild(span);
span.innerHTML = msg + '<br />';
}
};
Expand Down Expand Up @@ -811,18 +818,15 @@ function finishJSTest()
return;
isSuccessfullyParsed();

if (self._lazyDescription)
getOrCreateTestElement("description", "p").appendChild(self._lazyDescription);

if (self._lazyTestResults && self._lazyTestResults.length > 0) {
var consoleElement = document.getElementById("console");
if (!consoleElement) {
consoleElement = document.createElement("div");
consoleElement.id = "console";
var parent = document.body || document.documentElement;
parent.insertBefore(consoleElement, parent.firstChild);
}
var consoleElement = getOrCreateTestElement("console", "div");
self._lazyTestResults.forEach(function(msg) {
var span = document.createElement("span");
span.innerHTML = msg + '<br />';
consoleElement.appendChild(span);
span.innerHTML = msg + '<br />';
});
}

Expand Down

0 comments on commit 34c8bfd

Please sign in to comment.