Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: initial browser platform #576

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changes

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

- Support browser platform

## cordova-sqlite-storage 2.0.3

- Drop engines rule from package.json
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-sqlite-storage",
"version": "2.0.3",
"version": "2.1.0-browser-wip1",
"description": "Native interface to SQLite for PhoneGap/Cordova",
"cordova": {
"id": "cordova-sqlite-storage",
Expand Down
33 changes: 29 additions & 4 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="cordova-sqlite-storage"
version="2.0.3">
version="2.1.0-browser-wip1">

<name>Cordova sqlite storage plugin</name>

Expand All @@ -16,12 +16,25 @@
<!-- THANKS to AllJoyn-Cordova / cordova-plugin-alljoyn: -->
<hook type="before_plugin_install" src="scripts/beforePluginInstall.js" />

<js-module src="www/SQLitePlugin.js" name="SQLitePlugin">
<clobbers target="SQLitePlugin" />
</js-module>
<!-- 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">
<clobbers target="SQLitePlugin" />
</js-module>

<!-- Cordova >= 3.0.0 -->
<config-file target="res/xml/config.xml" parent="/*">
<feature name="SQLitePlugin">
Expand All @@ -45,6 +58,10 @@

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

<config-file target="config.xml" parent="/*">
<feature name="SQLitePlugin">
<param name="ios-package" value="SQLitePlugin" />
Expand All @@ -62,6 +79,10 @@

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

<config-file target="config.xml" parent="/*">
<feature name="SQLitePlugin">
<param name="ios-package" value="SQLitePlugin" />
Expand All @@ -80,6 +101,10 @@

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

<js-module src="src/windows/sqlite-proxy.js" name="SQLiteProxy">
<runs />
</js-module>
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 FIX TESTS:
<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>
<script src="spec/db-simultaneous-tx-access-test.js"></script>
<script src="spec/db-tx-multiple-update-test.js"></script>
<script src="spec/tx-semantics-test.js"></script>
<script src="spec/db-tx-error-handling-test.js"></script>
<!-- XXX TODO FIX TESTS:
<script src="spec/db-tx-value-bindings-test.js"></script>
-->
<script src="spec/db-tx-error-mapping-test.js"></script>
<!-- XXX TODO:
<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