summaryrefslogtreecommitdiffstats
path: root/dom/indexedDB/test/third_party_iframe1.html
blob: d0db9a2602bc2a065fc3cc3a43e09be2f2ab5f1e (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
<!--
  Any copyright is dedicated to the Public Domain.
  http://creativecommons.org/publicdomain/zero/1.0/
-->
<html>
<head>
  <title>Indexed Database Test</title>

  <script type="text/javascript">
    function messageListener(event) {
      let message = JSON.parse(event.data);

      if (message.source == "parent") {
        document.getElementById("iframe2").src = message.href;
      }
      else if (message.source == "iframe2") {
        parent.postMessage(event.data, "*");
      }
    }

    function report(result) {
      let message = { source: "iframe1" };
      message.result = result;
      window.parent.postMessage(JSON.stringify(message), "*");
    }

    function runIndexedDBTest() {
      window.addEventListener('message', messageListener);

      try {
        let request = indexedDB.open(window.location.pathname, 1);
        request.onsuccess = function(event) {
          report(!!(event.target.result instanceof IDBDatabase));
        };
      }
      catch (e) {
        report(false);
      }
    }
  </script>

</head>

<body onload="runIndexedDBTest();">
  <iframe id="iframe2"></iframe>
</body>

</html>