summaryrefslogtreecommitdiffstats
path: root/dom/indexedDB/test/browser_perwindow_privateBrowsing.js
blob: 08d329cbc4c68f7c94142503c2edd5fec917bfa3 (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
/**
 * Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

const testPageURL = "http://mochi.test:8888/browser/" +
  "dom/indexedDB/test/browser_permissionsPrompt.html";
const notificationID = "indexedDB-permissions-prompt";

function test()
{
  waitForExplicitFinish();
  // Avoids the actual prompt
  setPermission(testPageURL, "indexedDB");
  executeSoon(test1);
}

function test1()
{
  gBrowser.selectedTab = gBrowser.addTab();
  gBrowser.selectedBrowser.addEventListener("load", function () {
    if (content.location != testPageURL) {
      content.location = testPageURL;
      return;
    }
    gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);

    setFinishedCallback(function(isIDBDatabase, exception) {
      ok(isIDBDatabase,
         "First database creation was successful");
      ok(!exception, "No exception");
      gBrowser.removeCurrentTab();

      executeSoon(test2);
    });
  }, true);
  content.location = testPageURL;
}

function test2()
{
  var win = OpenBrowserWindow({private: true});
  win.addEventListener("load", function onLoad() {
    win.removeEventListener("load", onLoad, false);
    executeSoon(() => test3(win));
  }, false);
  registerCleanupFunction(() => win.close());
}

function test3(win)
{
  win.gBrowser.selectedTab = win.gBrowser.addTab();
  win.gBrowser.selectedBrowser.addEventListener("load", function () {
    if (win.content.location != testPageURL) {
      win.content.location = testPageURL;
      return;
    }
    win.gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);

    setFinishedCallback(function(isIDBDatabase, exception) {
      ok(!isIDBDatabase, "No database");
      is(exception, "InvalidStateError", "Correct exception");
      win.gBrowser.removeCurrentTab();

      executeSoon(finish);
    }, win);
  }, true);
  win.content.location = testPageURL;
}