summaryrefslogtreecommitdiffstats
path: root/dom/tests/browser/browser_localStorage_privatestorageevent.js
blob: 83458a399750b65f8314b52176bc28435aa6fe27 (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
add_task(function *() {
  var privWin = OpenBrowserWindow({private: true});
  yield new privWin.Promise(resolve => {
    privWin.addEventListener('load', function onLoad() {
      privWin.removeEventListener('load', onLoad, false);
      resolve();
    });
  });

  var pubWin = OpenBrowserWindow({private: false});
  yield new pubWin.Promise(resolve => {
    pubWin.addEventListener('load', function onLoad() {
      pubWin.removeEventListener('load', onLoad, false);
      resolve();
    });
  });

  var URL = "http://mochi.test:8888/browser/dom/tests/browser/page_privatestorageevent.html";

  var privTab = privWin.gBrowser.addTab(URL);
  yield BrowserTestUtils.browserLoaded(privWin.gBrowser.getBrowserForTab(privTab));
  var privBrowser = gBrowser.getBrowserForTab(privTab);

  var pubTab = pubWin.gBrowser.addTab(URL);
  yield BrowserTestUtils.browserLoaded(pubWin.gBrowser.getBrowserForTab(pubTab));
  var pubBrowser = gBrowser.getBrowserForTab(pubTab);

  // Check if pubWin can see privWin's storage events
  yield ContentTask.spawn(pubBrowser, null, function(opts) {
    content.window.gotStorageEvent = false;
    content.window.addEventListener('storage', ev => {
      content.window.gotStorageEvent = true;
    });
  });

  yield ContentTask.spawn(privBrowser, null, function(opts) {
    content.window.localStorage['key'] = 'ablooabloo';
  });

  let pubSaw = yield ContentTask.spawn(pubBrowser, null, function(opts) {
    return content.window.gotStorageEvent;
  });

  ok(!pubSaw, "pubWin shouldn't be able to see privWin's storage events");

  yield ContentTask.spawn(privBrowser, null, function(opts) {
    content.window.gotStorageEvent = false;
    content.window.addEventListener('storage', ev => {
      content.window.gotStorageEvent = true;
    });
  });

  // Check if privWin can see pubWin's storage events
  yield ContentTask.spawn(privBrowser, null, function(opts) {
    content.window.gotStorageEvent = false;
    content.window.addEventListener('storage', ev => {
      content.window.gotStorageEvent = true;
    });
  });

  yield ContentTask.spawn(pubBrowser, null, function(opts) {
    content.window.localStorage['key'] = 'ablooabloo';
  });

  let privSaw = yield ContentTask.spawn(privBrowser, null, function(opts) {
    return content.window.gotStorageEvent;
  });

  ok(!privSaw, "privWin shouldn't be able to see pubWin's storage events");

  yield BrowserTestUtils.removeTab(privTab);
  yield BrowserTestUtils.closeWindow(privWin);

  yield BrowserTestUtils.removeTab(pubTab);
  yield BrowserTestUtils.closeWindow(pubWin);
});