summaryrefslogtreecommitdiffstats
path: root/docshell/test/unit/test_setUsePrivateBrowsing.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /docshell/test/unit/test_setUsePrivateBrowsing.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'docshell/test/unit/test_setUsePrivateBrowsing.js')
-rw-r--r--docshell/test/unit/test_setUsePrivateBrowsing.js65
1 files changed, 65 insertions, 0 deletions
diff --git a/docshell/test/unit/test_setUsePrivateBrowsing.js b/docshell/test/unit/test_setUsePrivateBrowsing.js
new file mode 100644
index 000000000..739186895
--- /dev/null
+++ b/docshell/test/unit/test_setUsePrivateBrowsing.js
@@ -0,0 +1,65 @@
+"use strict";
+
+const {utils: Cu} = Components;
+
+Cu.import("resource://gre/modules/AppConstants.jsm");
+Cu.import("resource://gre/modules/Services.jsm");
+
+add_task(function*() {
+ let webNav = Services.appShell.createWindowlessBrowser(false);
+
+ let loadContext = webNav.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsILoadContext);
+
+ let docShell = webNav.getInterface(Ci.nsIDocShell);
+
+ equal(loadContext.usePrivateBrowsing, false, "Should start out in non-private mode");
+
+ loadContext.usePrivateBrowsing = true;
+ equal(loadContext.usePrivateBrowsing, true,
+ "Should be able to change to private mode prior to a document load");
+
+ loadContext.usePrivateBrowsing = false;
+ equal(loadContext.usePrivateBrowsing, false,
+ "Should be able to change to non-private mode prior to a document load");
+
+ let oa = docShell.getOriginAttributes();
+
+ oa.privateBrowsingId = 1;
+ docShell.setOriginAttributes(oa);
+
+ equal(loadContext.usePrivateBrowsing, true,
+ "Should be able to change origin attributes prior to a document load");
+
+ oa.privateBrowsingId = 0;
+ docShell.setOriginAttributes(oa);
+
+ equal(loadContext.usePrivateBrowsing, false,
+ "Should be able to change origin attributes prior to a document load");
+
+ webNav.loadURI("data:text/html,", webNav.LOAD_FLAGS_NONE, null, null, null);
+
+ // Return to the event loop so the load can begin.
+ yield new Promise(do_execute_soon);
+
+ // This causes a failed assertion rather than an exception on debug
+ // builds.
+ if (!AppConstants.DEBUG) {
+ Assert.throws(() => { loadContext.usePrivateBrowsing = true; },
+ /NS_ERROR_FAILURE/,
+ "Should not be able to change private browsing state after initial load has started");
+
+ oa.privateBrowsingId = 1;
+ Assert.throws(() => { docShell.setOriginAttributes(oa); },
+ /NS_ERROR_FAILURE/,
+ "Should not be able to change origin attributes after initial load has started");
+
+ equal(loadContext.usePrivateBrowsing, false,
+ "Should not be able to change private browsing state after initial load has started");
+
+ loadContext.usePrivateBrowsing = false;
+ ok(true, "Should be able to set usePrivateBrowsing to its current value even after initial load");
+ }
+
+ webNav.close();
+});