Skip to content
Permalink
Browse files
…emeablebrowser into CB-7179
  • Loading branch information
dpa99c committed Oct 9, 2018
2 parents 8248215 + 61014dd commit 3927b8f2fee8e168bb19de93031b2f930b542b24
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 82 deletions.
@@ -507,6 +507,7 @@ - (BOOL)webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*
}

return shouldStart;
}

- (void)webViewDidStartLoad:(UIWebView*)theWebView
{
@@ -36,122 +36,122 @@ exports.defineAutoTests = function () {
var createTests = function (platformOpts) {
platformOpts = platformOpts || '';

describe('cordova.InAppBrowser', function () {
describe('cordova.InAppBrowser', function () {

it('inappbrowser.spec.1 should exist', function () {
expect(cordova.InAppBrowser).toBeDefined();
});
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));
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 () {
describe('open method', function () {

if (cordova.platformId === 'osx') {
pending('Open method not fully supported on OSX.');
return;
}
if (cordova.platformId === 'osx') {
pending('Open method not fully supported on OSX.');
return;
}

var iabInstance;
var originalTimeout;
var url = 'https://dist.apache.org/repos/dist/dev/cordova/';
var badUrl = 'http://bad-uri/';
var iabInstance;
var originalTimeout;
var url = 'https://dist.apache.org/repos/dist/dev/cordova/';
var badUrl = 'http://bad-uri/';

beforeEach(function () {
beforeEach(function () {
// increase timeout to ensure test url could be loaded within test time
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;

iabInstance = null;
});
iabInstance = null;
});

afterEach(function (done) {
afterEach(function (done) {
// restore original timeout
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
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);
});
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);
// `exit` event does not have url field, browser returns null url for CORS requests
if (type !== 'exit' && !isBrowser) {
expect(evt.url).toEqual(url);
function verifyEvent (evt, type) {
expect(evt).toBeDefined();
expect(evt.type).toEqual(type);
// `exit` event does not have url field, browser returns null url for CORS requests
if (type !== 'exit' && !isBrowser) {
expect(evt.url).toEqual(url);
}
}
}

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));
}
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 return InAppBrowser instance with required methods', function () {
it('inappbrowser.spec.3 should return InAppBrowser instance with required methods', function () {
iabInstance = cordova.InAppBrowser.open(url, '_blank', platformOpts);

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.hide).toEqual(jasmine.any(Function));
expect(iabInstance.executeScript).toEqual(jasmine.any(Function));
expect(iabInstance.insertCSS).toEqual(jasmine.any(Function));
});
expect(iabInstance).toBeDefined();

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');
expect(iabInstance.addEventListener).toEqual(jasmine.any(Function));
expect(iabInstance.removeEventListener).toEqual(jasmine.any(Function));
expect(iabInstance.close).toEqual(jasmine.any(Function));
expect(iabInstance.show).toEqual(jasmine.any(Function));
expect(iabInstance.hide).toEqual(jasmine.any(Function));
expect(iabInstance.executeScript).toEqual(jasmine.any(Function));
expect(iabInstance.insertCSS).toEqual(jasmine.any(Function));
});

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', platformOpts);
iabInstance.addEventListener('loadstart', onLoadStart);
iabInstance.addEventListener('loadstop', function (evt) {
verifyEvent(evt, 'loadstop');
if (!isBrowser) {
iabInstance.addEventListener('loadstart', onLoadStart);
iabInstance.addEventListener('loadstop', function (evt) {
verifyEvent(evt, 'loadstop');
if (!isBrowser) {
// according to documentation, "loadstart" event is not supported on browser
// https://github.com/apache/cordova-plugin-inappbrowser#browser-quirks-1
expect(onLoadStart).toHaveBeenCalled();
}
done();
expect(onLoadStart).toHaveBeenCalled();
}
done();
});
});
});

it('inappbrowser.spec.5 should support exit event', function (done) {
it('inappbrowser.spec.5 should support exit event', function (done) {
iabInstance = cordova.InAppBrowser.open(url, '_blank', platformOpts);
iabInstance.addEventListener('exit', function (evt) {
verifyEvent(evt, 'exit');
done();
iabInstance.addEventListener('exit', function (evt) {
verifyEvent(evt, 'exit');
done();
});
iabInstance.close();
iabInstance = null;
});
iabInstance.close();
iabInstance = null;
});

it('inappbrowser.spec.6 should support loaderror event', function (done) {
if (isBrowser) {
it('inappbrowser.spec.6 should support loaderror event', function (done) {
if (isBrowser) {
// according to documentation, "loaderror" event is not supported on browser
// https://github.com/apache/cordova-plugin-inappbrowser#browser-quirks-1
pending('Browser platform doesn\'t support loaderror event');
}
pending('Browser platform doesn\'t support loaderror event');
}
iabInstance = cordova.InAppBrowser.open(badUrl, '_blank', platformOpts);
iabInstance.addEventListener('loaderror', function (evt) {
verifyLoadErrorEvent(evt);
done();
iabInstance.addEventListener('loaderror', function (evt) {
verifyLoadErrorEvent(evt);
done();
});
});
});
});
};
if (isIos) {
createTests('usewkwebview=no');

0 comments on commit 3927b8f

Please sign in to comment.