docshell/test/chrome/bug311007_window.xul

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 <?xml version="1.0"?>
     2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     4 <window id="311007Test"
     5         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
     6         width="600"
     7         height="600"
     8         onload="startup();"
     9         title="bug 311007 test">
    11   <script type="application/javascript" src="docshell_helpers.js"></script>
    12   <script type="application/javascript"><![CDATA[
    13 /*
    14    Regression test for bug 283733 and bug 307027.
    16    Bug 283733
    17      "accessing a relative anchor in a secure page removes the
    18       locked icon and yellow background UI"
    20    Bug 307027
    21      "Going back from secure page to error page does not clear yellow bar"
    23     And enhancements:
    25     Bug 478927
    26       onLocationChange should notify whether or not loading an error page.
    28  */
    30 const kDNSErrorURI = "https://example/err.html";
    31 const kSecureURI =
    32   "https://example.com/tests/docshell/test/navigation/blank.html";
    34 /*
    35   Step 1: load a network error page.   <err.html>       Not Secure
    36   Step 2: load a secure page.          <blank.html>     Secure
    37   Step 3: a secure page + hashchange.  <blank.html#foo> Secure     (bug 283733)
    38   Step 4: go back to the error page.   <err.html>       Not Secure (bug 307027)
    39  */
    41 var gListener = null;
    43 function WebProgressListener() {
    44   this._callback = null;
    45 }
    47 WebProgressListener.prototype = {
    48   QueryInterface: function(aIID) {
    49     if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
    50         aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
    51         aIID.equals(Components.interfaces.nsISupports))
    52       return this;
    53     throw Components.results.NS_NOINTERFACE;
    54   },
    56   onLocationChange: function(aWebProgress, aRequest, aLocation, aFlags) {
    57     setTimeout(this._callback, 0, aWebProgress, aRequest, aLocation, aFlags);
    58   },
    60   set callback(aVal) {
    61     this._callback = aVal;
    62   }
    63 };
    65 function startup() {
    66   gListener = new WebProgressListener();
    68   document.getElementById("content")
    69           .webProgress
    70           .addProgressListener(gListener,
    71                                Components.interfaces.nsIWebProgress
    72                                          .NOTIFY_LOCATION);
    74   setTimeout(step1A, 0);
    75 }
    77 /******************************************************************************
    78  * Step 1: Load an error page, and confirm UA knows it's insecure.
    79  ******************************************************************************/
    81 function step1A() {
    82   gListener.callback = step1B;
    83   content.location = kDNSErrorURI;
    84 }
    86 function step1B(aWebProgress, aRequest, aLocation, aFlags) {
    87   is(aLocation.spec, kDNSErrorURI, "Error page's URI (1)");
    89   ok(!(aFlags & Components.interfaces.nsIWebProgressListener
    90                           .LOCATION_CHANGE_SAME_DOCUMENT),
    91      "DocShell loaded a document (1)");
    93   ok((aFlags & Components.interfaces.nsIWebProgressListener
    94                          .LOCATION_CHANGE_ERROR_PAGE),
    95      "This page is an error page.");
    97   ok(!(aWebProgress.QueryInterface(Components.interfaces.nsIDocShell)
    98                    .securityUI.state &
    99        Components.interfaces.nsIWebProgressListener.STATE_IS_SECURE),
   100      "This is not a secure page (1)");
   102   /* Go to step 2. */
   103   setTimeout(step2A, 0);
   104 }
   106 /******************************************************************************
   107  * Step 2: Load a HTTPS page, and confirm it's secure. 
   108  ******************************************************************************/
   110 function step2A() {
   111   gListener.callback = step2B;
   112   content.location = kSecureURI;
   113 }
   115 function step2B(aWebProgress, aRequest, aLocation, aFlags) {
   116   is(aLocation.spec, kSecureURI, "A URI on HTTPS (2)");
   118   ok(!(aFlags & Components.interfaces.nsIWebProgressListener
   119                           .LOCATION_CHANGE_SAME_DOCUMENT),
   120      "DocShell loaded a document (2)");
   122   ok(!(aFlags & Components.interfaces.nsIWebProgressListener
   123                           .LOCATION_CHANGE_ERROR_PAGE),
   124      "This page is not an error page.");
   126   ok((aWebProgress.QueryInterface(Components.interfaces.nsIDocShell)
   127                   .securityUI.state &
   128       Components.interfaces.nsIWebProgressListener.STATE_IS_SECURE),
   129      "This is a secure page (2)");
   131   /* Go to step 3. */
   132   setTimeout(step3A, 0);
   133 }
   135 /*****************************************************************************
   136  * Step 3: Trigger hashchange within a secure page, and confirm UA knows
   137  *         it's secure. (Bug 283733)
   138  *****************************************************************************/
   140 function step3A() {
   141   gListener.callback = step3B;
   142   content.location += "#foo";
   143 }
   145 function step3B(aWebProgress, aRequest, aLocation, aFlags) {
   146   is(aLocation.spec, kSecureURI + "#foo", "hashchange on HTTPS (3)");
   148   ok((aFlags & Components.interfaces.nsIWebProgressListener
   149                          .LOCATION_CHANGE_SAME_DOCUMENT),
   150      "We are in the same document as before (3)");
   152   ok(!(aFlags & Components.interfaces.nsIWebProgressListener
   153                           .LOCATION_CHANGE_ERROR_PAGE),
   154      "This page is not an error page.");
   156   ok((aWebProgress.QueryInterface(Components.interfaces.nsIDocShell)
   157                   .securityUI.state &
   158       Components.interfaces.nsIWebProgressListener.STATE_IS_SECURE),
   159      "This is a secure page (3)");
   161   /* Go to step 4. */
   162   setTimeout(step4A, 0);
   163 }
   165 /*****************************************************************************
   166  * Step 4: Go back from a secure page to an error page, and confirm UA knows
   167  *         it's not secure. (Bug 307027)
   168  *****************************************************************************/
   170 function step4A() {
   171   gListener.callback = step4B;
   172   content.history.go(-2);
   173 }
   175 function step4B(aWebProgress, aRequest, aLocation, aFlags) {
   176   is(aLocation.spec, kDNSErrorURI, "Go back to the error URI (4)");
   178   ok(!(aFlags & Components.interfaces.nsIWebProgressListener
   179                           .LOCATION_CHANGE_SAME_DOCUMENT),
   180        "DocShell loaded a document (4)");
   182   ok((aFlags & Components.interfaces.nsIWebProgressListener
   183                          .LOCATION_CHANGE_ERROR_PAGE),
   184      "This page is an error page.");
   186   ok(!(aWebProgress.QueryInterface(Components.interfaces.nsIDocShell)
   187                    .securityUI.state &
   188        Components.interfaces.nsIWebProgressListener.STATE_IS_SECURE),
   189      "This is not a secure page (4)");
   191   /* End. */
   192   aWebProgress.removeProgressListener(gListener);
   193   delete(gListener);
   194   finish();
   195 }
   196   ]]></script>
   198   <browser type="content-primary" flex="1" id="content" src="about:blank"/>
   199 </window>

mercurial