Skip to content

Commit 01ff6f6

Browse files
author
Christopher J. Brody
committed
WIP: Add browser platform
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.
1 parent aff5f3c commit 01ff6f6

11 files changed

+250
-79
lines changed

CHANGES.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

5-
TBD
5+
- Support browser platform
66

77
## cordova-sqlite-storage 2.0.3
88

plugin.xml

+13
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@
1616
<!-- THANKS to AllJoyn-Cordova / cordova-plugin-alljoyn: -->
1717
<hook type="before_plugin_install" src="scripts/beforePluginInstall.js" />
1818

19+
<!-- browser -->
20+
<platform name="browser">
21+
<js-module src="src/browser/SQLitePlugin.js" name="SQLitePlugin">
22+
<clobbers target="SQLitePlugin" />
23+
</js-module>
24+
25+
<config-file target="config.xml" parent="/*">
26+
<feature name="SQLitePlugin">
27+
<param name="browser-package" value="SQLitePlugin" />
28+
</feature>
29+
</config-file>
30+
</platform>
31+
1932
<!-- android -->
2033
<platform name="android">
2134
<js-module src="www/SQLitePlugin.js" name="SQLitePlugin">

spec/www/index.html

+8
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,30 @@
2020

2121
<!-- spec file(s): -->
2222
<script src="spec/browser-check-startup.js"></script>
23+
<!-- XXX TODO:
2324
<script src="spec/self-test.js"></script>
25+
-->
2426
<script src="spec/sqlite-version-test.js"></script>
2527
<script src="spec/db-tx-string-test.js"></script>
2628
<script src="spec/db-tx-sql-select-value-test.js"></script>
2729
<script src="spec/basic-db-tx-sql-storage-results.js"></script>
2830
<script src="spec/db-sql-operations-test.js"></script>
31+
<!-- XXX TODO:
2932
<script src="spec/sql-batch-test.js"></script>
33+
-->
3034
<script src="spec/db-tx-sql-features-test.js"></script>
3135
<script src="spec/regexp-test.js"></script>
36+
<!-- XXX TODO:
3237
<script src="spec/db-simultaneous-tx-access-test.js"></script>
38+
-->
3339
<script src="spec/db-tx-multiple-update-test.js"></script>
40+
<!-- XXX TODO:
3441
<script src="spec/tx-semantics-test.js"></script>
3542
<script src="spec/db-tx-error-handling-test.js"></script>
3643
<script src="spec/db-tx-value-bindings-test.js"></script>
3744
<script src="spec/db-tx-error-mapping-test.js"></script>
3845
<script src="spec/db-open-close-delete-test.js"></script>
46+
-->
3947
<script src="spec/ext-tx-blob-test.js"></script>
4048

4149
</head>

spec/www/spec/basic-db-tx-sql-storage-results.js

+28-15
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ var mytests = function() {
211211
// ref: https://www.w3.org/TR/webdatabase/#database-query-results
212212
rs.insertId = 2;
213213
rs.rowsAffected = 3;
214-
if (isWebSql) {
214+
if (isWebSql || isBrowser) {
215215
expect(rs.insertId).toBe(1);
216216
expect(rs.rowsAffected).toBe(1);
217217
} else {
@@ -240,7 +240,7 @@ var mytests = function() {
240240
// rs.rows.length should be immutable
241241
// ref: https://www.w3.org/TR/webdatabase/#database-query-results
242242
rs.rows.length = 2;
243-
if (isWebSql) {
243+
if (isWebSql || isBrowser) {
244244
expect(rs.rows.length).toBe(1);
245245
} else {
246246
expect(rs.rows.length).toBe(2);
@@ -313,15 +313,21 @@ var mytests = function() {
313313
// Object from rows.item is immutable in Android/iOS WebKit Web SQL but NOT in this plugin:
314314
temp1.data = 'another';
315315

316-
if (isWebSql) {
316+
if (isBrowser) {
317+
// PLUGIN on browser platform:
318+
// 1. DEVIATION - temp1 is just like any other Javascript object:
319+
expect(temp1.data).toBe('another');
320+
// 2. According to Web SQL STANDARD - object returned by second resultSet.rows.item call not affected:
321+
expect(temp2.data).toBe('test');
322+
} else if (isWebSql) {
317323
// Web SQL STANDARD:
318324
// 1. this is a native object that is NOT affected by the change (SKIP for Android 5.x/+):
319325
if (!isAndroid || /Android [1-4]/.test(navigator.userAgent))
320326
expect(temp1.data).toBe('test');
321327
// 2. object returned by second resultSet.rows.item call not affected:
322328
expect(temp2.data).toBe('test');
323329
} else {
324-
// PLUGIN:
330+
// PLUGIN on other platforms:
325331
// 1. DEVIATION - temp1 is just like any other Javascript object:
326332
expect(temp1.data).toBe('another');
327333
// 2. DEVIATION - same object is returned by second resultSet.rows.item IS affected:
@@ -667,12 +673,17 @@ var mytests = function() {
667673
// CORRECT RESULT:
668674
//expect(resultSet.rows.length).toBe(2);
669675
// ACTUAL RESULT for PLUGIN [BROKEN with possible parameter data loss]:
670-
expect(resultSet.rows.length).toBe(1);
671-
672-
// FIRST ROW CORRECT:
673-
expect(resultSet.rows.item(0).data).toBe(1);
674-
// SECOND ROW MISSING:
675-
//expect(resultSet.rows.item(1).data).toBe(2);
676+
if (isBrowser) {
677+
// NO ROWS STORED ON BROWSER PLATFORM:
678+
expect(resultSet.rows.length).toBe(0);
679+
} else (isBrowser) {
680+
expect(resultSet.rows.length).toBe(1);
681+
682+
// FIRST ROW CORRECT:
683+
expect(resultSet.rows.item(0).data).toBe(1);
684+
// SECOND ROW MISSING:
685+
//expect(resultSet.rows.item(1).data).toBe(2);
686+
}
676687

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

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

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

714727
expect(error).toBeDefined();
@@ -886,7 +899,7 @@ var mytests = function() {
886899

887900
});
888901

889-
it(suiteName + 'INSERT OR IGNORE result in case of constraint violation [(WebKit) Web SQL DEVIATION on Android/iOS: reports old insertId value]', function(done) {
902+
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) {
890903
var db = openDatabase('INSERT-OR-IGNORE-test.db', '1.0', 'Test', DEFAULT_SIZE);
891904

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

spec/www/spec/browser-check-startup.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
var MYTIMEOUT = 12000;
44

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

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

1516
describe('check startup', function() {
1617
it('receives deviceready event', function(done) {

0 commit comments

Comments
 (0)