Chromium Code Reviews| Index: chrome/test/data/extensions/platform_apps/web_view_isolation/storage.js |
| diff --git a/chrome/test/data/extensions/platform_apps/web_view_isolation/storage.js b/chrome/test/data/extensions/platform_apps/web_view_isolation/storage.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..df84bf5ec9ed8912e3112b2835b3e6a3190815fe |
| --- /dev/null |
| +++ b/chrome/test/data/extensions/platform_apps/web_view_isolation/storage.js |
| @@ -0,0 +1,74 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
|
awong
2012/11/02 21:56:13
Can we add a comment explaining the basic action/o
nasko
2012/11/03 00:36:24
Done.
|
| +function initDomStorage(value) { |
| + window.localStorage.setItem('foo', 'local-' + value); |
| + window.sessionStorage.setItem('foo', 'session-' + value); |
| +} |
| + |
|
awong
2012/11/02 21:56:13
whack extra newline.
nasko
2012/11/03 00:36:24
Done.
|
| + |
| +var isolation = {}; |
| +window.indexedDB = window.indexedDB || window.webkitIndexedDB; |
| + |
| +isolation.db = null; |
| +isolation.onerror = function(e) { |
| + document.title = "error"; |
| +}; |
| + |
| +function initIDB() { |
| + var request = indexedDB.open("isolation"); |
| + request.onsuccess = function(e) { |
|
awong
2012/11/02 21:56:13
holy crap this is a complicated API.
nasko
2012/11/03 00:36:24
: )
|
| + var v = 3; |
| + isolation.db = e.target.result; |
| + if (v != isolation.db.version) { |
| + var setVrequest = isolation.db.setVersion(v); |
| + setVrequest.onerror = isolation.onerror; |
| + setVrequest.onsuccess = function(e) { |
| + var store = isolation.db.createObjectStore( |
| + "partitions", {keyPath: "id"}); |
| + e.target.transaction.oncomplete = function() { |
| + document.title = "idb created"; |
| + } |
| + }; |
| + } else { |
| + document.title = "idb open"; |
| + } |
| + }; |
| + request.onerror = isolation.onerror; |
| +} |
| + |
| +function addItemIDB(id, value) { |
| + var trans = isolation.db.transaction(["partitions"], "readwrite"); |
| + var store = trans.objectStore("partitions"); |
| + var data = { "partition": value, "id": id }; |
| + |
| + var request = store.put(data); |
| + request.onsuccess = function(e) { |
| + document.title = "addItemIDB complete"; |
| + }; |
| + request.onerror = isolation.onerror; |
| +}; |
| + |
| +var partition = null; |
| + |
| +function getValueIDB() { |
| + return partition; |
| +} |
| + |
| +function readItemIDB(id) { |
| + partition = null; |
| + var trans = isolation.db.transaction(["partitions"], "readwrite"); |
| + var store = trans.objectStore("partitions"); |
| + |
| + var request = store.get(id); |
| + request.onsuccess = function(e) { |
| + if (!!e.target.result != false) { |
| + partition = request.result.partition; |
| + } |
| + document.title = "readItemIDB complete"; |
| + } |
|
awong
2012/11/02 21:56:13
need ; to be safe
nasko
2012/11/03 00:36:24
Done.
|
| + request.onerror = isolation.onerror; |
| +} |
| + |
| + |