Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #32813 from julienw/1178242-fetch-type-from-zip-ma…
Browse files Browse the repository at this point in the history
…nifest

Bug 1178242 - properly preload privileged apps r=ricky
  • Loading branch information
julienw committed Oct 30, 2015
2 parents fd0cc68 + d0f31c1 commit 0036c75
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 2 deletions.
100 changes: 100 additions & 0 deletions build/test/unit/utils_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@

var assert = require('chai').assert;
var utils = require('../../utils');
var sinon = require('sinon');

suite('utils.js', function() {
setup(function() {
this.sinon = sinon.sandbox.create();
});

teardown(function() {
this.sinon.restore();
this.sinon = null;
});

test('isSubjectToBranding', function () {
var path = 'shared/resources/branding';
assert.isTrue(utils.isSubjectToBranding(path));
Expand All @@ -13,4 +23,94 @@ suite('utils.js', function() {
var path = 'locales/device_type';
assert.isTrue(utils.isSubjectToDeviceType(path));
});


suite('getWebapp', function() {
var appName, path, origin;

var config = {
GAIA_DOMAIN: 'gaiamobile.org',
GAIA_SCHEME: 'app://',
STAGE_DIR: 'stage_dir',
COREWEBAPPS_DIR: '/system'
};

setup(function() {
appName = 'helloworld';
path = 'some-path/' + appName;
origin = 'http://app.helloworld.fr';

this.sinon.stub(utils, 'getFile');
utils.getFile.withArgs(appName).returns({
exists: sinon.stub().returns(true),
remove: sinon.stub(),
isDirectory: sinon.stub.returns(false),
isFile: sinon.stub.returns(true),
isHidden: sinon.stub.returns(false),
path: path,
leafName: appName
});

utils.getFile.withArgs(path + '/manifest.webapp')
.returns('magic-manifest-webapp');

this.sinon.stub(utils, 'getJSON').withArgs('magic-manifest-webapp')
.returns({
name: appName
});

utils.getFile.withArgs(path, '..').returns({ leafName: '' });

utils.getFile.withArgs(path, 'metadata.json').returns({
exists: sinon.stub().returns(true),
leafName: 'metadata.json'
});

utils.getJSON
.withArgs(sinon.match.has('leafName', 'metadata.json'))
.returns({});

this.sinon.stub(utils, 'fileExists').returns(true);
this.sinon.stub(utils, 'readZipManifest')
.withArgs(sinon.match.has('leafName', appName))
.returns({
type: 'privileged',
name: appName,
origin: origin
});
this.sinon.stub(utils, 'isExternalApp').returns(true);

this.sinon.stub(utils, 'getUUIDMapping').returns({});
});

test('test', function() {
var webapp = utils.getWebapp(appName, config);
var directory = origin.replace(/^http:\/\//, '');

var expected = {
appDirPath: path,
manifest: { name: appName },
manifestFilePath: path + '/manifest.webapp',
url: config.GAIA_SCHEME + appName + '.' + config.GAIA_DOMAIN,
domain: appName + '.' + config.GAIA_DOMAIN,
sourceDirectoryFilePath: path,
sourceDirectoryName: appName,
sourceAppDirectoryName: '',
pckManifest: {
type: 'privileged',
name: appName,
origin: origin
},
metaData: {},
appStatus: 2,
buildDirectoryFilePath: config.STAGE_DIR + '/' + appName,
buildManifestFilePath:
config.STAGE_DIR + '/' + appName + '/manifest.webapp',
profileDirectoryFilePath:
config.COREWEBAPPS_DIR + '/webapps/' + directory
};

assert.deepEqual(webapp, expected);
});
});
});
6 changes: 5 additions & 1 deletion build/utils-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,11 @@ module.exports = {
if (metaData.exists()) {
webapp.pckManifest = this.readZipManifest(appDir);
webapp.metaData = this.getJSON(metaData);
webapp.appStatus = utils.getAppStatus(webapp.metaData.type || 'web');
webapp.appStatus = utils.getAppStatus(
webapp.metaData.type ||
(webapp.pckManifest && webapp.pckManifest.type) ||
'web'
);
} else {
webapp.appStatus = utils.getAppStatus(webapp.manifest.type);
}
Expand Down
6 changes: 5 additions & 1 deletion build/utils-xpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,11 @@ function getWebapp(app, config) {
webapp.pckManifest = readZipManifest(
getFile(webapp.sourceDirectoryFilePath));
webapp.metaData = getJSON(metaData);
webapp.appStatus = utils.getAppStatus(webapp.metaData.type || 'web');
webapp.appStatus = utils.getAppStatus(
webapp.metaData.type ||
(webapp.pckManifest && webapp.pckManifest.type) ||
'web'
);
} else {
webapp.appStatus = utils.getAppStatus(webapp.manifest.type);
}
Expand Down

0 comments on commit 0036c75

Please sign in to comment.