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 2015/03/04 19:42:33 UTC

[5/5] spec commit: Fix failing tests caused by Android's whitelist behaviour change

Fix failing tests caused by Android's whitelist behaviour change


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

Branch: refs/heads/master
Commit: 7ad3e7572f1887bd8410a8b3ae15abb0ad6d35f7
Parents: 370f7b3
Author: Andrew Grieve <ag...@chromium.org>
Authored: Wed Mar 4 13:41:12 2015 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Wed Mar 4 13:42:22 2015 -0500

----------------------------------------------------------------------
 config.xml                                      |  1 +
 .../AndroidMobileSpecTestPlugin.java            | 33 ++++++++++++++++++
 cordova-plugin-mobilespec-tests/plugin.xml      | 10 ++++++
 .../tests/bridge.tests.js                       | 19 +++++++----
 .../tests/datauri.tests.js                      | 36 +++++++-------------
 .../tests/whitelist.tests.js                    |  2 +-
 6 files changed, 70 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/7ad3e757/config.xml
----------------------------------------------------------------------
diff --git a/config.xml b/config.xml
index 5fcfe86..922e481 100644
--- a/config.xml
+++ b/config.xml
@@ -38,6 +38,7 @@
     <allow-intent href="mailto:*" />
     <allow-intent href="tel:*" />
     <allow-intent href="www.google.com" />
+    <allow-navigation href="data:*" />
     <platform name="blackberry10">
         <access origin="file:///" />
         <access origin="https://www.apache.org" />

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/7ad3e757/cordova-plugin-mobilespec-tests/AndroidMobileSpecTestPlugin.java
----------------------------------------------------------------------
diff --git a/cordova-plugin-mobilespec-tests/AndroidMobileSpecTestPlugin.java b/cordova-plugin-mobilespec-tests/AndroidMobileSpecTestPlugin.java
new file mode 100644
index 0000000..3d7c717
--- /dev/null
+++ b/cordova-plugin-mobilespec-tests/AndroidMobileSpecTestPlugin.java
@@ -0,0 +1,33 @@
+/*
+       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.
+*/
+package org.apache.cordova.mobilespec;
+
+import android.net.Uri;
+
+import org.apache.cordova.CordovaPlugin;
+
+public class AndroidMobileSpecTestPlugin extends CordovaPlugin {
+    @Override
+    public Uri remapUri(Uri uri) {
+        if ("stealbridgesecret.test".equals(uri.getHost())) {
+            return Uri.parse("data:text/html,");
+        }
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/7ad3e757/cordova-plugin-mobilespec-tests/plugin.xml
----------------------------------------------------------------------
diff --git a/cordova-plugin-mobilespec-tests/plugin.xml b/cordova-plugin-mobilespec-tests/plugin.xml
index 14723db..bf87049 100644
--- a/cordova-plugin-mobilespec-tests/plugin.xml
+++ b/cordova-plugin-mobilespec-tests/plugin.xml
@@ -46,4 +46,14 @@
 
     <js-module src="tests/input.tests.js" name="input.tests">
     </js-module>
+     
+    <platform name="android">
+        <source-file src="AndroidMobileSpecTestPlugin.java" target-dir="src/org/apache/cordova/mobilespec" />
+        <config-file target="res/xml/config.xml" parent="/*">
+            <feature name="org.apache.cordova.mobilespec.tests" >
+                <param name="android-package" value="org.apache.cordova.mobilespec.AndroidMobileSpecTestPlugin"/>
+                <param name="onload" value="true" />
+            </feature>
+        </config-file>
+    </platform>
 </plugin>

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/7ad3e757/cordova-plugin-mobilespec-tests/tests/bridge.tests.js
----------------------------------------------------------------------
diff --git a/cordova-plugin-mobilespec-tests/tests/bridge.tests.js b/cordova-plugin-mobilespec-tests/tests/bridge.tests.js
index 9bf40f1..954f41e 100644
--- a/cordova-plugin-mobilespec-tests/tests/bridge.tests.js
+++ b/cordova-plugin-mobilespec-tests/tests/bridge.tests.js
@@ -20,20 +20,27 @@
  */
 exports.defineAutoTests = function () {
     describe('Bridge', function (done) {
+        var frame;
+        afterEach(function () {
+            if (frame) {
+                document.body.removeChild(frame);
+            }
+        });
         it("bridge.spec.1 should reject bridge from iframe with data: URL", function (done) {
             if (cordova.platformId != 'android') {
                 pending();
+                return;
             }
-            var ifr = document.createElement('iframe');
+            frame = document.createElement('iframe');
 
-            ifr.src = 'data:text/html,';
-            ifr.onload = function () {
-                var stolenSecret = ifr.contentWindow.prompt('', 'gap_init:');
+            // Gets intercepted in native.
+            frame.src = 'http://stealbridgesecret.test/';
+            frame.onload = function () {
+                var stolenSecret = frame.contentWindow.prompt('', 'gap_init:');
                 expect(!!stolenSecret).toBe(false);
                 done();
             };
-            document.body.appendChild(ifr);
+            document.body.appendChild(frame);
         });
-
     });
 }

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/7ad3e757/cordova-plugin-mobilespec-tests/tests/datauri.tests.js
----------------------------------------------------------------------
diff --git a/cordova-plugin-mobilespec-tests/tests/datauri.tests.js b/cordova-plugin-mobilespec-tests/tests/datauri.tests.js
index bda89c8..109e97d 100644
--- a/cordova-plugin-mobilespec-tests/tests/datauri.tests.js
+++ b/cordova-plugin-mobilespec-tests/tests/datauri.tests.js
@@ -22,31 +22,20 @@ exports.defineAutoTests = function () {
     var isWindows = (cordova.platformId === "windows") || (cordova.platformId === "windows8");
 
     describe('data uris', function () {
-        var gotFoo = false,
-            onMessageBind,
-            originalTimeout;
+        var frame;
+        var onMessageBind;
 
-        function onMessage (done, msg) {
-            gotFoo = gotFoo || msg.data == 'foo';
-            if (gotFoo) {
-                expect(gotFoo).toBe(true);
-                if (typeof(done) === 'function') {
-                    done();
-                }
+        function onMessage(done, msg) {
+            if (msg.data == 'foo') {
+                done();
             }
-        };
-
-        beforeEach(function () {
-            originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
-            jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;
-        });
+        }
 
         afterEach(function () {
-            if (this.frame) {
-                document.body.removeChild(this.frame);
+            if (frame) {
+                document.body.removeChild(frame);
                 window.removeEventListener('message', onMessageBind, false);
             }
-            jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
         });
 
         it("datauri.spec.1 should work with iframes", function (done) {
@@ -58,13 +47,12 @@ exports.defineAutoTests = function () {
                 pending();
             }
 
-            this.frame = document.createElement('iframe');
-
+            frame = document.createElement('iframe');
             onMessageBind = onMessage.bind(null, done);
             window.addEventListener('message', onMessageBind, false);
-            this.frame.src = 'data:text/html;charset=utf-8,%3Chtml%3E%3Cscript%3Eparent.postMessage%28%27foo%27%2C%27%2A%27%29%3C%2Fscript%3E%3C%2Fhtml%3E';
-            document.body.appendChild(this.frame);
-        }, 'iframe did not load.');
+            frame.src = 'data:text/html;charset=utf-8,%3Chtml%3E%3Cscript%3Eparent.postMessage%28%27foo%27%2C%27%2A%27%29%3C%2Fscript%3E%3C%2Fhtml%3E';
+            document.body.appendChild(frame);
+        }, 1000);
     });
 
     describe('data uris', function () {

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/7ad3e757/cordova-plugin-mobilespec-tests/tests/whitelist.tests.js
----------------------------------------------------------------------
diff --git a/cordova-plugin-mobilespec-tests/tests/whitelist.tests.js b/cordova-plugin-mobilespec-tests/tests/whitelist.tests.js
index 0440a08..4c7a4e4 100644
--- a/cordova-plugin-mobilespec-tests/tests/whitelist.tests.js
+++ b/cordova-plugin-mobilespec-tests/tests/whitelist.tests.js
@@ -200,7 +200,7 @@ exports.defineAutoTests = function () {
             itShouldReject('http://www.apache.org:pass@evil.com/');
             itShouldReject('http://www.apache.org.evil.com/');
             itShouldAccept('file:///foo');
-            itShouldAccept('content:///foo');
+            itShouldReject('content:///foo');
         });
     });
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org