You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2013/03/23 19:04:47 UTC

spec commit: [CB-2305] Add spec tests for InAppBrowser.insertCSS and InAppBrowser.executeScript APIs

Updated Branches:
  refs/heads/master 64e9bbadf -> dbf631c43


[CB-2305] Add spec tests for InAppBrowser.insertCSS and InAppBrowser.executeScript APIs


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/dbf631c4
Tree: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/tree/dbf631c4
Diff: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/diff/dbf631c4

Branch: refs/heads/master
Commit: dbf631c43a76181e132a950a445e452ab44adf1e
Parents: 64e9bba
Author: Ian Clelland <ic...@chromium.org>
Authored: Fri Mar 15 23:26:34 2013 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Sat Mar 23 13:28:33 2013 -0400

----------------------------------------------------------------------
 inappbrowser/index.html  |   42 ++++++++++++++++++++++++++++++++++++--
 inappbrowser/inject.css  |    3 ++
 inappbrowser/inject.html |   44 +++++++++++++++++++++++++++++++++++++++++
 inappbrowser/inject.js   |    2 +
 4 files changed, 88 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/dbf631c4/inappbrowser/index.html
----------------------------------------------------------------------
diff --git a/inappbrowser/index.html b/inappbrowser/index.html
index cfa68b9..51e1af3 100644
--- a/inappbrowser/index.html
+++ b/inappbrowser/index.html
@@ -30,7 +30,7 @@
     <script type="text/javascript" charset="utf-8" src="../cordova.js"></script>      
 
       
-<script type="text/javascript" charset="utf-8">
+    <script type="text/javascript" charset="utf-8">
 
     var deviceReady = false;
     
@@ -62,8 +62,38 @@
              }
         );
     }
-</script>
 
+    function openWithStyle(url, cssUrl) {
+        var iab = window.open(url, '_blank', 'location=yes');
+        if (cssUrl) {
+            iab.addEventListener('loadstop', function(event) {
+                iab.insertCSS({file: cssUrl});
+            });
+        } else {
+            iab.addEventListener('loadstop', function(event) {
+                iab.insertCSS({code:'#style-update-literal { \ndisplay: block !important; \n}'});
+            });
+        }
+    }
+
+    function openWithScript(url, jsUrl) {
+        var iab = window.open(url, '_blank', 'location=yes');
+        if (jsUrl) {
+            iab.addEventListener('loadstop', function(event) {
+                iab.executeScript({file: jsUrl});
+            });
+        } 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' +
+                  '})()';
+                iab.executeScript({code:code});
+            });
+        }
+    }
+    </script>
   </head>
   <body onload="init();" id="stage" class="theme">
   
@@ -102,6 +132,12 @@
     <div class="btn large" onclick="openWithErrorHandler('x-ttp://www.invalid.com/');">Invalid Scheme</div>
     <div class="btn large" onclick="openWithErrorHandler('http://www.inv;alid.com/');">Invalid Host</div>
     <div class="btn large" onclick="openWithErrorHandler('nonexistent.html');">Missing File</div>
+    <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');">CSS Literal Injection</div>
+    <div class="btn large" onclick="openWithScript('inject.html', 'inject.js');">Script File Injection</div>
+    <div class="btn large" onclick="openWithScript('inject.html');">Script Literal Injection</div>
     <h2> </h2><div class="backBtn" onclick="backHome();">Back</div>
   </body>
-</html>      
+</html>

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/dbf631c4/inappbrowser/inject.css
----------------------------------------------------------------------
diff --git a/inappbrowser/inject.css b/inappbrowser/inject.css
new file mode 100644
index 0000000..8e9904d
--- /dev/null
+++ b/inappbrowser/inject.css
@@ -0,0 +1,3 @@
+#style-update-file {
+    display: block !important;
+}

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/dbf631c4/inappbrowser/inject.html
----------------------------------------------------------------------
diff --git a/inappbrowser/inject.html b/inappbrowser/inject.html
new file mode 100644
index 0000000..2dacafe
--- /dev/null
+++ b/inappbrowser/inject.html
@@ -0,0 +1,44 @@
+<!DOCTYPE html>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+-->
+
+
+<html>
+  <head>
+    <meta name="viewport" content="width=device-width,height=device-height,user-scalable=no,maximum-scale=1.0,initial-scale=1.0" />
+    <meta http-equiv="Content-type" content="text/html; charset=utf-8"> <!-- ISO-8859-1 -->
+    <title>Cordova Mobile Spec</title>
+    <link rel="stylesheet" href="../master.css" type="text/css" media="screen" title="no title" charset="utf-8">
+    <script type="text/javascript" charset="utf-8" src="../cordova.js"></script>
+  </head>
+  <body id="stage" class="theme">
+    <h1 id="header">InAppBrowser - Script / Style Injection Test</h1>
+    <h2 id="style-update-file" style="display:none">Style updated from file</h2>
+    <h2 id="style-update-literal" style="display:none">Style updated from literal</h2>
+  </body>
+  <script>
+      function updateUserAgent() {
+          document.getElementById("u-a").textContent = navigator.userAgent;
+      }
+      updateUserAgent();
+      window.setInterval(updateUserAgent, 1500);
+  </script>
+</html>

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/dbf631c4/inappbrowser/inject.js
----------------------------------------------------------------------
diff --git a/inappbrowser/inject.js b/inappbrowser/inject.js
new file mode 100644
index 0000000..982c8bd
--- /dev/null
+++ b/inappbrowser/inject.js
@@ -0,0 +1,2 @@
+var d = document.getElementById("header")
+d.innerHTML = "Script file successfully injected";