summaryrefslogtreecommitdiff
path: root/docshell/test/chrome/bug311007_window.xul
blob: 730580cc2bd3e6eb6e864577695a699d9156e490 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>

<window id="311007Test"
        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
        width="600"
        height="600"
        onload="startup();"
        title="bug 311007 test">

  <script type="application/javascript" src="docshell_helpers.js"></script>
  <script type="application/javascript"><![CDATA[
/*
   Regression test for bug 283733 and bug 307027.

   Bug 283733
     "accessing a relative anchor in a secure page removes the
      locked icon and yellow background UI"

   Bug 307027
     "Going back from secure page to error page does not clear yellow bar"

    And enhancements:

    Bug 478927
      onLocationChange should notify whether or not loading an error page.

 */

const kDNSErrorURI = "https://example/err.html";
const kSecureURI =
  "https://example.com/tests/docshell/test/navigation/blank.html";

/*
  Step 1: load a network error page.   <err.html>       Not Secure
  Step 2: load a secure page.          <blank.html>     Secure
  Step 3: a secure page + hashchange.  <blank.html#foo> Secure     (bug 283733)
  Step 4: go back to the error page.   <err.html>       Not Secure (bug 307027)
 */

var gListener = null;

function WebProgressListener() {
  this._callback = null;
}

WebProgressListener.prototype = {
  QueryInterface: function(aIID) {
    if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
        aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
        aIID.equals(Components.interfaces.nsISupports))
      return this;
    throw Components.results.NS_NOINTERFACE;
  },

  onLocationChange: function(aWebProgress, aRequest, aLocation, aFlags) {
    setTimeout(this._callback, 0, aWebProgress, aRequest, aLocation, aFlags);
  },

  set callback(aVal) {
    this._callback = aVal;
  }
};

function startup() {
  gListener = new WebProgressListener();

  document.getElementById("content")
          .webProgress
          .addProgressListener(gListener,
                               Components.interfaces.nsIWebProgress
                                         .NOTIFY_LOCATION);

  setTimeout(step1A, 0);
}

/******************************************************************************
 * Step 1: Load an error page, and confirm UA knows it's insecure.
 ******************************************************************************/

function step1A() {
  gListener.callback = step1B;
  content.location = kDNSErrorURI;
}

function step1B(aWebProgress, aRequest, aLocation, aFlags) {
  is(aLocation.spec, kDNSErrorURI, "Error page's URI (1)");

  ok(!(aFlags & Components.interfaces.nsIWebProgressListener
                          .LOCATION_CHANGE_SAME_DOCUMENT),
     "DocShell loaded a document (1)");

  ok((aFlags & Components.interfaces.nsIWebProgressListener
                         .LOCATION_CHANGE_ERROR_PAGE),
     "This page is an error page.");

  ok(!(aWebProgress.QueryInterface(Components.interfaces.nsIDocShell)
                   .securityUI.state &
       Components.interfaces.nsIWebProgressListener.STATE_IS_SECURE),
     "This is not a secure page (1)");

  /* Go to step 2. */
  setTimeout(step2A, 0);
}

/******************************************************************************
 * Step 2: Load a HTTPS page, and confirm it's secure. 
 ******************************************************************************/

function step2A() {
  gListener.callback = step2B;
  content.location = kSecureURI;
}

function step2B(aWebProgress, aRequest, aLocation, aFlags) {
  is(aLocation.spec, kSecureURI, "A URI on HTTPS (2)");

  ok(!(aFlags & Components.interfaces.nsIWebProgressListener
                          .LOCATION_CHANGE_SAME_DOCUMENT),
     "DocShell loaded a document (2)");

  ok(!(aFlags & Components.interfaces.nsIWebProgressListener
                          .LOCATION_CHANGE_ERROR_PAGE),
     "This page is not an error page.");

  ok((aWebProgress.QueryInterface(Components.interfaces.nsIDocShell)
                  .securityUI.state &
      Components.interfaces.nsIWebProgressListener.STATE_IS_SECURE),
     "This is a secure page (2)");

  /* Go to step 3. */
  setTimeout(step3A, 0);
}

/*****************************************************************************
 * Step 3: Trigger hashchange within a secure page, and confirm UA knows
 *         it's secure. (Bug 283733)
 *****************************************************************************/

function step3A() {
  gListener.callback = step3B;
  content.location += "#foo";
}

function step3B(aWebProgress, aRequest, aLocation, aFlags) {
  is(aLocation.spec, kSecureURI + "#foo", "hashchange on HTTPS (3)");

  ok((aFlags & Components.interfaces.nsIWebProgressListener
                         .LOCATION_CHANGE_SAME_DOCUMENT),
     "We are in the same document as before (3)");

  ok(!(aFlags & Components.interfaces.nsIWebProgressListener
                          .LOCATION_CHANGE_ERROR_PAGE),
     "This page is not an error page.");

  ok((aWebProgress.QueryInterface(Components.interfaces.nsIDocShell)
                  .securityUI.state &
      Components.interfaces.nsIWebProgressListener.STATE_IS_SECURE),
     "This is a secure page (3)");

  /* Go to step 4. */
  setTimeout(step4A, 0);
}

/*****************************************************************************
 * Step 4: Go back from a secure page to an error page, and confirm UA knows
 *         it's not secure. (Bug 307027)
 *****************************************************************************/

function step4A() {
  gListener.callback = step4B;
  content.history.go(-2);
}

function step4B(aWebProgress, aRequest, aLocation, aFlags) {
  is(aLocation.spec, kDNSErrorURI, "Go back to the error URI (4)");

  ok(!(aFlags & Components.interfaces.nsIWebProgressListener
                          .LOCATION_CHANGE_SAME_DOCUMENT),
       "DocShell loaded a document (4)");

  ok((aFlags & Components.interfaces.nsIWebProgressListener
                         .LOCATION_CHANGE_ERROR_PAGE),
     "This page is an error page.");

  ok(!(aWebProgress.QueryInterface(Components.interfaces.nsIDocShell)
                   .securityUI.state &
       Components.interfaces.nsIWebProgressListener.STATE_IS_SECURE),
     "This is not a secure page (4)");

  /* End. */
  aWebProgress.removeProgressListener(gListener);
  delete(gListener);
  finish();
}
  ]]></script>

  <browser type="content-primary" flex="1" id="content" src="about:blank"/>
</window>