Compare commits

..

1 Commits

Author SHA1 Message Date
sgrebnov 79e35d9790 CB-10441 Add auto tests for InAppBrowser plugin 2016-01-27 13:00:28 +03:00
8 changed files with 213 additions and 297 deletions
-12
View File
@@ -20,18 +20,6 @@
--> -->
# Release Notes # Release Notes
### 1.2.1 (Feb 02, 2016)
* [CB-10407](https://issues.apache.org/jira/browse/CB-10407) InAppBrowser not firing loadstart event on android
* [CB-10428](https://issues.apache.org/jira/browse/CB-10428) Fix syntax error when browserifying inAppBrowser plugin
* handle app store urls in system browser
* [CB-6702](https://issues.apache.org/jira/browse/CB-6702) InAppBrowser hangs when opening more than one instance
* [CB-10456](https://issues.apache.org/jira/browse/CB-10456) InAppBrowser is not closed if I close it programmatically on Android
* [CB-10451](https://issues.apache.org/jira/browse/CB-10451) InAppBrowser: loadstart event is not triggered on Windows
* [CB-10452](https://issues.apache.org/jira/browse/CB-10452) InAppBrowser: 'exit' event is not triggered on Windows
* [CB-10454](https://issues.apache.org/jira/browse/CB-10454) InAppBrowser: 'loaderror' event does not have code and message on Windows
* [CB-10450](https://issues.apache.org/jira/browse/CB-10450) InAppBrowser: Unable to get property 'canGoBack' of undefined on Windows
* [CB-10441](https://issues.apache.org/jira/browse/CB-10441) Add auto tests for InAppBrowser plugin
### 1.2.0 (Jan 15, 2016) ### 1.2.0 (Jan 15, 2016)
* CB-8180: Changing methods of interception in `WebViewClient` class * CB-8180: Changing methods of interception in `WebViewClient` class
* CB-10009 Improve `InAppBrowser` toolbar look and feel on **Windows** * CB-10009 Improve `InAppBrowser` toolbar look and feel on **Windows**
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "cordova-plugin-inappbrowser", "name": "cordova-plugin-inappbrowser",
"version": "1.2.1", "version": "1.2.1-dev",
"description": "Cordova InAppBrowser Plugin", "description": "Cordova InAppBrowser Plugin",
"cordova": { "cordova": {
"id": "cordova-plugin-inappbrowser", "id": "cordova-plugin-inappbrowser",
+1 -1
View File
@@ -20,7 +20,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="cordova-plugin-inappbrowser" id="cordova-plugin-inappbrowser"
version="1.2.1"> version="1.2.1-dev">
<name>InAppBrowser</name> <name>InAppBrowser</name>
<description>Cordova InAppBrowser Plugin</description> <description>Cordova InAppBrowser Plugin</description>
+14 -22
View File
@@ -362,22 +362,20 @@ public class InAppBrowser extends CordovaPlugin {
* Closes the dialog * Closes the dialog
*/ */
public void closeDialog() { public void closeDialog() {
final WebView childView = this.inAppWebView;
// The JS protects against multiple calls, so this should happen only when
// closeDialog() is called by other native code.
if (childView == null) {
return;
}
this.cordova.getActivity().runOnUiThread(new Runnable() { this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
final WebView childView = inAppWebView;
// The JS protects against multiple calls, so this should happen only when
// closeDialog() is called by other native code.
if (childView == null) {
return;
}
childView.setWebViewClient(new WebViewClient() { childView.setWebViewClient(new WebViewClient() {
// NB: wait for about:blank before dismissing // NB: wait for about:blank before dismissing
public void onPageFinished(WebView view, String url) { public void onPageFinished(WebView view, String url) {
if (dialog != null) { if (dialog != null) {
dialog.dismiss(); dialog.dismiss();
dialog = null;
} }
} }
}); });
@@ -385,16 +383,16 @@ public class InAppBrowser extends CordovaPlugin {
// other than your app's UI thread, it can cause unexpected results." // other than your app's UI thread, it can cause unexpected results."
// http://developer.android.com/guide/webapps/migrating.html#Threads // http://developer.android.com/guide/webapps/migrating.html#Threads
childView.loadUrl("about:blank"); childView.loadUrl("about:blank");
try {
JSONObject obj = new JSONObject();
obj.put("type", EXIT_EVENT);
sendUpdate(obj, false);
} catch (JSONException ex) {
Log.d(LOG_TAG, "Should never happen");
}
} }
}); });
try {
JSONObject obj = new JSONObject();
obj.put("type", EXIT_EVENT);
sendUpdate(obj, false);
} catch (JSONException ex) {
Log.d(LOG_TAG, "Should never happen");
}
} }
/** /**
@@ -521,12 +519,6 @@ public class InAppBrowser extends CordovaPlugin {
@SuppressLint("NewApi") @SuppressLint("NewApi")
public void run() { public void run() {
// CB-6702 InAppBrowser hangs when opening more than one instance
if (dialog != null) {
dialog.dismiss();
};
// Let's create the main dialog // Let's create the main dialog
dialog = new InAppBrowserDialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar); dialog = new InAppBrowserDialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar);
dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog; dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
+1 -8
View File
@@ -390,14 +390,7 @@
[self.commandDelegate sendPluginResult:pluginResult callbackId:scriptCallbackId]; [self.commandDelegate sendPluginResult:pluginResult callbackId:scriptCallbackId];
return NO; return NO;
} }
} } else if ((self.callbackId != nil) && isTopLevelNavigation) {
//if is an app store link, let the system handle it, otherwise it fails to load it
else if ([[ url scheme] isEqualToString:@"itms-appss"] || [[ url scheme] isEqualToString:@"itms-apps"]) {
[theWebView stopLoading];
[self openInSystem:url];
return NO;
}
else if ((self.callbackId != nil) && isTopLevelNavigation) {
// Send a loadstart event for each top-level navigation (includes redirects). // Send a loadstart event for each top-level navigation (includes redirects).
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsDictionary:@{@"type":@"loadstart", @"url":[url absoluteString]}]; messageAsDictionary:@{@"type":@"loadstart", @"url":[url absoluteString]}];
+176 -199
View File
@@ -25,6 +25,7 @@
var cordova = require('cordova'), var cordova = require('cordova'),
channel = require('cordova/channel'),
urlutil = require('cordova/urlutil'); urlutil = require('cordova/urlutil');
var browserWrap, var browserWrap,
@@ -34,12 +35,11 @@ var browserWrap,
backButton, backButton,
forwardButton, forwardButton,
closeButton, closeButton,
bodyOverflowStyle, bodyOverflowStyle;
navigationEventsCallback;
// x-ms-webview is available starting from Windows 8.1 (platformId is 'windows') // x-ms-webview is available starting from Windows 8.1 (platformId is 'windows')
// http://msdn.microsoft.com/en-us/library/windows/apps/dn301831.aspx // http://msdn.microsoft.com/en-us/library/windows/apps/dn301831.aspx
var isWebViewAvailable = cordova.platformId === 'windows'; var isWebViewAvailable = cordova.platformId == 'windows';
function attachNavigationEvents(element, callback) { function attachNavigationEvents(element, callback) {
if (isWebViewAvailable) { if (isWebViewAvailable) {
@@ -48,21 +48,17 @@ function attachNavigationEvents(element, callback) {
}); });
element.addEventListener("MSWebViewNavigationCompleted", function (e) { element.addEventListener("MSWebViewNavigationCompleted", function (e) {
if (e.isSuccess) { callback({ type: e.isSuccess ? "loadstop" : "loaderror", url: e.uri}, {keepCallback: true});
callback({ type: "loadstop", url: e.uri }, { keepCallback: true });
} else {
callback({ type: "loaderror", url: e.uri, code: e.webErrorStatus, message: "Navigation failed with error code " + e.webErrorStatus}, { keepCallback: true });
}
}); });
element.addEventListener("MSWebViewUnviewableContentIdentified", function (e) { element.addEventListener("MSWebViewUnviewableContentIdentified", function (e) {
// WebView found the content to be not HTML. // WebView found the content to be not HTML.
// http://msdn.microsoft.com/en-us/library/windows/apps/dn609716.aspx // http://msdn.microsoft.com/en-us/library/windows/apps/dn609716.aspx
callback({ type: "loaderror", url: e.uri, code: e.webErrorStatus, message: "Navigation failed with error code " + e.webErrorStatus}, { keepCallback: true }); callback({ type: "loaderror", url: e.uri}, {keepCallback: true});
}); });
element.addEventListener("MSWebViewContentLoading", function (e) { element.addEventListener("MSWebViewContentLoading", function (e) {
if (navigationButtonsDiv && popup) { if (navigationButtonsDiv) {
if (popup.canGoBack) { if (popup.canGoBack) {
backButton.removeAttribute("disabled"); backButton.removeAttribute("disabled");
} else { } else {
@@ -96,228 +92,209 @@ function attachNavigationEvents(element, callback) {
var IAB = { var IAB = {
close: function (win, lose) { close: function (win, lose) {
setImmediate(function () { if (browserWrap) {
if (browserWrap) { if (win) win({ type: "exit" });
if (navigationEventsCallback) {
navigationEventsCallback({ type: "exit" });
}
browserWrap.parentNode.removeChild(browserWrap); browserWrap.parentNode.removeChild(browserWrap);
// Reset body overflow style to initial value // Reset body overflow style to initial value
document.body.style.msOverflowStyle = bodyOverflowStyle; document.body.style.msOverflowStyle = bodyOverflowStyle;
browserWrap = null; browserWrap = null;
popup = null; popup = null;
} }
});
}, },
show: function (win, lose) { show: function (win, lose) {
setImmediate(function () { if (browserWrap) {
if (browserWrap) { browserWrap.style.display = "block";
browserWrap.style.display = "block"; }
}
});
}, },
open: function (win, lose, args) { open: function (win, lose, args) {
// make function async so that we can add navigation events handlers before view is loaded and navigation occured var strUrl = args[0],
setImmediate(function () { target = args[1],
var strUrl = args[0], features = args[2],
target = args[1], url;
features = args[2],
url;
navigationEventsCallback = win; if (target === "_system") {
url = new Windows.Foundation.Uri(strUrl);
Windows.System.Launcher.launchUriAsync(url);
} else if (target === "_self" || !target) {
window.location = strUrl;
} else {
// "_blank" or anything else
if (!browserWrap) {
var browserWrapStyle = document.createElement('link');
browserWrapStyle.rel = "stylesheet";
browserWrapStyle.type = "text/css";
browserWrapStyle.href = urlutil.makeAbsolute("/www/css/inappbrowser.css");
if (target === "_system") { document.head.appendChild(browserWrapStyle);
url = new Windows.Foundation.Uri(strUrl);
Windows.System.Launcher.launchUriAsync(url);
} else if (target === "_self" || !target) {
window.location = strUrl;
} else {
// "_blank" or anything else
if (!browserWrap) {
var browserWrapStyle = document.createElement('link');
browserWrapStyle.rel = "stylesheet";
browserWrapStyle.type = "text/css";
browserWrapStyle.href = urlutil.makeAbsolute("/www/css/inappbrowser.css");
document.head.appendChild(browserWrapStyle); browserWrap = document.createElement("div");
browserWrap.className = "inAppBrowserWrap";
browserWrap = document.createElement("div"); if (features.indexOf("fullscreen=yes") > -1) {
browserWrap.className = "inAppBrowserWrap"; browserWrap.classList.add("inAppBrowserWrapFullscreen");
if (features.indexOf("fullscreen=yes") > -1) {
browserWrap.classList.add("inAppBrowserWrapFullscreen");
}
// Save body overflow style to be able to reset it back later
bodyOverflowStyle = document.body.style.msOverflowStyle;
browserWrap.onclick = function () {
setTimeout(function () {
IAB.close(navigationEventsCallback);
}, 0);
};
document.body.appendChild(browserWrap);
// Hide scrollbars for the whole body while inappbrowser's window is open
document.body.style.msOverflowStyle = "none";
} }
if (features.indexOf("hidden=yes") !== -1) { // Save body overflow style to be able to reset it back later
browserWrap.style.display = "none"; bodyOverflowStyle = document.body.style.msOverflowStyle;
}
popup = document.createElement(isWebViewAvailable ? "x-ms-webview" : "iframe"); browserWrap.onclick = function () {
if (popup instanceof HTMLIFrameElement) { setTimeout(function () {
// For iframe we need to override bacground color of parent element here IAB.close(win);
// otherwise pages without background color set will have transparent background }, 0);
popup.style.backgroundColor = "white"; };
}
popup.style.borderWidth = "0px";
popup.style.width = "100%";
browserWrap.appendChild(popup); document.body.appendChild(browserWrap);
// Hide scrollbars for the whole body while inappbrowser's window is open
if (features.indexOf("location=yes") !== -1 || features.indexOf("location") === -1) { document.body.style.msOverflowStyle = "none";
popup.style.height = "calc(100% - 70px)";
navigationButtonsDiv = document.createElement("div");
navigationButtonsDiv.className = "inappbrowser-app-bar";
navigationButtonsDiv.onclick = function (e) {
e.cancelBubble = true;
};
navigationButtonsDivInner = document.createElement("div");
navigationButtonsDivInner.className = "inappbrowser-app-bar-inner"
navigationButtonsDivInner.onclick = function (e) {
e.cancelBubble = true;
};
backButton = document.createElement("div");
backButton.innerText = "back";
backButton.className = "app-bar-action action-back";
backButton.addEventListener("click", function (e) {
if (popup.canGoBack)
popup.goBack();
});
forwardButton = document.createElement("div");
forwardButton.innerText = "forward";
forwardButton.className = "app-bar-action action-forward";
forwardButton.addEventListener("click", function (e) {
if (popup.canGoForward)
popup.goForward();
});
closeButton = document.createElement("div");
closeButton.innerText = "close";
closeButton.className = "app-bar-action action-close";
closeButton.addEventListener("click", function (e) {
setTimeout(function () {
IAB.close(navigationEventsCallback);
}, 0);
});
if (!isWebViewAvailable) {
// iframe navigation is not yet supported
backButton.setAttribute("disabled", "true");
forwardButton.setAttribute("disabled", "true");
}
navigationButtonsDivInner.appendChild(backButton);
navigationButtonsDivInner.appendChild(forwardButton);
navigationButtonsDivInner.appendChild(closeButton);
navigationButtonsDiv.appendChild(navigationButtonsDivInner);
browserWrap.appendChild(navigationButtonsDiv);
} else {
popup.style.height = "100%";
}
// start listening for navigation events
attachNavigationEvents(popup, navigationEventsCallback);
if (isWebViewAvailable) {
strUrl = strUrl.replace("ms-appx://", "ms-appx-web://");
}
popup.src = strUrl;
} }
});
if (features.indexOf("hidden=yes") !== -1) {
browserWrap.style.display = "none";
}
popup = document.createElement(isWebViewAvailable ? "x-ms-webview" : "iframe");
if (popup instanceof HTMLIFrameElement) {
// For iframe we need to override bacground color of parent element here
// otherwise pages without background color set will have transparent background
popup.style.backgroundColor = "white";
}
popup.style.borderWidth = "0px";
popup.style.width = "100%";
browserWrap.appendChild(popup);
if (features.indexOf("location=yes") !== -1 || features.indexOf("location") === -1) {
popup.style.height = "calc(100% - 70px)";
navigationButtonsDiv = document.createElement("div");
navigationButtonsDiv.className = "inappbrowser-app-bar";
navigationButtonsDiv.onclick = function (e) {
e.cancelBubble = true;
};
navigationButtonsDivInner = document.createElement("div");
navigationButtonsDivInner.className = "inappbrowser-app-bar-inner"
navigationButtonsDivInner.onclick = function (e) {
e.cancelBubble = true;
};
backButton = document.createElement("div");
backButton.innerText = "back";
backButton.className = "app-bar-action action-back";
backButton.addEventListener("click", function (e) {
if (popup.canGoBack)
popup.goBack();
});
forwardButton = document.createElement("div");
forwardButton.innerText = "forward";
forwardButton.className = "app-bar-action action-forward";
forwardButton.addEventListener("click", function (e) {
if (popup.canGoForward)
popup.goForward();
});
closeButton = document.createElement("div");
closeButton.innerText = "close";
closeButton.className = "app-bar-action action-close";
closeButton.addEventListener("click", function (e) {
setTimeout(function () {
IAB.close(win);
}, 0);
});
if (!isWebViewAvailable) {
// iframe navigation is not yet supported
backButton.setAttribute("disabled", "true");
forwardButton.setAttribute("disabled", "true");
}
navigationButtonsDivInner.appendChild(backButton);
navigationButtonsDivInner.appendChild(forwardButton);
navigationButtonsDivInner.appendChild(closeButton);
navigationButtonsDiv.appendChild(navigationButtonsDivInner);
browserWrap.appendChild(navigationButtonsDiv);
} else {
popup.style.height = "100%";
}
// start listening for navigation events
attachNavigationEvents(popup, win);
if (isWebViewAvailable) {
strUrl = strUrl.replace("ms-appx://", "ms-appx-web://");
}
popup.src = strUrl;
}
}, },
injectScriptCode: function (win, fail, args) { injectScriptCode: function (win, fail, args) {
setImmediate(function () { var code = args[0],
var code = args[0], hasCallback = args[1];
hasCallback = args[1];
if (isWebViewAvailable && browserWrap && popup) { if (isWebViewAvailable && browserWrap && popup) {
var op = popup.invokeScriptAsync("eval", code); var op = popup.invokeScriptAsync("eval", code);
op.oncomplete = function (e) { op.oncomplete = function (e) {
// return null if event target is unavailable by some reason // return null if event target is unavailable by some reason
var result = (e && e.target) ? [e.target.result] : [null]; var result = (e && e.target) ? [e.target.result] : [null];
hasCallback && win(result); hasCallback && win(result);
}; };
op.onerror = function () { }; op.onerror = function () { };
op.start(); op.start();
} }
});
}, },
injectScriptFile: function (win, fail, args) { injectScriptFile: function (win, fail, args) {
setImmediate(function () { var filePath = args[0],
var filePath = args[0], hasCallback = args[1];
hasCallback = args[1];
if (!!filePath) { if (!!filePath) {
filePath = urlutil.makeAbsolute(filePath); filePath = urlutil.makeAbsolute(filePath);
} }
if (isWebViewAvailable && browserWrap && popup) { if (isWebViewAvailable && browserWrap && popup) {
var uri = new Windows.Foundation.Uri(filePath); var uri = new Windows.Foundation.Uri(filePath);
Windows.Storage.StorageFile.getFileFromApplicationUriAsync(uri).done(function (file) { Windows.Storage.StorageFile.getFileFromApplicationUriAsync(uri).done(function (file) {
Windows.Storage.FileIO.readTextAsync(file).done(function (code) { Windows.Storage.FileIO.readTextAsync(file).done(function (code) {
var op = popup.invokeScriptAsync("eval", code); var op = popup.invokeScriptAsync("eval", code);
op.oncomplete = function(e) { op.oncomplete = function(e) {
var result = [e.target.result]; var result = [e.target.result];
hasCallback && win(result); hasCallback && win(result);
}; };
op.onerror = function () { }; op.onerror = function () { };
op.start(); op.start();
});
}); });
} });
}); }
}, },
injectStyleCode: function (win, fail, args) { injectStyleCode: function (win, fail, args) {
setImmediate(function () { var code = args[0],
var code = args[0], hasCallback = args[1];
hasCallback = args[1];
if (isWebViewAvailable && browserWrap && popup) { if (isWebViewAvailable && browserWrap && popup) {
injectCSS(popup, code, hasCallback && win); injectCSS(popup, code, hasCallback && win);
} }
});
}, },
injectStyleFile: function (win, fail, args) { injectStyleFile: function (win, fail, args) {
setImmediate(function () { var filePath = args[0],
var filePath = args[0], hasCallback = args[1];
hasCallback = args[1];
filePath = filePath && urlutil.makeAbsolute(filePath); filePath = filePath && urlutil.makeAbsolute(filePath);
if (isWebViewAvailable && browserWrap && popup) { if (isWebViewAvailable && browserWrap && popup) {
var uri = new Windows.Foundation.Uri(filePath); var uri = new Windows.Foundation.Uri(filePath);
Windows.Storage.StorageFile.getFileFromApplicationUriAsync(uri).then(function (file) { Windows.Storage.StorageFile.getFileFromApplicationUriAsync(uri).then(function (file) {
return Windows.Storage.FileIO.readTextAsync(file); return Windows.Storage.FileIO.readTextAsync(file);
}).done(function (code) { }).done(function (code) {
injectCSS(popup, code, hasCallback && win); injectCSS(popup, code, hasCallback && win);
}, function () { }, function () {
// no-op, just catch an error // no-op, just catch an error
}); });
} }
});
} }
}; };
+1 -3
View File
@@ -20,12 +20,10 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="cordova-plugin-inappbrowser-tests" id="cordova-plugin-inappbrowser-tests"
version="1.2.1"> version="1.2.1-dev">
<name>Cordova InAppBrowser Plugin Tests</name> <name>Cordova InAppBrowser Plugin Tests</name>
<license>Apache 2.0</license> <license>Apache 2.0</license>
<dependency id="cordova-plugin-dialogs" />
<js-module src="tests.js" name="tests"> <js-module src="tests.js" name="tests">
</js-module> </js-module>
+19 -51
View File
@@ -34,64 +34,50 @@ exports.defineAutoTests = function () {
it("inappbrowser.spec.2 should contain open function", function () { it("inappbrowser.spec.2 should contain open function", function () {
expect(cordova.InAppBrowser.open).toBeDefined(); expect(cordova.InAppBrowser.open).toBeDefined();
expect(cordova.InAppBrowser.open).toEqual(jasmine.any(Function)); expect(typeof cordova.InAppBrowser.open === 'function').toBe(true);
}); });
}); });
describe('open method', function () { describe('open method', function () {
var iabInstance; var iabInsance;
var originalTimeout; var originalTimeout;
var url = 'http://apache.org/'; var url = 'http://apache.org/';
var badUrl = 'http://bad-uri/';
beforeEach(function () { beforeEach(function () {
// increase timeout to ensure test url could be loaded within test time // increase timeout to ensure test url could be loaded within test time
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 15000; jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
iabInstance = null; iabInsance = null;
}); });
afterEach(function (done) { afterEach(function () {
// restore original timeout // restore original timeout
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
if (iabInstance !== null && iabInstance.close) { if (iabInsance && iabInsance.close) {
iabInstance.close(); iabInsance.close();
} }
iabInstance = null; iabInsance = null;
// add some extra time so that iab dialog is closed
setTimeout(done, 2000);
}); });
function verifyEvent(evt, type) { function verifyEvent(evt, type) {
expect(evt).toBeDefined(); expect(evt).toBeDefined();
expect(evt.type).toEqual(type); expect(evt.type).toEqual(type);
if (type !== 'exit') { // `exit` event does not have url field expect(evt.url).toEqual(url);
expect(evt.url).toEqual(url);
}
} }
function verifyLoadErrorEvent(evt) { it("inappbrowser.spec.3 should retun InAppBrowser class instance", function () {
expect(evt).toBeDefined(); iabInsance = cordova.InAppBrowser.open(url, '_blank');
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 () { expect(iabInsance).toBeDefined();
iabInstance = cordova.InAppBrowser.open(url, '_blank');
expect(iabInstance).toBeDefined(); expect(iabInsance.addEventListener).toBeDefined();
expect(typeof iabInsance.addEventListener === 'function').toBe(true);
expect(iabInsance.close).toBeDefined();
expect(typeof iabInsance.close === 'function').toBe(true);
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) { it("inappbrowser.spec.4 should support loadstart and loadstop events", function (done) {
@@ -99,32 +85,14 @@ exports.defineAutoTests = function () {
verifyEvent(evt, 'loadstart'); verifyEvent(evt, 'loadstart');
}); });
iabInstance = cordova.InAppBrowser.open(url, '_blank'); iabInsance = cordova.InAppBrowser.open(url, '_blank');
iabInstance.addEventListener('loadstart', onLoadStart); iabInsance.addEventListener('loadstart', onLoadStart);
iabInstance.addEventListener('loadstop', function (evt) { iabInsance.addEventListener('loadstop', function (evt) {
verifyEvent(evt, 'loadstop'); verifyEvent(evt, 'loadstop');
expect(onLoadStart).toHaveBeenCalled(); expect(onLoadStart).toHaveBeenCalled();
done(); 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();
});
});
}); });
}; };