4
Licensed to the Apache Software Foundation (ASF) under one
5
or more contributor license agreements. See the NOTICE file
6
distributed with this work for additional information
7
regarding copyright ownership. The ASF licenses this file
8
to you under the Apache License, Version 2.0 (the
9
"License"); you may not use this file except in compliance
10
with the License. You may obtain a copy of the License at
12
http://www.apache.org/licenses/LICENSE-2.0
14
Unless required by applicable law or agreed to in writing,
15
software distributed under the License is distributed on an
16
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17
KIND, either express or implied. See the License for the
18
specific language governing permissions and limitations
26
<meta name="viewport" content="width=device-width,height=device-height,user-scalable=no,maximum-scale=1.0,initial-scale=1.0" />
27
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> <!-- ISO-8859-1 -->
28
<title>Cordova Mobile Spec</title>
29
<link rel="stylesheet" href="../master.css" type="text/css" media="screen" title="no title" charset="utf-8">
30
<script type="text/javascript" charset="utf-8" src="../cordova-incl.js"></script>
33
<script type="text/javascript" charset="utf-8">
35
var deviceReady = false;
38
* Function called when page has finished loading.
41
document.addEventListener("deviceready", function() {
43
console.log("Device="+device.platform+" "+device.version);
45
function updateUserAgent() {
46
document.getElementById("user-agent").textContent = navigator.userAgent;
49
window.setInterval(updateUserAgent, 1500);
50
window.setTimeout(function() {
52
alert("Error: Apache Cordova did not initialize. Demo will not run correctly.");
57
function doOpen(url, target, params, numExpectedRedirects) {
58
numExpectedRedirects = numExpectedRedirects || 0;
59
var iab = window.open(url, target, params);
61
alert('window.open returned ' + iab);
74
lastLoadStartURL = '';
78
function logEvent(e) {
79
console.log('IAB event=' + JSON.stringify(e));
81
// Verify that event.url gets updated on redirects.
82
if (e.type == 'loadstart') {
83
if (e.url == lastLoadStartURL) {
84
alert('Unexpected: loadstart fired multiple times for the same URL.');
86
lastLoadStartURL = e.url;
88
// Verify the right number of loadstart events were fired.
89
if (e.type == 'loadstop' || e.type == 'loaderror') {
90
if (e.url != lastLoadStartURL) {
91
alert('Unexpected: ' + e.type + ' event.url != loadstart\'s event.url');
93
if (numExpectedRedirects === 0 && counts['loadstart'] !== 1) {
94
// Do allow a loaderror without a loadstart (e.g. in the case of an invalid URL).
95
if (!(e.type == 'loaderror' && counts['loadstart'] === 0)) {
96
alert('Unexpected: got multiple loadstart events. (' + counts['loadstart'] + ')');
98
} else if (numExpectedRedirects > 0 && counts['loadstart'] < (numExpectedRedirects+1)) {
99
alert('Unexpected: should have got at least ' + (numExpectedRedirects+1) + ' loadstart events, but got ' + counts['loadstart']);
102
numExpectedRedirects = 0;
105
// Verify that loadend / loaderror was called.
106
if (e.type == 'exit') {
107
var numStopEvents = counts['loadstop'] + counts['loaderror'];
108
if (numStopEvents === 0 && !wasReset) {
109
alert('Unexpected: browser closed without a loadstop or loaderror.')
110
} else if (numStopEvents > 1) {
111
alert('Unexpected: got multiple loadstop/loaderror events.');
115
iab.addEventListener('loaderror', logEvent, false);
116
iab.addEventListener('loadstart', logEvent, false);
117
iab.addEventListener('loadstop', logEvent, false);
118
iab.addEventListener('exit', logEvent, false);
123
function openWithStyle(url, cssUrl, useCallback) {
124
var iab = doOpen(url, '_blank', 'location=yes');
125
var callback = function(results) {
126
if (results && results.length === 0) {
127
alert('Results verified');
129
console.log(results);
130
alert('Got: ' + typeof(results) + '\n' + JSON.stringify(results));
134
iab.addEventListener('loadstop', function(event) {
135
iab.insertCSS({file: cssUrl}, useCallback && callback);
138
iab.addEventListener('loadstop', function(event) {
139
iab.insertCSS({code:'#style-update-literal { \ndisplay: block !important; \n}'},
140
useCallback && callback);
145
function openWithScript(url, jsUrl, useCallback) {
146
var iab = doOpen(url, '_blank', 'location=yes');
148
iab.addEventListener('loadstop', function(event) {
149
iab.executeScript({file: jsUrl}, useCallback && function(results) {
150
if (results && results.length === 0) {
151
alert('Results verified');
153
console.log(results);
154
alert('Got: ' + typeof(results) + '\n' + JSON.stringify(results));
159
iab.addEventListener('loadstop', function(event) {
160
var code = '(function(){\n' +
161
' var header = document.getElementById("header");\n' +
162
' header.innerHTML = "Script literal successfully injected";\n' +
165
iab.executeScript({code:code}, useCallback && function(results) {
166
if (results && results.length === 1 && results[0] === 'abc') {
167
alert('Results verified');
169
console.log(results);
170
alert('Got: ' + typeof(results) + '\n' + JSON.stringify(results));
177
var loadlistener = function(event) { alert('background window loaded ' ); };
178
function openHidden(url, startHidden) {
179
var shopt =(startHidden) ? 'hidden=yes' : '';
180
hiddenwnd = window.open(url,'random_string',shopt);
182
alert('window.open returned ' + hiddenwnd);
185
if(startHidden) hiddenwnd.addEventListener('loadstop', loadlistener);
187
function showHidden() {
192
function closeHidden() {
194
hiddenwnd.removeEventListener('loadstop',loadlistener);
201
<body onload="init();" id="stage" class="theme">
203
<h1>InAppBrowser</h1>
205
Make sure http://www.google.com is white listed. </br>
206
Make sure http://www.apple.com is not in the white list.</br> In iOS, starred <span style="vertical-align:super">*</span> tests will leave the app with no way to return. </br>
207
<h4>User-Agent: <span id="user-agent"> </span></h4>
209
<div onclick="backHome();">Back</div>
211
<div class="btn large" onclick="doOpen('local.html');">Default: CordovaWebView</div>
212
<div class="btn large" onclick="doOpen('local.html', '_self');">Target=Self: CordovaWebView</div>
213
<div class="btn large" onclick="doOpen('local.html', '_system');">Target=System: Error</div>
214
<div class="btn large" onclick="doOpen('local.html', '_blank');">Target=Blank: InAppBrowser</div>
215
<div class="btn large" onclick="doOpen('local.html', 'random_string');">Target=Random: InAppBrowser</div>
216
<div class="btn large" onclick="doOpen('local.html', 'random_string', 'location=no');">Target=Random, no location bar: InAppBrowser</div>
217
<h1>White Listed URL</h1>
218
<div class="btn large" onclick="doOpen('http://www.google.com');">Default: CordovaWebView<span style="vertical-align:super">*</span></div>
219
<div class="btn large" onclick="doOpen('http://www.google.com', '_self');">Target=Self: CordovaWebView<span style="vertical-align:super">*</span></div>
220
<div class="btn large" onclick="doOpen('http://www.google.com', '_system');">Target=System: System Browser</div>
221
<div class="btn large" onclick="doOpen('http://www.google.com', '_blank');">Target=Blank: InAppBrowser</div>
222
<div class="btn large" onclick="doOpen('http://www.google.com', 'random_string');">Target=Random: InAppBrowser</div>
223
<div class="btn large" onclick="doOpen('http://www.google.com', 'random_string', 'location=no');">Target=Random, no location bar: InAppBrowser</div>
224
<h1>Non White Listed URL</h1>
225
<div class="btn large" onclick="doOpen('http://www.apple.com');">Default: InAppBrowser</div>
226
<div class="btn large" onclick="doOpen('http://www.apple.com', '_self');">Target=Self: InAppBrowser</div>
227
<div class="btn large" onclick="doOpen('http://www.apple.com', '_system');">Target=System: System</div>
228
<div class="btn large" onclick="doOpen('http://www.apple.com', '_blank');">Target=Blank: InAppBrowser</div>
229
<div class="btn large" onclick="doOpen('http://www.apple.com', 'random_string');">Target=Random: InAppBrowser</div>
230
<div class="btn large" onclick="doOpen('http://www.apple.com', 'random_string', 'location=no');">Target=Random, no location bar: InAppBrowser</div>
231
<h1>Page with redirect</h1>
232
<div class="btn large" onclick="doOpen('http://google.com', 'random_string', '', 1);">http://google.com (should 301)</div>
233
<div class="btn large" onclick="doOpen('http://goo.gl/pUFqg', 'random_string', '', 2);">http://www.zhihu.com/answer/16714076 (should 302)</div>
235
<div class="btn large" onclick="doOpen('http://www.stluciadance.com/prospectus_file/sample.pdf');">Remote URL</div>
236
<div class="btn large" onclick="doOpen('local.pdf', '_blank');">Local URL</div>
238
<div class="btn large" onclick="doOpen('x-ttp://www.invalid.com/', '_blank');">Invalid Scheme</div>
239
<div class="btn large" onclick="doOpen('http://www.inv;alid.com/', '_blank');">Invalid Host</div>
240
<div class="btn large" onclick="doOpen('nonexistent.html', '_blank');">Missing File</div>
241
<h1>CSS / JS Injection</h1>
242
<div class="btn large" onclick="doOpen('inject.html', '_blank');">Original Document</div>
243
<div class="btn large" onclick="openWithStyle('inject.html','inject.css');">CSS File Injection</div>
244
<div class="btn large" onclick="openWithStyle('inject.html','inject.css', true);">CSS File Injection (CB)</div>
245
<div class="btn large" onclick="openWithStyle('inject.html');">CSS Literal Injection</div>
246
<div class="btn large" onclick="openWithStyle('inject.html', null, true);">CSS Literal Injection (CB)</div>
247
<div class="btn large" onclick="openWithScript('inject.html', 'inject.js');">Script File Injection</div>
248
<div class="btn large" onclick="openWithScript('inject.html', 'inject.js', true);">Script File Injection (CB)</div>
249
<div class="btn large" onclick="openWithScript('inject.html');">Script Literal Injection</div>
250
<div class="btn large" onclick="openWithScript('inject.html', null, true);">Script Literal Injection (CB)</div>
251
<h1>Open Hidden </h1>
252
<div class="btn large" onclick="openHidden('http://google.com',true);">google.com hidden</div>
253
<div class="btn large" onclick="showHidden();">show hidden</div>
254
<div class="btn large" onclick="closeHidden();">close hidden</div>
255
<div class="btn large" onclick="openHidden('http://google.com',false);">google.com not hidden</div>
256
<h2> </h2><div class="backBtn" onclick="backHome();">Back</div>