refactor(eslint): use cordova-eslint /w fix (#747)

This commit is contained in:
Tim Brust 2020-07-02 15:41:21 +00:00 committed by GitHub
parent bdbb1df44c
commit 7c2810e885
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 621 additions and 314 deletions

View File

@ -1,10 +1,23 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
root: true root: true
extends: semistandard extends: '@cordova/eslint-config/browser'
rules:
indent: overrides:
- error - files: [tests/**/*.js]
- 4 extends: '@cordova/eslint-config/node-tests'
camelcase: off
padded-blocks: off
operator-linebreak: off
no-throw-literal: off

View File

@ -34,8 +34,8 @@
"cordova-windows" "cordova-windows"
], ],
"scripts": { "scripts": {
"test": "npm run eslint", "test": "npm run lint",
"eslint": "node node_modules/eslint/bin/eslint www && node node_modules/eslint/bin/eslint src && node node_modules/eslint/bin/eslint tests" "lint": "eslint ."
}, },
"engines": { "engines": {
"cordovaDependencies": { "cordovaDependencies": {
@ -54,12 +54,6 @@
"author": "Apache Software Foundation", "author": "Apache Software Foundation",
"license": "Apache-2.0", "license": "Apache-2.0",
"devDependencies": { "devDependencies": {
"eslint": "^4.0.0", "@cordova/eslint-config": "^3.0.0"
"eslint-config-semistandard": "^11.0.0",
"eslint-config-standard": "^10.2.1",
"eslint-plugin-import": "^2.3.0",
"eslint-plugin-node": "^5.0.0",
"eslint-plugin-promise": "^3.5.0",
"eslint-plugin-standard": "^3.0.1"
} }
} }

View File

@ -17,43 +17,37 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
* *
*/ */
var modulemapper = require('cordova/modulemapper'); var modulemapper = require('cordova/modulemapper');
var browserWrap, var browserWrap, popup, navigationButtonsDiv, navigationButtonsDivInner, backButton, forwardButton, closeButton;
popup,
navigationButtonsDiv,
navigationButtonsDivInner,
backButton,
forwardButton,
closeButton;
function attachNavigationEvents (element, callback) { function attachNavigationEvents (element, callback) {
var onError = function () { var onError = function () {
try { try {
callback({ type: 'loaderror', url: this.contentWindow.location.href }, {keepCallback: true}); // eslint-disable-line standard/no-callback-literal callback({ type: 'loaderror', url: this.contentWindow.location.href }, { keepCallback: true }); // eslint-disable-line standard/no-callback-literal
} catch (err) { } catch (err) {
// blocked by CORS :\ // blocked by CORS :\
callback({ type: 'loaderror', url: null }, {keepCallback: true}); // eslint-disable-line standard/no-callback-literal callback({ type: 'loaderror', url: null }, { keepCallback: true }); // eslint-disable-line standard/no-callback-literal
} }
}; };
element.addEventListener('pageshow', function () { element.addEventListener('pageshow', function () {
try { try {
callback({ type: 'loadstart', url: this.contentWindow.location.href }, {keepCallback: true}); // eslint-disable-line standard/no-callback-literal callback({ type: 'loadstart', url: this.contentWindow.location.href }, { keepCallback: true }); // eslint-disable-line standard/no-callback-literal
} catch (err) { } catch (err) {
// blocked by CORS :\ // blocked by CORS :\
callback({ type: 'loadstart', url: null }, {keepCallback: true}); // eslint-disable-line standard/no-callback-literal callback({ type: 'loadstart', url: null }, { keepCallback: true }); // eslint-disable-line standard/no-callback-literal
} }
}); });
element.addEventListener('load', function () { element.addEventListener('load', function () {
try { try {
callback({ type: 'loadstop', url: this.contentWindow.location.href }, {keepCallback: true}); // eslint-disable-line standard/no-callback-literal callback({ type: 'loadstop', url: this.contentWindow.location.href }, { keepCallback: true }); // eslint-disable-line standard/no-callback-literal
} catch (err) { } catch (err) {
// blocked by CORS :\ // blocked by CORS :\
callback({ type: 'loadstop', url: null }, {keepCallback: true}); // eslint-disable-line standard/no-callback-literal callback({ type: 'loadstop', url: null }, { keepCallback: true }); // eslint-disable-line standard/no-callback-literal
} }
}); });
@ -153,7 +147,9 @@ var IAB = {
backButton.innerHTML = '←'; backButton.innerHTML = '←';
backButton.addEventListener('click', function (e) { backButton.addEventListener('click', function (e) {
if (popup.canGoBack) { popup.goBack(); } if (popup.canGoBack) {
popup.goBack();
}
}); });
forwardButton = document.createElement('button'); forwardButton = document.createElement('button');
@ -164,7 +160,9 @@ var IAB = {
forwardButton.innerHTML = '→'; forwardButton.innerHTML = '→';
forwardButton.addEventListener('click', function (e) { forwardButton.addEventListener('click', function (e) {
if (popup.canGoForward) { popup.goForward(); } if (popup.canGoForward) {
popup.goForward();
}
}); });
closeButton = document.createElement('button'); closeButton = document.createElement('button');

View File

@ -17,11 +17,10 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
* *
*/ */
/* jslint sloppy:true */ /* eslint-disable standard/no-callback-literal */
/* global Windows:true, setImmediate */ /* global Windows, setImmediate */
/* eslint standard/no-callback-literal : 0 */
var cordova = require('cordova'); var cordova = require('cordova');
var urlutil = require('cordova/urlutil'); var urlutil = require('cordova/urlutil');
@ -44,21 +43,32 @@ var isWebViewAvailable = cordova.platformId === 'windows';
function attachNavigationEvents (element, callback) { function attachNavigationEvents (element, callback) {
if (isWebViewAvailable) { if (isWebViewAvailable) {
element.addEventListener('MSWebViewNavigationStarting', function (e) { element.addEventListener('MSWebViewNavigationStarting', function (e) {
callback({ type: 'loadstart', url: e.uri }, {keepCallback: true}); callback({ type: 'loadstart', url: e.uri }, { keepCallback: true });
}); });
element.addEventListener('MSWebViewNavigationCompleted', function (e) { element.addEventListener('MSWebViewNavigationCompleted', function (e) {
if (e.isSuccess) { if (e.isSuccess) {
callback({ type: 'loadstop', url: e.uri }, { keepCallback: true }); callback({ type: 'loadstop', url: e.uri }, { keepCallback: true });
} else { } else {
callback({ type: 'loaderror', url: e.uri, code: e.webErrorStatus, message: 'Navigation failed with error code ' + e.webErrorStatus }, { keepCallback: true }); callback(
{
type: 'loaderror',
url: e.uri,
code: e.webErrorStatus,
message: 'Navigation failed with error code ' + e.webErrorStatus
},
{ keepCallback: true }
);
} }
}); });
element.addEventListener('MSWebViewUnviewableContentIdentified', function (e) { element.addEventListener('MSWebViewUnviewableContentIdentified', function (e) {
// WebView found the content to be not HTML. // WebView found the content to be not HTML.
// http://msdn.microsoft.com/en-us/library/windows/apps/dn609716.aspx // http://msdn.microsoft.com/en-us/library/windows/apps/dn609716.aspx
callback({ type: 'loaderror', url: e.uri, code: e.webErrorStatus, message: 'Navigation failed with error code ' + e.webErrorStatus }, { keepCallback: true }); callback(
{ type: 'loaderror', url: e.uri, code: e.webErrorStatus, message: 'Navigation failed with error code ' + e.webErrorStatus },
{ keepCallback: true }
);
}); });
element.addEventListener('MSWebViewContentLoading', function (e) { element.addEventListener('MSWebViewContentLoading', function (e) {
@ -78,15 +88,15 @@ function attachNavigationEvents (element, callback) {
}); });
} else { } else {
var onError = function () { var onError = function () {
callback({ type: 'loaderror', url: this.contentWindow.location }, {keepCallback: true}); callback({ type: 'loaderror', url: this.contentWindow.location }, { keepCallback: true });
}; };
element.addEventListener('unload', function () { element.addEventListener('unload', function () {
callback({ type: 'loadstart', url: this.contentWindow.location }, {keepCallback: true}); callback({ type: 'loadstart', url: this.contentWindow.location }, { keepCallback: true });
}); });
element.addEventListener('load', function () { element.addEventListener('load', function () {
callback({ type: 'loadstop', url: this.contentWindow.location }, {keepCallback: true}); callback({ type: 'loadstop', url: this.contentWindow.location }, { keepCallback: true });
}); });
element.addEventListener('error', onError); element.addEventListener('error', onError);
@ -175,7 +185,8 @@ var IAB = {
} }
popup = document.createElement(isWebViewAvailable ? 'x-ms-webview' : 'iframe'); popup = document.createElement(isWebViewAvailable ? 'x-ms-webview' : 'iframe');
if (popup instanceof HTMLIFrameElement) { // eslint-disable-line no-undef if (popup instanceof HTMLIFrameElement) {
// eslint-disable-line no-undef
// For iframe we need to override bacground color of parent element here // For iframe we need to override bacground color of parent element here
// otherwise pages without background color set will have transparent background // otherwise pages without background color set will have transparent background
popup.style.backgroundColor = 'white'; popup.style.backgroundColor = 'white';
@ -240,14 +251,18 @@ var IAB = {
backButton.innerText = 'back'; backButton.innerText = 'back';
backButton.className = 'app-bar-action action-back'; backButton.className = 'app-bar-action action-back';
backButton.addEventListener('click', function (e) { backButton.addEventListener('click', function (e) {
if (popup.canGoBack) { popup.goBack(); } if (popup.canGoBack) {
popup.goBack();
}
}); });
forwardButton = document.createElement('div'); forwardButton = document.createElement('div');
forwardButton.innerText = 'forward'; forwardButton.innerText = 'forward';
forwardButton.className = 'app-bar-action action-forward'; forwardButton.className = 'app-bar-action action-forward';
forwardButton.addEventListener('click', function (e) { forwardButton.addEventListener('click', function (e) {
if (popup.canGoForward) { popup.goForward(); } if (popup.canGoForward) {
popup.goForward();
}
}); });
closeButton = document.createElement('div'); closeButton = document.createElement('div');
@ -292,11 +307,11 @@ var IAB = {
op.oncomplete = function (e) { op.oncomplete = function (e) {
if (hasCallback) { if (hasCallback) {
// return null if event target is unavailable by some reason // return null if event target is unavailable by some reason
var result = (e && e.target) ? [e.target.result] : [null]; var result = e && e.target ? [e.target.result] : [null];
win(result); win(result);
} }
}; };
op.onerror = function () { }; op.onerror = function () {};
op.start(); op.start();
} }
}); });
@ -323,7 +338,7 @@ var IAB = {
win(result); win(result);
} }
}; };
op.onerror = function () { }; op.onerror = function () {};
op.start(); op.start();
}); });
}); });
@ -352,13 +367,18 @@ var IAB = {
if (isWebViewAvailable && browserWrap && popup) { if (isWebViewAvailable && browserWrap && popup) {
// CB-12364 getFileFromApplicationUriAsync does not support ms-appx-web // CB-12364 getFileFromApplicationUriAsync does not support ms-appx-web
var uri = new Windows.Foundation.Uri(filePath.replace('ms-appx-web:', 'ms-appx:')); var uri = new Windows.Foundation.Uri(filePath.replace('ms-appx-web:', 'ms-appx:'));
Windows.Storage.StorageFile.getFileFromApplicationUriAsync(uri).then(function (file) { Windows.Storage.StorageFile.getFileFromApplicationUriAsync(uri)
return Windows.Storage.FileIO.readTextAsync(file); .then(function (file) {
}).done(function (code) { return Windows.Storage.FileIO.readTextAsync(file);
injectCSS(popup, code, hasCallback && win); })
}, function () { .done(
// no-op, just catch an error function (code) {
}); injectCSS(popup, code, hasCallback && win);
},
function () {
// no-op, just catch an error
}
);
} }
}); });
} }
@ -367,8 +387,10 @@ var IAB = {
function injectCSS (webView, cssCode, callback) { function injectCSS (webView, cssCode, callback) {
// This will automatically escape all thing that we need (quotes, slashes, etc.) // This will automatically escape all thing that we need (quotes, slashes, etc.)
var escapedCode = JSON.stringify(cssCode); var escapedCode = JSON.stringify(cssCode);
var evalWrapper = '(function(d){var c=d.createElement(\'style\');c.innerHTML=%s;d.head.appendChild(c);})(document)' var evalWrapper = "(function(d){var c=d.createElement('style');c.innerHTML=%s;d.head.appendChild(c);})(document)".replace(
.replace('%s', escapedCode); '%s',
escapedCode
);
var op = webView.invokeScriptAsync('eval', evalWrapper); var op = webView.invokeScriptAsync('eval', evalWrapper);
op.oncomplete = function () { op.oncomplete = function () {
@ -376,7 +398,7 @@ function injectCSS (webView, cssCode, callback) {
callback([]); callback([]);
} }
}; };
op.onerror = function () { }; op.onerror = function () {};
op.start(); op.start();
} }

View File

@ -15,6 +15,7 @@
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
var d = document.getElementById('header'); var d = document.getElementById('header');
d.innerHTML = 'Script file successfully injected'; d.innerHTML = 'Script file successfully injected';

View File

@ -17,7 +17,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
* *
*/ */
/* global MSApp */ /* global MSApp */
@ -38,7 +38,6 @@ exports.defineAutoTests = function () {
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();
}); });
@ -50,7 +49,6 @@ exports.defineAutoTests = function () {
}); });
describe('open method', function () { describe('open method', function () {
if (cordova.platformId === 'osx') { if (cordova.platformId === 'osx') {
pending('Open method not fully supported on OSX.'); pending('Open method not fully supported on OSX.');
return; return;
@ -62,7 +60,7 @@ exports.defineAutoTests = function () {
var badUrl = 'http://bad-uri/'; var badUrl = 'http://bad-uri/';
beforeEach(function () { beforeEach(function () {
// increase timeout to ensure test url could be loaded within test time // increase timeout to ensure test url could be loaded within test time
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000; jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
@ -70,7 +68,7 @@ exports.defineAutoTests = function () {
}); });
afterEach(function (done) { afterEach(function (done) {
// restore original timeout // restore original timeout
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
if (iabInstance !== null && iabInstance.close) { if (iabInstance !== null && iabInstance.close) {
@ -122,8 +120,8 @@ exports.defineAutoTests = function () {
iabInstance.addEventListener('loadstop', function (evt) { iabInstance.addEventListener('loadstop', function (evt) {
verifyEvent(evt, 'loadstop'); verifyEvent(evt, 'loadstop');
if (!isBrowser) { if (!isBrowser) {
// according to documentation, "loadstart" event is not supported on browser // 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
expect(onLoadStart).toHaveBeenCalled(); expect(onLoadStart).toHaveBeenCalled();
} }
done(); done();
@ -144,9 +142,9 @@ exports.defineAutoTests = function () {
it('inappbrowser.spec.6 should support loaderror event', function (done) { it('inappbrowser.spec.6 should support loaderror event', function (done) {
if (isBrowser) { if (isBrowser) {
// according to documentation, "loaderror" event is not supported on browser // according to documentation, "loaderror" 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'); pending("Browser platform doesn't support loaderror event");
} }
iabInstance = cordova.InAppBrowser.open(badUrl, '_blank', platformOpts); iabInstance = cordova.InAppBrowser.open(badUrl, '_blank', platformOpts);
iabInstance.addEventListener('loaderror', function (evt) { iabInstance.addEventListener('loaderror', function (evt) {
@ -157,7 +155,7 @@ exports.defineAutoTests = function () {
it('inappbrowser.spec.7 should support message event', function (done) { it('inappbrowser.spec.7 should support message event', function (done) {
if (!isAndroid && !isIos) { if (!isAndroid && !isIos) {
return pending(cordova.platformId + ' platform doesn\'t support message event'); return pending(cordova.platformId + " platform doesn't support message event");
} }
var messageKey = 'my_message'; var messageKey = 'my_message';
var messageValue = 'is_this'; var messageValue = 'is_this';
@ -172,13 +170,17 @@ exports.defineAutoTests = function () {
done(); done();
}); });
iabInstance.addEventListener('loadstop', function (evt) { iabInstance.addEventListener('loadstop', function (evt) {
var code = '(function(){\n' + var code =
' var message = {' + messageKey + ': "' + messageValue + '"};\n' + '(function(){\n' +
' var message = {' +
messageKey +
': "' +
messageValue +
'"};\n' +
' webkit.messageHandlers.cordova_iab.postMessage(JSON.stringify(message));\n' + ' webkit.messageHandlers.cordova_iab.postMessage(JSON.stringify(message));\n' +
'})()'; '})()';
iabInstance.executeScript({ code: code }); iabInstance.executeScript({ code: code });
}); });
}); });
}); });
}; };
@ -186,7 +188,6 @@ exports.defineAutoTests = function () {
}; };
exports.defineManualTests = function (contentEl, createActionButton) { exports.defineManualTests = function (contentEl, createActionButton) {
var platformOpts = ''; var platformOpts = '';
var platform_info = ''; var platform_info = '';
@ -200,10 +201,10 @@ exports.defineManualTests = function (contentEl, createActionButton) {
var wasReset = false; var wasReset = false;
function reset () { function reset () {
counts = { counts = {
'loaderror': 0, loaderror: 0,
'loadstart': 0, loadstart: 0,
'loadstop': 0, loadstop: 0,
'exit': 0 exit: 0
}; };
lastLoadStartURL = ''; lastLoadStartURL = '';
} }
@ -243,15 +244,20 @@ exports.defineManualTests = function (contentEl, createActionButton) {
// Verify the right number of loadstart events were fired. // Verify the right number of loadstart events were fired.
if (e.type === 'loadstop' || e.type === 'loaderror') { if (e.type === 'loadstop' || e.type === 'loaderror') {
if (e.url !== lastLoadStartURL) { if (e.url !== lastLoadStartURL) {
alert('Unexpected: ' + e.type + ' event.url != loadstart\'s event.url'); // eslint-disable-line no-undef alert('Unexpected: ' + e.type + " event.url != loadstart's event.url"); // eslint-disable-line no-undef
} }
if (numExpectedRedirects === 0 && counts.loadstart !== 1) { if (numExpectedRedirects === 0 && counts.loadstart !== 1) {
// Do allow a loaderror without a loadstart (e.g. in the case of an invalid URL). // Do allow a loaderror without a loadstart (e.g. in the case of an invalid URL).
if (!(e.type === 'loaderror' && counts.loadstart === 0)) { if (!(e.type === 'loaderror' && counts.loadstart === 0)) {
alert('Unexpected: got multiple loadstart events. (' + counts.loadstart + ')'); // eslint-disable-line no-undef alert('Unexpected: got multiple loadstart events. (' + counts.loadstart + ')'); // eslint-disable-line no-undef
} }
} else if (numExpectedRedirects > 0 && counts.loadstart < (numExpectedRedirects + 1)) { } else if (numExpectedRedirects > 0 && counts.loadstart < numExpectedRedirects + 1) {
alert('Unexpected: should have got at least ' + (numExpectedRedirects + 1) + ' loadstart events, but got ' + counts.loadstart); // eslint-disable-line no-undef alert(
'Unexpected: should have got at least ' +
(numExpectedRedirects + 1) +
' loadstart events, but got ' +
counts.loadstart
); // eslint-disable-line no-undef
} }
wasReset = true; wasReset = true;
numExpectedRedirects = 0; numExpectedRedirects = 0;
@ -273,7 +279,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
function doHookOpen (url, target, params, numExpectedRedirects) { function doHookOpen (url, target, params, numExpectedRedirects) {
var originalFunc = window.open; var originalFunc = window.open;
var wasClobbered = window.hasOwnProperty('open'); var wasClobbered = Object.prototype.hasOwnProperty.call(window, 'open');
window.open = cordova.InAppBrowser.open; window.open = cordova.InAppBrowser.open;
try { try {
@ -295,7 +301,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
alert('Results verified'); // eslint-disable-line no-undef alert('Results verified'); // eslint-disable-line no-undef
} else { } else {
console.log(results); console.log(results);
alert('Got: ' + typeof (results) + '\n' + JSON.stringify(results)); // eslint-disable-line no-undef alert('Got: ' + typeof results + '\n' + JSON.stringify(results)); // eslint-disable-line no-undef
} }
}; };
if (cssUrl) { if (cssUrl) {
@ -304,8 +310,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
}); });
} 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);
}); });
} }
} }
@ -314,37 +319,48 @@ 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(
if (results && results.length === 0) { { file: jsUrl },
alert('Results verified'); // eslint-disable-line no-undef useCallback &&
} else { function (results) {
console.log(results); if (results && results.length === 0) {
alert('Got: ' + typeof (results) + '\n' + JSON.stringify(results)); // eslint-disable-line no-undef alert('Results verified'); // eslint-disable-line no-undef
} } else {
}); console.log(results);
alert('Got: ' + typeof results + '\n' + JSON.stringify(results)); // eslint-disable-line no-undef
}
}
);
}); });
} else { } else {
iab.addEventListener('loadstop', function (event) { iab.addEventListener('loadstop', function (event) {
var code = '(function(){\n' + var code =
' var header = document.getElementById("header");\n' + '(function(){\n' +
' header.innerHTML = "Script literal successfully injected";\n' + ' var header = document.getElementById("header");\n' +
' return "abc";\n' + ' header.innerHTML = "Script literal successfully injected";\n' +
'})()'; ' return "abc";\n' +
iab.executeScript({ code: code }, useCallback && function (results) { '})()';
if (results && results.length === 1 && results[0] === 'abc') { iab.executeScript(
alert('Results verified'); // eslint-disable-line no-undef { code: code },
} else { useCallback &&
console.log(results); function (results) {
alert('Got: ' + typeof (results) + '\n' + JSON.stringify(results)); // eslint-disable-line no-undef if (results && results.length === 1 && results[0] === 'abc') {
} alert('Results verified'); // eslint-disable-line no-undef
}); } else {
console.log(results);
alert('Got: ' + typeof results + '\n' + JSON.stringify(results)); // eslint-disable-line no-undef
}
}
);
}); });
} }
} }
var hiddenwnd = null; var hiddenwnd = null;
var loadlistener = function (event) { alert('background window loaded '); }; // eslint-disable-line no-undef var loadlistener = function (event) {
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) {
shopt += (shopt ? ',' : '') + platformOpts; shopt += (shopt ? ',' : '') + platformOpts;
} }
@ -368,7 +384,8 @@ exports.defineManualTests = function (contentEl, createActionButton) {
} }
} }
var info_div = '<h1>InAppBrowser</h1>' + var info_div =
'<h1>InAppBrowser</h1>' +
'<div id="info">' + '<div id="info">' +
'Make sure http://cordova.apache.org and http://google.co.uk and https://www.google.co.uk are white listed. </br>' + 'Make sure http://cordova.apache.org and http://google.co.uk and https://www.google.co.uk are white listed. </br>' +
'Make sure http://www.apple.com is not in the white list.</br>' + 'Make sure http://www.apple.com is not in the white list.</br>' +
@ -376,7 +393,8 @@ 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 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.' +
'<p/> <div id="openLocalHook"></div>' + '<p/> <div id="openLocalHook"></div>' +
@ -396,7 +414,8 @@ exports.defineManualTests = function (contentEl, createActionButton) {
'<p/><div id="openLocalRandomToolBarTopNoLocation"></div>' + '<p/><div id="openLocalRandomToolBarTopNoLocation"></div>' +
'Expected result: open successfully in InAppBrowser with no locationBar. On iOS the toolbar is at the top.'; 'Expected result: open successfully in InAppBrowser with no locationBar. On iOS the toolbar is at the top.';
var white_listed_tests = '<h1>White Listed URL</h1>' + var white_listed_tests =
'<h1>White Listed URL</h1>' +
'<div id="openWhiteListed"></div>' + '<div id="openWhiteListed"></div>' +
'Expected result: open successfully in CordovaWebView to cordova.apache.org' + 'Expected result: open successfully in CordovaWebView to cordova.apache.org' +
'<p/> <div id="openWhiteListedHook"></div>' + '<p/> <div id="openWhiteListedHook"></div>' +
@ -412,7 +431,8 @@ exports.defineManualTests = function (contentEl, createActionButton) {
'<p/> <div id="openWhiteListedRandomNoLocation"></div>' + '<p/> <div id="openWhiteListedRandomNoLocation"></div>' +
'Expected result: open successfully in InAppBrowser to cordova.apache.org with no location bar.'; 'Expected result: open successfully in InAppBrowser to cordova.apache.org with no location bar.';
var non_white_listed_tests = '<h1>Non White Listed URL</h1>' + var non_white_listed_tests =
'<h1>Non White Listed URL</h1>' +
'<div id="openNonWhiteListed"></div>' + '<div id="openNonWhiteListed"></div>' +
'Expected result: open successfully in InAppBrowser to apple.com.' + 'Expected result: open successfully in InAppBrowser to apple.com.' +
'<p/> <div id="openNonWhiteListedHook"></div>' + '<p/> <div id="openNonWhiteListedHook"></div>' +
@ -428,19 +448,22 @@ exports.defineManualTests = function (contentEl, createActionButton) {
'<p/> <div id="openNonWhiteListedRandomNoLocation"></div>' + '<p/> <div id="openNonWhiteListedRandomNoLocation"></div>' +
'Expected result: open successfully in InAppBrowser to apple.com without locationBar.'; 'Expected result: open successfully in InAppBrowser to apple.com without locationBar.';
var page_with_redirects_tests = '<h1>Page with redirect</h1>' + var page_with_redirects_tests =
'<h1>Page with redirect</h1>' +
'<div id="openRedirect301"></div>' + '<div id="openRedirect301"></div>' +
'Expected result: should 301 and open successfully in InAppBrowser to https://www.google.co.uk.' + 'Expected result: should 301 and open successfully in InAppBrowser to https://www.google.co.uk.' +
'<p/> <div id="openRedirect302"></div>' + '<p/> <div id="openRedirect302"></div>' +
'Expected result: should 302 and open successfully in InAppBrowser to www.zhihu.com/answer/16714076.'; 'Expected result: should 302 and open successfully in InAppBrowser to www.zhihu.com/answer/16714076.';
var pdf_url_tests = '<h1>PDF URL</h1>' + var pdf_url_tests =
'<h1>PDF URL</h1>' +
'<div id="openPDF"></div>' + '<div id="openPDF"></div>' +
'Expected result: InAppBrowser opens. PDF should render on iOS.' + 'Expected result: InAppBrowser opens. PDF should render on iOS.' +
'<p/> <div id="openPDFBlank"></div>' + '<p/> <div id="openPDFBlank"></div>' +
'Expected result: InAppBrowser opens. PDF should render on iOS.'; 'Expected result: InAppBrowser opens. PDF should render on iOS.';
var invalid_url_tests = '<h1>Invalid URL</h1>' + var invalid_url_tests =
'<h1>Invalid URL</h1>' +
'<div id="openInvalidScheme"></div>' + '<div id="openInvalidScheme"></div>' +
'Expected result: fail to load in InAppBrowser.' + 'Expected result: fail to load in InAppBrowser.' +
'<p/> <div id="openInvalidHost"></div>' + '<p/> <div id="openInvalidHost"></div>' +
@ -448,7 +471,8 @@ exports.defineManualTests = function (contentEl, createActionButton) {
'<p/> <div id="openInvalidMissing"></div>' + '<p/> <div id="openInvalidMissing"></div>' +
'Expected result: fail to load in InAppBrowser (404).'; 'Expected result: fail to load in InAppBrowser (404).';
var css_js_injection_tests = '<h1>CSS / JS Injection</h1>' + var css_js_injection_tests =
'<h1>CSS / JS Injection</h1>' +
'<div id="openOriginalDocument"></div>' + '<div id="openOriginalDocument"></div>' +
'Expected result: open successfully in InAppBrowser without text "Style updated from..."' + 'Expected result: open successfully in InAppBrowser without text "Style updated from..."' +
'<p/> <div id="openCSSInjection"></div>' + '<p/> <div id="openCSSInjection"></div>' +
@ -468,7 +492,8 @@ exports.defineManualTests = function (contentEl, createActionButton) {
'<p/> <div id="openScriptLiteralInjectionCallback"></div>' + '<p/> <div id="openScriptLiteralInjectionCallback"></div>' +
'Expected result: open successfully in InAppBrowser with the text "Script literal successfully injected" and alert dialog with the text "Results verified".'; 'Expected result: open successfully in InAppBrowser with the text "Script literal successfully injected" and alert dialog with the text "Results verified".';
var open_hidden_tests = '<h1>Open Hidden </h1>' + var open_hidden_tests =
'<h1>Open Hidden </h1>' +
'<div id="openHidden"></div>' + '<div id="openHidden"></div>' +
'Expected result: no additional browser window. Alert appears with the text "background window loaded".' + 'Expected result: no additional browser window. Alert appears with the text "background window loaded".' +
'<p/> <div id="showHidden"></div>' + '<p/> <div id="showHidden"></div>' +
@ -480,13 +505,15 @@ exports.defineManualTests = function (contentEl, createActionButton) {
'<p/> <div id="openVisibleAndHide"></div>' + '<p/> <div id="openVisibleAndHide"></div>' +
'Expected result: open successfully in InAppBrowser to https://www.google.co.uk. Hide after 2 seconds'; 'Expected result: open successfully in InAppBrowser to https://www.google.co.uk. Hide after 2 seconds';
var clearing_cache_tests = '<h1>Clearing Cache</h1>' + var clearing_cache_tests =
'<h1>Clearing Cache</h1>' +
'<div id="openClearCache"></div>' + '<div id="openClearCache"></div>' +
'Expected result: ?' + 'Expected result: ?' +
'<p/> <div id="openClearSessionCache"></div>' + '<p/> <div id="openClearSessionCache"></div>' +
'Expected result: ?'; 'Expected result: ?';
var video_tag_tests = '<h1>Video tag</h1>' + var video_tag_tests =
'<h1>Video tag</h1>' +
'<div id="openRemoteVideo"></div>' + '<div id="openRemoteVideo"></div>' +
'Expected result: open successfully in InAppBrowser with an embedded video plays automatically on iOS and Android.' + 'Expected result: open successfully in InAppBrowser with an embedded video plays automatically on iOS and Android.' +
'<div id="openRemoteNeedUserNoVideo"></div>' + '<div id="openRemoteNeedUserNoVideo"></div>' +
@ -494,13 +521,15 @@ exports.defineManualTests = function (contentEl, createActionButton) {
'<div id="openRemoteNeedUserYesVideo"></div>' + '<div id="openRemoteNeedUserYesVideo"></div>' +
'Expected result: open successfully in InAppBrowser with an embedded video does not play automatically on iOS and Android but rather works after clicking the "play" button.'; 'Expected result: open successfully in InAppBrowser with an embedded video does not play automatically on iOS and Android but rather works after clicking the "play" button.';
var local_with_anchor_tag_tests = '<h1>Local with anchor tag</h1>' + var local_with_anchor_tag_tests =
'<h1>Local with anchor tag</h1>' +
'<div id="openAnchor1"></div>' + '<div id="openAnchor1"></div>' +
'Expected result: open successfully in InAppBrowser to the local page, scrolled to the top as normal.' + 'Expected result: open successfully in InAppBrowser to the local page, scrolled to the top as normal.' +
'<p/> <div id="openAnchor2"></div>' + '<p/> <div id="openAnchor2"></div>' +
'Expected result: open successfully in InAppBrowser to the local page, scrolled to the beginning of the tall div with border.'; 'Expected result: open successfully in InAppBrowser to the local page, scrolled to the beginning of the tall div with border.';
var hardwareback_tests = '<h1>HardwareBack</h1>' + var hardwareback_tests =
'<h1>HardwareBack</h1>' +
'<p/> <div id="openHardwareBackDefault"></div>' + '<p/> <div id="openHardwareBackDefault"></div>' +
'Expected result: By default hardwareback is yes so pressing back button should navigate backwards in history then close InAppBrowser' + 'Expected result: By default hardwareback is yes so pressing back button should navigate backwards in history then close InAppBrowser' +
'<p/> <div id="openHardwareBackYes"></div>' + '<p/> <div id="openHardwareBackYes"></div>' +
@ -514,12 +543,38 @@ exports.defineManualTests = function (contentEl, createActionButton) {
// see http://msdn.microsoft.com/en-us/library/windows/apps/hh465380.aspx#differences for details // see http://msdn.microsoft.com/en-us/library/windows/apps/hh465380.aspx#differences for details
if (window.MSApp && window.MSApp.execUnsafeLocalFunction) { if (window.MSApp && window.MSApp.execUnsafeLocalFunction) {
MSApp.execUnsafeLocalFunction(function () { MSApp.execUnsafeLocalFunction(function () {
contentEl.innerHTML = info_div + platform_info + local_tests + white_listed_tests + non_white_listed_tests + page_with_redirects_tests + pdf_url_tests + invalid_url_tests + contentEl.innerHTML =
css_js_injection_tests + open_hidden_tests + clearing_cache_tests + video_tag_tests + local_with_anchor_tag_tests + hardwareback_tests; info_div +
platform_info +
local_tests +
white_listed_tests +
non_white_listed_tests +
page_with_redirects_tests +
pdf_url_tests +
invalid_url_tests +
css_js_injection_tests +
open_hidden_tests +
clearing_cache_tests +
video_tag_tests +
local_with_anchor_tag_tests +
hardwareback_tests;
}); });
} else { } else {
contentEl.innerHTML = info_div + platform_info + local_tests + white_listed_tests + non_white_listed_tests + page_with_redirects_tests + pdf_url_tests + invalid_url_tests + contentEl.innerHTML =
css_js_injection_tests + open_hidden_tests + clearing_cache_tests + video_tag_tests + local_with_anchor_tag_tests + hardwareback_tests; info_div +
platform_info +
local_tests +
white_listed_tests +
non_white_listed_tests +
page_with_redirects_tests +
pdf_url_tests +
invalid_url_tests +
css_js_injection_tests +
open_hidden_tests +
clearing_cache_tests +
video_tag_tests +
local_with_anchor_tag_tests +
hardwareback_tests;
} }
document.getElementById('user-agent').textContent = navigator.userAgent; document.getElementById('user-agent').textContent = navigator.userAgent;
@ -534,206 +589,430 @@ exports.defineManualTests = function (contentEl, createActionButton) {
var videohtml = basePath + 'video.html'; var videohtml = basePath + 'video.html';
// Local // Local
createActionButton('target=Default', function () { createActionButton(
doOpen(localhtml); 'target=Default',
}, 'openLocal'); function () {
createActionButton('target=Default (window.open)', function () { doOpen(localhtml);
doHookOpen(localhtml); },
}, 'openLocalHook'); 'openLocal'
createActionButton('target=_self', function () { );
doOpen(localhtml, '_self'); createActionButton(
}, 'openLocalSelf'); 'target=Default (window.open)',
createActionButton('target=_system', function () { function () {
doOpen(localhtml, '_system'); doHookOpen(localhtml);
}, 'openLocalSystem'); },
createActionButton('target=_blank', function () { 'openLocalHook'
doOpen(localhtml, '_blank'); );
}, 'openLocalBlank'); createActionButton(
createActionButton('target=Random, location=no, disallowoverscroll=yes', function () { 'target=_self',
doOpen(localhtml, 'random_string', 'location=no, disallowoverscroll=yes'); function () {
}, 'openLocalRandomNoLocation'); doOpen(localhtml, '_self');
createActionButton('target=Random, toolbarposition=bottom', function () { },
doOpen(localhtml, 'random_string', 'toolbarposition=bottom'); 'openLocalSelf'
}, 'openLocalRandomToolBarBottom'); );
createActionButton('target=Random, toolbarposition=top', function () { createActionButton(
doOpen(localhtml, 'random_string', 'toolbarposition=top'); 'target=_system',
}, 'openLocalRandomToolBarTop'); function () {
createActionButton('target=Random, toolbarposition=top, location=no', function () { doOpen(localhtml, '_system');
doOpen(localhtml, 'random_string', 'toolbarposition=top,location=no'); },
}, 'openLocalRandomToolBarTopNoLocation'); 'openLocalSystem'
);
createActionButton(
'target=_blank',
function () {
doOpen(localhtml, '_blank');
},
'openLocalBlank'
);
createActionButton(
'target=Random, location=no, disallowoverscroll=yes',
function () {
doOpen(localhtml, 'random_string', 'location=no, disallowoverscroll=yes');
},
'openLocalRandomNoLocation'
);
createActionButton(
'target=Random, toolbarposition=bottom',
function () {
doOpen(localhtml, 'random_string', 'toolbarposition=bottom');
},
'openLocalRandomToolBarBottom'
);
createActionButton(
'target=Random, toolbarposition=top',
function () {
doOpen(localhtml, 'random_string', 'toolbarposition=top');
},
'openLocalRandomToolBarTop'
);
createActionButton(
'target=Random, toolbarposition=top, location=no',
function () {
doOpen(localhtml, 'random_string', 'toolbarposition=top,location=no');
},
'openLocalRandomToolBarTopNoLocation'
);
// White Listed // White Listed
createActionButton('* target=Default', function () { createActionButton(
doOpen('http://cordova.apache.org'); '* target=Default',
}, 'openWhiteListed'); function () {
createActionButton('* target=Default (window.open)', function () { doOpen('http://cordova.apache.org');
doHookOpen('http://cordova.apache.org'); },
}, 'openWhiteListedHook'); 'openWhiteListed'
createActionButton('* target=_self', function () { );
doOpen('http://cordova.apache.org', '_self'); createActionButton(
}, 'openWhiteListedSelf'); '* target=Default (window.open)',
createActionButton('target=_system', function () { function () {
doOpen('http://cordova.apache.org', '_system'); doHookOpen('http://cordova.apache.org');
}, 'openWhiteListedSystem'); },
createActionButton('target=_blank', function () { 'openWhiteListedHook'
doOpen('http://cordova.apache.org', '_blank'); );
}, 'openWhiteListedBlank'); createActionButton(
createActionButton('target=Random', function () { '* target=_self',
doOpen('http://cordova.apache.org', 'random_string'); function () {
}, 'openWhiteListedRandom'); doOpen('http://cordova.apache.org', '_self');
createActionButton('* target=Random, no location bar', function () { },
doOpen('http://cordova.apache.org', 'random_string', 'location=no'); 'openWhiteListedSelf'
}, 'openWhiteListedRandomNoLocation'); );
createActionButton(
'target=_system',
function () {
doOpen('http://cordova.apache.org', '_system');
},
'openWhiteListedSystem'
);
createActionButton(
'target=_blank',
function () {
doOpen('http://cordova.apache.org', '_blank');
},
'openWhiteListedBlank'
);
createActionButton(
'target=Random',
function () {
doOpen('http://cordova.apache.org', 'random_string');
},
'openWhiteListedRandom'
);
createActionButton(
'* target=Random, no location bar',
function () {
doOpen('http://cordova.apache.org', 'random_string', 'location=no');
},
'openWhiteListedRandomNoLocation'
);
// Non White Listed // Non White Listed
createActionButton('target=Default', function () { createActionButton(
doOpen('http://www.apple.com'); 'target=Default',
}, 'openNonWhiteListed'); function () {
createActionButton('target=Default (window.open)', function () { doOpen('http://www.apple.com');
doHookOpen('http://www.apple.com'); },
}, 'openNonWhiteListedHook'); 'openNonWhiteListed'
createActionButton('target=_self', function () { );
doOpen('http://www.apple.com', '_self'); createActionButton(
}, 'openNonWhiteListedSelf'); 'target=Default (window.open)',
createActionButton('target=_system', function () { function () {
doOpen('http://www.apple.com', '_system'); doHookOpen('http://www.apple.com');
}, 'openNonWhiteListedSystem'); },
createActionButton('target=_blank', function () { 'openNonWhiteListedHook'
doOpen('http://www.apple.com', '_blank'); );
}, 'openNonWhiteListedBlank'); createActionButton(
createActionButton('target=Random', function () { 'target=_self',
doOpen('http://www.apple.com', 'random_string'); function () {
}, 'openNonWhiteListedRandom'); doOpen('http://www.apple.com', '_self');
createActionButton('* target=Random, no location bar', function () { },
doOpen('http://www.apple.com', 'random_string', 'location=no'); 'openNonWhiteListedSelf'
}, 'openNonWhiteListedRandomNoLocation'); );
createActionButton(
'target=_system',
function () {
doOpen('http://www.apple.com', '_system');
},
'openNonWhiteListedSystem'
);
createActionButton(
'target=_blank',
function () {
doOpen('http://www.apple.com', '_blank');
},
'openNonWhiteListedBlank'
);
createActionButton(
'target=Random',
function () {
doOpen('http://www.apple.com', 'random_string');
},
'openNonWhiteListedRandom'
);
createActionButton(
'* target=Random, no location bar',
function () {
doOpen('http://www.apple.com', 'random_string', 'location=no');
},
'openNonWhiteListedRandomNoLocation'
);
// Page with redirect // Page with redirect
createActionButton('http://google.co.uk', function () { createActionButton(
doOpen('http://google.co.uk', 'random_string', '', 1); 'http://google.co.uk',
}, 'openRedirect301'); function () {
createActionButton('http://goo.gl/pUFqg', function () { doOpen('http://google.co.uk', 'random_string', '', 1);
doOpen('http://goo.gl/pUFqg', 'random_string', '', 2); },
}, 'openRedirect302'); 'openRedirect301'
);
createActionButton(
'http://goo.gl/pUFqg',
function () {
doOpen('http://goo.gl/pUFqg', 'random_string', '', 2);
},
'openRedirect302'
);
// PDF URL // PDF URL
createActionButton('Remote URL', function () { createActionButton(
doOpen('http://www.stluciadance.com/prospectus_file/sample.pdf'); 'Remote URL',
}, 'openPDF'); function () {
createActionButton('Local URL', function () { doOpen('http://www.stluciadance.com/prospectus_file/sample.pdf');
doOpen(localpdf, '_blank'); },
}, 'openPDFBlank'); 'openPDF'
);
createActionButton(
'Local URL',
function () {
doOpen(localpdf, '_blank');
},
'openPDFBlank'
);
// Invalid URL // Invalid URL
createActionButton('Invalid Scheme', function () { createActionButton(
doOpen('x-ttp://www.invalid.com/', '_blank'); 'Invalid Scheme',
}, 'openInvalidScheme'); function () {
createActionButton('Invalid Host', function () { doOpen('x-ttp://www.invalid.com/', '_blank');
doOpen('http://www.inv;alid.com/', '_blank'); },
}, 'openInvalidHost'); 'openInvalidScheme'
createActionButton('Missing Local File', function () { );
doOpen('nonexistent.html', '_blank'); createActionButton(
}, 'openInvalidMissing'); 'Invalid Host',
function () {
doOpen('http://www.inv;alid.com/', '_blank');
},
'openInvalidHost'
);
createActionButton(
'Missing Local File',
function () {
doOpen('nonexistent.html', '_blank');
},
'openInvalidMissing'
);
// CSS / JS injection // CSS / JS injection
createActionButton('Original Document', function () { createActionButton(
doOpen(injecthtml, '_blank'); 'Original Document',
}, 'openOriginalDocument'); function () {
createActionButton('CSS File Injection', function () { doOpen(injecthtml, '_blank');
openWithStyle(injecthtml, injectcss); },
}, 'openCSSInjection'); 'openOriginalDocument'
createActionButton('CSS File Injection (callback)', function () { );
openWithStyle(injecthtml, injectcss, true); createActionButton(
}, 'openCSSInjectionCallback'); 'CSS File Injection',
createActionButton('CSS Literal Injection', function () { function () {
openWithStyle(injecthtml); openWithStyle(injecthtml, injectcss);
}, 'openCSSLiteralInjection'); },
createActionButton('CSS Literal Injection (callback)', function () { 'openCSSInjection'
openWithStyle(injecthtml, null, true); );
}, 'openCSSLiteralInjectionCallback'); createActionButton(
createActionButton('Script File Injection', function () { 'CSS File Injection (callback)',
openWithScript(injecthtml, injectjs); function () {
}, 'openScriptInjection'); openWithStyle(injecthtml, injectcss, true);
createActionButton('Script File Injection (callback)', function () { },
openWithScript(injecthtml, injectjs, true); 'openCSSInjectionCallback'
}, 'openScriptInjectionCallback'); );
createActionButton('Script Literal Injection', function () { createActionButton(
openWithScript(injecthtml); 'CSS Literal Injection',
}, 'openScriptLiteralInjection'); function () {
createActionButton('Script Literal Injection (callback)', function () { openWithStyle(injecthtml);
openWithScript(injecthtml, null, true); },
}, 'openScriptLiteralInjectionCallback'); 'openCSSLiteralInjection'
);
createActionButton(
'CSS Literal Injection (callback)',
function () {
openWithStyle(injecthtml, null, true);
},
'openCSSLiteralInjectionCallback'
);
createActionButton(
'Script File Injection',
function () {
openWithScript(injecthtml, injectjs);
},
'openScriptInjection'
);
createActionButton(
'Script File Injection (callback)',
function () {
openWithScript(injecthtml, injectjs, true);
},
'openScriptInjectionCallback'
);
createActionButton(
'Script Literal Injection',
function () {
openWithScript(injecthtml);
},
'openScriptLiteralInjection'
);
createActionButton(
'Script Literal Injection (callback)',
function () {
openWithScript(injecthtml, null, true);
},
'openScriptLiteralInjectionCallback'
);
// Open hidden // Open hidden
createActionButton('Create Hidden', function () { createActionButton(
openHidden('https://www.google.co.uk', true); 'Create Hidden',
}, 'openHidden'); function () {
createActionButton('Show Hidden', function () { openHidden('https://www.google.co.uk', true);
showHidden(); },
}, 'showHidden'); 'openHidden'
createActionButton('Close Hidden', function () { );
closeHidden(); createActionButton(
}, 'closeHidden'); 'Show Hidden',
createActionButton('google.co.uk Not Hidden', function () { function () {
openHidden('https://www.google.co.uk', false); showHidden();
}, 'openHiddenShow'); },
createActionButton('google.co.uk shown for 2 seconds than hidden', function () { 'showHidden'
var iab = doOpen('https://www.google.co.uk/', 'random_sting'); );
setTimeout(function () { createActionButton(
iab.hide(); 'Close Hidden',
}, 2000); function () {
}, 'openVisibleAndHide'); closeHidden();
},
'closeHidden'
);
createActionButton(
'google.co.uk Not Hidden',
function () {
openHidden('https://www.google.co.uk', false);
},
'openHiddenShow'
);
createActionButton(
'google.co.uk shown for 2 seconds than hidden',
function () {
var iab = doOpen('https://www.google.co.uk/', 'random_sting');
setTimeout(function () {
iab.hide();
}, 2000);
},
'openVisibleAndHide'
);
// Clearing cache // Clearing cache
createActionButton('Clear Browser Cache', function () { createActionButton(
doOpen('https://www.google.co.uk', '_blank', 'clearcache=yes'); 'Clear Browser Cache',
}, 'openClearCache'); function () {
createActionButton('Clear Session Cache', function () { doOpen('https://www.google.co.uk', '_blank', 'clearcache=yes');
doOpen('https://www.google.co.uk', '_blank', 'clearsessioncache=yes'); },
}, 'openClearSessionCache'); 'openClearCache'
);
createActionButton(
'Clear Session Cache',
function () {
doOpen('https://www.google.co.uk', '_blank', 'clearsessioncache=yes');
},
'openClearSessionCache'
);
// Video tag // Video tag
createActionButton('Remote Video', function () { createActionButton(
doOpen(videohtml, '_blank'); 'Remote Video',
}, 'openRemoteVideo'); function () {
createActionButton('Remote Need User No Video', function () { doOpen(videohtml, '_blank');
doOpen(videohtml, '_blank', 'mediaPlaybackRequiresUserAction=no'); },
}, 'openRemoteNeedUserNoVideo'); 'openRemoteVideo'
createActionButton('Remote Need User Yes Video', function () { );
doOpen(videohtml, '_blank', 'mediaPlaybackRequiresUserAction=yes'); createActionButton(
}, 'openRemoteNeedUserYesVideo'); 'Remote Need User No Video',
function () {
doOpen(videohtml, '_blank', 'mediaPlaybackRequiresUserAction=no');
},
'openRemoteNeedUserNoVideo'
);
createActionButton(
'Remote Need User Yes Video',
function () {
doOpen(videohtml, '_blank', 'mediaPlaybackRequiresUserAction=yes');
},
'openRemoteNeedUserYesVideo'
);
// Local With Anchor Tag // Local With Anchor Tag
createActionButton('Anchor1', function () { createActionButton(
doOpen(localhtml + '#bogusanchor', '_blank'); 'Anchor1',
}, 'openAnchor1'); function () {
createActionButton('Anchor2', function () { doOpen(localhtml + '#bogusanchor', '_blank');
doOpen(localhtml + '#anchor2', '_blank'); },
}, 'openAnchor2'); 'openAnchor1'
);
createActionButton(
'Anchor2',
function () {
doOpen(localhtml + '#anchor2', '_blank');
},
'openAnchor2'
);
// Hardwareback // Hardwareback
createActionButton('no hardwareback (defaults to yes)', function () { createActionButton(
doOpen('http://cordova.apache.org', '_blank'); 'no hardwareback (defaults to yes)',
}, 'openHardwareBackDefault'); function () {
createActionButton('hardwareback=yes', function () { doOpen('http://cordova.apache.org', '_blank');
doOpen('http://cordova.apache.org', '_blank', 'hardwareback=yes'); },
}, 'openHardwareBackYes'); 'openHardwareBackDefault'
createActionButton('hardwareback=no', function () { );
doOpen('http://cordova.apache.org', '_blank', 'hardwareback=no'); createActionButton(
}, 'openHardwareBackNo'); 'hardwareback=yes',
createActionButton('no hardwareback -> hardwareback=no -> no hardwareback', function () { function () {
var ref = cordova.InAppBrowser.open('https://google.com', '_blank', 'location=yes' + (platformOpts ? ',' + platformOpts : '')); doOpen('http://cordova.apache.org', '_blank', 'hardwareback=yes');
ref.addEventListener('loadstop', function () { },
ref.close(); 'openHardwareBackYes'
}); );
ref.addEventListener('exit', function () { createActionButton(
var ref2 = cordova.InAppBrowser.open('https://google.com', '_blank', 'location=yes,hardwareback=no' + (platformOpts ? ',' + platformOpts : '')); 'hardwareback=no',
ref2.addEventListener('loadstop', function () { function () {
ref2.close(); doOpen('http://cordova.apache.org', '_blank', 'hardwareback=no');
},
'openHardwareBackNo'
);
createActionButton(
'no hardwareback -> hardwareback=no -> no hardwareback',
function () {
var ref = cordova.InAppBrowser.open('https://google.com', '_blank', 'location=yes' + (platformOpts ? ',' + platformOpts : ''));
ref.addEventListener('loadstop', function () {
ref.close();
}); });
ref2.addEventListener('exit', function () { ref.addEventListener('exit', function () {
cordova.InAppBrowser.open('https://google.com', '_blank', 'location=yes' + (platformOpts ? ',' + platformOpts : '')); var ref2 = cordova.InAppBrowser.open(
'https://google.com',
'_blank',
'location=yes,hardwareback=no' + (platformOpts ? ',' + platformOpts : '')
);
ref2.addEventListener('loadstop', function () {
ref2.close();
});
ref2.addEventListener('exit', function () {
cordova.InAppBrowser.open('https://google.com', '_blank', 'location=yes' + (platformOpts ? ',' + platformOpts : ''));
});
}); });
}); },
}, 'openHardwareBackDefaultAfterNo'); 'openHardwareBackDefaultAfterNo'
);
}; };

View File

@ -17,7 +17,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
* *
*/ */
(function () { (function () {
var exec = require('cordova/exec'); var exec = require('cordova/exec');
@ -27,19 +27,19 @@
function InAppBrowser () { function InAppBrowser () {
this.channels = { this.channels = {
'beforeload': channel.create('beforeload'), beforeload: channel.create('beforeload'),
'loadstart': channel.create('loadstart'), loadstart: channel.create('loadstart'),
'loadstop': channel.create('loadstop'), loadstop: channel.create('loadstop'),
'loaderror': channel.create('loaderror'), loaderror: channel.create('loaderror'),
'exit': channel.create('exit'), exit: channel.create('exit'),
'customscheme': channel.create('customscheme'), customscheme: channel.create('customscheme'),
'message': channel.create('message') message: channel.create('message')
}; };
} }
InAppBrowser.prototype = { InAppBrowser.prototype = {
_eventHandler: function (event) { _eventHandler: function (event) {
if (event && (event.type in this.channels)) { if (event && event.type in this.channels) {
if (event.type === 'beforeload') { if (event.type === 'beforeload') {
this.channels[event.type].fire(event, this._loadAfterBeforeload); this.channels[event.type].fire(event, this._loadAfterBeforeload);
} else { } else {