diff options
Diffstat (limited to 'LayoutTests/storage/open-database-creation-callback.html')
-rw-r--r-- | LayoutTests/storage/open-database-creation-callback.html | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/LayoutTests/storage/open-database-creation-callback.html b/LayoutTests/storage/open-database-creation-callback.html new file mode 100644 index 0000000..ac24942 --- /dev/null +++ b/LayoutTests/storage/open-database-creation-callback.html @@ -0,0 +1,90 @@ +<html> +<head> +<script> +function log(message) +{ + document.getElementById("console").innerHTML += message + "<br>"; +} + +function finishTest() +{ + if (window.layoutTestController) + layoutTestController.notifyDone(); +} + +function runTest() +{ + if (window.layoutTestController) { + layoutTestController.clearAllDatabases(); + layoutTestController.setDatabaseQuota(32768); + layoutTestController.dumpDatabaseCallbacks(); + layoutTestController.dumpAsText(); + layoutTestController.waitUntilDone(); + } + + var transactionsRun = 0; + + // Open a new database with a creation callback, and make sure the creation callback is queued + var creationCallbackCalled1 = false; + var db1 = openDatabase("OpenDatabaseCreationCallback1", "1.0", "", 1, + function(db) { + creationCallbackCalled1 = true; + if (db.version != "") { + log("Creation callback was called with a database with version " + + db.version + "; empty string expected."); + finishTest(); + } + }); + + // Putting this code inside a transaction on 'db1' makes sure that it is executed after + // the creation callback is. + db1.transaction(function(tx) { + if (!creationCallbackCalled1) { + log("Creation callback for db1 was not called."); + finishTest(); + } + if (++transactionsRun == 2) + finishTest(); + }); + + // Try to open another handle to the same database. + // Since the version of this database is "" (empty string), openDatabase() should return + // a null handle and throw a INVALID_STATE_ERR exception. + var db1Fail = null; + try { + db1Fail = openDatabase("OpenDatabaseCreationCallback1", "1.0", "", 1); + log("This statement should not have been executed; an INVALID_STATE_ERR exception should've been thrown."); + finishTest(); + } catch(err) { + if (db1Fail) { + log("db1Fail should have been null."); + finishTest(); + } + } + + // Open a handle to another database, first without a creation callback, then with one. + // Make sure the creation callback is not called. + var creationCallbackCalled2 = false; + var db2 = openDatabase("OpenDatabaseCreationCallback2", "1.0", "", 1); + db2 = openDatabase("OpenDatabaseCreationCallback2", "1.0", "", 1, + function(db) { creationCallbackCalled2 = true; }); + db2.transaction(function(tx) { + if (creationCallbackCalled2) { + log("Creation callback for db2 should not have been called."); + finishTest(); + } + if (++transactionsRun == 2) + finishTest(); + }); +} + +</script> +</head> + +<body onload="runTest()"> +This test tests openDatabase()'s creation callback. +<pre id="console"> +</pre> +</body> + +</html> |