summaryrefslogtreecommitdiffstats
path: root/dom/cache/test/mochitest/browser_cache_pb_window.js
blob: 05a0aa22b12cca31df9cd239e8490daba86cbf7c (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
var name = 'pb-window-cache';

function testMatch(win) {
  return new Promise(function(resolve, reject) {
    win.caches.match('http://foo.com').then(function(response) {
      ok(false, 'caches.match() should not return success');
      reject();
    }).catch(function(err) {
      is('SecurityError', err.name, 'caches.match() should throw SecurityError');
      resolve();
    });
  });
}

function testHas(win) {
  return new Promise(function(resolve, reject) {
    win.caches.has(name).then(function(result) {
      ok(false, 'caches.has() should not return success');
      reject();
    }).catch(function(err) {
      is('SecurityError', err.name, 'caches.has() should throw SecurityError');
      resolve();
    });
  });
}

function testOpen(win) {
  return new Promise(function(resolve, reject) {
    win.caches.open(name).then(function(c) {
      ok(false, 'caches.open() should not return success');
      reject();
    }).catch(function(err) {
      is('SecurityError', err.name, 'caches.open() should throw SecurityError');
      resolve();
    });
  });
}

function testDelete(win) {
  return new Promise(function(resolve, reject) {
    win.caches.delete(name).then(function(result) {
      ok(false, 'caches.delete() should not return success');
      reject();
    }).catch(function(err) {
      is('SecurityError', err.name, 'caches.delete() should throw SecurityError');
      resolve();
    });
  });
}

function testKeys(win) {
  return new Promise(function(resolve, reject) {
    win.caches.keys().then(function(names) {
      ok(false, 'caches.keys() should not return success');
      reject();
    }).catch(function(err) {
      is('SecurityError', err.name, 'caches.keys() should throw SecurityError');
      resolve();
    });
  });
}

function test() {
  waitForExplicitFinish();
  SpecialPowers.pushPrefEnv({'set': [['dom.caches.enabled', true],
                                     ['dom.caches.testing.enabled', true]]},
                            function() {
    var privateWin = OpenBrowserWindow({private: true});
    privateWin.addEventListener('load', function() {
      Promise.all([
        testMatch(privateWin),
        testHas(privateWin),
        testOpen(privateWin),
        testDelete(privateWin),
        testKeys(privateWin)
      ]).then(function() {
        BrowserTestUtils.closeWindow(privateWin).then(finish);
      });
    });
  });
}