Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test gets skipped with pattern: os == 'android'
- Manifest: docshell/test/chrome/chrome.toml
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?>
<!--
-->
<script type="application/javascript">
<![CDATA[
SimpleTest.waitForExplicitFinish();
const WEB_PROGRESS_LISTENER_FLAGS =
Object.keys(Ci.nsIWebProgressListener).filter(
propName => propName.startsWith("STATE_")
);
function bitFlagsToNames(flags, knownNames, intf) {
return knownNames.map( (F) => {
return (flags & intf[F]) ? F : undefined;
}).filter( (s) => !!s );
}
var progressListener = {
add(docShell, callback) {
this.callback = callback;
this.docShell = docShell;
docShell.
QueryInterface(Ci.nsIInterfaceRequestor).
getInterface(Ci.nsIWebProgress).
addProgressListener(this, Ci.nsIWebProgress.NOTIFY_STATE_ALL);
},
finish(success) {
this.docShell.
QueryInterface(Ci.nsIInterfaceRequestor).
getInterface(Ci.nsIWebProgress).
removeProgressListener(this);
this.callback(success);
},
onStateChange (webProgress, req, flags) {
if (!(flags & Ci.nsIWebProgressListener.STATE_IS_DOCUMENT) &&
!(flags & Ci.nsIWebProgressListener.STATE_IS_REDIRECTED_DOCUMENT))
return;
var channel = req.QueryInterface(Ci.nsIChannel);
if (flags & Ci.nsIWebProgressListener.STATE_IS_REDIRECTED_DOCUMENT) {
SimpleTest.is(channel.URI.host, "example.org",
"Should be redirected to example.org (see test_docRedirect.sjs)");
this.finish(true);
}
// Fail in case we didn't receive document redirection event.
if (flags & Ci.nsIWebProgressListener.STATE_STOP)
this.finish(false);
},
QueryInterface: ChromeUtils.generateQI([
"nsIWebProgressListener",
"nsISupportsWeakReference",
]),
}
var webNav = SpecialPowers.Services.appShell.createWindowlessBrowser(true);
let docShell = webNav.docShell;
let system = Cc["@mozilla.org/systemprincipal;1"].getService(Ci.nsIPrincipal);
docShell.createAboutBlankDocumentViewer(system, system);
progressListener.add(docShell, function(success) {
webNav.close();
SimpleTest.is(success, true, "Received document redirect event");
SimpleTest.finish();
});
var win = docShell.docViewer.DOMDocument.defaultView;
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
]]>
</script>
</body>
</window>