Skip to content

Commit

Permalink
Deflake color tests by lazily printing test results (3x faster)
Browse files Browse the repository at this point in the history
The color parser tests are slow because they have an O(n^2) pattern of
measuring elements in the page, then adding test results to the page in a
loop. This loop gets slower over time as the measurement step needs to
re-measure more and more elements. This patch adds some experimental
logic to js-test.js for lazily printing test results. If this pans out
we can investigate enabling this by default for all js-tests.

Before patch:
 css-parser/color3.html - 326ms
 css-parser/color3_hsl.html - 2344ms
 css-parser/color3_hsla_1.html - 3668ms
 css-parser/color3_hsla_2.html - 3765ms
 css-parser/color3_keywords.html - 1897ms

With patch:
 css-parser/color3.html - 138ms
 css-parser/color3_hsl.html - 718ms
 css-parser/color3_hsla_1.html - 1071ms
 css-parser/color3_hsla_2.html - 1124ms
 css-parser/color3_keywords.html - 616ms

TBR=leviw
BUG=435733

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

git-svn-id: svn://svn.chromium.org/blink/trunk@185924 bbb929c8-8fbe-4397-9dbb-9b2b20218538
  • Loading branch information
progers committed Nov 25, 2014
1 parent a2d25c2 commit f80c8d9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

function loadJson(path) {
var xhr = new XMLHttpRequest();
xhr.open("GET", path, false);
Expand Down Expand Up @@ -48,6 +47,8 @@ function escapeString(string) {
}

ColorTest.prototype.run = function() {
setPrintTestResultsLazily();

// This is a hack to make getComputedstyle work.
this.parentElement = document.createElement("foo");
this.testElement = document.createElement("bar");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ CONSOLE ERROR: Refused to evaluate a string as JavaScript because 'unsafe-eval'

CONSOLE ERROR: 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 222: 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 231: 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
35 changes: 32 additions & 3 deletions third_party/WebKit/LayoutTests/resources/js-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// js-test now supports lazily printing test results which dumps all test
// 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().

// svg/dynamic-updates tests set enablePixelTesting=true, as we want to dump text + pixel results
if (self.testRunner) {
if (self.enablePixelTesting)
Expand Down Expand Up @@ -53,9 +58,13 @@ var unexpectedErrorMessage; // set by onerror when expectingError is not true

debug = function debug(msg)
{
var span = document.createElement("span");
getOrCreate("console", "div").appendChild(span); // insert it first so XHTML knows the namespace
span.innerHTML = msg + '<br />';
if (self._lazyTestResults) {
self._lazyTestResults.push(msg);
} else {
var span = document.createElement("span");
getOrCreate("console", "div").appendChild(span); // insert it first so XHTML knows the namespace
span.innerHTML = msg + '<br />';
}
};

var css =
Expand Down Expand Up @@ -720,6 +729,10 @@ function asyncMinorGC(callback) {
setTimeout(callback, 1);
}

function setPrintTestResultsLazily() {
self._lazyTestResults = self._lazyTestResults || [];
}

function isSuccessfullyParsed()
{
// FIXME: Remove this and only report unexpected syntax errors.
Expand All @@ -738,6 +751,22 @@ function finishJSTest()
if (!self.wasPostTestScriptParsed)
return;
isSuccessfullyParsed();

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);
}
self._lazyTestResults.forEach(function(msg) {
var span = document.createElement("span");
span.innerHTML = msg + '<br />';
consoleElement.appendChild(span);
});
}

if (self.jsTestIsAsync && self.testRunner)
testRunner.notifyDone();
}
Expand Down

0 comments on commit f80c8d9

Please sign in to comment.