Commit e7beae72 authored by dumi@chromium.org's avatar dumi@chromium.org

WebCore: Implementing DatabaseSync::transaction() and DatabaseSync::changeVersion().

https://bugs.webkit.org/show_bug.cgi?id=40607

Reviewed by Darin Fisher

Tests: fast/workers/storage/change-version-handle-reuse-sync.html
       fast/workers/storage/change-version-sync.html
       fast/workers/storage/empty-statement-sync.html
       fast/workers/storage/execute-sql-args-sync.html
       fast/workers/storage/executesql-accepts-only-one-statement-sync.html
       fast/workers/storage/multiple-transactions-on-different-handles-sync.html
       fast/workers/storage/open-database-creation-callback-sync.html
       fast/workers/storage/open-database-empty-version-sync.html
       fast/workers/storage/open-database-inputs-sync.html
       fast/workers/storage/open-database-set-empty-version-sync.html
       fast/workers/storage/open-database-while-transaction-in-progress-sync.html
       fast/workers/storage/sql-data-types-sync.html
       fast/workers/storage/sql-exception-codes-sync.html
       fast/workers/storage/test-authorizer-sync.html
       fast/workers/storage/transaction-in-transaction-sync.html

* CMakeLists.txt:
* GNUmakefile.am:
* WebCore.gypi:
* WebCore.pro:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* storage/AbstractDatabase.cpp:
(WebCore::AbstractDatabase::maximumSize):
(WebCore::AbstractDatabase::incrementalVacuumIfNeeded):
* storage/AbstractDatabase.h:
(WebCore::AbstractDatabase::sqliteDatabase):
* storage/ChangeVersionWrapper.cpp:
(WebCore::ChangeVersionWrapper::performPreflight):
(WebCore::ChangeVersionWrapper::performPostflight):
* storage/Database.cpp:
(WebCore::Database::performGetTableNames):
* storage/Database.h:
* storage/DatabaseAuthorizer.cpp:
(WebCore::DatabaseAuthorizer::createVTable):
(WebCore::DatabaseAuthorizer::dropVTable):
* storage/DatabaseCallback.h:
* storage/DatabaseSync.cpp:
(WebCore::ChangeVersionPreflightStep::create):
(WebCore::ChangeVersionPreflightStep::performStep):
(WebCore::ChangeVersionPreflightStep::ChangeVersionPreflightStep):
(WebCore::ChangeVersionPostflightStep::create):
(WebCore::ChangeVersionPostflightStep::performStep):
(WebCore::ChangeVersionPostflightStep::ChangeVersionPostflightStep):
(WebCore::DatabaseSync::changeVersion):
(WebCore::DatabaseSync::transaction):
(WebCore::DatabaseSync::runTransaction):
* storage/DatabaseSync.h:
* storage/DatabaseTracker.cpp:
(WebCore::DatabaseTracker::getMaxSizeForDatabase):
* storage/SQLError.h:
* storage/SQLResultSet.cpp:
* storage/SQLResultSet.h:
* storage/SQLStatementCallback.h:
* storage/SQLStatementErrorCallback.h:
* storage/SQLStatementSync.cpp: Copied from WebCore/storage/SQLStatement.cpp.
(WebCore::SQLStatementSync::SQLStatementSync):
(WebCore::SQLStatementSync::execute):
* storage/SQLStatementSync.h: Added.
* storage/SQLTransaction.cpp:
(WebCore::SQLTransaction::runCurrentStatement):
(WebCore::SQLTransaction::deliverQuotaIncreaseCallback):
(WebCore::SQLTransaction::postflightAndCommit):
* storage/SQLTransaction.h:
* storage/SQLTransactionCallback.h:
* storage/SQLTransactionClient.cpp:
(WebCore::SQLTransactionClient::didCommitWriteTransaction):
(WebCore::SQLTransactionClient::didExecuteStatement):
(WebCore::SQLTransactionClient::didExceedQuota):
* storage/SQLTransactionClient.h:
* storage/SQLTransactionErrorCallback.h:
* storage/SQLTransactionSync.cpp:
(WebCore::transactionClient):
(WebCore::SQLTransactionSync::create):
(WebCore::SQLTransactionSync::SQLTransactionSync):
(WebCore::SQLTransactionSync::~SQLTransactionSync):
(WebCore::SQLTransactionSync::executeSQL):
(WebCore::SQLTransactionSync::begin):
(WebCore::SQLTransactionSync::execute):
(WebCore::SQLTransactionSync::commit):
(WebCore::SQLTransactionSync::rollback):
* storage/SQLTransactionSync.h:
(WebCore::SQLTransactionSync::SQLTransactionSyncOptionalStep::~SQLTransactionSyncOptionalStep):
* storage/SQLTransactionSyncCallback.h:
* storage/chromium/SQLTransactionClientChromium.cpp:
(WebCore::SQLTransactionClient::didCommitWriteTransaction):
(WebCore::SQLTransactionClient::didExecuteStatement):
(WebCore::SQLTransactionClient::didExceedQuota):

LayoutTests: Porting as many async DB tests as possible to sync DBs.
https://bugs.webkit.org/show_bug.cgi?id=40607

Reviewed by Darin Fisher.

* fast/workers/storage/change-version-handle-reuse-sync-expected.txt: Added.
* fast/workers/storage/change-version-handle-reuse-sync.html: Added.
* fast/workers/storage/change-version-sync-expected.txt: Added.
* fast/workers/storage/change-version-sync.html: Added.
* fast/workers/storage/empty-statement-sync-expected.txt: Added.
* fast/workers/storage/empty-statement-sync.html: Added.
* fast/workers/storage/execute-sql-args-sync-expected.txt: Added.
* fast/workers/storage/execute-sql-args-sync.html: Added.
* fast/workers/storage/executesql-accepts-only-one-statement-sync-expected.txt: Added.
* fast/workers/storage/executesql-accepts-only-one-statement-sync.html: Added.
* fast/workers/storage/multiple-transactions-on-different-handles-sync-expected.txt: Added.
* fast/workers/storage/multiple-transactions-on-different-handles-sync.html: Added.
* fast/workers/storage/open-database-creation-callback-sync-expected.txt: Added.
* fast/workers/storage/open-database-creation-callback-sync.html: Added.
* fast/workers/storage/open-database-empty-version-sync-expected.txt: Added.
* fast/workers/storage/open-database-empty-version-sync.html: Added.
* fast/workers/storage/open-database-inputs-sync-expected.txt: Copied from LayoutTests/fast/workers/storage/open-database-sync-inputs-expected.txt.
* fast/workers/storage/open-database-inputs-sync.html: Copied from LayoutTests/fast/workers/storage/open-database-sync-inputs.html.
* fast/workers/storage/open-database-set-empty-version-sync-expected.txt: Added.
* fast/workers/storage/open-database-set-empty-version-sync.html: Added.
* fast/workers/storage/open-database-sync-inputs-expected.txt: Removed.
* fast/workers/storage/open-database-sync-inputs.html: Removed.
* fast/workers/storage/open-database-while-transaction-in-progress-sync-expected.txt: Added.
* fast/workers/storage/open-database-while-transaction-in-progress-sync.html: Added.
* fast/workers/storage/resources/change-version-handle-reuse-sync.js: Added.
(catch):
* fast/workers/storage/resources/change-version-sync-1.js: Added.
():
(try):
* fast/workers/storage/resources/change-version-sync-2.js: Added.
* fast/workers/storage/resources/empty-statement-sync.js: Added.
* fast/workers/storage/resources/execute-sql-args-sync.js: Added.
(throwOnToStringObject.toString):
(var):
():
(runTransactionTest):
(runTransactionTests):
* fast/workers/storage/resources/executesql-accepts-only-one-statement-sync.js: Added.
(executeStatement):
* fast/workers/storage/resources/multiple-transactions-on-different-handles-sync.js: Added.
(runTransaction):
(var):
* fast/workers/storage/resources/multiple-transactions-sync.js: Added.
(checkCompletion):
(runTest.db):
(runTest):
* fast/workers/storage/resources/open-database-creation-callback-sync.js: Added.
* fast/workers/storage/resources/open-database-empty-version-sync.js: Added.
* fast/workers/storage/resources/open-database-inputs-sync.js: Copied from LayoutTests/fast/workers/storage/resources/open-database-sync-inputs.js.
* fast/workers/storage/resources/open-database-set-empty-version-sync.js: Added.
* fast/workers/storage/resources/open-database-sync-inputs.js: Removed.
* fast/workers/storage/resources/open-database-while-transaction-in-progress-sync.js: Added.
(openTestDatabase):
* fast/workers/storage/resources/sql-data-types-sync.js: Added.
():
(testDBValues):
* fast/workers/storage/resources/sql-exception-codes-sync.js: Added.
(testTransaction):
():
(testInvalidStatement):
(testIncorrectNumberOfBindParameters):
(testBindParameterOfWrongType.badString.toString):
(testBindParameterOfWrongType):
(testVersionMismatch.testTransaction):
(testVersionMismatch):
* fast/workers/storage/resources/test-authorizer-sync.js: Added.
(cleanup):
(executeStatement):
(createTableCallback):
(createStatementsCallback):
(otherStatementsCallback):
(dropStatementsCallback):
(testReadWriteMode):
(testReadOnlyMode):
* fast/workers/storage/resources/transaction-in-transaction-sync.js: Added.
* fast/workers/storage/sql-data-types-sync-expected.txt: Added.
* fast/workers/storage/sql-data-types-sync.html: Added.
* fast/workers/storage/sql-exception-codes-sync-expected.txt: Added.
* fast/workers/storage/sql-exception-codes-sync.html: Added.
* fast/workers/storage/test-authorizer-sync-expected.txt: Added.
* fast/workers/storage/test-authorizer-sync.html: Added.
* fast/workers/storage/transaction-in-transaction-sync-expected.txt: Added.
* fast/workers/storage/transaction-in-transaction-sync.html: Added.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@63278 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent ab5039f3
2010-07-13 Dumitru Daniliuc <dumi@chromium.org>
Reviewed by Darin Fisher.
Porting as many async DB tests as possible to sync DBs.
https://bugs.webkit.org/show_bug.cgi?id=40607
* fast/workers/storage/change-version-handle-reuse-sync-expected.txt: Added.
* fast/workers/storage/change-version-handle-reuse-sync.html: Added.
* fast/workers/storage/change-version-sync-expected.txt: Added.
* fast/workers/storage/change-version-sync.html: Added.
* fast/workers/storage/empty-statement-sync-expected.txt: Added.
* fast/workers/storage/empty-statement-sync.html: Added.
* fast/workers/storage/execute-sql-args-sync-expected.txt: Added.
* fast/workers/storage/execute-sql-args-sync.html: Added.
* fast/workers/storage/executesql-accepts-only-one-statement-sync-expected.txt: Added.
* fast/workers/storage/executesql-accepts-only-one-statement-sync.html: Added.
* fast/workers/storage/multiple-transactions-on-different-handles-sync-expected.txt: Added.
* fast/workers/storage/multiple-transactions-on-different-handles-sync.html: Added.
* fast/workers/storage/open-database-creation-callback-sync-expected.txt: Added.
* fast/workers/storage/open-database-creation-callback-sync.html: Added.
* fast/workers/storage/open-database-empty-version-sync-expected.txt: Added.
* fast/workers/storage/open-database-empty-version-sync.html: Added.
* fast/workers/storage/open-database-inputs-sync-expected.txt: Copied from LayoutTests/fast/workers/storage/open-database-sync-inputs-expected.txt.
* fast/workers/storage/open-database-inputs-sync.html: Copied from LayoutTests/fast/workers/storage/open-database-sync-inputs.html.
* fast/workers/storage/open-database-set-empty-version-sync-expected.txt: Added.
* fast/workers/storage/open-database-set-empty-version-sync.html: Added.
* fast/workers/storage/open-database-sync-inputs-expected.txt: Removed.
* fast/workers/storage/open-database-sync-inputs.html: Removed.
* fast/workers/storage/open-database-while-transaction-in-progress-sync-expected.txt: Added.
* fast/workers/storage/open-database-while-transaction-in-progress-sync.html: Added.
* fast/workers/storage/resources/change-version-handle-reuse-sync.js: Added.
(catch):
* fast/workers/storage/resources/change-version-sync-1.js: Added.
():
(try):
* fast/workers/storage/resources/change-version-sync-2.js: Added.
* fast/workers/storage/resources/empty-statement-sync.js: Added.
* fast/workers/storage/resources/execute-sql-args-sync.js: Added.
(throwOnToStringObject.toString):
(var):
():
(runTransactionTest):
(runTransactionTests):
* fast/workers/storage/resources/executesql-accepts-only-one-statement-sync.js: Added.
(executeStatement):
* fast/workers/storage/resources/multiple-transactions-on-different-handles-sync.js: Added.
(runTransaction):
(var):
* fast/workers/storage/resources/multiple-transactions-sync.js: Added.
(checkCompletion):
(runTest.db):
(runTest):
* fast/workers/storage/resources/open-database-creation-callback-sync.js: Added.
* fast/workers/storage/resources/open-database-empty-version-sync.js: Added.
* fast/workers/storage/resources/open-database-inputs-sync.js: Copied from LayoutTests/fast/workers/storage/resources/open-database-sync-inputs.js.
* fast/workers/storage/resources/open-database-set-empty-version-sync.js: Added.
* fast/workers/storage/resources/open-database-sync-inputs.js: Removed.
* fast/workers/storage/resources/open-database-while-transaction-in-progress-sync.js: Added.
(openTestDatabase):
* fast/workers/storage/resources/sql-data-types-sync.js: Added.
():
(testDBValues):
* fast/workers/storage/resources/sql-exception-codes-sync.js: Added.
(testTransaction):
():
(testInvalidStatement):
(testIncorrectNumberOfBindParameters):
(testBindParameterOfWrongType.badString.toString):
(testBindParameterOfWrongType):
(testVersionMismatch.testTransaction):
(testVersionMismatch):
* fast/workers/storage/resources/test-authorizer-sync.js: Added.
(cleanup):
(executeStatement):
(createTableCallback):
(createStatementsCallback):
(otherStatementsCallback):
(dropStatementsCallback):
(testReadWriteMode):
(testReadOnlyMode):
* fast/workers/storage/resources/transaction-in-transaction-sync.js: Added.
* fast/workers/storage/sql-data-types-sync-expected.txt: Added.
* fast/workers/storage/sql-data-types-sync.html: Added.
* fast/workers/storage/sql-exception-codes-sync-expected.txt: Added.
* fast/workers/storage/sql-exception-codes-sync.html: Added.
* fast/workers/storage/test-authorizer-sync-expected.txt: Added.
* fast/workers/storage/test-authorizer-sync.html: Added.
* fast/workers/storage/transaction-in-transaction-sync-expected.txt: Added.
* fast/workers/storage/transaction-in-transaction-sync.html: Added.
2010-07-13 Maciej Stachowiak <mjs@apple.com>
Reviewed by Oliver Hunt.
Test that the database can be accessed after changing its version.
PASS: changeVersion() transaction callback was called.
PASS: No exception thrown while executing statements.
PASS: No exception thrown while running a transaction.
<html>
<head>
<script src="resources/test-inputs-common.js"></script>
</head>
<body onload="runTest('resources/change-version-handle-reuse-sync.js')">
Test that the database can be accessed after changing its version.
<pre id="console">
</pre>
</body>
</html>
Test that version updates in sync databases work correctly.
PASS: db.version is 3 as expected.
<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.dumpAsText();
layoutTestController.waitUntilDone();
}
if (window.location.search == "?2") {
var worker = new Worker("resources/change-version-sync-2.js");
worker.onmessage = function(event) {
if (event.data == "done")
finishTest();
else
log(event.data);
};
} else {
var worker = new Worker("resources/change-version-sync-1.js");
worker.onmessage = function(event) {
if (event.data == "done")
window.location.href = window.location + "?2";
else if (event.data == "fail")
finishTest();
else
log(event.data);
};
}
}
</script>
</head>
<body onload="runTest()">
Test that version updates in sync databases work correctly.
<pre id="console">
</pre>
</body>
</html>
This test tries to execute an empty statement.
PASS: result is null
PASS
<html>
<head>
<script src="resources/test-inputs-common.js"></script>
</head>
<body onload="runTest('resources/empty-statement-sync.js')">
This test tries to execute an empty statement.
<pre id="console">
</pre>
</body>
</html>
Test various inputs to executeSql().
PASS: executeSql("") did not throw an exception.
PASS: executeSql("", null) did not throw an exception.
PASS: executeSql("", undefined) did not throw an exception.
PASS: executeSql("", []) did not throw an exception.
PASS: executeSql("", [ "arg0" ]) did not throw an exception.
PASS: executeSql("", { }) did not throw an exception.
PASS: executeSql("", { length: 0 }) did not throw an exception.
PASS: executeSql("", { length: 1, 0: "arg0" }) did not throw an exception.
PASS: executeSql() threw an exception as expected.
PASS: executeSql(null) threw an exception as expected.
PASS: executeSql(undefined) threw an exception as expected.
PASS: executeSql(0) threw an exception as expected.
PASS: executeSql(throwOnToStringObject) threw an exception as expected.
PASS: executeSql("", throwOnGetLengthObject) threw an exception as expected.
PASS: executeSql("", throwOnGetZeroObject) threw an exception as expected.
PASS: executeSql("", [ throwOnToStringObject ]) threw an exception as expected.
PASS: executeSql("", 0) threw an exception as expected.
PASS: executeSql("", "") threw an exception as expected.
<html>
<head>
<script src="resources/test-inputs-common.js"></script>
</head>
<body onload="runTest('resources/execute-sql-args-sync.js')">
Test various inputs to executeSql().
<pre id="console">
</pre>
</body>
</html>
Test that executeSql() accepts only one statement.
PASS: INSERT INTO Test VALUES (1)
PASS: INSERT INTO Test VALUES (2);
PASS: INSERT INTO Test VALUES (3)
PASS: INSERT INTO Test VALUES (4);
PASS: INSERT INTO Test VALUES (5) ;
PASS: INSERT INTO Test VALUES (6); garbage
PASS: INSERT INTO Test VALUES (7); INSERT INTO Test VALUES (8)
PASS: INSERT INTO Test VALUES (9); INSERT INTO Test VALUES (10);
<html>
<head>
<script src="resources/test-inputs-common.js"></script>
</head>
<body onload="runTest('resources/executesql-accepts-only-one-statement-sync.js')">
Test that executeSql() accepts only one statement.
<pre id="console">
</pre>
</body>
</html>
Test that executing multiple transactions on different handles to the same database doesn't cause deadlocks.
PASS
<html>
<head>
<script src="resources/test-inputs-common.js"></script>
</head>
<body onload="runTest('resources/multiple-transactions-on-different-handles-sync.js')">
Test that executing multiple transactions on different handles to the same database doesn't cause deadlocks.
<pre id="console">
</pre>
</body>
</html>
This test tests openDatabaseSync()'s creation callback.
PASS: Creation callback was called.
PASS: Version set to empty string as expected.
PASS: An exception was thrown and db1Fail is null as expected.
<html>
<head>
<script src="resources/test-inputs-common.js"></script>
</head>
<body onload="runTest('resources/open-database-creation-callback-sync.js')">
This test tests openDatabaseSync()'s creation callback.
<pre id="console">
</pre>
</body>
</html>
Test that no exception is thrown when the database is opened with an empty version.
PASS
<html>
<head>
<script src="resources/test-inputs-common.js"></script>
</head>
<body onload="runTest('resources/open-database-empty-version-sync.js')">
Test that no exception is thrown when the database is opened with an empty version.
<pre id="console">
</pre>
</body>
</html>
......@@ -4,7 +4,7 @@
<script src="resources/test-inputs-common.js"></script>
</head>
<body onload="runTest('resources/open-database-sync-inputs.js')">
<body onload="runTest('resources/open-database-inputs-sync.js')">
This test makes sure that openDatabaseSync() accepts only valid parameters.
<pre id="console">
</pre>
......
This tests that calling openDatabase with an empty version string sets the current version of that database to the empty string and subsequent attempts to open the database with a different expected version throw an exception.
PASS
<html>
<head>
<script src="resources/test-inputs-common.js"></script>
</head>
<body onload="runTest('resources/open-database-set-empty-version-sync.js')">
This tests that calling openDatabase with an empty version string sets the current version of that database to the empty string and subsequent attempts to open the database with a different expected version throw an exception.
<pre id="console">
</pre>
</body>
</html>
Test that a second handle to the same database can be opened inside a transaction running on the first handle.
PASS: second handle opened successfully.
<html>
<head>
<script src="resources/test-inputs-common.js"></script>
</head>
<body onload="runTest('resources/open-database-while-transaction-in-progress-sync.js')">
Test that a second handle to the same database can be opened inside a transaction running on the first handle.
<pre id="console">
</pre>
</body>
</html>
var db = null;
try {
var dbName = "ChangeVersionHandleReuseTest" + (new Date()).getTime();
db = openDatabaseSync(dbName, "", "Test that the DB handle is valid after changing the version.", 1);
var version = db.version;
var newVersion = version ? (parseInt(version) + 1).toString() : "1";
db.changeVersion(version, newVersion, function(tx) {
postMessage("PASS: changeVersion() transaction callback was called.");
});
} catch (err) {
postMessage("FAIL: changeVersion() threw an exception: " + err);
}
try {
db.transaction(function(tx) {
try {
tx.executeSql("CREATE TABLE IF NOT EXISTS Test (Foo INT)");
tx.executeSql("SELECT * from Test");
postMessage("PASS: No exception thrown while executing statements.");
} catch (err) {
postMessage("FAIL: An exception was thrown while executing statements: " + err);
}
});
postMessage("PASS: No exception thrown while running a transaction.");
} catch (err) {
postMessage("FAIL: An exception was thrown while running a transaction: " + err);
}
postMessage("done");
var EXPECTED_VERSION_AFTER_HIXIE_TEST = "2";
var EXPECTED_VERSION_AFTER_RELOAD = "3";
function emptyFunction() { }
var db1 = openDatabaseSync("ChangeVersionTest", "1", "Test for the database.changeVersion() function", 1);
var db2 = openDatabaseSync("ChangeVersionTest", "1", "Test for the database.changeVersion() function", 1);
// First run Hixie's test to ensure basic changeVersion() functionality works (see bug 28418).
db1.changeVersion("1", EXPECTED_VERSION_AFTER_HIXIE_TEST, emptyFunction);
if (db2.version != db1.version) {
postMessage("FAIL: changing db1's version (" + db1.version + ") did not change db2's version (" + db2.version + ") as expected.");
postMessage("fail");
} else
postMessage("PASS: changing db1's version (" + db1.version + ") changed db2's version too.");
db2.transaction(function(tx) {
try {
tx.executeSql("CREATE TABLE IF NOT EXISTS Test (Foo INT)");
postMessage("FAIL: The DB version changed, executing any statement on db2 should fail.");
postMessage("fail");
} catch(err) {
postMessage("PASS: Executing a statement on db2 threw an exception as expected.");
}
});
// Make sure any new handle to the same DB sees the new version
try {
var db3 = openDatabaseSync("ChangeVersionTest", EXPECTED_VERSION_AFTER_HIXIE_TEST, "", 1);
postMessage("PASS: Successfully opened a new DB handle.");
} catch (err) {
postMessage("FAIL: Unexpected exception thrown while trying to open a new DB handle: " + err);
postMessage("fail");
}
if (db1.version != db3.version) {
postMessage("FAIL: db1.version (" + db1.version + ") does not match db3.version(" + db3.version +")");
postMessage("fail");
} else
postMessage("PASS: db1.version (" + db1.version + ") matches db3.version.");
// Now try a test to ensure the version persists after reloading (see bug 27836)
db1.changeVersion(EXPECTED_VERSION_AFTER_HIXIE_TEST, EXPECTED_VERSION_AFTER_RELOAD,
function(tx) {
tx.executeSql("DROP TABLE IF EXISTS Info");
tx.executeSql("CREATE TABLE IF NOT EXISTS Info (Version INTEGER)");
tx.executeSql("INSERT INTO Info VALUES (?)", [EXPECTED_VERSION_AFTER_RELOAD]);
});
postMessage("done");
var EXPECTED_VERSION_AFTER_RELOAD = '3';
var db = openDatabaseSync("ChangeVersionTest", "", "Test the changeVersion() function.", 1);
if (db.version == EXPECTED_VERSION_AFTER_RELOAD)
postMessage("PASS: db.version is " + EXPECTED_VERSION_AFTER_RELOAD + " as expected.");
else
postMessage("FAIL: db.version is " + db.version + "; expected " + EXPECTED_VERSION_AFTER_RELOAD);
// Reset the version; otherwise this test will fail the next time it's run
db.changeVersion(db.version, "1", function(tx) { });
postMessage("done");
try {
var db = openDatabaseSync("EmptyStatementSync", "1.0", "Test an empty statement.", 1);
db.transaction(function(tx) {
var result = tx.executeSql("");
postMessage(result ? "FAIL: result is not null" : "PASS: result is null");
});
postMessage("PASS");
} catch (err) {
postMessage("FAIL");
}
postMessage("done");
var throwOnToStringObject = { };
throwOnToStringObject.toString = function () { throw "Cannot call toString on this object." };
var throwOnGetLengthObject = { };
throwOnGetLengthObject.__defineGetter__("length", function () { throw "Cannot get length of this object."; });
var throwOnGetZeroObject = { length: 1 };
throwOnGetZeroObject.__defineGetter__("0", function () { throw "Cannot get 0 property of this object."; });
var expectNoException = [
'""',
'"", null',
'"", undefined',
'"", []',
'"", [ "arg0" ]',
'"", { }',
'"", { length: 0 }',
'"", { length: 1, 0: "arg0" }',
];
var expectException = [
'',
'null',
'undefined',
'0',
'throwOnToStringObject',
'"", throwOnGetLengthObject',
'"", throwOnGetZeroObject',
'"", [ throwOnToStringObject ]',
'"", 0',
'"", ""',
];
function tryExecuteSql(transaction, parameterList)
{
try {
eval('transaction.executeSql(' + parameterList + ')');
return null;
} catch (exception) {
return exception;
}
}
function runTransactionTest(transaction, parameterList, expectException)
{
var exception = tryExecuteSql(transaction, parameterList);
if (expectException) {
if (exception)
postMessage("PASS: executeSql(" + parameterList + ") threw an exception as expected.");
else
postMessage("FAIL: executeSql(" + parameterList + ") did not throw an exception.");
} else {
if (exception)
postMessage("FAIL: executeSql(" + parameterList + ") threw an exception: " + exception);
else
postMessage("PASS: executeSql(" + parameterList + ") did not throw an exception.");
}
}
function runTransactionTests(transaction)
{
for (i in expectNoException)
runTransactionTest(transaction, expectNoException[i], false);
for (i in expectException)
runTransactionTest(transaction, expectException[i], true);
}
var db = openDatabaseSync("ExecuteSQLArgsTest", "1.0", "Test of handling of the arguments to SQLTransactionSync.executeSql", 1);
db.transaction(runTransactionTests);
postMessage("done");
function executeStatement(tx, expectedToPass, statement)
{
try {
tx.executeSql(statement);
postMessage(expectedToPass ? "PASS: " + statement : "FAIL: " + statement);
} catch (err) {
postMessage(!expectedToPass ? "PASS: " + statement : "FAIL: " + statement);
}
}
var db = openDatabaseSync("ExecuteSQLAcceptsOnlyOneStatementTest", "1.0", "", 1);
db.transaction(function(tx) {
tx.executeSql("CREATE TABLE IF NOT EXISTS Test (Foo INT)");
executeStatement(tx, true, "INSERT INTO Test VALUES (1)");
executeStatement(tx, true, "INSERT INTO Test VALUES (2);");
executeStatement(tx, true, " INSERT INTO Test VALUES (3) ");
executeStatement(tx, true, " INSERT INTO Test VALUES (4); ");
executeStatement(tx, true, "INSERT INTO Test VALUES (5) ;");
executeStatement(tx, false, "INSERT INTO Test VALUES (6); garbage");
executeStatement(tx, false, "INSERT INTO Test VALUES (7); INSERT INTO Test VALUES (8)");
executeStatement(tx, false, " INSERT INTO Test VALUES (9); INSERT INTO Test VALUES (10); ");
});
postMessage("done");
function runTransaction(db)
{
db.transaction(function(tx) {
// Execute a read-only statement
tx.executeSql("SELECT COUNT(*) FROM Test;");
// Execute a write statement to make sure SQLite tries to acquire an exclusive lock on the DB file
tx.executeSql("INSERT INTO Test VALUES (?);", [1]);
});
}
var db1 = openDatabaseSync("MultipleTransactionsOnDifferentHandlesTest", "1.0",
"Test transactions on different handles to the same DB.", 1);
db1.transaction(function(tx) {
tx.executeSql("CREATE TABLE IF NOT EXISTS Test (Foo int);");
});
var db2 = openDatabaseSync("MultipleTransactionsOnDifferentHandlesTest", "1.0",
"Test transactions on different handles to the same DB.", 1);
if (db1 == db2)
postMessage("FAIL: db1 == db2");
else {
try {
runTransaction