Skip to content

Commit 72ac4d7

Browse files
committed
CB-13028 (CI) Browser builds on Travis and AppVeyor, Fixes tests on browser and browser implementation
1 parent 32d867f commit 72ac4d7

File tree

5 files changed

+64
-18
lines changed

5 files changed

+64
-18
lines changed

.appveyor.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ environment:
1515
nodejs_version: "4"
1616
matrix:
1717
- PLATFORM: windows-10-store
18-
18+
JUST_BUILD: --justBuild
19+
- PLATFORM: local\browser
1920
install:
2021
- npm cache clean -f
2122
- node --version
@@ -25,4 +26,4 @@ install:
2526
build: off
2627

2728
test_script:
28-
- cordova-paramedic --config pr\%PLATFORM% --plugin . --justBuild
29+
- cordova-paramedic --config pr\%PLATFORM% --plugin . %JUST_BUILD%

.travis.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@ env:
88
- TRAVIS_NODE_VERSION="4.2"
99
matrix:
1010
include:
11+
- env: PLATFORM=browser-chrome
12+
os: linux
13+
language: node_js
14+
node_js: '4.2'
15+
- env: PLATFORM=browser-firefox
16+
os: linux
17+
language: node_js
18+
node_js: '4.2'
19+
- env: PLATFORM=browser-safari
20+
os: linux
21+
language: node_js
22+
node_js: '4.2'
23+
- env: PLATFORM=browser-edge
24+
os: linux
25+
language: node_js
26+
node_js: '4.2'
1127
- env: PLATFORM=ios-9.3
1228
os: osx
1329
osx_image: xcode7.3

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,12 @@ instance, or the system browser.
144144
- Amazon Fire OS
145145
- Android
146146
- BlackBerry 10
147+
- Browser
147148
- Firefox OS
148149
- iOS
149150
- OSX
150151
- Windows 8 and 8.1
151152
- Windows Phone 7 and 8
152-
- Browser
153153

154154
### Example
155155

@@ -323,10 +323,10 @@ function executeScriptCallBack(params) {
323323

324324
- Amazon Fire OS
325325
- Android
326+
- Browser
326327
- iOS
327328
- Windows 8 and 8.1
328329
- Windows Phone 7 and 8
329-
- Browser
330330

331331
### Browser Quirks
332332

@@ -359,10 +359,10 @@ The function is passed an `InAppBrowserEvent` object.
359359

360360
- Amazon Fire OS
361361
- Android
362+
- Browser
362363
- iOS
363364
- Windows 8 and 8.1
364365
- Windows Phone 7 and 8
365-
- Browser
366366

367367
### Quick Example
368368

@@ -383,11 +383,11 @@ The function is passed an `InAppBrowserEvent` object.
383383

384384
- Amazon Fire OS
385385
- Android
386+
- Browser
386387
- Firefox OS
387388
- iOS
388389
- Windows 8 and 8.1
389390
- Windows Phone 7 and 8
390-
- Browser
391391

392392
### Quick Example
393393

@@ -406,9 +406,9 @@ The function is passed an `InAppBrowserEvent` object.
406406

407407
- Amazon Fire OS
408408
- Android
409+
- Browser
409410
- iOS
410411
- Windows 8 and 8.1
411-
- Browser
412412

413413
### Quick Example
414414

@@ -460,9 +460,9 @@ The function is passed an `InAppBrowserEvent` object.
460460

461461
- Amazon Fire OS
462462
- Android
463+
- Browser
463464
- iOS
464465
- Windows 8 and 8.1
465-
- Browser
466466

467467
### Quick Example
468468

src/browser/InAppBrowserProxy.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,30 @@ var browserWrap,
3131

3232
function attachNavigationEvents(element, callback) {
3333
var onError = function () {
34-
callback({ type: "loaderror", url: this.contentWindow.location.href}, {keepCallback: true});
34+
try {
35+
callback({ type: "loaderror", url: this.contentWindow.location.href}, {keepCallback: true});
36+
} catch (err) {
37+
// blocked by CORS :\
38+
callback({ type: "loaderror", url: null}, {keepCallback: true});
39+
}
3540
};
3641

3742
element.addEventListener("pageshow", function () {
38-
callback({ type: "loadstart", url: this.contentWindow.location.href}, {keepCallback: true});
43+
try {
44+
callback({ type: "loadstart", url: this.contentWindow.location.href}, {keepCallback: true});
45+
} catch (err) {
46+
// blocked by CORS :\
47+
callback({ type: "loadstart", url: null}, {keepCallback: true});
48+
}
3949
});
4050

4151
element.addEventListener("load", function () {
42-
callback({ type: "loadstop", url: this.contentWindow.location.href}, {keepCallback: true});
52+
try {
53+
callback({ type: "loadstop", url: this.contentWindow.location.href}, {keepCallback: true});
54+
} catch (err) {
55+
// blocked by CORS :\
56+
callback({ type: "loadstop", url: null}, {keepCallback: true});
57+
}
4358
});
4459

4560
element.addEventListener("error", onError);
@@ -49,7 +64,8 @@ function attachNavigationEvents(element, callback) {
4964
var IAB = {
5065
close: function (win, lose) {
5166
if (browserWrap) {
52-
if (win) win({ type: "exit" });
67+
// use the "open" function callback so that the exit event is fired properly
68+
if (IAB._win) IAB._win({ type: "exit" });
5369

5470
browserWrap.parentNode.removeChild(browserWrap);
5571
browserWrap = null;
@@ -68,6 +84,8 @@ var IAB = {
6884
target = args[1],
6985
features = args[2];
7086

87+
IAB._win = win;
88+
7189
if (target === "_self" || !target) {
7290
window.location = strUrl;
7391
} else if (target === "_system") {
@@ -88,7 +106,7 @@ var IAB = {
88106

89107
browserWrap.onclick = function () {
90108
setTimeout(function () {
91-
IAB.close(win);
109+
IAB.close();
92110
}, 0);
93111
};
94112

@@ -161,7 +179,7 @@ var IAB = {
161179
closeButton.innerHTML = "✖";
162180
closeButton.addEventListener("click", function (e) {
163181
setTimeout(function () {
164-
IAB.close(win);
182+
IAB.close();
165183
}, 0);
166184
});
167185

tests/tests.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
/* global MSApp */
2424

2525
var cordova = require('cordova');
26-
var isWindows = cordova.platformId == 'windows';
26+
var isWindows = cordova.platformId === 'windows';
27+
var isBrowser = cordova.platformId === 'browser';
2728

2829
window.alert = window.alert || navigator.notification.alert;
2930
if (isWindows && navigator && navigator.notification && navigator.notification.alert) {
@@ -80,7 +81,8 @@ exports.defineAutoTests = function () {
8081
function verifyEvent(evt, type) {
8182
expect(evt).toBeDefined();
8283
expect(evt.type).toEqual(type);
83-
if (type !== 'exit') { // `exit` event does not have url field
84+
// `exit` event does not have url field, browser returns null url for CORS requests
85+
if (type !== 'exit' && !isBrowser) {
8486
expect(evt.url).toEqual(url);
8587
}
8688
}
@@ -93,7 +95,7 @@ exports.defineAutoTests = function () {
9395
expect(evt.message).toEqual(jasmine.any(String));
9496
}
9597

96-
it("inappbrowser.spec.3 should retun InAppBrowser instance with required methods", function () {
98+
it("inappbrowser.spec.3 should return InAppBrowser instance with required methods", function () {
9799
iabInstance = cordova.InAppBrowser.open(url, '_blank');
98100

99101
expect(iabInstance).toBeDefined();
@@ -116,7 +118,11 @@ exports.defineAutoTests = function () {
116118
iabInstance.addEventListener('loadstart', onLoadStart);
117119
iabInstance.addEventListener('loadstop', function (evt) {
118120
verifyEvent(evt, 'loadstop');
119-
expect(onLoadStart).toHaveBeenCalled();
121+
if (!isBrowser) {
122+
// according to documentation, "loadstart" event is not supported on browser
123+
// https://github.com/apache/cordova-plugin-inappbrowser#browser-quirks-1
124+
expect(onLoadStart).toHaveBeenCalled();
125+
}
120126
done();
121127
});
122128
});
@@ -132,6 +138,11 @@ exports.defineAutoTests = function () {
132138
});
133139

134140
it("inappbrowser.spec.6 should support loaderror event", function (done) {
141+
if (isBrowser) {
142+
// according to documentation, "loaderror" event is not supported on browser
143+
// https://github.com/apache/cordova-plugin-inappbrowser#browser-quirks-1
144+
pending('Browser platform doesn\'t support loaderror event');
145+
}
135146
iabInstance = cordova.InAppBrowser.open(badUrl, '_blank');
136147
iabInstance.addEventListener('loaderror', function (evt) {
137148
verifyLoadErrorEvent(evt);

0 commit comments

Comments
 (0)