~ps-jenkins/cordova-ubuntu-tests/latestsnapshot-2.11+14.04.20131106-0ubuntu1

« back to all changes in this revision

Viewing changes to www/inappbrowser/index.html

  • Committer: VĂ­ctor R. Ruiz
  • Date: 2013-07-25 13:09:34 UTC
  • Revision ID: victor.ruiz@canonical.com-20130725130934-d4q95mh8eehbv363
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE html>
 
2
<!--
 
3
 
 
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
 
11
 
 
12
   http://www.apache.org/licenses/LICENSE-2.0
 
13
 
 
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
 
19
 under the License.
 
20
 
 
21
-->
 
22
 
 
23
 
 
24
<html>
 
25
  <head>
 
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>      
 
31
 
 
32
      
 
33
    <script type="text/javascript" charset="utf-8">
 
34
 
 
35
    var deviceReady = false;
 
36
    
 
37
    /**
 
38
     * Function called when page has finished loading.
 
39
     */
 
40
    function init() {
 
41
        document.addEventListener("deviceready", function() {
 
42
                deviceReady = true;
 
43
                console.log("Device="+device.platform+" "+device.version);
 
44
            }, false);
 
45
        function updateUserAgent() {
 
46
            document.getElementById("user-agent").textContent = navigator.userAgent;
 
47
        }
 
48
        updateUserAgent();
 
49
        window.setInterval(updateUserAgent, 1500);
 
50
        window.setTimeout(function() {
 
51
                if (!deviceReady) {
 
52
                        alert("Error: Apache Cordova did not initialize.  Demo will not run correctly.");
 
53
                }
 
54
        },1000);
 
55
    }
 
56
 
 
57
    function doOpen(url, target, params, numExpectedRedirects) {
 
58
        numExpectedRedirects = numExpectedRedirects || 0;
 
59
        var iab = window.open(url, target, params);
 
60
        if (!iab) {
 
61
            alert('window.open returned ' + iab);
 
62
            return;
 
63
        }
 
64
        var counts;
 
65
        var lastLoadStartURL;
 
66
        var wasReset = false;
 
67
        function reset()  {
 
68
            counts = {
 
69
                'loaderror': 0,
 
70
                'loadstart': 0,
 
71
                'loadstop': 0,
 
72
                'exit': 0
 
73
            };
 
74
            lastLoadStartURL = '';
 
75
        }
 
76
        reset();
 
77
 
 
78
        function logEvent(e) {
 
79
            console.log('IAB event=' + JSON.stringify(e));
 
80
            counts[e.type]++;
 
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.');
 
85
                }
 
86
                lastLoadStartURL = e.url;
 
87
            }
 
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');
 
92
                }
 
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'] + ')');
 
97
                    }
 
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']);
 
100
                }
 
101
                wasReset = true;
 
102
                numExpectedRedirects = 0;
 
103
                reset();
 
104
            }
 
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.');
 
112
                }
 
113
            }
 
114
        }
 
115
        iab.addEventListener('loaderror', logEvent, false);
 
116
        iab.addEventListener('loadstart', logEvent, false);
 
117
        iab.addEventListener('loadstop', logEvent, false);
 
118
        iab.addEventListener('exit', logEvent, false);
 
119
 
 
120
        return iab;
 
121
    }
 
122
 
 
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');
 
128
            } else {
 
129
                console.log(results);
 
130
                alert('Got: ' + typeof(results) + '\n' + JSON.stringify(results));
 
131
            }
 
132
        };
 
133
        if (cssUrl) {
 
134
            iab.addEventListener('loadstop', function(event) {
 
135
                iab.insertCSS({file: cssUrl}, useCallback && callback);
 
136
            });
 
137
        } else {
 
138
            iab.addEventListener('loadstop', function(event) {
 
139
                iab.insertCSS({code:'#style-update-literal { \ndisplay: block !important; \n}'},
 
140
                              useCallback && callback);
 
141
            });
 
142
        }
 
143
    }
 
144
 
 
145
    function openWithScript(url, jsUrl, useCallback) {
 
146
        var iab = doOpen(url, '_blank', 'location=yes');
 
147
        if (jsUrl) {
 
148
            iab.addEventListener('loadstop', function(event) {
 
149
                iab.executeScript({file: jsUrl}, useCallback && function(results) {
 
150
                    if (results && results.length === 0) {
 
151
                        alert('Results verified');
 
152
                    } else {
 
153
                        console.log(results);
 
154
                        alert('Got: ' + typeof(results) + '\n' + JSON.stringify(results));
 
155
                    }
 
156
                });
 
157
            });
 
158
        } else {
 
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' +
 
163
                  '    return "abc";\n' +
 
164
                  '})()';
 
165
                iab.executeScript({code:code}, useCallback && function(results) {
 
166
                    if (results && results.length === 1 && results[0] === 'abc') {
 
167
                        alert('Results verified');
 
168
                    } else {
 
169
                        console.log(results);
 
170
                        alert('Got: ' + typeof(results) + '\n' + JSON.stringify(results));
 
171
                    }
 
172
                });
 
173
            });
 
174
        }
 
175
    }
 
176
    var hiddenwnd=null;
 
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);
 
181
        if (!hiddenwnd) {
 
182
            alert('window.open returned ' + hiddenwnd);
 
183
            return;
 
184
        }
 
185
        if(startHidden) hiddenwnd.addEventListener('loadstop', loadlistener);
 
186
    }
 
187
    function showHidden() {
 
188
        if(!!hiddenwnd ) {
 
189
            hiddenwnd.show();
 
190
        }
 
191
    }
 
192
    function closeHidden() {
 
193
       if(!!hiddenwnd ) {
 
194
           hiddenwnd.removeEventListener('loadstop',loadlistener);
 
195
           hiddenwnd.close();
 
196
           hiddenwnd=null;
 
197
       }
 
198
    }
 
199
    </script>
 
200
  </head>
 
201
  <body onload="init();" id="stage" class="theme">
 
202
  
 
203
    <h1>InAppBrowser</h1>
 
204
    <div id="info">
 
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>
 
208
    </div>
 
209
    <div onclick="backHome();">Back</div>
 
210
    <h1>Local URL</h1>
 
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>
 
234
    <h1>PDF URL</h1>
 
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>
 
237
    <h1>INVALID URL</h1>
 
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>
 
257
  </body>
 
258
</html>