You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2013/06/13 20:21:39 UTC
[16/78] [partial] start of lazy loading: axe all vendored-in libs
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/67fa7ebb/lib/cordova-blackberry/framework/test/unit/lib/plugins/event.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/framework/test/unit/lib/plugins/event.js b/lib/cordova-blackberry/framework/test/unit/lib/plugins/event.js
deleted file mode 100644
index ea92f1d..0000000
--- a/lib/cordova-blackberry/framework/test/unit/lib/plugins/event.js
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright 2010-2011 Research In Motion Limited.
- *
- * Licensed 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("event plugin", function () {
-
- var ROOT = "./../../../../",
- eventLib = require(ROOT + "lib/event"),
- eventPlugin;
-
- describe("once function", function () {
- var args = {
- eventName: encodeURIComponent(JSON.stringify("GRRRRR"))
- };
-
- it("calls success if no error", function () {
- var success = jasmine.createSpy(),
- fail = jasmine.createSpy(),
- webview = {};
-
- spyOn(eventLib, "add");
- delete require.cache[require.resolve(ROOT + "lib/plugins/event")];
- eventPlugin = require(ROOT + "lib/plugins/event");
- this.after(function () {
- delete require.cache[require.resolve(ROOT + "lib/plugins/event")];
- });
-
- eventPlugin.once(undefined, success, fail, args, {webview: webview});
-
- expect(eventLib.add).toHaveBeenCalledWith(
- {
- event: "GRRRRR",
- once: true
- },
- webview
- );
- expect(success).toHaveBeenCalled();
- expect(fail).not.toHaveBeenCalledWith(-1, jasmine.any(String));
- });
-
- it("calls fail if there is an error", function () {
- var success = jasmine.createSpy(),
- fail = jasmine.createSpy(),
- webview = {};
-
- spyOn(eventLib, "add").andThrow("ERRRORZ");
- delete require.cache[require.resolve(ROOT + "lib/plugins/event")];
- eventPlugin = require(ROOT + "lib/plugins/event");
- this.after(function () {
- delete require.cache[require.resolve(ROOT + "lib/plugins/event")];
- });
-
- eventPlugin.once(undefined, success, fail, args, {webview: webview});
-
- expect(eventLib.add).toHaveBeenCalledWith(
- {
- event: "GRRRRR",
- once: true
- },
- webview
- );
- expect(success).not.toHaveBeenCalled();
- expect(fail).toHaveBeenCalledWith(-1, jasmine.any(String));
- });
- });
-});
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/67fa7ebb/lib/cordova-blackberry/framework/test/unit/lib/policy/webkitOriginAccess.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/framework/test/unit/lib/policy/webkitOriginAccess.js b/lib/cordova-blackberry/framework/test/unit/lib/policy/webkitOriginAccess.js
deleted file mode 100644
index 4a5ac8e..0000000
--- a/lib/cordova-blackberry/framework/test/unit/lib/policy/webkitOriginAccess.js
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * Copyright 2012 Research In Motion Limited.
- *
- * Licensed 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.
- */
-
-var LIB_PATH = __dirname + "/../../../../lib/",
- utils = require(LIB_PATH + 'utils'),
- webkitOriginAccess = require(LIB_PATH + "policy/webkitOriginAccess"),
- LOCAL_URI = "local://",
- FILE_URI = "file://",
- WW_URI = utils.getURIPrefix(),
- mockWebView;
-
-describe("lib/policy/webkitOriginAccess", function () {
- beforeEach(function () {
- mockWebView = {
- addOriginAccessWhitelistEntry: jasmine.createSpy()
- };
- });
-
- afterEach(function () {
- mockWebView = undefined;
- delete require.cache[require.resolve(LIB_PATH + "config")];
- delete require.cache[require.resolve(LIB_PATH + "policy/webkitOriginAccess")];
- webkitOriginAccess = require(LIB_PATH + "policy/webkitOriginAccess");
- });
-
- function mockConfig(mockAccessList, hasMultiAccess) {
- delete require.cache[require.resolve(LIB_PATH + "config")];
- delete require.cache[require.resolve(LIB_PATH + "policy/webkitOriginAccess")];
- var config = require(LIB_PATH + "config");
- config.accessList = mockAccessList;
- config.hasMultiAccess = !!hasMultiAccess;
- webkitOriginAccess = require(LIB_PATH + "policy/webkitOriginAccess");
- }
-
- describe("addWebview function", function () {
-
- it("exists", function () {
- expect(webkitOriginAccess.addWebView).toBeDefined();
- });
-
- it("sets up one time whitelisting", function () {
- webkitOriginAccess.addWebView(mockWebView);
-
- expect(mockWebView.addOriginAccessWhitelistEntry).toHaveBeenCalledWith(LOCAL_URI, FILE_URI, true);
- expect(mockWebView.addOriginAccessWhitelistEntry).toHaveBeenCalledWith(FILE_URI, LOCAL_URI, true);
- expect(mockWebView.addOriginAccessWhitelistEntry).toHaveBeenCalledWith(LOCAL_URI, WW_URI, true);
- });
-
- it("initializes the webview with whitelisting based on the config", function () {
- var mockAccessList = [
- {
- uri : "http://google.com",
- allowSubDomain : true,
- features : null
- }
- ];
- mockConfig(mockAccessList);
-
- webkitOriginAccess.addWebView(mockWebView);
- expect(mockWebView.addOriginAccessWhitelistEntry).toHaveBeenCalledWith(LOCAL_URI, "http://google.com", true);
- expect(mockWebView.addOriginAccessWhitelistEntry).toHaveBeenCalledWith("http://google.com", LOCAL_URI, true);
- expect(mockWebView.addOriginAccessWhitelistEntry).toHaveBeenCalledWith("http://google.com", WW_URI, true);
- });
-
- it("initializes the webview with whitelisting based on what domains have been added", function () {
- var mockAccessList = [{
- uri : "http://google.com",
- allowSubDomain : true,
- features : null
- }],
- url = "http://www.rim.com";
-
- mockConfig(mockAccessList, true);
-
- webkitOriginAccess.addOriginAccess(url, true);
-
- webkitOriginAccess.addWebView(mockWebView);
- expect(mockWebView.addOriginAccessWhitelistEntry).toHaveBeenCalledWith(LOCAL_URI, url, true);
- expect(mockWebView.addOriginAccessWhitelistEntry).toHaveBeenCalledWith(url, LOCAL_URI, true);
- expect(mockWebView.addOriginAccessWhitelistEntry).toHaveBeenCalledWith(url, "http://google.com", true);
- expect(mockWebView.addOriginAccessWhitelistEntry).toHaveBeenCalledWith("http://google.com", url, true);
- expect(mockWebView.addOriginAccessWhitelistEntry).toHaveBeenCalledWith(url, WW_URI, true);
- });
-
- it("will not initialize twice", function () {
- var origCallCount;
-
- webkitOriginAccess.addWebView(mockWebView);
- origCallCount = mockWebView.addOriginAccessWhitelistEntry.callCount;
- webkitOriginAccess.addWebView(mockWebView);
-
- expect(mockWebView.addOriginAccessWhitelistEntry.callCount).toEqual(origCallCount);
- });
-
- });
-
- describe("addOriginAccess function", function () {
- it("exists", function () {
- expect(webkitOriginAccess.addOriginAccess).toBeDefined();
- });
-
- it("Treats falsey values as false", function () {
- var url = "http://www.rim.com";
-
- webkitOriginAccess.addWebView(mockWebView);
- webkitOriginAccess.addOriginAccess(url);
- expect(mockWebView.addOriginAccessWhitelistEntry).toHaveBeenCalledWith(LOCAL_URI, url, false);
- });
-
- it("Adds access for any non-local and non-file url", function () {
- var url = "http://www.rim.com/grrr/arrg/blah.htm";
-
- webkitOriginAccess.addWebView(mockWebView);
- webkitOriginAccess.addOriginAccess(url);
- expect(mockWebView.addOriginAccessWhitelistEntry).toHaveBeenCalledWith(LOCAL_URI, url, false);
- });
-
- //Because local:// is already a domain, the spy should not have no new calls
- it("Local uris are treated as local://", function () {
- var url = "local:///buy/local/beef/mmmmmmmmmmmmm/Steak.yum",
- origCallCount;
-
- webkitOriginAccess.addWebView(mockWebView);
- webkitOriginAccess.addOriginAccess(url);
- origCallCount = mockWebView.addOriginAccessWhitelistEntry.callCount;
- webkitOriginAccess.addOriginAccess(url);
- expect(mockWebView.addOriginAccessWhitelistEntry.callCount).toEqual(origCallCount);
- });
-
- it("File uris are treated as file://", function () {
- var url = "file:///buy/local/beef/mmmmmmmmmmmmm/Steak.yum",
- authority = "file://";
-
- webkitOriginAccess.addWebView(mockWebView);
- webkitOriginAccess.addOriginAccess(url);
- expect(mockWebView.addOriginAccessWhitelistEntry).toHaveBeenCalledWith(LOCAL_URI, authority, false);
- });
-
- it("updates all managed webviews of the new domain access", function () {
- var mockWebView2 = {
- addOriginAccessWhitelistEntry: jasmine.createSpy()
- },
- url = "http://www.rim.com";
-
- webkitOriginAccess.addWebView(mockWebView);
- webkitOriginAccess.addWebView(mockWebView2);
-
- webkitOriginAccess.addOriginAccess(url, true);
-
- expect(mockWebView.addOriginAccessWhitelistEntry).toHaveBeenCalledWith(LOCAL_URI, url, true);
- expect(mockWebView.addOriginAccessWhitelistEntry).toHaveBeenCalledWith(url, LOCAL_URI, true);
- expect(mockWebView.addOriginAccessWhitelistEntry).toHaveBeenCalledWith(url, WW_URI, true);
- expect(mockWebView2.addOriginAccessWhitelistEntry).toHaveBeenCalledWith(LOCAL_URI, url, true);
- expect(mockWebView2.addOriginAccessWhitelistEntry).toHaveBeenCalledWith(url, LOCAL_URI, true);
- expect(mockWebView2.addOriginAccessWhitelistEntry).toHaveBeenCalledWith(url, WW_URI, true);
- });
-
- it("updates all managed webviews when a new domain is added", function () {
- var mockAccessList = [{
- uri : "http://google.com",
- allowSubDomain : true,
- features : null
- }],
- url = "http://www.rim.com";
-
- mockConfig(mockAccessList, true);
-
- webkitOriginAccess.addWebView(mockWebView);
-
- expect(mockWebView.addOriginAccessWhitelistEntry).not.toHaveBeenCalledWith(url, "http://google.com", true);
- expect(mockWebView.addOriginAccessWhitelistEntry).not.toHaveBeenCalledWith("http://google.com", url, true);
-
- webkitOriginAccess.addOriginAccess(url, true);
-
- expect(mockWebView.addOriginAccessWhitelistEntry).toHaveBeenCalledWith(url, "http://google.com", true);
- expect(mockWebView.addOriginAccessWhitelistEntry).toHaveBeenCalledWith("http://google.com", url, true);
- });
-
- });
-
-});
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/67fa7ebb/lib/cordova-blackberry/framework/test/unit/lib/policy/whitelist.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/framework/test/unit/lib/policy/whitelist.js b/lib/cordova-blackberry/framework/test/unit/lib/policy/whitelist.js
deleted file mode 100644
index 59f9425..0000000
--- a/lib/cordova-blackberry/framework/test/unit/lib/policy/whitelist.js
+++ /dev/null
@@ -1,859 +0,0 @@
-/*
- * Copyright 2011 Research In Motion Limited.
- *
- * Licensed 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.
- */
-
-var srcPath = __dirname + "/../../../../lib/",
- Whitelist = require(srcPath + "policy/whitelist").Whitelist;
-
-describe("whitelist", function () {
- describe("when user includes a wildcard access", function () {
- it("can allow access to any domain not from XHR using uri *", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : true,
- accessList : null
- });
-
- expect(whitelist.isAccessAllowed("http://www.google.com")).toEqual(true);
- expect(whitelist.isAccessAllowed("http://www.msn.com")).toEqual(true);
- expect(whitelist.isAccessAllowed("http://www.cnn.com")).toEqual(true);
- expect(whitelist.isAccessAllowed("http://www.rim.com")).toEqual(true);
- expect(whitelist.isAccessAllowed("local:///index.html")).toEqual(true);
- expect(whitelist.isAccessAllowed("file://store/home/user/documents/file.doc")).toEqual(true);
- });
- it("can allow access to explicit domains only when XHR using uri *", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : true,
- accessList : [
- {
- uri : "http://google.com",
- allowSubDomain : true,
- features : null
- }
- ]
- });
-
- expect(whitelist.isAccessAllowed("http://www.google.com", true)).toEqual(true);
- expect(whitelist.isAccessAllowed("http://www.google.com/a/b/c", true)).toEqual(true);
- expect(whitelist.isAccessAllowed("http://www.msn.com", true)).toEqual(false);
- expect(whitelist.isAccessAllowed("http://www.cnn.com", true)).toEqual(false);
- });
- });
-
- describe("when user does not include a wildcard access", function () {
- it("can deny all web access when no uris are whitelisted", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : null
- });
-
- expect(whitelist.isAccessAllowed("http://www.google.com")).toEqual(false);
- });
-
- it("can deny all API access when no uris are whitelisted", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : null
- });
-
- expect(whitelist.isFeatureAllowed("http://www.google.com"), "blackberry.app").toEqual(false);
- });
-
- it("can return empty feature list when nothing is whitelisted", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : null
- });
-
- expect(whitelist.getFeaturesForUrl("http://www.google.com")).toEqual([]);
- });
-
- it("can allow access to whitelisted HTTP URL", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [{
- uri : "http://google.com",
- allowSubDomain : true,
- features : null
- }]
- });
-
- expect(whitelist.isAccessAllowed("http://www.google.com")).toEqual(true);
- expect(whitelist.isAccessAllowed("http://www.cnn.com")).toEqual(false);
- });
-
- it("can allow access to whitelisted URL with different case (host)", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [{
- uri : "http://google.com",
- allowSubDomain : true,
- features : null
- },
- {
- uri : "http://ABC.com",
- allowSubDomain : true,
- features : null
- }]
- });
-
- expect(whitelist.isAccessAllowed("http://www.GOOGLE.com")).toEqual(true);
- expect(whitelist.isAccessAllowed("http://www.abc.com")).toEqual(true);
- });
-
- it("can allow access to whitelisted URL with different case (path)", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [{
- uri : "http://google.com/SOME/path",
- allowSubDomain : true,
- features : null
- },
- {
- uri : "http://google.com/another/path",
- allowSubDomain : true,
- features : null
- }]
- });
-
- expect(whitelist.isAccessAllowed("http://www.google.com/some/path")).toEqual(true);
- expect(whitelist.isAccessAllowed("http://www.google.com/ANOTHER/path")).toEqual(true);
- });
-
- it("can deny access to non-whitelisted HTTP URL", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [{
- uri : "http://google.com",
- allowSubDomain : true,
- features : null
- }]
- });
-
- expect(whitelist.isAccessAllowed("http://www.cnn.com")).toEqual(false);
- });
-
- it("can allow access to whitelisted feature for whitelisted HTTP uris", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [
- {
- uri : "http://google.com",
- allowSubDomain : false,
- features : [{
- id : "blackberry.app",
- required : true,
- version : "1.0.0"
- }]
- }, {
- uri: "http://smoketest1-vmyyz.labyyz.testnet.rim.net:8080/",
- allowSubDomain: false,
- features: [{
- id : "blackberry.app",
- required : true,
- version : "1.0.0"
- }]
- }
- ]
- });
-
- expect(whitelist.isFeatureAllowed("http://google.com", "blackberry.app")).toEqual(true);
- expect(whitelist.isFeatureAllowed("http://smoketest1-vmyyz.labyyz.testnet.rim.net:8080/a/webworks.html", "blackberry.app")).toEqual(true);
- });
-
- it("can deny access to non-whitelisted feature for whitelisted HTTP uris", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [{
- uri : "http://google.com",
- allowSubDomain : false,
- features : [{
- id : "blackberry.app",
- required : true,
- version : "1.0.0"
- }]
- }]
- });
-
- expect(whitelist.isFeatureAllowed("http://google.com", "blackberry.io.file")).toEqual(false);
- });
-
- it("can get all whitelisted features for url", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [{
- uri : "http://google.com",
- allowSubDomain : false,
- features : [{
- id : "blackberry.app",
- required : true,
- version : "1.0.0"
- }, {
- id : "blackberry.media.camera",
- required : true,
- version : "1.0.0"
- }, {
- id : "blackberry.io.dir",
- required : true,
- version : "1.0.0"
- }]
- }]
- });
-
- expect(whitelist.getFeaturesForUrl("http://google.com")).toContain("blackberry.app");
- expect(whitelist.getFeaturesForUrl("http://google.com")).toContain("blackberry.media.camera");
- expect(whitelist.getFeaturesForUrl("http://google.com")).toContain("blackberry.io.dir");
- expect(whitelist.getFeaturesForUrl("http://www.wikipedia.org")).toEqual([]);
- });
-
- it("can allow access for query strings using a query string wildcard", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [{
- uri : "http://www.google.com/search?*",
- allowSubDomain : true,
- features : null
- }]
- });
-
- expect(whitelist.isAccessAllowed("http://www.google.com/search?q=awesome")).toEqual(true);
- expect(whitelist.isAccessAllowed("http://www.google.com/search?a=anyLetter")).toEqual(true);
- expect(whitelist.isAccessAllowed("http://www.google.com/search")).toEqual(false);
- expect(whitelist.isAccessAllowed("http://www.google.com/blah?q=awesome")).toEqual(false);
- });
-
- it("can deny access for query strings without a query string wildcard", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [{
- uri : "http://www.google.com/search",
- allowSubDomain : true,
- features : null
- }]
- });
-
- expect(whitelist.isAccessAllowed("http://www.google.com/search?q=awesome", true)).toEqual(false);
- expect(whitelist.isAccessAllowed("http://www.google.com/search?a=anyLetter", true)).toEqual(false);
- });
-
- it("can allow access for ports given just the whitelist url", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [{
- uri : "http://www.awesome.com",
- allowSubDomain : true,
- features : null
- }]
- });
-
- expect(whitelist.isAccessAllowed("http://www.awesome.com:9000")).toEqual(true);
- });
-
- it("allows api access for ports given just the whitelist url", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [{
- uri : "http://www.awesome.com",
- allowSubDomain : true,
- features : [{
- id : "blackberry.app",
- required : true,
- version : "1.0.0"
- }]
- }]
- });
-
- expect(whitelist.isFeatureAllowed("http://www.awesome.com:8080", "blackberry.app")).toEqual(true);
- });
-
- it("allows api access for child pages with ports given just the whitelist url", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [{
- uri : "http://smoketest8-vmyyz.labyyz.testnet.rim.net/",
- allowSubDomain : true,
- features : [{
- id : "blackberry.app",
- required : true,
- version : "1.0.0"
- }]
- }]
- });
-
- expect(whitelist.isFeatureAllowed("http://www.smoketest8-vmyyz.labyyz.testnet.rim.net:8080//webworks.html", "blackberry.app")).toEqual(true);
- });
-
- it("can allow folder level access of whitelisted uris", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [{
- uri : "http://www.awesome.com/parent/child",
- allowSubDomain : false,
- features : null
- }]
- });
-
- expect(whitelist.isAccessAllowed("http://www.awesome.com/parent/child")).toEqual(true);
- });
-
- it("can deny access to parent folders of whitelisted uris", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [{
- uri : "http://www.awesome.com/parent/child",
- allowSubDomain : false,
- features : null
- }]
- });
-
- expect(whitelist.isAccessAllowed("http://www.awesome.com/parent")).toEqual(false);
- });
-
- it("can deny access to sibling folders of whitelisted uris", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [{
- uri : "http://www.awesome.com/parent/child/",
- allowSubDomain : false,
- features : null
- }]
- });
-
- expect(whitelist.isAccessAllowed("http://www.awesome.com/parent/sibling/")).toEqual(false);
- });
-
- it("can deny access to sibling folders of whitelisted uris", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [{
- uri : "http://rim4.awesome.com/goodChild/index.html",
- allowSubDomain : false,
- features : null
- }]
- });
-
- expect(whitelist.isAccessAllowed("http://rim4.awesome.com/goodChild/index.html")).toEqual(true);
- expect(whitelist.isAccessAllowed("http://rim4.awesome.com/badChild/index.html")).toEqual(false);
- });
-
- it("can get whitelisted features at a folder level", function () {
- var list1 = [{
- id : "blackberry.app",
- required : true,
- version : "1.0.0"
- }],
- list2 = [{
- id : "blackberry.media.camera",
- required : true,
- version : "1.0.0"
- }],
- whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [{
- uri : "http://google.com/ninjas",
- allowSubDomain : true,
- features : list1
- }, {
- uri : "http://google.com/pirates",
- allowSubDomain : true,
- features : list2
- }]
- });
-
- expect(whitelist.getFeaturesForUrl("http://google.com/ninjas")).toEqual(["blackberry.app"]);
- expect(whitelist.getFeaturesForUrl("http://google.com/pirates")).toEqual(["blackberry.media.camera"]);
- });
-
- it("can allow API permissions at a folder level", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [{
- uri : "http://google.com/ninjas",
- allowSubDomain : true,
- features : [{
- id : "blackberry.app",
- required : true,
- version : "1.0.0"
- }]
- }, {
- uri : "http://google.com/pirates",
- allowSubDomain : true,
- features : [{
- id : "blackberry.media.camera",
- required : true,
- version : "1.0.0"
- }]
- }]
- });
-
- expect(whitelist.isFeatureAllowed("http://google.com/ninjas", "blackberry.app")).toEqual(true);
- expect(whitelist.isFeatureAllowed("http://google.com/pirates", "blackberry.media.camera")).toEqual(true);
- });
-
- it("can deny API permissions at a folder level", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [{
- uri : "http://google.com/ninjas",
- allowSubDomain : true,
- features : [{
- id : "blackberry.app",
- required : true,
- version : "1.0.0"
- }]
- }, {
- uri : "http://google.com/pirates",
- allowSubDomain : true,
- features : [{
- id : "blackberry.media.camera",
- required : true,
- version : "1.0.0"
- }]
- }]
- });
-
- expect(whitelist.isFeatureAllowed("http://google.com/ninjas", "blackberry.media.camera")).toEqual(false);
- expect(whitelist.isFeatureAllowed("http://google.com/pirates", "blackberry.app")).toEqual(false);
- });
-
- it("can allow access specific folder rules to override more general domain rules", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [{
- uri : "http://google.com",
- allowSubDomain : true,
- features : [{
- id : "blackberry.app",
- required : true,
- version : "1.0.0"
- }]
- }, {
- uri : "http://google.com/folder",
- allowSubDomain : true,
- features : [{
- id : "blackberry.media.camera",
- required : true,
- version : "1.0.0"
- }]
- }]
- });
-
- expect(whitelist.isFeatureAllowed("http://google.com/folder", "blackberry.app")).toEqual(false);
- expect(whitelist.isFeatureAllowed("http://google.com/folder", "blackberry.media.camera")).toEqual(true);
- });
-
- describe("when access uris have subdomains", function () {
- it("can get whitelisted features for subdomains", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [{
- uri : "http://google.com",
- allowSubDomain : true,
- features : [{
- id : "blackberry.system",
- required : true,
- version : "1.0.0.0"
- }, {
- id : "blackberry.media.microphone",
- required : true,
- version : "1.0.0.0"
- }]
- }]
- });
-
- expect(whitelist.getFeaturesForUrl("http://code.google.com")).toContain("blackberry.media.microphone");
- expect(whitelist.getFeaturesForUrl("http://code.google.com")).toContain("blackberry.system");
- expect(whitelist.getFeaturesForUrl("http://translate.google.com/lang=en")).toContain("blackberry.media.microphone");
- expect(whitelist.getFeaturesForUrl("http://translate.google.com/lang=en")).toContain("blackberry.system");
- expect(whitelist.getFeaturesForUrl("http://blah.goooooogle.com")).toEqual([]);
- });
-
- it("can allow access to whitelisted features for the subdomains", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [{
- uri : "http://google.com",
- allowSubDomain : true,
- features : [{
- id : "blackberry.app",
- required : true,
- version : "1.0.0"
- }]
- }]
- });
-
- expect(whitelist.isFeatureAllowed("http://abc.google.com", "blackberry.app")).toEqual(true);
- expect(whitelist.isFeatureAllowed("http://xyz.google.com", "blackberry.app")).toEqual(true);
- });
-
- it("can allow access to subdomains of whitelisted uris", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [
- {
- uri : "http://awesome.com/",
- allowSubDomain : true,
- features : null
- }, {
- uri: "http://smoketest9-vmyyz.labyyz.testnet.rim.net:8080",
- allowSubDomain: true,
- features: null
- }
- ]
- });
-
- expect(whitelist.isAccessAllowed("http://subdomain.awesome.com")).toEqual(true);
- expect(whitelist.isAccessAllowed("http://www.smoketest9-vmyyz.labyyz.testnet.rim.net:8080")).toEqual(true);
- });
-
- it("can disallow access to subdomains of whitelisted uris", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [{
- uri : "http://awesome.com/",
- allowSubDomain : false,
- features : null
- }]
- });
-
- expect(whitelist.isAccessAllowed("http://subdomain.awesome.com")).toEqual(false);
- });
-
- it("can disallow access to subdomains of a specified uri", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [{
- uri : "http://awesome.com/",
- allowSubDomain : true,
- features : null
- }, {
- uri : "http://moreawesome.com/",
- allowSubDomain : false,
- features : null
- }]
- });
-
- expect(whitelist.isAccessAllowed("http://subdomain.moreawesome.com")).toEqual(false);
- });
-
- it("can allow specific subdomain rules to override more general domain rules when subdomains are allowed", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [{
- uri : "http://google.com",
- allowSubDomain : true,
- features : [{
- id : "blackberry.app",
- required : true,
- version : "1.0.0"
- }]
- }, {
- uri : "http://sub.google.com",
- allowSubDomain : true,
- features : [{
- id : "blackberry.media.camera",
- required : true,
- version : "1.0.0"
- }]
- }]
- });
-
- expect(whitelist.isFeatureAllowed("http://sub.google.com", "blackberry.app")).toEqual(false);
- expect(whitelist.isFeatureAllowed("http://sub.google.com", "blackberry.media.camera")).toEqual(true);
- });
-
- it("can get whitelisted features for a more specific subdomain", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [{
- uri : "http://google.com",
- allowSubDomain : false,
- features : [{
- id : "blackberry.app",
- required : true,
- version : "1.0.0"
- }]
- }, {
- uri : "http://sub.google.com",
- allowSubDomain : false,
- features : [{
- id : "blackberry.media.camera",
- required : true,
- version : "1.0.0"
- }]
- }]
- });
-
- expect(whitelist.getFeaturesForUrl("http://google.com")).toContain("blackberry.app");
- expect(whitelist.getFeaturesForUrl("http://sub.google.com")).toContain("blackberry.media.camera");
- expect(whitelist.getFeaturesForUrl("http://sub.google.com")).not.toContain("blckberry.app");
- expect(whitelist.getFeaturesForUrl("http://code.google.com")).toEqual([]);
- });
-
- it("can allow specific subdomain rules to override more general domain rules when subdomains are disallowed", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [{
- uri : "http://google.com",
- allowSubDomain : false,
- features : [{
- id : "blackberry.app",
- required : true,
- version : "1.0.0"
- }]
- }, {
- uri : "http://sub.google.com",
- allowSubDomain : false,
- features : [{
- id : "blackberry.media.camera",
- required : true,
- version : "1.0.0"
- }]
- }]
- });
-
- expect(whitelist.isFeatureAllowed("http://sub.google.com", "blackberry.app")).toEqual(false);
- expect(whitelist.isFeatureAllowed("http://sub.google.com", "blackberry.media.camera")).toEqual(true);
- });
- });
-
- describe("when uris with other protocols are requested", function () {
- it("can allow access to whitelisted HTTPS URL", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [{
- uri : "https://google.com",
- allowSubDomain : true,
- features : null
- }]
- });
-
- expect(whitelist.isAccessAllowed("https://www.google.com")).toEqual(true);
- expect(whitelist.isAccessAllowed("https://www.cnn.com")).toEqual(false);
- });
-
- it("can deny access to non-whitelisted HTTPS URL", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [{
- uri : "https://google.com",
- allowSubDomain : true,
- features : null
- }]
- });
-
- expect(whitelist.isAccessAllowed("https://www.cnn.com")).toEqual(false);
- });
-
- it("can allow access to local URLs", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [{
- uri : "WIDGET_LOCAL", // packager always inserts a local access into access list
- allowSubDomain : false
- }]
- });
-
- expect(whitelist.isAccessAllowed("local:///index.html")).toEqual(true);
- expect(whitelist.isAccessAllowed("local:///appDir/subDir/index.html")).toEqual(true);
- });
-
- it("can allow access to whitelisted features for local URLs", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [{
- uri : "WIDGET_LOCAL", // packager always inserts a local access into access list
- allowSubDomain : false,
- features : [{
- id : "blackberry.media.microphone",
- required : true,
- version : "2.0.0"
- }, {
- id : "blackberry.media.camera",
- required : true,
- version : "1.0.0"
- }]
- }]
- });
-
- expect(whitelist.isFeatureAllowed("local:///index.html", "blackberry.media.microphone")).toEqual(true);
- expect(whitelist.isFeatureAllowed("local:///index.html", "blackberry.media.camera")).toEqual(true);
- });
-
- it("can allow access to whitelisted file URL", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [{
- uri : "file://store/home/user/documents",
- allowSubDomain : false,
- features : null
- }]
- });
-
- expect(whitelist.isAccessAllowed("file://store/home/user/documents/file.doc")).toEqual(true);
- });
-
- it("can access file if rule specifed was file:///", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [
- {
- uri : "file:///accounts/1000/shared/documents/textData.txt",
- allowSubDomain : false,
- features: []
- }
- ]
- });
-
- expect(whitelist.isAccessAllowed("file:///accounts/1000/shared/documents/textData.txt")).toEqual(true);
- expect(whitelist.isAccessAllowed("file:///etc/passwd")).toEqual(false);
- });
-
- it("can access file if rule specifed was file:///", function () {
- var whitelist = new Whitelist({
- "hasMultiAccess": false,
- "accessList": [
- {
- "features": [],
- "uri": "WIDGET_LOCAL",
- "allowSubDomain": true
- },
- {
- "features": [],
- "uri": "file:///accounts/1000/shared/documents/textData.txt"
- }
- ]
- });
- expect(whitelist.isAccessAllowed("file:///etc/passwd", false)).toEqual(false);
- });
-
- it("can deny file access when access file:/// with no rule", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : null
- });
-
- expect(whitelist.isAccessAllowed("file:///accounts/1000/shared/documents/textData.txt")).toEqual(false);
- });
-
- it("can allow access to whitelisted file URL from an external startup page", function () {
- var whitelist = new Whitelist({
- content: "http://www.google.com",
- hasMultiAccess : false,
- accessList : [{
- uri : "file://store/home/user/documents",
- allowSubDomain : false,
- features : null
- }]
- });
-
- expect(whitelist.isAccessAllowed("file://store/home/user/documents/file.doc")).toEqual(true);
- });
-
- it("can allow access to whitelisted local URL from an external startup page", function () {
- var whitelist = new Whitelist({
- content: "http://www.google.com",
- hasMultiAccess : false,
- accessList : [{
- uri : "local://localpage.html",
- allowSubDomain : false,
- features : null
- }]
- });
-
- expect(whitelist.isAccessAllowed("local://localpage.html")).toEqual(true);
- });
-
- it("can allow access to whitelisted file URL from an external startup page with wildcard access", function () {
- var whitelist = new Whitelist({
- content: "http://www.google.com",
- hasMultiAccess : true
- });
-
- expect(whitelist.isAccessAllowed("file://store/home/user/documents/file.doc")).toEqual(true);
- });
-
- it("can allow access to whitelisted local URL from an external startup page with wildcard access", function () {
- var whitelist = new Whitelist({
- content: "http://www.google.com",
- hasMultiAccess : true
- });
-
- expect(whitelist.isAccessAllowed("local://localpage.html")).toEqual(true);
- });
-
- it("can deny file URL access when no file urls are whitelisted", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : null
- });
-
- expect(whitelist.isAccessAllowed("file://store/home/user/documents/file.doc")).toEqual(false);
- });
-
- it("can allow access to a subfolder of a whitelisted file URL", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [{
- uri : "file://store/home/user/",
- allowSubDomain : false,
- features : null
- }]
- });
-
- expect(whitelist.isAccessAllowed("file://store/home/user/documents/file.doc")).toEqual(true);
- });
-
- it("can deny access to a different folder of a whitelisted file URL", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [{
- uri : "http://store.com/home/user/documents",
- allowSubDomain : false,
- features : null
- }]
- });
-
- expect(whitelist.isAccessAllowed("http://store.com/home/user/documents/file.doc")).toEqual(true);
- expect(whitelist.isAccessAllowed("http://store.com/file2.doc")).toEqual(false);
- });
-
- it("can allow access to RTSP protocol urls", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [{
- uri : "rtsp://media.com",
- allowSubDomain : false,
- features : null
- }]
- });
-
- expect(whitelist.isAccessAllowed("rtsp://media.com/video.avi")).toEqual(true);
- });
-
- it("always allows access to data-uris", function () {
- var whitelist = new Whitelist({
- hasMultiAccess : false,
- accessList : [{
- uri : "http://awesome.com",
- allowSubDomain : false,
- features : null
- }]
- });
-
- expect(whitelist.isAccessAllowed("data:image/png;base64,zamagawdbase64string")).toEqual(true);
- });
- });
- });
-});
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/67fa7ebb/lib/cordova-blackberry/framework/test/unit/lib/server.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/framework/test/unit/lib/server.js b/lib/cordova-blackberry/framework/test/unit/lib/server.js
deleted file mode 100644
index 2b89b0a..0000000
--- a/lib/cordova-blackberry/framework/test/unit/lib/server.js
+++ /dev/null
@@ -1,293 +0,0 @@
-/*
- * Copyright 2010-2011 Research In Motion Limited.
- *
- * Licensed 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.
- */
-var ROOT = "../../../";
-
-describe("server", function () {
-
- var server = require(ROOT + "lib/server"),
- plugin = require(ROOT + "lib/plugins/default"),
- applicationAPIServer,
- utils,
- DEFAULT_SERVICE = "default",
- DEFAULT_ACTION = "exec",
- config = {};
-
- beforeEach(function () {
- applicationAPIServer = {
- getReadOnlyFields: function () {}
- };
- delete require.cache[require.resolve(ROOT + "lib/utils")];
- utils = require("../../../lib/utils");
- spyOn(utils, "loadModule").andCallFake(function (module) {
- if (module.indexOf("plugin/") >= 0) {
- // on device, "plugin/blackberry.app/index.js" would exist
- return applicationAPIServer;
- } else {
- return require("../../../lib/" + module);
- }
- });
- });
-
- describe("when handling requests", function () {
- var req, res;
-
- beforeEach(function () {
- req = {
- params: {
- service: "",
- action: ""
- },
- body: "",
- origin: ""
- };
- res = {
- send: jasmine.createSpy()
- };
- GLOBAL.frameworkModules = ['plugin/blackberry.app/index.js', 'lib/plugins/default.js'];
- });
-
- afterEach(function () {
- delete GLOBAL.frameworkModules;
- });
-
- it("calls the default plugin if the service doesn't exist", function () {
- var rebuiltRequest = {
- params: {
- service: DEFAULT_SERVICE,
- action: DEFAULT_ACTION,
- ext: "not",
- method: "here",
- args: null
- },
- body: "",
- origin: ""
- },
- webview = {};
-
- spyOn(plugin, DEFAULT_ACTION);
- req.params.service = "not";
- req.params.action = "here";
-
- server.handle(req, res, webview, config);
-
- expect(plugin[DEFAULT_ACTION]).toHaveBeenCalledWith(
- rebuiltRequest, jasmine.any(Function),
- jasmine.any(Function),
- rebuiltRequest.params.args,
- {
- request: rebuiltRequest,
- response: res,
- webview: webview,
- config: config
- }
- );
- });
-
- it("returns 404 if the action doesn't exist", function () {
- req.params.service = "default";
- req.params.action = "ThisActionDoesNotExist";
-
- spyOn(console, "error");
-
- server.handle(req, res);
- expect(res.send).toHaveBeenCalledWith(404, jasmine.any(String));
- expect(console.error).toHaveBeenCalled();
- });
-
- it("calls the action method on the plugin", function () {
- var webview = "BLAHBLAHBLAH";
-
- spyOn(plugin, "exec");
-
- req.params.service = "default";
- req.params.action = "exec";
-
- expect(function () {
- return server.handle(req, res, webview, config);
- }).not.toThrow();
- expect(plugin.exec).toHaveBeenCalledWith(
- req,
- jasmine.any(Function),
- jasmine.any(Function),
- req.params.args,
- {
- request: req,
- response: res,
- webview: webview,
- config: config
- });
- });
-
- it("parses url encoded args", function () {
- var webview = "BLAHBLAHBLAH";
-
- spyOn(plugin, "exec");
-
- expect(function () {
- req.params.service = "default";
- req.params.action = "exec";
- req.params.args = "a=1&b=2&c=3";
-
- return server.handle(req, res, webview);
- }).not.toThrow();
- expect(plugin.exec).toHaveBeenCalledWith(
- jasmine.any(Object),
- jasmine.any(Function),
- jasmine.any(Function),
- {
- a: '1',
- b: '2',
- c: '3'
- },
- jasmine.any(Object)
- );
- });
-
- it("parses url encoded args", function () {
- var webview = "BLAHBLAHBLAH";
-
- spyOn(plugin, "exec");
-
- expect(function () {
- req.params.service = "default";
- req.params.action = "exec";
- req.body = JSON.stringify({a: '1', b: '2', c: '3'});
-
- return server.handle(req, res, webview);
- }).not.toThrow();
- expect(plugin.exec).toHaveBeenCalledWith(
- jasmine.any(Object),
- jasmine.any(Function),
- jasmine.any(Function),
- {
- a: '1',
- b: '2',
- c: '3'
- },
- jasmine.any(Object)
- );
- });
-
- it("returns the result and code 42 when success callback called", function () {
- spyOn(plugin, "exec").andCallFake(function (request, succ, fail, body) {
- succ(["MyFeatureId"]);
- });
-
- req.params.service = "default";
- req.params.action = "exec";
-
- server.handle(req, res);
- expect(res.send).toHaveBeenCalledWith(200, encodeURIComponent(JSON.stringify({
- code: 42,
- data: ["MyFeatureId"]
- })));
- });
-
- it("returns the result and code -1 when fail callback called", function () {
- spyOn(plugin, "exec").andCallFake(function (request, succ, fail, body) {
- fail(-1, "ErrorMessage");
- });
-
- req.params.service = "default";
- req.params.action = "exec";
-
- server.handle(req, res);
- expect(res.send).toHaveBeenCalledWith(200, encodeURIComponent(JSON.stringify({
- code: -1,
- data: null,
- msg: "ErrorMessage"
- })));
- });
- });
-
- describe("when handling feature requests", function () {
- var req, res;
-
- beforeEach(function () {
- req = {
- params: {
- service: "default",
- action: "exec",
- ext: "blackberry.app",
- method: "getReadOnlyFields",
- args: null
- },
- headers: {
- host: ""
- },
- url: "",
- body: "",
- origin: ""
- };
- res = {
- send: jasmine.createSpy()
- };
- GLOBAL.frameworkModules = ['plugin/blackberry.app/index.js', 'lib/plugins/default.js'];
- });
-
- afterEach(function () {
- delete GLOBAL.frameworkModules;
- });
-
- it("calls the action method on the feature", function () {
- var webview = {};
- spyOn(applicationAPIServer, "getReadOnlyFields");
- server.handle(req, res, webview, config);
- expect(applicationAPIServer.getReadOnlyFields).toHaveBeenCalledWith(
- jasmine.any(Function),
- jasmine.any(Function),
- req.params.args,
- {
- request: req,
- response: res,
- webview: webview,
- config: config
- }
- );
- });
-
- it("returns the result and code 42 when success callback called", function () {
- var expectedResult = {"getReadOnlyFields": "Yogi bear"};
-
- spyOn(applicationAPIServer, "getReadOnlyFields").andCallFake(function (success, fail) {
- success(expectedResult);
- });
-
- server.handle(req, res);
-
- expect(res.send).toHaveBeenCalledWith(200, encodeURIComponent(JSON.stringify({
- code: 42,
- data: expectedResult
- })));
- });
-
- it("returns the result and code -1 when fail callback called", function () {
- var expectedResult = "omg";
-
- spyOn(applicationAPIServer, "getReadOnlyFields").andCallFake(function (success, fail) {
- fail(-1, expectedResult);
- });
-
- server.handle(req, res);
-
- expect(res.send).toHaveBeenCalledWith(200, encodeURIComponent(JSON.stringify({
- code: -1,
- data: null,
- msg: expectedResult
- })));
- });
- });
-});
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/67fa7ebb/lib/cordova-blackberry/framework/test/unit/lib/utils.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/framework/test/unit/lib/utils.js b/lib/cordova-blackberry/framework/test/unit/lib/utils.js
deleted file mode 100644
index 4b7f5a8..0000000
--- a/lib/cordova-blackberry/framework/test/unit/lib/utils.js
+++ /dev/null
@@ -1,280 +0,0 @@
-/*
- * Copyright 2010-2011 Research In Motion Limited.
- *
- * Licensed 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.
- */
-
-var srcPath = __dirname + '/../../../lib/';
-
-describe("Utils", function () {
- var utils = require(srcPath + 'utils.js');
-
- describe("endsWith", function () {
- it("returns true when a string ends with another", function () {
- expect(utils.endsWith("www.smoketest9-vmyyz.labyyz.testnet.rim.net:8080", ".smoketest9-vmyyz.labyyz.testnet.rim.net:8080")).toEqual(true);
- });
- });
-
- it("Verify that the filenameToImageMIME is defined", function () {
- expect(utils.fileNameToImageMIME).toBeDefined();
- });
-
- it("Verify that the proper PNG MIME types are returned", function () {
- expect(utils.fileNameToImageMIME("test.png")).toEqual("image/png");
- });
-
- it("Verify that the proper period MIME types are returned", function () {
- expect(utils.fileNameToImageMIME("test.t.png")).toEqual("image/png");
- });
-
- it("Verify that the proper JPG types are returned", function () {
- expect(utils.fileNameToImageMIME("test.jpg")).toEqual("image/jpeg");
- });
-
- it("Verify that the proper GIF types are returned", function () {
- expect(utils.fileNameToImageMIME("test.gif")).toEqual("image/gif");
- });
-
- it("Verify that the proper TIFF types are returned", function () {
- expect(utils.fileNameToImageMIME("test_test_.tif")).toEqual("image/tiff");
- });
-
- it("Verify that the proper TIFF types are returned", function () {
- expect(utils.fileNameToImageMIME("test_test_.tiff")).toEqual("image/tiff");
- });
-
- it("Verify that the proper JPE MIME types are returned", function () {
- expect(utils.fileNameToImageMIME("test.jpe")).toEqual("image/jpeg");
- });
-
- it("Verify that the proper BMP MIME types are returned", function () {
- expect(utils.fileNameToImageMIME("test.bmp")).toEqual("image/bmp");
- });
-
- it("Verify that the proper JPEG MIME types are returned", function () {
- expect(utils.fileNameToImageMIME("test.jpeg")).toEqual("image/jpeg");
- });
-
- it("Verify that the proper SVG MIME types are returned", function () {
- expect(utils.fileNameToImageMIME("test.svg")).toEqual("image/svg+xml");
- });
-
- it("has an invokeInBrowser function", function () {
- var url = "http://www.webworks.com",
- mockApplication = {
- invocation: {
- invoke: jasmine.createSpy("invocation.invoke")
- }
- },
- mockWindow = {
- qnx: {
- webplatform: {
- getApplication: function () {
- return mockApplication;
- }
- }
- }
- };
-
- GLOBAL.window = mockWindow;
-
- this.after(function () {
- delete GLOBAL.window;
- });
-
- expect(utils.invokeInBrowser).toBeDefined();
-
- utils.invokeInBrowser(url);
-
- expect(mockApplication.invocation.invoke).toHaveBeenCalledWith({
- uri: url,
- target: "sys.browser"
- });
- });
-
- // A cascading method invoker, kinda like jWorkflow
- describe("series", function () {
- var tasks,
- callbackObj,
- seriesComplete,
- callbackInvocations,
- invocationCounter,
- task;
-
- beforeEach(function () {
- tasks = [];
- callbackInvocations = [];
- invocationCounter = 0;
- seriesComplete = false;
- callbackObj = {
- func: function (args) {
- callbackInvocations.push('done');
- seriesComplete = true;
- },
- args: []
- };
- task = {
- func: function (callback) {
- callbackInvocations.push(invocationCounter++);
- callback();
- },
- args: []
- };
- });
-
- afterEach(function () {
- tasks = null;
- callbackObj = null;
- seriesComplete = null;
- callbackInvocations = null;
- invocationCounter = null;
- task = null;
- });
-
- it('should call callback right away when there are no tasks to execute', function () {
- spyOn(callbackObj, 'func');
- utils.series(tasks, callbackObj);
- expect(callbackObj.func).toHaveBeenCalled();
- });
-
- it('should invoke the task method before the callback', function () {
- tasks.push(task);
- utils.series(tasks, callbackObj);
- waitsFor(function () {
- return seriesComplete;
- });
-
- expect(callbackInvocations.length).toEqual(2);
- expect(callbackInvocations[0]).toEqual(0);
- expect(callbackInvocations[1]).toEqual('done');
- });
-
- it('should invocation the tasks in order with the callback being the last invocation', function () {
- var i;
-
- tasks.push(task);
- tasks.push(task);
- tasks.push(task);
- tasks.push(task);
-
- utils.series(tasks, callbackObj);
-
- waitsFor(function () {
- return seriesComplete;
- });
-
- expect(callbackInvocations.length).toEqual(5);
-
- for (i = 0; i < 4; i++) {
- expect(callbackInvocations[i]).toEqual(i);
- }
-
- expect(callbackInvocations[4]).toEqual('done');
- });
- });
-
- describe("utils translate path", function () {
- beforeEach(function () {
- GLOBAL.window = {
- qnx: {
- webplatform: {
- getApplication: function () {
- return {
- getEnv: function (path) {
- if (path === "HOME")
- return "/accounts/home";
- }
- };
- }
- }
- }
- };
- });
-
- afterEach(function () {
- delete GLOBAL.window;
- });
-
- it("Expect translate path to be defined", function () {
- expect(utils.translatePath).toBeDefined();
- });
- it("translate path successfully returns the original path when passed non local value", function () {
- var path = "http://google.com";
- path = utils.translatePath(path);
- expect(path).toEqual("http://google.com");
- });
- it("translate path successfully returns the original path when passed a telephone uri", function () {
- var path = "tel://250-654-34243";
- path = utils.translatePath(path);
- expect(path).toEqual("tel://250-654-34243");
- });
- it("translate path successfully retuns an updated string for a local path", function () {
- var path = "local:///this-is-a-local/img/path.jpg";
- path = utils.translatePath(path);
- expect(path).toEqual("file:///accounts/home/../app/native/this-is-a-local/img/path.jpg");
- });
- });
-
- describe("deepclone", function () {
- it("passes through null", function () {
- expect(utils.deepclone(null)).toBe(null);
- });
-
- it("passes through undefined", function () {
- expect(utils.deepclone(undefined)).toBe(undefined);
- });
-
- it("passes through a Number", function () {
- expect(utils.deepclone(1)).toBe(1);
- });
-
- it("passes through a String", function () {
- var str = "hello world";
- expect(utils.deepclone(str)).toBe(str);
- });
-
- it("passes through a Boolean", function () {
- expect(utils.deepclone(true)).toBe(true);
- expect(utils.deepclone(false)).toBe(false);
- });
-
- it("returns a new Date", function () {
- var date = new Date(),
- dateCopy = utils.deepclone(date);
-
- expect(dateCopy instanceof Date).toBe(true, "Not a Date");
- expect(date).not.toBe(dateCopy);
- expect(date.getTime()).toBe(dateCopy.getTime());
- });
-
- it("returns a new RegExp", function () {
- var regex = /a/,
- regexCopy = utils.deepclone(regex);
-
- expect(regexCopy instanceof RegExp).toBe(true, "Not a RegExp");
- expect(regexCopy).not.toBe(regex);
- expect(regexCopy.toString()).toBe(regex.toString());
- });
-
- it("copies nested Object properties", function () {
- var obj = {
- a: "hello world",
- b: "hello again"
- },
- objCopy = utils.deepclone(obj);
-
- expect(obj).not.toBe(objCopy);
- expect(obj).toEqual(objCopy);
- });
- });
-});
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/67fa7ebb/lib/cordova-blackberry/framework/test/unit/lib/webkitHandlers/networkResourceRequested.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/framework/test/unit/lib/webkitHandlers/networkResourceRequested.js b/lib/cordova-blackberry/framework/test/unit/lib/webkitHandlers/networkResourceRequested.js
deleted file mode 100644
index efd4efe..0000000
--- a/lib/cordova-blackberry/framework/test/unit/lib/webkitHandlers/networkResourceRequested.js
+++ /dev/null
@@ -1,167 +0,0 @@
-describe("NetworkResourceRequested event handler", function () {
- var LIB_PATH = "./../../../../lib/",
- networkResourceRequested = require(LIB_PATH + "webkitHandlers/networkResourceRequested"),
- Whitelist = require(LIB_PATH + 'policy/whitelist').Whitelist,
- server = require(LIB_PATH + 'server'),
- utils = require(LIB_PATH + 'utils'),
- mockedWebview;
-
- beforeEach(function () {
- mockedWebview = {
- originalLocation : "http://www.origin.com",
- executeJavaScript : jasmine.createSpy(),
- id: 42,
- uiWebView: {
- childwebviewcontrols: {
- open: jasmine.createSpy()
- }
- }
- };
- });
-
- afterEach(function () {
- mockedWebview = undefined;
- });
-
- it("creates a callback for yous", function () {
- var requestObj = networkResourceRequested.createHandler();
- expect(requestObj.networkResourceRequestedHandler).toBeDefined();
- });
-
-
- it("can access the whitelist", function () {
- spyOn(Whitelist.prototype, "isAccessAllowed").andReturn(true);
- var url = "http://www.google.com",
- requestObj = networkResourceRequested.createHandler(mockedWebview);
- requestObj.networkResourceRequestedHandler(JSON.stringify({url: url}));
- expect(Whitelist.prototype.isAccessAllowed).toHaveBeenCalled();
- });
-
- it("checks whether the request is for an iframe when accessing the whitelist", function () {
- spyOn(Whitelist.prototype, "isAccessAllowed").andReturn(true);
- var url = "http://www.google.com",
- requestObj = networkResourceRequested.createHandler(mockedWebview);
- requestObj.networkResourceRequestedHandler(JSON.stringify({url: url, targetType: "TargetIsXMLHTTPRequest"}));
- expect(Whitelist.prototype.isAccessAllowed).toHaveBeenCalledWith(url, true);
- });
-
- it("can apply whitelist rules and allow valid urls", function () {
- spyOn(Whitelist.prototype, "isAccessAllowed").andReturn(true);
- var url = "http://www.google.com",
- requestObj = networkResourceRequested.createHandler(mockedWebview),
- returnValue = requestObj.networkResourceRequestedHandler(JSON.stringify({url: url}));
- expect(Whitelist.prototype.isAccessAllowed).toHaveBeenCalled();
- expect(JSON.parse(returnValue).setAction).toEqual("ACCEPT");
- });
-
- it("can apply whitelist rules and deny blocked urls", function () {
- spyOn(Whitelist.prototype, "isAccessAllowed").andReturn(false);
- spyOn(utils, "invokeInBrowser");
- spyOn(console, "warn");
-
- var url = "http://www.google.com",
- requestObj = networkResourceRequested.createHandler(mockedWebview),
- returnValue = requestObj.networkResourceRequestedHandler(JSON.stringify({url: url})),
- deniedMsg = "Access to \"" + url + "\" not allowed";
-
- expect(Whitelist.prototype.isAccessAllowed).toHaveBeenCalled();
- expect(JSON.parse(returnValue).setAction).toEqual("DENY");
- expect(utils.invokeInBrowser).not.toHaveBeenCalledWith(url);
- expect(mockedWebview.uiWebView.childwebviewcontrols.open).not.toHaveBeenCalledWith(url);
- expect(mockedWebview.executeJavaScript).toHaveBeenCalledWith("alert('" + deniedMsg + "')");
- expect(console.warn).toHaveBeenCalledWith(deniedMsg);
- });
-
- it("can apply whitelist rules and deny blocked urls and route to a uiWebView when target is main frame", function () {
- spyOn(Whitelist.prototype, "isAccessAllowed").andReturn(false);
- spyOn(utils, "invokeInBrowser");
- spyOn(console, "warn");
-
- var url = "http://www.google.com",
- requestObj = networkResourceRequested.createHandler(mockedWebview),
- returnValue = requestObj.networkResourceRequestedHandler(JSON.stringify({url: url, targetType: "TargetIsMainFrame"})),
- deniedMsg = "Access to \"" + url + "\" not allowed";
-
- expect(Whitelist.prototype.isAccessAllowed).toHaveBeenCalled();
- expect(mockedWebview.uiWebView.childwebviewcontrols.open).toHaveBeenCalledWith(url);
- expect(mockedWebview.executeJavaScript).not.toHaveBeenCalledWith("alert('" + deniedMsg + "')");
- expect(console.warn).toHaveBeenCalledWith(deniedMsg);
- expect(utils.invokeInBrowser).not.toHaveBeenCalledWith(url);
- expect(JSON.parse(returnValue).setAction).toEqual("DENY");
- });
-
- it("can apply whitelist rules and deny blocked urls and route to the browser when target is main frame and childWebView is disabled", function () {
- var url = "http://www.google.com",
- config = require(LIB_PATH + "config"),
- deniedMsg = "Access to \"" + url + "\" not allowed",
- requestObj,
- returnValue;
-
- spyOn(Whitelist.prototype, "isAccessAllowed").andReturn(false);
- spyOn(utils, "invokeInBrowser");
- spyOn(console, "warn");
-
- config.enableChildWebView = false;
-
- this.after(function () {
- delete require.cache[require.resolve(LIB_PATH + "config")];
- });
-
- requestObj = networkResourceRequested.createHandler(mockedWebview);
- returnValue = requestObj.networkResourceRequestedHandler(JSON.stringify({url: url, targetType: "TargetIsMainFrame"}));
-
- expect(Whitelist.prototype.isAccessAllowed).toHaveBeenCalled();
- expect(mockedWebview.uiWebView.childwebviewcontrols.open).not.toHaveBeenCalledWith(url);
- expect(mockedWebview.executeJavaScript).not.toHaveBeenCalledWith("alert('" + deniedMsg + "')");
- expect(console.warn).toHaveBeenCalledWith(deniedMsg);
- expect(utils.invokeInBrowser).toHaveBeenCalledWith(url);
- expect(JSON.parse(returnValue).setAction).toEqual("DENY");
- });
-
- it("can call the server handler when certain urls are detected", function () {
- spyOn(server, "handle");
- var url = "http://localhost:8472/roomService/kungfuAction/customExt/crystalMethod?blargs=yes",
- requestObj = networkResourceRequested.createHandler(mockedWebview),
- returnValue = requestObj.networkResourceRequestedHandler(JSON.stringify({url: url, referrer: "http://www.origin.com"})),
- expectedRequest = {
- params: {
- service: "roomService",
- action: "kungfuAction",
- ext: "customExt",
- method: "crystalMethod",
- args: "blargs=yes"
- },
- body: undefined,
- origin: "http://www.origin.com"
- },
- expectedResponse = {
- send: jasmine.any(Function)
- };
- expect(JSON.parse(returnValue).setAction).toEqual("SUBSTITUTE");
- expect(server.handle).toHaveBeenCalledWith(expectedRequest, expectedResponse, mockedWebview);
- });
-
- it("can call the server handler correctly with a multi-level method", function () {
- spyOn(server, "handle");
- var url = "http://localhost:8472/roomService/kungfuAction/customExt/crystal/Method?blargs=yes",
- requestObj = networkResourceRequested.createHandler(mockedWebview),
- returnValue = requestObj.networkResourceRequestedHandler(JSON.stringify({url: url, referrer: "http://www.origin.com"})),
- expectedRequest = {
- params: {
- service: "roomService",
- action: "kungfuAction",
- ext: "customExt",
- method: "crystal/Method",
- args: "blargs=yes"
- },
- body: undefined,
- origin: "http://www.origin.com"
- },
- expectedResponse = {
- send: jasmine.any(Function)
- };
- expect(JSON.parse(returnValue).setAction).toEqual("SUBSTITUTE");
- expect(server.handle).toHaveBeenCalledWith(expectedRequest, expectedResponse, mockedWebview);
- });
-
-});