dom/indexedDB/test/file_app_isolation.html

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

michael@0 1 <!DOCTYPE html>
michael@0 2 <html>
michael@0 3 <body>
michael@0 4 foobar!
michael@0 5 </body>
michael@0 6 <script>
michael@0 7 var data = [
michael@0 8 { id: "0", name: "foo" },
michael@0 9 ];
michael@0 10
michael@0 11 var action = window.location.search.substring(1);
michael@0 12 var finished = false;
michael@0 13 var created = false; // We use that for 'read-no' action.
michael@0 14
michael@0 15 function finish(value) {
michael@0 16 value ? alert('success') : alert('failure');
michael@0 17 finished = true;
michael@0 18 }
michael@0 19
michael@0 20 var request = window.indexedDB.open('AppIsolationTest');
michael@0 21
michael@0 22 request.onupgradeneeded = function(event) {
michael@0 23 if (finished) {
michael@0 24 finish(false);
michael@0 25 return;
michael@0 26 }
michael@0 27
michael@0 28 switch (action) {
michael@0 29 case 'read-no':
michael@0 30 created = true;
michael@0 31 break;
michael@0 32 case 'read-yes':
michael@0 33 finish(false);
michael@0 34 break;
michael@0 35 case 'write':
michael@0 36 created = true;
michael@0 37
michael@0 38 var db = event.target.result;
michael@0 39
michael@0 40 var objectStore = db.createObjectStore("test", { keyPath: "id" });
michael@0 41 for (var i in data) {
michael@0 42 objectStore.add(data[i]);
michael@0 43 }
michael@0 44 break;
michael@0 45 }
michael@0 46 }
michael@0 47
michael@0 48 request.onsuccess = function(event) {
michael@0 49 if (finished) {
michael@0 50 finish(false);
michael@0 51 return;
michael@0 52 }
michael@0 53
michael@0 54 var db = event.target.result;
michael@0 55
michael@0 56 // Think about close the db!
michael@0 57 switch (action) {
michael@0 58 case 'read-no':
michael@0 59 db.close();
michael@0 60
michael@0 61 if (created) { // That means we have created it.
michael@0 62 indexedDB.deleteDatabase('AppIsolationTest').onsuccess = function() {
michael@0 63 finish(true);
michael@0 64 };
michael@0 65 } else {
michael@0 66 finish(false);
michael@0 67 }
michael@0 68 break;
michael@0 69 case 'read-yes':
michael@0 70 db.transaction("test").objectStore("test").get("0").onsuccess = function(event) {
michael@0 71 var name = event.target.result.name;
michael@0 72 db.close();
michael@0 73
michael@0 74 indexedDB.deleteDatabase('AppIsolationTest').onsuccess = function() {
michael@0 75 finish(name == 'foo');
michael@0 76 };
michael@0 77 };
michael@0 78 break;
michael@0 79 case 'write':
michael@0 80 db.close();
michael@0 81
michael@0 82 // Success only if the db was actually created.
michael@0 83 finish(created);
michael@0 84 break;
michael@0 85 }
michael@0 86 };
michael@0 87 </script>
michael@0 88 </html>

mercurial