diff --git a/CHANGES.md b/CHANGES.md index e5a1d790e..5a54928e5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,7 +2,7 @@ ## cordova-sqlite-storage 2.1.0-browser-wip1 -TBD +- Support browser platform ## cordova-sqlite-storage 2.0.3 diff --git a/plugin.xml b/plugin.xml index 01414944c..082304e87 100644 --- a/plugin.xml +++ b/plugin.xml @@ -16,6 +16,19 @@ + + + + + + + + + + + + + diff --git a/spec/www/index.html b/spec/www/index.html index f286f7a1b..d0b6bac7a 100644 --- a/spec/www/index.html +++ b/spec/www/index.html @@ -20,22 +20,30 @@ + + + + diff --git a/spec/www/spec/basic-db-tx-sql-storage-results.js b/spec/www/spec/basic-db-tx-sql-storage-results.js index 2ad14b56e..1a594a0b1 100644 --- a/spec/www/spec/basic-db-tx-sql-storage-results.js +++ b/spec/www/spec/basic-db-tx-sql-storage-results.js @@ -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 { @@ -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); @@ -313,7 +313,13 @@ 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)) @@ -321,7 +327,7 @@ var mytests = function() { // 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: @@ -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); @@ -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. @@ -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(); @@ -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(); @@ -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) { @@ -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); diff --git a/spec/www/spec/browser-check-startup.js b/spec/www/spec/browser-check-startup.js index 019ddefe1..1bf4a69f9 100644 --- a/spec/www/spec/browser-check-startup.js +++ b/spec/www/spec/browser-check-startup.js @@ -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) { diff --git a/spec/www/spec/db-sql-operations-test.js b/spec/www/spec/db-sql-operations-test.js index a5ed27b72..196fc20b9 100755 --- a/spec/www/spec/db-sql-operations-test.js +++ b/spec/www/spec/db-sql-operations-test.js @@ -32,7 +32,8 @@ function start(n) { 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); -var isMac = /Macintosh/.test(navigator.userAgent); +var isBrowser = !isWindows && !isAndroid && /Chrome/.test(navigator.userAgent); +var isMac = !isBrowser && /Macintosh/.test(navigator.userAgent); var isWKWebView = !isWindows && !isAndroid && !isWP8 && !isMac && !!window.webkit && !!window.webkit.messageHandlers; // NOTE: In the common storage-master branch there is no difference between the @@ -156,7 +157,7 @@ var mytests = function() { expect(rs).toBeDefined(); expect(rs.rows).toBeDefined(); expect(rs.rows.length).toBe(1); - if (isMac || isWKWebView) + if (isBrowser || isMac || isWKWebView) expect(rs.rows.item(0).myresult).toBe('real'); else if (isAndroid && isImpl2) expect(rs.rows.item(0).myresult).toBe('text'); @@ -200,7 +201,7 @@ var mytests = function() { expect(rs).toBeDefined(); expect(rs.rows).toBeDefined(); expect(rs.rows.length).toBe(1); - if (isMac || isWKWebView) + if (isBrowser || isMac || isWKWebView) expect(rs.rows.item(0).myresult).toBe('real'); else if (isAndroid && isImpl2) expect(rs.rows.item(0).myresult).toBe('text'); @@ -328,7 +329,7 @@ var mytests = function() { expect(rs).toBeDefined(); expect(rs.rows).toBeDefined(); expect(rs.rows.length).toBe(1); - if (isMac || isWKWebView) + if (isBrowser || isMac || isWKWebView) expect(rs.rows.item(0).myresult).toBe('real'); else if (isAndroid && isImpl2) expect(rs.rows.item(0).myresult).toBe('text'); @@ -393,7 +394,7 @@ var mytests = function() { expect(rs).toBeDefined(); expect(rs.rows).toBeDefined(); expect(rs.rows.length).toBe(1); - if (isAndroid && isImpl2) + if (isBrowser || (isAndroid && isImpl2)) expect(rs.rows.item(0).myresult).toBe('text'); else expect(rs.rows.item(0).myresult).toBe('null'); @@ -416,9 +417,9 @@ var mytests = function() { expect(rs).toBeDefined(); expect(rs.rows).toBeDefined(); expect(rs.rows.length).toBe(1); - if (isAndroid && isImpl2) + if (isMac || isWKWebView) expect(rs.rows.item(0).myresult).toBe('text'); - else if (!isWindows && !isMac) + else if (!isBrowser && !isWindows && !isMac) expect(rs.rows.item(0).myresult).toBe('null'); else expect(rs.rows.item(0).myresult).toBe('real'); @@ -442,7 +443,7 @@ var mytests = function() { expect(rs).toBeDefined(); expect(rs.rows).toBeDefined(); expect(rs.rows.length).toBe(1); - if (isWindows) + if (isBrowser || isWindows) expect(rs.rows.item(0).myresult).toBe(Infinity); else if (isAndroid && isImpl2) expect(rs.rows.item(0).myresult).toBe(''); @@ -469,7 +470,7 @@ var mytests = function() { expect(rs.rows.length).toBe(1); if (isAndroid && isImpl2) expect(rs.rows.item(0).myresult).toBe('text'); - else if (!isWindows && !isMac) + else if (!isBrowser && !isWindows && !isMac) expect(rs.rows.item(0).myresult).toBe('null'); else expect(rs.rows.item(0).myresult).toBe('real'); @@ -493,7 +494,7 @@ var mytests = function() { expect(rs).toBeDefined(); expect(rs.rows).toBeDefined(); expect(rs.rows.length).toBe(1); - if (isWindows) + if (isBrowser || isWindows) expect(rs.rows.item(0).myresult).toBe(-Infinity); else if (isAndroid && isImpl2) expect(rs.rows.item(0).myresult).toBe(''); @@ -548,22 +549,22 @@ var mytests = function() { expect(rs.rows).toBeDefined(); expect(rs.rows.length).toBe(9); expect(rs.rows.item(0).d1).toBe(101); - if (isMac || isWKWebView) + if (isBrowser || isMac || isWKWebView) expect(rs.rows.item(0).t1).toBe('real'); else expect(rs.rows.item(0).t1).toBe('integer'); expect(rs.rows.item(0).a1).toBe(101); - if (isMac || isWKWebView) + if (isBrowser || isMac || isWKWebView) expect(rs.rows.item(0).u1).toBe('101.0'); else expect(rs.rows.item(0).u1).toBe('101'); expect(rs.rows.item(1).d1).toBe(-101); - if (isMac || isWKWebView) + if (isBrowser || isMac || isWKWebView) expect(rs.rows.item(1).t1).toBe('real'); else expect(rs.rows.item(1).t1).toBe('integer'); expect(rs.rows.item(1).a1).toBe(101); - if (isMac || isWKWebView) + if (isBrowser || isMac || isWKWebView) expect(rs.rows.item(1).u1).toBe('-101.0'); else expect(rs.rows.item(1).u1).toBe('-101'); @@ -576,22 +577,22 @@ var mytests = function() { expect(rs.rows.item(3).a1).toBe(123.456); expect(rs.rows.item(3).u1).toBe('-123.456'); expect(rs.rows.item(4).d1).toBe(1234567890123); - if (isMac || isWKWebView) + if (isBrowser || isMac || isWKWebView) expect(rs.rows.item(4).t1).toBe('real'); else expect(rs.rows.item(4).t1).toBe('integer'); expect(rs.rows.item(4).a1).toBe(1234567890123); - if (isMac || isWKWebView) + if (isBrowser || isMac || isWKWebView) expect(rs.rows.item(4).u1).toBe('1234567890123.0'); else expect(rs.rows.item(4).u1).toBe('1234567890123'); expect(rs.rows.item(5).d1).toBe(-1234567890123); - if (isMac || isWKWebView) + if (isBrowser || isMac || isWKWebView) expect(rs.rows.item(5).t1).toBe('real'); else expect(rs.rows.item(5).t1).toBe('integer'); expect(rs.rows.item(5).a1).toBe(1234567890123); - if (isMac || isWKWebView) + if (isBrowser || isMac || isWKWebView) expect(rs.rows.item(5).u1).toBe('-1234567890123.0'); else expect(rs.rows.item(5).u1).toBe('-1234567890123'); @@ -604,12 +605,12 @@ var mytests = function() { expect(rs.rows.item(7).a1).toBe(1234567890123.4); expect(rs.rows.item(7).u1).toBe('-1234567890123.4'); expect(rs.rows.item(8).d1).toBe(0); - if (isMac || isWKWebView) + if (isBrowser || isMac || isWKWebView) expect(rs.rows.item(8).t1).toBe('real'); else expect(rs.rows.item(8).t1).toBe('integer'); expect(rs.rows.item(8).a1).toBe(0); - if (isMac || isWKWebView) + if (isBrowser || isMac || isWKWebView) expect(rs.rows.item(8).u1).toBe('0.0'); else expect(rs.rows.item(8).u1).toBe('0'); @@ -634,10 +635,22 @@ var mytests = function() { expect(rs.rows.item(0).t1).toBe('null'); expect(rs.rows.item(0).a1).toBe(null); expect(rs.rows.item(0).u1).toBe(null); - expect(rs.rows.item(1).d1).toBe(null); - expect(rs.rows.item(1).t1).toBe('null'); - expect(rs.rows.item(1).a1).toBe(null); - expect(rs.rows.item(1).u1).toBe(null); + if (isBrowser) + expect(rs.rows.item(1).d1).toBe('undefined'); + else + expect(rs.rows.item(1).d1).toBe(null); + if (isBrowser) + expect(rs.rows.item(1).t1).toBe('text'); + else + expect(rs.rows.item(1).t1).toBe('null'); + if (isBrowser) + expect(rs.rows.item(1).a1).toBe(0); + else + expect(rs.rows.item(1).a1).toBe(null); + if (isBrowser) + expect(rs.rows.item(1).u1).toBe('UNDEFINED'); + else + expect(rs.rows.item(1).u1).toBe(null); db.close(done, done); }); }, MYTIMEOUT); @@ -657,7 +670,7 @@ var mytests = function() { db.executeSql('SELECT data AS d1, TYPEOF(data) AS t1, ABS(data) AS a1, UPPER(data) as u1 FROM MyTable', [], function (rs) { expect(rs.rows).toBeDefined(); expect(rs.rows.length).toBe(3); - if (isWindows) { + if (isBrowser || isWindows) { expect(rs.rows.item(0).d1).toBe(Infinity); expect(rs.rows.item(0).t1).toBe('real'); expect(rs.rows.item(0).a1).toBe(Infinity); @@ -786,8 +799,13 @@ var mytests = function() { expect(rs).toBeDefined(); expect(rs.rows).toBeDefined(); expect(rs.rows.length).toBe(1); - expect(rs.rows.item(0).upper1).toBeNull(); - expect(rs.rows.item(0).upper2).toBeNull(); + if (isBrowser) { + expect(rs.rows.item(0).upper1).toBe('S1'); + expect(rs.rows.item(0).upper2).toBe('S2'); + } else { + expect(rs.rows.item(0).upper1).toBeNull(); + expect(rs.rows.item(0).upper2).toBeNull(); + } db.close(done, done); }, function(error) { // NOT EXPECTED: @@ -1034,7 +1052,8 @@ var mytests = function() { expect(false).toBe(null); db.close(done, done); }, function(error) { - expect('Behavior changed please update this test').toBe('--'); + if (!isBrowser) + expect('Behavior changed please update this test').toBe('--'); expect(error).toBeDefined(); expect(error.code).toBeDefined(); expect(error.message).toBeDefined(); @@ -1051,6 +1070,8 @@ var mytests = function() { expect(true).toBe(true); // SKIP for now else if (isWindows) expect(error.message).toMatch(/Error preparing an SQLite statement/); + else if (isBrowser) + expect(true).toBe(true); // SKIP for now else expect(error.message).toMatch(/near \"SLCT\": syntax error/); }); @@ -1077,7 +1098,8 @@ var mytests = function() { expect(false).toBe(null); db.close(done, done); }, function(error) { - expect('Behavior changed please update this test').toBe('--'); + if (!isBrowser) + expect('Behavior changed please update this test').toBe('--'); expect(error).toBeDefined(); expect(error.code).toBeDefined(); expect(error.message).toBeDefined(); @@ -1094,6 +1116,8 @@ var mytests = function() { expect(true).toBe(true); // SKIP for now else if (isWindows) expect(error.message).toMatch(/Error preparing an SQLite statement/); + else if (isBrowser) + expect(true).toBe(true); // TBD SKIP for now else expect(error.message).toMatch(/near \"SLCT\": syntax error/); }); @@ -1346,7 +1370,10 @@ var mytests = function() { }, function(error) { // EXPECTED RESULT expect(error).toBeDefined(); - expect(error.code).toBeDefined(); + if (isBrowser) + expect(error.code).not.toBeDefined(); + else + expect(error.code).toBeDefined(); expect(error.message).toBeDefined(); db.close(done, done); }); @@ -1368,7 +1395,10 @@ var mytests = function() { }, function(error) { // EXPECTED RESULT expect(error).toBeDefined(); - expect(error.code).toBeDefined(); + if (isBrowser) + expect(error.code).not.toBeDefined(); + else + expect(error.code).toBeDefined(); expect(error.message).toBeDefined(); db.close(done, done); }); @@ -1670,7 +1700,7 @@ var mytests = function() { return window.sqlitePlugin.openDatabase(dbopts, okcb, errorcb); } - test_it(suiteName + "PRAGMAs & multiple database transactions mixed together", function() { + xtest_it(suiteName + "PRAGMAs & multiple database transactions mixed together", function() { var db = openDatabase("DB1", "1.0", "Demo", DEFAULT_SIZE); var db2 = openDatabase("DB2", "1.0", "Demo", DEFAULT_SIZE); diff --git a/spec/www/spec/db-tx-sql-features-test.js b/spec/www/spec/db-tx-sql-features-test.js index a272e6eb1..b80c68a69 100644 --- a/spec/www/spec/db-tx-sql-features-test.js +++ b/spec/www/spec/db-tx-sql-features-test.js @@ -7,6 +7,7 @@ var DEFAULT_SIZE = 5000000; // max to avoid popup in safari/ios 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); +var isBrowser = !isWindows && !isAndroid && /Chrome/.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 @@ -126,6 +127,7 @@ var mytests = function() { it(suiteName + 'create virtual table using FTS4', function(done) { if (isWP8) pending('NOT IMPLEMENTED for WP(8)'); // NOT IMPLEMENTED in CSharp-SQLite if (isWebSql) pending('SKIP for Web SQL'); + if (isBrowser) pending('SKIP for browser platform'); var db = openDatabase('virtual-table-using-fts4.db', '1.0', 'Test', DEFAULT_SIZE); @@ -274,6 +276,7 @@ var mytests = function() { it(suiteName + 'create virtual table using R-Tree', function(done) { if (isWebSql) pending('SKIP for Web SQL'); if (isWP8) pending('NOT IMPLEMENTED for WP(8)'); // NOT IMPLEMENTED in CSharp-SQLite + if (isBrowser) pending('SKIP for browser platform'); if (isAndroid && isImpl2) pending('NOT IMPLEMENTED for all versions of android.database'); // NOT IMPLEMENTED for all versions of Android database (failed in Circle CI) var db = openDatabase('virtual-table-using-r-tree.db', '1.0', 'Test', DEFAULT_SIZE); diff --git a/spec/www/spec/db-tx-sql-select-value-test.js b/spec/www/spec/db-tx-sql-select-value-test.js index 690d8b93a..ccde44e71 100644 --- a/spec/www/spec/db-tx-sql-select-value-test.js +++ b/spec/www/spec/db-tx-sql-select-value-test.js @@ -7,7 +7,8 @@ var DEFAULT_SIZE = 5000000; // max to avoid popup in safari/ios 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); -var isMac = /Macintosh/.test(navigator.userAgent); +var isBrowser = !isWindows && !isAndroid && /Chrome/.test(navigator.userAgent); +var isMac = !isBrowser && /Macintosh/.test(navigator.userAgent); var isWKWebView = !isWindows && !isAndroid && !isWP8 && !isMac && !!window.webkit && !!window.webkit.messageHandlers; // The following openDatabase settings are used for Plugin-implementation-2 @@ -238,7 +239,7 @@ var mytests = function() { expect(rs).toBeDefined(); expect(rs.rows).toBeDefined(); expect(rs.rows.length).toBe(1); - if ((isWebSql && isAndroid) || (!isWebSql && isAndroid && isImpl2)) + if (isBrowser || (isWebSql && isAndroid) || (!isWebSql && isAndroid && isImpl2)) expect(rs.rows.item(0).myresult).toBe('text'); else expect(rs.rows.item(0).myresult).toBe('null'); @@ -261,7 +262,7 @@ var mytests = function() { expect(rs).toBeDefined(); expect(rs.rows).toBeDefined(); expect(rs.rows.length).toBe(1); - if (isWebSql && isAndroid) + if (isBrowser || (isWebSql && isAndroid)) expect(rs.rows.item(0).myresult).toBe('undefined'); else if (!isWebSql && isAndroid && isImpl2) expect(rs.rows.item(0).myresult).toBe(''); @@ -408,7 +409,7 @@ var mytests = function() { expect(rs).toBeDefined(); expect(rs.rows).toBeDefined(); expect(rs.rows.length).toBe(1); - if (isWebSql || isMac || isWKWebView) + if (isWebSql || isBrowser || isMac || isWKWebView) expect(rs.rows.item(0).myresult).toBe('real'); else if (!isWebSql && isAndroid && isImpl2) expect(rs.rows.item(0).myresult).toBe('text'); @@ -473,7 +474,7 @@ var mytests = function() { expect(rs).toBeDefined(); expect(rs.rows).toBeDefined(); expect(rs.rows.length).toBe(1); - if (isWebSql || isMac || isWKWebView) + if (isWebSql || isBrowser || isMac || isWKWebView) expect(rs.rows.item(0).myresult).toBe('real'); else if (!isWebSql && isAndroid && isImpl2) expect(rs.rows.item(0).myresult).toBe('text'); @@ -664,7 +665,7 @@ var mytests = function() { expect(rs).toBeDefined(); expect(rs.rows).toBeDefined(); expect(rs.rows.length).toBe(1); - if (isWebSql || isMac || isWKWebView) + if (isWebSql || isBrowser || isMac || isWKWebView) expect(rs.rows.item(0).myresult).toBe('real'); else if (!isWebSql && isAndroid && isImpl2) expect(rs.rows.item(0).myresult).toBe('text'); @@ -729,7 +730,7 @@ var mytests = function() { expect(rs).toBeDefined(); expect(rs.rows).toBeDefined(); expect(rs.rows.length).toBe(1); - if (isWebSql || isMac || isWKWebView) + if (isWebSql || isBrowser || isMac || isWKWebView) expect(rs.rows.item(0).myresult).toBe('real'); else if (!isWebSql && isAndroid && isImpl2) expect(rs.rows.item(0).myresult).toBe('text'); @@ -923,7 +924,7 @@ var mytests = function() { expect(rs).toBeDefined(); expect(rs.rows).toBeDefined(); expect(rs.rows.length).toBe(1); - if (isWebSql || isMac || isWKWebView) + if (isWebSql || isBrowser || isMac || isWKWebView) expect(rs.rows.item(0).myresult).toBe('real'); else if (!isWebSql && isAndroid && isImpl2) expect(rs.rows.item(0).myresult).toBe('text'); @@ -988,7 +989,7 @@ var mytests = function() { expect(rs).toBeDefined(); expect(rs.rows).toBeDefined(); expect(rs.rows.length).toBe(1); - if (isWebSql || isMac || isWKWebView) + if (isWebSql || isBrowser || isMac || isWKWebView) expect(rs.rows.item(0).myresult).toBe('real'); else if (!isWebSql && isAndroid && isImpl2) expect(rs.rows.item(0).myresult).toBe('text'); @@ -1186,12 +1187,12 @@ var mytests = function() { expect(rs.rows.item(0).myresult).toBeDefined(); // Android/iOS plugin issue - if (!isWebSql && isAndroid && isImpl2) + if (isBrowser || isWindows) + expect(rs.rows.item(0).myresult).toBe('inf'); + else if (isWebSql || isMac || isWKWebView) expect(rs.rows.item(0).myresult).toBe(''); - else if (!isWebSql && !isWindows && !isMac) - expect(rs.rows.item(0).myresult).toBe(null); else - expect(rs.rows.item(0).myresult).toBe('inf'); + expect(rs.rows.item(0).myresult).toBe(null); // Close (plugin only) & finish: (isWebSql) ? done() : db.close(done, done); @@ -1221,7 +1222,10 @@ var mytests = function() { expect(rs.rows.item(0).myresult).toBeDefined(); // Android/iOS plugin issue - if (!isWebSql && isAndroid && isImpl2) + if (isBrowser) + expect(rs.rows.item(0).myresult).toBe('-INF'); + else + if (isWebSql || isMac || isWKWebView) expect(rs.rows.item(0).myresult).toBe(''); else if (!isWebSql && !isWindows && !isMac) expect(rs.rows.item(0).myresult).toBe(null); @@ -1256,7 +1260,10 @@ var mytests = function() { expect(rs.rows.item(0).myresult).toBeDefined(); // Android/iOS plugin issue - if (!isWebSql && isAndroid && isImpl2) + if (isBrowser) + expect(rs.rows.item(0).myresult).toBe('real'); + else + if (isWebSql || isMac || isWKWebView) expect(rs.rows.item(0).myresult).toBe('text'); else if (!isWebSql && !isWindows && !isMac) expect(rs.rows.item(0).myresult).toBe('null'); @@ -1291,7 +1298,10 @@ var mytests = function() { expect(rs.rows.item(0).myresult).toBeDefined(); // Android/iOS plugin issue - if (!isWebSql && isAndroid && isImpl2) + if (isBrowser) + expect(rs.rows.item(0).myresult).toBe('real'); + else + if (isWebSql || isMac || isWKWebView) expect(rs.rows.item(0).myresult).toBe('text'); else if (!isWebSql && !isWindows && !isMac) expect(rs.rows.item(0).myresult).toBe('null'); @@ -1326,7 +1336,10 @@ var mytests = function() { expect(rs.rows.length).toBe(1); // Android/iOS plugin issue - if (!isWebSql && isAndroid && isImpl2) + if (isBrowser) + expect(rs.rows.item(0).myresult).toBe(Infinity); + else + if (!isBrowser && (isWebSql || isMac || isWKWebView)) expect(rs.rows.item(0).myresult).toBe(''); else if (!isWebSql && !isWindows) expect(rs.rows.item(0).myresult).toBe(null); @@ -1361,7 +1374,10 @@ var mytests = function() { expect(rs.rows.length).toBe(1); // Android/iOS plugin issue - if (!isWebSql && isAndroid && isImpl2) + if (isBrowser) + expect(rs.rows.item(0).myresult).toBe(-Infinity); + else + if (isWebSql || isMac || isWKWebView) expect(rs.rows.item(0).myresult).toBe(''); else if (!isWebSql && !isWindows) expect(rs.rows.item(0).myresult).toBe(null); @@ -1840,7 +1856,7 @@ var mytests = function() { expect(rs).toBeDefined(); expect(rs.rows).toBeDefined(); expect(rs.rows.length).toBe(1); - if (!isWebSql && !isAndroid && !isWindows && !isWP8) + if (!isWebSql && !isBrowser && !isAndroid && !isWindows && !isWP8) expect(rs.rows.item(0).myresult).not.toBeDefined(); // not defined iOS/macOS else expect(rs.rows.item(0).myresult).toBeDefined(); diff --git a/spec/www/spec/db-tx-string-test.js b/spec/www/spec/db-tx-string-test.js index 64401321a..2bbcb6286 100755 --- a/spec/www/spec/db-tx-string-test.js +++ b/spec/www/spec/db-tx-string-test.js @@ -7,6 +7,8 @@ var DEFAULT_SIZE = 5000000; // max to avoid popup in safari/ios var isWP8 = /IEMobile/.test(navigator.userAgent); // Matches WP(7/8/8.1) var isWindows = /Windows /.test(navigator.userAgent); // Windows (8.1) var isAndroid = !isWindows && /Android/.test(navigator.userAgent); +var isBrowser = !isWindows && !isAndroid && /Chrome/.test(navigator.userAgent); +//var isMac = !isBrowser && /Macintosh/.test(navigator.userAgent); // The following openDatabase settings are used for Plugin-implementation-2 // on Android: @@ -596,7 +598,7 @@ var mytests = function() { expect(rs).toBeDefined(); expect(rs.rows).toBeDefined(); expect(rs.rows.length).toBe(1); - if (isAndroid && (isWebSql || (isImpl2 && /Android [5-9]/.test(navigator.userAgent)))) + if (isBrowser || (isAndroid && (isWebSql || (isImpl2 && /Android [5-9]/.test(navigator.userAgent))))) expect(rs.rows.item(0).myresult).toBe('AÉ'); else expect(rs.rows.item(0).myresult).toBe('Aé'); @@ -996,7 +998,7 @@ var mytests = function() { expect(rs).toBeDefined(); expect(rs.rows).toBeDefined(); expect(rs.rows.length).toBe(1); - if (isAndroid && (isWebSql || (isImpl2 && /Android [5-9]/.test(navigator.userAgent)))) + if (isBrowser || (isAndroid && (isWebSql || (isImpl2 && /Android [5-9]/.test(navigator.userAgent))))) expect(rs.rows.item(0).upper_result).toBe('TEST ¢ É €'); else expect(rs.rows.item(0).upper_result).toBe('TEST ¢ é €'); @@ -1024,7 +1026,7 @@ var mytests = function() { expect(rs).toBeDefined(); expect(rs.rows).toBeDefined(); expect(rs.rows.length).toBe(1); - if (isAndroid && (isWebSql || (isImpl2 && /Android [5-9]/.test(navigator.userAgent)))) + if (isBrowser || (isAndroid && (isWebSql || (isImpl2 && /Android [5-9]/.test(navigator.userAgent))))) expect(rs.rows.item(0).upper_result).toBe('TEST ¢ É €'); else expect(rs.rows.item(0).upper_result).toBe('TEST ¢ é €'); @@ -1462,7 +1464,7 @@ var mytests = function() { expect(rs).toBeDefined(); expect(rs.rows).toBeDefined(); expect(rs.rows.length).toBe(1); - if (isWebSql) { + if (isWebSql || isBrowser) { expect(rs.rows.item(0).upper1).toBe('S1'); expect(rs.rows.item(0).upper2).toBe('S2'); } else { diff --git a/spec/www/spec/sqlite-version-test.js b/spec/www/spec/sqlite-version-test.js index 0ede7faee..3f7fb1a0c 100755 --- a/spec/www/spec/sqlite-version-test.js +++ b/spec/www/spec/sqlite-version-test.js @@ -7,6 +7,7 @@ var DEFAULT_SIZE = 5000000; // max to avoid popup in safari/ios var isWP8 = /IEMobile/.test(navigator.userAgent); // Matches WP(7/8/8.1) var isWindows = /Windows /.test(navigator.userAgent); // Windows (8.1) var isAndroid = !isWindows && /Android/.test(navigator.userAgent); +var isBrowser = !isWindows && !isAndroid && /Chrome/.test(navigator.userAgent); // The following openDatabase settings are used for Plugin-implementation-2 // on Android: @@ -50,7 +51,7 @@ var mytests = function() { describe(suiteName + 'basic sqlite version test(s)', function() { - it(suiteName + 'Check sqlite version (pattern ONLY for WebKit Web SQL & androidDatabaseImplementation: 2)', function(done) { + it(suiteName + 'Check sqlite version (pattern ONLY for WebKit Web SQL, browser, & androidDatabaseImplementation: 2)', function(done) { var db = openDatabase("check-sqlite-version.db", "1.0", "Demo", DEFAULT_SIZE); expect(db).toBeDefined(); @@ -65,7 +66,7 @@ var mytests = function() { // Check pattern (both Web SQL & plugin) expect(rs.rows.item(0).myResult).toMatch(/3\.[0-9]+\.[0-9]+/); // Check specific [plugin only]: - if (!isWebSql && !(!isWindows && isAndroid && isImpl2)) + if (!isWebSql && !isBrowser && !(!isWindows && isAndroid && isImpl2)) expect(rs.rows.item(0).myResult).toBe('3.15.2'); // Close (plugin only) & finish: @@ -84,7 +85,8 @@ var mytests = function() { describe(suiteName + 'sqlite encoding test(s)', function() { it(suiteName + 'Check internal database encoding: UTF-16le for Windows, UTF-8 for others (plugin ONLY)', function(done) { - if (isWebSql) pending('SKIP: NOT SUPPORTED for (WebKit) Web SQL'); + if (isWebSql) pending('NOT SUPPORTED by (WebKit) Web SQL'); + if (isBrowser) pending('NOT SUPPORTED by Browser platform'); var db = openDatabase("Check-sqlite-PRAGMA-encoding.db", "1.0", "Demo", DEFAULT_SIZE); diff --git a/src/browser/SQLitePlugin.js b/src/browser/SQLitePlugin.js new file mode 100644 index 000000000..b192d5e18 --- /dev/null +++ b/src/browser/SQLitePlugin.js @@ -0,0 +1,83 @@ +(function(root) { + //var root = this; + + nextTick = window.setImmediate || function(fun) { + window.setTimeout(fun, 0); + }; + + root.sqlitePlugin = { + sqliteFeatures: { + isSQLitePlugin: true + }, + // TODO: echoTest, selfTest + openDatabase: function(opts, okcb, errorcb) { + var mydb = window.openDatabase(opts.name, '1.0', 'Test', 5*1024*1024); + var dbobj = { + //* ** + transaction: function(f, errorcb, okcb) { + mydb.transaction(function(tx) { + var txobj = { + executeSql: function(sql, values, sqlok, sqlerror) { + tx.executeSql(sql, values, function(ignored, rs) { + if (!!sqlok) sqlok(txobj, rs); + }, function(ignored, error) { + if (!!sqlerror) sqlerror(txobj, error); + }); + } + }; + f(txobj); + }, function(error) { + if (!!errorcb) errorcb(error); + }, function() { + if (!!okcb) okcb(); + }); + }, + readTransaction: function(f, errorcb, okcb) { + mydb.readTransaction(function(tx) { + var txobj = { + executeSql: function(sql, values, sqlok, sqlerror) { + tx.executeSql(sql, values, function(ignored, rs) { + if (!!sqlok) sqlok(txobj, rs); + }, function(ignored, error) { + if (!!sqlerror) sqlerror(txobj, error); + }); + } + }; + f(txobj); + }, function(error) { + if (!!errorcb) errorcb(error); + }, function() { + if (!!okcb) okcb(); + }); + }, + executeSql: function(sql, values, sqlok, sqlerror) { + mydb.transaction(function(tx) { + try { + tx.executeSql(sql, values, function(ignored, rs) { + if (!!sqlok) sqlok(rs); + }, function(ignored, error) { + if (!!sqlerror) sqlerror(error); + }); + } catch(e) { + if (!!sqlerror) sqlerror(e); + } + }); + }, + sqlBatch: function(sl, okcb, errorcb) { + if (!!errorcb) nextTick(function() { + errorcb(new Error('NOT IMPLEMENTED')); + }); + }, + close: function(cb1, cb2) { + if (!!cb1) nextTick(cb1); + } + }; + nextTick(function() { + if (!!okcb) okcb(dbobj); + }); + return dbobj; + }, + // TODO: deleteDatabase + }; + +})(this);