UNPKG

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