2 <?xml-stylesheet type=
"text/css" href=
"chrome://global/skin"?>
3 <?xml-stylesheet type=
"text/css" href=
"/tests/SimpleTest/test.css"?>
5 https://bugzilla.mozilla.org/show_bug.cgi?id=1342989
7 <window title=
"Mozilla Bug 1342989"
8 xmlns=
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
10 <script src=
"chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
12 <script type=
"application/javascript">
14 SimpleTest.waitForExplicitFinish();
16 const WEB_PROGRESS_LISTENER_FLAGS =
17 Object.keys(Ci.nsIWebProgressListener).filter(
18 propName =
> propName.startsWith(
"STATE_")
21 function bitFlagsToNames(flags, knownNames, intf) {
22 return knownNames.map( (F) =
> {
23 return (flags & intf[F]) ? F : undefined;
24 }).filter( (s) =
> !!s );
27 var progressListener = {
28 add(docShell, callback) {
29 this.callback = callback;
30 this.docShell = docShell;
32 QueryInterface(Ci.nsIInterfaceRequestor).
33 getInterface(Ci.nsIWebProgress).
34 addProgressListener(this, Ci.nsIWebProgress.NOTIFY_STATE_ALL);
39 QueryInterface(Ci.nsIInterfaceRequestor).
40 getInterface(Ci.nsIWebProgress).
41 removeProgressListener(this);
42 this.callback(success);
45 onStateChange (webProgress, req, flags, status) {
46 if (!(flags & Ci.nsIWebProgressListener.STATE_IS_DOCUMENT) &&
47 !(flags & Ci.nsIWebProgressListener.STATE_IS_REDIRECTED_DOCUMENT))
50 var channel = req.QueryInterface(Ci.nsIChannel);
52 if (flags & Ci.nsIWebProgressListener.STATE_IS_REDIRECTED_DOCUMENT) {
53 SimpleTest.is(channel.URI.host,
"example.org",
54 "Should be redirected to example.org (see test_docRedirect.sjs)");
58 // Fail in case we didn't receive document redirection event.
59 if (flags & Ci.nsIWebProgressListener.STATE_STOP)
63 QueryInterface: ChromeUtils.generateQI([
64 "nsIWebProgressListener",
65 "nsISupportsWeakReference",
69 var webNav = SpecialPowers.Services.appShell.createWindowlessBrowser(true);
70 let docShell = webNav.docShell;
71 let system = Cc[
"@mozilla.org/systemprincipal;1"].getService(Ci.nsIPrincipal);
72 docShell.createAboutBlankContentViewer(system, system);
74 progressListener.add(docShell, function(success) {
76 SimpleTest.is(success, true,
"Received document redirect event");
80 var win = docShell.contentViewer.DOMDocument.defaultView;
81 // eslint-disable-next-line @microsoft/sdl/no-insecure-url
82 win.location =
"http://example.com/chrome/docshell/test/chrome/test_docRedirect.sjs"
87 <body xmlns=
"http://www.w3.org/1999/xhtml">
88 <a href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=1342989"
89 target=
"_blank">Mozilla Bug
1342989</a>