| OLD | NEW |
| 1 <script> | 1 <!-- |
| 2 // store some stuff in local storage | 2 * Copyright (c) 2011 The Chromium Authors. All rights reserved. Use of this |
| 3 localStorage.foo = "bar"; | 3 * source code is governed by a BSD-style license that can be found in the |
| 4 | 4 * LICENSE file. |
| 5 console.log("Opening database..."); | 5 --> |
| 6 // store some stuff in a database | 6 <script src="background.js"></script> |
| 7 var db = window.openDatabase("mydb2", "1.0", "database test", 2048); | |
| 8 if (!db) | |
| 9 chrome.test.notifyFail("failed to open database"); | |
| 10 | |
| 11 console.log("Performing transaction..."); | |
| 12 db.transaction(function(tx) { | |
| 13 tx.executeSql("drop table if exists note", [], onDropSuccess, onSqlError); | |
| 14 tx.executeSql("create table note (body text)", [], onCreateSuccess, onSqlErr
or); | |
| 15 tx.executeSql("insert into note values ('hotdog')", [], onSqlExecuted, | |
| 16 onSqlError); | |
| 17 }, function(error) { | |
| 18 chrome.test.notifyFail(error.message); | |
| 19 }); | |
| 20 | |
| 21 function onDropSuccess(tx, res) { | |
| 22 console.log("note table dropped"); | |
| 23 } | |
| 24 function onCreateSuccess(tx, res) { | |
| 25 console.log("note table created"); | |
| 26 } | |
| 27 function onSqlError(tx, error) { | |
| 28 chrome.test.notifyFail(error.message); | |
| 29 } | |
| 30 function onSqlExecuted() { | |
| 31 console.log("Opening tab..."); | |
| 32 // Open a tab. This doesn't really prove we're writing to disk, but it is | |
| 33 // difficult to prove that without shutting down the process. We'll just | |
| 34 // trust that if this next trick works, that the real testing for local | |
| 35 // storage is good enough to catch more subtle errors. | |
| 36 chrome.tabs.create({ | |
| 37 url: "tab.html" | |
| 38 }); | |
| 39 } | |
| 40 </script> | |
| OLD | NEW |