1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // This method initializes the two types of DOM storage.
6 function initDomStorage(value) {
7 window.localStorage.setItem('foo', 'local-' + value);
8 window.sessionStorage.setItem('bar', 'session-' + value);
11 // The code below is used for testing IndexedDB isolation.
12 // The test uses three basic operations -- open, read, write -- to verify proper
13 // isolation across webview tags with different storage partitions.
14 // Each of the basic functions below sets document.title to a specific text,
15 // which the main browser test is waiting for. This is needed because all
16 // the functions get their results through callbacks and cannot return the
19 window.indexedDB = window.indexedDB || window.webkitIndexedDB;
22 isolation.onerror = function(e) {
23 document.title = "error";
26 // This method opens the database and creates the objectStore if it doesn't
27 // exist. It sets the document.title to a string referring to which
28 // operation has been performed - open vs create.
31 var ranVersionChangeTransaction = false;
32 var request = indexedDB.open("isolation", v);
33 request.onupgradeneeded = function(e) {
34 isolation.db = e.target.result;
35 var store = isolation.db.createObjectStore(
36 "partitions", {keyPath: "id"});
37 e.target.transaction.oncomplete = function() {
38 ranVersionChangeTransaction = true;
41 request.onsuccess = function(e) {
42 isolation.db = e.target.result;
43 if (ranVersionChangeTransaction) {
44 document.title = "idb created";
46 document.title = "idb open";
49 request.onerror = isolation.onerror;
50 request.onblocked = isolation.onerror;
53 // This method adds a |value| to the database identified by |id|.
54 function addItemIDB(id, value) {
55 var trans = isolation.db.transaction(["partitions"], "readwrite");
56 var store = trans.objectStore("partitions");
57 var data = { "partition": value, "id": id };
59 var request = store.put(data);
60 request.onsuccess = function(e) {
61 document.title = "addItemIDB complete";
63 request.onerror = isolation.onerror;
66 var storedValue = null;
68 // This method reads an item from the database, identified by |id|. Since
69 // the value cannot be returned directly, it is saved into the global
70 // "storedValue" variable, which is then read through getValueIDB().
71 function readItemIDB(id) {
73 var trans = isolation.db.transaction(["partitions"], "readwrite");
74 var store = trans.objectStore("partitions");
76 var request = store.get(id);
77 request.onsuccess = function(e) {
78 if (!!e.target.result != false) {
79 storedValue = request.result.partition;
81 document.title = "readItemIDB complete";
83 request.onerror = isolation.onerror;
86 function getValueIDB() {