зеркало из https://github.com/mozilla/gecko-dev.git
131 строка
3.3 KiB
HTML
131 строка
3.3 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<!--
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=147777
|
|
-->
|
|
<head>
|
|
<title>Test for visited link coloring pref Bug 147777</title>
|
|
<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/WindowSnapshot.js"></script>
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
|
<style type="text/css">
|
|
|
|
:link { float: left; }
|
|
|
|
:visited { float: right; }
|
|
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=147777">Mozilla Bug 147777</a>
|
|
<iframe id="iframe" src="visited-pref-iframe.html" style="width: 10em; height: 5em"></iframe>
|
|
<pre id="test">
|
|
<script type="application/javascript">
|
|
|
|
/** Test for Bug 147777 **/
|
|
|
|
function reinsert_node(e) {
|
|
var sib = e.nextSibling;
|
|
var par = e.parentNode;
|
|
par.removeChild(e);
|
|
par.insertBefore(e, sib);
|
|
}
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
var prefService = Components.classes["@mozilla.org/preferences-service;1"].
|
|
getService(Components.interfaces.nsIPrefService);
|
|
var dispBranch = prefService.getBranch("layout.css.");
|
|
|
|
function get_pref()
|
|
{
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
return dispBranch.getBoolPref("visited_links_enabled");
|
|
}
|
|
|
|
function set_pref(val)
|
|
{
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
dispBranch.setBoolPref("visited_links_enabled", val);
|
|
}
|
|
|
|
function snapshotsEqual(snap1, snap2)
|
|
{
|
|
return compareSnapshots(snap1, snap2, true)[0];
|
|
}
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
window.addEventListener("load", step1, false);
|
|
|
|
var iframe, subdoc, subwin;
|
|
var link;
|
|
var start;
|
|
var timeout;
|
|
|
|
var unvisref; // reference image for unvisited style
|
|
|
|
function step1()
|
|
{
|
|
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_pref(true);
|
|
|
|
SimpleTest.finish();
|
|
}
|
|
|
|
</script>
|
|
</pre>
|
|
</body>
|
|
</html>
|