Add test for background image loading behavior for :visited links. (Bug 557287)
authorL. David Baron <dbaron@dbaron.org>
Tue, 06 Apr 2010 12:42:41 -0700
changeset 40499 aa2b262d938a21f0787962899ed826c1c5229d3d
parent 40498 363849c0170b1493960b7ed527cef775401ec43b
child 40500 9786ae3984b3d467bbe0c372c38fb69ff9775526
push id12634
push userdbaron@mozilla.com
push dateTue, 06 Apr 2010 19:43:29 +0000
treeherdermozilla-central@aa2b262d938a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs557287
milestone1.9.3a4pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
Add test for background image loading behavior for :visited links. (Bug 557287)
layout/style/test/Makefile.in
layout/style/test/test_visited_image_loading.html
layout/style/test/test_visited_image_loading_empty.html
layout/style/test/visited_image_loading.sjs
layout/style/test/visited_image_loading_frame.html
layout/style/test/visited_image_loading_frame_empty.html
--- a/layout/style/test/Makefile.in
+++ b/layout/style/test/Makefile.in
@@ -171,16 +171,18 @@ GARBAGE += css_properties.js
 		test_transitions_bug537151.html \
 		test_units_angle.html \
 		test_units_frequency.html \
 		test_units_length.html \
 		test_units_time.html \
 		test_value_cloning.html \
 		test_value_computation.html \
 		test_value_storage.html \
+		test_visited_image_loading.html \
+		test_visited_image_loading_empty.html \
 		test_visited_lying.html \
 		test_visited_pref.html \
 		test_visited_reftests.html \
 		css_properties.js \
 		property_database.js \
 		descriptor_database.js \
 		unstyled.xml \
 		unstyled.css \
@@ -199,16 +201,19 @@ GARBAGE += css_properties.js
 		bug453896_iframe.html \
 		bug517224.sjs \
 		test_bug525952.html \
 		ccd-quirks.html \
 		ccd-standards.html \
 		ccd.sjs \
 		visited-pref-iframe.html \
 		visited-lying-inner.html \
+		visited_image_loading.sjs \
+		visited_image_loading_frame.html \
+		visited_image_loading_frame_empty.html \
 		$(NULL)
 
 _VISITED_REFTEST_FILES = \
 		$(shell find $(topsrcdir)/layout/reftests/css-visited/ -name '*.html' -o -name '*.xhtml') \
 		$(topsrcdir)/layout/reftests/svg/pseudo-classes-02.svg \
 		$(topsrcdir)/layout/reftests/svg/pseudo-classes-02-ref.svg \
 		$(NULL)
 
new file mode 100644
--- /dev/null
+++ b/layout/style/test/test_visited_image_loading.html
@@ -0,0 +1,68 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=557287
+-->
+<head>
+  <title>Test for Bug 557287</title>
+  <script type="application/javascript" src="/MochiKit/packed.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=557287">Mozilla Bug 147777</a>
+<iframe id="display" src="visited_image_loading_frame.html"></iframe>
+<pre id="test">
+<script type="application/ecmascript" src="visited_image_loading.sjs?reset"></script>
+<script type="application/javascript">
+
+/** Test for Bug 557287 **/
+
+SimpleTest.waitForExplicitFinish();
+
+var subdoc, subwin;
+
+window.addEventListener("load", run, false);
+
+function run()
+{
+  var frame = document.getElementById("display");
+  subdoc = frame.contentDocument;
+  subwin = frame.contentWindow;
+  setTimeout(check_link_styled, 50);
+}
+
+function visitedDependentComputedStyle(win, elem, property) {
+  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+  var utils = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
+                getInterface(Components.interfaces.nsIDOMWindowUtils);
+  return utils.getVisitedDependentComputedStyle(elem, "", property);
+}
+
+function check_link_styled()
+{
+  var vislink = subdoc.getElementById("visited");
+  var bgcolor =
+    visitedDependentComputedStyle(subwin, vislink, "background-color");
+  if (bgcolor == "rgb(128, 0, 128)") {
+    // We've done our async :visited processing and restyled accordingly.
+    // Make sure that we've actually painted before finishing the test.
+    subwin.addEventListener("MozAfterPaint", paint_listener, false);
+    // do something that forces a paint
+    subdoc.body.appendChild(subdoc.createTextNode("new text node"));
+  } else {
+    setTimeout(check_link_styled, 50);
+  }
+}
+
+function paint_listener(event)
+{
+  var s = document.createElement("script");
+  s.src = "visited_image_loading.sjs?result";
+  document.body.appendChild(s);
+}
+
+</script>
+</pre>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/style/test/test_visited_image_loading_empty.html
@@ -0,0 +1,68 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=557287
+-->
+<head>
+  <title>Test for Bug 557287</title>
+  <script type="application/javascript" src="/MochiKit/packed.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=557287">Mozilla Bug 147777</a>
+<iframe id="display" src="visited_image_loading_frame_empty.html"></iframe>
+<pre id="test">
+<script type="application/ecmascript" src="visited_image_loading.sjs?reset"></script>
+<script type="application/javascript">
+
+/** Test for Bug 557287 **/
+
+SimpleTest.waitForExplicitFinish();
+
+var subdoc, subwin;
+
+window.addEventListener("load", run, false);
+
+function run()
+{
+  var frame = document.getElementById("display");
+  subdoc = frame.contentDocument;
+  subwin = frame.contentWindow;
+  setTimeout(check_link_styled, 50);
+}
+
+function visitedDependentComputedStyle(win, elem, property) {
+  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+  var utils = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
+                getInterface(Components.interfaces.nsIDOMWindowUtils);
+  return utils.getVisitedDependentComputedStyle(elem, "", property);
+}
+
+function check_link_styled()
+{
+  var vislink = subdoc.getElementById("visited");
+  var bgcolor =
+    visitedDependentComputedStyle(subwin, vislink, "background-color");
+  if (bgcolor == "rgb(128, 0, 128)") {
+    // We've done our async :visited processing and restyled accordingly.
+    // Make sure that we've actually painted before finishing the test.
+    subwin.addEventListener("MozAfterPaint", paint_listener, false);
+    // do something that forces a paint
+    subdoc.body.appendChild(subdoc.createTextNode("new text node"));
+  } else {
+    setTimeout(check_link_styled, 50);
+  }
+}
+
+function paint_listener(event)
+{
+  var s = document.createElement("script");
+  s.src = "visited_image_loading.sjs?result";
+  document.body.appendChild(s);
+}
+
+</script>
+</pre>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/style/test/visited_image_loading.sjs
@@ -0,0 +1,36 @@
+function handleRequest(request, response)
+{
+  response.setHeader("Cache-Control", "no-cache", false);
+  var query = request.queryString;
+  switch (query) {
+    case "reset":
+      response.setHeader("Content-Type", "application/ecmascript", false);
+      setState("1l", "");
+      setState("1v", "");
+      setState("2l", "");
+      setState("2v", "");
+      break;
+    case "1l":
+    case "1v":
+    case "2l":
+    case "2v":
+      setState(query, getState(query) + "load");
+      response.setStatusLine("1.1", 302, "Found");
+      // redirect to a solid blue image
+      response.setHeader("Location", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVQI12NgYPgPAAEDAQDZqt2zAAAAAElFTkSuQmCC");
+      response.setHeader("Content-Type", "text/plain", false);
+      break;
+    case "result":
+      response.setHeader("Content-Type", "application/ecmascript", false);
+      response.write("is('" + getState("1l") +
+                     "', 'load', 'image 1l should have been loaded once')\n");
+      response.write("is('" + getState("1v") +
+                     "', '', 'image 1v should not have been loaded')\n");
+      response.write("is('" + getState("2l") +
+                     "', 'load', 'image 2l should have been loaded once')\n");
+      response.write("is('" + getState("2v") +
+                     "', '', 'image 2v should not have been loaded')\n");
+      response.write("SimpleTest.finish()");
+      break;
+  }
+}
new file mode 100644
--- /dev/null
+++ b/layout/style/test/visited_image_loading_frame.html
@@ -0,0 +1,15 @@
+<!DOCTYPE HTML>
+<title>Test for :visited image loading</title>
+<style type="text/css">
+
+:link { background-color: blue }
+:visited { background-color: purple }
+
+#link:link       { background-image: url("visited_image_loading.sjs?1l"); }
+#link:visited    { background-image: url("visited_image_loading.sjs?1v"); }
+#visited:link    { background-image: url("visited_image_loading.sjs?2l"); }
+#visited:visited { background-image: url("visited_image_loading.sjs?2v"); }
+
+</style>
+<a id="link" href="do-not-visit-this-link.html">unvisited link</a>
+<a id="visited" href="visited_image_loading_frame.html">visited link</a>
new file mode 100644
--- /dev/null
+++ b/layout/style/test/visited_image_loading_frame_empty.html
@@ -0,0 +1,15 @@
+<!DOCTYPE HTML>
+<title>Test for :visited image loading</title>
+<style type="text/css">
+
+:link { background-color: blue }
+:visited { background-color: purple }
+
+#link:link       { background-image: url("visited_image_loading.sjs?1l"); }
+#link:visited    { background-image: url("visited_image_loading.sjs?1v"); }
+#visited:link    { background-image: url("visited_image_loading.sjs?2l"); }
+#visited:visited { background-image: url("visited_image_loading.sjs?2v"); }
+
+</style>
+<a id="link" href="do-not-visit-this-link.html"></a>
+<a id="visited" href="visited_image_loading_frame_empty.html"></a>