cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i..@apache.org
Subject [1/4] spec commit: [CB-4094] Add whitelist spec tests
Date Thu, 11 Jul 2013 18:34:33 GMT
Updated Branches:
  refs/heads/master 7102bbf15 -> 4fd626a72


[CB-4094] Add whitelist spec tests


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

Branch: refs/heads/master
Commit: 4fd626a729dd3f1abc100446d9f4dc3eb7250f66
Parents: 2412466
Author: Ian Clelland <iclelland@chromium.org>
Authored: Thu Jul 11 14:33:51 2013 -0400
Committer: Ian Clelland <iclelland@chromium.org>
Committed: Thu Jul 11 14:34:21 2013 -0400

----------------------------------------------------------------------
 autotest/index.html               |   1 +
 autotest/pages/whitelist.html     |  71 +++++++++++++++++
 autotest/tests/whitelist.tests.js | 139 +++++++++++++++++++++++++++++++++
 3 files changed, 211 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/4fd626a7/autotest/index.html
----------------------------------------------------------------------
diff --git a/autotest/index.html b/autotest/index.html
index 15f3ed2..d213400 100644
--- a/autotest/index.html
+++ b/autotest/index.html
@@ -54,6 +54,7 @@
     <a href="pages/storage.html" class="btn large" style="width:100%;">Run Storage
Tests</a>
     <a href="pages/bridge.html" class="btn large" style="width:100%;">Run Bridge Tests</a>
     <a href="pages/splashscreen.html" class="btn large" style="width:100%;">Run Splashscreen
Tests</a>
+    <a href="pages/whitelist.html" class="btn large" style="width:100%;">Run Whitelist
Tests</a>
 
     <h2> </h2><div class="backBtn" onclick="backHome();">Back</div>
   </body>

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/4fd626a7/autotest/pages/whitelist.html
----------------------------------------------------------------------
diff --git a/autotest/pages/whitelist.html b/autotest/pages/whitelist.html
new file mode 100644
index 0000000..ca3712c
--- /dev/null
+++ b/autotest/pages/whitelist.html
@@ -0,0 +1,71 @@
+<!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>
+  <title>Cordova: Whitelist API Specs</title>
+
+  <meta name="viewport" content="width=device-width, height=device-height, user-scalable=yes,
initial-scale=1.0;" />
+  <!-- Load jasmine -->
+  <link href="../jasmine.css" rel="stylesheet"/>
+  <script type="text/javascript" src="../jasmine.js"></script>
+  <script type="text/javascript" src="../html/HtmlReporterHelpers.js"></script>
+  <script type="text/javascript" src="../html/HtmlReporter.js"></script>
+  <script type="text/javascript" src="../html/ReporterView.js"></script>
+  <script type="text/javascript" src="../html/SpecView.js"></script>
+  <script type="text/javascript" src="../html/SuiteView.js"></script>
+  <script type="text/javascript" src="../html/TrivialReporter.js"></script>
+
+  <!-- Source -->
+  <script type="text/javascript" src="../../cordova-incl.js"></script>
+
+  <!-- Load Test Runner -->
+  <script type="text/javascript" src="../test-runner.js"></script>
+
+  <!-- Tests -->
+  <script type="text/javascript" src="../tests/whitelist.tests.js"></script>
+
+  <script type="text/javascript">
+    document.addEventListener('deviceready', function () {
+      var jasmineEnv = jasmine.getEnv();
+      jasmineEnv.updateInterval = 1000;
+
+      var htmlReporter = new jasmine.HtmlReporter();
+
+      jasmineEnv.addReporter(htmlReporter);
+
+      jasmineEnv.specFilter = function(spec) {
+        return htmlReporter.specFilter(spec);
+      };
+
+      jasmineEnv.execute();
+    }, false);
+  </script>
+</head>
+
+<body>
+  <a href="javascript:" class="backBtn" onclick="backHome();">Back</a>
+</body>
+</html>
+

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/4fd626a7/autotest/tests/whitelist.tests.js
----------------------------------------------------------------------
diff --git a/autotest/tests/whitelist.tests.js b/autotest/tests/whitelist.tests.js
new file mode 100644
index 0000000..b1021b2
--- /dev/null
+++ b/autotest/tests/whitelist.tests.js
@@ -0,0 +1,139 @@
+/*
+ *
+ * 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.
+ *
+*/
+
+describe('Whitelist API (cordova.whitelist)', function () {
+	it("should exist", function() {
+        expect(cordova.whitelist).toBeDefined();
+	});
+
+    describe("Match function", function() {
+        function expectMatchWithResult(result) {
+            return (function(url, patterns, description) {
+                description = description || ((result ? "should accept " : "should reject
") + url + " for " + JSON.stringify(patterns));
+                it(description, function() {
+                    var cb = jasmine.createSpy();
+                    runs(function() {
+                        cordova.whitelist.match(url, patterns, cb);
+                    });
+                    waitsFor(function() { return cb.wasCalled; }, "success callback never
called", Tests.TEST_TIMEOUT);
+                    runs(function() {
+                        expect(cb).toHaveBeenCalledWith(result);
+                    });
+                });
+            });
+        }
+
+        var itShouldMatch = expectMatchWithResult(true);
+        var itShouldNotMatch = expectMatchWithResult(false);
+
+        it("should exist", function() {
+            expect(cordova.whitelist.match).toBeDefined();
+            expect(typeof cordova.whitelist.match).toBe("function");
+        });
+
+        itShouldMatch('http://www.apache.org/',['*'], "should accept any domain for *");
+        itShouldNotMatch('http://www.apache.org/',[], "should not accept any domain for []");
+
+        itShouldMatch('http://apache.org/', ['http://*.apache.org']);
+        itShouldMatch('http://www.apache.org/', ['http://*.apache.org']);
+        itShouldMatch('http://www.apache.org/some/path', ['http://*.apache.org']);
+        itShouldMatch('http://some.domain.under.apache.org/', ['http://*.apache.org']);
+        itShouldMatch('http://user:pass@apache.org/', ['http://*.apache.org']);
+        itShouldMatch('http://user:pass@www.apache.org/', ['http://*.apache.org']);
+        itShouldMatch('http://www.apache.org/?some=params', ['http://*.apache.org']);
+        itShouldNotMatch('http://apache.com/', ['http://*.apache.org']);
+        itShouldNotMatch('http://www.evil.com/?url=www.apache.org', ['http://*.apache.org']);
+        itShouldNotMatch('http://www.evil.com/?url=http://www.apache.org', ['http://*.apache.org']);
+        itShouldNotMatch('http://www.evil.com/?url=http%3A%2F%2Fwww%2Eapache%2Eorg', ['http://*.apache.org']);
+        itShouldNotMatch('https://apache.org/', ['http://*.apache.org']);
+        itShouldNotMatch('http://www.apache.org:pass@evil.com/', ['http://*.apache.org']);
+        itShouldNotMatch('http://www.apache.org.evil.com/', ['http://*.apache.org']);
+
+        itShouldMatch('http://www.apache.org/',['http://*.apache.org','https://*.apache.org']);
+        itShouldMatch('https://www.apache.org/',['http://*.apache.org','https://*.apache.org']);
+        itShouldNotMatch('ftp://www.apache.org/',['http://*.apache.org','https://*.apache.org']);
+        itShouldNotMatch('http://www.apache.com/',['http://*.apache.org','https://*.apache.org']);
+
+        itShouldMatch('http://www.apache.org/',['http://www.apache.org']);
+        itShouldNotMatch('http://build.apache.org/',['http://www.apache.org']);
+        itShouldNotMatch('http://apache.org/',['http://www.apache.org']);
+
+        itShouldMatch('http://www.apache.org/', ['http://*/*']);
+        itShouldMatch('http://www.apache.org/foo/bar.html', ['http://*/*']);
+
+        itShouldMatch('http://www.apache.org/foo', ['http://*/foo*']);
+        itShouldMatch('http://www.apache.org/foo/bar.html', ['http://*/foo*']);
+        itShouldNotMatch('http://www.apache.org/', ['http://*/foo*']);
+
+        itShouldMatch('file:///foo', ['file:///*']);
+
+        itShouldMatch('file:///foo', ['file:///foo*']);
+        itShouldMatch('file:///foo/bar.html', ['file:///foo*']);
+        itShouldNotMatch('file:///etc/foo', ['file:///foo*']);
+        itShouldNotMatch('http://www.apache.org/foo', ['file:///foo*']);
+
+        itShouldMatch('http://www.apache.org/', ['*://www.apache.org/*']);
+        itShouldMatch('https://www.apache.org/', ['*://www.apache.org/*']);
+        itShouldMatch('ftp://www.apache.org/', ['*://www.apache.org/*']);
+        itShouldNotMatch('http://www.apache.com/', ['*://www.apache.org/*']);
+    });
+
+    describe("Test function", function() {
+        function expectTestWithResult(result) {
+            return (function(url, description) {
+                description = description || ((result ? "should accept " : "should reject
") + url);
+                it(description, function() {
+                    var cb = jasmine.createSpy();
+                    runs(function() {
+                        cordova.whitelist.test(url, cb);
+                    });
+                    waitsFor(function() { return cb.wasCalled; }, "success callback never
called", Tests.TEST_TIMEOUT);
+                    runs(function() {
+                        expect(cb).toHaveBeenCalledWith(result);
+                    });
+                });
+            });
+        }
+
+        var itShouldAccept = expectTestWithResult(true);
+        var itShouldReject = expectTestWithResult(false);
+
+        it("should exist", function() {
+            expect(cordova.whitelist.test).toBeDefined();
+            expect(typeof cordova.whitelist.test).toBe("function");
+        });
+
+        itShouldAccept('http://apache.org');
+        itShouldAccept('http://apache.org/');
+        itShouldAccept('http://www.apache.org/');
+        itShouldAccept('http://www.apache.org/some/path');
+        itShouldAccept('http://some.domain.under.apache.org/');
+        itShouldAccept('http://user:pass@apache.org/');
+        itShouldAccept('http://user:pass@www.apache.org/');
+        itShouldAccept('https://www.apache.org/');
+        itShouldReject('ftp://www.apache.org/');
+        itShouldReject('http://www.apache.com/');
+        itShouldReject('http://www.apache.org:pass@evil.com/');
+        itShouldReject('http://www.apache.org.evil.com/');
+        itShouldAccept('file:///foo');
+        itShouldAccept('content:///foo');
+    });
+});


Mime
View raw message