// The default flags we will stick on the docShell - every request made by the
// docShell should include those flags.
const TEST_FLAGS = Ci.nsIRequest.LOAD_ANONYMOUS |
Ci.nsIRequest.LOAD_BYPASS_CACHE |
Ci.nsIRequest.INHIBIT_CACHING;
// These are the requests we expect to see loading TEST_URL into our iframe.
// The test entry-point. The basic outline is:
// * Create an iframe and set defaultLoadFlags on its docShell.
// * Add a web progress listener to observe each request as the iframe is
// loaded, and check that each request has the flags we specified.
// * Load our test URL into the iframe and wait for the load to complete.
function test() { variframe = document.createElement("iframe");
document.body.appendChild(iframe); var docShell = iframe.contentWindow.docShell;
// Add our progress listener - when it notices the top-level document is
// complete, the test will end.
RequestWatcher.init(docShell, SimpleTest.finish);
// Set the flags we care about, then load our test URL.
docShell.defaultLoadFlags = TEST_FLAGS; iframe.setAttribute("src", TEST_URL);
}
// Finalize the test after we detect a completed load. We check we saw the
// correct requests and make a callback to exit.
finalize() {
ok(Object.keys(this.requestCounts).length, "we expected some requests");
for (var url in this.requestCounts) { var count = this.requestCounts[url];
// As we are looking at all request states, we expect more than 1 for
// each URL - 0 or 1 would imply something went wrong - >1 just means
// multiple states for each request were recorded, which we don't care
// about (we do care they all have the correct flags though - but we
// do that in onStateChange)
ok(count > 1, url + " saw " + count + " requests");
}
this.docShell.
QueryInterface(Ci.nsIInterfaceRequestor).
getInterface(Ci.nsIWebProgress).
removeProgressListener(this);
this.callback();
},
onStateChange(webProgress, req, flags) {
// We are checking requests - if there isn't one, ignore it.
if (!req) {
return;
}
// We will usually see requests for 'about:document-onload-blocker' not
// have the flag, so we just ignore them.
// We also see, eg, resource://gre-resources/loading-image.png, so
// skip resource:// URLs too.
// We may also see, eg, chrome://global/skin/icons/chevron.svg, so
// skip chrome:// URLs too.
if (req.name.startsWith("about:") || req.name.startsWith("resource:") ||
req.name.startsWith("chrome:") || req.name.startsWith("documentchannel:")) {
return;
}
is(req.loadFlags & TEST_FLAGS, TEST_FLAGS, "request " + req.name + " has the expected flags");
this.requestCounts[req.name] += 1; var stopFlags = Ci.nsIWebProgressListener.STATE_STOP |
Ci.nsIWebProgressListener.STATE_IS_DOCUMENT;
if (req.name == TEST_URL && (flags & stopFlags) == stopFlags) {
this.finalize();
}
},
QueryInterface: ChromeUtils.generateQI([ "nsIWebProgressListener", "nsISupportsWeakReference",
]),
};
</script>
</head>
</html>
¤ Dauer der Verarbeitung: 0.29 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.