Skip to content

Commit

Permalink
WIP: Add browser platform
Browse files Browse the repository at this point in the history
NOTE: This is an initial implementation with some major items missing
including:
- echoTest/selfTest
- sqlBatch
- deleteDatabase

Also broken: error handling

Certain tests are disabled due to timeouts.

Quite a few more tests will need to be adapted to work with the browser platform.
  • Loading branch information
Christopher J. Brody committed May 1, 2017
1 parent aff5f3c commit 01ff6f6
Show file tree
Hide file tree
Showing 11 changed files with 250 additions and 79 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## cordova-sqlite-storage 2.1.0-browser-wip1

TBD
- Support browser platform

## cordova-sqlite-storage 2.0.3

Expand Down
13 changes: 13 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@
<!-- THANKS to AllJoyn-Cordova / cordova-plugin-alljoyn: -->
<hook type="before_plugin_install" src="scripts/beforePluginInstall.js" />

<!-- browser -->
<platform name="browser">
<js-module src="src/browser/SQLitePlugin.js" name="SQLitePlugin">
<clobbers target="SQLitePlugin" />
</js-module>

<config-file target="config.xml" parent="/*">
<feature name="SQLitePlugin">
<param name="browser-package" value="SQLitePlugin" />
</feature>
</config-file>
</platform>

<!-- android -->
<platform name="android">
<js-module src="www/SQLitePlugin.js" name="SQLitePlugin">
Expand Down
8 changes: 8 additions & 0 deletions spec/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,30 @@

<!-- spec file(s): -->
<script src="spec/browser-check-startup.js"></script>
<!-- XXX TODO:
<script src="spec/self-test.js"></script>
-->
<script src="spec/sqlite-version-test.js"></script>
<script src="spec/db-tx-string-test.js"></script>
<script src="spec/db-tx-sql-select-value-test.js"></script>
<script src="spec/basic-db-tx-sql-storage-results.js"></script>
<script src="spec/db-sql-operations-test.js"></script>
<!-- XXX TODO:
<script src="spec/sql-batch-test.js"></script>
-->
<script src="spec/db-tx-sql-features-test.js"></script>
<script src="spec/regexp-test.js"></script>
<!-- XXX TODO:
<script src="spec/db-simultaneous-tx-access-test.js"></script>
-->
<script src="spec/db-tx-multiple-update-test.js"></script>
<!-- XXX TODO:
<script src="spec/tx-semantics-test.js"></script>
<script src="spec/db-tx-error-handling-test.js"></script>
<script src="spec/db-tx-value-bindings-test.js"></script>
<script src="spec/db-tx-error-mapping-test.js"></script>
<script src="spec/db-open-close-delete-test.js"></script>
-->
<script src="spec/ext-tx-blob-test.js"></script>

</head>
Expand Down
43 changes: 28 additions & 15 deletions spec/www/spec/basic-db-tx-sql-storage-results.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ var mytests = function() {
// ref: https://www.w3.org/TR/webdatabase/#database-query-results
rs.insertId = 2;
rs.rowsAffected = 3;
if (isWebSql) {
if (isWebSql || isBrowser) {
expect(rs.insertId).toBe(1);
expect(rs.rowsAffected).toBe(1);
} else {
Expand Down Expand Up @@ -240,7 +240,7 @@ var mytests = function() {
// rs.rows.length should be immutable
// ref: https://www.w3.org/TR/webdatabase/#database-query-results
rs.rows.length = 2;
if (isWebSql) {
if (isWebSql || isBrowser) {
expect(rs.rows.length).toBe(1);
} else {
expect(rs.rows.length).toBe(2);
Expand Down Expand Up @@ -313,15 +313,21 @@ var mytests = function() {
// Object from rows.item is immutable in Android/iOS WebKit Web SQL but NOT in this plugin:
temp1.data = 'another';

if (isWebSql) {
if (isBrowser) {
// PLUGIN on browser platform:
// 1. DEVIATION - temp1 is just like any other Javascript object:
expect(temp1.data).toBe('another');
// 2. According to Web SQL STANDARD - object returned by second resultSet.rows.item call not affected:
expect(temp2.data).toBe('test');
} else if (isWebSql) {
// Web SQL STANDARD:
// 1. this is a native object that is NOT affected by the change (SKIP for Android 5.x/+):
if (!isAndroid || /Android [1-4]/.test(navigator.userAgent))
expect(temp1.data).toBe('test');
// 2. object returned by second resultSet.rows.item call not affected:
expect(temp2.data).toBe('test');
} else {
// PLUGIN:
// PLUGIN on other platforms:
// 1. DEVIATION - temp1 is just like any other Javascript object:
expect(temp1.data).toBe('another');
// 2. DEVIATION - same object is returned by second resultSet.rows.item IS affected:
Expand Down Expand Up @@ -667,12 +673,17 @@ var mytests = function() {
// CORRECT RESULT:
//expect(resultSet.rows.length).toBe(2);
// ACTUAL RESULT for PLUGIN [BROKEN with possible parameter data loss]:
expect(resultSet.rows.length).toBe(1);

// FIRST ROW CORRECT:
expect(resultSet.rows.item(0).data).toBe(1);
// SECOND ROW MISSING:
//expect(resultSet.rows.item(1).data).toBe(2);
if (isBrowser) {
// NO ROWS STORED ON BROWSER PLATFORM:
expect(resultSet.rows.length).toBe(0);
} else (isBrowser) {
expect(resultSet.rows.length).toBe(1);

// FIRST ROW CORRECT:
expect(resultSet.rows.item(0).data).toBe(1);
// SECOND ROW MISSING:
//expect(resultSet.rows.item(1).data).toBe(2);
}

// Close (plugin only) & finish:
(isWebSql) ? done() : db.close(done, done);
Expand All @@ -681,7 +692,7 @@ var mytests = function() {
});
}, MYTIMEOUT);

it(suiteName + 'executeSql with SELECT statement list - NOT ALLOWED [PLUGIN BROKEN]', function(done) {
it(suiteName + 'executeSql with SELECT statement list - NOT ALLOWED [Android/iOS/macOS/Windows PLUGIN BROKEN]', function(done) {
// TO FIX ref: https://www.sqlite.org/c3ref/prepare.html
// When calling sqlite3_prepare_v2 check the OUT pzTail pointer
// to ensure there is no other statement afterwards.
Expand All @@ -694,6 +705,8 @@ var mytests = function() {
// INCORRECT (PLUGIN BROKEN)
if (isWebSql)
expect('WebKit Web SQL implementation changed (DEVIATION)').toBe('--');
else if (isBrowser)
expect('Browser platform implementation changed (DEVIATION)').toBe('--');
else
expect(rs).toBeDefined();

Expand All @@ -708,7 +721,7 @@ var mytests = function() {
isWebSql ? done() : db.close(done, done);
});
}, function(ignored, error) {
if (!isWebSql)
if (!isWebSql && !isBrowser)
expect('PLUGIN FIXED, please update this test').toBe('--');

expect(error).toBeDefined();
Expand Down Expand Up @@ -886,7 +899,7 @@ var mytests = function() {

});

it(suiteName + 'INSERT OR IGNORE result in case of constraint violation [(WebKit) Web SQL DEVIATION on Android/iOS: reports old insertId value]', function(done) {
it(suiteName + 'INSERT OR IGNORE result in case of constraint violation [Android/iOS (WebKit) Web SQL & browser plugin DEVIATION: reports old insertId value]', function(done) {
var db = openDatabase('INSERT-OR-IGNORE-test.db', '1.0', 'Test', DEFAULT_SIZE);

db.transaction(function(tx) {
Expand Down Expand Up @@ -917,8 +930,8 @@ var mytests = function() {
// NOTE: According to https://www.w3.org/TR/webdatabase/#database-query-results (section 4.5)
// this access should really raise an INVALID_ACCESS_ERR exception.
var checkInsertId = rs1.insertId;
if (isWebSql)
expect(checkInsertId).toBe(2); // Andriod/iOS WebKit Web SQL DEVIATION: OLD insertId value
if (isWebSql || isBrowser)
expect(checkInsertId).toBe(2); // Andriod/iOS WebKit Web SQL & browser plugin DEVIATION: OLD insertId value
else
expect(checkInsertId).toBe(undefined);

Expand Down
11 changes: 6 additions & 5 deletions spec/www/spec/browser-check-startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

var MYTIMEOUT = 12000;

var isAndroid = /Android/.test(navigator.userAgent);
var isWP8 = /IEMobile/.test(navigator.userAgent); // Matches WP(7/8/8.1)
var isWindows = /Windows /.test(navigator.userAgent); // Windows 8.1/Windows Phone 8.1/Windows 10
var isMac = /Macintosh/.test(navigator.userAgent);
var isAndroid = !isWindows && /Android/.test(navigator.userAgent);
var isBrowser = !isWindows && !isAndroid && /Chrome/.test(navigator.userAgent);
var isMac = !isBrowser && /Macintosh/.test(navigator.userAgent);

window.hasBrowser = true;
// XXX TODO rename to something like window.hasWebKitWebSQL here and
// in actual test scripts
window.hasWebKitBrowser = (!isWindows && !isWP8 && !isMac && (isAndroid || !(window.webkit && window.webkit.messageHandlers)));
// XXX FUTURE TODO rename to something like window.hasWebKitWebSQL here
// and in actual test scripts
window.hasWebKitBrowser = (!isWindows && !isWP8 && !isMac && (isAndroid || isBrowser || !(window.webkit && window.webkit.messageHandlers)));

describe('check startup', function() {
it('receives deviceready event', function(done) {
Expand Down
Loading

0 comments on commit 01ff6f6

Please sign in to comment.