summaryrefslogtreecommitdiffstats
path: root/dom/indexedDB/test/leaving_page_iframe.html
blob: 4ed299df33104357206f4aac0eec0f759e3043ff (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
<!DOCTYPE html>
<html>
<head>
  <script>
var db;
function startDBWork() {
  indexedDB.open(parent.location, 1).onupgradeneeded = function(e) {
    db = e.target.result;
    if (db.objectStoreNames.contains("mystore")) {
      db.deleteObjectStore("mystore");
    }
    var store = db.createObjectStore("mystore");
    store.add({ hello: "world" }, 42);
    e.target.onsuccess = madeMod;
  };
}

function madeMod() {
  var trans = db.transaction(["mystore"], "readwrite");
  var store = trans.
              objectStore("mystore");
  trans.oncomplete = function() {
    parent.postMessage("didcommit", "*");
  };

  store.put({ hello: "officer" }, 42).onsuccess = function(e) {
    // Make this transaction run until the end of time or until the page is
    // navigated away, whichever comes first.
    function doGet() {
      store.get(42).onsuccess = doGet;
    }
    doGet();
    document.location = "about:blank";
  };
}
  </script>
</head>
<body onload="startDBWork();">
  This is page one.
</body>
</html>