tests.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. /*
  2. *
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. *
  20. */
  21. /* global MSApp */
  22. var cordova = require('cordova');
  23. var isWindows = cordova.platformId === 'windows';
  24. var isBrowser = cordova.platformId === 'browser';
  25. window.alert = window.alert || navigator.notification.alert;
  26. if (isWindows && navigator && navigator.notification && navigator.notification.alert) {
  27. // window.alert is defined but not functional on UWP
  28. window.alert = navigator.notification.alert;
  29. }
  30. exports.defineAutoTests = function () {
  31. describe('cordova.InAppBrowser', function () {
  32. it('inappbrowser.spec.1 should exist', function () {
  33. expect(cordova.InAppBrowser).toBeDefined();
  34. });
  35. it('inappbrowser.spec.2 should contain open function', function () {
  36. expect(cordova.InAppBrowser.open).toBeDefined();
  37. expect(cordova.InAppBrowser.open).toEqual(jasmine.any(Function));
  38. });
  39. });
  40. describe('open method', function () {
  41. if (cordova.platformId === 'osx') {
  42. pending('Open method not fully supported on OSX.');
  43. return;
  44. }
  45. var iabInstance;
  46. var originalTimeout;
  47. var url = 'https://dist.apache.org/repos/dist/dev/cordova/';
  48. var badUrl = 'http://bad-uri/';
  49. beforeEach(function () {
  50. // increase timeout to ensure test url could be loaded within test time
  51. originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
  52. jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
  53. iabInstance = null;
  54. });
  55. afterEach(function (done) {
  56. // restore original timeout
  57. jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
  58. if (iabInstance !== null && iabInstance.close) {
  59. iabInstance.close();
  60. }
  61. iabInstance = null;
  62. // add some extra time so that iab dialog is closed
  63. setTimeout(done, 2000);
  64. });
  65. function verifyEvent (evt, type) {
  66. expect(evt).toBeDefined();
  67. expect(evt.type).toEqual(type);
  68. // `exit` event does not have url field, browser returns null url for CORS requests
  69. if (type !== 'exit' && !isBrowser) {
  70. expect(evt.url).toEqual(url);
  71. }
  72. }
  73. function verifyLoadErrorEvent (evt) {
  74. expect(evt).toBeDefined();
  75. expect(evt.type).toEqual('loaderror');
  76. expect(evt.url).toEqual(badUrl);
  77. expect(evt.code).toEqual(jasmine.any(Number));
  78. expect(evt.message).toEqual(jasmine.any(String));
  79. }
  80. it('inappbrowser.spec.3 should return InAppBrowser instance with required methods', function () {
  81. iabInstance = cordova.InAppBrowser.open(url, '_blank');
  82. expect(iabInstance).toBeDefined();
  83. expect(iabInstance.addEventListener).toEqual(jasmine.any(Function));
  84. expect(iabInstance.removeEventListener).toEqual(jasmine.any(Function));
  85. expect(iabInstance.close).toEqual(jasmine.any(Function));
  86. expect(iabInstance.show).toEqual(jasmine.any(Function));
  87. expect(iabInstance.hide).toEqual(jasmine.any(Function));
  88. expect(iabInstance.executeScript).toEqual(jasmine.any(Function));
  89. expect(iabInstance.insertCSS).toEqual(jasmine.any(Function));
  90. });
  91. it('inappbrowser.spec.4 should support loadstart and loadstop events', function (done) {
  92. var onLoadStart = jasmine.createSpy('loadstart event callback').and.callFake(function (evt) {
  93. verifyEvent(evt, 'loadstart');
  94. });
  95. iabInstance = cordova.InAppBrowser.open(url, '_blank');
  96. iabInstance.addEventListener('loadstart', onLoadStart);
  97. iabInstance.addEventListener('loadstop', function (evt) {
  98. verifyEvent(evt, 'loadstop');
  99. if (!isBrowser) {
  100. // according to documentation, "loadstart" event is not supported on browser
  101. // https://github.com/apache/cordova-plugin-inappbrowser#browser-quirks-1
  102. expect(onLoadStart).toHaveBeenCalled();
  103. }
  104. done();
  105. });
  106. });
  107. it('inappbrowser.spec.5 should support exit event', function (done) {
  108. iabInstance = cordova.InAppBrowser.open(url, '_blank');
  109. iabInstance.addEventListener('exit', function (evt) {
  110. verifyEvent(evt, 'exit');
  111. done();
  112. });
  113. iabInstance.close();
  114. iabInstance = null;
  115. });
  116. it('inappbrowser.spec.6 should support loaderror event', function (done) {
  117. if (isBrowser) {
  118. // according to documentation, "loaderror" event is not supported on browser
  119. // https://github.com/apache/cordova-plugin-inappbrowser#browser-quirks-1
  120. pending('Browser platform doesn\'t support loaderror event');
  121. }
  122. iabInstance = cordova.InAppBrowser.open(badUrl, '_blank');
  123. iabInstance.addEventListener('loaderror', function (evt) {
  124. verifyLoadErrorEvent(evt);
  125. done();
  126. });
  127. });
  128. });
  129. };
  130. exports.defineManualTests = function (contentEl, createActionButton) {
  131. function doOpen (url, target, params, numExpectedRedirects, useWindowOpen) {
  132. numExpectedRedirects = numExpectedRedirects || 0;
  133. useWindowOpen = useWindowOpen || false;
  134. console.log('Opening ' + url);
  135. var counts;
  136. var lastLoadStartURL;
  137. var wasReset = false;
  138. function reset () {
  139. counts = {
  140. 'loaderror': 0,
  141. 'loadstart': 0,
  142. 'loadstop': 0,
  143. 'exit': 0
  144. };
  145. lastLoadStartURL = '';
  146. }
  147. reset();
  148. var iab;
  149. var callbacks = {
  150. loaderror: logEvent,
  151. loadstart: logEvent,
  152. loadstop: logEvent,
  153. exit: logEvent
  154. };
  155. if (useWindowOpen) {
  156. console.log('Use window.open() for url');
  157. iab = window.open(url, target, params, callbacks);
  158. } else {
  159. iab = cordova.InAppBrowser.open(url, target, params, callbacks);
  160. }
  161. if (!iab) {
  162. alert('open returned ' + iab); // eslint-disable-line no-undef
  163. return;
  164. }
  165. function logEvent (e) {
  166. console.log('IAB event=' + JSON.stringify(e));
  167. counts[e.type]++;
  168. // Verify that event.url gets updated on redirects.
  169. if (e.type === 'loadstart') {
  170. if (e.url === lastLoadStartURL) {
  171. alert('Unexpected: loadstart fired multiple times for the same URL.'); // eslint-disable-line no-undef
  172. }
  173. lastLoadStartURL = e.url;
  174. }
  175. // Verify the right number of loadstart events were fired.
  176. if (e.type === 'loadstop' || e.type === 'loaderror') {
  177. if (e.url !== lastLoadStartURL) {
  178. alert('Unexpected: ' + e.type + ' event.url != loadstart\'s event.url'); // eslint-disable-line no-undef
  179. }
  180. if (numExpectedRedirects === 0 && counts.loadstart !== 1) {
  181. // Do allow a loaderror without a loadstart (e.g. in the case of an invalid URL).
  182. if (!(e.type === 'loaderror' && counts.loadstart === 0)) {
  183. alert('Unexpected: got multiple loadstart events. (' + counts.loadstart + ')'); // eslint-disable-line no-undef
  184. }
  185. } else if (numExpectedRedirects > 0 && counts.loadstart < (numExpectedRedirects + 1)) {
  186. alert('Unexpected: should have got at least ' + (numExpectedRedirects + 1) + ' loadstart events, but got ' + counts.loadstart); // eslint-disable-line no-undef
  187. }
  188. wasReset = true;
  189. numExpectedRedirects = 0;
  190. reset();
  191. }
  192. // Verify that loadend / loaderror was called.
  193. if (e.type === 'exit') {
  194. var numStopEvents = counts.loadstop + counts.loaderror;
  195. if (numStopEvents === 0 && !wasReset) {
  196. alert('Unexpected: browser closed without a loadstop or loaderror.'); // eslint-disable-line no-undef
  197. } else if (numStopEvents > 1) {
  198. alert('Unexpected: got multiple loadstop/loaderror events.'); // eslint-disable-line no-undef
  199. }
  200. }
  201. }
  202. return iab;
  203. }
  204. function doHookOpen (url, target, params, numExpectedRedirects) {
  205. var originalFunc = window.open;
  206. var wasClobbered = window.hasOwnProperty('open');
  207. window.open = cordova.InAppBrowser.open;
  208. try {
  209. doOpen(url, target, params, numExpectedRedirects, true);
  210. } finally {
  211. if (wasClobbered) {
  212. window.open = originalFunc;
  213. } else {
  214. console.log('just delete, to restore open from prototype');
  215. delete window.open;
  216. }
  217. }
  218. }
  219. function openWithStyle (url, cssUrl, useCallback) {
  220. var iab = doOpen(url, '_blank', 'location=yes');
  221. var callback = function (results) {
  222. if (results && results.length === 0) {
  223. alert('Results verified'); // eslint-disable-line no-undef
  224. } else {
  225. console.log(results);
  226. alert('Got: ' + typeof (results) + '\n' + JSON.stringify(results)); // eslint-disable-line no-undef
  227. }
  228. };
  229. if (cssUrl) {
  230. iab.addEventListener('loadstop', function (event) {
  231. iab.insertCSS({ file: cssUrl }, useCallback && callback);
  232. });
  233. } else {
  234. iab.addEventListener('loadstop', function (event) {
  235. iab.insertCSS({ code: '#style-update-literal { \ndisplay: block !important; \n}' },
  236. useCallback && callback);
  237. });
  238. }
  239. }
  240. function openWithScript (url, jsUrl, useCallback) {
  241. var iab = doOpen(url, '_blank', 'location=yes');
  242. if (jsUrl) {
  243. iab.addEventListener('loadstop', function (event) {
  244. iab.executeScript({ file: jsUrl }, useCallback && function (results) {
  245. if (results && results.length === 0) {
  246. alert('Results verified'); // eslint-disable-line no-undef
  247. } else {
  248. console.log(results);
  249. alert('Got: ' + typeof (results) + '\n' + JSON.stringify(results)); // eslint-disable-line no-undef
  250. }
  251. });
  252. });
  253. } else {
  254. iab.addEventListener('loadstop', function (event) {
  255. var code = '(function(){\n' +
  256. ' var header = document.getElementById("header");\n' +
  257. ' header.innerHTML = "Script literal successfully injected";\n' +
  258. ' return "abc";\n' +
  259. '})()';
  260. iab.executeScript({ code: code }, useCallback && function (results) {
  261. if (results && results.length === 1 && results[0] === 'abc') {
  262. alert('Results verified'); // eslint-disable-line no-undef
  263. } else {
  264. console.log(results);
  265. alert('Got: ' + typeof (results) + '\n' + JSON.stringify(results)); // eslint-disable-line no-undef
  266. }
  267. });
  268. });
  269. }
  270. }
  271. var hiddenwnd = null;
  272. var loadlistener = function (event) { alert('background window loaded '); }; // eslint-disable-line no-undef
  273. function openHidden (url, startHidden) {
  274. var shopt = (startHidden) ? 'hidden=yes' : '';
  275. hiddenwnd = cordova.InAppBrowser.open(url, 'random_string', shopt);
  276. if (!hiddenwnd) {
  277. alert('cordova.InAppBrowser.open returned ' + hiddenwnd); // eslint-disable-line no-undef
  278. return;
  279. }
  280. if (startHidden) hiddenwnd.addEventListener('loadstop', loadlistener);
  281. }
  282. function showHidden () {
  283. if (hiddenwnd) {
  284. hiddenwnd.show();
  285. }
  286. }
  287. function closeHidden () {
  288. if (hiddenwnd) {
  289. hiddenwnd.removeEventListener('loadstop', loadlistener);
  290. hiddenwnd.close();
  291. hiddenwnd = null;
  292. }
  293. }
  294. var info_div = '<h1>InAppBrowser</h1>' +
  295. '<div id="info">' +
  296. 'Make sure http://cordova.apache.org and http://google.co.uk and https://www.google.co.uk are white listed. </br>' +
  297. 'Make sure http://www.apple.com is not in the white list.</br>' +
  298. 'In iOS, starred <span style="vertical-align:super">*</span> tests will put the app in a state with no way to return. </br>' +
  299. '<h4>User-Agent: <span id="user-agent"> </span></hr>' +
  300. '</div>';
  301. var local_tests = '<h1>Local URL</h1>' +
  302. '<div id="openLocal"></div>' +
  303. 'Expected result: opens successfully in CordovaWebView.' +
  304. '<p/> <div id="openLocalHook"></div>' +
  305. 'Expected result: opens successfully in CordovaWebView (using hook of window.open()).' +
  306. '<p/> <div id="openLocalSelf"></div>' +
  307. 'Expected result: opens successfully in CordovaWebView.' +
  308. '<p/> <div id="openLocalSystem"></div>' +
  309. 'Expected result: fails to open' +
  310. '<p/> <div id="openLocalBlank"></div>' +
  311. 'Expected result: opens successfully in InAppBrowser with locationBar at top.' +
  312. '<p/> <div id="openLocalRandomNoLocation"></div>' +
  313. 'Expected result: opens successfully in InAppBrowser without locationBar.' +
  314. '<p/> <div id="openLocalRandomToolBarBottom"></div>' +
  315. 'Expected result: opens successfully in InAppBrowser with locationBar. On iOS the toolbar is at the bottom.' +
  316. '<p/> <div id="openLocalRandomToolBarTop"></div>' +
  317. 'Expected result: opens successfully in InAppBrowser with locationBar. On iOS the toolbar is at the top.' +
  318. '<p/><div id="openLocalRandomToolBarTopNoLocation"></div>' +
  319. 'Expected result: open successfully in InAppBrowser with no locationBar. On iOS the toolbar is at the top.';
  320. var white_listed_tests = '<h1>White Listed URL</h1>' +
  321. '<div id="openWhiteListed"></div>' +
  322. 'Expected result: open successfully in CordovaWebView to cordova.apache.org' +
  323. '<p/> <div id="openWhiteListedHook"></div>' +
  324. 'Expected result: open successfully in CordovaWebView to cordova.apache.org (using hook of window.open())' +
  325. '<p/> <div id="openWhiteListedSelf"></div>' +
  326. 'Expected result: open successfully in CordovaWebView to cordova.apache.org' +
  327. '<p/> <div id="openWhiteListedSystem"></div>' +
  328. 'Expected result: open successfully in system browser to cordova.apache.org' +
  329. '<p/> <div id="openWhiteListedBlank"></div>' +
  330. 'Expected result: open successfully in InAppBrowser to cordova.apache.org' +
  331. '<p/> <div id="openWhiteListedRandom"></div>' +
  332. 'Expected result: open successfully in InAppBrowser to cordova.apache.org' +
  333. '<p/> <div id="openWhiteListedRandomNoLocation"></div>' +
  334. 'Expected result: open successfully in InAppBrowser to cordova.apache.org with no location bar.';
  335. var non_white_listed_tests = '<h1>Non White Listed URL</h1>' +
  336. '<div id="openNonWhiteListed"></div>' +
  337. 'Expected result: open successfully in InAppBrowser to apple.com.' +
  338. '<p/> <div id="openNonWhiteListedHook"></div>' +
  339. 'Expected result: open successfully in InAppBrowser to apple.com (using hook of window.open()).' +
  340. '<p/> <div id="openNonWhiteListedSelf"></div>' +
  341. 'Expected result: open successfully in InAppBrowser to apple.com (_self enforces whitelist).' +
  342. '<p/> <div id="openNonWhiteListedSystem"></div>' +
  343. 'Expected result: open successfully in system browser to apple.com.' +
  344. '<p/> <div id="openNonWhiteListedBlank"></div>' +
  345. 'Expected result: open successfully in InAppBrowser to apple.com.' +
  346. '<p/> <div id="openNonWhiteListedRandom"></div>' +
  347. 'Expected result: open successfully in InAppBrowser to apple.com.' +
  348. '<p/> <div id="openNonWhiteListedRandomNoLocation"></div>' +
  349. 'Expected result: open successfully in InAppBrowser to apple.com without locationBar.';
  350. var page_with_redirects_tests = '<h1>Page with redirect</h1>' +
  351. '<div id="openRedirect301"></div>' +
  352. 'Expected result: should 301 and open successfully in InAppBrowser to https://www.google.co.uk.' +
  353. '<p/> <div id="openRedirect302"></div>' +
  354. 'Expected result: should 302 and open successfully in InAppBrowser to www.zhihu.com/answer/16714076.';
  355. var pdf_url_tests = '<h1>PDF URL</h1>' +
  356. '<div id="openPDF"></div>' +
  357. 'Expected result: InAppBrowser opens. PDF should render on iOS.' +
  358. '<p/> <div id="openPDFBlank"></div>' +
  359. 'Expected result: InAppBrowser opens. PDF should render on iOS.';
  360. var invalid_url_tests = '<h1>Invalid URL</h1>' +
  361. '<div id="openInvalidScheme"></div>' +
  362. 'Expected result: fail to load in InAppBrowser.' +
  363. '<p/> <div id="openInvalidHost"></div>' +
  364. 'Expected result: fail to load in InAppBrowser.' +
  365. '<p/> <div id="openInvalidMissing"></div>' +
  366. 'Expected result: fail to load in InAppBrowser (404).';
  367. var css_js_injection_tests = '<h1>CSS / JS Injection</h1>' +
  368. '<div id="openOriginalDocument"></div>' +
  369. 'Expected result: open successfully in InAppBrowser without text "Style updated from..."' +
  370. '<p/> <div id="openCSSInjection"></div>' +
  371. 'Expected result: open successfully in InAppBrowser with "Style updated from file".' +
  372. '<p/> <div id="openCSSInjectionCallback"></div>' +
  373. 'Expected result: open successfully in InAppBrowser with "Style updated from file", and alert dialog with text "Results verified".' +
  374. '<p/> <div id="openCSSLiteralInjection"></div>' +
  375. 'Expected result: open successfully in InAppBrowser with "Style updated from literal".' +
  376. '<p/> <div id="openCSSLiteralInjectionCallback"></div>' +
  377. 'Expected result: open successfully in InAppBrowser with "Style updated from literal", and alert dialog with text "Results verified".' +
  378. '<p/> <div id="openScriptInjection"></div>' +
  379. 'Expected result: open successfully in InAppBrowser with text "Script file successfully injected".' +
  380. '<p/> <div id="openScriptInjectionCallback"></div>' +
  381. 'Expected result: open successfully in InAppBrowser with text "Script file successfully injected" and alert dialog with the text "Results verified".' +
  382. '<p/> <div id="openScriptLiteralInjection"></div>' +
  383. 'Expected result: open successfully in InAppBrowser with the text "Script literal successfully injected" .' +
  384. '<p/> <div id="openScriptLiteralInjectionCallback"></div>' +
  385. 'Expected result: open successfully in InAppBrowser with the text "Script literal successfully injected" and alert dialog with the text "Results verified".';
  386. var open_hidden_tests = '<h1>Open Hidden </h1>' +
  387. '<div id="openHidden"></div>' +
  388. 'Expected result: no additional browser window. Alert appears with the text "background window loaded".' +
  389. '<p/> <div id="showHidden"></div>' +
  390. 'Expected result: after first clicking on previous test "create hidden", open successfully in InAppBrowser to https://www.google.co.uk.' +
  391. '<p/> <div id="closeHidden"></div>' +
  392. 'Expected result: no output. But click on "show hidden" again and nothing should be shown.' +
  393. '<p/> <div id="openHiddenShow"></div>' +
  394. 'Expected result: open successfully in InAppBrowser to https://www.google.co.uk' +
  395. '<p/> <div id="openVisibleAndHide"></div>' +
  396. 'Expected result: open successfully in InAppBrowser to https://www.google.co.uk. Hide after 2 seconds';
  397. var clearing_cache_tests = '<h1>Clearing Cache</h1>' +
  398. '<div id="openClearCache"></div>' +
  399. 'Expected result: ?' +
  400. '<p/> <div id="openClearSessionCache"></div>' +
  401. 'Expected result: ?';
  402. var video_tag_tests = '<h1>Video tag</h1>' +
  403. '<div id="openRemoteVideo"></div>' +
  404. 'Expected result: open successfully in InAppBrowser with an embedded video plays automatically on iOS and Android.' +
  405. '<div id="openRemoteNeedUserNoVideo"></div>' +
  406. 'Expected result: open successfully in InAppBrowser with an embedded video plays automatically on iOS and Android.' +
  407. '<div id="openRemoteNeedUserYesVideo"></div>' +
  408. '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.';
  409. var local_with_anchor_tag_tests = '<h1>Local with anchor tag</h1>' +
  410. '<div id="openAnchor1"></div>' +
  411. 'Expected result: open successfully in InAppBrowser to the local page, scrolled to the top as normal.' +
  412. '<p/> <div id="openAnchor2"></div>' +
  413. 'Expected result: open successfully in InAppBrowser to the local page, scrolled to the beginning of the tall div with border.';
  414. var hardwareback_tests = '<h1>HardwareBack</h1>' +
  415. '<p/> <div id="openHardwareBackDefault"></div>' +
  416. 'Expected result: By default hardwareback is yes so pressing back button should navigate backwards in history then close InAppBrowser' +
  417. '<p/> <div id="openHardwareBackYes"></div>' +
  418. 'Expected result: hardwareback=yes pressing back button should navigate backwards in history then close InAppBrowser' +
  419. '<p/> <div id="openHardwareBackNo"></div>' +
  420. 'Expected result: hardwareback=no pressing back button should close InAppBrowser regardless history' +
  421. '<p/> <div id="openHardwareBackDefaultAfterNo"></div>' +
  422. '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';
  423. // CB-7490 We need to wrap this code due to Windows security restrictions
  424. // see http://msdn.microsoft.com/en-us/library/windows/apps/hh465380.aspx#differences for details
  425. if (window.MSApp && window.MSApp.execUnsafeLocalFunction) {
  426. MSApp.execUnsafeLocalFunction(function () {
  427. contentEl.innerHTML = info_div + local_tests + white_listed_tests + non_white_listed_tests + page_with_redirects_tests + pdf_url_tests + invalid_url_tests +
  428. css_js_injection_tests + open_hidden_tests + clearing_cache_tests + video_tag_tests + local_with_anchor_tag_tests + hardwareback_tests;
  429. });
  430. } else {
  431. contentEl.innerHTML = info_div + local_tests + white_listed_tests + non_white_listed_tests + page_with_redirects_tests + pdf_url_tests + invalid_url_tests +
  432. css_js_injection_tests + open_hidden_tests + clearing_cache_tests + video_tag_tests + local_with_anchor_tag_tests + hardwareback_tests;
  433. }
  434. document.getElementById('user-agent').textContent = navigator.userAgent;
  435. // we are already in cdvtests directory
  436. var basePath = 'iab-resources/';
  437. var localhtml = basePath + 'local.html';
  438. var localpdf = basePath + 'local.pdf';
  439. var injecthtml = basePath + 'inject.html';
  440. var injectjs = isWindows ? basePath + 'inject.js' : 'inject.js';
  441. var injectcss = isWindows ? basePath + 'inject.css' : 'inject.css';
  442. var videohtml = basePath + 'video.html';
  443. // Local
  444. createActionButton('target=Default', function () {
  445. doOpen(localhtml);
  446. }, 'openLocal');
  447. createActionButton('target=Default (window.open)', function () {
  448. doHookOpen(localhtml);
  449. }, 'openLocalHook');
  450. createActionButton('target=_self', function () {
  451. doOpen(localhtml, '_self');
  452. }, 'openLocalSelf');
  453. createActionButton('target=_system', function () {
  454. doOpen(localhtml, '_system');
  455. }, 'openLocalSystem');
  456. createActionButton('target=_blank', function () {
  457. doOpen(localhtml, '_blank');
  458. }, 'openLocalBlank');
  459. createActionButton('target=Random, location=no, disallowoverscroll=yes', function () {
  460. doOpen(localhtml, 'random_string', 'location=no, disallowoverscroll=yes');
  461. }, 'openLocalRandomNoLocation');
  462. createActionButton('target=Random, toolbarposition=bottom', function () {
  463. doOpen(localhtml, 'random_string', 'toolbarposition=bottom');
  464. }, 'openLocalRandomToolBarBottom');
  465. createActionButton('target=Random, toolbarposition=top', function () {
  466. doOpen(localhtml, 'random_string', 'toolbarposition=top');
  467. }, 'openLocalRandomToolBarTop');
  468. createActionButton('target=Random, toolbarposition=top, location=no', function () {
  469. doOpen(localhtml, 'random_string', 'toolbarposition=top,location=no');
  470. }, 'openLocalRandomToolBarTopNoLocation');
  471. // White Listed
  472. createActionButton('* target=Default', function () {
  473. doOpen('http://cordova.apache.org');
  474. }, 'openWhiteListed');
  475. createActionButton('* target=Default (window.open)', function () {
  476. doHookOpen('http://cordova.apache.org');
  477. }, 'openWhiteListedHook');
  478. createActionButton('* target=_self', function () {
  479. doOpen('http://cordova.apache.org', '_self');
  480. }, 'openWhiteListedSelf');
  481. createActionButton('target=_system', function () {
  482. doOpen('http://cordova.apache.org', '_system');
  483. }, 'openWhiteListedSystem');
  484. createActionButton('target=_blank', function () {
  485. doOpen('http://cordova.apache.org', '_blank');
  486. }, 'openWhiteListedBlank');
  487. createActionButton('target=Random', function () {
  488. doOpen('http://cordova.apache.org', 'random_string');
  489. }, 'openWhiteListedRandom');
  490. createActionButton('* target=Random, no location bar', function () {
  491. doOpen('http://cordova.apache.org', 'random_string', 'location=no');
  492. }, 'openWhiteListedRandomNoLocation');
  493. // Non White Listed
  494. createActionButton('target=Default', function () {
  495. doOpen('http://www.apple.com');
  496. }, 'openNonWhiteListed');
  497. createActionButton('target=Default (window.open)', function () {
  498. doHookOpen('http://www.apple.com');
  499. }, 'openNonWhiteListedHook');
  500. createActionButton('target=_self', function () {
  501. doOpen('http://www.apple.com', '_self');
  502. }, 'openNonWhiteListedSelf');
  503. createActionButton('target=_system', function () {
  504. doOpen('http://www.apple.com', '_system');
  505. }, 'openNonWhiteListedSystem');
  506. createActionButton('target=_blank', function () {
  507. doOpen('http://www.apple.com', '_blank');
  508. }, 'openNonWhiteListedBlank');
  509. createActionButton('target=Random', function () {
  510. doOpen('http://www.apple.com', 'random_string');
  511. }, 'openNonWhiteListedRandom');
  512. createActionButton('* target=Random, no location bar', function () {
  513. doOpen('http://www.apple.com', 'random_string', 'location=no');
  514. }, 'openNonWhiteListedRandomNoLocation');
  515. // Page with redirect
  516. createActionButton('http://google.co.uk', function () {
  517. doOpen('http://google.co.uk', 'random_string', '', 1);
  518. }, 'openRedirect301');
  519. createActionButton('http://goo.gl/pUFqg', function () {
  520. doOpen('http://goo.gl/pUFqg', 'random_string', '', 2);
  521. }, 'openRedirect302');
  522. // PDF URL
  523. createActionButton('Remote URL', function () {
  524. doOpen('http://www.stluciadance.com/prospectus_file/sample.pdf');
  525. }, 'openPDF');
  526. createActionButton('Local URL', function () {
  527. doOpen(localpdf, '_blank');
  528. }, 'openPDFBlank');
  529. // Invalid URL
  530. createActionButton('Invalid Scheme', function () {
  531. doOpen('x-ttp://www.invalid.com/', '_blank');
  532. }, 'openInvalidScheme');
  533. createActionButton('Invalid Host', function () {
  534. doOpen('http://www.inv;alid.com/', '_blank');
  535. }, 'openInvalidHost');
  536. createActionButton('Missing Local File', function () {
  537. doOpen('nonexistent.html', '_blank');
  538. }, 'openInvalidMissing');
  539. // CSS / JS injection
  540. createActionButton('Original Document', function () {
  541. doOpen(injecthtml, '_blank');
  542. }, 'openOriginalDocument');
  543. createActionButton('CSS File Injection', function () {
  544. openWithStyle(injecthtml, injectcss);
  545. }, 'openCSSInjection');
  546. createActionButton('CSS File Injection (callback)', function () {
  547. openWithStyle(injecthtml, injectcss, true);
  548. }, 'openCSSInjectionCallback');
  549. createActionButton('CSS Literal Injection', function () {
  550. openWithStyle(injecthtml);
  551. }, 'openCSSLiteralInjection');
  552. createActionButton('CSS Literal Injection (callback)', function () {
  553. openWithStyle(injecthtml, null, true);
  554. }, 'openCSSLiteralInjectionCallback');
  555. createActionButton('Script File Injection', function () {
  556. openWithScript(injecthtml, injectjs);
  557. }, 'openScriptInjection');
  558. createActionButton('Script File Injection (callback)', function () {
  559. openWithScript(injecthtml, injectjs, true);
  560. }, 'openScriptInjectionCallback');
  561. createActionButton('Script Literal Injection', function () {
  562. openWithScript(injecthtml);
  563. }, 'openScriptLiteralInjection');
  564. createActionButton('Script Literal Injection (callback)', function () {
  565. openWithScript(injecthtml, null, true);
  566. }, 'openScriptLiteralInjectionCallback');
  567. // Open hidden
  568. createActionButton('Create Hidden', function () {
  569. openHidden('https://www.google.co.uk', true);
  570. }, 'openHidden');
  571. createActionButton('Show Hidden', function () {
  572. showHidden();
  573. }, 'showHidden');
  574. createActionButton('Close Hidden', function () {
  575. closeHidden();
  576. }, 'closeHidden');
  577. createActionButton('google.co.uk Not Hidden', function () {
  578. openHidden('https://www.google.co.uk', false);
  579. }, 'openHiddenShow');
  580. createActionButton('google.co.uk shown for 2 seconds than hidden', function () {
  581. var iab = doOpen('https://www.google.co.uk/', 'random_sting');
  582. setTimeout(function () {
  583. iab.hide();
  584. }, 2000);
  585. }, 'openVisibleAndHide');
  586. // Clearing cache
  587. createActionButton('Clear Browser Cache', function () {
  588. doOpen('https://www.google.co.uk', '_blank', 'clearcache=yes');
  589. }, 'openClearCache');
  590. createActionButton('Clear Session Cache', function () {
  591. doOpen('https://www.google.co.uk', '_blank', 'clearsessioncache=yes');
  592. }, 'openClearSessionCache');
  593. // Video tag
  594. createActionButton('Remote Video', function () {
  595. doOpen(videohtml, '_blank');
  596. }, 'openRemoteVideo');
  597. createActionButton('Remote Need User No Video', function () {
  598. doOpen(videohtml, '_blank', 'mediaPlaybackRequiresUserAction=no');
  599. }, 'openRemoteNeedUserNoVideo');
  600. createActionButton('Remote Need User Yes Video', function () {
  601. doOpen(videohtml, '_blank', 'mediaPlaybackRequiresUserAction=yes');
  602. }, 'openRemoteNeedUserYesVideo');
  603. // Local With Anchor Tag
  604. createActionButton('Anchor1', function () {
  605. doOpen(localhtml + '#bogusanchor', '_blank');
  606. }, 'openAnchor1');
  607. createActionButton('Anchor2', function () {
  608. doOpen(localhtml + '#anchor2', '_blank');
  609. }, 'openAnchor2');
  610. // Hardwareback
  611. createActionButton('no hardwareback (defaults to yes)', function () {
  612. doOpen('http://cordova.apache.org', '_blank');
  613. }, 'openHardwareBackDefault');
  614. createActionButton('hardwareback=yes', function () {
  615. doOpen('http://cordova.apache.org', '_blank', 'hardwareback=yes');
  616. }, 'openHardwareBackYes');
  617. createActionButton('hardwareback=no', function () {
  618. doOpen('http://cordova.apache.org', '_blank', 'hardwareback=no');
  619. }, 'openHardwareBackNo');
  620. createActionButton('no hardwareback -> hardwareback=no -> no hardwareback', function () {
  621. var ref = cordova.InAppBrowser.open('https://google.com', '_blank', 'location=yes');
  622. ref.addEventListener('loadstop', function () {
  623. ref.close();
  624. });
  625. ref.addEventListener('exit', function () {
  626. var ref2 = cordova.InAppBrowser.open('https://google.com', '_blank', 'location=yes,hardwareback=no');
  627. ref2.addEventListener('loadstop', function () {
  628. ref2.close();
  629. });
  630. ref2.addEventListener('exit', function () {
  631. cordova.InAppBrowser.open('https://google.com', '_blank', 'location=yes');
  632. });
  633. });
  634. }, 'openHardwareBackDefaultAfterNo');
  635. };