Fix tests so they auto-start when run via cordova-paramedic
This commit is contained in:
parent
cbfa195f7d
commit
86cc778c4a
247
tests/tests.js
247
tests/tests.js
@ -19,7 +19,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* global MSApp, alert */
|
/* global MSApp */
|
||||||
|
|
||||||
var cordova = require('cordova');
|
var cordova = require('cordova');
|
||||||
var isWindows = cordova.platformId === 'windows';
|
var isWindows = cordova.platformId === 'windows';
|
||||||
@ -33,128 +33,126 @@ if (isWindows && navigator && navigator.notification && navigator.notification.a
|
|||||||
}
|
}
|
||||||
|
|
||||||
exports.defineAutoTests = function () {
|
exports.defineAutoTests = function () {
|
||||||
|
|
||||||
var createTests = function (platformOpts) {
|
var createTests = function (platformOpts) {
|
||||||
platformOpts = platformOpts || '';
|
platformOpts = platformOpts || '';
|
||||||
|
|
||||||
describe('cordova.InAppBrowser', function () {
|
describe('cordova.InAppBrowser', function () {
|
||||||
|
|
||||||
it('inappbrowser.spec.1 should exist', function () {
|
it('inappbrowser.spec.1 should exist', function () {
|
||||||
expect(cordova.InAppBrowser).toBeDefined();
|
expect(cordova.InAppBrowser).toBeDefined();
|
||||||
});
|
|
||||||
|
|
||||||
it('inappbrowser.spec.2 should contain open function', function () {
|
|
||||||
expect(cordova.InAppBrowser.open).toBeDefined();
|
|
||||||
expect(cordova.InAppBrowser.open).toEqual(jasmine.any(Function));
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('open method', function () {
|
it('inappbrowser.spec.2 should contain open function', function () {
|
||||||
|
expect(cordova.InAppBrowser.open).toBeDefined();
|
||||||
|
expect(cordova.InAppBrowser.open).toEqual(jasmine.any(Function));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
if (cordova.platformId === 'osx') {
|
describe('open method', function () {
|
||||||
pending('Open method not fully supported on OSX.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var iabInstance;
|
if (cordova.platformId === 'osx') {
|
||||||
var originalTimeout;
|
pending('Open method not fully supported on OSX.');
|
||||||
var url = 'https://dist.apache.org/repos/dist/dev/cordova/';
|
return;
|
||||||
var badUrl = 'http://bad-uri/';
|
}
|
||||||
|
|
||||||
beforeEach(function () {
|
var iabInstance;
|
||||||
// increase timeout to ensure test url could be loaded within test time
|
var originalTimeout;
|
||||||
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
var url = 'https://dist.apache.org/repos/dist/dev/cordova/';
|
||||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
|
var badUrl = 'http://bad-uri/';
|
||||||
|
|
||||||
iabInstance = null;
|
beforeEach(function () {
|
||||||
});
|
// increase timeout to ensure test url could be loaded within test time
|
||||||
|
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
||||||
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
|
||||||
|
|
||||||
afterEach(function (done) {
|
iabInstance = null;
|
||||||
// restore original timeout
|
});
|
||||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
|
|
||||||
|
|
||||||
if (iabInstance !== null && iabInstance.close) {
|
afterEach(function (done) {
|
||||||
iabInstance.close();
|
// restore original timeout
|
||||||
}
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
|
||||||
iabInstance = null;
|
|
||||||
// add some extra time so that iab dialog is closed
|
|
||||||
setTimeout(done, 2000);
|
|
||||||
});
|
|
||||||
|
|
||||||
function verifyEvent (evt, type) {
|
if (iabInstance !== null && iabInstance.close) {
|
||||||
expect(evt).toBeDefined();
|
|
||||||
expect(evt.type).toEqual(type);
|
|
||||||
// `exit` event does not have url field, browser returns null url for CORS requests
|
|
||||||
if (type !== 'exit' && !isBrowser) {
|
|
||||||
expect(evt.url).toEqual(url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function verifyLoadErrorEvent (evt) {
|
|
||||||
expect(evt).toBeDefined();
|
|
||||||
expect(evt.type).toEqual('loaderror');
|
|
||||||
expect(evt.url).toEqual(badUrl);
|
|
||||||
expect(evt.code).toEqual(jasmine.any(Number));
|
|
||||||
expect(evt.message).toEqual(jasmine.any(String));
|
|
||||||
}
|
|
||||||
|
|
||||||
it('inappbrowser.spec.3 should return InAppBrowser instance with required methods', function () {
|
|
||||||
iabInstance = cordova.InAppBrowser.open(url, '_blank', platformOpts);
|
|
||||||
|
|
||||||
expect(iabInstance).toBeDefined();
|
|
||||||
|
|
||||||
expect(iabInstance.addEventListener).toEqual(jasmine.any(Function));
|
|
||||||
expect(iabInstance.removeEventListener).toEqual(jasmine.any(Function));
|
|
||||||
expect(iabInstance.close).toEqual(jasmine.any(Function));
|
|
||||||
expect(iabInstance.show).toEqual(jasmine.any(Function));
|
|
||||||
expect(iabInstance.hide).toEqual(jasmine.any(Function));
|
|
||||||
expect(iabInstance.executeScript).toEqual(jasmine.any(Function));
|
|
||||||
expect(iabInstance.insertCSS).toEqual(jasmine.any(Function));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('inappbrowser.spec.4 should support loadstart and loadstop events', function (done) {
|
|
||||||
var onLoadStart = jasmine.createSpy('loadstart event callback').and.callFake(function (evt) {
|
|
||||||
verifyEvent(evt, 'loadstart');
|
|
||||||
});
|
|
||||||
|
|
||||||
iabInstance = cordova.InAppBrowser.open(url, '_blank', platformOpts);
|
|
||||||
iabInstance.addEventListener('loadstart', onLoadStart);
|
|
||||||
iabInstance.addEventListener('loadstop', function (evt) {
|
|
||||||
verifyEvent(evt, 'loadstop');
|
|
||||||
if (!isBrowser) {
|
|
||||||
// according to documentation, "loadstart" event is not supported on browser
|
|
||||||
// https://github.com/apache/cordova-plugin-inappbrowser#browser-quirks-1
|
|
||||||
expect(onLoadStart).toHaveBeenCalled();
|
|
||||||
}
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('inappbrowser.spec.5 should support exit event', function (done) {
|
|
||||||
iabInstance = cordova.InAppBrowser.open(url, '_blank', platformOpts);
|
|
||||||
iabInstance.addEventListener('exit', function (evt) {
|
|
||||||
verifyEvent(evt, 'exit');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
iabInstance.close();
|
iabInstance.close();
|
||||||
iabInstance = null;
|
}
|
||||||
|
iabInstance = null;
|
||||||
|
// add some extra time so that iab dialog is closed
|
||||||
|
setTimeout(done, 2000);
|
||||||
|
});
|
||||||
|
|
||||||
|
function verifyEvent (evt, type) {
|
||||||
|
expect(evt).toBeDefined();
|
||||||
|
expect(evt.type).toEqual(type);
|
||||||
|
// `exit` event does not have url field, browser returns null url for CORS requests
|
||||||
|
if (type !== 'exit' && !isBrowser) {
|
||||||
|
expect(evt.url).toEqual(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function verifyLoadErrorEvent (evt) {
|
||||||
|
expect(evt).toBeDefined();
|
||||||
|
expect(evt.type).toEqual('loaderror');
|
||||||
|
expect(evt.url).toEqual(badUrl);
|
||||||
|
expect(evt.code).toEqual(jasmine.any(Number));
|
||||||
|
expect(evt.message).toEqual(jasmine.any(String));
|
||||||
|
}
|
||||||
|
|
||||||
|
it('inappbrowser.spec.3 should return InAppBrowser instance with required methods', function () {
|
||||||
|
iabInstance = cordova.InAppBrowser.open(url, '_blank', platformOpts);
|
||||||
|
|
||||||
|
expect(iabInstance).toBeDefined();
|
||||||
|
|
||||||
|
expect(iabInstance.addEventListener).toEqual(jasmine.any(Function));
|
||||||
|
expect(iabInstance.removeEventListener).toEqual(jasmine.any(Function));
|
||||||
|
expect(iabInstance.close).toEqual(jasmine.any(Function));
|
||||||
|
expect(iabInstance.show).toEqual(jasmine.any(Function));
|
||||||
|
expect(iabInstance.hide).toEqual(jasmine.any(Function));
|
||||||
|
expect(iabInstance.executeScript).toEqual(jasmine.any(Function));
|
||||||
|
expect(iabInstance.insertCSS).toEqual(jasmine.any(Function));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('inappbrowser.spec.4 should support loadstart and loadstop events', function (done) {
|
||||||
|
var onLoadStart = jasmine.createSpy('loadstart event callback').and.callFake(function (evt) {
|
||||||
|
verifyEvent(evt, 'loadstart');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('inappbrowser.spec.6 should support loaderror event', function (done) {
|
iabInstance = cordova.InAppBrowser.open(url, '_blank', platformOpts);
|
||||||
if (isBrowser) {
|
iabInstance.addEventListener('loadstart', onLoadStart);
|
||||||
// according to documentation, "loaderror" event is not supported on browser
|
iabInstance.addEventListener('loadstop', function (evt) {
|
||||||
|
verifyEvent(evt, 'loadstop');
|
||||||
|
if (!isBrowser) {
|
||||||
|
// according to documentation, "loadstart" event is not supported on browser
|
||||||
// https://github.com/apache/cordova-plugin-inappbrowser#browser-quirks-1
|
// https://github.com/apache/cordova-plugin-inappbrowser#browser-quirks-1
|
||||||
pending('Browser platform doesn\'t support loaderror event');
|
expect(onLoadStart).toHaveBeenCalled();
|
||||||
}
|
}
|
||||||
iabInstance = cordova.InAppBrowser.open(badUrl, '_blank', platformOpts);
|
done();
|
||||||
iabInstance.addEventListener('loaderror', function (evt) {
|
|
||||||
verifyLoadErrorEvent(evt);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
|
||||||
|
it('inappbrowser.spec.5 should support exit event', function (done) {
|
||||||
|
iabInstance = cordova.InAppBrowser.open(url, '_blank', platformOpts);
|
||||||
|
iabInstance.addEventListener('exit', function (evt) {
|
||||||
|
verifyEvent(evt, 'exit');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
iabInstance.close();
|
||||||
|
iabInstance = null;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('inappbrowser.spec.6 should support loaderror event', function (done) {
|
||||||
|
if (isBrowser) {
|
||||||
|
// according to documentation, "loaderror" event is not supported on browser
|
||||||
|
// https://github.com/apache/cordova-plugin-inappbrowser#browser-quirks-1
|
||||||
|
pending('Browser platform doesn\'t support loaderror event');
|
||||||
|
}
|
||||||
|
iabInstance = cordova.InAppBrowser.open(badUrl, '_blank', platformOpts);
|
||||||
|
iabInstance.addEventListener('loaderror', function (evt) {
|
||||||
|
verifyLoadErrorEvent(evt);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
if (isIos) {
|
if (isIos) {
|
||||||
createTests('usewkwebview=no');
|
createTests('usewkwebview=no');
|
||||||
createTests('usewkwebview=yes');
|
createTests('usewkwebview=yes');
|
||||||
@ -165,6 +163,15 @@ exports.defineAutoTests = function () {
|
|||||||
|
|
||||||
exports.defineManualTests = function (contentEl, createActionButton) {
|
exports.defineManualTests = function (contentEl, createActionButton) {
|
||||||
|
|
||||||
|
var platformOpts = '';
|
||||||
|
var platform_info = '';
|
||||||
|
if (isIos) {
|
||||||
|
platformOpts = 'usewkwebview=no';
|
||||||
|
platform_info = '<h1>Webview</h1>' +
|
||||||
|
'<p>Use this button to toggle the Webview implementation.</p>' +
|
||||||
|
'<div id="webviewToggle"></div>';
|
||||||
|
}
|
||||||
|
|
||||||
function doOpen (url, target, params, numExpectedRedirects, useWindowOpen) {
|
function doOpen (url, target, params, numExpectedRedirects, useWindowOpen) {
|
||||||
numExpectedRedirects = numExpectedRedirects || 0;
|
numExpectedRedirects = numExpectedRedirects || 0;
|
||||||
useWindowOpen = useWindowOpen || false;
|
useWindowOpen = useWindowOpen || false;
|
||||||
@ -173,7 +180,6 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
|||||||
var counts;
|
var counts;
|
||||||
var lastLoadStartURL;
|
var lastLoadStartURL;
|
||||||
var wasReset = false;
|
var wasReset = false;
|
||||||
|
|
||||||
function reset () {
|
function reset () {
|
||||||
counts = {
|
counts = {
|
||||||
'loaderror': 0,
|
'loaderror': 0,
|
||||||
@ -183,7 +189,6 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
|||||||
};
|
};
|
||||||
lastLoadStartURL = '';
|
lastLoadStartURL = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
|
|
||||||
var iab;
|
var iab;
|
||||||
@ -277,11 +282,11 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
|||||||
};
|
};
|
||||||
if (cssUrl) {
|
if (cssUrl) {
|
||||||
iab.addEventListener('loadstop', function (event) {
|
iab.addEventListener('loadstop', function (event) {
|
||||||
iab.insertCSS({file: cssUrl}, useCallback && callback);
|
iab.insertCSS({ file: cssUrl }, useCallback && callback);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
iab.addEventListener('loadstop', function (event) {
|
iab.addEventListener('loadstop', function (event) {
|
||||||
iab.insertCSS({code: '#style-update-literal { \ndisplay: block !important; \n}'},
|
iab.insertCSS({ code: '#style-update-literal { \ndisplay: block !important; \n}' },
|
||||||
useCallback && callback);
|
useCallback && callback);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -291,7 +296,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
|||||||
var iab = doOpen(url, '_blank', 'location=yes');
|
var iab = doOpen(url, '_blank', 'location=yes');
|
||||||
if (jsUrl) {
|
if (jsUrl) {
|
||||||
iab.addEventListener('loadstop', function (event) {
|
iab.addEventListener('loadstop', function (event) {
|
||||||
iab.executeScript({file: jsUrl}, useCallback && function (results) {
|
iab.executeScript({ file: jsUrl }, useCallback && function (results) {
|
||||||
if (results && results.length === 0) {
|
if (results && results.length === 0) {
|
||||||
alert('Results verified'); // eslint-disable-line no-undef
|
alert('Results verified'); // eslint-disable-line no-undef
|
||||||
} else {
|
} else {
|
||||||
@ -303,11 +308,11 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
|||||||
} else {
|
} else {
|
||||||
iab.addEventListener('loadstop', function (event) {
|
iab.addEventListener('loadstop', function (event) {
|
||||||
var code = '(function(){\n' +
|
var code = '(function(){\n' +
|
||||||
' var header = document.getElementById("header");\n' +
|
' var header = document.getElementById("header");\n' +
|
||||||
' header.innerHTML = "Script literal successfully injected";\n' +
|
' header.innerHTML = "Script literal successfully injected";\n' +
|
||||||
' return "abc";\n' +
|
' return "abc";\n' +
|
||||||
'})()';
|
'})()';
|
||||||
iab.executeScript({code: code}, useCallback && function (results) {
|
iab.executeScript({ code: code }, useCallback && function (results) {
|
||||||
if (results && results.length === 1 && results[0] === 'abc') {
|
if (results && results.length === 1 && results[0] === 'abc') {
|
||||||
alert('Results verified'); // eslint-disable-line no-undef
|
alert('Results verified'); // eslint-disable-line no-undef
|
||||||
} else {
|
} else {
|
||||||
@ -318,11 +323,8 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var hiddenwnd = null;
|
var hiddenwnd = null;
|
||||||
var loadlistener = function (event) {
|
var loadlistener = function (event) { alert('background window loaded '); }; // eslint-disable-line no-undef
|
||||||
alert('background window loaded ');
|
|
||||||
}; // eslint-disable-line no-undef
|
|
||||||
function openHidden (url, startHidden) {
|
function openHidden (url, startHidden) {
|
||||||
var shopt = (startHidden) ? 'hidden=yes' : '';
|
var shopt = (startHidden) ? 'hidden=yes' : '';
|
||||||
if (platformOpts) {
|
if (platformOpts) {
|
||||||
@ -335,13 +337,11 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
|||||||
}
|
}
|
||||||
if (startHidden) hiddenwnd.addEventListener('loadstop', loadlistener);
|
if (startHidden) hiddenwnd.addEventListener('loadstop', loadlistener);
|
||||||
}
|
}
|
||||||
|
|
||||||
function showHidden () {
|
function showHidden () {
|
||||||
if (hiddenwnd) {
|
if (hiddenwnd) {
|
||||||
hiddenwnd.show();
|
hiddenwnd.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeHidden () {
|
function closeHidden () {
|
||||||
if (hiddenwnd) {
|
if (hiddenwnd) {
|
||||||
hiddenwnd.removeEventListener('loadstop', loadlistener);
|
hiddenwnd.removeEventListener('loadstop', loadlistener);
|
||||||
@ -358,15 +358,6 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
|||||||
'<h4>User-Agent: <span id="user-agent"> </span></hr>' +
|
'<h4>User-Agent: <span id="user-agent"> </span></hr>' +
|
||||||
'</div>';
|
'</div>';
|
||||||
|
|
||||||
var platformOpts = '';
|
|
||||||
var platform_info = '';
|
|
||||||
if (isIos) {
|
|
||||||
platformOpts = 'usewkwebview=no';
|
|
||||||
platform_info = '<h1>Webview</h1>' +
|
|
||||||
'<p>Use this button to toggle the Webview implementation.</p>' +
|
|
||||||
'<div id="webviewToggle"></div>';
|
|
||||||
}
|
|
||||||
|
|
||||||
var local_tests = '<h1>Local URL</h1>' +
|
var local_tests = '<h1>Local URL</h1>' +
|
||||||
'<div id="openLocal"></div>' +
|
'<div id="openLocal"></div>' +
|
||||||
'Expected result: opens successfully in CordovaWebView.' +
|
'Expected result: opens successfully in CordovaWebView.' +
|
||||||
@ -523,13 +514,11 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
|||||||
var injectjs = isWindows ? basePath + 'inject.js' : 'inject.js';
|
var injectjs = isWindows ? basePath + 'inject.js' : 'inject.js';
|
||||||
var injectcss = isWindows ? basePath + 'inject.css' : 'inject.css';
|
var injectcss = isWindows ? basePath + 'inject.css' : 'inject.css';
|
||||||
var videohtml = basePath + 'video.html';
|
var videohtml = basePath + 'video.html';
|
||||||
|
|
||||||
if (isIos) {
|
if (isIos) {
|
||||||
createActionButton('Webview=UIWebView', function () {
|
createActionButton('Webview=UIWebView', function () {
|
||||||
var webviewOption = 'usewkwebview=';
|
var webviewOption = 'usewkwebview=';
|
||||||
var webviewToggle = document.getElementById('webviewToggle');
|
var webviewToggle = document.getElementById('webviewToggle');
|
||||||
var button = webviewToggle.getElementsByClassName('topcoat-button')[0];
|
var button = webviewToggle.getElementsByClassName('topcoat-button')[0];
|
||||||
|
|
||||||
if (platformOpts === webviewOption + 'yes') {
|
if (platformOpts === webviewOption + 'yes') {
|
||||||
platformOpts = webviewOption + 'no';
|
platformOpts = webviewOption + 'no';
|
||||||
button.textContent = 'Webview=UIWebView';
|
button.textContent = 'Webview=UIWebView';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user