Updated Branches: refs/heads/master 3a53fb754 -> 19267e2ea
[CB-4076] Added support for the origin attribute in config.xml Reviewed by Jeffrey Heifetz <[email protected]> Tested by Tracy Li <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/commit/19267e2e Tree: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/tree/19267e2e Diff: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/diff/19267e2e Branch: refs/heads/master Commit: 19267e2ea12be1265d2268cc29a6e9e9bc1165f4 Parents: 3a53fb7 Author: Kristoffer Flores <[email protected]> Authored: Thu Jul 11 11:19:48 2013 -0400 Committer: Bryan Higgins <[email protected]> Committed: Tue Aug 6 11:09:35 2013 -0400 ---------------------------------------------------------------------- .../project/cordova/lib/config-parser.js | 36 ++++++++++--- .../templates/project/cordova/lib/localize.js | 5 +- blackberry10/bin/test/cordova/unit/config.xml | 2 +- .../bin/test/cordova/unit/configUri.xml | 53 ++++++++++++++++++ .../bin/test/cordova/unit/configUriOrigin.xml | 57 ++++++++++++++++++++ .../test/cordova/unit/spec/lib/config-parser.js | 45 ++++++++++++---- .../cordova/unit/spec/lib/test-utilities.js | 30 ++++++----- 7 files changed, 195 insertions(+), 33 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/19267e2e/blackberry10/bin/templates/project/cordova/lib/config-parser.js ---------------------------------------------------------------------- diff --git a/blackberry10/bin/templates/project/cordova/lib/config-parser.js b/blackberry10/bin/templates/project/cordova/lib/config-parser.js index 0e3d9e9..0cb06e5 100644 --- a/blackberry10/bin/templates/project/cordova/lib/config-parser.js +++ b/blackberry10/bin/templates/project/cordova/lib/config-parser.js @@ -97,9 +97,9 @@ function processFeatures(featuresArray, widgetConfig, processPredefinedFeatures) return features; } -function createAccessListObj(uri, allowSubDomain) { +function createAccessListObj(uriOrOrigin, allowSubDomain) { return { - uri: uri, + uri: uriOrOrigin, allowSubDomain: allowSubDomain }; } @@ -124,7 +124,11 @@ function processBuildID(widgetConfig, session) { } function processWidgetData(data, widgetConfig, session) { - var attribs, featureArray, header; + var attribs, + featureArray, + uriExist, + originExist, + header; if (data["@"]) { widgetConfig.version = data["@"].version; @@ -169,19 +173,37 @@ function processWidgetData(data, widgetConfig, session) { data.access = [data.access]; } + //check if uri and origin attributes are used + data.access.forEach(function (accessElement, accessIndex) { + attribs = accessElement["@"]; + + if (attribs) { + if (attribs.uri) { + uriExist = true; + } + if (attribs.origin) { + originExist = true; + } + } + }); + if (uriExist === true && originExist === true) { + logger.warn(localize.translate("WARNING_URI_AND_ORIGIN_FOUND_IN_CONFIG")); + } + data.access.forEach(function (accessElement) { attribs = accessElement["@"]; if (attribs) { - if (attribs.uri === "*") { + if (attribs.uri === "*" || attribs.origin === "*") { if (accessElement.feature) { - throw localize.translate("EXCEPTION_FEATURE_DEFINED_WITH_WILDCARD_ACCESS_URI"); + throw localize.translate("EXCEPTION_FEATURE_DEFINED_WITH_WILDCARD_ACCESS_URI_OR_ORIGIN"); } - widgetConfig.hasMultiAccess = true; } else { attribs.subdomains = packagerUtils.toBoolean(attribs.subdomains); - widgetConfig.accessList.push(createAccessListObj(attribs.uri, attribs.subdomains)); + if (attribs.uri || attribs.origin) { + widgetConfig.accessList.push(createAccessListObj(attribs.uri || attribs.origin, attribs.subdomains)); + } } } }); http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/19267e2e/blackberry10/bin/templates/project/cordova/lib/localize.js ---------------------------------------------------------------------- diff --git a/blackberry10/bin/templates/project/cordova/lib/localize.js b/blackberry10/bin/templates/project/cordova/lib/localize.js index 57316c2..d51629a 100755 --- a/blackberry10/bin/templates/project/cordova/lib/localize.js +++ b/blackberry10/bin/templates/project/cordova/lib/localize.js @@ -82,12 +82,15 @@ var Localize = require("localize"), "EXCEPTION_BUFFER_ERROR": { "en": "ERROR in bufferToString(): Buffer length must be even" }, - "EXCEPTION_FEATURE_DEFINED_WITH_WILDCARD_ACCESS_URI": { + "EXCEPTION_FEATURE_DEFINED_WITH_WILDCARD_ACCESS_URI_OR_ORIGIN": { "en": "Invalid config.xml - no <feature> tags are allowed for this <access> element" }, "EXCEPTION_INVALID_ACCESS_URI_NO_PROTOCOL": { "en": "Invalid URI attribute in the access element - protocol required($[1])" }, + "WARNING_URI_AND_ORIGIN_FOUND_IN_CONFIG": { + "en": "Invalid config.xml - <access> tags should have one of 'uri' or 'origin' attributes. 'origin' attribute will be ignored" + }, "EXCEPTION_INVALID_ACCESS_URI_NO_URN": { "en": "Failed to parse the URI attribute in the access element($[1])" }, http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/19267e2e/blackberry10/bin/test/cordova/unit/config.xml ---------------------------------------------------------------------- diff --git a/blackberry10/bin/test/cordova/unit/config.xml b/blackberry10/bin/test/cordova/unit/config.xml index 8650a90..9f42675 100644 --- a/blackberry10/bin/test/cordova/unit/config.xml +++ b/blackberry10/bin/test/cordova/unit/config.xml @@ -28,7 +28,7 @@ <param name="popupBlocker" value="enable" /> </feature> <feature id="blackberry.system" required="true" version="1.0.0.3"/> - <access uri="http://www.somedomain1.com" subdomains="true"> + <access origin="http://www.somedomain1.com" subdomains="true"> <feature id="blackberry.app" required="true" version="1.0.0.0"/> <feature id="blackberry.app.event" required="false" version="2.0.0.0"/> </access> http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/19267e2e/blackberry10/bin/test/cordova/unit/configUri.xml ---------------------------------------------------------------------- diff --git a/blackberry10/bin/test/cordova/unit/configUri.xml b/blackberry10/bin/test/cordova/unit/configUri.xml new file mode 100644 index 0000000..8650a90 --- /dev/null +++ b/blackberry10/bin/test/cordova/unit/configUri.xml @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="utf-8"?> +<widget xmlns=" http://www.w3.org/ns/widgets" + xmlns:rim="http://www.blackberry.com/ns/widgets" + version="1.0.0" + id="My WidgetId" + rim:header="RIM-Widget:rim/widget" + rim:userAgent="A Test-User-Agent/(Blackberry-Agent)"> + <name>Demo</name> + <content src="local:///startPage.html"/> + <author rim:copyright="No Copyright" + href="http://www.rim.com/" + email = "[email protected]">Research In Motion Ltd.</author> + <description>This app does everything.</description> + <license href="http://www.apache.org/licenses/LICENSE-2.0">My License</license> + <icon src="test.png" /> + <rim:permissions> + <rim:permit>access_shared</rim:permit> + <rim:permit>read_geolocation</rim:permit> + <rim:permit>use_camera</rim:permit> + </rim:permissions> + <feature id="blackberry.app.orientation"> + <param name="mode" value="portrait" /> + <param name="other" value="portrait" /> + </feature> + <feature id="blackberry.app" required="true" version="1.0.0.0"> + <param name="childBrowser" value="disable" /> + <param name="websecurity" value="disable" /> + <param name="popupBlocker" value="enable" /> + </feature> + <feature id="blackberry.system" required="true" version="1.0.0.3"/> + <access uri="http://www.somedomain1.com" subdomains="true"> + <feature id="blackberry.app" required="true" version="1.0.0.0"/> + <feature id="blackberry.app.event" required="false" version="2.0.0.0"/> + </access> + <rim:invoke-target id="com.domain.subdomain.appname.app1"> + <type>APPLICATION</type> + <require-source-permissions>invoke_accross_perimeters,access_shared</require-source-permissions> + <filter> + <action>bb.action.OPEN</action> + <action>bb.action.SET</action> + <action>bb.action.VIEW</action> + <mime-type>image/*</mime-type> + <mime-type>text/*</mime-type> + <property var="uris" value="ftp://" /> + <property var="uris" value="http://" /> + <property var="uris" value="https://" /> + <property var="exts" value="jpg" /> + <property var="exts" value="png" /> + <property var="exts" value="txt" /> + <property var="exts" value="doc" /> + </filter> + </rim:invoke-target> +</widget> http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/19267e2e/blackberry10/bin/test/cordova/unit/configUriOrigin.xml ---------------------------------------------------------------------- diff --git a/blackberry10/bin/test/cordova/unit/configUriOrigin.xml b/blackberry10/bin/test/cordova/unit/configUriOrigin.xml new file mode 100644 index 0000000..5267c40 --- /dev/null +++ b/blackberry10/bin/test/cordova/unit/configUriOrigin.xml @@ -0,0 +1,57 @@ +<?xml version="1.0" encoding="utf-8"?> +<widget xmlns=" http://www.w3.org/ns/widgets" + xmlns:rim="http://www.blackberry.com/ns/widgets" + version="1.0.0" + id="My WidgetId" + rim:header="RIM-Widget:rim/widget" + rim:userAgent="A Test-User-Agent/(Blackberry-Agent)"> + <name>Demo</name> + <content src="local:///startPage.html"/> + <author rim:copyright="No Copyright" + href="http://www.rim.com/" + email = "[email protected]">Research In Motion Ltd.</author> + <description>This app does everything.</description> + <license href="http://www.apache.org/licenses/LICENSE-2.0">My License</license> + <icon src="test.png" /> + <rim:permissions> + <rim:permit>access_shared</rim:permit> + <rim:permit>read_geolocation</rim:permit> + <rim:permit>use_camera</rim:permit> + </rim:permissions> + <feature id="blackberry.app.orientation"> + <param name="mode" value="portrait" /> + <param name="other" value="portrait" /> + </feature> + <feature id="blackberry.app" required="true" version="1.0.0.0"> + <param name="childBrowser" value="disable" /> + <param name="websecurity" value="disable" /> + <param name="popupBlocker" value="enable" /> + </feature> + <feature id="blackberry.system" required="true" version="1.0.0.3"/> + <access uri="http://www.somedomain1.com" subdomains="true"> + <feature id="blackberry.app" required="true" version="1.0.0.0"/> + <feature id="blackberry.app.event" required="false" version="2.0.0.0"/> + </access> + <access origin="http://www.somedomain1.com" subdomains="true"> + <feature id="blackberry.app" required="true" version="1.0.0.0"/> + <feature id="blackberry.app.event" required="false" version="2.0.0.0"/> + </access> + <rim:invoke-target id="com.domain.subdomain.appname.app1"> + <type>APPLICATION</type> + <require-source-permissions>invoke_accross_perimeters,access_shared</require-source-permissions> + <filter> + <action>bb.action.OPEN</action> + <action>bb.action.SET</action> + <action>bb.action.VIEW</action> + <mime-type>image/*</mime-type> + <mime-type>text/*</mime-type> + <property var="uris" value="ftp://" /> + <property var="uris" value="http://" /> + <property var="uris" value="https://" /> + <property var="exts" value="jpg" /> + <property var="exts" value="png" /> + <property var="exts" value="txt" /> + <property var="exts" value="doc" /> + </filter> + </rim:invoke-target> +</widget> http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/19267e2e/blackberry10/bin/test/cordova/unit/spec/lib/config-parser.js ---------------------------------------------------------------------- diff --git a/blackberry10/bin/test/cordova/unit/spec/lib/config-parser.js b/blackberry10/bin/test/cordova/unit/spec/lib/config-parser.js index 41775f4..32cacf0 100644 --- a/blackberry10/bin/test/cordova/unit/spec/lib/config-parser.js +++ b/blackberry10/bin/test/cordova/unit/spec/lib/config-parser.js @@ -12,6 +12,8 @@ var testData = require("./test-data"), fs = require("fs"), session = testData.session, configPath = path.resolve("bin/test/cordova/unit/config.xml"), + configPathUri = path.resolve("bin/test/cordova/unit/configUri.xml"), + configPathUriOrigin = path.resolve("bin/test/cordova/unit/configUriOrigin.xml"), configBadPath = path.resolve("test2/config.xml"), configBareMinimumPath = path.resolve("bin/test/cordova/unit/config-bare-minimum.xml"), mockParsing = testUtilities.mockParsing; @@ -56,12 +58,11 @@ describe("config parser", function () { var localAccessList, accessListFeature; - configParser.parse(configPath, session, function (configObj) { + configParser.parse(configPathUri, session, function (configObj) { //validate WIDGET_LOCAL accessList - localAccessList = testUtilities.getAccessListForUri(configObj.accessList, "WIDGET_LOCAL"); + localAccessList = testUtilities.getAccessList(configObj.accessList, "WIDGET_LOCAL"); expect(localAccessList).toBeDefined(); expect(localAccessList.uri).toEqual("WIDGET_LOCAL"); - expect(localAccessList.allowSubDomain).toEqual(true); }); }); @@ -69,9 +70,9 @@ describe("config parser", function () { var customAccessList, accessListFeature; - configParser.parse(configPath, session, function (configObj) { + configParser.parse(configPathUri, session, function (configObj) { //validate http://www.somedomain1.com accessList - customAccessList = testUtilities.getAccessListForUri(configObj.accessList, "http://www.somedomain1.com"); + customAccessList = testUtilities.getAccessList(configObj.accessList, "http://www.somedomain1.com"); expect(customAccessList).toBeDefined(); expect(customAccessList.uri).toEqual("http://www.somedomain1.com"); expect(customAccessList.allowSubDomain).toEqual(true); @@ -101,7 +102,6 @@ describe("config parser", function () { data["@"].id = undefined; mockParsing(data); - //Should throw an EXCEPTION_INVALID_ID error expect(function () { configParser.parse(configPath, session, {}); @@ -134,7 +134,7 @@ describe("config parser", function () { it("Fails when no name was provided - multiple elements", function () { var data = testUtilities.cloneObj(testData.xml2jsConfig); data.name = ["", - { '#': 'API Smoke Test-FR', '@': { 'xml:lang': 'fr' } }, + { '#': 'API Smoke Test-FR', '@': { 'xml:lang': 'fr' } } ]; mockParsing(data); @@ -147,7 +147,7 @@ describe("config parser", function () { it("Fails when localized name was provided but empty", function () { var data = testUtilities.cloneObj(testData.xml2jsConfig); data.name = ["API Smoke Test", - { '#': '', '@': { 'xml:lang': 'fr' } }, + { '#': '', '@': { 'xml:lang': 'fr' } } ]; mockParsing(data); @@ -207,7 +207,7 @@ describe("config parser", function () { it("Fails when localized name was provided but empty", function () { var data = testUtilities.cloneObj(testData.xml2jsConfig); data.name = ['API Smoke Test', - { '#': '', '@': { 'xml:lang': 'fr' } }, + { '#': '', '@': { 'xml:lang': 'fr' } } ]; mockParsing(data); @@ -454,6 +454,11 @@ describe("config parser", function () { }).not.toThrow(); }); + it("throws a warning when both uri and origin attributes exist", function () { + configParser.parse(configPathUriOrigin, session, function (configObj) {}); + expect(logger.warn).toHaveBeenCalled(); + }); + it("multi access should be false if no access", function () { var data = testUtilities.cloneObj(testData.xml2jsConfig); @@ -487,6 +492,24 @@ describe("config parser", function () { }); }); + it("multi access should be false if no origin is equal to *", function () { + var data = testUtilities.cloneObj(testData.xml2jsConfig); + data['access'] = {"@" : {"origin" : "http://www.somedomain1.com"}}; + + mockParsing(data); + + configParser.parse(configPath, session, function (configObj) { + //hasMultiAccess was set to false + expect(configObj.hasMultiAccess).toEqual(false); + expect(configObj.accessList).toEqual([ { + origin : 'WIDGET_LOCAL', + allowSubDomain : true + }, { + "origin" : "http://www.somedomain1.com" + } ]); + }); + }); + it("multi access should be true with the uri being equal to *", function () { var data = testUtilities.cloneObj(testData.xml2jsConfig); data['access'] = {"@" : {"uri" : "*"}}; @@ -529,7 +552,7 @@ describe("config parser", function () { expect(function () { configParser.parse(configPath, session, function (configObj) {}); - }).toThrow(localize.translate("EXCEPTION_FEATURE_DEFINED_WITH_WILDCARD_ACCESS_URI")); + }).toThrow(localize.translate("EXCEPTION_FEATURE_DEFINED_WITH_WILDCARD_ACCESS_URI_OR_ORIGIN")); }); it("should fail when multi features are defined with the uri being equal to *", function () { @@ -540,7 +563,7 @@ describe("config parser", function () { expect(function () { configParser.parse(configPath, session, function (configObj) {}); - }).toThrow(localize.translate("EXCEPTION_FEATURE_DEFINED_WITH_WILDCARD_ACCESS_URI")); + }).toThrow(localize.translate("EXCEPTION_FEATURE_DEFINED_WITH_WILDCARD_ACCESS_URI_OR_ORIGIN")); }); it("should fail when the access uri attribute does not specify a protocol", function () { http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/19267e2e/blackberry10/bin/test/cordova/unit/spec/lib/test-utilities.js ---------------------------------------------------------------------- diff --git a/blackberry10/bin/test/cordova/unit/spec/lib/test-utilities.js b/blackberry10/bin/test/cordova/unit/spec/lib/test-utilities.js index 6f0dbf9..80867a7 100644 --- a/blackberry10/bin/test/cordova/unit/spec/lib/test-utilities.js +++ b/blackberry10/bin/test/cordova/unit/spec/lib/test-utilities.js @@ -9,16 +9,20 @@ function getObjectByProperty(array, propertyName, propertyValue) { } module.exports = { - getAccessListForUri: function (accessListArray, uriValue) { - return getObjectByProperty(accessListArray, "uri", uriValue); + getAccessList: function (accessListArray, value) { + if (accessListArray[0].hasOwnProperty("uri") === true) { + return getObjectByProperty(accessListArray, "uri", value); + } else { + return getObjectByProperty(accessListArray, "origin", value); + } }, - + getFeatureByID: function (featureArray, featureID) { return getObjectByProperty(featureArray, "id", featureID); }, - + mockResolve: function (path) { - //Mock resolve because of a weird issue where resolve would return an + //Mock resolve because of a weird issue where resolve would return an //invalid path on Mac if it cannot find the directory (c:/ doesnt exist on mac) spyOn(path, "resolve").andCallFake(function (to) { if (arguments.length === 2) { @@ -29,20 +33,20 @@ module.exports = { } }); }, - + cloneObj: function (obj) { var newObj = (obj instanceof Array) ? [] : {}, i; - + for (i in obj) { if (i === 'clone') continue; - + if (obj[i] && typeof obj[i] === "object") { newObj[i] = this.cloneObj(obj[i]); } else { newObj[i] = obj[i]; } } - + return newObj; }, @@ -58,12 +62,12 @@ module.exports = { describe("test-utilities", function () { var testUtilities = require("./test-utilities"); - + it("can clone objects using cloneObj", function () { var obj = { A: "A", B: "B", - C: { + C: { CA: "CA", CB: "CB", CC: { @@ -72,10 +76,10 @@ describe("test-utilities", function () { } }, clonedObj = testUtilities.cloneObj(obj); - + //not the same object expect(clonedObj).not.toBe(obj); - + //has the same data expect(clonedObj).toEqual(obj); });
