summaryrefslogtreecommitdiffstats
path: root/netwerk/cookie/test/browser/browser_indexedDB.js
blob: 1da0940c4e4a27a01a6135fb1cf2b76b46fa3086 (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
"use strict";

CookiePolicyHelper.runTest("IndexedDB", {
  cookieJarAccessAllowed: async w => {
    w.indexedDB.open("test", "1");
    ok(true, "IDB should be allowed");
  },

  cookieJarAccessDenied: async w => {
    try {
      w.indexedDB.open("test", "1");
      ok(false, "IDB should be blocked");
    } catch (e) {
      ok(true, "IDB should be blocked");
      is(e.name, "SecurityError", "We want a security error message.");
    }
  },
});

CookiePolicyHelper.runTest("IndexedDB in workers", {
  cookieJarAccessAllowed: async w => {
    function nonBlockCode() {
      indexedDB.open("test", "1");
      postMessage(true);
    }

    let blob = new w.Blob([nonBlockCode.toString() + "; nonBlockCode();"]);
    ok(blob, "Blob has been created");

    let blobURL = w.URL.createObjectURL(blob);
    ok(blobURL, "Blob URL has been created");

    let worker = new w.Worker(blobURL);
    ok(worker, "Worker has been created");

    await new w.Promise((resolve, reject) => {
      worker.onmessage = function(e) {
        if (e.data) {
          resolve();
        } else {
          reject();
        }
      };

      worker.onerror = function(e) {
        reject();
      };
    });
  },

  cookieJarAccessDenied: async w => {
    function blockCode() {
      try {
        indexedDB.open("test", "1");
        postMessage(false);
      } catch (e) {
        postMessage(e.name == "SecurityError");
      }
    }

    let blob = new w.Blob([blockCode.toString() + "; blockCode();"]);
    ok(blob, "Blob has been created");

    let blobURL = w.URL.createObjectURL(blob);
    ok(blobURL, "Blob URL has been created");

    let worker = new w.Worker(blobURL);
    ok(worker, "Worker has been created");

    await new w.Promise((resolve, reject) => {
      worker.onmessage = function(e) {
        if (e.data) {
          resolve();
        } else {
          reject();
        }
      };

      worker.onerror = function(e) {
        reject();
      };
    });
  },
});