1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <!DOCTYPE html>
- <html>
- <body>
- foobar!
- </body>
- <script>
- var data = [
- { id: "0", name: "foo" },
- ];
- var action = window.location.search.substring(1);
- var finished = false;
- var created = false; // We use that for 'read-no' action.
- function finish(value) {
- value ? alert('success') : alert('failure');
- finished = true;
- }
- var request = window.indexedDB.open('AppIsolationTest');
- request.onupgradeneeded = function(event) {
- if (finished) {
- finish(false);
- return;
- }
- switch (action) {
- case 'read-no':
- created = true;
- break;
- case 'read-yes':
- finish(false);
- break;
- case 'write':
- created = true;
- var db = event.target.result;
- var objectStore = db.createObjectStore("test", { keyPath: "id" });
- for (var i in data) {
- objectStore.add(data[i]);
- }
- break;
- }
- }
- request.onsuccess = function(event) {
- if (finished) {
- finish(false);
- return;
- }
- var db = event.target.result;
- // Think about close the db!
- switch (action) {
- case 'read-no':
- db.close();
- if (created) { // That means we have created it.
- indexedDB.deleteDatabase('AppIsolationTest').onsuccess = function() {
- finish(true);
- };
- } else {
- finish(false);
- }
- break;
- case 'read-yes':
- db.transaction("test").objectStore("test").get("0").onsuccess = function(event) {
- var name = event.target.result.name;
- db.close();
- indexedDB.deleteDatabase('AppIsolationTest').onsuccess = function() {
- finish(name == 'foo');
- };
- };
- break;
- case 'write':
- db.close();
- // Success only if the db was actually created.
- finish(created);
- break;
- }
- };
- </script>
- </html>
|