Updated Branches:
  refs/heads/master 50c068e6f -> 93f50aea9

[CB-2305] Validate InAppBrowser executeScript/injectCSS callbacks


Project: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/commit/93f50aea
Tree: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/tree/93f50aea
Diff: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/diff/93f50aea

Branch: refs/heads/master
Commit: 93f50aea9f8df9894283cfcd681c0f301178d9e1
Parents: 50c068e
Author: Ian Clelland <[email protected]>
Authored: Thu Mar 28 11:52:27 2013 -0400
Committer: Andrew Grieve <[email protected]>
Committed: Thu Apr 4 14:37:52 2013 -0400

----------------------------------------------------------------------
 inappbrowser/index.html |   43 ++++++++++++++++++++++++++++++++++-------
 1 files changed, 35 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/93f50aea/inappbrowser/index.html
----------------------------------------------------------------------
diff --git a/inappbrowser/index.html b/inappbrowser/index.html
index 51e1af3..fa9623a 100644
--- a/inappbrowser/index.html
+++ b/inappbrowser/index.html
@@ -63,33 +63,56 @@
         );
     }
 
-    function openWithStyle(url, cssUrl) {
+    function openWithStyle(url, cssUrl, useCallback) {
         var iab = window.open(url, '_blank', 'location=yes');
+        var callback = function(results) {
+            if (results && results.length === 0) {
+                alert('Results verified');
+            } else {
+                console.log(results);
+                alert('Got: ' + typeof(results) + '\n' + 
JSON.stringify(results));
+            }
+        };
         if (cssUrl) {
             iab.addEventListener('loadstop', function(event) {
-                iab.insertCSS({file: cssUrl});
+                iab.insertCSS({file: cssUrl}, useCallback && callback);
             });
         } else {
             iab.addEventListener('loadstop', function(event) {
-                iab.insertCSS({code:'#style-update-literal { \ndisplay: block 
!important; \n}'});
+                iab.insertCSS({code:'#style-update-literal { \ndisplay: block 
!important; \n}'},
+                              useCallback && callback);
             });
         }
     }
 
-    function openWithScript(url, jsUrl) {
+    function openWithScript(url, jsUrl, useCallback) {
         var iab = window.open(url, '_blank', 'location=yes');
         if (jsUrl) {
             iab.addEventListener('loadstop', function(event) {
-                iab.executeScript({file: jsUrl});
+                iab.executeScript({file: jsUrl}, useCallback && 
function(results) {
+                    if (results && results.length === 0) {
+                        alert('Results verified');
+                    } else {
+                        console.log(results);
+                        alert('Got: ' + typeof(results) + '\n' + 
JSON.stringify(results));
+                    }
+                });
             });
         } else {
             iab.addEventListener('loadstop', function(event) {
                 var code = '(function(){\n' +
                   '    var header = document.getElementById("header");\n' +
                   '    header.innerHTML = "Script literal successfully 
injected";\n' +
-                  '    return {result:header};\n' +
+                  '    return "abc";\n' +
                   '})()';
-                iab.executeScript({code:code});
+                iab.executeScript({code:code}, useCallback && 
function(results) {
+                    if (results && results.length === 1 && results[0] === 
'abc') {
+                        alert('Results verified');
+                    } else {
+                        console.log(results);
+                        alert('Got: ' + typeof(results) + '\n' + 
JSON.stringify(results));
+                    }
+                });
             });
         }
     }
@@ -100,7 +123,7 @@
     <h1>InAppBrowser</h1>
     <div id="info">
         Make sure http://www.google.com is white listed. </br>
-        Make sure http://www.apple.com is not in the white list.</br>  In iOS, 
starred <span style="vertial-align:super">*</span> tests will leave the app 
with no way to return.  </br>
+        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>
         <h4>User-Agent: <span id="user-agent"> </span></h4>
     </div>
     <div onclick="backHome();">Back</div>
@@ -135,9 +158,13 @@
     <h1>CSS / JS Injection</h1>
     <div class="btn large" onclick="window.open('inject.html', 
'_blank');">Original Document</div>
     <div class="btn large" 
onclick="openWithStyle('inject.html','inject.css');">CSS File Injection</div>
+    <div class="btn large" onclick="openWithStyle('inject.html','inject.css', 
true);">CSS File Injection (CB)</div>
     <div class="btn large" onclick="openWithStyle('inject.html');">CSS Literal 
Injection</div>
+    <div class="btn large" onclick="openWithStyle('inject.html', null, 
true);">CSS Literal Injection (CB)</div>
     <div class="btn large" onclick="openWithScript('inject.html', 
'inject.js');">Script File Injection</div>
+    <div class="btn large" onclick="openWithScript('inject.html', 'inject.js', 
true);">Script File Injection (CB)</div>
     <div class="btn large" onclick="openWithScript('inject.html');">Script 
Literal Injection</div>
+    <div class="btn large" onclick="openWithScript('inject.html', null, 
true);">Script Literal Injection (CB)</div>
     <h2> </h2><div class="backBtn" onclick="backHome();">Back</div>
   </body>
 </html>

Reply via email to