You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by lo...@apache.org on 2013/05/07 17:24:21 UTC
[16/51] [partial] [BlackBerry10] Added support for new platform
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/6831bed4/lib/cordova-blackberry/blackberry10/framework/test/unit/lib/overlayWebView.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/blackberry10/framework/test/unit/lib/overlayWebView.js b/lib/cordova-blackberry/blackberry10/framework/test/unit/lib/overlayWebView.js
new file mode 100644
index 0000000..21150a9
--- /dev/null
+++ b/lib/cordova-blackberry/blackberry10/framework/test/unit/lib/overlayWebView.js
@@ -0,0 +1,187 @@
+/*
+ * 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.
+ */
+describe("Overlay Webview", function () {
+ var webview,
+ libPath = "./../../../",
+ mockedController,
+ mockedWebview,
+ mockedApplication;
+
+ beforeEach(function () {
+ webview = require(libPath + "lib/overlayWebView");
+ mockedWebview = {
+ id: 42,
+ enableCrossSiteXHR: undefined,
+ visible: undefined,
+ active: undefined,
+ zOrder: undefined,
+ url: undefined,
+ setGeometry: jasmine.createSpy(),
+ setApplicationOrientation: jasmine.createSpy(),
+ notifyApplicationOrientationDone: jasmine.createSpy(),
+ onContextMenuRequestEvent: undefined,
+ onNetworkResourceRequested: undefined,
+ destroy: jasmine.createSpy(),
+ executeJavaScript: jasmine.createSpy(),
+ windowGroup: undefined,
+ addEventListener: jasmine.createSpy(),
+ enableWebEventRedirect: jasmine.createSpy(),
+ notifyContextMenuCancelled: jasmine.createSpy(),
+ allowQnxObject: undefined,
+ allowRpc: undefined,
+ contextMenu: {
+ subscribeTo: jasmine.createSpy()
+ },
+ invocationlist: {
+ show: jasmine.createSpy()
+ }
+ };
+ mockedController = {
+ dispatchEvent : jasmine.createSpy(),
+ addEventListener : jasmine.createSpy()
+ };
+
+ mockedApplication = {
+ windowVisible: undefined
+ };
+ GLOBAL.qnx = {
+ callExtensionMethod: jasmine.createSpy(),
+ webplatform: {
+ getController: function () {
+ return mockedController;
+ },
+ createUIWebView: function (createFunction) {
+ runs(createFunction);
+ return mockedWebview;
+ },
+ getApplication: function () {
+ return mockedApplication;
+ }
+ }
+ };
+ GLOBAL.window = {
+ qnx: qnx
+ };
+ GLOBAL.screen = {
+ width : 1024,
+ height: 768
+ };
+ });
+
+ describe("create", function () {
+ it("sets up the visible webview", function () {
+ webview.create();
+ waits(1);
+ runs(function () {
+ expect(mockedWebview.visible).toEqual(true);
+ expect(mockedWebview.active).toEqual(true);
+ expect(mockedWebview.zOrder).toEqual(2);
+ expect(mockedWebview.setGeometry).toHaveBeenCalledWith(0, 0, screen.width, screen.height);
+ expect(mockedWebview.backgroundColor).toEqual(0x00FFFFFF);
+ expect(mockedWebview.sensitivity).toEqual("SensitivityTest");
+ expect(mockedWebview.allowQnxObject).toEqual(true);
+ expect(mockedWebview.allowRpc).toEqual(true);
+ expect(mockedController.dispatchEvent).toHaveBeenCalledWith("overlayWebView.initialized", jasmine.any(Array));
+ });
+ });
+
+ it("calls the ready function", function () {
+ var chuck = jasmine.createSpy();
+ webview.create(chuck);
+ waits(1);
+ runs(function () {
+ expect(chuck).toHaveBeenCalled();
+ });
+ });
+
+ });
+
+ describe("methods other than create", function () {
+
+ it("calls the underlying destroy", function () {
+ webview.create(mockedWebview);
+ webview.destroy();
+ expect(mockedWebview.destroy).toHaveBeenCalled();
+ });
+
+ it("sets the url property", function () {
+ var url = "http://AWESOMESAUCE.com";
+ webview.create(mockedWebview);
+ webview.setURL(url);
+ expect(mockedWebview.url).toEqual(url);
+ });
+
+ it("calls the underlying executeJavascript", function () {
+ var js = "var awesome='Jasmine BDD'";
+ webview.create(mockedWebview);
+ webview.executeJavascript(js);
+ expect(mockedWebview.executeJavaScript).toHaveBeenCalledWith(js);
+ });
+ it("calls the underlying windowGroup property", function () {
+ webview.create(mockedWebview);
+ expect(webview.windowGroup()).toEqual(mockedWebview.windowGroup);
+ });
+
+ it("can get the id for the webiew", function () {
+ webview.create();
+ expect(webview.id).toEqual(mockedWebview.id);
+ });
+
+ it("can set geometry", function () {
+ webview.create();
+ webview.setGeometry(0, 0, 100, 200);
+ expect(mockedWebview.setGeometry).toHaveBeenCalledWith(0, 0, 100, 200);
+ });
+
+ it("can set application orientation", function () {
+ webview.create();
+ webview.setApplicationOrientation(90);
+ expect(mockedWebview.setApplicationOrientation).toHaveBeenCalledWith(90);
+ });
+
+ it("can notifyApplicationOrientationDone", function () {
+ webview.create();
+ webview.notifyApplicationOrientationDone();
+ expect(mockedWebview.notifyApplicationOrientationDone).toHaveBeenCalled();
+ });
+
+ it("can notifyContextMenuCancelled", function () {
+ webview.create();
+ webview.notifyContextMenuCancelled();
+ expect(mockedWebview.notifyContextMenuCancelled).toHaveBeenCalled();
+ });
+
+ it("can render the ccm for another webview ", function () {
+ webview.create();
+ webview.renderContextMenuFor(webview);
+ expect(mockedWebview.contextMenu.subscribeTo).toHaveBeenCalledWith(webview);
+ });
+
+ it("It has a zOrder propety ", function () {
+ expect(webview.zOrder).toBeDefined();
+ });
+
+ it('proxies calls to invocationlist.show()', function () {
+ var request = {},
+ title = {},
+ success = function () {},
+ error = function () {};
+ webview.create();
+ webview.showInvocationList(request, title, success, error);
+ expect(mockedWebview.invocationlist.show).toHaveBeenCalledWith(request, title, success, error);
+ });
+ });
+});
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/6831bed4/lib/cordova-blackberry/blackberry10/framework/test/unit/lib/plugins/default.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/blackberry10/framework/test/unit/lib/plugins/default.js b/lib/cordova-blackberry/blackberry10/framework/test/unit/lib/plugins/default.js
new file mode 100644
index 0000000..349bfea
--- /dev/null
+++ b/lib/cordova-blackberry/blackberry10/framework/test/unit/lib/plugins/default.js
@@ -0,0 +1,154 @@
+/*
+ * 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("default plugin", function () {
+
+ var defaultPlugin = require(ROOT + 'lib/plugins/default'),
+ testExtension,
+ utils,
+ mockController,
+ mockApplication;
+
+ describe("when handling requests", function () {
+ var req, res, succ, fail, args;
+
+ beforeEach(function () {
+ req = {
+ origin: "http://www.origin.com",
+ params: {}
+ };
+ res = {
+ send: jasmine.createSpy()
+ };
+ succ = jasmine.createSpy("lib/plugin/default success");
+ fail = jasmine.createSpy("lib/plugin/default fail");
+ args = {};
+
+ GLOBAL.frameworkModules = ["plugin/blackberry.app/index.js"];
+
+ //All of this mocking is required for modules to load, DO NOT REMOVE
+ mockController = {
+ dispatchEvent: jasmine.createSpy()
+ };
+ mockApplication = {
+ };
+ GLOBAL.window = {
+ qnx: {
+ webplatform: {
+ getController: jasmine.createSpy().andReturn(mockController),
+ getApplication: jasmine.createSpy().andReturn(mockApplication)
+ }
+ }
+ };
+
+ testExtension = {
+ getReadOnlyFields: function () {}
+ };
+
+ delete require.cache[require.resolve(ROOT + "lib/utils")];
+ utils = require(ROOT + "lib/utils");
+ spyOn(utils, "loadModule").andCallFake(function (module) {
+ // on device, "plugin/blackberry.app/index.js" would exist since packager would
+ // name the extension folder with feature id in compilation time
+ if (module.indexOf("/plugin") !== -1) {
+ return testExtension;
+ } else {
+ return undefined;
+ }
+ });
+ });
+
+ afterEach(function () {
+ delete GLOBAL.frameworkModules;
+ delete GLOBAL.window;
+ });
+
+ it("returns 404 if the extension is not found", function () {
+ var ext = "NotAnExt",
+ errMsg = "Extension " + ext + " not found";
+
+ req.params.ext = ext;
+ spyOn(console, "warn");
+
+ defaultPlugin.exec(req, succ, fail, args);
+
+ expect(fail).toHaveBeenCalledWith(-1, errMsg, 404);
+ expect(console.warn).toHaveBeenCalledWith(errMsg);
+ });
+
+ it("returns 404 if the method is not found", function () {
+ req.params.ext = "blackberry.app";
+ req.params.method = "NotAMethod";
+ spyOn(console, "warn");
+
+ defaultPlugin.exec(req, succ, fail, args);
+
+ expect(fail).toHaveBeenCalledWith(-1, jasmine.any(String), 404);
+ expect(console.warn).toHaveBeenCalledWith("Method " + req.params.method + " for " + req.params.ext + " not found");
+ });
+
+ it("calls the method of the extension", function () {
+ var env = {"request": req, "response": res};
+
+ spyOn(testExtension, "getReadOnlyFields");
+
+ req.params.ext = "blackberry.app";
+ req.params.method = "getReadOnlyFields";
+
+ defaultPlugin.exec(req, succ, fail, args, env);
+
+ expect(testExtension.getReadOnlyFields).toHaveBeenCalledWith(succ, fail, args, env);
+ });
+
+ it("calls a multi-level method of the extension", function () {
+ var env = {"request": req, "response": res};
+
+ spyOn(testExtension, "getReadOnlyFields");
+ testExtension.getReadOnlyFields.a = {
+ b : {
+ c : jasmine.createSpy()
+ }
+ };
+
+ req.params.ext = "blackberry.app";
+ req.params.method = "getReadOnlyFields/a/b/c";
+
+ defaultPlugin.exec(req, succ, fail, args, env);
+
+ expect(fail).wasNotCalled();
+ expect(testExtension.getReadOnlyFields.a.b.c).toHaveBeenCalledWith(succ, fail, args, env);
+ });
+
+ it("throws a 404 is a multi-level method is not found", function () {
+ var env = {"request": req, "response": res};
+
+ spyOn(console, "warn");
+ spyOn(testExtension, "getReadOnlyFields");
+ testExtension.getReadOnlyFields.a = {
+ };
+
+ req.params.ext = "blackberry.app";
+ req.params.method = "getReadOnlyFields/a/b/c";
+
+ defaultPlugin.exec(req, succ, fail, args, env);
+
+ expect(fail).toHaveBeenCalledWith(-1, jasmine.any(String), 404);
+ expect(console.warn).toHaveBeenCalledWith("Method " + req.params.method + " for " + req.params.ext + " not found");
+ });
+ });
+
+});
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/6831bed4/lib/cordova-blackberry/blackberry10/framework/test/unit/lib/plugins/event.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/blackberry10/framework/test/unit/lib/plugins/event.js b/lib/cordova-blackberry/blackberry10/framework/test/unit/lib/plugins/event.js
new file mode 100644
index 0000000..ea92f1d
--- /dev/null
+++ b/lib/cordova-blackberry/blackberry10/framework/test/unit/lib/plugins/event.js
@@ -0,0 +1,78 @@
+/*
+ * 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/6831bed4/lib/cordova-blackberry/blackberry10/framework/test/unit/lib/policy/webkitOriginAccess.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/blackberry10/framework/test/unit/lib/policy/webkitOriginAccess.js b/lib/cordova-blackberry/blackberry10/framework/test/unit/lib/policy/webkitOriginAccess.js
new file mode 100644
index 0000000..4a5ac8e
--- /dev/null
+++ b/lib/cordova-blackberry/blackberry10/framework/test/unit/lib/policy/webkitOriginAccess.js
@@ -0,0 +1,194 @@
+/*
+ * 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/6831bed4/lib/cordova-blackberry/blackberry10/framework/test/unit/lib/policy/whitelist.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/blackberry10/framework/test/unit/lib/policy/whitelist.js b/lib/cordova-blackberry/blackberry10/framework/test/unit/lib/policy/whitelist.js
new file mode 100644
index 0000000..59f9425
--- /dev/null
+++ b/lib/cordova-blackberry/blackberry10/framework/test/unit/lib/policy/whitelist.js
@@ -0,0 +1,859 @@
+/*
+ * 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/6831bed4/lib/cordova-blackberry/blackberry10/framework/test/unit/lib/server.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/blackberry10/framework/test/unit/lib/server.js b/lib/cordova-blackberry/blackberry10/framework/test/unit/lib/server.js
new file mode 100644
index 0000000..2b89b0a
--- /dev/null
+++ b/lib/cordova-blackberry/blackberry10/framework/test/unit/lib/server.js
@@ -0,0 +1,293 @@
+/*
+ * 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/6831bed4/lib/cordova-blackberry/blackberry10/framework/test/unit/lib/utils.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/blackberry10/framework/test/unit/lib/utils.js b/lib/cordova-blackberry/blackberry10/framework/test/unit/lib/utils.js
new file mode 100644
index 0000000..4b7f5a8
--- /dev/null
+++ b/lib/cordova-blackberry/blackberry10/framework/test/unit/lib/utils.js
@@ -0,0 +1,280 @@
+/*
+ * 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);
+ });
+ });
+});