Skip to content

Commit

Permalink
Error test updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher J. Brody committed May 3, 2017
1 parent f23ed61 commit 843b056
Show file tree
Hide file tree
Showing 3 changed files with 298 additions and 6 deletions.
202 changes: 199 additions & 3 deletions spec/www/spec/db-tx-error-handling-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ var isWP8 = /IEMobile/.test(navigator.userAgent); // Matches WP(7/8/8.1)
var isWindows = /Windows /.test(navigator.userAgent); // Windows
var isAndroid = !isWindows && /Android/.test(navigator.userAgent);

// NOTE: In the common storage-master branch there is no difference between the
// default implementation and implementation #2. But the test will also apply
// the androidLockWorkaround: 1 option in the case of implementation #2.
// NOTE: While in certain version branches there is no difference between
// the default Android implementation and implementation #2,
// this test script will also apply the androidLockWorkaround: 1 option
// in case of implementation #2.
var scenarioList = [
isAndroid ? 'Plugin-implementation-default' : 'Plugin',
'HTML5',
Expand Down Expand Up @@ -361,6 +362,138 @@ var mytests = function() {
});
}, MYTIMEOUT);

it(suiteName + 'transaction ends with error if success callback throws [TBD (WebKit) Web SQL vs plugin error message]', function(done) {
var db = openDatabase('transaction-error-if-success-cb-throws.db')
expect(db).toBeDefined();

db.transaction(function(tx) {
expect(tx).toBeDefined();

//var check1 = false;
tx.executeSql('SELECT 1', null, function(ignored, rs) {
expect(rs).toBeDefined();
expect(rs.rows).toBeDefined();
expect(rs.rows.length).toBe(1);
//check1 = true;
throw new Error('Boom');
});

tx.executeSql('SELECT 1', null, function(ignored1, ignored2) {
// NOT EXPECTED:
expect(false).toBe(true);

// Close (plugin only) & finish:
(isWebSql) ? done() : db.close(done, done);
}, function(ignored1, ignored2) {
// NOT EXPECTED:
expect(false).toBe(true);
});
}, function(error) {
expect(error).toBeDefined();
expect(error.code).toBeDefined();
expect(error.message).toBeDefined();
expect(error.code).toBe(0);
// TBD (WebKit) Web SQL vs plugin:
if (isWebSql)
expect(error.message).toMatch(/callback raised an exception.*or.*error callback did not return false/);
else
expect(error.message).toBe('Boom');

// VERIFY we can still continue:
var gotStringLength = false; // poor man's spy
db.transaction(function (tx) {
tx.executeSql("SELECT LENGTH('tenletters') AS stringlength", [], function (txIgnored, rs) {
expect(rs).toBeDefined();
expect(rs.rows).toBeDefined();
expect(rs.rows.length).toBe(1);
expect(rs.rows.item(0).stringlength).toBe(10);
gotStringLength = true;
});

}, function (error) {
// NOT EXPECTED:
expect(false).toBe(true);
expect(error.message).toBe('--');
// Close (plugin only) & finish:
(isWebSql) ? done() : db.close(done, done);

}, function () {
// EXPECTED RESULT (transaction finished OK):
expect(true).toBe(true);
expect(gotStringLength).toBe(true);
// Close (plugin only) & finish:
(isWebSql) ? done() : db.close(done, done);
});

});
}, MYTIMEOUT);

it(suiteName + 'readTransaction ends with error if success callback throws [TBD (WebKit) Web SQL vs plugin error message]', function(done) {
var db = openDatabase('readTransaction-error-if-success-cb-throws.db')
expect(db).toBeDefined();

db.readTransaction(function(tx) {
expect(tx).toBeDefined();

//var check1 = false;
tx.executeSql('SELECT 1', null, function(ignored, rs) {
expect(rs).toBeDefined();
expect(rs.rows).toBeDefined();
expect(rs.rows.length).toBe(1);
//check1 = true;
throw new Error('Boom');
});

tx.executeSql('SELECT 1', null, function(ignored1, ignored2) {
// NOT EXPECTED:
expect(false).toBe(true);

// Close (plugin only) & finish:
(isWebSql) ? done() : db.close(done, done);
}, function(ignored1, ignored2) {
// NOT EXPECTED:
expect(false).toBe(true);
});
}, function(error) {
expect(error).toBeDefined();
expect(error.code).toBeDefined();
expect(error.message).toBeDefined();
expect(error.code).toBe(0);
// TBD (WebKit) Web SQL vs plugin:
if (isWebSql)
expect(error.message).toMatch(/callback raised an exception.*or.*error callback did not return false/);
else
expect(error.message).toBe('Boom');

// VERIFY we can still continue:
var gotStringLength = false; // poor man's spy
db.readTransaction(function (tx) {
tx.executeSql("SELECT LENGTH('tenletters') AS stringlength", [], function (txIgnored, rs) {
expect(rs).toBeDefined();
expect(rs.rows).toBeDefined();
expect(rs.rows.length).toBe(1);
expect(rs.rows.item(0).stringlength).toBe(10);
gotStringLength = true;
});

}, function (error) {
// NOT EXPECTED:
expect(false).toBe(true);
expect(error.message).toBe('--');
// Close (plugin only) & finish:
(isWebSql) ? done() : db.close(done, done);

}, function () {
// EXPECTED RESULT (transaction finished OK):
expect(true).toBe(true);
expect(gotStringLength).toBe(true);
// Close (plugin only) & finish:
(isWebSql) ? done() : db.close(done, done);
});

});
}, MYTIMEOUT);

});

describe(scenarioList[i] + ': other tx error handling test(s)', function() {
Expand Down Expand Up @@ -2151,6 +2284,69 @@ var mytests = function() {

}, MYTIMEOUT);

it(suiteName + 'transaction.executeSql with undefined for SQL statement (BOGUS)', function (done) {
var db = openDatabase('tx-with-undefined-for-sql-statement.db');

var check1 = false;
db.transaction(function(transaction) {
// NOT expected to throw in case of Web SQL:
transaction.executeSql(undefined);

if (!isWebSql) expect('Plugin behavior changed please update this test').toBe('--');
check1 = true;

}, function(error) {
// EXPECTED RESULT:
if (isWebSql)
expect(check1).toBe(true);
expect(error).toBeDefined();
expect(error.code).toBeDefined()
expect(error.message).toBeDefined();

if (!isWebSql)
expect(error.code).toBe(0);
else
expect(error.code).toBe(5);

if (isWebSql)
expect(error.message).toMatch(/could not prepare statement \(1 near \"undefined\": syntax error\)/);
else if (isWindows)
expect(error.message).toMatch(/Unable to get property 'toString' of undefined or null reference/);
else if (isAndroid)
expect(error.message).toMatch(/Cannot .* 'toString' of undefined/);
else
expect(error.message).toMatch(/undefined is not an object \(evaluating 'sql\.toString'\)/);

// Verify we can still continue:
var gotStringLength = false; // poor man's spy
db.transaction(function (tx) {
tx.executeSql("SELECT LENGTH('tenletters') AS stringlength", [], function (tx, res) {
expect(res.rows.item(0).stringlength).toBe(10);
gotStringLength = true;
});
}, function (error) {
// NOT EXPECTED:
expect(false).toBe(true);
// Close (plugin only) & finish:
(isWebSql) ? done() : db.close(done, done);

}, function () {
// EXPECTED RESULT (transaction finished OK):
expect(true).toBe(true);
expect(gotStringLength).toBe(true);
// Close (plugin only) & finish:
(isWebSql) ? done() : db.close(done, done);
});

}, function() {
// NOT EXPECTED:
expect(false).toBe(true);
// Close (plugin only) & finish:
(isWebSql) ? done() : db.close(done, done);
});

}, MYTIMEOUT);

it(suiteName + 'transaction.executeSql with null for SQL statement (BOGUS)', function (done) {
var db = openDatabase("tx-with-null-for-sql-statement.db", "1.0", "Demo", DEFAULT_SIZE);

Expand Down
Loading

0 comments on commit 843b056

Please sign in to comment.