Skip to content

Commit

Permalink
(WebKit) Web SQL testing on browser platform
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher J. Brody committed Aug 14, 2018
1 parent e748166 commit eade090
Show file tree
Hide file tree
Showing 19 changed files with 350 additions and 51 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ and limit database access to DRAFT standard transactions, no plugin-specific API
- no `echoTest` or `selfTest` possible
- no `deleteDatabase` calls

This kind of usage on Safari and Chrome desktop browser (with (WebKit) Web SQL) is now covered by the `spec` test suite.

It would be ideal for the application code to abstract the openDatabase part away from the rest of the database access code.

### Windows platform notes
Expand Down
16 changes: 14 additions & 2 deletions spec/www/spec/basic-db-tx-sql-storage-results.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,24 @@

var MYTIMEOUT = 12000;

var DEFAULT_SIZE = 5000000; // max to avoid popup in safari/ios
// NOTE: DEFAULT_SIZE wanted depends on type of browser

var isWindows = /MSAppHost/.test(navigator.userAgent);
var isAndroid = !isWindows && /Android/.test(navigator.userAgent);
var isMac = /Macintosh/.test(navigator.userAgent);
var isFirefox = /Firefox/.test(navigator.userAgent);
var isWebKitBrowser = !isWindows && !isAndroid && /Safari/.test(navigator.userAgent);
var isBrowser = isWebKitBrowser || isFirefox;
var isEdgeBrowser = isBrowser && (/Edge/.test(navigator.userAgent));
var isChromeBrowser = isBrowser && !isEdgeBrowser && (/Chrome/.test(navigator.userAgent));
var isSafariBrowser = isWebKitBrowser && !isEdgeBrowser && !isChromeBrowser;
var isMac = !isBrowser && /Macintosh/.test(navigator.userAgent);
var isAppleMobileOS = /iPhone/.test(navigator.userAgent) ||
/iPad/.test(navigator.userAgent) || /iPod/.test(navigator.userAgent);

// should avoid popups (Safari seems to count 2x)
var DEFAULT_SIZE = isSafariBrowser ? 2000000 : 5000000;
// FUTURE TBD: 50MB should be OK on Chrome and some other test browsers.

// 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
Expand All @@ -27,6 +37,8 @@ var scenarioCount = (!!window.hasWebKitWebSQL) ? (isAndroid ? 3 : 2) : 1;
var mytests = function() {

for (var i=0; i<scenarioCount; ++i) {
// TBD skip plugin test on browser platform (not yet supported):
if (isBrowser && (i === 0)) continue;

describe(scenarioList[i] + ': BASIC db tx sql storage results test(s)', function() {
var scenarioName = scenarioList[i];
Expand Down
8 changes: 6 additions & 2 deletions spec/www/spec/browser-check-startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ var MYTIMEOUT = 12000;

var isWindows = /MSAppHost/.test(navigator.userAgent);
var isAndroid = !isWindows && /Android/.test(navigator.userAgent);
var isMac = /Macintosh/.test(navigator.userAgent);
var isFirefox = /Firefox/.test(navigator.userAgent);
var isWebKitBrowser = !isWindows && !isAndroid && /Safari/.test(navigator.userAgent);
var isBrowser = isWebKitBrowser || isFirefox;
var isEdgeBrowser = isBrowser && (/Edge/.test(navigator.userAgent));
var isMac = !isBrowser && /Macintosh/.test(navigator.userAgent);
var isAppleMobileOS = /iPhone/.test(navigator.userAgent) ||
/iPad/.test(navigator.userAgent) || /iPod/.test(navigator.userAgent);
var hasMobileWKWebView = isAppleMobileOS && !!window.webkit && !!window.webkit.messageHandlers;

window.hasBrowser = true;
window.hasWebKitWebSQL = isAndroid || (isAppleMobileOS && !isWKWebView);
window.hasWebKitWebSQL = isAndroid || (isAppleMobileOS && !isWKWebView) || (isWebKitBrowser && !isEdgeBrowser);

describe('Check startup for navigator.userAgent: ' + navigator.userAgent, function() {
it('receives deviceready event', function(done) {
Expand Down
18 changes: 17 additions & 1 deletion spec/www/spec/db-open-close-delete-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var MYTIMEOUT = 12000;

var DEFAULT_SIZE = 5000000; // max to avoid popup in safari/ios
// NOTE: DEFAULT_SIZE wanted depends on type of browser

// FUTURE TODO replace in test(s):
function ok(test, desc) { expect(test).toBe(true); }
Expand Down Expand Up @@ -32,6 +32,16 @@ function start(n) {

var isWindows = /MSAppHost/.test(navigator.userAgent);
var isAndroid = !isWindows && /Android/.test(navigator.userAgent);
var isFirefox = /Firefox/.test(navigator.userAgent);
var isWebKitBrowser = !isWindows && !isAndroid && /Safari/.test(navigator.userAgent);
var isBrowser = isWebKitBrowser || isFirefox;
var isEdgeBrowser = isBrowser && (/Edge/.test(navigator.userAgent));
var isChromeBrowser = isBrowser && !isEdgeBrowser && (/Chrome/.test(navigator.userAgent));
var isSafariBrowser = isWebKitBrowser && !isEdgeBrowser && !isChromeBrowser;

// should avoid popups (Safari seems to count 2x)
var DEFAULT_SIZE = isSafariBrowser ? 2000000 : 5000000;
// FUTURE TBD: 50MB should be OK on Chrome and some other test browsers.

// NOTE: While in certain version branches there is no difference between
// the default Android implementation and implementation #2,
Expand All @@ -47,6 +57,8 @@ var pluginScenarioCount = isAndroid ? 2 : 1;
var mytests = function() {

describe('Open database parameter test(s)', function() {
// TBD skip plugin test on browser platform (not yet supported):
if (isBrowser) return;

for (var i=0; i<pluginScenarioCount; ++i) {

Expand Down Expand Up @@ -887,6 +899,8 @@ var mytests = function() {


describe('Plugin - basic sqlitePlugin.deleteDatabase parameter check test(s)', function() {
// TBD skip plugin test on browser platform (not yet supported):
if (isBrowser) return;

var suiteName = 'plugin: ';

Expand Down Expand Up @@ -1116,6 +1130,8 @@ var mytests = function() {
});

describe('Plugin: db open-close-delete test(s)', function() {
// TBD skip plugin test on browser platform (not yet supported):
if (isBrowser) return;

for (var i=0; i<pluginScenarioCount; ++i) {

Expand Down
14 changes: 13 additions & 1 deletion spec/www/spec/db-simultaneous-tx-access-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var MYTIMEOUT = 12000;

var DEFAULT_SIZE = 5000000; // max to avoid popup in safari/ios
// NOTE: DEFAULT_SIZE wanted depends on type of browser

// FUTURE TODO replace in test(s):
function ok(test, desc) { expect(test).toBe(true); }
Expand Down Expand Up @@ -32,6 +32,16 @@ function start(n) {

var isWindows = /MSAppHost/.test(navigator.userAgent);
var isAndroid = !isWindows && /Android/.test(navigator.userAgent);
var isFirefox = /Firefox/.test(navigator.userAgent);
var isWebKitBrowser = !isWindows && !isAndroid && /Safari/.test(navigator.userAgent);
var isBrowser = isWebKitBrowser || isFirefox;
var isEdgeBrowser = isBrowser && (/Edge/.test(navigator.userAgent));
var isChromeBrowser = isBrowser && !isEdgeBrowser && (/Chrome/.test(navigator.userAgent));
var isSafariBrowser = isWebKitBrowser && !isEdgeBrowser && !isChromeBrowser;

// should avoid popups (Safari seems to count 2x)
var DEFAULT_SIZE = isSafariBrowser ? 2000000 : 5000000;
// FUTURE TBD: 50MB should be OK on Chrome and some other test browsers.

// NOTE: While in certain version branches there is no difference between
// the default Android implementation and implementation #2,
Expand All @@ -48,6 +58,8 @@ var scenarioCount = (!!window.hasWebKitWebSQL) ? (isAndroid ? 3 : 2) : 1;
var mytests = function() {

for (var i=0; i<scenarioCount; ++i) {
// TBD skip plugin test on browser platform (not yet supported):
if (isBrowser && (i === 0)) continue;

describe(scenarioList[i] + ': simultaneous tx access test(s)', function() {
var scenarioName = scenarioList[i];
Expand Down
10 changes: 9 additions & 1 deletion spec/www/spec/db-sql-operations-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ var MYTIMEOUT = 30000;

var isWindows = /MSAppHost/.test(navigator.userAgent);
var isAndroid = !isWindows && /Android/.test(navigator.userAgent);
var isMac = /Macintosh/.test(navigator.userAgent);
var isFirefox = /Firefox/.test(navigator.userAgent);
var isWebKitBrowser = !isWindows && !isAndroid && /Safari/.test(navigator.userAgent);
var isBrowser = isWebKitBrowser || isFirefox;
var isEdgeBrowser = isBrowser && (/Edge/.test(navigator.userAgent));
var isChromeBrowser = isBrowser && !isEdgeBrowser && (/Chrome/.test(navigator.userAgent));
var isMac = !isBrowser && /Macintosh/.test(navigator.userAgent);
var isAppleMobileOS = /iPhone/.test(navigator.userAgent) ||
/iPad/.test(navigator.userAgent) || /iPod/.test(navigator.userAgent);
var hasMobileWKWebView = isAppleMobileOS && !!window.webkit && !!window.webkit.messageHandlers;
Expand All @@ -25,6 +30,9 @@ var mytests = function() {
for (var i=0; i<pluginScenarioCount; ++i) {

describe(pluginScenarioList[i] + ': sql operations via plugin-specific db.executeSql test(s)', function() {
// TBD skip plugin test on browser platform (not yet supported):
if (isBrowser) return;

var scenarioName = pluginScenarioList[i];
var suiteName = scenarioName + ': ';
var isImpl2 = (i === 1);
Expand Down
Loading

0 comments on commit eade090

Please sign in to comment.