Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / storage / websql / open-database-creation-callback.html
blob64af63f7181d0dde0a07197ccbb0852e3e0d3eb1
1 <html>
2 <head>
3 <script>
4 function log(message)
6 document.getElementById("console").innerHTML += message + "<br>";
9 function finishTest()
11 if (window.testRunner)
12 testRunner.notifyDone();
15 function runTest()
17 if (window.testRunner) {
18 testRunner.clearAllDatabases();
19 testRunner.setDatabaseQuota(32768);
20 testRunner.dumpDatabaseCallbacks();
21 testRunner.dumpAsText();
22 testRunner.waitUntilDone();
25 var transactionsRun = 0;
27 // Open a new database with a creation callback, and make sure the creation callback is queued
28 var creationCallbackCalled1 = false;
29 var db1Name = "OpenDatabaseCreationCallback1" + (new Date()).getTime();
30 var db1 = openDatabase(db1Name, "1.0", "", 1,
31 function(db) {
32 creationCallbackCalled1 = true;
33 if (db.version != "") {
34 log("Creation callback was called with a database with version " +
35 db.version + "; empty string expected.");
36 finishTest();
38 });
40 // Putting this code inside a transaction on 'db1' makes sure that it is executed after
41 // the creation callback is.
42 db1.transaction(function(tx) {
43 if (!creationCallbackCalled1) {
44 log("Creation callback for db1 was not called.");
45 finishTest();
47 if (++transactionsRun == 2)
48 finishTest();
49 });
51 // Try to open another handle to the same database.
52 // Since the version of this database is "" (empty string), openDatabase() should return
53 // a null handle and throw a INVALID_STATE_ERR exception.
54 var db1Fail = null;
55 try {
56 db1Fail = openDatabase(db1Name, "1.0", "", 1);
57 log("This statement should not have been executed; an INVALID_STATE_ERR exception should've been thrown.");
58 finishTest();
59 } catch(err) {
60 if (db1Fail) {
61 log("db1Fail should have been null.");
62 finishTest();
66 // Open a handle to another database, first without a creation callback, then with one.
67 // Make sure the creation callback is not called.
68 var creationCallbackCalled2 = false;
69 var db2 = openDatabase("OpenDatabaseCreationCallback2", "1.0", "", 1);
70 db2 = openDatabase("OpenDatabaseCreationCallback2", "1.0", "", 1,
71 function(db) { creationCallbackCalled2 = true; });
72 db2.transaction(function(tx) {
73 if (creationCallbackCalled2) {
74 log("Creation callback for db2 should not have been called.");
75 finishTest();
77 if (++transactionsRun == 2)
78 finishTest();
79 });
82 </script>
83 </head>
85 <body onload="runTest()">
86 This test tests openDatabase()'s creation callback.
87 <pre id="console">
88 </pre>
89 </body>
91 </html>