Title: [143678] trunk/LayoutTests
Revision
143678
Author
[email protected]
Date
2013-02-21 18:29:41 -0800 (Thu, 21 Feb 2013)

Log Message

Add support for testing states changing asynchronously. Apply it to state-url-sets-links-visited.html.
https://bugs.webkit.org/show_bug.cgi?id=109883

Reviewed by Antti Koivisto.

Some tests depends on state change happening asynchronously. This is typically solved by using
timers with a long enough interval.

Timers have the general pitfalls of causing unreliable tests, and forcing unnecessary delays
in the tests.

This patch introduces new testing helpers, shouldBecomeEqual and shouldBecomeEqualToString, to
test a change of state repetively until it succeed (or timeout). Those test functions execute
the condition every 5ms until the test succeed.

The helper shouldBecomeEqualToString is applied on state-url-sets-links-visited.html to illustrate
the concept.

* fast/js/resources/js-test-pre.js:
(_waitForCondition): Generic helper function for the familly shouldBecomeXXX.
(.condition):
(.failureHandler):
(shouldBecomeEqual):
(shouldBecomeEqualToString):

* fast/loader/stateobjects/state-url-sets-links-visited.html:
* platform/wk2/TestExpectations:
state-url-sets-links-visited.html fails on WebKit2 because the visited links table is updated
asynchronously, and the style is only updated after 1 IPC message + 1 timer + 1 IPC message.

The test is changed to use shouldBecomeEqualToString in order to become reliable. If the UIProcess
does not update the style in a reasonable amount of time, the test fails.

Modified Paths

Removed Paths

  • trunk/LayoutTests/platform/chromium-win/fast/loader/stateobjects/
  • trunk/LayoutTests/platform/win/fast/loader/stateobjects/

Diff

Modified: trunk/LayoutTests/ChangeLog (143677 => 143678)


--- trunk/LayoutTests/ChangeLog	2013-02-22 02:10:01 UTC (rev 143677)
+++ trunk/LayoutTests/ChangeLog	2013-02-22 02:29:41 UTC (rev 143678)
@@ -1,3 +1,38 @@
+2013-02-21  Benjamin Poulain  <[email protected]>
+
+        Add support for testing states changing asynchronously. Apply it to state-url-sets-links-visited.html.
+        https://bugs.webkit.org/show_bug.cgi?id=109883
+
+        Reviewed by Antti Koivisto.
+
+        Some tests depends on state change happening asynchronously. This is typically solved by using
+        timers with a long enough interval.
+
+        Timers have the general pitfalls of causing unreliable tests, and forcing unnecessary delays
+        in the tests.
+
+        This patch introduces new testing helpers, shouldBecomeEqual and shouldBecomeEqualToString, to
+        test a change of state repetively until it succeed (or timeout). Those test functions execute
+        the condition every 5ms until the test succeed.
+
+        The helper shouldBecomeEqualToString is applied on state-url-sets-links-visited.html to illustrate
+        the concept.
+
+        * fast/js/resources/js-test-pre.js:
+        (_waitForCondition): Generic helper function for the familly shouldBecomeXXX.
+        (.condition):
+        (.failureHandler):
+        (shouldBecomeEqual):
+        (shouldBecomeEqualToString):
+
+        * fast/loader/stateobjects/state-url-sets-links-visited.html:
+        * platform/wk2/TestExpectations:
+        state-url-sets-links-visited.html fails on WebKit2 because the visited links table is updated
+        asynchronously, and the style is only updated after 1 IPC message + 1 timer + 1 IPC message.
+
+        The test is changed to use shouldBecomeEqualToString in order to become reliable. If the UIProcess
+        does not update the style in a reasonable amount of time, the test fails.
+
 2013-02-21  Adam Barth  <[email protected]>
 
         Threaded HTML Parser fails fast/dom/Document/readystate.html

Modified: trunk/LayoutTests/fast/js/resources/js-test-pre.js (143677 => 143678)


--- trunk/LayoutTests/fast/js/resources/js-test-pre.js	2013-02-22 02:10:01 UTC (rev 143677)
+++ trunk/LayoutTests/fast/js/resources/js-test-pre.js	2013-02-22 02:29:41 UTC (rev 143678)
@@ -188,6 +188,60 @@
     testFailed(_a + " should be " + _bv + " (of type " + typeof _bv + "). Was " + _av + " (of type " + typeof _av + ").");
 }
 
+// Execute condition every 5 milliseconds until it succeed or failureTime is reached.
+// completionHandler is executed on success, failureHandler is executed on timeout.
+function _waitForCondition(condition, failureTime, completionHandler, failureHandler)
+{
+  if (condition()) {
+    completionHandler();
+  } else if (Date() > failureTime) {
+    failureHandler();
+  } else {
+    setTimeout(_waitForCondition, 5, condition, failureTime, completionHandler, failureHandler);
+  }
+}
+
+function shouldBecomeEqual(value, reference, completionHandler, timeout)
+{
+  if (typeof value != "string" || typeof reference != "string")
+    debug("WARN: shouldBe() expects string arguments");
+  var _bv = eval(reference);
+
+  if (timeout === undefined)
+    timeout = 500;
+
+  var condition = function() {
+    var exception;
+    var _av;
+    try {
+      _av = eval(value);
+    } catch (e) {
+      exception = e;
+    }
+    if (exception)
+      testFailed(value + " should become " + _bv + ". Threw exception " + exception);
+    if (isResultCorrect(_av, _bv)) {
+      testPassed(value + " became " + reference);
+      return true;
+    }
+    return false;
+  };
+  var failureTime = new Date() + Date(timeout);
+  var failureHandler = function () {
+    testFailed(value + " failed to change to " + reference + " in " + (timeout / 1000) + " seconds.");
+    completionHandler();
+  };
+  _waitForCondition(condition, failureTime, completionHandler, failureHandler);
+}
+
+function shouldBecomeEqualToString(value, reference, completionHandler, timeout)
+{
+  if (typeof value !== "string" || typeof reference !== "string")
+    debug("WARN: shouldBecomeEqualToString() expects string arguments");
+  var unevaledString = JSON.stringify(reference);
+  shouldBecomeEqual(value, unevaledString, completionHandler, timeout);
+}
+
 function shouldBeType(_a, _type) {
   var exception;
   var _av;

Modified: trunk/LayoutTests/fast/loader/stateobjects/state-url-sets-links-visited-expected.txt (143677 => 143678)


--- trunk/LayoutTests/fast/loader/stateobjects/state-url-sets-links-visited-expected.txt	2013-02-22 02:10:01 UTC (rev 143677)
+++ trunk/LayoutTests/fast/loader/stateobjects/state-url-sets-links-visited-expected.txt	2013-02-22 02:29:41 UTC (rev 143678)
@@ -1,3 +1,8 @@
+Verify that changes done by history.replaceState and history.pushState update visitedLinks.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
 This link should get colored visited as a result of replaceState() setting it as the current URL
 This link should get colored visited as a result of pushState() adding it to the forward list
 If you're running in a browser, the link should be orange-on-black and you should see "replacedURL.html" in your global history.
@@ -2,2 +7,7 @@
 If you're running in DRT, the test will also append "PASS" or "FAIL".
-PASS
+PASS style1.color became "rgb(255, 165, 0)"
+PASS style2.color became "rgb(255, 165, 0)"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Modified: trunk/LayoutTests/fast/loader/stateobjects/state-url-sets-links-visited.html (143677 => 143678)


--- trunk/LayoutTests/fast/loader/stateobjects/state-url-sets-links-visited.html	2013-02-22 02:10:01 UTC (rev 143677)
+++ trunk/LayoutTests/fast/loader/stateobjects/state-url-sets-links-visited.html	2013-02-22 02:29:41 UTC (rev 143678)
@@ -1,24 +1,27 @@
+<html>
+<head>
+<script src=""
 <script>
+jsTestIsAsync = true;
 
-if (window.testRunner) {
+if (window.testRunner)
     testRunner.keepWebHistory();
-    testRunner.dumpAsText();
-}
 
 function loaded()
 {
+    description('Verify that changes done by history.replaceState and history.pushState update visitedLinks.');
+
     window.history.replaceState(null, "Title", "replacedURL.html");
     window.history.pushState(null, "Title", "pushedURL.html");
 
     if (window.testRunner) {
-        var style1 = window.testRunner.computedStyleIncludingVisitedInfo(document.getElementById('link1'));
-        var style2 = window.testRunner.computedStyleIncludingVisitedInfo(document.getElementById('link2'));
-        var result = document.createElement("p");
-        if (style1.color != "rgb(255, 165, 0)" || style2.color != "rgb(255, 165, 0)")
-            result.innerText = "FAIL";
-        else
-            result.innerText = "PASS";
-        document.body.appendChild(result);
+        style1 = testRunner.computedStyleIncludingVisitedInfo(document.getElementById('link1'));
+        style2 = testRunner.computedStyleIncludingVisitedInfo(document.getElementById('link2'));
+
+        // The style is not necessarily updated synchronously in response to history.replaceState and history.pushState.
+        shouldBecomeEqualToString("style1.color", "rgb(255, 165, 0)", function() {
+            shouldBecomeEqualToString("style2.color", "rgb(255, 165, 0)", finishJSTest);
+        });
     }
 }
 
@@ -28,10 +31,14 @@
 :link { color: rgb(0, 255, 0); background-color: white }
 :visited { color: rgb(255, 165, 0); background-color: black }
 </style>
-
+</head>
 <body _onload_="loaded();">
+<p id=description></p>
 <a id="link1" href="" link should get colored visited as a result of replaceState() setting it as the current URL</a><br>
 <a id="link2" href="" link should get colored visited as a result of pushState() adding it to the forward list</a><br>
 If you're running in a browser, the link should be orange-on-black and you should see "replacedURL.html" in your global history.<br>
 If you're running in DRT, the test will also append "PASS" or "FAIL".<br>
+<div id=console></div>
 </body>
+<script src=""
+</html>

Modified: trunk/LayoutTests/platform/chromium/TestExpectations (143677 => 143678)


--- trunk/LayoutTests/platform/chromium/TestExpectations	2013-02-22 02:10:01 UTC (rev 143677)
+++ trunk/LayoutTests/platform/chromium/TestExpectations	2013-02-22 02:29:41 UTC (rev 143678)
@@ -2206,7 +2206,7 @@
 webkit.org/b/37297 fast/history/nested-visited-test.html [ Failure ]
 webkit.org/b/37297 fast/history/self-is-visited.html [ Failure ]
 webkit.org/b/37297 fast/history/sibling-visited-test.html [ Failure ]
-webkit.org/b/37297 [ Mac Android ] fast/loader/stateobjects/state-url-sets-links-visited.html [ Failure ]
+webkit.org/b/37297 fast/loader/stateobjects/state-url-sets-links-visited.html [ Failure ]
 webkit.org/b/58000 [ Mac Android ] fast/history/visited-link-background-color.html [ Failure ]
 
 # Added in http://trac.webkit.org/changeset/57476. Fails in Chromium because

Modified: trunk/LayoutTests/platform/wk2/TestExpectations (143677 => 143678)


--- trunk/LayoutTests/platform/wk2/TestExpectations	2013-02-22 02:10:01 UTC (rev 143677)
+++ trunk/LayoutTests/platform/wk2/TestExpectations	2013-02-22 02:29:41 UTC (rev 143678)
@@ -285,7 +285,6 @@
 fast/history/nested-visited-test.html
 fast/history/self-is-visited.html
 fast/history/sibling-visited-test.html
-fast/loader/stateobjects/state-url-sets-links-visited.html
 platform/mac/accessibility/search-predicate.html
 
 # [WK2] CSP reporting doesn't work
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to