forked from mirrors/gecko-dev
Fix existing tests to deal with getComputedStyle lying about :link vs. :visited. (Bug 147777) r=sdwilsh
This commit is contained in:
parent
5d680f5d9b
commit
7a857e9b5a
9 changed files with 129 additions and 51 deletions
|
|
@ -77,14 +77,19 @@ function link123HrefIs(href, testNum) {
|
||||||
|
|
||||||
var gGen;
|
var gGen;
|
||||||
|
|
||||||
|
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 getColor(elem) {
|
function getColor(elem) {
|
||||||
return document.defaultView.getComputedStyle(elem, "").color;
|
return visitedDependentComputedStyle(document.defaultView, elem, "color");
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFill(elem) {
|
function getFill(elem) {
|
||||||
return document.defaultView
|
return visitedDependentComputedStyle(document.defaultView, elem, "fill");
|
||||||
.getComputedStyle(elem, "")
|
|
||||||
.getPropertyValue("fill");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function setXlinkHref(elem, href) {
|
function setXlinkHref(elem, href) {
|
||||||
|
|
|
||||||
|
|
@ -51,12 +51,18 @@ function continueTest() {
|
||||||
function checkLinkColor(aElmId, aExpectedColor, aMessage) {
|
function checkLinkColor(aElmId, aExpectedColor, aMessage) {
|
||||||
// Because link coloring is asynchronous, we wait until we get the right
|
// Because link coloring is asynchronous, we wait until we get the right
|
||||||
// result, or we will time out (resulting in a failure).
|
// result, or we will time out (resulting in a failure).
|
||||||
var getCS = document.defaultView.getComputedStyle;
|
function getColor() {
|
||||||
while (getCS($(aElmId), "").color != aExpectedColor) {
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||||
|
var utils = document.defaultView.
|
||||||
|
QueryInterface(Components.interfaces.nsIInterfaceRequestor).
|
||||||
|
getInterface(Components.interfaces.nsIDOMWindowUtils);
|
||||||
|
return utils.getVisitedDependentComputedStyle($(aElmId), "", "color");
|
||||||
|
}
|
||||||
|
while (getColor() != aExpectedColor) {
|
||||||
setTimeout(continueTest, 10);
|
setTimeout(continueTest, 10);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
is(getCS($(aElmId), "").color, aExpectedColor, aMessage);
|
is(getColor(), aExpectedColor, aMessage);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@
|
||||||
<head>
|
<head>
|
||||||
<title>Bug 293235 page1</title>
|
<title>Bug 293235 page1</title>
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
a:visited { color: rgb(128, 0, 128); }
|
a:visited, a.forcevisited.forcevisited { color: rgb(128, 0, 128); }
|
||||||
a:link { color: rgb(0, 0, 128); }
|
a:link, a.forcelink.forcelink { color: rgb(0, 0, 128); }
|
||||||
a:focus { color: rgb(128, 0, 0); }
|
a:focus { color: rgb(128, 0, 0); }
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
src=
|
src=
|
||||||
"chrome://mochikit/content/chrome/docshell/test/chrome/docshell_helpers.js">
|
"chrome://mochikit/content/chrome/docshell/test/chrome/docshell_helpers.js">
|
||||||
</script>
|
</script>
|
||||||
|
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/WindowSnapshot.js"></script>
|
||||||
|
|
||||||
<script type="application/javascript"><![CDATA[
|
<script type="application/javascript"><![CDATA[
|
||||||
const Ci = Components.interfaces;
|
const Ci = Components.interfaces;
|
||||||
|
|
@ -74,9 +75,22 @@
|
||||||
yield;
|
yield;
|
||||||
|
|
||||||
// Now that we've been notified, we can check our link color.
|
// Now that we've been notified, we can check our link color.
|
||||||
is(TestWindow.getWindow().getComputedStyle($("link1"), "").color,
|
// Since we can't use getComputedStyle() for this because
|
||||||
"rgb(0, 0, 128)",
|
// getComputedStyle lies about styles that result from :visited,
|
||||||
"link not initially blue");
|
// we have to take snapshots.
|
||||||
|
// First, take two reference snapshots.
|
||||||
|
var link1 = $("link1");
|
||||||
|
link1.className = "forcelink";
|
||||||
|
var refLink = snapshotWindow(TestWindow.getWindow());
|
||||||
|
link1.className = "forcevisited";
|
||||||
|
var refVisited = snapshotWindow(TestWindow.getWindow());
|
||||||
|
link1.className = "";
|
||||||
|
function snapshotsEqual(snap1, snap2) {
|
||||||
|
return compareSnapshots(snap1, snap2, true)[0];
|
||||||
|
}
|
||||||
|
ok(!snapshotsEqual(refLink, refVisited), "references should not match");
|
||||||
|
ok(snapshotsEqual(refLink, snapshotWindow(TestWindow.getWindow())),
|
||||||
|
"link should initially be blue");
|
||||||
|
|
||||||
// Load the page that the link on the previous page points to.
|
// Load the page that the link on the previous page points to.
|
||||||
doPageNavigation({
|
doPageNavigation({
|
||||||
|
|
@ -109,9 +123,8 @@
|
||||||
yield;
|
yield;
|
||||||
|
|
||||||
// Now we can test the link color.
|
// Now we can test the link color.
|
||||||
is(TestWindow.getWindow().getComputedStyle($("link1"), "").color,
|
ok(snapshotsEqual(refVisited, snapshotWindow(TestWindow.getWindow())),
|
||||||
"rgb(128, 0, 128)",
|
"visited link should be purple");
|
||||||
":visited link wrong color");
|
|
||||||
|
|
||||||
// Tell the framework the test is finished. Include the final 'yield'
|
// Tell the framework the test is finished. Include the final 'yield'
|
||||||
// statement to prevent a StopIteration exception from being thrown.
|
// statement to prevent a StopIteration exception from being thrown.
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,11 @@ function popstateExpected(msg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getColor(elem) {
|
function getColor(elem) {
|
||||||
return document.defaultView.getComputedStyle(elem, "").color;
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||||
|
var utils = document.defaultView.
|
||||||
|
QueryInterface(Components.interfaces.nsIInterfaceRequestor).
|
||||||
|
getInterface(Components.interfaces.nsIDOMWindowUtils);
|
||||||
|
return utils.getVisitedDependentComputedStyle(elem, "", "color");
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSHistory(theWindow)
|
function getSHistory(theWindow)
|
||||||
|
|
|
||||||
|
|
@ -200,6 +200,7 @@ _TEST_FILES = test_acid3_test46.html \
|
||||||
ccd-quirks.html \
|
ccd-quirks.html \
|
||||||
ccd-standards.html \
|
ccd-standards.html \
|
||||||
ccd.sjs \
|
ccd.sjs \
|
||||||
|
visited-pref-iframe.html \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
_BROWSER_FILES = \
|
_BROWSER_FILES = \
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=147777
|
||||||
<title>Test for visited link coloring pref Bug 147777</title>
|
<title>Test for visited link coloring pref Bug 147777</title>
|
||||||
<script type="application/javascript" src="/MochiKit/packed.js"></script>
|
<script type="application/javascript" src="/MochiKit/packed.js"></script>
|
||||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||||
|
<script type="application/javascript" src="/tests/SimpleTest/WindowSnapshot.js"></script>
|
||||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
|
|
||||||
|
|
@ -18,14 +19,12 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=147777
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=147777">Mozilla Bug 147777</a>
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=147777">Mozilla Bug 147777</a>
|
||||||
<p id="display"><a id="mylink" href="test_visited_pref.html">link to this page</a></p>
|
<iframe id="iframe" src="visited-pref-iframe.html" style="width: 10em; height: 5em"></iframe>
|
||||||
<pre id="test">
|
<pre id="test">
|
||||||
<script type="application/javascript">
|
<script type="application/javascript">
|
||||||
|
|
||||||
/** Test for Bug 147777 **/
|
/** Test for Bug 147777 **/
|
||||||
|
|
||||||
// NOTE: this test will fail when ran by itself because the URL is different!
|
|
||||||
|
|
||||||
function reinsert_node(e) {
|
function reinsert_node(e) {
|
||||||
var sib = e.nextSibling;
|
var sib = e.nextSibling;
|
||||||
var par = e.parentNode;
|
var par = e.parentNode;
|
||||||
|
|
@ -50,41 +49,80 @@ function set_pref(val)
|
||||||
dispBranch.setBoolPref("visited_links_enabled", val);
|
dispBranch.setBoolPref("visited_links_enabled", val);
|
||||||
}
|
}
|
||||||
|
|
||||||
is(get_pref(), true, "pref defaults to true");
|
function snapshotsEqual(snap1, snap2)
|
||||||
|
{
|
||||||
|
return compareSnapshots(snap1, snap2, true)[0];
|
||||||
|
}
|
||||||
|
|
||||||
// Link coloring is asynchronous (and non-deterministic), so we wait until it
|
SimpleTest.waitForExplicitFinish();
|
||||||
// changes.
|
window.addEventListener("load", step1, false);
|
||||||
var thread = Components.classes["@mozilla.org/thread-manager;1"].
|
|
||||||
getService(Components.interfaces.nsIThreadManager).
|
|
||||||
mainThread;
|
|
||||||
var link = document.getElementById("mylink");
|
|
||||||
var cs;
|
|
||||||
var start = Date.now();
|
|
||||||
do {
|
|
||||||
while (thread.hasPendingEvents())
|
|
||||||
thread.processNextEvent(false);
|
|
||||||
cs = getComputedStyle(link, "");
|
|
||||||
} while(cs.cssFloat != "right");
|
|
||||||
var end = Date.now();
|
|
||||||
is(cs.cssFloat, "right", ":visited selector applies given default preferences");
|
|
||||||
|
|
||||||
set_pref(false);
|
var iframe, subdoc, subwin;
|
||||||
|
var link;
|
||||||
|
var start;
|
||||||
|
var timeout;
|
||||||
|
|
||||||
// we don't handle dynamic changes of this pref; it only takes effect
|
var unvisref; // reference image for unvisited style
|
||||||
// when a new page loads
|
|
||||||
reinsert_node(link);
|
|
||||||
|
|
||||||
// Wait a while to make sure we don't update the style on our reinserted node.
|
function step1()
|
||||||
setTimeout(function() {
|
{
|
||||||
is(cs.cssFloat, "left", ":visited selector does not apply given false preference");
|
is(get_pref(), true, "pref defaults to true");
|
||||||
|
|
||||||
|
iframe = document.getElementById("iframe");
|
||||||
|
subdoc = iframe.contentDocument;
|
||||||
|
subwin = iframe.contentWindow;
|
||||||
|
link = subdoc.getElementById("link");
|
||||||
|
|
||||||
|
unvisref = snapshotWindow(subwin, false);
|
||||||
|
|
||||||
|
// Now set the href of the link to a location that's actually visited.
|
||||||
|
link.href = window.location;
|
||||||
|
|
||||||
|
start = Date.now();
|
||||||
|
|
||||||
|
// And wait for the link to get restyled when the history lets us
|
||||||
|
// know it is (asynchronously).
|
||||||
|
setTimeout(poll_for_visited_style, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
function poll_for_visited_style()
|
||||||
|
{
|
||||||
|
var snapshot = snapshotWindow(subwin, false);
|
||||||
|
if (snapshotsEqual(unvisref, snapshot)) {
|
||||||
|
// hasn't been styled yet
|
||||||
|
setTimeout(poll_for_visited_style, 100);
|
||||||
|
|
||||||
|
// If it never gets styled correctly, this test will fail because
|
||||||
|
// this loop will never complete.
|
||||||
|
} else {
|
||||||
|
var end = Date.now();
|
||||||
|
timeout = 3 * Math.max(end - start, 300);
|
||||||
|
step2();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function step2()
|
||||||
|
{
|
||||||
|
set_pref(false);
|
||||||
|
|
||||||
|
// we don't handle dynamic changes of this pref; it only takes effect
|
||||||
|
// when a new page loads
|
||||||
|
reinsert_node(link);
|
||||||
|
|
||||||
|
setTimeout(step3, timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
function step3()
|
||||||
|
{
|
||||||
|
var snapshot = snapshotWindow(subwin, false);
|
||||||
|
ok(snapshotsEqual(unvisref, snapshot),
|
||||||
|
":visited selector does not apply given false preference");
|
||||||
|
|
||||||
// Set the pref back for the rest of the tests.
|
// Set the pref back for the rest of the tests.
|
||||||
set_pref(true);
|
set_pref(true);
|
||||||
|
|
||||||
SimpleTest.finish();
|
SimpleTest.finish();
|
||||||
}, 10 * Math.max(end - start, 100));
|
}
|
||||||
|
|
||||||
SimpleTest.waitForExplicitFinish();
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</pre>
|
</pre>
|
||||||
|
|
|
||||||
7
layout/style/test/visited-pref-iframe.html
Normal file
7
layout/style/test/visited-pref-iframe.html
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
<!DOCTYPE HTML>
|
||||||
|
<title>iframe for test_visited_pref.html</title>
|
||||||
|
<style>
|
||||||
|
:link { color: blue }
|
||||||
|
:visited { color: purple }
|
||||||
|
</style>
|
||||||
|
<a href="http://www.example.com/url-that-has-not-been-visited" id="link">link</a>
|
||||||
|
|
@ -112,6 +112,13 @@ function loadNextTest() {
|
||||||
iframe.src = prefix + subtests[testNum-1];
|
iframe.src = prefix + subtests[testNum-1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getColor(doc, win, id) {
|
||||||
|
var elem = doc.getElementById(id);
|
||||||
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||||
|
var utils = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
|
||||||
|
getInterface(Components.interfaces.nsIDOMWindowUtils);
|
||||||
|
return utils.getVisitedDependentComputedStyle(elem, "", "color");
|
||||||
|
}
|
||||||
|
|
||||||
function checkTest() {
|
function checkTest() {
|
||||||
switch (testNum) {
|
switch (testNum) {
|
||||||
|
|
@ -123,24 +130,21 @@ function checkTest() {
|
||||||
// run outside of private mode, link should appear as visited
|
// run outside of private mode, link should appear as visited
|
||||||
var doc = iframe.contentDocument;
|
var doc = iframe.contentDocument;
|
||||||
var win = doc.defaultView;
|
var win = doc.defaultView;
|
||||||
var style = win.getComputedStyle(doc.getElementById("link"), "");
|
is(getColor(doc, win, "link"), kRed, "Visited link coloring should work outside of private mode");
|
||||||
is(style.getPropertyValue("color"), kRed, "Visited link coloring should work outside of private mode");
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
// run inside of private mode, link should appear as not visited
|
// run inside of private mode, link should appear as not visited
|
||||||
var doc = iframe.contentDocument;
|
var doc = iframe.contentDocument;
|
||||||
var win = doc.defaultView;
|
var win = doc.defaultView;
|
||||||
var style = win.getComputedStyle(doc.getElementById("link"), "");
|
is(getColor(doc, win, "link"), kBlue, "Visited link coloring should not work inside of private mode");
|
||||||
is(style.getPropertyValue("color"), kBlue, "Visited link coloring should not work inside of private mode");
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
// run outside of private mode, link should appear as visited
|
// run outside of private mode, link should appear as visited
|
||||||
var doc = iframe.contentDocument;
|
var doc = iframe.contentDocument;
|
||||||
var win = doc.defaultView;
|
var win = doc.defaultView;
|
||||||
var style = win.getComputedStyle(doc.getElementById("link"), "");
|
is(getColor(doc, win, "link"), kRed, "Visited link coloring should work outside of private mode");
|
||||||
is(style.getPropertyValue("color"), kRed, "Visited link coloring should work outside of private mode");
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue