summaryrefslogtreecommitdiffstats
path: root/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_sidebar.js
blob: 58a333bfdb30e0b6c61bc6b3c71ede62fa018166 (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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// This test makes sure that Sidebars do not migrate across windows with
// different privacy states

// See Bug 885054: https://bugzilla.mozilla.org/show_bug.cgi?id=885054

function test() {
  waitForExplicitFinish();

  // opens a sidebar
  function openSidebar(win) {
    return win.SidebarUI.show("viewBookmarksSidebar").then(() => win);
  }

  let windowCache = [];
  function cacheWindow(w) {
    windowCache.push(w);
    return w;
  }
  function closeCachedWindows() {
    windowCache.forEach(w => w.close());
  }

  // Part 1: NON PRIVATE WINDOW -> PRIVATE WINDOW
  openWindow(window, {}, 1)
    .then(cacheWindow)
    .then(openSidebar)
    .then(win => openWindow(win, { private: true }))
    .then(cacheWindow)
    .then(function ({ document }) {
      let sidebarBox = document.getElementById("sidebar-box");
      is(
        sidebarBox.hidden,
        true,
        "Opening a private window from reg window does not open the sidebar"
      );
    })
    .then(closeCachedWindows)
    // Part 2: NON PRIVATE WINDOW -> NON PRIVATE WINDOW
    .then(() => openWindow(window))
    .then(cacheWindow)
    .then(openSidebar)
    .then(win => openWindow(win))
    .then(cacheWindow)
    .then(function ({ document }) {
      let sidebarBox = document.getElementById("sidebar-box");
      is(
        sidebarBox.hidden,
        false,
        "Opening a reg window from reg window does open the sidebar"
      );
    })
    .then(closeCachedWindows)
    // Part 3: PRIVATE WINDOW -> NON PRIVATE WINDOW
    .then(() => openWindow(window, { private: true }))
    .then(cacheWindow)
    .then(openSidebar)
    .then(win => openWindow(win))
    .then(cacheWindow)
    .then(function ({ document }) {
      let sidebarBox = document.getElementById("sidebar-box");
      is(
        sidebarBox.hidden,
        true,
        "Opening a reg window from a private window does not open the sidebar"
      );
    })
    .then(closeCachedWindows)
    // Part 4: PRIVATE WINDOW -> PRIVATE WINDOW
    .then(() => openWindow(window, { private: true }))
    .then(cacheWindow)
    .then(openSidebar)
    .then(win => openWindow(win, { private: true }))
    .then(cacheWindow)
    .then(function ({ document }) {
      let sidebarBox = document.getElementById("sidebar-box");
      is(
        sidebarBox.hidden,
        false,
        "Opening a private window from private window does open the sidebar"
      );
    })
    .then(closeCachedWindows)
    .then(finish);
}