2009-07-09 14:09:44 -07:00
|
|
|
<?xml version="1.0"?>
|
|
|
|
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
|
|
|
|
|
|
|
|
<window id="293235Test"
|
|
|
|
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
|
|
|
width="600"
|
|
|
|
height="600"
|
|
|
|
onload="setTimeout(nextTest,0);"
|
|
|
|
title="bug 293235 test">
|
|
|
|
|
2011-10-06 07:51:03 -07:00
|
|
|
<script type="text/javascript"
|
|
|
|
src="chrome://mochikit/content/tests/SimpleTest/specialpowersAPI.js"/>
|
|
|
|
<script type="text/javascript"
|
|
|
|
src="chrome://mochikit/content/tests/SimpleTest/SpecialPowersObserverAPI.js"/>
|
|
|
|
<script type="text/javascript"
|
|
|
|
src="chrome://mochikit/content/tests/SimpleTest/ChromePowers.js"/>
|
2010-12-09 14:47:21 -08:00
|
|
|
<script type="application/javascript" src= "chrome://mochikit/content/chrome-harness.js" />
|
|
|
|
<script type="application/javascript" src="docshell_helpers.js" />
|
2010-04-02 18:58:25 -07:00
|
|
|
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/WindowSnapshot.js"></script>
|
2009-07-09 14:09:44 -07:00
|
|
|
|
|
|
|
<script type="application/javascript"><![CDATA[
|
2011-10-06 07:51:03 -07:00
|
|
|
var Ci = Components.interfaces;
|
|
|
|
var Cc = Components.classes;
|
2010-02-24 08:37:02 -08:00
|
|
|
Components.utils.import("resource://gre/modules/NetUtil.jsm");
|
|
|
|
|
2009-07-09 14:09:44 -07:00
|
|
|
// Define the generator-iterator for the tests.
|
|
|
|
var tests = testIterator();
|
|
|
|
|
|
|
|
////
|
|
|
|
// Execute the next test in the generator function.
|
|
|
|
//
|
|
|
|
function nextTest() {
|
|
|
|
tests.next();
|
|
|
|
}
|
2010-02-24 08:37:02 -08:00
|
|
|
|
2009-07-09 14:09:44 -07:00
|
|
|
// Return the Element object for the specified element id
|
|
|
|
function $(id) { return TestWindow.getDocument().getElementById(id); }
|
|
|
|
|
|
|
|
////
|
2010-02-24 08:37:02 -08:00
|
|
|
// Generator function for test steps for bug 293235:
|
2009-07-09 14:09:44 -07:00
|
|
|
// A visited link should have the :visited style applied
|
|
|
|
// to it when displayed on a page which was fetched from
|
|
|
|
// the bfcache.
|
|
|
|
//
|
|
|
|
function testIterator()
|
|
|
|
{
|
2010-02-24 08:37:02 -08:00
|
|
|
// Register our observer to know when the link lookup is complete.
|
|
|
|
let testURI = NetUtil.newURI(getHttpUrl("bug293235_p2.html"));
|
|
|
|
let os = Cc["@mozilla.org/observer-service;1"].
|
|
|
|
getService(Ci.nsIObserverService);
|
|
|
|
const URI_VISITED_RESOLUTION_TOPIC = "visited-status-resolution";
|
|
|
|
let observer = {
|
|
|
|
notified: false,
|
|
|
|
observe: function(aSubject, aTopic, aData)
|
|
|
|
{
|
|
|
|
if (!testURI.equals(aSubject.QueryInterface(Ci.nsIURI))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
is(aTopic, URI_VISITED_RESOLUTION_TOPIC, "Unexpected topic");
|
|
|
|
this.notified = true;
|
|
|
|
|
|
|
|
// Cleanup after ourselves...
|
|
|
|
os.removeObserver(this, URI_VISITED_RESOLUTION_TOPIC);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
os.addObserver(observer, URI_VISITED_RESOLUTION_TOPIC, false);
|
|
|
|
function notified() observer.notified;
|
|
|
|
|
2009-07-09 14:09:44 -07:00
|
|
|
// Load a test page containing a link that should be initially
|
|
|
|
// blue, per the :link style.
|
|
|
|
doPageNavigation({
|
|
|
|
uri: getHttpUrl("bug293235.html"),
|
|
|
|
onNavComplete: nextTest
|
|
|
|
});
|
|
|
|
yield;
|
2010-02-24 08:37:02 -08:00
|
|
|
|
|
|
|
// Before we go any further, make sure our link has been notified.
|
|
|
|
waitForTrue(notified, nextTest);
|
|
|
|
yield;
|
|
|
|
|
|
|
|
// Now that we've been notified, we can check our link color.
|
2010-04-02 18:58:25 -07:00
|
|
|
// Since we can't use getComputedStyle() for this because
|
|
|
|
// getComputedStyle lies about styles that result from :visited,
|
|
|
|
// 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");
|
2009-07-09 14:09:44 -07:00
|
|
|
|
2010-07-22 15:40:04 -07:00
|
|
|
let observedVisit = false, observedPageShow = false;
|
|
|
|
function maybeRunNextTest() {
|
|
|
|
ok(true, "maybe run next test? visited: " + observedVisit + " pageShow: " + observedPageShow);
|
|
|
|
if (observedVisit && observedPageShow)
|
|
|
|
nextTest();
|
|
|
|
}
|
|
|
|
|
2010-07-22 05:09:10 -07:00
|
|
|
// Because adding visits is async, we will not be notified imemdiately.
|
|
|
|
let visitObserver = {
|
|
|
|
observe: function(aSubject, aTopic, aData)
|
|
|
|
{
|
|
|
|
if (!testURI.equals(aSubject.QueryInterface(Ci.nsIURI))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
os.removeObserver(this, aTopic);
|
2010-07-22 15:40:04 -07:00
|
|
|
observedVisit = true;
|
|
|
|
maybeRunNextTest();
|
2010-07-22 05:09:10 -07:00
|
|
|
},
|
|
|
|
};
|
|
|
|
os.addObserver(visitObserver, "uri-visit-saved", false);
|
2009-07-09 14:09:44 -07:00
|
|
|
// Load the page that the link on the previous page points to.
|
|
|
|
doPageNavigation({
|
2010-07-22 15:40:04 -07:00
|
|
|
uri: getHttpUrl("bug293235_p2.html"),
|
|
|
|
onNavComplete: function() {
|
|
|
|
observedPageShow = true;
|
|
|
|
maybeRunNextTest();
|
|
|
|
}
|
2009-07-09 14:09:44 -07:00
|
|
|
});
|
|
|
|
yield;
|
|
|
|
|
2010-02-24 08:37:02 -08:00
|
|
|
// And the nodes get notified after the "link-visited" topic, so
|
|
|
|
// we need to execute soon...
|
|
|
|
SimpleTest.executeSoon(nextTest);
|
|
|
|
yield;
|
|
|
|
|
2009-07-09 14:09:44 -07:00
|
|
|
// Go back, verify the original page was loaded from the bfcache,
|
|
|
|
// and verify that the link is now purple, per the
|
|
|
|
// :visited style.
|
|
|
|
doPageNavigation({
|
|
|
|
back: true,
|
|
|
|
eventsToListenFor: ["pageshow"],
|
|
|
|
expectedEvents: [ { type: "pageshow",
|
|
|
|
persisted: true,
|
|
|
|
title: "Bug 293235 page1" } ],
|
|
|
|
onNavComplete: nextTest
|
|
|
|
});
|
|
|
|
yield;
|
|
|
|
|
2010-02-24 08:37:02 -08:00
|
|
|
// Now we can test the link color.
|
2010-04-02 18:58:25 -07:00
|
|
|
ok(snapshotsEqual(refVisited, snapshotWindow(TestWindow.getWindow())),
|
|
|
|
"visited link should be purple");
|
2009-07-09 14:09:44 -07:00
|
|
|
|
2010-02-24 08:37:02 -08:00
|
|
|
// Tell the framework the test is finished. Include the final 'yield'
|
2009-07-09 14:09:44 -07:00
|
|
|
// statement to prevent a StopIteration exception from being thrown.
|
|
|
|
finish();
|
|
|
|
yield;
|
|
|
|
}
|
2010-02-24 08:37:02 -08:00
|
|
|
|
2009-07-09 14:09:44 -07:00
|
|
|
]]></script>
|
|
|
|
|
|
|
|
<browser type="content-primary" flex="1" id="content" src="about:blank"/>
|
|
|
|
</window>
|