19
19
*
20
20
*/
21
21
22
- /* global MSApp, alert */
22
+ /* global MSApp */
23
23
24
24
var cordova = require ( 'cordova' ) ;
25
25
var isWindows = cordova . platformId === 'windows' ;
@@ -33,128 +33,126 @@ if (isWindows && navigator && navigator.notification && navigator.notification.a
33
33
}
34
34
35
35
exports . defineAutoTests = function ( ) {
36
-
37
36
var createTests = function ( platformOpts ) {
38
37
platformOpts = platformOpts || '' ;
39
38
40
- describe ( 'cordova.InAppBrowser' , function ( ) {
39
+ describe ( 'cordova.InAppBrowser' , function ( ) {
41
40
42
- it ( 'inappbrowser.spec.1 should exist' , function ( ) {
43
- expect ( cordova . InAppBrowser ) . toBeDefined ( ) ;
44
- } ) ;
41
+ it ( 'inappbrowser.spec.1 should exist' , function ( ) {
42
+ expect ( cordova . InAppBrowser ) . toBeDefined ( ) ;
43
+ } ) ;
45
44
46
- it ( 'inappbrowser.spec.2 should contain open function' , function ( ) {
47
- expect ( cordova . InAppBrowser . open ) . toBeDefined ( ) ;
48
- expect ( cordova . InAppBrowser . open ) . toEqual ( jasmine . any ( Function ) ) ;
49
- } ) ;
45
+ it ( 'inappbrowser.spec.2 should contain open function' , function ( ) {
46
+ expect ( cordova . InAppBrowser . open ) . toBeDefined ( ) ;
47
+ expect ( cordova . InAppBrowser . open ) . toEqual ( jasmine . any ( Function ) ) ;
50
48
} ) ;
49
+ } ) ;
51
50
52
- describe ( 'open method' , function ( ) {
51
+ describe ( 'open method' , function ( ) {
53
52
54
- if ( cordova . platformId === 'osx' ) {
55
- pending ( 'Open method not fully supported on OSX.' ) ;
56
- return ;
57
- }
53
+ if ( cordova . platformId === 'osx' ) {
54
+ pending ( 'Open method not fully supported on OSX.' ) ;
55
+ return ;
56
+ }
58
57
59
- var iabInstance ;
60
- var originalTimeout ;
61
- var url = 'https://dist.apache.org/repos/dist/dev/cordova/' ;
62
- var badUrl = 'http://bad-uri/' ;
58
+ var iabInstance ;
59
+ var originalTimeout ;
60
+ var url = 'https://dist.apache.org/repos/dist/dev/cordova/' ;
61
+ var badUrl = 'http://bad-uri/' ;
63
62
64
- beforeEach ( function ( ) {
65
- // increase timeout to ensure test url could be loaded within test time
66
- originalTimeout = jasmine . DEFAULT_TIMEOUT_INTERVAL ;
67
- jasmine . DEFAULT_TIMEOUT_INTERVAL = 30000 ;
63
+ beforeEach ( function ( ) {
64
+ // increase timeout to ensure test url could be loaded within test time
65
+ originalTimeout = jasmine . DEFAULT_TIMEOUT_INTERVAL ;
66
+ jasmine . DEFAULT_TIMEOUT_INTERVAL = 30000 ;
68
67
69
- iabInstance = null ;
70
- } ) ;
71
-
72
- afterEach ( function ( done ) {
73
- // restore original timeout
74
- jasmine . DEFAULT_TIMEOUT_INTERVAL = originalTimeout ;
68
+ iabInstance = null ;
69
+ } ) ;
75
70
76
- if ( iabInstance !== null && iabInstance . close ) {
77
- iabInstance . close ( ) ;
78
- }
79
- iabInstance = null ;
80
- // add some extra time so that iab dialog is closed
81
- setTimeout ( done , 2000 ) ;
82
- } ) ;
71
+ afterEach ( function ( done ) {
72
+ // restore original timeout
73
+ jasmine . DEFAULT_TIMEOUT_INTERVAL = originalTimeout ;
83
74
84
- function verifyEvent ( evt , type ) {
85
- expect ( evt ) . toBeDefined ( ) ;
86
- expect ( evt . type ) . toEqual ( type ) ;
87
- // `exit` event does not have url field, browser returns null url for CORS requests
88
- if ( type !== 'exit' && ! isBrowser ) {
89
- expect ( evt . url ) . toEqual ( url ) ;
90
- }
75
+ if ( iabInstance !== null && iabInstance . close ) {
76
+ iabInstance . close ( ) ;
91
77
}
78
+ iabInstance = null ;
79
+ // add some extra time so that iab dialog is closed
80
+ setTimeout ( done , 2000 ) ;
81
+ } ) ;
92
82
93
- function verifyLoadErrorEvent ( evt ) {
94
- expect ( evt ) . toBeDefined ( ) ;
95
- expect ( evt . type ) . toEqual ( 'loaderror' ) ;
96
- expect ( evt . url ) . toEqual ( badUrl ) ;
97
- expect ( evt . code ) . toEqual ( jasmine . any ( Number ) ) ;
98
- expect ( evt . message ) . toEqual ( jasmine . any ( String ) ) ;
83
+ function verifyEvent ( evt , type ) {
84
+ expect ( evt ) . toBeDefined ( ) ;
85
+ expect ( evt . type ) . toEqual ( type ) ;
86
+ // `exit` event does not have url field, browser returns null url for CORS requests
87
+ if ( type !== 'exit' && ! isBrowser ) {
88
+ expect ( evt . url ) . toEqual ( url ) ;
99
89
}
90
+ }
91
+
92
+ function verifyLoadErrorEvent ( evt ) {
93
+ expect ( evt ) . toBeDefined ( ) ;
94
+ expect ( evt . type ) . toEqual ( 'loaderror' ) ;
95
+ expect ( evt . url ) . toEqual ( badUrl ) ;
96
+ expect ( evt . code ) . toEqual ( jasmine . any ( Number ) ) ;
97
+ expect ( evt . message ) . toEqual ( jasmine . any ( String ) ) ;
98
+ }
100
99
101
- it ( 'inappbrowser.spec.3 should return InAppBrowser instance with required methods' , function ( ) {
100
+ it ( 'inappbrowser.spec.3 should return InAppBrowser instance with required methods' , function ( ) {
102
101
iabInstance = cordova . InAppBrowser . open ( url , '_blank' , platformOpts ) ;
103
102
104
- expect ( iabInstance ) . toBeDefined ( ) ;
103
+ expect ( iabInstance ) . toBeDefined ( ) ;
105
104
106
- expect ( iabInstance . addEventListener ) . toEqual ( jasmine . any ( Function ) ) ;
107
- expect ( iabInstance . removeEventListener ) . toEqual ( jasmine . any ( Function ) ) ;
108
- expect ( iabInstance . close ) . toEqual ( jasmine . any ( Function ) ) ;
109
- expect ( iabInstance . show ) . toEqual ( jasmine . any ( Function ) ) ;
110
- expect ( iabInstance . hide ) . toEqual ( jasmine . any ( Function ) ) ;
111
- expect ( iabInstance . executeScript ) . toEqual ( jasmine . any ( Function ) ) ;
112
- expect ( iabInstance . insertCSS ) . toEqual ( jasmine . any ( Function ) ) ;
113
- } ) ;
105
+ expect ( iabInstance . addEventListener ) . toEqual ( jasmine . any ( Function ) ) ;
106
+ expect ( iabInstance . removeEventListener ) . toEqual ( jasmine . any ( Function ) ) ;
107
+ expect ( iabInstance . close ) . toEqual ( jasmine . any ( Function ) ) ;
108
+ expect ( iabInstance . show ) . toEqual ( jasmine . any ( Function ) ) ;
109
+ expect ( iabInstance . hide ) . toEqual ( jasmine . any ( Function ) ) ;
110
+ expect ( iabInstance . executeScript ) . toEqual ( jasmine . any ( Function ) ) ;
111
+ expect ( iabInstance . insertCSS ) . toEqual ( jasmine . any ( Function ) ) ;
112
+ } ) ;
114
113
115
- it ( 'inappbrowser.spec.4 should support loadstart and loadstop events' , function ( done ) {
116
- var onLoadStart = jasmine . createSpy ( 'loadstart event callback' ) . and . callFake ( function ( evt ) {
117
- verifyEvent ( evt , 'loadstart' ) ;
118
- } ) ;
114
+ it ( 'inappbrowser.spec.4 should support loadstart and loadstop events' , function ( done ) {
115
+ var onLoadStart = jasmine . createSpy ( 'loadstart event callback' ) . and . callFake ( function ( evt ) {
116
+ verifyEvent ( evt , 'loadstart' ) ;
117
+ } ) ;
119
118
120
119
iabInstance = cordova . InAppBrowser . open ( url , '_blank' , platformOpts ) ;
121
- iabInstance . addEventListener ( 'loadstart' , onLoadStart ) ;
122
- iabInstance . addEventListener ( 'loadstop' , function ( evt ) {
123
- verifyEvent ( evt , 'loadstop' ) ;
124
- if ( ! isBrowser ) {
125
- // according to documentation, "loadstart" event is not supported on browser
126
- // https://github.com/apache/cordova-plugin-inappbrowser#browser-quirks-1
127
- expect ( onLoadStart ) . toHaveBeenCalled ( ) ;
128
- }
129
- done ( ) ;
130
- } ) ;
120
+ iabInstance . addEventListener ( 'loadstart' , onLoadStart ) ;
121
+ iabInstance . addEventListener ( 'loadstop' , function ( evt ) {
122
+ verifyEvent ( evt , 'loadstop' ) ;
123
+ if ( ! isBrowser ) {
124
+ // according to documentation, "loadstart" event is not supported on browser
125
+ // https://github.com/apache/cordova-plugin-inappbrowser#browser-quirks-1
126
+ expect ( onLoadStart ) . toHaveBeenCalled ( ) ;
127
+ }
128
+ done ( ) ;
131
129
} ) ;
130
+ } ) ;
132
131
133
- it ( 'inappbrowser.spec.5 should support exit event' , function ( done ) {
132
+ it ( 'inappbrowser.spec.5 should support exit event' , function ( done ) {
134
133
iabInstance = cordova . InAppBrowser . open ( url , '_blank' , platformOpts ) ;
135
- iabInstance . addEventListener ( 'exit' , function ( evt ) {
136
- verifyEvent ( evt , 'exit' ) ;
137
- done ( ) ;
138
- } ) ;
139
- iabInstance . close ( ) ;
140
- iabInstance = null ;
134
+ iabInstance . addEventListener ( 'exit' , function ( evt ) {
135
+ verifyEvent ( evt , 'exit' ) ;
136
+ done ( ) ;
141
137
} ) ;
138
+ iabInstance . close ( ) ;
139
+ iabInstance = null ;
140
+ } ) ;
142
141
143
- it ( 'inappbrowser.spec.6 should support loaderror event' , function ( done ) {
144
- if ( isBrowser ) {
145
- // according to documentation, "loaderror" event is not supported on browser
146
- // https://github.com/apache/cordova-plugin-inappbrowser#browser-quirks-1
147
- pending ( 'Browser platform doesn\'t support loaderror event' ) ;
148
- }
142
+ it ( 'inappbrowser.spec.6 should support loaderror event' , function ( done ) {
143
+ if ( isBrowser ) {
144
+ // according to documentation, "loaderror" event is not supported on browser
145
+ // https://github.com/apache/cordova-plugin-inappbrowser#browser-quirks-1
146
+ pending ( 'Browser platform doesn\'t support loaderror event' ) ;
147
+ }
149
148
iabInstance = cordova . InAppBrowser . open ( badUrl , '_blank' , platformOpts ) ;
150
- iabInstance . addEventListener ( 'loaderror' , function ( evt ) {
151
- verifyLoadErrorEvent ( evt ) ;
152
- done ( ) ;
153
- } ) ;
149
+ iabInstance . addEventListener ( 'loaderror' , function ( evt ) {
150
+ verifyLoadErrorEvent ( evt ) ;
151
+ done ( ) ;
154
152
} ) ;
155
153
} ) ;
154
+ } ) ;
156
155
} ;
157
-
158
156
if ( isIos ) {
159
157
createTests ( 'usewkwebview=no' ) ;
160
158
createTests ( 'usewkwebview=yes' ) ;
@@ -165,6 +163,15 @@ exports.defineAutoTests = function () {
165
163
166
164
exports . defineManualTests = function ( contentEl , createActionButton ) {
167
165
166
+ var platformOpts = '' ;
167
+ var platform_info = '' ;
168
+ if ( isIos ) {
169
+ platformOpts = 'usewkwebview=no' ;
170
+ platform_info = '<h1>Webview</h1>' +
171
+ '<p>Use this button to toggle the Webview implementation.</p>' +
172
+ '<div id="webviewToggle"></div>' ;
173
+ }
174
+
168
175
function doOpen ( url , target , params , numExpectedRedirects , useWindowOpen ) {
169
176
numExpectedRedirects = numExpectedRedirects || 0 ;
170
177
useWindowOpen = useWindowOpen || false ;
@@ -173,7 +180,6 @@ exports.defineManualTests = function (contentEl, createActionButton) {
173
180
var counts ;
174
181
var lastLoadStartURL ;
175
182
var wasReset = false ;
176
-
177
183
function reset ( ) {
178
184
counts = {
179
185
'loaderror' : 0 ,
@@ -183,7 +189,6 @@ exports.defineManualTests = function (contentEl, createActionButton) {
183
189
} ;
184
190
lastLoadStartURL = '' ;
185
191
}
186
-
187
192
reset ( ) ;
188
193
189
194
var iab ;
@@ -277,11 +282,11 @@ exports.defineManualTests = function (contentEl, createActionButton) {
277
282
} ;
278
283
if ( cssUrl ) {
279
284
iab . addEventListener ( 'loadstop' , function ( event ) {
280
- iab . insertCSS ( { file : cssUrl } , useCallback && callback ) ;
285
+ iab . insertCSS ( { file : cssUrl } , useCallback && callback ) ;
281
286
} ) ;
282
287
} else {
283
288
iab . addEventListener ( 'loadstop' , function ( event ) {
284
- iab . insertCSS ( { code : '#style-update-literal { \ndisplay: block !important; \n}' } ,
289
+ iab . insertCSS ( { code : '#style-update-literal { \ndisplay: block !important; \n}' } ,
285
290
useCallback && callback ) ;
286
291
} ) ;
287
292
}
@@ -291,7 +296,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
291
296
var iab = doOpen ( url , '_blank' , 'location=yes' ) ;
292
297
if ( jsUrl ) {
293
298
iab . addEventListener ( 'loadstop' , function ( event ) {
294
- iab . executeScript ( { file : jsUrl } , useCallback && function ( results ) {
299
+ iab . executeScript ( { file : jsUrl } , useCallback && function ( results ) {
295
300
if ( results && results . length === 0 ) {
296
301
alert ( 'Results verified' ) ; // eslint-disable-line no-undef
297
302
} else {
@@ -303,11 +308,11 @@ exports.defineManualTests = function (contentEl, createActionButton) {
303
308
} else {
304
309
iab . addEventListener ( 'loadstop' , function ( event ) {
305
310
var code = '(function(){\n' +
306
- ' var header = document.getElementById("header");\n' +
307
- ' header.innerHTML = "Script literal successfully injected";\n' +
308
- ' return "abc";\n' +
309
- '})()' ;
310
- iab . executeScript ( { code : code } , useCallback && function ( results ) {
311
+ ' var header = document.getElementById("header");\n' +
312
+ ' header.innerHTML = "Script literal successfully injected";\n' +
313
+ ' return "abc";\n' +
314
+ '})()' ;
315
+ iab . executeScript ( { code : code } , useCallback && function ( results ) {
311
316
if ( results && results . length === 1 && results [ 0 ] === 'abc' ) {
312
317
alert ( 'Results verified' ) ; // eslint-disable-line no-undef
313
318
} else {
@@ -318,11 +323,8 @@ exports.defineManualTests = function (contentEl, createActionButton) {
318
323
} ) ;
319
324
}
320
325
}
321
-
322
326
var hiddenwnd = null ;
323
- var loadlistener = function ( event ) {
324
- alert ( 'background window loaded ' ) ;
325
- } ; // eslint-disable-line no-undef
327
+ var loadlistener = function ( event ) { alert ( 'background window loaded ' ) ; } ; // eslint-disable-line no-undef
326
328
function openHidden ( url , startHidden ) {
327
329
var shopt = ( startHidden ) ? 'hidden=yes' : '' ;
328
330
if ( platformOpts ) {
@@ -335,13 +337,11 @@ exports.defineManualTests = function (contentEl, createActionButton) {
335
337
}
336
338
if ( startHidden ) hiddenwnd . addEventListener ( 'loadstop' , loadlistener ) ;
337
339
}
338
-
339
340
function showHidden ( ) {
340
341
if ( hiddenwnd ) {
341
342
hiddenwnd . show ( ) ;
342
343
}
343
344
}
344
-
345
345
function closeHidden ( ) {
346
346
if ( hiddenwnd ) {
347
347
hiddenwnd . removeEventListener ( 'loadstop' , loadlistener ) ;
@@ -358,15 +358,6 @@ exports.defineManualTests = function (contentEl, createActionButton) {
358
358
'<h4>User-Agent: <span id="user-agent"> </span></hr>' +
359
359
'</div>' ;
360
360
361
- var platformOpts = '' ;
362
- var platform_info = '' ;
363
- if ( isIos ) {
364
- platformOpts = 'usewkwebview=no' ;
365
- platform_info = '<h1>Webview</h1>' +
366
- '<p>Use this button to toggle the Webview implementation.</p>' +
367
- '<div id="webviewToggle"></div>' ;
368
- }
369
-
370
361
var local_tests = '<h1>Local URL</h1>' +
371
362
'<div id="openLocal"></div>' +
372
363
'Expected result: opens successfully in CordovaWebView.' +
@@ -523,13 +514,11 @@ exports.defineManualTests = function (contentEl, createActionButton) {
523
514
var injectjs = isWindows ? basePath + 'inject.js' : 'inject.js' ;
524
515
var injectcss = isWindows ? basePath + 'inject.css' : 'inject.css' ;
525
516
var videohtml = basePath + 'video.html' ;
526
-
527
517
if ( isIos ) {
528
518
createActionButton ( 'Webview=UIWebView' , function ( ) {
529
519
var webviewOption = 'usewkwebview=' ;
530
520
var webviewToggle = document . getElementById ( 'webviewToggle' ) ;
531
521
var button = webviewToggle . getElementsByClassName ( 'topcoat-button' ) [ 0 ] ;
532
-
533
522
if ( platformOpts === webviewOption + 'yes' ) {
534
523
platformOpts = webviewOption + 'no' ;
535
524
button . textContent = 'Webview=UIWebView' ;
0 commit comments