|
1 'use strict'; |
|
2 |
|
3 const tabs = require('sdk/tabs'); |
|
4 const { isPrivate } = require('sdk/private-browsing'); |
|
5 const { getOwnerWindow } = require('sdk/private-browsing/window/utils'); |
|
6 const { promise: windowPromise, close, focus } = require('sdk/window/helpers'); |
|
7 const { getMostRecentBrowserWindow } = require('sdk/window/utils'); |
|
8 |
|
9 exports.testOpenTabWithPrivateActiveWindowNoIsPrivateOption = function(assert, done) { |
|
10 let window = getMostRecentBrowserWindow().OpenBrowserWindow({ private: true }); |
|
11 |
|
12 windowPromise(window, 'load').then(focus).then(function (window) { |
|
13 assert.ok(isPrivate(window), 'new window is private'); |
|
14 |
|
15 tabs.open({ |
|
16 url: 'about:blank', |
|
17 onOpen: function(tab) { |
|
18 assert.ok(isPrivate(tab), 'new tab is private'); |
|
19 assert.ok(isPrivate(getOwnerWindow(tab)), 'new tab window is private'); |
|
20 assert.strictEqual(getOwnerWindow(tab), window, 'the tab window and the private window are the same'); |
|
21 |
|
22 close(window).then(done).then(null, assert.fail); |
|
23 } |
|
24 }) |
|
25 }).then(null, assert.fail); |
|
26 } |
|
27 |
|
28 exports.testOpenTabWithNonPrivateActiveWindowNoIsPrivateOption = function(assert, done) { |
|
29 let window = getMostRecentBrowserWindow().OpenBrowserWindow({ private: false }); |
|
30 |
|
31 windowPromise(window, 'load').then(focus).then(function (window) { |
|
32 assert.equal(isPrivate(window), false, 'new window is not private'); |
|
33 |
|
34 tabs.open({ |
|
35 url: 'about:blank', |
|
36 onOpen: function(tab) { |
|
37 assert.equal(isPrivate(tab), false, 'new tab is not private'); |
|
38 assert.equal(isPrivate(getOwnerWindow(tab)), false, 'new tab window is not private'); |
|
39 assert.strictEqual(getOwnerWindow(tab), window, 'the tab window and the new window are the same'); |
|
40 |
|
41 close(window).then(done).then(null, assert.fail); |
|
42 } |
|
43 }) |
|
44 }).then(null, assert.fail); |
|
45 } |
|
46 |
|
47 exports.testOpenTabWithPrivateActiveWindowWithIsPrivateOptionTrue = function(assert, done) { |
|
48 let window = getMostRecentBrowserWindow().OpenBrowserWindow({ private: true }); |
|
49 |
|
50 windowPromise(window, 'load').then(focus).then(function (window) { |
|
51 assert.ok(isPrivate(window), 'new window is private'); |
|
52 |
|
53 tabs.open({ |
|
54 url: 'about:blank', |
|
55 isPrivate: true, |
|
56 onOpen: function(tab) { |
|
57 assert.ok(isPrivate(tab), 'new tab is private'); |
|
58 assert.ok(isPrivate(getOwnerWindow(tab)), 'new tab window is private'); |
|
59 assert.strictEqual(getOwnerWindow(tab), window, 'the tab window and the private window are the same'); |
|
60 |
|
61 close(window).then(done).then(null, assert.fail); |
|
62 } |
|
63 }) |
|
64 }).then(null, assert.fail); |
|
65 } |
|
66 |
|
67 exports.testOpenTabWithNonPrivateActiveWindowWithIsPrivateOptionFalse = function(assert, done) { |
|
68 let window = getMostRecentBrowserWindow().OpenBrowserWindow({ private: false }); |
|
69 |
|
70 windowPromise(window, 'load').then(focus).then(function (window) { |
|
71 assert.equal(isPrivate(window), false, 'new window is not private'); |
|
72 |
|
73 tabs.open({ |
|
74 url: 'about:blank', |
|
75 isPrivate: false, |
|
76 onOpen: function(tab) { |
|
77 assert.equal(isPrivate(tab), false, 'new tab is not private'); |
|
78 assert.equal(isPrivate(getOwnerWindow(tab)), false, 'new tab window is not private'); |
|
79 assert.strictEqual(getOwnerWindow(tab), window, 'the tab window and the new window are the same'); |
|
80 |
|
81 close(window).then(done).then(null, assert.fail); |
|
82 } |
|
83 }) |
|
84 }).then(null, assert.fail); |
|
85 } |