summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/newtab/browser_newtab_perwindow_private_browsing.js
blob: b330bec1307752960b67d74bd693ab89b207f06f (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

/*
 * These tests ensure that all changes made to the new tab page in private
 * browsing mode are discarded after switching back to normal mode again.
 * The private browsing mode should start with the current grid shown in normal
 * mode.
 */

add_task(function* () {
  // prepare the grid
  yield testOnWindow(undefined);
  yield setLinks("0,1,2,3,4,5,6,7,8,9");

  yield* addNewTabPageTab();
  yield pinCell(0);
  yield* checkGrid("0p,1,2,3,4,5,6,7,8");

  // open private window
  yield testOnWindow({private: true});

  yield* addNewTabPageTab();
  yield* checkGrid("0p,1,2,3,4,5,6,7,8");

  // modify the grid while we're in pb mode
  yield blockCell(1);
  yield* checkGrid("0p,2,3,4,5,6,7,8");

  yield unpinCell(0);
  yield* checkGrid("0,2,3,4,5,6,7,8");

  // open normal window
  yield testOnWindow(undefined);

  // check that the grid is the same as before entering pb mode
  yield* addNewTabPageTab();
  yield* checkGrid("0,2,3,4,5,6,7,8")
});

var windowsToClose = [];
function* testOnWindow(options) {
  let newWindowPromise = BrowserTestUtils.waitForNewWindow();
  var win = OpenBrowserWindow(options);
  windowsToClose.push(win);
  gWindow = win;
  yield newWindowPromise;
}

registerCleanupFunction(function () {
  gWindow = window;
  windowsToClose.forEach(function(win) {
    win.close();
  });
});