diff options
Diffstat (limited to 'StoneIsland/plugins/cordova-plugin-inappbrowser/tests/tests.js')
| -rw-r--r--[-rwxr-xr-x] | StoneIsland/plugins/cordova-plugin-inappbrowser/tests/tests.js | 155 |
1 files changed, 145 insertions, 10 deletions
diff --git a/StoneIsland/plugins/cordova-plugin-inappbrowser/tests/tests.js b/StoneIsland/plugins/cordova-plugin-inappbrowser/tests/tests.js index a8279868..1a96029d 100755..100644 --- a/StoneIsland/plugins/cordova-plugin-inappbrowser/tests/tests.js +++ b/StoneIsland/plugins/cordova-plugin-inappbrowser/tests/tests.js @@ -19,11 +19,118 @@ * */ +/* jshint jasmine: true */ +/* global MSApp */ + var cordova = require('cordova'); var isWindows = cordova.platformId == 'windows'; window.alert = window.alert || navigator.notification.alert; +exports.defineAutoTests = function () { + + describe('cordova.InAppBrowser', function () { + + it("inappbrowser.spec.1 should exist", function () { + expect(cordova.InAppBrowser).toBeDefined(); + }); + + it("inappbrowser.spec.2 should contain open function", function () { + expect(cordova.InAppBrowser.open).toBeDefined(); + expect(cordova.InAppBrowser.open).toEqual(jasmine.any(Function)); + }); + }); + + describe('open method', function () { + + var iabInstance; + var originalTimeout; + var url = 'https://dist.apache.org/repos/dist/dev/cordova/'; + var badUrl = 'http://bad-uri/'; + + beforeEach(function () { + // increase timeout to ensure test url could be loaded within test time + originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; + jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000; + + iabInstance = null; + }); + + afterEach(function (done) { + // restore original timeout + jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; + + if (iabInstance !== null && iabInstance.close) { + iabInstance.close(); + } + iabInstance = null; + // add some extra time so that iab dialog is closed + setTimeout(done, 2000); + }); + + function verifyEvent(evt, type) { + expect(evt).toBeDefined(); + expect(evt.type).toEqual(type); + if (type !== 'exit') { // `exit` event does not have url field + expect(evt.url).toEqual(url); + } + } + + function verifyLoadErrorEvent(evt) { + expect(evt).toBeDefined(); + expect(evt.type).toEqual('loaderror'); + expect(evt.url).toEqual(badUrl); + expect(evt.code).toEqual(jasmine.any(Number)); + expect(evt.message).toEqual(jasmine.any(String)); + } + + it("inappbrowser.spec.3 should retun InAppBrowser instance with required methods", function () { + iabInstance = cordova.InAppBrowser.open(url, '_blank'); + + expect(iabInstance).toBeDefined(); + + expect(iabInstance.addEventListener).toEqual(jasmine.any(Function)); + expect(iabInstance.removeEventListener).toEqual(jasmine.any(Function)); + expect(iabInstance.close).toEqual(jasmine.any(Function)); + expect(iabInstance.show).toEqual(jasmine.any(Function)); + expect(iabInstance.executeScript).toEqual(jasmine.any(Function)); + expect(iabInstance.insertCSS).toEqual(jasmine.any(Function)); + }); + + it("inappbrowser.spec.4 should support loadstart and loadstop events", function (done) { + var onLoadStart = jasmine.createSpy('loadstart event callback').and.callFake(function (evt) { + verifyEvent(evt, 'loadstart'); + }); + + iabInstance = cordova.InAppBrowser.open(url, '_blank'); + iabInstance.addEventListener('loadstart', onLoadStart); + iabInstance.addEventListener('loadstop', function (evt) { + verifyEvent(evt, 'loadstop'); + expect(onLoadStart).toHaveBeenCalled(); + done(); + }); + }); + + it("inappbrowser.spec.5 should support exit event", function (done) { + iabInstance = cordova.InAppBrowser.open(url, '_blank'); + iabInstance.addEventListener('exit', function (evt) { + verifyEvent(evt, 'exit'); + done(); + }); + iabInstance.close(); + iabInstance = null; + }); + + it("inappbrowser.spec.6 should support loaderror event", function (done) { + iabInstance = cordova.InAppBrowser.open(badUrl, '_blank'); + iabInstance.addEventListener('loaderror', function (evt) { + verifyLoadErrorEvent(evt); + done(); + }); + }); + }); +}; + exports.defineManualTests = function (contentEl, createActionButton) { function doOpen(url, target, params, numExpectedRedirects, useWindowOpen) { @@ -79,13 +186,13 @@ exports.defineManualTests = function (contentEl, createActionButton) { if (e.url != lastLoadStartURL) { alert('Unexpected: ' + e.type + ' event.url != loadstart\'s event.url'); } - if (numExpectedRedirects === 0 && counts['loadstart'] !== 1) { + if (numExpectedRedirects === 0 && counts.loadstart !== 1) { // Do allow a loaderror without a loadstart (e.g. in the case of an invalid URL). - if (!(e.type == 'loaderror' && counts['loadstart'] === 0)) { - alert('Unexpected: got multiple loadstart events. (' + counts['loadstart'] + ')'); + if (!(e.type == 'loaderror' && counts.loadstart === 0)) { + alert('Unexpected: got multiple loadstart events. (' + counts.loadstart + ')'); } - } else if (numExpectedRedirects > 0 && counts['loadstart'] < (numExpectedRedirects + 1)) { - alert('Unexpected: should have got at least ' + (numExpectedRedirects + 1) + ' loadstart events, but got ' + counts['loadstart']); + } else if (numExpectedRedirects > 0 && counts.loadstart < (numExpectedRedirects + 1)) { + alert('Unexpected: should have got at least ' + (numExpectedRedirects + 1) + ' loadstart events, but got ' + counts.loadstart); } wasReset = true; numExpectedRedirects = 0; @@ -93,7 +200,7 @@ exports.defineManualTests = function (contentEl, createActionButton) { } // Verify that loadend / loaderror was called. if (e.type == 'exit') { - var numStopEvents = counts['loadstop'] + counts['loaderror']; + var numStopEvents = counts.loadstop + counts.loaderror; if (numStopEvents === 0 && !wasReset) { alert('Unexpected: browser closed without a loadstop or loaderror.'); } else if (numStopEvents > 1) { @@ -319,7 +426,11 @@ exports.defineManualTests = function (contentEl, createActionButton) { var video_tag_tests = '<h1>Video tag</h1>' + '<div id="openRemoteVideo"></div>' + - 'Expected result: open successfully in InAppBrowser with an embedded video that works after clicking the "play" button.'; + '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.'; var local_with_anchor_tag_tests = '<h1>Local with anchor tag</h1>' + '<div id="openAnchor1"></div>' + @@ -327,16 +438,24 @@ exports.defineManualTests = function (contentEl, createActionButton) { '<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.'; + var hardwareback_tests = '<h1>HardwareBack</h1>' + + '<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>' + + 'Expected result: hardwareback=no pressing back button should close InAppBrowser regardless history'; + // 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) { MSApp.execUnsafeLocalFunction(function() { contentEl.innerHTML = info_div + 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; + css_js_injection_tests + open_hidden_tests + clearing_cache_tests + video_tag_tests + local_with_anchor_tag_tests + hardwareback_tests; }); } else { contentEl.innerHTML = info_div + 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; + css_js_injection_tests + open_hidden_tests + clearing_cache_tests + video_tag_tests + local_with_anchor_tag_tests + hardwareback_tests; } document.getElementById("user-agent").textContent = navigator.userAgent; @@ -507,6 +626,12 @@ exports.defineManualTests = function (contentEl, createActionButton) { 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'); //Local With Anchor Tag createActionButton('Anchor1', function () { @@ -515,5 +640,15 @@ exports.defineManualTests = function (contentEl, createActionButton) { createActionButton('Anchor2', function () { doOpen(localhtml + '#anchor2', '_blank'); }, 'openAnchor2'); -}; + // Hardwareback + 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'); +}; |
