Bug 461199 (Part 27) - Fix test_visited_pref.html so it passes with the new async isVisited API

r?dbaron
This commit is contained in:
Shawn Wilsher 2010-02-17 14:04:33 -08:00
parent 855db8485f
commit 2fae1f0f51

View File

@ -24,6 +24,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=147777
/** Test for Bug 147777 **/
// NOTE: this test will fail when ran by itself because the URL is different!
function reinsert_node(e) {
var sib = e.nextSibling;
var par = e.parentNode;
@ -50,8 +52,20 @@ function set_pref(val)
is(get_pref(), true, "pref defaults to true");
// Link coloring is asynchronous (and non-deterministic), so we wait until it
// changes.
var thread = Components.classes["@mozilla.org/thread-manager;1"].
getService(Components.interfaces.nsIThreadManager).
mainThread;
var link = document.getElementById("mylink");
var cs = getComputedStyle(link, "");
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);
@ -60,10 +74,17 @@ set_pref(false);
// when a new page loads
reinsert_node(link);
is(cs.cssFloat, "left", ":visited selector does not apply given false preference");
// Wait a while to make sure we don't update the style on our reinserted node.
setTimeout(function() {
is(cs.cssFloat, "left", ":visited selector does not apply given false preference");
// Set the pref back for the rest of the tests.
set_pref(true);
// Set the pref back for the rest of the tests.
set_pref(true);
SimpleTest.finish();
}, 10 * Math.max(end - start, 100));
SimpleTest.waitForExplicitFinish();
</script>
</pre>