Permalink
Browse files

Implementation and unit test for default icon.

Fixes github issue: blackberry/BB10-Webworks-Packager#156
Reviewed By: Rosa Tse <rtse@rim.com>
Tested By: Smita Pillai <spillai@rim.com>
  • Loading branch information...
1 parent 85857c4 commit dd54adf7d3fe7e29f92f637822eaa40b5e3ee7f7 @adrianlee adrianlee committed with Sergey Golod Jul 6, 2012
Showing with 120 additions and 59 deletions.
  1. +3 −1 build/build/pack.js
  2. BIN default-icon.png
  3. +2 −1 lib/conf.js
  4. +15 −3 lib/config-parser.js
  5. +100 −54 test/unit/lib/config-parser.js
View
4 build/build/pack.js
@@ -35,7 +35,8 @@ module.exports = function (src, baton) {
//files
bbwpFile = path.join(_c.ROOT, 'bbwp'),
bbwpBatFile = path.join(_c.ROOT, 'bbwp.bat'),
- licenseFile = path.join(_c.ROOT, 'licenses.txt');
+ licenseFile = path.join(_c.ROOT, 'licenses.txt'),
+ defaultIcon = path.join(_c.ROOT, 'default-icon.png');
//Copy folders to target directory
copyFolder(_c.FRAMEWORK_DEPLOY, frameworkDest);
@@ -46,4 +47,5 @@ module.exports = function (src, baton) {
utils.copyFile(bbwpFile, _c.DEPLOY);
utils.copyFile(bbwpBatFile, _c.DEPLOY);
utils.copyFile(licenseFile, _c.DEPLOY);
+ utils.copyFile(defaultIcon, _c.DEPLOY);
};
View
BIN default-icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
3 lib/conf.js
@@ -28,5 +28,6 @@ module.exports = {
DEPENDENCIES_EMU: path.normalize(__dirname + "/../Framework/dependencies/BBX-Emulator"),
DEPENDENCIES_WWE: path.normalize(__dirname + "/../dependencies/%s-wwe"),
DEPENDENCIES_BAR: path.normalize(__dirname + "/../dependencies/bar-dependencies/%s"),
- DEBUG_TOKEN: path.normalize(__dirname + "/../debugtoken.bar")
+ DEBUG_TOKEN: path.normalize(__dirname + "/../debugtoken.bar"),
+ DEFAULT_ICON: path.normalize(__dirname + "/../default-icon.png")
};
View
18 lib/config-parser.js
@@ -14,9 +14,10 @@
* limitations under the License.
*/
-var fs = require('fs'),
+var fs = require("fsext"),
util = require('util'),
xml2js = require('xml2js'),
+ path = require("path"),
packagerUtils = require('./packager-utils'),
check = require('validator').check,
sanitize = require('validator').sanitize,
@@ -178,7 +179,7 @@ function processSplashScreenData(data, widgetConfig) {
processSplashScreenIconSrc(data, widgetConfig, "rim:splash");
}
-function processIconData(data, widgetConfig) {
+function processIconData(data, widgetConfig, session) {
//
// This takes config.xml markup in the form of:
//
@@ -191,7 +192,18 @@ function processIconData(data, widgetConfig) {
//
// Folder-based localization now done in i18n-manager
//
+ var default_icon_filename = "default-icon.png",
+ default_icon_src = session.conf.DEFAULT_ICON,
+ default_icon_dst = path.join(session.sourceDir, default_icon_filename);
+
processSplashScreenIconSrc(data, widgetConfig, "icon");
+
+ if (!widgetConfig.icon) {
+ fs.copySync(default_icon_src, default_icon_dst);
+
+ widgetConfig["icon"] = [];
+ widgetConfig["icon"].push(default_icon_filename);
+ }
}
function validateSplashScreensIcon(widgetConfig, key) {
@@ -439,7 +451,7 @@ function processResult(data, session) {
var widgetConfig = {};
processWidgetData(data, widgetConfig, session);
- processIconData(data, widgetConfig);
+ processIconData(data, widgetConfig, session);
processAuthorData(data, widgetConfig);
processLicenseData(data, widgetConfig);
processContentData(data, widgetConfig);
View
154 test/unit/lib/config-parser.js
@@ -6,8 +6,10 @@ var testData = require("./test-data"),
xml2js = require('xml2js'),
localize = require(testData.libPath + "/localize"),
path = require("path"),
+ fs = require("fsext"),
session = testData.session,
- configPath = path.resolve("test/config.xml");
+ configPath = path.resolve("test/config.xml"),
+ configBareMinimumPath = path.resolve("test/config-bare-minimum.xml");
function mockParsing(data, error) {
spyOn(xml2js, "Parser").andReturn({
@@ -19,6 +21,10 @@ function mockParsing(data, error) {
}
describe("config parser", function () {
+ beforeEach(function () {
+ spyOn(fs, "copySync");
+ });
+
it("parses standard elements in a config.xml", function () {
configParser.parse(configPath, session, function (configObj) {
expect(configObj.content).toEqual("local:///startPage.html");
@@ -39,7 +45,7 @@ describe("config parser", function () {
expect(configObj.permissions).toContain('use_camera');
});
});
-
+
it("parses Feature elements in a config.xml", function () {
var localAccessList,
accessListFeature;
@@ -50,14 +56,14 @@ describe("config parser", function () {
expect(localAccessList).toBeDefined();
expect(localAccessList.uri).toEqual("WIDGET_LOCAL");
expect(localAccessList.allowSubDomain).toEqual(true);
-
+
//validate WIDGET_LOCAL feature [blackberry.app]
accessListFeature = testUtilities.getFeatureByID(localAccessList.features, "blackberry.app");
expect(accessListFeature).toBeDefined();
expect(accessListFeature.id).toEqual("blackberry.app");
expect(accessListFeature.required).toEqual(true);
expect(accessListFeature.version).toEqual("1.0.0.0");
-
+
//validate WIDGET_LOCAL feature [blackberry.system]
accessListFeature = testUtilities.getFeatureByID(localAccessList.features, "blackberry.system");
expect(accessListFeature).toBeDefined();
@@ -66,7 +72,7 @@ describe("config parser", function () {
expect(accessListFeature.version).toEqual("1.0.0.3");
});
});
-
+
it("parses Access elements a config.xml", function () {
var customAccessList,
accessListFeature;
@@ -77,14 +83,14 @@ describe("config parser", function () {
expect(customAccessList).toBeDefined();
expect(customAccessList.uri).toEqual("http://www.somedomain1.com");
expect(customAccessList.allowSubDomain).toEqual(true);
-
+
//validate http://www.somedomain1.com feature [blackberry.app]
accessListFeature = testUtilities.getFeatureByID(customAccessList.features, "blackberry.app");
expect(accessListFeature).toBeDefined();
expect(accessListFeature.id).toEqual("blackberry.app");
expect(accessListFeature.required).toEqual(true);
expect(accessListFeature.version).toEqual("1.0.0.0");
-
+
//validate http://www.somedomain1.com feature [blackberry.app.event]
accessListFeature = testUtilities.getFeatureByID(customAccessList.features, "blackberry.app.event");
expect(accessListFeature).toBeDefined();
@@ -111,37 +117,37 @@ describe("config parser", function () {
expect(configObj.licenseURL).toEqual("http://www.apache.org/licenses/LICENSE-2.0");
});
});
-
+
it("fails when id is undefined", function () {
var data = testUtilities.cloneObj(testData.xml2jsConfig);
data["@"].id = undefined;
-
+
mockParsing(data);
-
+
//Should throw an EXCEPTION_INVALID_ID error
expect(function () {
configParser.parse(configPath, session, {});
}).toThrow(localize.translate("EXCEPTION_INVALID_ID"));
});
-
+
it("fails when id begins with a number", function () {
var data = testUtilities.cloneObj(testData.xml2jsConfig);
data["@"].id = "1abcdefghijk";
-
+
mockParsing(data);
-
+
//Should throw an EXCEPTION_INVALID_ID error
expect(function () {
configParser.parse(configPath, session, {});
}).toThrow(localize.translate("EXCEPTION_INVALID_ID"));
});
-
+
it("fails when id contains a non [a-zA-Z0-9] character", function () {
var data = testUtilities.cloneObj(testData.xml2jsConfig);
data["@"].id = "abcde#fghijk";
-
+
mockParsing(data);
-
+
//Should throw an EXCEPTION_INVALID_ID error
expect(function () {
configParser.parse(configPath, session, {});
@@ -151,9 +157,9 @@ describe("config parser", function () {
it("fails when id starts with a space", function () {
var data = testUtilities.cloneObj(testData.xml2jsConfig);
data["@"].id = " abcdefghijk";
-
+
mockParsing(data);
-
+
//Should throw an EXCEPTION_INVALID_ID error
expect(function () {
configParser.parse(configPath, session, {});
@@ -163,9 +169,9 @@ describe("config parser", function () {
it("fails when id ends with a space", function () {
var data = testUtilities.cloneObj(testData.xml2jsConfig);
data["@"].id = "abcdefghijk ";
-
+
mockParsing(data);
-
+
//Should throw an EXCEPTION_INVALID_ID error
expect(function () {
configParser.parse(configPath, session, {});
@@ -175,82 +181,83 @@ describe("config parser", function () {
it("Fails when missing content error is not shown", function () {
var data = testUtilities.cloneObj(testData.xml2jsConfig);
data.content = "";
+
mockParsing(data);
expect(function () {
configParser.parse(configPath, session, {});
}).toThrow(localize.translate("EXCEPTION_INVALID_CONTENT"));
});
-
+
it("Fails when missing feature error is not shown", function () {
var data = testUtilities.cloneObj(testData.xml2jsConfig);
- data.feature = {};
+ data.feature = {};
+
mockParsing(data);
expect(function () {
configParser.parse(configPath, session, {});
}).toThrow(localize.translate("EXCEPTION_INVALID_FEATURE_ID"));
});
-
it("adds local:/// protocol to urls", function () {
var data = testUtilities.cloneObj(testData.xml2jsConfig);
data.content["@"].src = "localFile.html";
-
+
mockParsing(data);
-
+
configParser.parse(configPath, session, function (configObj) {
expect(configObj.content).toEqual("local:///localFile.html");
});
});
-
+
it("cleans source folder on error", function () {
mockParsing({}, "ERROR");
spyOn(logger, "error");
spyOn(fileManager, "cleanSource");
configParser.parse(configPath, session, function () {});
-
+
expect(fileManager.cleanSource).toHaveBeenCalled();
});
-
+
it("adds the access_internet permission if unprovided", function () {
var data = testUtilities.cloneObj(testData.xml2jsConfig);
data['rim:permit'] = [];
-
+
mockParsing(data);
-
+
configParser.parse(configPath, session, function (configObj) {
//access_internet permission was set
expect(configObj.permissions).toContain('access_internet');
});
});
-
+
it("does not add unwanted local features to custom access rules", function () {
var customAccessList,
data = testUtilities.cloneObj(testData.xml2jsConfig);
-
+
//Add a local feature element and a custom access list
data['feature'] = {'@': {id: 'blackberry.app', required: 'true', version: '1.0.0.0'}};//local feature
data['access'] = {'@': {uri: 'http://ci0000000094448.rim.net', subdomains: 'true'}};//custom access rule
-
+
mockParsing(data);
configParser.parse(configPath, session, function (configObj) {
customAccessList = testUtilities.getAccessListForUri(configObj.accessList, 'http://ci0000000094448.rim.net');
-
+
//The custom access list features should only contain global features
expect(customAccessList.features).toEqual(configParser.getGlobalFeatures());
});
});
-
+
it("does not throw an exception with empty permit tags", function () {
var data = testUtilities.cloneObj(testData.xml2jsConfig);
data['rim:permit'] = ['read_geolocation', {}, 'access_internet' ];
-
+
mockParsing(data);
-
+
expect(function () {
configParser.parse(configPath, session, function (configObj) {});
}).not.toThrow();
@@ -395,7 +402,7 @@ describe("config parser", function () {
it("does not fail when there is a single feature element in the access list", function () {
var data = testUtilities.cloneObj(testData.xml2jsConfig);
-
+
//Add an access element with one feature
data['access'] = {
'@': {
@@ -406,9 +413,9 @@ describe("config parser", function () {
'@': { id: 'blackberry.system' }
}
};
-
+
mockParsing(data);
-
+
expect(function () {
configParser.parse(configPath, session, function (configObj) {});
}).not.toThrow();
@@ -417,49 +424,49 @@ describe("config parser", function () {
it("supports 4 digit version [build id]", function () {
var data = testUtilities.cloneObj(testData.xml2jsConfig);
data["@"].version = "1.0.0.50";
-
+
mockParsing(data);
-
+
configParser.parse(configPath, session, function (configObj) {
expect(configObj.version).toEqual("1.0.0");
expect(configObj.buildId).toEqual("50");
});
});
-
+
it("uses --buildId when set", function () {
var data = testUtilities.cloneObj(testData.xml2jsConfig);
//--buildId 100
session.buildId = "100";
-
+
mockParsing(data);
-
+
configParser.parse(configPath, session, function (configObj) {
expect(configObj.buildId).toEqual("100");
});
});
-
+
it("overides the build id specified in version with --buildId flag", function () {
var data = testUtilities.cloneObj(testData.xml2jsConfig);
data["@"].version = "1.0.0.50";
-
+
//--buildId 100
session.buildId = "100";
-
+
mockParsing(data);
-
+
configParser.parse(configPath, session, function (configObj) {
expect(configObj.version).toEqual("1.0.0");
expect(configObj.buildId).toEqual("100");
});
});
-
+
it("throws a proper error when author tag is empty", function () {
var data = testUtilities.cloneObj(testData.xml2jsConfig);
data.author = {};
-
+
mockParsing(data);
-
+
//Should throw an EXCEPTION_INVALID_AUTHOR error
expect(function () {
configParser.parse(configPath, session, {});
@@ -501,7 +508,7 @@ describe("config parser", function () {
});
});
});
-
+
it("can parse multiple filters in one element", function () {
var data = testUtilities.cloneObj(testData.xml2jsConfig);
data["rim:invoke-target"] = {
@@ -568,7 +575,7 @@ describe("config parser", function () {
},
type: {}
};
-
+
mockParsing(data);
expect(function () {
@@ -866,5 +873,44 @@ describe("config parser", function () {
configParser.parse(configPath, session, function (configObj) {});
}).toThrow(localize.translate("EXCEPTION_INVALID_ICON_SRC_LOCALES"));
});
+
+ it("should copy the default icon to the src dir when no icon specified", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+
+ mockParsing(data);
+
+ expect(function () {
+ configParser.parse(configPath, session, function (configObj) {});
+ }).not.toThrow();
+
+ expect(fs.copySync).toHaveBeenCalled();
+ });
+
+ it("should use the default icon config when no icon is specified", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+
+ mockParsing(data);
+
+ configParser.parse(configBareMinimumPath, session, function (configObj) {
+ expect(configObj.icon).toEqual(["default-icon.png"]);
+ });
+ });
+
+ it("should not use the default icon config when icon is specified", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data["icon"] = {
+ "@": {
+ "src": "test.png"
+ }
+ };
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.icon).toEqual(["test.png"]);
+ expect(configObj.icon).not.toEqual(["default-icon.png"]);
+ expect(configObj.icon).not.toContain("default-icon.png");
+ });
+ });
});
});

0 comments on commit dd54adf

Please sign in to comment.