2014-07-15 03:21:41 +08:00
/ *
*
* 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 .
*
2020-07-02 23:41:21 +08:00
* /
2014-07-15 03:21:41 +08:00
2018-10-06 04:23:56 +08:00
/* global MSApp */
2016-02-19 20:39:28 +08:00
2014-10-15 07:07:15 +08:00
var cordova = require ( 'cordova' ) ;
2017-07-27 20:55:11 +08:00
var isWindows = cordova . platformId === 'windows' ;
2018-09-03 20:12:15 +08:00
var isIos = cordova . platformId === 'ios' ;
2018-12-14 00:21:45 +08:00
var isAndroid = cordova . platformId === 'android' ;
2017-07-27 20:55:11 +08:00
var isBrowser = cordova . platformId === 'browser' ;
2014-10-15 07:07:15 +08:00
2014-10-15 03:18:29 +08:00
window . alert = window . alert || navigator . notification . alert ;
2017-01-18 22:42:55 +08:00
if ( isWindows && navigator && navigator . notification && navigator . notification . alert ) {
// window.alert is defined but not functional on UWP
window . alert = navigator . notification . alert ;
}
2014-10-15 03:18:29 +08:00
2016-01-27 17:35:44 +08:00
exports . defineAutoTests = function ( ) {
2018-09-03 20:12:15 +08:00
var createTests = function ( platformOpts ) {
platformOpts = platformOpts || '' ;
2016-01-27 17:35:44 +08:00
2018-10-09 18:48:15 +08:00
describe ( 'cordova.InAppBrowser' , function ( ) {
it ( 'inappbrowser.spec.1 should exist' , function ( ) {
expect ( cordova . InAppBrowser ) . toBeDefined ( ) ;
} ) ;
2016-01-27 17:35:44 +08:00
2018-10-09 18:48:15 +08:00
it ( 'inappbrowser.spec.2 should contain open function' , function ( ) {
expect ( cordova . InAppBrowser . open ) . toBeDefined ( ) ;
expect ( cordova . InAppBrowser . open ) . toEqual ( jasmine . any ( Function ) ) ;
} ) ;
2016-01-27 17:35:44 +08:00
} ) ;
2018-10-09 18:48:15 +08:00
describe ( 'open method' , function ( ) {
if ( cordova . platformId === 'osx' ) {
pending ( 'Open method not fully supported on OSX.' ) ;
return ;
}
2016-10-07 00:39:10 +08:00
2018-10-09 18:48:15 +08:00
var iabInstance ;
var originalTimeout ;
var url = 'https://dist.apache.org/repos/dist/dev/cordova/' ;
var badUrl = 'http://bad-uri/' ;
2016-01-27 17:35:44 +08:00
2018-10-09 18:48:15 +08:00
beforeEach ( function ( ) {
2020-07-02 23:41:21 +08:00
// increase timeout to ensure test url could be loaded within test time
2018-10-09 18:48:15 +08:00
originalTimeout = jasmine . DEFAULT _TIMEOUT _INTERVAL ;
jasmine . DEFAULT _TIMEOUT _INTERVAL = 30000 ;
2016-01-27 17:35:44 +08:00
2018-10-09 18:48:15 +08:00
iabInstance = null ;
} ) ;
2016-01-27 17:35:44 +08:00
2018-10-09 18:48:15 +08:00
afterEach ( function ( done ) {
2020-07-02 23:41:21 +08:00
// restore original timeout
2018-10-09 18:48:15 +08:00
jasmine . DEFAULT _TIMEOUT _INTERVAL = originalTimeout ;
2018-09-03 20:12:15 +08:00
2018-10-09 18:48:15 +08:00
if ( iabInstance !== null && iabInstance . close ) {
iabInstance . close ( ) ;
}
iabInstance = null ;
// add some extra time so that iab dialog is closed
setTimeout ( done , 2000 ) ;
} ) ;
2016-01-27 17:35:44 +08:00
2018-10-09 18:48:15 +08:00
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 ) ;
}
2016-01-27 17:35:44 +08:00
}
2018-10-06 04:23:56 +08:00
2018-10-09 18:48:15 +08:00
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 ) ) ;
}
2016-01-27 17:35:44 +08:00
2018-10-09 18:48:15 +08:00
it ( 'inappbrowser.spec.3 should return InAppBrowser instance with required methods' , function ( ) {
2018-09-03 20:12:15 +08:00
iabInstance = cordova . InAppBrowser . open ( url , '_blank' , platformOpts ) ;
2016-01-27 17:35:44 +08:00
2018-10-09 18:48:15 +08:00
expect ( iabInstance ) . toBeDefined ( ) ;
2016-01-27 17:35:44 +08:00
2018-10-09 18:48:15 +08:00
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 ) ) ;
2018-10-06 04:23:56 +08:00
} ) ;
2016-01-27 17:35:44 +08:00
2018-10-09 18:48:15 +08:00
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' ) ;
} ) ;
2018-09-03 20:12:15 +08:00
iabInstance = cordova . InAppBrowser . open ( url , '_blank' , platformOpts ) ;
2018-10-09 18:48:15 +08:00
iabInstance . addEventListener ( 'loadstart' , onLoadStart ) ;
iabInstance . addEventListener ( 'loadstop' , function ( evt ) {
verifyEvent ( evt , 'loadstop' ) ;
if ( ! isBrowser ) {
2020-07-02 23:41:21 +08:00
// according to documentation, "loadstart" event is not supported on browser
// https://github.com/apache/cordova-plugin-inappbrowser#browser-quirks-1
2018-10-09 18:48:15 +08:00
expect ( onLoadStart ) . toHaveBeenCalled ( ) ;
}
done ( ) ;
} ) ;
2016-01-27 17:35:44 +08:00
} ) ;
2018-10-09 18:48:15 +08:00
it ( 'inappbrowser.spec.5 should support exit event' , function ( done ) {
2018-09-03 20:12:15 +08:00
iabInstance = cordova . InAppBrowser . open ( url , '_blank' , platformOpts ) ;
2018-10-09 18:48:15 +08:00
iabInstance . addEventListener ( 'exit' , function ( evt ) {
verifyEvent ( evt , 'exit' ) ;
done ( ) ;
} ) ;
2019-03-06 10:47:21 +08:00
iabInstance . addEventListener ( 'loadstop' , function ( evt ) {
iabInstance . close ( ) ;
iabInstance = null ;
} ) ;
2016-01-27 17:35:44 +08:00
} ) ;
2018-10-09 18:48:15 +08:00
it ( 'inappbrowser.spec.6 should support loaderror event' , function ( done ) {
if ( isBrowser ) {
2020-07-02 23:41:21 +08:00
// 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" ) ;
2018-10-09 18:48:15 +08:00
}
2018-09-03 20:12:15 +08:00
iabInstance = cordova . InAppBrowser . open ( badUrl , '_blank' , platformOpts ) ;
2018-10-09 18:48:15 +08:00
iabInstance . addEventListener ( 'loaderror' , function ( evt ) {
verifyLoadErrorEvent ( evt ) ;
done ( ) ;
} ) ;
2016-01-27 17:35:44 +08:00
} ) ;
2018-12-14 00:21:45 +08:00
it ( 'inappbrowser.spec.7 should support message event' , function ( done ) {
if ( ! isAndroid && ! isIos ) {
2020-07-02 23:41:21 +08:00
return pending ( cordova . platformId + " platform doesn't support message event" ) ;
2018-12-14 00:21:45 +08:00
}
var messageKey = 'my_message' ;
var messageValue = 'is_this' ;
iabInstance = cordova . InAppBrowser . open ( url , '_blank' , platformOpts ) ;
iabInstance . addEventListener ( 'message' , function ( evt ) {
// Verify message event
expect ( evt ) . toBeDefined ( ) ;
expect ( evt . type ) . toEqual ( 'message' ) ;
expect ( evt . data ) . toBeDefined ( ) ;
expect ( evt . data [ messageKey ] ) . toBeDefined ( ) ;
expect ( evt . data [ messageKey ] ) . toEqual ( messageValue ) ;
done ( ) ;
} ) ;
iabInstance . addEventListener ( 'loadstop' , function ( evt ) {
2020-07-02 23:41:21 +08:00
var code =
'(function(){\n' +
' var message = {' +
messageKey +
': "' +
messageValue +
'"};\n' +
2018-12-14 00:21:45 +08:00
' webkit.messageHandlers.cordova_iab.postMessage(JSON.stringify(message));\n' +
'})()' ;
iabInstance . executeScript ( { code : code } ) ;
} ) ;
} ) ;
2016-01-27 17:35:44 +08:00
} ) ;
2018-09-03 20:12:15 +08:00
} ;
2020-03-05 22:51:31 +08:00
createTests ( ) ;
2016-01-27 17:35:44 +08:00
} ;
2014-07-15 03:21:41 +08:00
exports . defineManualTests = function ( contentEl , createActionButton ) {
2018-10-06 04:23:56 +08:00
var platformOpts = '' ;
var platform _info = '' ;
2017-06-13 01:34:08 +08:00
function doOpen ( url , target , params , numExpectedRedirects , useWindowOpen ) {
2014-07-15 03:21:41 +08:00
numExpectedRedirects = numExpectedRedirects || 0 ;
2015-02-13 05:34:32 +08:00
useWindowOpen = useWindowOpen || false ;
2017-06-13 01:34:08 +08:00
console . log ( 'Opening ' + url ) ;
2014-10-15 07:23:26 +08:00
2014-07-15 03:21:41 +08:00
var counts ;
var lastLoadStartURL ;
var wasReset = false ;
2017-06-13 01:34:08 +08:00
function reset ( ) {
2014-07-15 03:21:41 +08:00
counts = {
2020-07-02 23:41:21 +08:00
loaderror : 0 ,
loadstart : 0 ,
loadstop : 0 ,
exit : 0
2014-07-15 03:21:41 +08:00
} ;
lastLoadStartURL = '' ;
}
reset ( ) ;
2015-02-13 05:34:32 +08:00
var iab ;
var callbacks = {
2014-10-15 07:23:26 +08:00
loaderror : logEvent ,
loadstart : logEvent ,
loadstop : logEvent ,
exit : logEvent
2015-02-13 05:34:32 +08:00
} ;
if ( useWindowOpen ) {
console . log ( 'Use window.open() for url' ) ;
iab = window . open ( url , target , params , callbacks ) ;
2017-06-13 01:34:08 +08:00
} else {
2018-09-03 20:12:15 +08:00
if ( platformOpts ) {
params += ( params ? ',' : '' ) + platformOpts ;
}
2015-02-13 05:34:32 +08:00
iab = cordova . InAppBrowser . open ( url , target , params , callbacks ) ;
}
2014-10-15 07:23:26 +08:00
if ( ! iab ) {
2017-06-13 01:34:08 +08:00
alert ( 'open returned ' + iab ) ; // eslint-disable-line no-undef
2014-10-15 07:23:26 +08:00
return ;
}
2015-02-13 05:34:32 +08:00
2017-06-13 01:34:08 +08:00
function logEvent ( e ) {
2014-07-15 03:21:41 +08:00
console . log ( 'IAB event=' + JSON . stringify ( e ) ) ;
counts [ e . type ] ++ ;
// Verify that event.url gets updated on redirects.
2017-06-13 01:34:08 +08:00
if ( e . type === 'loadstart' ) {
if ( e . url === lastLoadStartURL ) {
alert ( 'Unexpected: loadstart fired multiple times for the same URL.' ) ; // eslint-disable-line no-undef
2014-07-15 03:21:41 +08:00
}
lastLoadStartURL = e . url ;
}
// Verify the right number of loadstart events were fired.
2017-06-13 01:34:08 +08:00
if ( e . type === 'loadstop' || e . type === 'loaderror' ) {
if ( e . url !== lastLoadStartURL ) {
2020-07-02 23:41:21 +08:00
alert ( 'Unexpected: ' + e . type + " event.url != loadstart's event.url" ) ; // eslint-disable-line no-undef
2014-07-15 03:21:41 +08:00
}
2016-02-19 20:39:28 +08:00
if ( numExpectedRedirects === 0 && counts . loadstart !== 1 ) {
2014-07-15 03:21:41 +08:00
// Do allow a loaderror without a loadstart (e.g. in the case of an invalid URL).
2017-06-13 01:34:08 +08:00
if ( ! ( e . type === 'loaderror' && counts . loadstart === 0 ) ) {
alert ( 'Unexpected: got multiple loadstart events. (' + counts . loadstart + ')' ) ; // eslint-disable-line no-undef
2014-07-15 03:21:41 +08:00
}
2020-07-02 23:41:21 +08:00
} 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
2014-07-15 03:21:41 +08:00
}
wasReset = true ;
numExpectedRedirects = 0 ;
reset ( ) ;
}
// Verify that loadend / loaderror was called.
2017-06-13 01:34:08 +08:00
if ( e . type === 'exit' ) {
2016-02-19 20:39:28 +08:00
var numStopEvents = counts . loadstop + counts . loaderror ;
2014-07-15 03:21:41 +08:00
if ( numStopEvents === 0 && ! wasReset ) {
2017-06-13 01:34:08 +08:00
alert ( 'Unexpected: browser closed without a loadstop or loaderror.' ) ; // eslint-disable-line no-undef
2014-07-15 03:21:41 +08:00
} else if ( numStopEvents > 1 ) {
2017-06-13 01:34:08 +08:00
alert ( 'Unexpected: got multiple loadstop/loaderror events.' ) ; // eslint-disable-line no-undef
2014-07-15 03:21:41 +08:00
}
}
}
return iab ;
}
2017-06-13 01:34:08 +08:00
function doHookOpen ( url , target , params , numExpectedRedirects ) {
2015-02-13 05:34:32 +08:00
var originalFunc = window . open ;
2020-07-02 23:41:21 +08:00
var wasClobbered = Object . prototype . hasOwnProperty . call ( window , 'open' ) ;
2015-02-13 05:34:32 +08:00
window . open = cordova . InAppBrowser . open ;
try {
doOpen ( url , target , params , numExpectedRedirects , true ) ;
2017-06-13 01:34:08 +08:00
} finally {
2015-02-13 05:34:32 +08:00
if ( wasClobbered ) {
window . open = originalFunc ;
2017-06-13 01:34:08 +08:00
} else {
console . log ( 'just delete, to restore open from prototype' ) ;
2015-02-13 05:34:32 +08:00
delete window . open ;
}
}
}
2017-06-13 01:34:08 +08:00
function openWithStyle ( url , cssUrl , useCallback ) {
2014-07-15 03:21:41 +08:00
var iab = doOpen ( url , '_blank' , 'location=yes' ) ;
var callback = function ( results ) {
if ( results && results . length === 0 ) {
2017-06-13 01:34:08 +08:00
alert ( 'Results verified' ) ; // eslint-disable-line no-undef
2014-07-15 03:21:41 +08:00
} else {
console . log ( results ) ;
2020-07-02 23:41:21 +08:00
alert ( 'Got: ' + typeof results + '\n' + JSON . stringify ( results ) ) ; // eslint-disable-line no-undef
2014-07-15 03:21:41 +08:00
}
} ;
if ( cssUrl ) {
iab . addEventListener ( 'loadstop' , function ( event ) {
2018-10-06 04:23:56 +08:00
iab . insertCSS ( { file : cssUrl } , useCallback && callback ) ;
2014-07-15 03:21:41 +08:00
} ) ;
} else {
iab . addEventListener ( 'loadstop' , function ( event ) {
2020-07-02 23:41:21 +08:00
iab . insertCSS ( { code : '#style-update-literal { \ndisplay: block !important; \n}' } , useCallback && callback ) ;
2014-07-15 03:21:41 +08:00
} ) ;
}
}
2017-06-13 01:34:08 +08:00
function openWithScript ( url , jsUrl , useCallback ) {
2014-07-15 03:21:41 +08:00
var iab = doOpen ( url , '_blank' , 'location=yes' ) ;
if ( jsUrl ) {
iab . addEventListener ( 'loadstop' , function ( event ) {
2020-07-02 23:41:21 +08:00
iab . executeScript (
{ file : jsUrl } ,
useCallback &&
function ( results ) {
if ( results && results . length === 0 ) {
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
}
}
) ;
2014-07-15 03:21:41 +08:00
} ) ;
} else {
iab . addEventListener ( 'loadstop' , function ( event ) {
2020-07-02 23:41:21 +08:00
var code =
'(function(){\n' +
' var header = document.getElementById("header");\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' ) {
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
}
}
) ;
2014-07-15 03:21:41 +08:00
} ) ;
}
}
var hiddenwnd = null ;
2020-07-02 23:41:21 +08:00
var loadlistener = function ( event ) {
alert ( 'background window loaded ' ) ;
} ; // eslint-disable-line no-undef
2017-06-13 01:34:08 +08:00
function openHidden ( url , startHidden ) {
2020-07-02 23:41:21 +08:00
var shopt = startHidden ? 'hidden=yes' : '' ;
2018-09-03 20:12:15 +08:00
if ( platformOpts ) {
shopt += ( shopt ? ',' : '' ) + platformOpts ;
}
2015-02-13 05:34:32 +08:00
hiddenwnd = cordova . InAppBrowser . open ( url , 'random_string' , shopt ) ;
2014-07-15 03:21:41 +08:00
if ( ! hiddenwnd ) {
2017-06-13 01:34:08 +08:00
alert ( 'cordova.InAppBrowser.open returned ' + hiddenwnd ) ; // eslint-disable-line no-undef
2014-07-15 03:21:41 +08:00
return ;
}
if ( startHidden ) hiddenwnd . addEventListener ( 'loadstop' , loadlistener ) ;
}
2017-06-13 01:34:08 +08:00
function showHidden ( ) {
if ( hiddenwnd ) {
2014-07-15 03:21:41 +08:00
hiddenwnd . show ( ) ;
}
}
2017-06-13 01:34:08 +08:00
function closeHidden ( ) {
if ( hiddenwnd ) {
2014-07-15 03:21:41 +08:00
hiddenwnd . removeEventListener ( 'loadstop' , loadlistener ) ;
hiddenwnd . close ( ) ;
hiddenwnd = null ;
}
}
2020-07-02 23:41:21 +08:00
var info _div =
'<h1>InAppBrowser</h1>' +
2014-07-15 03:21:41 +08:00
'<div id="info">' +
2014-10-28 00:23:10 +08:00
'Make sure http://cordova.apache.org and http://google.co.uk and https://www.google.co.uk are white listed. </br>' +
2014-07-15 03:21:41 +08:00
'Make sure http://www.apple.com is not in the white list.</br>' +
'In iOS, starred <span style="vertical-align:super">*</span> tests will put the app in a state with no way to return. </br>' +
'<h4>User-Agent: <span id="user-agent"> </span></hr>' +
'</div>' ;
2020-07-02 23:41:21 +08:00
var local _tests =
'<h1>Local URL</h1>' +
2014-07-15 03:21:41 +08:00
'<div id="openLocal"></div>' +
'Expected result: opens successfully in CordovaWebView.' +
2015-02-13 05:34:32 +08:00
'<p/> <div id="openLocalHook"></div>' +
'Expected result: opens successfully in CordovaWebView (using hook of window.open()).' +
2014-07-15 03:21:41 +08:00
'<p/> <div id="openLocalSelf"></div>' +
'Expected result: opens successfully in CordovaWebView.' +
'<p/> <div id="openLocalSystem"></div>' +
'Expected result: fails to open' +
'<p/> <div id="openLocalBlank"></div>' +
'Expected result: opens successfully in InAppBrowser with locationBar at top.' +
'<p/> <div id="openLocalRandomNoLocation"></div>' +
'Expected result: opens successfully in InAppBrowser without locationBar.' +
'<p/> <div id="openLocalRandomToolBarBottom"></div>' +
'Expected result: opens successfully in InAppBrowser with locationBar. On iOS the toolbar is at the bottom.' +
'<p/> <div id="openLocalRandomToolBarTop"></div>' +
'Expected result: opens successfully in InAppBrowser with locationBar. On iOS the toolbar is at the top.' +
'<p/><div id="openLocalRandomToolBarTopNoLocation"></div>' +
'Expected result: open successfully in InAppBrowser with no locationBar. On iOS the toolbar is at the top.' ;
2020-07-02 23:41:21 +08:00
var white _listed _tests =
'<h1>White Listed URL</h1>' +
2014-07-15 03:21:41 +08:00
'<div id="openWhiteListed"></div>' +
2014-10-28 00:23:10 +08:00
'Expected result: open successfully in CordovaWebView to cordova.apache.org' +
2015-02-13 05:34:32 +08:00
'<p/> <div id="openWhiteListedHook"></div>' +
'Expected result: open successfully in CordovaWebView to cordova.apache.org (using hook of window.open())' +
2014-07-15 03:21:41 +08:00
'<p/> <div id="openWhiteListedSelf"></div>' +
2014-10-28 00:23:10 +08:00
'Expected result: open successfully in CordovaWebView to cordova.apache.org' +
2014-07-15 03:21:41 +08:00
'<p/> <div id="openWhiteListedSystem"></div>' +
2014-10-28 00:23:10 +08:00
'Expected result: open successfully in system browser to cordova.apache.org' +
2014-07-15 03:21:41 +08:00
'<p/> <div id="openWhiteListedBlank"></div>' +
2014-10-28 00:23:10 +08:00
'Expected result: open successfully in InAppBrowser to cordova.apache.org' +
2014-07-15 03:21:41 +08:00
'<p/> <div id="openWhiteListedRandom"></div>' +
2014-10-28 00:23:10 +08:00
'Expected result: open successfully in InAppBrowser to cordova.apache.org' +
2014-07-15 03:21:41 +08:00
'<p/> <div id="openWhiteListedRandomNoLocation"></div>' +
2014-10-28 00:23:10 +08:00
'Expected result: open successfully in InAppBrowser to cordova.apache.org with no location bar.' ;
2014-07-15 03:21:41 +08:00
2020-07-02 23:41:21 +08:00
var non _white _listed _tests =
'<h1>Non White Listed URL</h1>' +
2014-07-15 03:21:41 +08:00
'<div id="openNonWhiteListed"></div>' +
2015-02-13 05:34:32 +08:00
'Expected result: open successfully in InAppBrowser to apple.com.' +
'<p/> <div id="openNonWhiteListedHook"></div>' +
'Expected result: open successfully in InAppBrowser to apple.com (using hook of window.open()).' +
2014-07-15 03:21:41 +08:00
'<p/> <div id="openNonWhiteListedSelf"></div>' +
'Expected result: open successfully in InAppBrowser to apple.com (_self enforces whitelist).' +
'<p/> <div id="openNonWhiteListedSystem"></div>' +
'Expected result: open successfully in system browser to apple.com.' +
'<p/> <div id="openNonWhiteListedBlank"></div>' +
'Expected result: open successfully in InAppBrowser to apple.com.' +
'<p/> <div id="openNonWhiteListedRandom"></div>' +
'Expected result: open successfully in InAppBrowser to apple.com.' +
'<p/> <div id="openNonWhiteListedRandomNoLocation"></div>' +
'Expected result: open successfully in InAppBrowser to apple.com without locationBar.' ;
2020-07-02 23:41:21 +08:00
var page _with _redirects _tests =
'<h1>Page with redirect</h1>' +
2014-07-15 03:21:41 +08:00
'<div id="openRedirect301"></div>' +
2014-10-28 00:23:10 +08:00
'Expected result: should 301 and open successfully in InAppBrowser to https://www.google.co.uk.' +
2014-07-15 03:21:41 +08:00
'<p/> <div id="openRedirect302"></div>' +
'Expected result: should 302 and open successfully in InAppBrowser to www.zhihu.com/answer/16714076.' ;
2020-07-02 23:41:21 +08:00
var pdf _url _tests =
'<h1>PDF URL</h1>' +
2014-07-15 03:21:41 +08:00
'<div id="openPDF"></div>' +
'Expected result: InAppBrowser opens. PDF should render on iOS.' +
'<p/> <div id="openPDFBlank"></div>' +
'Expected result: InAppBrowser opens. PDF should render on iOS.' ;
2020-07-02 23:41:21 +08:00
var invalid _url _tests =
'<h1>Invalid URL</h1>' +
2014-07-15 03:21:41 +08:00
'<div id="openInvalidScheme"></div>' +
'Expected result: fail to load in InAppBrowser.' +
'<p/> <div id="openInvalidHost"></div>' +
'Expected result: fail to load in InAppBrowser.' +
'<p/> <div id="openInvalidMissing"></div>' +
'Expected result: fail to load in InAppBrowser (404).' ;
2020-07-02 23:41:21 +08:00
var css _js _injection _tests =
'<h1>CSS / JS Injection</h1>' +
2014-07-15 03:21:41 +08:00
'<div id="openOriginalDocument"></div>' +
'Expected result: open successfully in InAppBrowser without text "Style updated from..."' +
'<p/> <div id="openCSSInjection"></div>' +
'Expected result: open successfully in InAppBrowser with "Style updated from file".' +
'<p/> <div id="openCSSInjectionCallback"></div>' +
'Expected result: open successfully in InAppBrowser with "Style updated from file", and alert dialog with text "Results verified".' +
'<p/> <div id="openCSSLiteralInjection"></div>' +
'Expected result: open successfully in InAppBrowser with "Style updated from literal".' +
'<p/> <div id="openCSSLiteralInjectionCallback"></div>' +
'Expected result: open successfully in InAppBrowser with "Style updated from literal", and alert dialog with text "Results verified".' +
'<p/> <div id="openScriptInjection"></div>' +
'Expected result: open successfully in InAppBrowser with text "Script file successfully injected".' +
'<p/> <div id="openScriptInjectionCallback"></div>' +
'Expected result: open successfully in InAppBrowser with text "Script file successfully injected" and alert dialog with the text "Results verified".' +
'<p/> <div id="openScriptLiteralInjection"></div>' +
'Expected result: open successfully in InAppBrowser with the text "Script literal successfully injected" .' +
'<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".' ;
2020-07-02 23:41:21 +08:00
var open _hidden _tests =
'<h1>Open Hidden </h1>' +
2014-07-15 03:21:41 +08:00
'<div id="openHidden"></div>' +
'Expected result: no additional browser window. Alert appears with the text "background window loaded".' +
'<p/> <div id="showHidden"></div>' +
2014-10-28 00:23:10 +08:00
'Expected result: after first clicking on previous test "create hidden", open successfully in InAppBrowser to https://www.google.co.uk.' +
2014-07-15 03:21:41 +08:00
'<p/> <div id="closeHidden"></div>' +
'Expected result: no output. But click on "show hidden" again and nothing should be shown.' +
'<p/> <div id="openHiddenShow"></div>' +
2016-10-19 17:36:20 +08:00
'Expected result: open successfully in InAppBrowser to https://www.google.co.uk' +
'<p/> <div id="openVisibleAndHide"></div>' +
'Expected result: open successfully in InAppBrowser to https://www.google.co.uk. Hide after 2 seconds' ;
2014-07-15 03:21:41 +08:00
2020-07-02 23:41:21 +08:00
var clearing _cache _tests =
'<h1>Clearing Cache</h1>' +
2014-07-15 03:21:41 +08:00
'<div id="openClearCache"></div>' +
'Expected result: ?' +
'<p/> <div id="openClearSessionCache"></div>' +
'Expected result: ?' ;
2020-07-02 23:41:21 +08:00
var video _tag _tests =
'<h1>Video tag</h1>' +
2014-07-15 03:21:41 +08:00
'<div id="openRemoteVideo"></div>' +
2015-12-31 03:02:52 +08:00
'Expected result: open successfully in InAppBrowser with an embedded video plays automatically on iOS and Android.' +
'<div id="openRemoteNeedUserNoVideo"></div>' +
'Expected result: open successfully in InAppBrowser with an embedded video plays automatically on iOS and Android.' +
'<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.' ;
2014-07-15 03:21:41 +08:00
2020-07-02 23:41:21 +08:00
var local _with _anchor _tag _tests =
'<h1>Local with anchor tag</h1>' +
2014-07-15 03:21:41 +08:00
'<div id="openAnchor1"></div>' +
2014-08-28 05:15:55 +08:00
'Expected result: open successfully in InAppBrowser to the local page, scrolled to the top as normal.' +
2014-07-15 03:21:41 +08:00
'<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.' ;
2020-07-02 23:41:21 +08:00
var hardwareback _tests =
'<h1>HardwareBack</h1>' +
2016-08-17 01:10:15 +08:00
'<p/> <div id="openHardwareBackDefault"></div>' +
'Expected result: By default hardwareback is yes so pressing back button should navigate backwards in history then close InAppBrowser' +
'<p/> <div id="openHardwareBackYes"></div>' +
'Expected result: hardwareback=yes pressing back button should navigate backwards in history then close InAppBrowser' +
'<p/> <div id="openHardwareBackNo"></div>' +
2017-06-13 01:34:08 +08:00
'Expected result: hardwareback=no pressing back button should close InAppBrowser regardless history' +
2016-09-20 15:23:37 +08:00
'<p/> <div id="openHardwareBackDefaultAfterNo"></div>' +
'Expected result: consistently open browsers with with the appropriate option: hardwareback=defaults to yes then hardwareback=no then hardwareback=defaults to yes. By default hardwareback is yes so pressing back button should navigate backwards in history then close InAppBrowser' ;
2016-08-17 01:10:15 +08:00
2014-09-08 18:43:19 +08:00
// CB-7490 We need to wrap this code due to Windows security restrictions
// see http://msdn.microsoft.com/en-us/library/windows/apps/hh465380.aspx#differences for details
if ( window . MSApp && window . MSApp . execUnsafeLocalFunction ) {
2017-06-13 01:34:08 +08:00
MSApp . execUnsafeLocalFunction ( function ( ) {
2020-07-02 23:41:21 +08:00
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 +
css _js _injection _tests +
open _hidden _tests +
clearing _cache _tests +
video _tag _tests +
local _with _anchor _tag _tests +
hardwareback _tests ;
2014-09-08 18:43:19 +08:00
} ) ;
} else {
2020-07-02 23:41:21 +08:00
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 +
css _js _injection _tests +
open _hidden _tests +
clearing _cache _tests +
video _tag _tests +
local _with _anchor _tag _tests +
hardwareback _tests ;
2014-09-08 18:43:19 +08:00
}
2014-07-15 03:21:41 +08:00
2017-06-13 01:34:08 +08:00
document . getElementById ( 'user-agent' ) . textContent = navigator . userAgent ;
2014-08-28 03:56:46 +08:00
// we are already in cdvtests directory
var basePath = 'iab-resources/' ;
2017-06-13 01:34:08 +08:00
var localhtml = basePath + 'local.html' ;
var localpdf = basePath + 'local.pdf' ;
var injecthtml = basePath + 'inject.html' ;
var injectjs = isWindows ? basePath + 'inject.js' : 'inject.js' ;
var injectcss = isWindows ? basePath + 'inject.css' : 'inject.css' ;
var videohtml = basePath + 'video.html' ;
2018-09-03 20:12:15 +08:00
2017-06-13 01:34:08 +08:00
// Local
2020-07-02 23:41:21 +08:00
createActionButton (
'target=Default' ,
function ( ) {
doOpen ( localhtml ) ;
} ,
'openLocal'
) ;
createActionButton (
'target=Default (window.open)' ,
function ( ) {
doHookOpen ( localhtml ) ;
} ,
'openLocalHook'
) ;
createActionButton (
'target=_self' ,
function ( ) {
doOpen ( localhtml , '_self' ) ;
} ,
'openLocalSelf'
) ;
createActionButton (
'target=_system' ,
function ( ) {
doOpen ( localhtml , '_system' ) ;
} ,
'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'
) ;
2014-07-15 03:21:41 +08:00
2017-06-13 01:34:08 +08:00
// White Listed
2020-07-02 23:41:21 +08:00
createActionButton (
'* target=Default' ,
function ( ) {
doOpen ( 'http://cordova.apache.org' ) ;
} ,
'openWhiteListed'
) ;
createActionButton (
'* target=Default (window.open)' ,
function ( ) {
doHookOpen ( 'http://cordova.apache.org' ) ;
} ,
'openWhiteListedHook'
) ;
createActionButton (
'* target=_self' ,
function ( ) {
doOpen ( 'http://cordova.apache.org' , '_self' ) ;
} ,
'openWhiteListedSelf'
) ;
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'
) ;
2014-07-15 03:21:41 +08:00
2017-06-13 01:34:08 +08:00
// Non White Listed
2020-07-02 23:41:21 +08:00
createActionButton (
'target=Default' ,
function ( ) {
doOpen ( 'http://www.apple.com' ) ;
} ,
'openNonWhiteListed'
) ;
createActionButton (
'target=Default (window.open)' ,
function ( ) {
doHookOpen ( 'http://www.apple.com' ) ;
} ,
'openNonWhiteListedHook'
) ;
createActionButton (
'target=_self' ,
function ( ) {
doOpen ( 'http://www.apple.com' , '_self' ) ;
} ,
'openNonWhiteListedSelf'
) ;
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'
) ;
2014-07-15 03:21:41 +08:00
2017-06-13 01:34:08 +08:00
// Page with redirect
2020-07-02 23:41:21 +08:00
createActionButton (
'http://google.co.uk' ,
function ( ) {
doOpen ( 'http://google.co.uk' , 'random_string' , '' , 1 ) ;
} ,
'openRedirect301'
) ;
createActionButton (
'http://goo.gl/pUFqg' ,
function ( ) {
doOpen ( 'http://goo.gl/pUFqg' , 'random_string' , '' , 2 ) ;
} ,
'openRedirect302'
) ;
2014-07-15 03:21:41 +08:00
2017-06-13 01:34:08 +08:00
// PDF URL
2020-07-02 23:41:21 +08:00
createActionButton (
'Remote URL' ,
function ( ) {
doOpen ( 'http://www.stluciadance.com/prospectus_file/sample.pdf' ) ;
} ,
'openPDF'
) ;
createActionButton (
'Local URL' ,
function ( ) {
doOpen ( localpdf , '_blank' ) ;
} ,
'openPDFBlank'
) ;
2014-07-15 03:21:41 +08:00
2017-06-13 01:34:08 +08:00
// Invalid URL
2020-07-02 23:41:21 +08:00
createActionButton (
'Invalid Scheme' ,
function ( ) {
doOpen ( 'x-ttp://www.invalid.com/' , '_blank' ) ;
} ,
'openInvalidScheme'
) ;
createActionButton (
'Invalid Host' ,
function ( ) {
doOpen ( 'http://www.inv;alid.com/' , '_blank' ) ;
} ,
'openInvalidHost'
) ;
createActionButton (
'Missing Local File' ,
function ( ) {
doOpen ( 'nonexistent.html' , '_blank' ) ;
} ,
'openInvalidMissing'
) ;
2014-07-15 03:21:41 +08:00
2017-06-13 01:34:08 +08:00
// CSS / JS injection
2020-07-02 23:41:21 +08:00
createActionButton (
'Original Document' ,
function ( ) {
doOpen ( injecthtml , '_blank' ) ;
} ,
'openOriginalDocument'
) ;
createActionButton (
'CSS File Injection' ,
function ( ) {
openWithStyle ( injecthtml , injectcss ) ;
} ,
'openCSSInjection'
) ;
createActionButton (
'CSS File Injection (callback)' ,
function ( ) {
openWithStyle ( injecthtml , injectcss , true ) ;
} ,
'openCSSInjectionCallback'
) ;
createActionButton (
'CSS Literal Injection' ,
function ( ) {
openWithStyle ( injecthtml ) ;
} ,
'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'
) ;
2014-07-15 03:21:41 +08:00
2017-06-13 01:34:08 +08:00
// Open hidden
2020-07-02 23:41:21 +08:00
createActionButton (
'Create Hidden' ,
function ( ) {
openHidden ( 'https://www.google.co.uk' , true ) ;
} ,
'openHidden'
) ;
createActionButton (
'Show Hidden' ,
function ( ) {
showHidden ( ) ;
} ,
'showHidden'
) ;
createActionButton (
'Close Hidden' ,
function ( ) {
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'
) ;
2014-07-15 03:21:41 +08:00
2017-06-13 01:34:08 +08:00
// Clearing cache
2020-07-02 23:41:21 +08:00
createActionButton (
'Clear Browser Cache' ,
function ( ) {
doOpen ( 'https://www.google.co.uk' , '_blank' , 'clearcache=yes' ) ;
} ,
'openClearCache'
) ;
createActionButton (
'Clear Session Cache' ,
function ( ) {
doOpen ( 'https://www.google.co.uk' , '_blank' , 'clearsessioncache=yes' ) ;
} ,
'openClearSessionCache'
) ;
2014-07-15 03:21:41 +08:00
2017-06-13 01:34:08 +08:00
// Video tag
2020-07-02 23:41:21 +08:00
createActionButton (
'Remote Video' ,
function ( ) {
doOpen ( videohtml , '_blank' ) ;
} ,
'openRemoteVideo'
) ;
createActionButton (
'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'
) ;
2014-07-15 03:21:41 +08:00
2017-06-13 01:34:08 +08:00
// Local With Anchor Tag
2020-07-02 23:41:21 +08:00
createActionButton (
'Anchor1' ,
function ( ) {
doOpen ( localhtml + '#bogusanchor' , '_blank' ) ;
} ,
'openAnchor1'
) ;
createActionButton (
'Anchor2' ,
function ( ) {
doOpen ( localhtml + '#anchor2' , '_blank' ) ;
} ,
'openAnchor2'
) ;
2016-08-17 01:10:15 +08:00
// Hardwareback
2020-07-02 23:41:21 +08:00
createActionButton (
'no hardwareback (defaults to yes)' ,
function ( ) {
doOpen ( 'http://cordova.apache.org' , '_blank' ) ;
} ,
'openHardwareBackDefault'
) ;
createActionButton (
'hardwareback=yes' ,
function ( ) {
doOpen ( 'http://cordova.apache.org' , '_blank' , 'hardwareback=yes' ) ;
} ,
'openHardwareBackYes'
) ;
createActionButton (
'hardwareback=no' ,
function ( ) {
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 ( ) ;
2016-09-20 15:23:37 +08:00
} ) ;
2020-07-02 23:41:21 +08:00
ref . addEventListener ( 'exit' , function ( ) {
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 : '' ) ) ;
} ) ;
2016-09-20 15:23:37 +08:00
} ) ;
2020-07-02 23:41:21 +08:00
} ,
'openHardwareBackDefaultAfterNo'
) ;
2014-07-15 03:21:41 +08:00
} ;