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:25 UTC
[20/51] [partial] [BlackBerry10] Added support for new platform
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/6831bed4/lib/cordova-blackberry/blackberry10/bin/test/cordova/unit/spec/lib/config-parser.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/blackberry10/bin/test/cordova/unit/spec/lib/config-parser.js b/lib/cordova-blackberry/blackberry10/bin/test/cordova/unit/spec/lib/config-parser.js
new file mode 100644
index 0000000..41775f4
--- /dev/null
+++ b/lib/cordova-blackberry/blackberry10/bin/test/cordova/unit/spec/lib/config-parser.js
@@ -0,0 +1,1411 @@
+/*jshint sub:true*/
+
+var testData = require("./test-data"),
+ configParser = require(testData.libPath + "/config-parser"),
+ packagerUtils = require(testData.libPath + "/packager-utils"),
+ fileManager = require(testData.libPath + "/file-manager"),
+ logger = require(testData.libPath + "./logger"),
+ testUtilities = require("./test-utilities"),
+ xml2js = require('xml2js'),
+ localize = require(testData.libPath + "/localize"),
+ path = require("path"),
+ fs = require("fs"),
+ session = testData.session,
+ configPath = path.resolve("bin/test/cordova/unit/config.xml"),
+ configBadPath = path.resolve("test2/config.xml"),
+ configBareMinimumPath = path.resolve("bin/test/cordova/unit/config-bare-minimum.xml"),
+ mockParsing = testUtilities.mockParsing;
+
+describe("config parser", function () {
+ beforeEach(function () {
+ spyOn(logger, "warn");
+ spyOn(packagerUtils, "copyFile");
+ });
+
+ it("tries to open a config.xml file that doesn't exist", function () {
+ expect(function () {
+ configParser.parse(configBadPath, session, {});
+ }).toThrow(localize.translate("EXCEPTION_CONFIG_NOT_FOUND"));
+ });
+
+ it("parses standard elements in a config.xml", function () {
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.content).toEqual("local:///startPage.html");
+ expect(configObj.id).toEqual("My WidgetId");
+ expect(configObj.customHeaders).toEqual({ 'RIM-Widget' : 'rim/widget'});
+ expect(configObj.version).toEqual("1.0.0");
+ expect(configObj.license).toEqual("My License");
+ expect(configObj.licenseURL).toEqual("http://www.apache.org/licenses/LICENSE-2.0");
+ expect(configObj.icon).toEqual(["test.png"]);
+ expect(configObj.configXML).toEqual("config.xml");
+ expect(configObj.author).toEqual("Research In Motion Ltd.");
+ expect(configObj.authorURL).toEqual("http://www.rim.com/");
+ expect(configObj.copyright).toEqual("No Copyright");
+ expect(configObj.authorEmail).toEqual("author@rim.com");
+ expect(configObj.name).toEqual({ default : 'Demo' });
+ expect(configObj.description).toEqual({ default : 'This app does everything.' });
+ expect(configObj.permissions).toContain('access_shared');
+ expect(configObj.permissions).toContain('read_geolocation');
+ expect(configObj.permissions).toContain('use_camera');
+ expect(configObj.enableChildWebView).toBe(false);
+ expect(configObj.enableChildWebView).toBe(false);
+ });
+ });
+
+ it("parses Feature elements in a config.xml", function () {
+ var localAccessList,
+ accessListFeature;
+
+ configParser.parse(configPath, session, function (configObj) {
+ //validate WIDGET_LOCAL accessList
+ localAccessList = testUtilities.getAccessListForUri(configObj.accessList, "WIDGET_LOCAL");
+ expect(localAccessList).toBeDefined();
+ expect(localAccessList.uri).toEqual("WIDGET_LOCAL");
+ expect(localAccessList.allowSubDomain).toEqual(true);
+ });
+ });
+
+ it("parses Access elements a config.xml", function () {
+ var customAccessList,
+ accessListFeature;
+
+ configParser.parse(configPath, session, function (configObj) {
+ //validate http://www.somedomain1.com accessList
+ customAccessList = testUtilities.getAccessListForUri(configObj.accessList, "http://www.somedomain1.com");
+ expect(customAccessList).toBeDefined();
+ expect(customAccessList.uri).toEqual("http://www.somedomain1.com");
+ expect(customAccessList.allowSubDomain).toEqual(true);
+ });
+ });
+
+ it("parses a bare minimum config.xml without error", function () {
+ var bareMinimumConfigPath = path.resolve("bin/test/cordova/unit/config-bare-minimum.xml");
+
+ configParser.parse(bareMinimumConfigPath, session, function (configObj) {
+ expect(configObj.content).toEqual("local:///startPage.html");
+ expect(configObj.version).toEqual("1.0.0");
+ });
+ });
+
+ it("license url is set even if license body is empty", function () {
+ var licenseConfigPath = path.resolve("bin/test/cordova/unit/config-license.xml");
+
+ configParser.parse(licenseConfigPath, session, function (configObj) {
+ expect(configObj.license).toEqual("");
+ 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 is empty", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data["@"].id = "";
+
+ mockParsing(data);
+
+ //Should throw an EXCEPTION_INVALID_ID error
+ expect(function () {
+ configParser.parse(configPath, session, {});
+ }).toThrow(localize.translate("EXCEPTION_INVALID_ID"));
+ });
+
+ it("Fails when no name was provided - single element", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data.name = "";
+
+ mockParsing(data);
+
+ expect(function () {
+ configParser.parse(configPath, session, {});
+ }).toThrow(localize.translate("EXCEPTION_INVALID_NAME"));
+ });
+
+ 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' } },
+ ];
+
+ mockParsing(data);
+
+ expect(function () {
+ configParser.parse(configPath, session, {});
+ }).toThrow(localize.translate("EXCEPTION_INVALID_NAME"));
+ });
+
+ it("Fails when localized name was provided but empty", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data.name = ["API Smoke Test",
+ { '#': '', '@': { 'xml:lang': 'fr' } },
+ ];
+
+ mockParsing(data);
+
+ expect(function () {
+ configParser.parse(configPath, session, {});
+ }).toThrow(localize.translate("EXCEPTION_INVALID_NAME"));
+ });
+
+ it("Parses a name element - single element", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data.name = "API Smoke Test";
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.name).toEqual({"default": "API Smoke Test"});
+ });
+ });
+
+ it("Parses a name element with xml:lang - single element", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data.name = { '#': 'EN VALUE', '@': { 'xml:lang': 'en' } };
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.name).toEqual({"en": "EN VALUE"});
+ });
+ });
+
+ it("Parses a name element that is not case sensitive", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data.name = { '#': 'EN VALUE', '@': { 'xml:lang': 'eN' } };
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.name).toEqual({"en": "EN VALUE"});
+ });
+ });
+
+ it("Parses a name element with xml:lang - multi element", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data.name = ['API Smoke Test',
+ { '#': 'EN VALUE', '@': { 'xml:lang': 'en' } },
+ { '#': 'FR VALUE', '@': { 'xml:lang': 'fr' } }
+
+ ];
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.name).toEqual({"default": "API Smoke Test", "en": "EN VALUE", "fr": "FR VALUE"});
+ });
+ });
+
+ it("Fails when localized name was provided but empty", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data.name = ['API Smoke Test',
+ { '#': '', '@': { 'xml:lang': 'fr' } },
+ ];
+
+ mockParsing(data);
+
+ expect(function () {
+ configParser.parse(configPath, session, {});
+ }).toThrow(localize.translate("EXCEPTION_INVALID_NAME"));
+ });
+
+ it("Parses a description element - single element", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data.description = "This is my app";
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.description).toEqual({"default": "This is my app"});
+ });
+ });
+
+ it("Parses a description element with xml:lang - single element", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data.description = { '#': 'EN VALUE', '@': { 'xml:lang': 'en' } };
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.description).toEqual({"en": "EN VALUE"});
+ });
+ });
+
+ it("Parses a description element that is not case sensitive", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data.description = { '#': 'EN VALUE', '@': { 'xml:lang': 'eN' } };
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.description).toEqual({"en": "EN VALUE"});
+ });
+ });
+
+ it("Parses a description element with xml:lang - multi element", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data.description = ['This is my app',
+ { '#': 'EN VALUE', '@': { 'xml:lang': 'en' } },
+ { '#': 'FR VALUE', '@': { 'xml:lang': 'fr' } }
+
+ ];
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.description).toEqual({"default": "This is my app", "en": "EN VALUE", "fr": "FR VALUE"});
+ });
+ });
+
+ 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("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("parses a single permission (comes in as string)", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data['rim:permissions'] = {};
+ data['rim:permissions']['rim:permit'] = 'onePermissionNoAttribs';
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.permissions).toContain('onePermissionNoAttribs');
+ });
+ });
+
+ it("parses a single permission with attribs (comes in as object)", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data['rim:permissions'] = {};
+ data['rim:permissions']['rim:permit'] = { '#': 'systemPerm', '@': { system: 'true' } };
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.permissions).toContain({ '#': 'systemPerm', '@': { system: 'true' } });
+ });
+ });
+
+ it("parses multiple permissions with no attribs (comes in as array)", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data['rim:permissions'] = {};
+ data['rim:permissions']['rim:permit'] = [ 'access_shared', 'read_geolocation', 'use_camera' ];
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.permissions).toContain('access_shared');
+ expect(configObj.permissions).toContain('read_geolocation');
+ expect(configObj.permissions).toContain('use_camera');
+ });
+ });
+
+ it("parses multiple permissions with attribs (comes in as array)", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data['rim:permissions'] = {};
+ data['rim:permissions']['rim:permit'] = [
+ { '#': 'systemPerm', '@': { system: 'true' } },
+ { '#': 'nonSystemPerm', '@': { system: 'false' } }
+ ];
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.permissions).toContain({ '#': 'systemPerm', '@': { system: 'true' } });
+ expect(configObj.permissions).toContain({ '#': 'nonSystemPerm', '@': { system: 'false' } });
+ });
+ });
+
+ it("parses a config with no permissions set", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ delete data['rim:permissions']; //No permissions set in config
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.permissions).toEqual([]);
+ });
+ });
+
+ it("enables the enable-flash feature when specified", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+
+ //Add the enable-flash feature element
+ data['feature'] = {'@': {id: 'enable-flash'}};
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.enableFlash).toEqual(true);
+ });
+ });
+
+ it("does not enable the enable-flash feature when specified in an access element", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+
+ //Add the enable-flash to an access element
+ data['access'] = {"@" : {"uri" : "http://somewebsite.com"}, "feature" : {"@": {id: 'enable-flash'}}};
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.enableFlash).toEqual(false);
+ });
+ });
+
+ it("disables the enable-flash feature by default", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data['feature'] = undefined;//no features
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.enableFlash).toEqual(false);
+ });
+ });
+
+ it("sets autoDeferNetworkingAndJavaScript to false when the blackberry.push feature is specified", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+
+ //Add the blackberry.push feature element
+ data["rim:permissions"] = {}; // ensure no run_when_backgrounded permission exists
+ data['feature'] = {'@': {id: 'blackberry.push'}};
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.autoDeferNetworkingAndJavaScript).toEqual(false);
+ });
+ });
+
+ it("sets autoDeferNetworkingAndJavaScript to false when the run_when_backgrounded permission is specified", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+
+ //Add the run_when_backgrounded permission
+ data['feature'] = undefined; // no features
+ data["rim:permissions"] = {
+ "rim:permit" : [ 'read_geolocation', 'run_when_backgrounded', 'access_internet' ]
+ };
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.permissions).toContain('run_when_backgrounded');
+ expect(configObj.autoDeferNetworkingAndJavaScript).toEqual(false);
+ });
+ });
+
+ it("sets autoDeferNetworkingAndJavaScript to true by default", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+
+ data['feature'] = undefined; // no features
+ data["rim:permissions"] = {}; // ensure no run_when_backgrounded permission exists
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.autoDeferNetworkingAndJavaScript).toEqual(true);
+ });
+ });
+
+ 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();
+ });
+
+ it("multi access should be false if no access", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ //hasMultiAccess was set to false
+ expect(configObj.hasMultiAccess).toEqual(false);
+ expect(configObj.accessList).toEqual([ {
+ uri : 'WIDGET_LOCAL',
+ allowSubDomain : true
+ } ]);
+ });
+ });
+
+ it("multi access should be false if no uri is equal to *", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data['access'] = {"@" : {"uri" : "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([ {
+ uri : 'WIDGET_LOCAL',
+ allowSubDomain : true
+ }, {
+ "uri" : "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" : "*"}};
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ //hasMultiAccess was set to true
+ expect(configObj.hasMultiAccess).toEqual(true);
+ expect(configObj.accessList).toEqual([ {
+ uri : 'WIDGET_LOCAL',
+ allowSubDomain : true
+ } ]);
+ });
+ });
+
+ it("multi access should be true with one uri being equal to *", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data['access'] = [{"@" : {"uri" : "*"}}, {"@" : {"uri" : "http://www.somedomain1.com"}}];
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ //hasMultiAccess was set to true
+ expect(configObj.hasMultiAccess).toEqual(true);
+ expect(configObj.accessList).toEqual([ {
+ uri : 'WIDGET_LOCAL',
+ allowSubDomain : true
+ }, {
+ "uri" : "http://www.somedomain1.com"
+ } ]);
+ });
+ });
+
+ it("should fail when feature is defined with the uri being equal to *", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data['access'] = {"@" : {"uri" : "*"}, "feature" : {"@": {"id": "blackberry.app"}}};
+
+ mockParsing(data);
+
+ expect(function () {
+ configParser.parse(configPath, session, function (configObj) {});
+ }).toThrow(localize.translate("EXCEPTION_FEATURE_DEFINED_WITH_WILDCARD_ACCESS_URI"));
+ });
+
+ it("should fail when multi features are defined with the uri being equal to *", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data['access'] = {"@" : {"uri" : "*"}, "feature" : [{"@": {"id": "blackberry.app"}}, {"@": {"id": "blackberry.system"}}, {"@": {"id": "blackberry.invoke"}}]};
+
+ mockParsing(data);
+
+ expect(function () {
+ configParser.parse(configPath, session, function (configObj) {});
+ }).toThrow(localize.translate("EXCEPTION_FEATURE_DEFINED_WITH_WILDCARD_ACCESS_URI"));
+ });
+
+ it("should fail when the access uri attribute does not specify a protocol", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+
+ //Add an access element with one feature
+ data['access'] = {
+ '@': {
+ uri: 'rim.net',
+ subdomains: 'true'
+ },
+ feature: {
+ '@': { id: 'blackberry.system' }
+ }
+ };
+
+ mockParsing(data);
+
+ expect(function () {
+ configParser.parse(configPath, session, function (configObj) {});
+ }).toThrow(localize.translate("EXCEPTION_INVALID_ACCESS_URI_NO_PROTOCOL", data['access']['@'].uri));
+ });
+
+ it("should fail when the access uri attribute does not specify a URN", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+
+ //Add an access element with one feature
+ data['access'] = {
+ '@': {
+ uri: 'http://',
+ subdomains: 'true'
+ },
+ feature: {
+ '@': { id: 'blackberry.system' }
+ }
+ };
+
+ mockParsing(data);
+
+ expect(function () {
+ configParser.parse(configPath, session, function (configObj) {});
+ }).toThrow(localize.translate("EXCEPTION_INVALID_ACCESS_URI_NO_URN", data['access']['@'].uri));
+ });
+
+ 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'] = {
+ '@': {
+ uri: 'http://rim.net',
+ subdomains: 'true'
+ },
+ feature: {
+ '@': { id: 'blackberry.system' }
+ }
+ };
+
+ mockParsing(data);
+
+ expect(function () {
+ configParser.parse(configPath, session, function (configObj) {});
+ }).not.toThrow();
+ });
+
+ 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, {});
+ }).toThrow(localize.translate("EXCEPTION_INVALID_AUTHOR"));
+ });
+
+ it("can parse a standard rim:invoke-target element", function () {
+
+ configParser.parse(configPath, session, function (configObj) {
+ var invokeTarget = configObj["invoke-target"][0];
+
+ expect(invokeTarget).toBeDefined();
+ expect(invokeTarget["@"]).toBeDefined();
+ expect(invokeTarget["@"]["id"]).toBeDefined();
+ expect(invokeTarget["@"]["id"]).toEqual("com.domain.subdomain.appname.app1");
+ expect(invokeTarget.type).toBeDefined();
+ expect(invokeTarget.type).toEqual("APPLICATION");
+ expect(invokeTarget["require-source-permissions"]).toBeDefined();
+ expect(invokeTarget["require-source-permissions"]).toEqual("invoke_accross_perimeters,access_shared");
+ expect(invokeTarget.filter).toBeDefined();
+ expect(invokeTarget.filter[0].action).toBeDefined();
+ expect(invokeTarget.filter[0].action).toContain("bb.action.VIEW");
+ expect(invokeTarget.filter[0].action).toContain("bb.action.SET");
+ expect(invokeTarget.filter[0].action).toContain("bb.action.OPEN");
+ expect(invokeTarget.filter[0]["mime-type"]).toBeDefined();
+ expect(invokeTarget.filter[0]["mime-type"]).toContain("image/*");
+ expect(invokeTarget.filter[0]["mime-type"]).toContain("text/*");
+ expect(invokeTarget.filter[0].property).toBeDefined();
+
+ invokeTarget.filter[0].property.forEach(function (property) {
+ expect(property["@"]).toBeDefined();
+ expect(property["@"]["var"]).toBeDefined();
+ expect(property["@"]["var"]).toMatch("^(exts|uris)$");
+ if (property["@"]["var"] === "uris") {
+ expect(property["@"]["value"]).toMatch("^(ftp|http|https):\/\/$");
+ } else if (property["@"]["var"] === "exts") {
+ expect(property["@"]["value"]).toMatch("^(jpg|png|txt|doc)$");
+ }
+ });
+ });
+ });
+
+ it("can parse multiple filters in one element", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data["rim:invoke-target"] = {
+ "@": {
+ "id": "com.domain.subdomain.appName.app"
+ },
+ "type": "application",
+ "filter": [{
+ "action": "bb.action.OPEN",
+ "mime-type": ["text/*", "image/*"]
+ }, {
+ "action": "bb.action.SET",
+ "mime-type": "image/*"
+ }]
+ };
+
+ mockParsing(data);
+
+ expect(function () {
+ configParser.parse(configPath, session, function (configObj) {});
+ }).not.toThrow();
+ });
+
+ it("can parse multiple invoke targets", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data["rim:invoke-target"] = [{
+ "@": {
+ "id": "com.domain.subdomain.appName.app"
+ },
+ "type": "application"
+ }, {
+ "@": {
+ "id": "com.domain.subdomain.appName.viewer"
+ },
+ "type": "viewer"
+ }];
+
+ mockParsing(data);
+
+ expect(function () {
+ configParser.parse(configPath, session, function (configObj) {});
+ }).not.toThrow();
+
+ });
+
+ it("throws an error when an invoke target doesn't specify an invocation id", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data["rim:invoke-target"] = {
+ type: "APPLICATION"
+ };
+
+ mockParsing(data);
+
+ expect(function () {
+ configParser.parse(configPath, session, function (configObj) {});
+ }).toThrow(localize.translate("EXCEPTION_INVOKE_TARGET_INVALID_ID"));
+ });
+
+ it("throws and error when an invoke target xml doesn't specify an invocation type", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data["rim:invoke-target"] = {
+ "@": {
+ "id": "com.domain.subdomain.appName.app"
+ },
+ type: {}
+ };
+
+ mockParsing(data);
+
+ expect(function () {
+ configParser.parse(configPath, session, function (configObj) {});
+ }).toThrow(localize.translate("EXCEPTION_INVOKE_TARGET_INVALID_TYPE"));
+ });
+
+ it("throws an error when an invoke target doesn't specify an invocation type", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data["rim:invoke-target"] = {
+ "@": {
+ "id": "com.domain.subdomain.appName.app"
+ }
+ };
+
+ mockParsing(data);
+
+ expect(function () {
+ configParser.parse(configPath, session, function (configObj) {});
+ }).toThrow(localize.translate("EXCEPTION_INVOKE_TARGET_INVALID_TYPE"));
+ });
+
+ it("throws an error when an invoke target filter doesn't contain an action", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data["rim:invoke-target"] = {
+ "@": {
+ "id": "com.domain.subdomain.appName.app"
+ },
+ "type": "APPLICATION",
+ "filter": {
+ "mime-type": "text/*",
+ "property": [{
+ "@": {
+ "var": "uris",
+ "value": "https://"
+ }
+ }, {
+ "@": {
+ "var": "exts",
+ "value": "html"
+ }
+ }, {
+ "@": {
+ "var": "exts",
+ "value": "htm"
+ }
+ }]
+ }
+ };
+
+ mockParsing(data);
+
+ expect(function () {
+ configParser.parse(configPath, session, function (configObj) {});
+ }).toThrow(localize.translate("EXCEPTION_INVOKE_TARGET_ACTION_INVALID"));
+ });
+
+ it("throws an error when a filter doesn't contain a mime-type", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data["rim:invoke-target"] = {
+ "@": {
+ "id": "com.domain.subdomain.appName.app"
+ },
+ "type": "application",
+ "filter": {
+ "action": "bb.action.OPEN",
+ "property": [{
+ "@": {
+ "var": "uris",
+ "value": "https://"
+ }
+ }, {
+ "@": {
+ "var": "exts",
+ "value": "html"
+ }
+ }]
+ }
+ };
+
+ mockParsing(data);
+
+ expect(function () {
+ configParser.parse(configPath, session, function (configObj) {});
+ }).toThrow(localize.translate("EXCEPTION_INVOKE_TARGET_MIME_TYPE_INVALID"));
+ });
+
+ describe("splash screen", function () {
+ it("throws error when rim:splash element does not contain src attribute", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data["rim:splash"] = {};
+
+ mockParsing(data);
+
+ expect(function () {
+ configParser.parse(configPath, session, function (configObj) {});
+ }).toThrow(localize.translate("EXCEPTION_INVALID_SPLASH_SRC"));
+ });
+
+ it("throws error when rim:splash element contains empty src attribute", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data["rim:splash"] = {
+ "@": {
+ "src": ""
+ }
+ };
+
+ mockParsing(data);
+
+ expect(function () {
+ configParser.parse(configPath, session, function (configObj) {});
+ }).toThrow(localize.translate("EXCEPTION_INVALID_SPLASH_SRC"));
+ });
+
+ it("throws error when one of many rim:splash elements does not contain attribute", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data["rim:splash"] = [{
+ "@": {
+ "src": "a.jpg"
+ }
+ }, {
+ "#": "blah"
+ }];
+
+ mockParsing(data);
+
+ expect(function () {
+ configParser.parse(configPath, session, function (configObj) {});
+ }).toThrow(localize.translate("EXCEPTION_INVALID_SPLASH_SRC"));
+ });
+
+ it("allow one rim:splash element that contains non-empty src attribute", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data["rim:splash"] = {
+ "@": {
+ "src": "a.jpg"
+ }
+ };
+
+ mockParsing(data);
+
+ expect(function () {
+ configParser.parse(configPath, session, function (configObj) {});
+ }).not.toThrow();
+ });
+
+ it("allow multiple rim:splash elements that contain non-empty src attribute", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data["rim:splash"] = [{
+ "@": {
+ "src": "a.jpg"
+ }
+ }, {
+ "@": {
+ "src": "b.jpg"
+ }
+ }];
+
+ mockParsing(data);
+
+ expect(function () {
+ configParser.parse(configPath, session, function (configObj) {});
+ }).not.toThrow();
+ });
+
+ it("throws error when rim:splash src starts with 'locales' subfolder", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data["rim:splash"] = [{
+ "@": {
+ "src": "a.jpg"
+ }
+ }, {
+ "@": {
+ "src": "locales/en/b.jpg"
+ }
+ }];
+
+ mockParsing(data);
+
+ expect(function () {
+ configParser.parse(configPath, session, function (configObj) {});
+ }).toThrow(localize.translate("EXCEPTION_INVALID_SPLASH_SRC_LOCALES"));
+ });
+ });
+
+ describe("icon", function () {
+ it("throws error when icon element does not contain src attribute", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data["icon"] = {};
+
+ mockParsing(data);
+
+ expect(function () {
+ configParser.parse(configPath, session, function (configObj) {});
+ }).toThrow(localize.translate("EXCEPTION_INVALID_ICON_SRC"));
+ });
+
+ it("throws error when icon element contains empty src attribute", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data["icon"] = {
+ "@": {
+ "src": ""
+ }
+ };
+
+ mockParsing(data);
+
+ expect(function () {
+ configParser.parse(configPath, session, function (configObj) {});
+ }).toThrow(localize.translate("EXCEPTION_INVALID_ICON_SRC"));
+ });
+
+ it("throws error when one of many icon elements does not contain attribute", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data["icon"] = [{
+ "@": {
+ "src": "a.jpg"
+ }
+ }, {
+ "#": "blah"
+ }];
+
+ mockParsing(data);
+
+ expect(function () {
+ configParser.parse(configPath, session, function (configObj) {});
+ }).toThrow(localize.translate("EXCEPTION_INVALID_ICON_SRC"));
+ });
+
+ it("allow one icon element that contains non-empty src attribute", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data["icon"] = {
+ "@": {
+ "src": "a.jpg"
+ }
+ };
+
+ mockParsing(data);
+
+ expect(function () {
+ configParser.parse(configPath, session, function (configObj) {});
+ }).not.toThrow();
+ });
+
+ it("allow multiple icon elements that contain non-empty src attribute", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data["icon"] = [{
+ "@": {
+ "src": "a.jpg"
+ }
+ }, {
+ "@": {
+ "src": "b.jpg"
+ }
+ }];
+
+ mockParsing(data);
+
+ expect(function () {
+ configParser.parse(configPath, session, function (configObj) {});
+ }).not.toThrow();
+ });
+
+ it("throws error when icon src starts with 'locales' subfolder", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data["icon"] = [{
+ "@": {
+ "src": "a.jpg"
+ }
+ }, {
+ "@": {
+ "src": "locales/en/b.jpg"
+ }
+ }];
+
+ mockParsing(data);
+
+ expect(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(packagerUtils.copyFile).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");
+ });
+ });
+
+ it("sets orientation to landscape when specified", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data['feature'] = { '@': { id: 'blackberry.app', required: true },
+ param: { '@': { name: 'orientation', value: 'landscape' } } };
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.orientation).toEqual("landscape");
+ expect(configObj.autoOrientation).toEqual(false);
+ });
+ });
+
+ it("sets orientation to portrait when specified", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data['feature'] = { '@': { id: 'blackberry.app', required: true },
+ param: { '@': { name: 'orientation', value: 'portrait' } } };
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.orientation).toEqual("portrait");
+ expect(configObj.autoOrientation).toEqual(false);
+ });
+ });
+
+ it("sets auto orientation to true by default", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ delete data["feature"];//Remove any orientation data
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.autoOrientation).toEqual(true);
+ });
+ });
+
+ it("throws a warning when blackberry.app.orientation exists", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data['feature'] = { '@': { id: 'blackberry.app.orientation', required: true },
+ param: { '@': { name: 'mode', value: 'portrait' } } };
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {});
+ expect(logger.warn).toHaveBeenCalled();
+ });
+
+ it("throws an error when blackberry.app orientation exists with an invalid mode param", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data['feature'] = { '@': { id: 'blackberry.app', required: true },
+ param: { '@': { name: 'orientation', value: 'notAValidMode' } } };
+
+ mockParsing(data);
+
+ //Should throw an EXCEPTION_INVALID_ORIENTATION_MODE error
+ expect(function () {
+ configParser.parse(configPath, session, function (configObj) {});
+ }).toThrow(localize.translate("EXCEPTION_INVALID_ORIENTATION_MODE", "notAValidMode"));
+ });
+
+ it("sets backgroundColor when specified via blackberry.app namespace", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data['feature'] = { '@': { id: 'blackberry.app', required: true },
+ param: { '@': { name: 'backgroundColor', value: '0xffffff' } } };
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.backgroundColor).toEqual(16777215);//Decimal value of 0xffffff
+ });
+ });
+
+ it("throws an error when blackberry.app backgroundColor param is not a number", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data['feature'] = { '@': { id: 'blackberry.app', required: true },
+ param: { '@': { name: 'backgroundColor', value: '$UI*@@$' } } };
+
+ mockParsing(data);
+
+ //Should throw an EXCEPTION_BGCOLOR_INVALID error
+ expect(function () {
+ configParser.parse(configPath, session, {});
+ }).toThrow(localize.translate("EXCEPTION_BGCOLOR_INVALID", "$UI*@@$"));
+ });
+
+ it("can properly parse the custom RIM-Wiget:rim/wiget element", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.customHeaders).toEqual({ 'RIM-Widget' : 'rim/widget'});
+ });
+ });
+
+ it("can properly parse the custom attributes but ignores improper headers", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data["@"] = {
+ "xmlns": " http://www.w3.org/ns/widgets",
+ "xmlns:rim": "http://www.blackberry.com/ns/widgets",
+ "version": "1.0.0",
+ "id": "myID"
+ };
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.id).toEqual("myID");
+ expect(configObj.customHeaders).toEqual(undefined);
+ });
+ });
+
+ it("can properly parse the custom attributes but ignores improper headers", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data["@"] = {
+ "xmlns": " http://www.w3.org/ns/widgets",
+ "xmlns:rim": "http://www.blackberry.com/ns/widgets",
+ "version": "1.0.0",
+ "id": "myID",
+ "rim:userAgent" : "A Test-User-Agent/(Blackberry-Agent)"
+ };
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.id).toEqual("myID");
+ expect(configObj.userAgent).toEqual("A Test-User-Agent/(Blackberry-Agent)");
+ });
+ });
+
+ describe('disabling childBrowser (childWebView)', function () {
+
+ // { '@': { id: 'blackberry.app', required: true, version: '1.0.0.0' },
+ // param: { '@': { name: 'childBrowser', value: 'disable' } } }
+
+
+ it("sets enableChildWebView to true when childBrowser value is enable", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data['feature'] = { '@': { id: 'blackberry.app' },
+ param: { '@': { name: 'childBrowser', value: 'enable' } } };
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.enableChildWebView).toBe(true);
+ });
+ });
+
+ it("sets enableChildWebView to false when value is disable", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data['feature'] = { '@': { id: 'blackberry.app' },
+ param: { '@': { name: 'childBrowser', value: 'disable' } } };
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.enableChildWebView).toBe(false);
+ });
+ });
+ });
+
+ describe('disabling formcontrol', function () {
+
+ it("sets enableFormControl to true when formControl value is enable", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data['feature'] = { '@': { id: 'blackberry.app' },
+ param: { '@': { name: 'formControl', value: 'enable' } } };
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.enableFormControl).toBe(true);
+ });
+ });
+
+ it("sets enableFormControl to false when value is disable", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data['feature'] = { '@': { id: 'blackberry.app' },
+ param: { '@': { name: 'formControl', value: 'disable' } } };
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.enableFormControl).toBe(false);
+ });
+ });
+ });
+
+ describe('setting theme for some core ui elements', function () {
+ function testTheme(themeInConfig, themeParsed) {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+
+ if (themeInConfig) {
+ data['feature'] = { '@': { id: 'blackberry.app' },
+ param: { '@': { name: 'theme', value: themeInConfig } } };
+
+ mockParsing(data);
+ }
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.theme).toBe(themeParsed);
+ });
+ }
+
+ it("sets theme to dark when config has theme with dark", function () {
+ testTheme("dark", "dark");
+ });
+
+ it("sets theme to bright when config has theme with bright", function () {
+ testTheme("bright", "bright");
+ });
+
+ it("sets theme to inherit when config has theme with inherit", function () {
+ testTheme("inherit", "inherit");
+ });
+
+ it("sets theme to default when config has theme with default", function () {
+ testTheme("default", "default");
+ });
+
+ it("sets theme to default when config has unsupported theme", function () {
+ testTheme("unsupportedthemename", "default");
+ });
+
+ it("sets theme to default when config has no theme provided", function () {
+ testTheme(undefined, "default");
+ });
+
+ it("sets theme to dark when config has theme with case insensitive dark", function () {
+ testTheme("dArK", "dark");
+ });
+
+ it("sets theme to bright when config has theme with case insensitive bright", function () {
+ testTheme("BriGht", "bright");
+ });
+
+ it("sets theme to inherit when config has theme with case insensitive inherit", function () {
+ testTheme("inHerIt", "inherit");
+ });
+
+ it("sets theme to inherit when config has theme with case insensitive inherit", function () {
+ testTheme("DefAulT", "default");
+ });
+
+ it("sets theme to default when config has NO theme tag provided", function () {
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.theme).toBe("default");
+ });
+ });
+ });
+
+ describe('disabling WebSecurity', function () {
+
+ // { '@': { id: 'blackberry.app', required: true, version: '1.0.0.0' },
+ // param: { '@': { name: 'childBrowser', value: 'disable' } } }
+
+
+ it("doesn't set enableWebSecurity to anything when param value is anything but disable", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data.feature = { '@': { id: 'blackberry.app' },
+ param: { '@': { name: 'websecurity', value: (new Date()).toString() } } };
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.enableWebSecurity).toBe(undefined);
+ expect(logger.warn).not.toHaveBeenCalledWith(localize.translate("WARNING_WEBSECURITY_DISABLED"));
+ });
+ });
+
+ it("sets enableWebSecurity to false when value is disable", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data.feature = { '@': { id: 'blackberry.app' },
+ param: { '@': { name: 'websecurity', value: 'disable' } } };
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.enableWebSecurity).toBe(false);
+ expect(logger.warn).toHaveBeenCalledWith(localize.translate("WARNING_WEBSECURITY_DISABLED"));
+ });
+ });
+
+ it("sets enableWebSecurity to false when value is disable case insensitive", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data.feature = { '@': { id: 'blackberry.app' },
+ param: { '@': { name: 'websecurity', value: 'DisAble' } } };
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.enableWebSecurity).toBe(false);
+ expect(logger.warn).toHaveBeenCalledWith(localize.translate("WARNING_WEBSECURITY_DISABLED"));
+ });
+ });
+ });
+
+ describe('enabling popupBlocker', function () {
+
+ // { '@': { id: 'blackberry.app', required: true, version: '1.0.0.0' },
+ // param: { '@': { name: 'childBrowser', value: 'disable' } } }
+
+ it("sets enableWebSecurity to false when value is disable", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data.feature = { '@': { id: 'blackberry.app' },
+ param: { '@': { name: 'popupBlocker', value: 'enable' } } };
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.enablePopupBlocker).toBe(true);
+ });
+ });
+
+ it("sets enableWebSecurity to false when value is disable case insensitive", function () {
+ var data = testUtilities.cloneObj(testData.xml2jsConfig);
+ data.feature = { '@': { id: 'blackberry.app' },
+ param: { '@': { name: 'popupBlocker', value: 'EnAbLe' } } };
+
+ mockParsing(data);
+
+ configParser.parse(configPath, session, function (configObj) {
+ expect(configObj.enablePopupBlocker).toBe(true);
+ });
+ });
+ });
+ });
+});
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/6831bed4/lib/cordova-blackberry/blackberry10/bin/test/cordova/unit/spec/lib/file-manager.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/blackberry10/bin/test/cordova/unit/spec/lib/file-manager.js b/lib/cordova-blackberry/blackberry10/bin/test/cordova/unit/spec/lib/file-manager.js
new file mode 100644
index 0000000..363d625
--- /dev/null
+++ b/lib/cordova-blackberry/blackberry10/bin/test/cordova/unit/spec/lib/file-manager.js
@@ -0,0 +1,178 @@
+var srcPath = __dirname + "/../../../../../templates/project/cordova/lib/",
+ barconf = require(srcPath + "bar-conf.js"),
+ fs = require("fs"),
+ path = require("path"),
+ util = require("util"),
+ packager_utils = require(srcPath + "packager-utils"),
+ localize = require(srcPath + "localize"),
+ wrench = require("wrench"),
+ logger = require(srcPath + "logger"),
+ conf = require(srcPath + "conf"),
+ fileMgr = require(srcPath + "file-manager"),
+ testData = require("./test-data"),
+ testUtilities = require("./test-utilities"),
+ session = testData.session,
+ extManager = {
+ getAllExtensionsToCopy: function (accessList) {
+ return ["app"];
+ },
+ getFeatureIdByExtensionBasename: function (extBasename) {
+ return "blackberry." + extBasename;
+ }
+ };
+
+describe("File manager", function () {
+
+ afterEach(function () {
+ //cleanup packager-tests temp folder
+ wrench.rmdirSyncRecursive(testData.session.outputDir);
+ });
+
+ it("prepareOutputFiles() should copy files and unzip archive", function () {
+ spyOn(wrench, "copyDirSyncRecursive");
+ fileMgr.prepareOutputFiles(session);
+
+ expect(fs.existsSync(session.sourcePaths.CHROME)).toBeTruthy();
+ expect(wrench.copyDirSyncRecursive).toHaveBeenCalledWith(session.conf.DEPENDENCIES_BOOTSTRAP, session.sourcePaths.CHROME);
+ expect(fs.existsSync(session.sourcePaths.LIB)).toBeTruthy();
+ });
+
+
+ it("copyWWE() should copy wwe of the specified target", function () {
+ //Create packager-tests source folder
+ wrench.mkdirSyncRecursive(session.sourceDir);
+
+ spyOn(packager_utils, "copyFile");
+ fileMgr.copyWWE(session, "simulator");
+
+ expect(packager_utils.copyFile).toHaveBeenCalledWith(path.normalize(session.conf.DEPENDENCIES_BOOTSTRAP + "/wwe"), path.normalize(session.sourceDir));
+ });
+
+ it("copyExtensions() should copy all .js files required by features listed in config.xml", function () {
+ var session = testData.session,
+ featureId = "Device",
+ toDir = path.join(session.sourcePaths.EXT, featureId),
+ apiDir = path.resolve(session.conf.EXT, featureId),
+
+ //extension javascript files
+ indexJS = path.join(apiDir, "index.js"),
+ clientJS = path.join(apiDir, "client.js"),
+ subfolderJS = path.join(apiDir, "/subfolder/myjs.js");//Sub folder js file
+
+ //Create packager-tests source folder
+ wrench.mkdirSyncRecursive(session.sourceDir);
+
+ spyOn(fs, "existsSync").andReturn(true);
+ spyOn(wrench, "mkdirSyncRecursive");
+ spyOn(packager_utils, "copyFile");
+
+ //Mock the extension directory
+ spyOn(wrench, "readdirSyncRecursive").andCallFake(function (directory) {
+ return [
+ indexJS,
+ clientJS,
+ subfolderJS,
+ ];
+ });
+
+ fileMgr.copyExtensions(session, session.targets[0]);
+
+ //Extension directory is created
+ expect(wrench.mkdirSyncRecursive).toHaveBeenCalledWith(toDir, "0755");
+
+ //Javascript files are copied
+ expect(packager_utils.copyFile).toHaveBeenCalledWith(indexJS, toDir, apiDir);
+ expect(packager_utils.copyFile).toHaveBeenCalledWith(clientJS, toDir, apiDir);
+ expect(packager_utils.copyFile).toHaveBeenCalledWith(subfolderJS, toDir, apiDir);
+ });
+
+ it("copyExtensions() should copy .so files required by features listed in config.xml", function () {
+ var session = testData.session,
+ extBasename = "app",
+ apiDir = path.resolve(session.conf.EXT, extBasename),
+ soDest = session.sourcePaths.JNEXT_PLUGINS,
+
+ //extension .so files
+ simulatorSO = path.join(apiDir, "/simulator/myso.so"),//simulator so file
+ deviceSO = path.join(apiDir, "/device/myso.so");//device so file
+
+ //Create packager-tests source folder
+ wrench.mkdirSyncRecursive(session.sourceDir);
+
+ spyOn(fs, "existsSync").andReturn(true);
+ spyOn(wrench, "mkdirSyncRecursive");
+ spyOn(packager_utils, "copyFile");
+
+ //Mock the extension directory
+ spyOn(wrench, "readdirSyncRecursive").andCallFake(function (directory) {
+ return [
+ simulatorSO,
+ deviceSO
+ ];
+ });
+
+ fileMgr.copyExtensions(session, session.targets[0]);
+
+ //plugins/jnext output directory is created
+ expect(wrench.mkdirSyncRecursive).toHaveBeenCalledWith(session.sourcePaths.JNEXT_PLUGINS, "0755");
+
+ //The .so files are copied
+ expect(packager_utils.copyFile).toHaveBeenCalledWith(simulatorSO, soDest);
+ expect(packager_utils.copyFile).toHaveBeenCalledWith(deviceSO, soDest);
+ });
+
+ it("unzip() should extract 'from' zip file to 'to' directory", function () {
+ var from = session.archivePath,
+ to = session.sourceDir;
+
+ fileMgr.unzip(from, to);
+
+ expect(fs.statSync(session.sourceDir + "/a").isDirectory()).toBeTruthy();
+ expect(fs.statSync(session.sourceDir + "/a/dummy.txt").isFile()).toBeTruthy();
+ expect(fs.statSync(session.sourceDir + "/a/b").isDirectory()).toBeTruthy();
+ expect(fs.statSync(session.sourceDir + "/a/b/dummy2.txt").isFile()).toBeTruthy();
+ expect(fs.statSync(session.sourceDir + "/startPage.html").isFile()).toBeTruthy();
+ expect(fs.statSync(session.sourceDir + "/config.xml").isFile()).toBeTruthy();
+ expect(fs.statSync(session.sourceDir + "/test.png").isFile()).toBeTruthy();
+ });
+
+ it("cleanSource() should delete source folder", function () {
+ //Create packager-tests source folder
+ wrench.mkdirSyncRecursive(session.sourceDir);
+
+ fileMgr.cleanSource(session);
+ expect(fs.existsSync(session.sourceDir)).toBeFalsy();
+ });
+
+ it("prepareOutputFiles() should copy files if a folder is sent in", function () {
+ spyOn(wrench, "copyDirSyncRecursive");
+ fileMgr.prepareOutputFiles(session);
+
+ expect(fs.existsSync(session.sourcePaths.CHROME)).toBeTruthy();
+ expect(wrench.copyDirSyncRecursive).toHaveBeenCalledWith(session.conf.DEPENDENCIES_BOOTSTRAP, session.sourcePaths.CHROME);
+ expect(fs.existsSync(session.sourcePaths.LIB)).toBeTruthy();
+ });
+
+ it("prepareOutputFiles() should copy files if a folder is sent in without .bbwpignore", function () {
+ var oldPathExistsSync = fs.existsSync;
+ spyOn(fs, "existsSync").andCallFake(function (ipath) {
+ return path.basename(ipath) === conf.BBWP_IGNORE_FILENAME ? false : oldPathExistsSync(ipath);
+ });
+ spyOn(wrench, "copyDirSyncRecursive");
+ fileMgr.prepareOutputFiles(session);
+
+ expect(fs.existsSync(session.sourcePaths.CHROME)).toBeTruthy();
+ expect(wrench.copyDirSyncRecursive).toHaveBeenCalledWith(session.conf.DEPENDENCIES_BOOTSTRAP, session.sourcePaths.CHROME);
+ expect(fs.existsSync(session.sourcePaths.LIB)).toBeTruthy();
+ });
+
+ it("prepareOutputFiles() should throw an error if the archive path doesn't exist", function () {
+ spyOn(wrench, "copyDirSyncRecursive");
+ var tempSession = testUtilities.cloneObj(session);
+ tempSession.archivePath = path.resolve("test/non-existant.zip");
+ expect(function () {
+ fileMgr.prepareOutputFiles(tempSession);
+ }).toThrow(localize.translate("EXCEPTION_INVALID_ARCHIVE_PATH", tempSession.archivePath));
+ });
+
+});
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/6831bed4/lib/cordova-blackberry/blackberry10/bin/test/cordova/unit/spec/lib/i18n-manager.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/blackberry10/bin/test/cordova/unit/spec/lib/i18n-manager.js b/lib/cordova-blackberry/blackberry10/bin/test/cordova/unit/spec/lib/i18n-manager.js
new file mode 100644
index 0000000..50d7225
--- /dev/null
+++ b/lib/cordova-blackberry/blackberry10/bin/test/cordova/unit/spec/lib/i18n-manager.js
@@ -0,0 +1,298 @@
+/*
+ * 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 testData = require("./test-data"),
+ i18nMgr = require(testData.libPath + "/i18n-manager"),
+ session = testData.session,
+ fs = require("fs"),
+ wrench = require("wrench"),
+ pkgrUtils = require(testData.libPath + "/packager-utils");
+
+function mockOSReturnFiles(files) {
+ if (pkgrUtils.isWindows()) {
+ var newFiles = [];
+ files.forEach(function (f) {
+ newFiles.push(session.sourceDir + "\\locales\\" + f.split("/").join("\\"));
+ });
+ return newFiles;
+ } else {
+ return files;
+ }
+}
+
+describe("i18n manager", function () {
+ it("generate correct metadata for icon", function () {
+ var config = {
+ icon: ["logo.png"]
+ },
+ xmlObject = {};
+
+ spyOn(fs, "existsSync").andReturn(true);
+ spyOn(wrench, "readdirSyncRecursive").andReturn(mockOSReturnFiles([
+ 'fr',
+ 'fr/logo.png'
+ ]));
+
+ i18nMgr.generateLocalizedMetadata(session, config, xmlObject, "icon");
+
+ expect(xmlObject.icon).toBeDefined();
+ expect(xmlObject.icon.image).toBeDefined();
+ expect(xmlObject.icon.image.length).toBe(2);
+ expect(xmlObject.icon.image).toContain({
+ _value: "logo.png"
+ });
+ expect(xmlObject.icon.image).toContain({
+ text: {
+ _attr: {
+ "xml:lang": "fr"
+ },
+ _value: "locales/fr/logo.png"
+ }
+ });
+ });
+
+ it("generate correct metadata for icon when locales folder does not exist", function () {
+ var config = {
+ icon: ["logo.png"]
+ },
+ xmlObject = {};
+
+ spyOn(fs, "existsSync").andReturn(false);
+
+ i18nMgr.generateLocalizedMetadata(session, config, xmlObject, "icon");
+
+ expect(xmlObject.icon).toBeDefined();
+ expect(xmlObject.icon.image).toBeDefined();
+ expect(xmlObject.icon.image.length).toBe(1);
+ expect(xmlObject.icon.image).toContain({
+ _value: "logo.png"
+ });
+ });
+
+ it("generate correct metadata for icon when locale folder does not contain matching image", function () {
+ var config = {
+ icon: ["logo.png"]
+ },
+ xmlObject = {};
+
+ spyOn(fs, "existsSync").andReturn(true);
+ spyOn(wrench, "readdirSyncRecursive").andReturn(mockOSReturnFiles([
+ 'fr',
+ 'fr/logo-mismatch.png'
+ ]));
+
+ i18nMgr.generateLocalizedMetadata(session, config, xmlObject, "icon");
+
+ expect(xmlObject.icon).toBeDefined();
+ expect(xmlObject.icon.image).toBeDefined();
+ expect(xmlObject.icon.image.length).toBe(1);
+ expect(xmlObject.icon.image).toContain({
+ _value: "logo.png"
+ });
+ });
+
+ it("generate correct metadata for icon when image is in subfolder", function () {
+ var config = {
+ icon: ["assets\\images\\logo.png"]
+ },
+ xmlObject = {};
+
+ spyOn(fs, "existsSync").andReturn(true);
+ spyOn(wrench, "readdirSyncRecursive").andReturn(mockOSReturnFiles([
+ 'fr',
+ 'fr/assets/images/logo.png'
+ ]));
+
+ i18nMgr.generateLocalizedMetadata(session, config, xmlObject, "icon");
+
+ expect(xmlObject.icon).toBeDefined();
+ expect(xmlObject.icon.image).toBeDefined();
+ expect(xmlObject.icon.image.length).toBe(2);
+ expect(xmlObject.icon.image).toContain({
+ _value: "assets/images/logo.png"
+ });
+ expect(xmlObject.icon.image).toContain({
+ text: {
+ _attr: {
+ "xml:lang": "fr"
+ },
+ _value: "locales/fr/assets/images/logo.png"
+ }
+ });
+ });
+
+ it("generate correct metadata for icon when image is in subfolder and OS is windows", function () {
+ var config = {
+ icon: ["assets\\images\\logo.png"]
+ },
+ xmlObject = {};
+
+ spyOn(pkgrUtils, 'isWindows').andReturn(true);
+ spyOn(fs, "existsSync").andReturn(true);
+ spyOn(wrench, "readdirSyncRecursive").andReturn(mockOSReturnFiles([
+ 'fr',
+ 'fr\\assets\\images\\logo.png'
+ ]));
+
+ i18nMgr.generateLocalizedMetadata(session, config, xmlObject, "icon");
+
+ expect(xmlObject.icon).toBeDefined();
+ expect(xmlObject.icon.image).toBeDefined();
+ expect(xmlObject.icon.image.length).toBe(1);
+ expect(xmlObject.icon.image).toContain({
+ _value: "assets/images/logo.png"
+ });
+ });
+
+ it("generate correct metadata for splash and OS is *nx", function () {
+ var config = {
+ "rim:splash": ["splash-1280x768.jpg", "splash-768x1280.jpg"]
+ },
+ xmlObject = {};
+
+ spyOn(pkgrUtils, 'isWindows').andReturn(false);
+ spyOn(fs, "existsSync").andReturn(true);
+ spyOn(wrench, "readdirSyncRecursive").andReturn(mockOSReturnFiles([
+ 'fr',
+ 'fr/splash-1280x768.jpg',
+ 'fr/splash-768x1280.jpg'
+ ]));
+
+ i18nMgr.generateLocalizedMetadata(session, config, xmlObject, "rim:splash");
+
+ expect(xmlObject.splashScreens).toBeDefined();
+ expect(xmlObject.splashScreens.image).toBeDefined();
+ expect(xmlObject.splashScreens.image.length).toBe(4);
+ expect(xmlObject.splashScreens.image).toContain({
+ _value: "splash-1280x768.jpg"
+ });
+ expect(xmlObject.splashScreens.image).toContain({
+ _value: "splash-768x1280.jpg"
+ });
+ expect(xmlObject.splashScreens.image).toContain({
+ text: {
+ _attr: {
+ "xml:lang": "fr"
+ },
+ _value: "locales/fr/splash-1280x768.jpg"
+ }
+ });
+ expect(xmlObject.splashScreens.image).toContain({
+ text: {
+ _attr: {
+ "xml:lang": "fr"
+ },
+ _value: "locales/fr/splash-768x1280.jpg"
+ }
+ });
+ });
+
+ it("generate correct metadata for splash when locales folder does not exist", function () {
+ var config = {
+ "rim:splash": ["splash-1280x768.jpg", "splash-768x1280.jpg"]
+ },
+ xmlObject = {};
+
+ spyOn(fs, "existsSync").andReturn(false);
+
+ i18nMgr.generateLocalizedMetadata(session, config, xmlObject, "rim:splash");
+
+ expect(xmlObject.splashScreens).toBeDefined();
+ expect(xmlObject.splashScreens.image).toBeDefined();
+ expect(xmlObject.splashScreens.image.length).toBe(2);
+ expect(xmlObject.splashScreens.image).toContain({
+ _value: "splash-1280x768.jpg"
+ });
+ expect(xmlObject.splashScreens.image).toContain({
+ _value: "splash-768x1280.jpg"
+ });
+ });
+
+ it("generate correct metadata for splash when locale folder does not contain matching image", function () {
+ var config = {
+ "rim:splash": ["splash-1280x768.jpg", "splash-768x1280.jpg"]
+ },
+ xmlObject = {};
+
+ spyOn(fs, "existsSync").andReturn(true);
+ spyOn(wrench, "readdirSyncRecursive").andReturn(mockOSReturnFiles([
+ 'fr',
+ 'fr/splash-1280x768-mismatch.jpg',
+ 'fr/splash-768x1280.jpg'
+ ]));
+
+ i18nMgr.generateLocalizedMetadata(session, config, xmlObject, "rim:splash");
+
+ expect(xmlObject.splashScreens).toBeDefined();
+ expect(xmlObject.splashScreens.image).toBeDefined();
+ expect(xmlObject.splashScreens.image.length).toBe(3);
+ expect(xmlObject.splashScreens.image).toContain({
+ _value: "splash-1280x768.jpg"
+ });
+ expect(xmlObject.splashScreens.image).toContain({
+ _value: "splash-768x1280.jpg"
+ });
+ expect(xmlObject.splashScreens.image).toContain({
+ text: {
+ _attr: {
+ "xml:lang": "fr"
+ },
+ _value: "locales/fr/splash-768x1280.jpg"
+ }
+ });
+ });
+
+ it("generate correct metadata for splash when image is in subfolder", function () {
+ var config = {
+ "rim:splash": ["assets\\images\\splash-1280x768.jpg", "assets\\images\\splash-768x1280.jpg"]
+ },
+ xmlObject = {};
+
+ spyOn(fs, "existsSync").andReturn(true);
+ spyOn(wrench, "readdirSyncRecursive").andReturn(mockOSReturnFiles([
+ 'fr',
+ 'fr/assets/images/splash-1280x768.jpg',
+ 'fr/assets/images/splash-768x1280.jpg'
+ ]));
+
+ i18nMgr.generateLocalizedMetadata(session, config, xmlObject, "rim:splash");
+
+ expect(xmlObject.splashScreens).toBeDefined();
+ expect(xmlObject.splashScreens.image).toBeDefined();
+ expect(xmlObject.splashScreens.image.length).toBe(4);
+ expect(xmlObject.splashScreens.image).toContain({
+ _value: "assets/images/splash-1280x768.jpg"
+ });
+ expect(xmlObject.splashScreens.image).toContain({
+ _value: "assets/images/splash-768x1280.jpg"
+ });
+ expect(xmlObject.splashScreens.image).toContain({
+ text: {
+ _attr: {
+ "xml:lang": "fr"
+ },
+ _value: "locales/fr/assets/images/splash-1280x768.jpg"
+ }
+ });
+ expect(xmlObject.splashScreens.image).toContain({
+ text: {
+ _attr: {
+ "xml:lang": "fr"
+ },
+ _value: "locales/fr/assets/images/splash-768x1280.jpg"
+ }
+ });
+ });
+});
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/6831bed4/lib/cordova-blackberry/blackberry10/bin/test/cordova/unit/spec/lib/logger.js
----------------------------------------------------------------------
diff --git a/lib/cordova-blackberry/blackberry10/bin/test/cordova/unit/spec/lib/logger.js b/lib/cordova-blackberry/blackberry10/bin/test/cordova/unit/spec/lib/logger.js
new file mode 100644
index 0000000..c8aadb9
--- /dev/null
+++ b/lib/cordova-blackberry/blackberry10/bin/test/cordova/unit/spec/lib/logger.js
@@ -0,0 +1,101 @@
+/*
+ * 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 srcPath = __dirname + "/../../../../../templates/project/cordova/lib/",
+ logger = require(srcPath + "logger");
+
+describe("logger", function () {
+ describe("when the log level is verbose", function () {
+ beforeEach(function () {
+ spyOn(console, "log");
+ logger.level('verbose');
+ });
+
+ it("logs info messages", function () {
+ logger.info("cheese is made from milk");
+ expect(console.log).toHaveBeenCalledWith("[INFO] cheese is made from milk");
+ });
+
+ it("logs error messages", function () {
+ logger.error("PC LOAD LETTER");
+ expect(console.log).toHaveBeenCalledWith("[ERROR] PC LOAD LETTER");
+ });
+
+ it("logs warning messages", function () {
+ logger.warn("beware the ides of march");
+ expect(console.log).toHaveBeenCalledWith("[WARN] beware the ides of march");
+ });
+
+ it("logs messages", function () {
+ logger.log("Hulk Smash!");
+ expect(console.log).toHaveBeenCalledWith("[BUILD] Hulk Smash!");
+ });
+ });
+
+ describe("when the log level is warn", function () {
+ beforeEach(function () {
+ spyOn(console, "log");
+ logger.level('warn');
+ });
+
+ it("doesn't log info messages", function () {
+ logger.info("cheese is made from milk");
+ expect(console.log).not.toHaveBeenCalledWith("[INFO] cheese is made from milk");
+ });
+
+ it("logs error messages", function () {
+ logger.error("PC LOAD LETTER");
+ expect(console.log).toHaveBeenCalledWith("[ERROR] PC LOAD LETTER");
+ });
+
+ it("logs warning messages", function () {
+ logger.warn("beware the ides of march");
+ expect(console.log).toHaveBeenCalledWith("[WARN] beware the ides of march");
+ });
+
+ it("logs messages", function () {
+ logger.log("Hulk Smash!");
+ expect(console.log).toHaveBeenCalledWith("[BUILD] Hulk Smash!");
+ });
+ });
+
+ describe("when the log level is error", function () {
+ beforeEach(function () {
+ spyOn(console, "log");
+ logger.level('error');
+ });
+
+ it("doesn't log info messages", function () {
+ logger.info("cheese is made from milk");
+ expect(console.log).not.toHaveBeenCalledWith("[INFO] cheese is made from milk");
+ });
+
+ it("logs error messages", function () {
+ logger.error("PC LOAD LETTER");
+ expect(console.log).toHaveBeenCalledWith("[ERROR] PC LOAD LETTER");
+ });
+
+ it("doesn't log warning messages", function () {
+ logger.warn("beware the ides of march");
+ expect(console.log).not.toHaveBeenCalledWith("[WARN] beware the ides of march");
+ });
+
+ it("logs messages", function () {
+ logger.log("Hulk Smash!");
+ expect(console.log).toHaveBeenCalledWith("[BUILD] Hulk Smash!");
+ });
+ });
+});