browser_privatebrowsing_certexceptionsui.js
Go to the documentation of this file.
1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * The contents of this file are subject to the Mozilla Public License Version
5  * 1.1 (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS" basis,
10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11  * for the specific language governing rights and limitations under the
12  * License.
13  *
14  * The Original Code is Private Browsing Tests.
15  *
16  * The Initial Developer of the Original Code is
17  * Ehsan Akhgari.
18  * Portions created by the Initial Developer are Copyright (C) 2009
19  * the Initial Developer. All Rights Reserved.
20  *
21  * Contributor(s):
22  * Ehsan Akhgari <ehsan.akhgari@gmail.com> (Original Author)
23  *
24  * Alternatively, the contents of this file may be used under the terms of
25  * either of the GNU General Public License Version 2 or later (the "GPL"),
26  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27  * in which case the provisions of the GPL or the LGPL are applicable instead
28  * of those above. If you wish to allow use of your version of this file only
29  * under the terms of either the GPL or the LGPL, and not to allow others to
30  * use your version of this file under the terms of the MPL, indicate your
31  * decision by deleting the provisions above and replace them with the notice
32  * and other provisions required by the GPL or the LGPL. If you do not delete
33  * the provisions above, a recipient may use your version of this file under
34  * the terms of any one of the MPL, the GPL or the LGPL.
35  *
36  * ***** END LICENSE BLOCK ***** */
37 
38 // This test makes sure that certificate exceptions UI behaves correctly
39 // inside the private browsing mode, based on whether it's opened from the prefs
40 // window or from the SSL error page (see bug 461627).
41 
42 function test() {
43  // initialization
44  let pb = Cc["@mozilla.org/privatebrowsing;1"].
45  getService(Ci.nsIPrivateBrowsingService);
46 
47  const EXCEPTIONS_DLG_URL = 'chrome://pippki/content/exceptionDialog.xul';
48  const EXCEPTIONS_DLG_FEATURES = 'chrome,centerscreen';
49  const INVALID_CERT_LOCATION = 'https://nocert.example.com/';
51 
52  // enter private browsing mode
53  pb.privateBrowsingEnabled = true;
54 
55  step1();
56 
57  // Test the certificate exceptions dialog as it is invoked from about:certerror
58  function step1() {
59  let params = {
60  exceptionAdded : false,
61  location: INVALID_CERT_LOCATION,
62  handlePrivateBrowsing : true,
63  prefetchCert: true,
64  };
65  function testCheckbox() {
66  let obsSvc = Cc["@mozilla.org/observer-service;1"].
67  getService(Ci.nsIObserverService);
68  obsSvc.addObserver({
69  observe: function(aSubject, aTopic, aData) {
70  obsSvc.removeObserver(this, "cert-exception-ui-ready", false);
71  ok(win.gCert, "The certificate information should be available now");
72 
73  let checkbox = win.document.getElementById("permanent");
74  ok(checkbox.hasAttribute("disabled"),
75  "the permanent checkbox should be disabled when handling the private browsing mode");
76  ok(!checkbox.hasAttribute("checked"),
77  "the permanent checkbox should not be checked when handling the private browsing mode");
78  win.close();
79  step2();
80  }
81  }, "cert-exception-ui-ready", false);
82  }
83  var win = openDialog(EXCEPTIONS_DLG_URL, "", EXCEPTIONS_DLG_FEATURES, params);
84  win.addEventListener("load", testCheckbox, false);
85  }
86 
87  // Test the certificate excetions dialog as it is invoked from the Preferences dialog
88  function step2() {
89  let params = {
90  exceptionAdded : false,
91  location: INVALID_CERT_LOCATION,
92  prefetchCert: true,
93  };
94  function testCheckbox() {
95  let obsSvc = Cc["@mozilla.org/observer-service;1"].
96  getService(Ci.nsIObserverService);
97  obsSvc.addObserver({
98  observe: function(aSubject, aTopic, aData) {
99  obsSvc.removeObserver(this, "cert-exception-ui-ready", false);
100  ok(win.gCert, "The certificate information should be available now");
101 
102  let checkbox = win.document.getElementById("permanent");
103  ok(!checkbox.hasAttribute("disabled"),
104  "the permanent checkbox should not be disabled when not handling the private browsing mode");
105  ok(checkbox.hasAttribute("checked"),
106  "the permanent checkbox should be checked when not handling the private browsing mode");
107  win.close();
108  cleanup();
109  }
110  }, "cert-exception-ui-ready", false);
111  }
112  var win = openDialog(EXCEPTIONS_DLG_URL, "", EXCEPTIONS_DLG_FEATURES, params);
113  win.addEventListener("load", testCheckbox, false);
114  }
115 
116  function cleanup() {
117  // leave the private browsing mode
118  pb.privateBrowsingEnabled = false;
119  finish();
120  }
121 }
const Cc
function step2()
getService(Ci.sbIFaceplateManager)
waitForExplicitFinish()
function cleanup()
const Ci
_updateTextAndScrollDataForFrame aData
sbDeviceFirmwareAutoCheckForUpdate prototype observe