Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
This commit is contained in:
parent
93e3a48004
commit
b38dea0597
25901 changed files with 9982925 additions and 369 deletions
83
gaia/build/test/unit/app_test.js
Executable file
83
gaia/build/test/unit/app_test.js
Executable file
|
|
@ -0,0 +1,83 @@
|
|||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire');
|
||||
var mockUtils = require('./mock_utils.js');
|
||||
|
||||
suite('app.js', function() {
|
||||
var app;
|
||||
var files = [];
|
||||
var copied = false;
|
||||
var existed = false;
|
||||
var stageDir = '/path/to/build_stage';
|
||||
var applist = ['app1', 'app2', 'app3'];
|
||||
var options = {
|
||||
rebuildAppDirs: ['/path/to/app1', '/path/to/app2', '/path/to/app3'],
|
||||
STAGE_DIR: stageDir
|
||||
};
|
||||
|
||||
setup(function() {
|
||||
mockUtils.getFile = function() {
|
||||
var path = Array.prototype.slice.call(arguments, 0).join('/');
|
||||
var file = {
|
||||
path: path,
|
||||
leafName: path.split('/').pop(),
|
||||
exists: function() { return existed; }
|
||||
};
|
||||
files.push(file);
|
||||
return file;
|
||||
};
|
||||
|
||||
mockUtils.copyToStage = function() {
|
||||
copied = true;
|
||||
};
|
||||
|
||||
mockUtils.ensureFolderExists = function() {
|
||||
return true;
|
||||
};
|
||||
|
||||
mockUtils.NodeHelper = function() {
|
||||
this.require = function() {};
|
||||
};
|
||||
|
||||
var stubs = {
|
||||
'utils': mockUtils,
|
||||
'./rebuild': {},
|
||||
'./post-app': { execute: function() {} }
|
||||
};
|
||||
app = proxyquire.noCallThru().load('../../app', stubs);
|
||||
});
|
||||
|
||||
test('BUILD_APP_NAME = *', function() {
|
||||
options.BUILD_APP_NAME = '*';
|
||||
app.buildApps(options);
|
||||
|
||||
applist.forEach(function(appName, i) {
|
||||
var baseIdx = i * applist.length;
|
||||
assert.equal(files[baseIdx].path, '/path/to/' + appName,
|
||||
'1st file which access in app.js should be app absolute dir');
|
||||
assert.equal(files[baseIdx + 1].path, stageDir + '/' + appName,
|
||||
'2nd file which access in app.js should be app dir in build_stage');
|
||||
assert.equal(files[baseIdx + 2].path,
|
||||
'/path/to/' + appName + '/build/build.js',
|
||||
'3rd file which access in app.js should be build script in app dir');
|
||||
});
|
||||
});
|
||||
|
||||
test('BUILD_APP_NAME = app1', function() {
|
||||
var appName = 'app1';
|
||||
options.BUILD_APP_NAME = appName;
|
||||
app.buildApps(options);
|
||||
assert.equal(files[0].path, '/path/to/' + appName,
|
||||
'1st file which access in app.js should be app absolute dir');
|
||||
assert.equal(files[1].path, stageDir + '/' + appName,
|
||||
'2nd file which access in app.js should be app dir in build_stage');
|
||||
assert.equal(files[2].path,
|
||||
'/path/to/' + appName + '/build/build.js',
|
||||
'3rd file which access in app.js should be build script in app dir');
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
files = [];
|
||||
});
|
||||
});
|
||||
103
gaia/build/test/unit/keyboard_layouts_test.js
Executable file
103
gaia/build/test/unit/keyboard_layouts_test.js
Executable file
|
|
@ -0,0 +1,103 @@
|
|||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire');
|
||||
var mockUtils = require('./mock_utils.js');
|
||||
|
||||
suite('keyboard-layouts.js', function() {
|
||||
var app;
|
||||
var config = {
|
||||
KEYBOARD_LAYOUTS_PATH: 'test_keyboard_layouts.json'
|
||||
};
|
||||
|
||||
var defaultManifestURL = 'app://keyboard.gaiamobile.org/manifest.webapp';
|
||||
var webappsMapping = {
|
||||
keyboard: {
|
||||
manifestURL: defaultManifestURL
|
||||
}
|
||||
};
|
||||
|
||||
var result;
|
||||
|
||||
suiteSetup(function() {
|
||||
app = proxyquire.noCallThru().load(
|
||||
'../../keyboard-layouts', {
|
||||
'./utils': mockUtils
|
||||
});
|
||||
mockUtils.writeContent = function(file, content) {
|
||||
result = content;
|
||||
};
|
||||
|
||||
mockUtils.resolve = function(fileName, dir) {
|
||||
return {
|
||||
exists: function() {
|
||||
return true;
|
||||
},
|
||||
path: dir + '/' + fileName
|
||||
};
|
||||
};
|
||||
|
||||
mockUtils.getJSON = function() {
|
||||
return {
|
||||
'layout': {
|
||||
'en-US': [
|
||||
{'layoutId': 'en', 'app': ['apps', 'keyboard']}
|
||||
],
|
||||
'zh-TW': [
|
||||
{'layoutId': 'zhuyin', 'app': ['apps', 'keyboard']},
|
||||
{'layoutId': 'en', 'app': ['apps', 'keyboard']}
|
||||
],
|
||||
'es': [
|
||||
{'layoutId': 'es', 'app': ['apps', 'keyboard']}
|
||||
]
|
||||
},
|
||||
'langIndependentLayouts':
|
||||
[{'layoutId': 'number', 'app': ['apps', 'keyboard']}]
|
||||
,
|
||||
'fallbackLayouts':
|
||||
[{'layoutId': 'preload', 'app': ['apps', 'keyboard']}]
|
||||
};
|
||||
};
|
||||
|
||||
mockUtils.getFileContent = function() {
|
||||
return '';
|
||||
};
|
||||
});
|
||||
|
||||
test('Check the generated keyboard_layouts.json', function() {
|
||||
var preloadSet = ['en', 'zhuyin', 'es'];
|
||||
app.genDefaultLayouts(config, webappsMapping, preloadSet);
|
||||
|
||||
var expectedResult = {
|
||||
'layout': {
|
||||
'en-US': [{'layoutId': 'en', 'appManifestURL': defaultManifestURL}],
|
||||
'zh-TW': [{'layoutId': 'zhuyin', 'appManifestURL': defaultManifestURL},
|
||||
{'layoutId': 'en', 'appManifestURL': defaultManifestURL}],
|
||||
'es': [{'layoutId': 'es', 'appManifestURL': defaultManifestURL}],
|
||||
},
|
||||
'langIndependentLayouts':
|
||||
[{'layoutId': 'number', 'appManifestURL': defaultManifestURL}]
|
||||
};
|
||||
|
||||
assert.equal(result, JSON.stringify(expectedResult, null, 2));
|
||||
});
|
||||
|
||||
test('Check the generatedkeyboard_layouts.json with a minimal' +
|
||||
' preloaded layout set', function() {
|
||||
|
||||
var preloadSet = ['en'];
|
||||
app.genDefaultLayouts(config, webappsMapping, preloadSet);
|
||||
|
||||
var expectedResult = {
|
||||
'layout': {
|
||||
'en-US': [{'layoutId': 'en', 'appManifestURL': defaultManifestURL}],
|
||||
'zh-TW': [{'layoutId': 'en', 'appManifestURL': defaultManifestURL}],
|
||||
'es': [{'layoutId': 'preload', 'appManifestURL': defaultManifestURL}]
|
||||
},
|
||||
'langIndependentLayouts':
|
||||
[{'layoutId': 'number', 'appManifestURL': defaultManifestURL}]
|
||||
};
|
||||
|
||||
assert.equal(result, JSON.stringify(expectedResult, null, 2));
|
||||
});
|
||||
});
|
||||
111
gaia/build/test/unit/media_resolution_test.js
Executable file
111
gaia/build/test/unit/media_resolution_test.js
Executable file
|
|
@ -0,0 +1,111 @@
|
|||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire');
|
||||
var mockUtils = require('./mock_utils.js');
|
||||
|
||||
suite('media-resolution.js', function() {
|
||||
var app;
|
||||
var isFileExists;
|
||||
|
||||
setup(function() {
|
||||
app = proxyquire.noCallThru().load(
|
||||
'../../media-resolution', {
|
||||
'./utils': mockUtils
|
||||
});
|
||||
|
||||
var GetFile = function(path) {
|
||||
this.path = path;
|
||||
this.isRemoved = false;
|
||||
};
|
||||
|
||||
GetFile.prototype = {
|
||||
remove: function() {
|
||||
this.isRemoved = true;
|
||||
},
|
||||
get parent() {
|
||||
return mockUtils.getFile(this.path + '_parent');
|
||||
},
|
||||
exists: function() {
|
||||
return isFileExists;
|
||||
}
|
||||
};
|
||||
|
||||
mockUtils.getFile = function(path) {
|
||||
return new GetFile(path);
|
||||
};
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
app = null;
|
||||
isFileExists = null;
|
||||
});
|
||||
|
||||
suite('pickMediaByResolution', function() {
|
||||
var mediaResolution;
|
||||
|
||||
setup(function() {
|
||||
mediaResolution = new app.MediaResolution();
|
||||
});
|
||||
|
||||
test('pickMediaByResolution, when scanned file is 2x and ' +
|
||||
'GAIA_DEV_PIXELS_PER_PX is 1', function() {
|
||||
var filePath = 'test@2x.png';
|
||||
var file = mockUtils.getFile(filePath);
|
||||
mediaResolution.options = {};
|
||||
mediaResolution.options.GAIA_DEV_PIXELS_PER_PX = '1';
|
||||
mediaResolution.pickMediaByResolution(file);
|
||||
|
||||
assert.equal(file.isRemoved, true);
|
||||
});
|
||||
|
||||
test('pickMediaByResolution, when scanned file is default and ' +
|
||||
'GAIA_DEV_PIXELS_PER_PX is 1', function() {
|
||||
var filePath = 'test.png';
|
||||
var file = mockUtils.getFile(filePath);
|
||||
mediaResolution.options = {};
|
||||
mediaResolution.options.GAIA_DEV_PIXELS_PER_PX = '1';
|
||||
mediaResolution.pickMediaByResolution(file);
|
||||
|
||||
assert.equal(file.isRemoved, false);
|
||||
});
|
||||
|
||||
test('pickMediaByResolution, when scanned file is default and ' +
|
||||
'GAIA_DEV_PIXELS_PER_PX is 2 and @2x file exists', function() {
|
||||
var filePath = 'test.png';
|
||||
var file = mockUtils.getFile(filePath);
|
||||
mediaResolution.options = {};
|
||||
mediaResolution.options.GAIA_DEV_PIXELS_PER_PX = '2';
|
||||
mediaResolution.pickMediaByResolution(file);
|
||||
|
||||
// hidpi file which meet GAIA_DEV_PIXELS_PER_PX exists.
|
||||
isFileExists = true;
|
||||
assert.equal(file.isRemoved, false);
|
||||
});
|
||||
|
||||
test('pickMediaByResolution, when scanned file is default and ' +
|
||||
'GAIA_DEV_PIXELS_PER_PX is 2 and @2x file doenot exist', function() {
|
||||
var filePath = 'test.png';
|
||||
var file = mockUtils.getFile(filePath);
|
||||
mediaResolution.options = {};
|
||||
mediaResolution.options.GAIA_DEV_PIXELS_PER_PX = '2';
|
||||
mediaResolution.pickMediaByResolution(file);
|
||||
|
||||
isFileExists = false;
|
||||
assert.equal(file.isRemoved, false);
|
||||
});
|
||||
|
||||
test('pickMediaByResolution, when scanned file has video extension and ' +
|
||||
'GAIA_DEV_PIXELS_PER_PX is 2 and @2x file exists', function() {
|
||||
var filePath = 'test.mp4';
|
||||
var file = mockUtils.getFile(filePath);
|
||||
mediaResolution.options = {};
|
||||
mediaResolution.options.GAIA_DEV_PIXELS_PER_PX = '2';
|
||||
mediaResolution.pickMediaByResolution(file);
|
||||
|
||||
// hidpi file which meet GAIA_DEV_PIXELS_PER_PX exists.
|
||||
isFileExists = true;
|
||||
assert.equal(file.isRemoved, false);
|
||||
});
|
||||
});
|
||||
});
|
||||
87
gaia/build/test/unit/mock_child_process.js
Executable file
87
gaia/build/test/unit/mock_child_process.js
Executable file
|
|
@ -0,0 +1,87 @@
|
|||
'use strict';
|
||||
|
||||
(function() {
|
||||
|
||||
|
||||
var MockChildProcess = function() {};
|
||||
MockChildProcess.prototype = {
|
||||
states: {
|
||||
command: '',
|
||||
options: {},
|
||||
environment: {},
|
||||
|
||||
// callback registry
|
||||
stdout: {},
|
||||
stderr: {},
|
||||
on: {}
|
||||
},
|
||||
rc: null
|
||||
};
|
||||
|
||||
MockChildProcess.prototype.spawn = function(cmd, opts, env) {
|
||||
this.states.command = cmd;
|
||||
this.states.options = opts;
|
||||
this.states.environment = env;
|
||||
return {
|
||||
'stdout': {'on': this.stdout.bind(this)},
|
||||
'stderr': {'on': this.stderr.bind(this)},
|
||||
'on': this.on.bind(this)
|
||||
};
|
||||
};
|
||||
|
||||
MockChildProcess.prototype.on = function(ename, cb) {
|
||||
this.states.on[ename] = cb;
|
||||
};
|
||||
|
||||
MockChildProcess.prototype.stdout = function(ename, cb) {
|
||||
this.states.stdout[ename] = cb;
|
||||
};
|
||||
|
||||
MockChildProcess.prototype.stderr = function(ename, cb) {
|
||||
this.states.stderr[ename] = cb;
|
||||
};
|
||||
|
||||
/**
|
||||
* Would generate a "remote controller" to let user feed in
|
||||
* stdout, stderr and close, exit and so on events.
|
||||
*/
|
||||
MockChildProcess.prototype.rc = function() {
|
||||
var rcInstance = {
|
||||
stdout: {on:
|
||||
this.rcStdOutOn.bind(this)
|
||||
},
|
||||
stderr: {on:
|
||||
this.rcStdErrOn.bind(this)
|
||||
},
|
||||
on: this.rcOn.bind(this)
|
||||
};
|
||||
|
||||
if(!this.rcInstance) {
|
||||
this.rcInstance = rcInstance;
|
||||
}
|
||||
return this.rcInstance;
|
||||
};
|
||||
|
||||
MockChildProcess.prototype.rcStdOutOn = function(ename, content) {
|
||||
var cb = this.states.stdout[ename];
|
||||
if(cb) {
|
||||
return cb(content);
|
||||
}
|
||||
};
|
||||
|
||||
MockChildProcess.prototype.rcStdErrOn = function(ename, content) {
|
||||
var cb = this.states.stderr[ename];
|
||||
if(cb) {
|
||||
return cb(content);
|
||||
}
|
||||
};
|
||||
|
||||
MockChildProcess.prototype.rcOn = function(ename, content) {
|
||||
var cb = this.states.on[ename];
|
||||
if(cb) {
|
||||
return cb(content);
|
||||
}
|
||||
};
|
||||
|
||||
exports.MockChildProcess = MockChildProcess;
|
||||
})();
|
||||
128
gaia/build/test/unit/mock_utils.js
Executable file
128
gaia/build/test/unit/mock_utils.js
Executable file
|
|
@ -0,0 +1,128 @@
|
|||
'use strict';
|
||||
|
||||
var hasRunCommands = {};
|
||||
var gaiaOriginURL = function(name, scheme, domain, port) {
|
||||
return scheme + name + '.' + domain + (port ? port : '');
|
||||
};
|
||||
|
||||
exports.Q = require('q');
|
||||
|
||||
var joinPath = function() {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
return args.join('/');
|
||||
};
|
||||
|
||||
exports.joinPath = joinPath;
|
||||
|
||||
exports.Commander = function(type) {
|
||||
hasRunCommands[type] = [];
|
||||
this.run = function(cmds, callback) {
|
||||
hasRunCommands[type].push(cmds.join(' '));
|
||||
callback && callback();
|
||||
};
|
||||
this.initPath = function() {
|
||||
};
|
||||
};
|
||||
|
||||
exports.killAppByPid = function(appName) {
|
||||
hasRunCommands.sh.push('-c adb shell kill ' + appName);
|
||||
};
|
||||
|
||||
exports.hasRunCommands = hasRunCommands;
|
||||
|
||||
exports.psParser = function(content) {
|
||||
return content;
|
||||
};
|
||||
|
||||
exports.setEnv = function() {
|
||||
};
|
||||
|
||||
exports.getEnvPath = function() {
|
||||
};
|
||||
|
||||
exports.processEvents = function() {
|
||||
};
|
||||
|
||||
var mockNSIFile = function() {
|
||||
return {
|
||||
clone: mockNSIFile,
|
||||
remove: function() {},
|
||||
append: function() {}
|
||||
};
|
||||
};
|
||||
|
||||
exports.getTempFolder = function() {
|
||||
return mockNSIFile();
|
||||
};
|
||||
|
||||
exports.getJSON = function() {
|
||||
};
|
||||
|
||||
exports.gaiaOriginURL = gaiaOriginURL;
|
||||
|
||||
exports.gaiaManifestURL = function(name, scheme, domain, port) {
|
||||
return gaiaOriginURL(name, scheme, domain, port) + '/manifest.webapp';
|
||||
};
|
||||
|
||||
exports.log = console.log;
|
||||
exports.getExtension = function(filename) {
|
||||
return filename.substr(filename.lastIndexOf('.') + 1).toLowerCase();
|
||||
};
|
||||
|
||||
exports.isSubjectToBranding = function(path) {
|
||||
return /shared[\/\\][a-zA-Z]+[\/\\]branding$/.test(path) ||
|
||||
/branding[\/\\]initlogo.png/.test(path);
|
||||
};
|
||||
|
||||
exports.isSubjectToDeviceType = function(path) {
|
||||
return /locales[\/\\]?[a-zA-Z]*[\/\\]?device_type$/.test(path);
|
||||
};
|
||||
|
||||
exports.cloneJSON = function(obj) {
|
||||
return JSON.parse(JSON.stringify(obj));
|
||||
};
|
||||
|
||||
exports.existsInAppDirs = function(appDirs, appName) {
|
||||
var apps = appDirs.split(' ');
|
||||
var exists = apps.some(function (appPath) {
|
||||
let appFile = {
|
||||
leafName: appPath
|
||||
};
|
||||
return (appName === appFile.leafName);
|
||||
});
|
||||
return exists;
|
||||
};
|
||||
|
||||
exports.getAppNameRegex = function(buildAppName) {
|
||||
return buildAppName === '*' ? /.+/ : new RegExp(buildAppName);
|
||||
};
|
||||
|
||||
exports.scriptLoader = {
|
||||
load: function load() {}
|
||||
};
|
||||
|
||||
exports.dirname = function(path) {
|
||||
return path.substr(0, path.lastIndexOf('/'));
|
||||
};
|
||||
|
||||
exports.basename = function(path) {
|
||||
return path.substr(path.lastIndexOf('/')+1);
|
||||
};
|
||||
|
||||
exports.relativePath = function(from, to) {
|
||||
// that's really dummy, but we need it for webapp-optimize tests.
|
||||
return to;
|
||||
};
|
||||
|
||||
exports.gaia = {
|
||||
getInstance: function(options) {
|
||||
var rebuildWebapps = options.rebuildAppDirs.map(function(appDir) {
|
||||
return {
|
||||
appDirPath: appDir
|
||||
};
|
||||
});
|
||||
return {
|
||||
rebuildWebapps: rebuildWebapps
|
||||
};
|
||||
}
|
||||
};
|
||||
4
gaia/build/test/unit/mock_webapp_manifests.js
Executable file
4
gaia/build/test/unit/mock_webapp_manifests.js
Executable file
|
|
@ -0,0 +1,4 @@
|
|||
'use strict';
|
||||
|
||||
exports = {
|
||||
};
|
||||
447
gaia/build/test/unit/preference_test.js
Executable file
447
gaia/build/test/unit/preference_test.js
Executable file
|
|
@ -0,0 +1,447 @@
|
|||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire');
|
||||
var mockUtils = require('./mock_utils.js');
|
||||
|
||||
suite('preferences.js', function() {
|
||||
var app;
|
||||
var preferences;
|
||||
var fileContent;
|
||||
var servicePrefs = {};
|
||||
setup(function() {
|
||||
app = proxyquire.noCallThru().load(
|
||||
'../../preferences', {
|
||||
'./utils': mockUtils
|
||||
});
|
||||
mockUtils.gaia = {
|
||||
getInstance: function(config) {
|
||||
return config;
|
||||
}
|
||||
};
|
||||
mockUtils.getFile = function() {
|
||||
return {
|
||||
path: Array.prototype.join.call(arguments, '/'),
|
||||
exists: function() {
|
||||
return true;
|
||||
},
|
||||
clone: function() {
|
||||
return {
|
||||
append: function() {},
|
||||
exists: function() { return true; }
|
||||
};
|
||||
},
|
||||
};
|
||||
};
|
||||
mockUtils.getFileContent = function(file) {
|
||||
return file.path;
|
||||
};
|
||||
mockUtils.getFileURISpec = function(file) {
|
||||
return file.path;
|
||||
};
|
||||
mockUtils.writeContent = function(file, content) {
|
||||
fileContent = {
|
||||
file: file.path,
|
||||
content: content
|
||||
};
|
||||
return fileContent;
|
||||
};
|
||||
mockUtils.getLocaleBasedir = function(dir) {
|
||||
return dir;
|
||||
};
|
||||
mockUtils.Services = {
|
||||
prefs: {
|
||||
setCharPref: function(key, val) {
|
||||
servicePrefs[key] = {
|
||||
value: val,
|
||||
type: 'char'
|
||||
};
|
||||
},
|
||||
setBoolPref: function(key, val) {
|
||||
servicePrefs[key] = {
|
||||
value: val,
|
||||
type: 'bool'
|
||||
};
|
||||
},
|
||||
setIntPref: function(key, val) {
|
||||
servicePrefs[key] = {
|
||||
value: val,
|
||||
type: 'int'
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
suite('setConfig, execute, writePref, setPrefs, loadPrefFile, ' +
|
||||
'customizePrefValue', function() {
|
||||
var config;
|
||||
setup(function() {
|
||||
preferences = new app.PreferencesBuilder();
|
||||
config = {
|
||||
PROFILE_DIR: 'testProfileDir'
|
||||
};
|
||||
});
|
||||
|
||||
test('setConfig', function () {
|
||||
preferences.setConfig(config);
|
||||
|
||||
assert.deepEqual(preferences.config, config);
|
||||
assert.deepEqual(preferences.prefs, {});
|
||||
assert.deepEqual(preferences.gaia, config);
|
||||
assert.deepEqual(preferences.extenedPrefFiles,
|
||||
['custom-prefs.js', 'gps-prefs.js', 'payment-prefs.js'],
|
||||
'extenedPrefFiles should contain three *-prefs.js');
|
||||
});
|
||||
|
||||
test('setConfig with DEBUG=1', function () {
|
||||
config.DEBUG = '1';
|
||||
preferences.setConfig(config);
|
||||
assert.ok(preferences.extenedPrefFiles.indexOf('debug-prefs.js') !== -1,
|
||||
'extenedPrefFiles should contain debug-prefs.js');
|
||||
});
|
||||
|
||||
test('setConfig with GAIA_APP_TARGET=engineering', function () {
|
||||
config.GAIA_APP_TARGET = 'engineering';
|
||||
preferences.setConfig(config);
|
||||
assert.ok(
|
||||
preferences.extenedPrefFiles.indexOf('payment-dev-prefs.js') !== -1,
|
||||
'extenedPrefFiles should contain payment-dev-prefs.js'
|
||||
);
|
||||
});
|
||||
|
||||
test('setConfig with GAIA_APP_TARGET=dogfood', function () {
|
||||
config.GAIA_APP_TARGET = 'dogfood';
|
||||
preferences.setConfig(config);
|
||||
assert.ok(
|
||||
preferences.extenedPrefFiles.indexOf('dogfood-prefs.js') !== -1,
|
||||
'extenedPrefFiles should contain dogfood-prefs.js'
|
||||
);
|
||||
});
|
||||
|
||||
test('execute', function () {
|
||||
var result;
|
||||
preferences.preparePref = function() {};
|
||||
preferences.writePrefs = function() {result = 'xpcshell';};
|
||||
preferences.setPrefs = function() {result = 'b2g';};
|
||||
preferences.execute({engine: 'xpcshell'});
|
||||
assert.equal(result, 'xpcshell');
|
||||
preferences.execute({engine: 'b2g'});
|
||||
assert.equal(result, 'b2g');
|
||||
});
|
||||
|
||||
test('writePrefs', function () {
|
||||
preferences.config = {
|
||||
PROFILE_DIR: 'testProfileDir'
|
||||
};
|
||||
preferences.prefs = {
|
||||
'testKey': 'testContent'
|
||||
};
|
||||
preferences.userPrefs = {
|
||||
'testKey2': 'testContent2'
|
||||
};
|
||||
preferences.writePrefs(preferences.config.PROFILE_DIR + 'user.js',
|
||||
preferences.prefs, preferences.userPrefs
|
||||
);
|
||||
assert.deepEqual(fileContent, {
|
||||
file: preferences.config.PROFILE_DIR + 'user.js',
|
||||
content: 'pref(\'' + 'testKey' + '\', ' +
|
||||
JSON.stringify('testContent') + ');\n' +
|
||||
'user_pref(\'' + 'testKey2' + '\', ' +
|
||||
JSON.stringify('testContent2') + ');\n' + '\n'
|
||||
});
|
||||
});
|
||||
|
||||
test('setPrefs', function () {
|
||||
preferences.prefs = {
|
||||
string: 'abc',
|
||||
bool: true,
|
||||
num: 3
|
||||
};
|
||||
preferences.setPrefs();
|
||||
assert.deepEqual(servicePrefs, {
|
||||
'string': {
|
||||
value: 'abc',
|
||||
type: 'char'
|
||||
},
|
||||
'bool': {
|
||||
value: true,
|
||||
type: 'bool'
|
||||
},
|
||||
'num': {
|
||||
value: 3,
|
||||
type: 'int'
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test('loadPrefFile', function() {
|
||||
preferences.prefs = {};
|
||||
preferences.userPrefs = {};
|
||||
var callingCount = 0;
|
||||
var oldLoader = mockUtils.scriptLoader.load;
|
||||
mockUtils.scriptLoader.load = function(path, exportObj, withoutCache) {
|
||||
assert.isDefined(path);
|
||||
assert.isDefined(exportObj);
|
||||
callingCount++;
|
||||
exportObj.pref('test-string-key-' + callingCount, path);
|
||||
exportObj.pref('test-boolean-key-' + callingCount, true);
|
||||
exportObj.pref('test-integer-key-' + callingCount, 1);
|
||||
exportObj.user_pref('test-user-string-key-' + callingCount,
|
||||
'test user value');
|
||||
exportObj.user_pref('test-user-boolean-key-' + callingCount, false);
|
||||
exportObj.user_pref('test-user-integer-key-' + callingCount, 2);
|
||||
};
|
||||
|
||||
var prefsList = ['prefs-a', 'prefs-b', 'prefs-c'];
|
||||
var exists = function() { return true; };
|
||||
var srcDir = {
|
||||
path: 'build/config',
|
||||
exists: exists,
|
||||
clone: function() {
|
||||
var path = 'build/config';
|
||||
return {
|
||||
path: path,
|
||||
exists: exists,
|
||||
append: function(filename) {
|
||||
this.path += '/' + filename;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
preferences.loadPrefFile(srcDir, prefsList);
|
||||
assert.equal(callingCount, 3);
|
||||
assert.deepEqual(preferences.prefs, {
|
||||
'test-string-key-1': 'build/config/prefs-a',
|
||||
'test-boolean-key-1': true,
|
||||
'test-integer-key-1': 1,
|
||||
'test-string-key-2': 'build/config/prefs-b',
|
||||
'test-boolean-key-2': true,
|
||||
'test-integer-key-2': 1,
|
||||
'test-string-key-3': 'build/config/prefs-c',
|
||||
'test-boolean-key-3': true,
|
||||
'test-integer-key-3': 1
|
||||
});
|
||||
assert.deepEqual(preferences.userPrefs, {
|
||||
'test-user-string-key-1': 'test user value',
|
||||
'test-user-boolean-key-1': false,
|
||||
'test-user-integer-key-1': 2,
|
||||
'test-user-string-key-2': 'test user value',
|
||||
'test-user-boolean-key-2': false,
|
||||
'test-user-integer-key-2': 2,
|
||||
'test-user-string-key-3': 'test user value',
|
||||
'test-user-boolean-key-3': false,
|
||||
'test-user-integer-key-3': 2
|
||||
});
|
||||
mockUtils.scriptLoader.load = oldLoader;
|
||||
});
|
||||
|
||||
test('customizePrefValue', function() {
|
||||
// responsive UI
|
||||
var value = preferences.customizePrefValue(
|
||||
'devtools.responsiveUI.customWidth', 0);
|
||||
assert.equal(value, 32);
|
||||
value = preferences.customizePrefValue(
|
||||
'devtools.responsiveUI.customHeight', 0);
|
||||
assert.equal(value, 61);
|
||||
value = preferences.customizePrefValue('other-integer-pref', 0);
|
||||
assert.equal(value, 0);
|
||||
value = preferences.customizePrefValue('other-boolean-pref', true);
|
||||
assert.isTrue(value);
|
||||
value = preferences.customizePrefValue('other-string-pref', 'test');
|
||||
assert.equal(value, 'test');
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
config = null;
|
||||
preferences = null;
|
||||
fileContent = null;
|
||||
servicePrefs = {};
|
||||
});
|
||||
});
|
||||
|
||||
suite('editLocalDomainPref, editDesktopPref, editDebugPref, ' +
|
||||
'editDeviceDebugPref', function() {
|
||||
var config;
|
||||
setup(function() {
|
||||
preferences = new app.PreferencesBuilder();
|
||||
});
|
||||
|
||||
test('editLocalDomainPref', function () {
|
||||
preferences.domains = ['test1', 'test2'];
|
||||
preferences.prefs = {};
|
||||
preferences.userPrefs = {};
|
||||
preferences.setLocalDomainPref();
|
||||
|
||||
assert.deepEqual(preferences.userPrefs, {
|
||||
'network.dns.localDomains': preferences.domains.join(',')
|
||||
});
|
||||
});
|
||||
|
||||
test('editDesktopPref', function () {
|
||||
preferences.system = 'testSystem';
|
||||
preferences.prefs = {};
|
||||
preferences.userPrefs = {};
|
||||
preferences.setDesktopPref();
|
||||
assert.deepEqual(preferences.userPrefs, {
|
||||
'extensions.autoDisableScopes': 0,
|
||||
'xpinstall.signatures.required': false
|
||||
});
|
||||
});
|
||||
|
||||
test('editDebugPref', function () {
|
||||
preferences.homescreen = 'testHomescreen';
|
||||
preferences.config = {
|
||||
GAIA_DIR: 'testGaiaDir',
|
||||
GAIA_DOMAIN: 'testGaiaDomain',
|
||||
GAIA_PORT: ':8080',
|
||||
GAIA_APPDIRS: 'testAppDirs',
|
||||
GAIA_ALLAPPDIRS: 'testAppDir1 testAppDir2',
|
||||
GAIA_LOCALES_PATH: 'testLocalesPath',
|
||||
OFFICIAL: 1,
|
||||
LOCALES_FILE: 'testLocaleFile',
|
||||
LOCALE_BASEDIR: 'testLocaleBaseDir',
|
||||
GAIA_DEV_PIXELS_PER_PX: 2
|
||||
};
|
||||
preferences.gaia = {
|
||||
webapps: [
|
||||
{
|
||||
sourceAppDirectoryName: 'testSourceName',
|
||||
sourceDirectoryName: 'testDirName'
|
||||
}
|
||||
]
|
||||
};
|
||||
preferences.prefs = {};
|
||||
preferences.userPrefs = {};
|
||||
preferences.setDebugPref();
|
||||
assert.deepEqual(preferences.userPrefs, {
|
||||
'docshell.device_size_is_page_size': true,
|
||||
'marionette.defaultPrefs.enabled': true,
|
||||
'nglayout.debug.disable_xul_cache': true,
|
||||
'nglayout.debug.disable_xul_fastload': true,
|
||||
'javascript.options.showInConsole': true,
|
||||
'browser.dom.window.dump.enabled': true,
|
||||
'dom.report_all_js_exceptions': true,
|
||||
'dom.w3c_touch_events.enabled': 1,
|
||||
'dom.promise.enabled': true,
|
||||
'dom.wakelock.enabled': true,
|
||||
'image.mozsamplesize.enabled': true,
|
||||
'webgl.verbose': true,
|
||||
'dom.max_script_run_time': 0,
|
||||
'toolkit.identity.debug': true,
|
||||
'extensions.gaia.dir': preferences.config.GAIA_DIR,
|
||||
'extensions.gaia.domain': preferences.config.GAIA_DOMAIN,
|
||||
'extensions.gaia.port': 8080,
|
||||
'extensions.gaia.appdirs': preferences.config.GAIA_APPDIRS,
|
||||
'extensions.gaia.allappdirs': preferences.config.GAIA_ALLAPPDIRS,
|
||||
'extensions.gaia.locales_debug_path':
|
||||
preferences.config.GAIA_LOCALES_PATH,
|
||||
'extensions.gaia.official': true,
|
||||
'extensions.gaia.locales_file': preferences.config.LOCALES_FILE,
|
||||
'extensions.gaia.locale_basedir': preferences.config.LOCALE_BASEDIR,
|
||||
'extensions.gaia.device_pixel_suffix':
|
||||
'@' + preferences.config.GAIA_DEV_PIXELS_PER_PX + 'x',
|
||||
'extensions.autoDisableScopes': 0,
|
||||
'xpinstall.signatures.required': false,
|
||||
'browser.tabs.remote.autostart': false,
|
||||
'browser.tabs.remote.autostart.1': false,
|
||||
'browser.tabs.remote.autostart.2': false,
|
||||
'browser.shell.checkDefaultBrowser': false
|
||||
});
|
||||
assert.isUndefined(preferences.userPrefs['network.http.use-cache']);
|
||||
});
|
||||
|
||||
test('editDeviceDebugPref', function () {
|
||||
preferences.prefs = {};
|
||||
preferences.userPrefs = {};
|
||||
preferences.setDeviceDebugPref();
|
||||
assert.deepEqual(preferences.userPrefs, {
|
||||
'devtools.debugger.prompt-connection': false,
|
||||
'devtools.debugger.forbid-certified-apps': false,
|
||||
'javascript.options.discardSystemSource': false,
|
||||
'dom.apps.developer_mode': true,
|
||||
'network.disable.ipc.security': true,
|
||||
'dom.webcomponents.enabled': true,
|
||||
'b2g.adb.timeout': 0
|
||||
});
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
config = null;
|
||||
preferences = null;
|
||||
fileContent = null;
|
||||
});
|
||||
});
|
||||
suite('preparePref', function() {
|
||||
var config;
|
||||
setup(function() {
|
||||
preferences = new app.PreferencesBuilder();
|
||||
});
|
||||
|
||||
test('preparePref', function () {
|
||||
var cusPref;
|
||||
preferences.setLocalDomainPref = function() {
|
||||
cusPref = 'local';
|
||||
};
|
||||
preferences.setDesktopPref = function() {
|
||||
cusPref = 'desktop';
|
||||
};
|
||||
preferences.setDebugPref = function() {
|
||||
cusPref = 'debug';
|
||||
};
|
||||
preferences.setDeviceDebugPref = function() {
|
||||
cusPref = 'device';
|
||||
};
|
||||
|
||||
preferences.gaia = {
|
||||
webapps: [
|
||||
{ domain: 'testDomain' }
|
||||
]
|
||||
};
|
||||
preferences.config = {
|
||||
SYSTEM: 'app://system',
|
||||
GAIA_PORT: '8000',
|
||||
GAIA_DOMAIN: 'domain',
|
||||
GAIA_ALLAPPDIRS: 'testAppDir1 testAppDir2'
|
||||
};
|
||||
|
||||
preferences.prefs = {};
|
||||
preferences.userPrefs = {};
|
||||
preferences.preparePref();
|
||||
assert.deepEqual(preferences.userPrefs, {
|
||||
'b2g.system_manifest_url': 'app://system/manifest.webapp',
|
||||
'b2g.neterror.url': 'app://system/net_error.html',
|
||||
'b2g.system_startup_url': 'app://system/index.html',
|
||||
'network.http.max-connections-per-server': 15,
|
||||
'dom.mozInputMethod.enabled': true,
|
||||
'intl.uidirection.ar-x-psbidi': 'rtl',
|
||||
'layout.css.scroll-behavior.enabled': true,
|
||||
'layout.css.sticky.enabled': true,
|
||||
'ril.debugging.enabled': false,
|
||||
'dom.mms.version': 0x11,
|
||||
'b2g.wifi.allow_unsafe_wpa_eap': true
|
||||
});
|
||||
preferences.config.LOCAL_DOMAINS = '1';
|
||||
preferences.preparePref();
|
||||
assert.equal(cusPref, 'local');
|
||||
delete preferences.config.LOCAL_DOMAINS;
|
||||
preferences.config.DESKTOP = '1';
|
||||
preferences.preparePref();
|
||||
assert.equal(cusPref, 'desktop');
|
||||
delete preferences.config.DESKTOP;
|
||||
preferences.config.DEBUG = '1';
|
||||
preferences.preparePref();
|
||||
assert.equal(cusPref, 'debug');
|
||||
delete preferences.config.DEBUG;
|
||||
preferences.config.DEVICE_DEBUG = '1';
|
||||
preferences.preparePref();
|
||||
assert.equal(cusPref, 'device');
|
||||
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
config = null;
|
||||
preferences = null;
|
||||
});
|
||||
});
|
||||
});
|
||||
269
gaia/build/test/unit/push_to_device_test.js
Executable file
269
gaia/build/test/unit/push_to_device_test.js
Executable file
|
|
@ -0,0 +1,269 @@
|
|||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire');
|
||||
var mockUtils = require('./mock_utils.js');
|
||||
|
||||
suite('push-to-device.js', function() {
|
||||
var app;
|
||||
setup(function() {
|
||||
app = proxyquire.noCallThru().load(
|
||||
'../../push-to-device', {
|
||||
'./utils': mockUtils
|
||||
});
|
||||
mockUtils.getFileContent = function(file) {
|
||||
return file;
|
||||
};
|
||||
});
|
||||
|
||||
suite('pushToDevice, getPid and installSvoperapps', function() {
|
||||
var profileFolder = 'testProfileFolder';
|
||||
var remotePath = 'testRemotePath';
|
||||
|
||||
test('pushToDevice without indexedDbFile', function(done) {
|
||||
mockUtils.getFile = function() {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
var path = args.join('/');
|
||||
var indexDbFileExists = (path === profileFolder + '/indexedDB');
|
||||
return {
|
||||
exists: function() {
|
||||
return !indexDbFileExists;
|
||||
},
|
||||
isDirectory: function() {
|
||||
return !indexDbFileExists;
|
||||
},
|
||||
path: profileFolder + '/indexedDB'
|
||||
};
|
||||
};
|
||||
var queue = app.pushToDevice(profileFolder, remotePath, 'adb');
|
||||
queue.done(function() {
|
||||
assert.deepEqual(
|
||||
mockUtils.hasRunCommands,
|
||||
{ sh: [
|
||||
'-c adb shell rm -r /' + remotePath + '/webapps',
|
||||
'-c adb shell rm //data/local/user.js',
|
||||
'-c adb push "' + profileFolder + '/webapps" /' + remotePath +
|
||||
'/webapps',
|
||||
'-c adb push "' + profileFolder +
|
||||
'/user.js" //data/local/user.js']
|
||||
}
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('pushToDevice with indexedDbFile', function(done) {
|
||||
mockUtils.getFile = function() {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
var path = args.join('/');
|
||||
var indexDbFileExists = (path === profileFolder + '/indexedDB');
|
||||
return {
|
||||
exists: function() {
|
||||
return indexDbFileExists;
|
||||
},
|
||||
isDirectory: function() {
|
||||
return indexDbFileExists;
|
||||
},
|
||||
path: profileFolder + '/indexedDB'
|
||||
};
|
||||
};
|
||||
var queue = app.pushToDevice(profileFolder, remotePath, 'adb');
|
||||
queue.done(function() {
|
||||
assert.deepEqual(
|
||||
mockUtils.hasRunCommands,
|
||||
{ sh: [
|
||||
'-c adb shell rm -r /' + remotePath + '/webapps',
|
||||
'-c adb shell rm //data/local/user.js',
|
||||
'-c adb push "' + profileFolder + '/webapps" /' + remotePath +
|
||||
'/webapps',
|
||||
'-c adb push "' + profileFolder +
|
||||
'/user.js" //data/local/user.js',
|
||||
'-c adb push "' + profileFolder +
|
||||
'/indexedDB" //data/local/indexedDB']
|
||||
}
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('installSvoperapps', function(done) {
|
||||
var queue = app.installSvoperapps(profileFolder, 'adb');
|
||||
queue.done(function() {
|
||||
assert.deepEqual(mockUtils.hasRunCommands, {
|
||||
sh: [
|
||||
'-c adb shell rm -r //data/local/svoperapps',
|
||||
'-c adb push "' + profileFolder +
|
||||
'/svoperapps" //data/local/svoperapps'
|
||||
]
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('execute', function() {
|
||||
var options;
|
||||
var appID;
|
||||
setup(function() {
|
||||
options = {
|
||||
ADB: 'adb',
|
||||
GAIA_DIR: 'testGaia',
|
||||
PROFILE_DIR: 'testProfileFolder',
|
||||
GAIA_INSTALL_PARENT: '/system/b2g',
|
||||
GAIA_DOMAIN: 'testDomain',
|
||||
DEFAULT_KEYBOAD_SYMBOLS_FONT:
|
||||
'shared/style/keyboard_symbols/Keyboard-Symbols.ttf',
|
||||
DEFAULT_GAIA_ICONS_FONT:
|
||||
'shared/elements/gaia-icons/fonts/gaia-icons.ttf'
|
||||
};
|
||||
appID = '999';
|
||||
mockUtils.getFile = function() {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
var path = args.join('/');
|
||||
var profileExists = (path === options.PROFILE_DIR);
|
||||
return {
|
||||
exists: function() {
|
||||
return profileExists;
|
||||
},
|
||||
isDirectory: function() {
|
||||
return profileExists;
|
||||
},
|
||||
path: options.PROFILE_DIR
|
||||
};
|
||||
};
|
||||
mockUtils.readZipManifest = function() {
|
||||
return {
|
||||
name: options.BUILD_APP_NAME
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
test('execute, test it without assigning app name', function(done) {
|
||||
options.BUILD_APP_NAME = '*';
|
||||
var queue = app.execute(options);
|
||||
queue.done(function() {
|
||||
assert.deepEqual(mockUtils.hasRunCommands, {
|
||||
sh: [
|
||||
'-c adb start-server',
|
||||
'-c adb wait-for-device',
|
||||
'-c adb shell stop b2g',
|
||||
'-c adb shell rm -r //cache/*',
|
||||
'-c adb remount',
|
||||
'-c adb shell rm -r /' + options.GAIA_INSTALL_PARENT +
|
||||
'/webapps',
|
||||
'-c adb shell rm //data/local/user.js',
|
||||
'-c adb push "' + options.PROFILE_DIR + '/webapps"' +
|
||||
' //system/b2g/webapps',
|
||||
'-c adb push "' + options.PROFILE_DIR + '/user.js"' +
|
||||
' //data/local/user.js',
|
||||
'-c adb push "shared/elements/gaia-icons/fonts/gaia-icons.ttf"' +
|
||||
' //system/fonts/hidden/gaia-icons.ttf',
|
||||
'-c adb push "shared/style/keyboard_symbols/Keyboard-Symbols.ttf"' +
|
||||
' //system/fonts/hidden/Keyboard-Symbols.ttf',
|
||||
'-c adb shell start b2g']});
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('execute, test it with testApp as an app name', function(done) {
|
||||
options.BUILD_APP_NAME = 'testApp';
|
||||
mockUtils.psParser = function() {
|
||||
var pidMap = {};
|
||||
pidMap[options.BUILD_APP_NAME] = {
|
||||
PID: appID
|
||||
};
|
||||
return pidMap;
|
||||
};
|
||||
var queue = app.execute(options);
|
||||
queue.done(function() {
|
||||
assert.deepEqual(mockUtils.hasRunCommands, {
|
||||
sh: [
|
||||
'-c adb start-server',
|
||||
'-c adb wait-for-device',
|
||||
'-c adb shell rm -r //cache/*',
|
||||
'-c adb remount',
|
||||
'-c adb push "' + options.PROFILE_DIR + '/webapps/' +
|
||||
options.BUILD_APP_NAME + '.' + options.GAIA_DOMAIN +
|
||||
'/manifest.webapp" //data/local/tmp/pushgaia/' +
|
||||
options.BUILD_APP_NAME + '.' + options.GAIA_DOMAIN +
|
||||
'/manifest.webapp',
|
||||
'-c adb push "' + options.PROFILE_DIR + '/webapps/' +
|
||||
options.BUILD_APP_NAME + '.' + options.GAIA_DOMAIN +
|
||||
'/application.zip" //data/local/tmp/pushgaia/' +
|
||||
options.BUILD_APP_NAME + '.' + options.GAIA_DOMAIN +
|
||||
'/application.zip',
|
||||
'-c adb shell "cat /data/local/tmp/pushgaia/' +
|
||||
options.BUILD_APP_NAME + '.' + options.GAIA_DOMAIN +
|
||||
'/manifest.webapp > ' + options.GAIA_INSTALL_PARENT +
|
||||
'/webapps/' + options.BUILD_APP_NAME + '.' +
|
||||
options.GAIA_DOMAIN + '/manifest.webapp"',
|
||||
'-c adb shell "cat /data/local/tmp/pushgaia/' +
|
||||
options.BUILD_APP_NAME + '.' + options.GAIA_DOMAIN +
|
||||
'/application.zip > ' + options.GAIA_INSTALL_PARENT +
|
||||
'/webapps/' + options.BUILD_APP_NAME + '.' +
|
||||
options.GAIA_DOMAIN + '/application.zip"',
|
||||
'-c adb shell rm -rf //data/local/tmp/pushgaia',
|
||||
'-c adb shell kill testApp']});
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('getRemoteInstallPath', function() {
|
||||
test('Return /system/b2g if no profile on device', function() {
|
||||
var realGetJSON = mockUtils.getJSON;
|
||||
mockUtils.getJSON = function(file) {
|
||||
// getJSON should throw in this case because the content of the
|
||||
// tempFile will be an adb error message.
|
||||
return JSON.parse(
|
||||
'remote object \'' + file.path + '\' does not exist');
|
||||
};
|
||||
var path = app.getRemoteInstallPath('adb');
|
||||
assert.equal(path, '/system/b2g');
|
||||
|
||||
mockUtils.getJSON = realGetJSON;
|
||||
});
|
||||
test('Return /data/local if no app was installed on /system/b2g',
|
||||
function() {
|
||||
var realGetJSON = mockUtils.getJSON;
|
||||
mockUtils.getJSON = function(file) {
|
||||
return {
|
||||
'app1.gaiamobile.org': {
|
||||
'basePath': '/data/local/webapps'
|
||||
},
|
||||
'app2.gaiamobile.org': {
|
||||
'basePath': '/data/local/webapps'
|
||||
},
|
||||
'app3.gaiamobile.org': {
|
||||
'basePath': '/data/local/webapps'
|
||||
}
|
||||
};
|
||||
};
|
||||
var path = app.getRemoteInstallPath('adb');
|
||||
assert.equal(path, '/data/local');
|
||||
|
||||
mockUtils.getJSON = realGetJSON;
|
||||
});
|
||||
test('Return /system/b2g if any app was installed there', function() {
|
||||
var realGetJSON = mockUtils.getJSON;
|
||||
mockUtils.getJSON = function(file) {
|
||||
return {
|
||||
'app1.gaiamobile.org': {
|
||||
'basePath': '/data/local/webapps'
|
||||
},
|
||||
'app2.gaiamobile.org': {
|
||||
'basePath': '/system/b2g/webapps'
|
||||
},
|
||||
'app3.gaiamobile.org': {
|
||||
'basePath': '/system/b2g/webapps'
|
||||
}
|
||||
};
|
||||
};
|
||||
var path = app.getRemoteInstallPath('adb');
|
||||
assert.equal(path, '/system/b2g');
|
||||
|
||||
mockUtils.getJSON = realGetJSON;
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
82
gaia/build/test/unit/rebuild_test.js
Executable file
82
gaia/build/test/unit/rebuild_test.js
Executable file
|
|
@ -0,0 +1,82 @@
|
|||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire');
|
||||
var mockUtils = require('./mock_utils.js');
|
||||
|
||||
suite('rebuild.js', function() {
|
||||
var rebuild;
|
||||
var appDirs = ['path/to/app1'];
|
||||
var files = [
|
||||
{ path: 'path/to/app1/app1.js', lastModifiedTime: 1 },
|
||||
{ path: 'path/to/app1/test/app1_test.js', lastModifiedTime: 2 },
|
||||
{ path: 'path/to/app1/.jshintrc', lastModifiedTime: 3 },
|
||||
{ path: '.gitignore', lastModifiedTime: 4 }
|
||||
];
|
||||
var config = {
|
||||
'rebuildBlacklist': []
|
||||
};
|
||||
|
||||
setup(function() {
|
||||
var stubs = {
|
||||
'./utils': mockUtils,
|
||||
'./config/build-config.json': config
|
||||
};
|
||||
rebuild = proxyquire.noCallThru().load('../../rebuild', stubs);
|
||||
|
||||
mockUtils.getFile = function() {
|
||||
var path = Array.prototype.slice.call(arguments, 0).join('/');
|
||||
return {
|
||||
path: path,
|
||||
leafName: path.split('/').pop(),
|
||||
exists: function() { return true; },
|
||||
isDirectory: function() { return true; }
|
||||
};
|
||||
};
|
||||
|
||||
mockUtils.ls = function() {
|
||||
return files;
|
||||
};
|
||||
|
||||
mockUtils.relativePath = function(from, to) {
|
||||
return to.slice(from.length + 1);
|
||||
};
|
||||
|
||||
mockUtils.getFileContent = function() {
|
||||
return '';
|
||||
};
|
||||
});
|
||||
|
||||
test('getTimestamp', function() {
|
||||
var expected = {
|
||||
'path/to/app1': {
|
||||
'app1.js': 1,
|
||||
'test/app1_test.js': 2
|
||||
}
|
||||
};
|
||||
assert.deepEqual(expected, rebuild.getTimestamp(appDirs));
|
||||
});
|
||||
|
||||
test('isFileWatched', function() {
|
||||
var expected = [
|
||||
{ path: 'path/to/app1/app1.js', lastModifiedTime: 1 },
|
||||
{ path: 'path/to/app1/test/app1_test.js', lastModifiedTime: 2 }
|
||||
];
|
||||
assert.deepEqual(expected, files.filter(rebuild.isFileWatched));
|
||||
});
|
||||
|
||||
test('dirChanged', function() {
|
||||
var prev = {
|
||||
'path/to/app1/file1': 1,
|
||||
'path/to/app1/file2': 2,
|
||||
'path/to/app1/file3': 3
|
||||
};
|
||||
var current = {
|
||||
'path/to/app1/file1': 5,
|
||||
'path/to/app1/file2': 2,
|
||||
'path/to/app1/file3': 3
|
||||
};
|
||||
assert.equal(false, rebuild.dirChanged(prev, prev, 'app1'));
|
||||
assert.equal(true, rebuild.dirChanged(prev, current, 'app1'));
|
||||
});
|
||||
});
|
||||
572
gaia/build/test/unit/settings_test.js
Executable file
572
gaia/build/test/unit/settings_test.js
Executable file
|
|
@ -0,0 +1,572 @@
|
|||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire');
|
||||
var mockUtils = require('./mock_utils.js');
|
||||
|
||||
suite('settings.js', function() {
|
||||
var app;
|
||||
setup(function() {
|
||||
app = proxyquire.noCallThru().load(
|
||||
'../../settings', {
|
||||
'./utils': mockUtils
|
||||
});
|
||||
mockUtils.getFileContent = function(file) {
|
||||
return file;
|
||||
};
|
||||
mockUtils.getFileAsDataURI = function(file) {
|
||||
return file.path;
|
||||
};
|
||||
});
|
||||
suite('setWallpaper, setRingtone, setNotification, overrideSettings, ' +
|
||||
'setHomescreenURL and writeSettings',
|
||||
function() {
|
||||
var config;
|
||||
var settings = {};
|
||||
var jpgLink;
|
||||
setup(function() {
|
||||
config = {
|
||||
GAIA_DISTRIBUTION_DIR: 'testDistributionDir',
|
||||
GAIA_DIR: 'testGaia',
|
||||
SETTINGS_PATH: 'testSettingsPath',
|
||||
STAGE_DIR: 'testStageDir',
|
||||
PROFILE_DIR: 'testProfileDir'
|
||||
};
|
||||
mockUtils.resolve = function(file, baseLink) {
|
||||
var fileExist = false;
|
||||
if (file === jpgLink && baseLink === config.GAIA_DIR) {
|
||||
fileExist = true;
|
||||
}
|
||||
return {
|
||||
exists: function() {
|
||||
return fileExist;
|
||||
},
|
||||
path: baseLink + '/' + file
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
test('setWallpaper, GAIA_DEV_PIXELS_PER_PX is not 1 and use default.jpg',
|
||||
function () {
|
||||
config.GAIA_DEV_PIXELS_PER_PX = '3';
|
||||
jpgLink = config.GAIA_DISTRIBUTION_DIR + '/wallpapers/default@' +
|
||||
config.GAIA_DEV_PIXELS_PER_PX + 'x.jpg';
|
||||
|
||||
app.setWallpaper(settings, config);
|
||||
assert.equal(settings['wallpaper.image'], config.GAIA_DIR + '/' +
|
||||
jpgLink);
|
||||
});
|
||||
|
||||
test('setWallpaper, when GAIA_DEV_PIXELS_PER_PX is 1 and use default.jpg',
|
||||
function () {
|
||||
config.GAIA_DEV_PIXELS_PER_PX = '1';
|
||||
jpgLink = config.GAIA_DISTRIBUTION_DIR + '/wallpapers/default.jpg';
|
||||
|
||||
app.setWallpaper(settings, config);
|
||||
assert.equal(settings['wallpaper.image'], config.GAIA_DIR + '/' +
|
||||
jpgLink);
|
||||
});
|
||||
|
||||
test('setWallpaper, when GAIA_DEV_PIXELS_PER_PX is 1 and use wallpaper.jpg',
|
||||
function () {
|
||||
config.GAIA_DEV_PIXELS_PER_PX = '1';
|
||||
jpgLink = 'build/config/wallpaper.jpg';
|
||||
|
||||
app.setWallpaper(settings, config);
|
||||
assert.equal(settings['wallpaper.image'], config.GAIA_DIR + '/' +
|
||||
jpgLink);
|
||||
});
|
||||
|
||||
test('setWallpaper, GAIA_DEV_PIXELS_PER_PX is null and use wallpaper.jpg',
|
||||
function () {
|
||||
config.GAIA_DEV_PIXELS_PER_PX = '';
|
||||
jpgLink = 'build/config/wallpaper.jpg';
|
||||
|
||||
app.setWallpaper(settings, config);
|
||||
assert.equal(settings['wallpaper.image'], config.GAIA_DIR + '/' +
|
||||
jpgLink);
|
||||
});
|
||||
|
||||
test('setMediatone', function () {
|
||||
var mediatoneLink =
|
||||
'shared/resources/media/notifications/' +
|
||||
'notifier_firefox.opus';
|
||||
app.setMediatone(settings, config);
|
||||
assert.equal(settings['media.ringtone'], config.GAIA_DIR + '/' +
|
||||
mediatoneLink);
|
||||
});
|
||||
|
||||
test('setAlarmtone', function () {
|
||||
var alarmtoneLink =
|
||||
'shared/resources/media/alarms/' +
|
||||
'ac_awake.opus';
|
||||
app.setAlarmtone(settings, config);
|
||||
assert.equal(settings['alarm.ringtone'], config.GAIA_DIR + '/' +
|
||||
alarmtoneLink);
|
||||
});
|
||||
|
||||
test('setRingtone', function () {
|
||||
var ringtoneLink =
|
||||
'shared/resources/media/ringtones/' +
|
||||
'ringer_firefox.opus';
|
||||
app.setRingtone(settings, config);
|
||||
assert.equal(settings['dialer.ringtone'], config.GAIA_DIR + '/' +
|
||||
ringtoneLink);
|
||||
assert.deepEqual(settings['dialer.ringtone.name'],
|
||||
{l10nID: 'ringer_firefox2'});
|
||||
assert.equal(settings['dialer.ringtone.id'],
|
||||
'builtin:ringtone/ringer_firefox');
|
||||
assert.equal(settings['dialer.ringtone.default.id'],
|
||||
'builtin:ringtone/ringer_firefox');
|
||||
});
|
||||
|
||||
test('setNotification', function () {
|
||||
var notificationLink =
|
||||
'shared/resources/media/notifications/' +
|
||||
'notifier_firefox.opus';
|
||||
mockUtils.resolve = function(file, baseLink) {
|
||||
return {
|
||||
path: baseLink + '/' + file
|
||||
};
|
||||
};
|
||||
app.setNotification(settings, config);
|
||||
assert.equal(settings['notification.ringtone'],
|
||||
config.GAIA_DIR + '/' + notificationLink);
|
||||
assert.deepEqual(settings['notification.ringtone.name'],
|
||||
{l10nID: 'notifier_firefox2'});
|
||||
assert.equal(settings['notification.ringtone.id'],
|
||||
'builtin:alerttone/notifier_firefox');
|
||||
assert.equal(settings['notification.ringtone.default.id'],
|
||||
'builtin:alerttone/notifier_firefox');
|
||||
});
|
||||
|
||||
test('overrideSettings', function () {
|
||||
var testResult = {
|
||||
'testConfig': ''
|
||||
};
|
||||
mockUtils.resolve = function(file, baseLink) {
|
||||
testResult.testConfig = baseLink + '/' + file;
|
||||
return {
|
||||
path: testResult.testConfig,
|
||||
exists: function() {
|
||||
if (file === config.SETTINGS_PATH &&
|
||||
baseLink === config.GAIA_DIR) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
};
|
||||
mockUtils.getJSON = function(json) {
|
||||
return testResult;
|
||||
};
|
||||
app.overrideSettings(settings, config);
|
||||
assert.equal(settings.testConfig,
|
||||
testResult.testConfig);
|
||||
});
|
||||
|
||||
test('deviceTypeSettings', function () {
|
||||
var testResult = {
|
||||
'testConfig': 'abc'
|
||||
};
|
||||
mockUtils.getFile = function() {
|
||||
return {
|
||||
exists: function() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
};
|
||||
mockUtils.getJSON = function(json) {
|
||||
return testResult;
|
||||
};
|
||||
app.deviceTypeSettings(settings, config);
|
||||
assert.equal(settings.testConfig,
|
||||
testResult.testConfig);
|
||||
});
|
||||
|
||||
test('writeSettings', function () {
|
||||
var settingsFile = { result: '' };
|
||||
var settings = { 'testKey': 'testValue' };
|
||||
mockUtils.getFile = function() {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
return {
|
||||
path: args.join('/'),
|
||||
append: function() {}
|
||||
};
|
||||
};
|
||||
mockUtils.writeContent = function(target, string) {
|
||||
if (target.path === config.PROFILE_DIR + '/settings.json') {
|
||||
settingsFile.result = string;
|
||||
}
|
||||
};
|
||||
app.writeSettings(settings, config);
|
||||
assert.deepEqual(JSON.parse(settingsFile.result), settings);
|
||||
});
|
||||
|
||||
test('setHomescreenURL with default homescreen', function() {
|
||||
config.GAIA_SCHEME = 'app://';
|
||||
config.GAIA_DOMAIN = 'gaiamobile.com';
|
||||
config.GAIA_PORT = ':8080';
|
||||
var settings = {};
|
||||
var testResult = mockUtils.gaiaManifestURL('homescreen',
|
||||
config.GAIA_SCHEME, config.GAIA_DOMAIN, config.GAIA_PORT);
|
||||
app.setHomescreenURL(settings, config);
|
||||
assert.equal(settings['homescreen.manifestURL'], testResult);
|
||||
});
|
||||
|
||||
test('setHomescreenURL with customizable', function() {
|
||||
config.GAIA_APPDIRS = 'homescreen system sms';
|
||||
config.GAIA_SCHEME = 'app://';
|
||||
config.GAIA_DOMAIN = 'gaiamobile.com';
|
||||
config.GAIA_PORT = ':8080';
|
||||
var settings = { 'homescreen.appName': 'homescreen' };
|
||||
var testResult = mockUtils.gaiaManifestURL('homescreen',
|
||||
config.GAIA_SCHEME, config.GAIA_DOMAIN, config.GAIA_PORT);
|
||||
app.setHomescreenURL(settings, config);
|
||||
assert.equal(settings['homescreen.manifestURL'], testResult);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
suite('execute', function() {
|
||||
var config;
|
||||
setup(function() {
|
||||
config = {
|
||||
GAIA_DISTRIBUTION_DIR: 'testDistributionDir',
|
||||
GAIA_DIR: 'testGaia',
|
||||
SETTINGS_PATH: 'testSettingsPath',
|
||||
GAIA_SCHEME: 'testScheme',
|
||||
GAIA_PORT: '9999',
|
||||
GAIA_DEFAULT_LOCALE: 'testLocale',
|
||||
REMOTE_DEBUGGER: '1',
|
||||
GAIA_DOMAIN: 'testDomain'
|
||||
};
|
||||
mockUtils.getFileAsDataURI = function() {
|
||||
return undefined;
|
||||
};
|
||||
mockUtils.getFile = function() {
|
||||
return {
|
||||
exists: function() {
|
||||
return true;
|
||||
},
|
||||
append: function() {}
|
||||
};
|
||||
};
|
||||
mockUtils.getJSON = function(json) {
|
||||
return {};
|
||||
};
|
||||
});
|
||||
|
||||
test('TARGET_BUILD_VARIANT != user', function(done) {
|
||||
config.TARGET_BUILD_VARIANT = 'notuser';
|
||||
var queue = app.execute(config);
|
||||
var expected = {
|
||||
'debug.console.enabled': true,
|
||||
'metrics.selectedMetrics.level': 'Basic',
|
||||
'developer.menu.enabled': true,
|
||||
'homescreen.manifestURL': config.GAIA_SCHEME +
|
||||
'homescreen.' + config.GAIA_DOMAIN + config.GAIA_PORT +
|
||||
'/manifest.webapp',
|
||||
'rocketbar.newTabAppURL': config.GAIA_SCHEME + 'search.' +
|
||||
config.GAIA_DOMAIN + config.GAIA_PORT + '/index.html',
|
||||
'rocketbar.searchAppURL': config.GAIA_SCHEME + 'search.' +
|
||||
config.GAIA_DOMAIN + config.GAIA_PORT + '/index.html',
|
||||
'debugger.remote-mode': 'adb-only',
|
||||
'language.current': config.GAIA_DEFAULT_LOCALE,
|
||||
'wallpaper.image': undefined,
|
||||
'media.ringtone': undefined,
|
||||
'alarm.ringtone': undefined,
|
||||
'dialer.ringtone.name': {l10nID: 'ringer_firefox2'},
|
||||
'dialer.ringtone.id': 'builtin:ringtone/ringer_firefox',
|
||||
'dialer.ringtone.default.id': 'builtin:ringtone/ringer_firefox',
|
||||
'dialer.ringtone': undefined,
|
||||
'notification.ringtone.name': {l10nID: 'notifier_firefox2'},
|
||||
'notification.ringtone.id': 'builtin:alerttone/notifier_firefox',
|
||||
'notification.ringtone.default.id':
|
||||
'builtin:alerttone/notifier_firefox',
|
||||
'notification.ringtone': undefined,
|
||||
'ftu.pingURL': config.FTU_PING_URL
|
||||
};
|
||||
queue.done(function(result) {
|
||||
assert.deepEqual(expected, result,
|
||||
'these two objects should be the same: \n' +
|
||||
'expected: \n' + JSON.stringify(expected, null, 2) + '\n' +
|
||||
'actually: \n' + JSON.stringify(result, null, 2) + '\n');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('NOFTU === 0', function(done) {
|
||||
config.NOFTU = '0';
|
||||
config.TARGET_BUILD_VARIANT = 'user';
|
||||
var queue = app.execute(config);
|
||||
queue.done(function(result) {
|
||||
assert.deepEqual({
|
||||
'homescreen.manifestURL': config.GAIA_SCHEME +
|
||||
'homescreen.' + config.GAIA_DOMAIN + config.GAIA_PORT +
|
||||
'/manifest.webapp',
|
||||
'rocketbar.newTabAppURL': config.GAIA_SCHEME + 'search.' +
|
||||
config.GAIA_DOMAIN + config.GAIA_PORT + '/index.html',
|
||||
'rocketbar.searchAppURL': config.GAIA_SCHEME + 'search.' +
|
||||
config.GAIA_DOMAIN + config.GAIA_PORT + '/index.html',
|
||||
'language.current': config.GAIA_DEFAULT_LOCALE,
|
||||
'debugger.remote-mode': 'adb-only',
|
||||
'ftu.manifestURL': config.GAIA_SCHEME +
|
||||
'ftu.' + config.GAIA_DOMAIN + config.GAIA_PORT +
|
||||
'/manifest.webapp',
|
||||
'wallpaper.image': undefined,
|
||||
'media.ringtone': undefined,
|
||||
'alarm.ringtone': undefined,
|
||||
'dialer.ringtone.name': {l10nID: 'ringer_firefox2'},
|
||||
'dialer.ringtone.id': 'builtin:ringtone/ringer_firefox',
|
||||
'dialer.ringtone.default.id': 'builtin:ringtone/ringer_firefox',
|
||||
'dialer.ringtone': undefined,
|
||||
'notification.ringtone.name': {l10nID: 'notifier_firefox2'},
|
||||
'notification.ringtone.id': 'builtin:alerttone/notifier_firefox',
|
||||
'notification.ringtone.default.id':
|
||||
'builtin:alerttone/notifier_firefox',
|
||||
'notification.ringtone': undefined,
|
||||
'ftu.pingURL': config.FTU_PING_URL,
|
||||
'metrics.selectedMetrics.level': 'Basic' },
|
||||
result);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('PRODUCTION === 1', function(done) {
|
||||
config.PRODUCTION = '1';
|
||||
config.TARGET_BUILD_VARIANT = 'user';
|
||||
var queue = app.execute(config);
|
||||
queue.done(function(result) {
|
||||
assert.equal(Object.keys(result)
|
||||
.indexOf('dom.mozApps.signed_apps_installable_from'), -1);
|
||||
assert.deepEqual({
|
||||
'homescreen.manifestURL': config.GAIA_SCHEME +
|
||||
'homescreen.' + config.GAIA_DOMAIN + config.GAIA_PORT +
|
||||
'/manifest.webapp',
|
||||
'rocketbar.newTabAppURL': config.GAIA_SCHEME + 'search.' +
|
||||
config.GAIA_DOMAIN + config.GAIA_PORT + '/index.html',
|
||||
'rocketbar.searchAppURL': config.GAIA_SCHEME + 'search.' +
|
||||
config.GAIA_DOMAIN + config.GAIA_PORT + '/index.html',
|
||||
'feedback.url': 'https://input.mozilla.org/api/v1/feedback/',
|
||||
'gaia.system.checkForUpdates': true,
|
||||
'language.current': config.GAIA_DEFAULT_LOCALE,
|
||||
'debugger.remote-mode': 'disabled',
|
||||
'wallpaper.image': undefined,
|
||||
'media.ringtone': undefined,
|
||||
'alarm.ringtone': undefined,
|
||||
'dialer.ringtone.name': {l10nID: 'ringer_firefox2'},
|
||||
'dialer.ringtone.id': 'builtin:ringtone/ringer_firefox',
|
||||
'dialer.ringtone.default.id': 'builtin:ringtone/ringer_firefox',
|
||||
'dialer.ringtone': undefined,
|
||||
'notification.ringtone.name': {l10nID: 'notifier_firefox2'},
|
||||
'notification.ringtone.id': 'builtin:alerttone/notifier_firefox',
|
||||
'notification.ringtone.default.id':
|
||||
'builtin:alerttone/notifier_firefox',
|
||||
'notification.ringtone': undefined,
|
||||
'ftu.pingURL': config.FTU_PING_URL,
|
||||
'metrics.selectedMetrics.level': 'Basic' },
|
||||
result);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('PRODUCTION === 0', function(done) {
|
||||
config.PRODUCTION = '0';
|
||||
config.TARGET_BUILD_VARIANT = 'user';
|
||||
var settingName = 'dom.mozApps.signed_apps_installable_from';
|
||||
var marketplaceProd = 'https://marketplace.firefox.com';
|
||||
var marketplaceStage = 'https://marketplace.allizom.org';
|
||||
var queue = app.execute(config);
|
||||
queue.done(function(result) {
|
||||
var originsSetting = Object.keys(result);
|
||||
assert.ok(originsSetting.indexOf(settingName) >= 0);
|
||||
var origins = result[settingName].split(',');
|
||||
assert.equal(origins.length, 2);
|
||||
assert.ok(origins.indexOf(marketplaceProd) >= 0);
|
||||
assert.ok(origins.indexOf(marketplaceStage) >= 0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('DOGFOOD === 1', function(done) {
|
||||
config.DOGFOOD = '1';
|
||||
config.TARGET_BUILD_VARIANT = 'user';
|
||||
var queue = app.execute(config);
|
||||
queue.done(function(result) {
|
||||
assert.equal(Object.keys(result)
|
||||
.indexOf('dom.mozApps.signed_apps_installable_from'), -1);
|
||||
assert.deepEqual({
|
||||
'homescreen.manifestURL': config.GAIA_SCHEME +
|
||||
'homescreen.' + config.GAIA_DOMAIN + config.GAIA_PORT +
|
||||
'/manifest.webapp',
|
||||
'rocketbar.newTabAppURL': config.GAIA_SCHEME + 'search.' +
|
||||
config.GAIA_DOMAIN + config.GAIA_PORT + '/index.html',
|
||||
'rocketbar.searchAppURL': config.GAIA_SCHEME + 'search.' +
|
||||
config.GAIA_DOMAIN + config.GAIA_PORT + '/index.html',
|
||||
'language.current': config.GAIA_DEFAULT_LOCALE,
|
||||
'debugger.remote-mode': 'adb-only',
|
||||
'wallpaper.image': undefined,
|
||||
'media.ringtone': undefined,
|
||||
'alarm.ringtone': undefined,
|
||||
'dialer.ringtone.name': {l10nID: 'ringer_firefox2'},
|
||||
'dialer.ringtone.id': 'builtin:ringtone/ringer_firefox',
|
||||
'dialer.ringtone.default.id': 'builtin:ringtone/ringer_firefox',
|
||||
'dialer.ringtone': undefined,
|
||||
'notification.ringtone.name': {l10nID: 'notifier_firefox2'},
|
||||
'notification.ringtone.id': 'builtin:alerttone/notifier_firefox',
|
||||
'notification.ringtone.default.id':
|
||||
'builtin:alerttone/notifier_firefox',
|
||||
'notification.ringtone': undefined,
|
||||
'ftu.pingURL': config.FTU_PING_URL,
|
||||
'debug.performance_data.dogfooding': true,
|
||||
'devtools.overlay': true,
|
||||
'hud.hide': true,
|
||||
'metrics.appusage.reportInterval': 86400000,
|
||||
'metrics.selectedMetrics.level': 'Enhanced' },
|
||||
result);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('DEVICE_DEBUG === 1', function(done) {
|
||||
config.DEVICE_DEBUG = '1';
|
||||
config.NO_LOCK_SCREEN = '1';
|
||||
config.TARGET_BUILD_VARIANT = 'user';
|
||||
var queue = app.execute(config);
|
||||
queue.done(function(result) {
|
||||
assert.deepEqual({
|
||||
'homescreen.manifestURL': config.GAIA_SCHEME +
|
||||
'homescreen.' + config.GAIA_DOMAIN + config.GAIA_PORT +
|
||||
'/manifest.webapp',
|
||||
'rocketbar.newTabAppURL': config.GAIA_SCHEME + 'search.' +
|
||||
config.GAIA_DOMAIN + config.GAIA_PORT + '/index.html',
|
||||
'rocketbar.searchAppURL': config.GAIA_SCHEME + 'search.' +
|
||||
config.GAIA_DOMAIN + config.GAIA_PORT + '/index.html',
|
||||
'language.current': config.GAIA_DEFAULT_LOCALE,
|
||||
'debugger.remote-mode': 'adb-devtools',
|
||||
'lockscreen.enabled': false,
|
||||
'lockscreen.locked': false,
|
||||
'wallpaper.image': undefined,
|
||||
'media.ringtone': undefined,
|
||||
'alarm.ringtone': undefined,
|
||||
'dialer.ringtone.name': {l10nID: 'ringer_firefox2'},
|
||||
'dialer.ringtone.id': 'builtin:ringtone/ringer_firefox',
|
||||
'dialer.ringtone.default.id': 'builtin:ringtone/ringer_firefox',
|
||||
'dialer.ringtone': undefined,
|
||||
'notification.ringtone.name': {l10nID: 'notifier_firefox2'},
|
||||
'notification.ringtone.id': 'builtin:alerttone/notifier_firefox',
|
||||
'notification.ringtone.default.id':
|
||||
'builtin:alerttone/notifier_firefox',
|
||||
'notification.ringtone': undefined,
|
||||
'ftu.pingURL': config.FTU_PING_URL,
|
||||
'metrics.selectedMetrics.level': 'Basic' },
|
||||
result);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('SCREEN_TIMEOUT === 600', function(done) {
|
||||
config.DEVICE_DEBUG = '1';
|
||||
config.SCREEN_TIMEOUT = '600';
|
||||
config.TARGET_BUILD_VARIANT = 'user';
|
||||
var queue = app.execute(config);
|
||||
queue.done(function(result) {
|
||||
assert.deepEqual({
|
||||
'homescreen.manifestURL': config.GAIA_SCHEME +
|
||||
'homescreen.' + config.GAIA_DOMAIN + config.GAIA_PORT +
|
||||
'/manifest.webapp',
|
||||
'rocketbar.newTabAppURL': config.GAIA_SCHEME + 'search.' +
|
||||
config.GAIA_DOMAIN + config.GAIA_PORT + '/index.html',
|
||||
'rocketbar.searchAppURL': config.GAIA_SCHEME + 'search.' +
|
||||
config.GAIA_DOMAIN + config.GAIA_PORT + '/index.html',
|
||||
'language.current': config.GAIA_DEFAULT_LOCALE,
|
||||
'debugger.remote-mode': 'adb-devtools',
|
||||
'wallpaper.image': undefined,
|
||||
'media.ringtone': undefined,
|
||||
'alarm.ringtone': undefined,
|
||||
'dialer.ringtone.name': {l10nID: 'ringer_firefox2'},
|
||||
'dialer.ringtone.id': 'builtin:ringtone/ringer_firefox',
|
||||
'dialer.ringtone.default.id': 'builtin:ringtone/ringer_firefox',
|
||||
'dialer.ringtone': undefined,
|
||||
'notification.ringtone.name': {l10nID: 'notifier_firefox2'},
|
||||
'notification.ringtone.id': 'builtin:alerttone/notifier_firefox',
|
||||
'notification.ringtone.default.id':
|
||||
'builtin:alerttone/notifier_firefox',
|
||||
'notification.ringtone': undefined,
|
||||
'ftu.pingURL': config.FTU_PING_URL,
|
||||
'screen.timeout': 600,
|
||||
'metrics.selectedMetrics.level': 'Basic' },
|
||||
result);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
config = {};
|
||||
});
|
||||
});
|
||||
|
||||
suite('setDefaultKeyboardLayouts', function() {
|
||||
var config;
|
||||
var settings = {};
|
||||
var defaultManifestURL = 'app://keyboard.gaiamobile.org/manifest.webapp';
|
||||
var expectedLayouts = {};
|
||||
expectedLayouts[defaultManifestURL] = {en: true, number: true};
|
||||
|
||||
setup(function() {
|
||||
config = {
|
||||
GAIA_DISTRIBUTION_DIR: 'testDistributionDir',
|
||||
GAIA_DIR: 'testGaia',
|
||||
SETTINGS_PATH: 'testSettingsPath'
|
||||
};
|
||||
mockUtils.resolve = function(file, baseLink) {
|
||||
return {
|
||||
exists: function() {
|
||||
return true;
|
||||
},
|
||||
path: baseLink + '/' + file
|
||||
};
|
||||
};
|
||||
|
||||
mockUtils.getJSON = function() {
|
||||
return {
|
||||
'layout': {
|
||||
'en-US': [
|
||||
{'layoutId': 'en', 'appManifestURL': defaultManifestURL}
|
||||
],
|
||||
'zh-TW': [
|
||||
{'layoutId': 'zhuyin', 'appManifestURL': defaultManifestURL},
|
||||
{'layoutId': 'en', 'appManifestURL': defaultManifestURL}
|
||||
]
|
||||
},
|
||||
'langIndependentLayouts':
|
||||
[{'layoutId': 'number', 'appManifestURL': defaultManifestURL}]
|
||||
};
|
||||
|
||||
};
|
||||
});
|
||||
|
||||
test('Set default keyboard layouts, lang = en-US', function() {
|
||||
app.setDefaultKeyboardLayouts('en-US', settings, config);
|
||||
assert.deepEqual(settings['keyboard.enabled-layouts'],
|
||||
expectedLayouts);
|
||||
});
|
||||
|
||||
test('Set default keyboard layouts, lang = zh-TW', function() {
|
||||
app.setDefaultKeyboardLayouts('zh-TW', settings, config);
|
||||
|
||||
var expectedLayoutsChinese = {};
|
||||
expectedLayoutsChinese[defaultManifestURL] = {zhuyin: true, en: true,
|
||||
number: true};
|
||||
assert.deepEqual(settings['keyboard.enabled-layouts'],
|
||||
expectedLayoutsChinese);
|
||||
});
|
||||
|
||||
test('Fall back to default keyboard layouts as en, lang = de', function() {
|
||||
app.setDefaultKeyboardLayouts('de', settings, config);
|
||||
assert.deepEqual(settings['keyboard.enabled-layouts'],
|
||||
expectedLayouts);
|
||||
});
|
||||
});
|
||||
});
|
||||
116
gaia/build/test/unit/utils_test.js
Executable file
116
gaia/build/test/unit/utils_test.js
Executable file
|
|
@ -0,0 +1,116 @@
|
|||
'use strict';
|
||||
|
||||
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));
|
||||
});
|
||||
|
||||
test('isSubjectToDeviceType', 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);
|
||||
});
|
||||
});
|
||||
});
|
||||
206
gaia/build/test/unit/webapp_manifests_test.js
Executable file
206
gaia/build/test/unit/webapp_manifests_test.js
Executable file
|
|
@ -0,0 +1,206 @@
|
|||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire');
|
||||
var mockUtils = require('./mock_utils.js');
|
||||
|
||||
suite('webapp-manifest.js', function() {
|
||||
var app;
|
||||
var fileExists;
|
||||
var writingContent = null;
|
||||
var isExternalApp = false;
|
||||
var mockConfig;
|
||||
var mockWebapp;
|
||||
setup(function() {
|
||||
var fileExists = false;
|
||||
app = proxyquire.noCallThru().load(
|
||||
'../../webapp-manifests', {
|
||||
'./utils': mockUtils
|
||||
});
|
||||
|
||||
mockUtils.getFileContent = function(file) {
|
||||
return file;
|
||||
};
|
||||
|
||||
mockUtils.getFileAsDataURI = function(file) {
|
||||
return file.path;
|
||||
};
|
||||
|
||||
mockUtils.ensureFolderExists = function(filePath) {
|
||||
return fileExists;
|
||||
};
|
||||
|
||||
mockUtils.writeContent = function(file, content) {
|
||||
writingContent = content;
|
||||
};
|
||||
|
||||
mockUtils.generateUUID = function() {
|
||||
return 'tewwtwuuid-1234';
|
||||
};
|
||||
|
||||
mockUtils.getNewURI = function(origin) {
|
||||
return {
|
||||
host: origin + '_host',
|
||||
scheme: origin + '_scheme',
|
||||
prePath: origin
|
||||
};
|
||||
};
|
||||
|
||||
mockUtils.isExternalApp = function(webapp) {
|
||||
return isExternalApp;
|
||||
};
|
||||
|
||||
mockUtils.gaia = {
|
||||
getInstance: function(config) {
|
||||
return config;
|
||||
}
|
||||
};
|
||||
|
||||
mockConfig = {
|
||||
GAIA_DIR: 'testGaiaDir',
|
||||
GAIA_DOMAIN: 'testGaiaDomain',
|
||||
GAIA_PORT: 'testGaiaPort',
|
||||
GAIA_SCHEME: 'testGaiaScheme',
|
||||
stageDir: 'testStageDir'
|
||||
};
|
||||
|
||||
mockWebapp = {
|
||||
url: 'mockWebappUrl',
|
||||
appStatus: 'mockWebappAppStatus',
|
||||
manifest: 'mockWebappManifest',
|
||||
pckManifest: {
|
||||
origin: 'pckManifestOrigin'
|
||||
},
|
||||
metaData: {
|
||||
installOrigin: 'metaDataInstallOrigin',
|
||||
manifestURL: 'metaDataManifestURL',
|
||||
// origin: 'metaDataOrigin',
|
||||
removable: false,
|
||||
etag: 'metaDataEtag',
|
||||
packageEtag: 'metaDataPackageEtag'
|
||||
},
|
||||
sourceDirectoryName: 'sourceDirectoryName',
|
||||
domain: 'domain',
|
||||
profileDirectoryFilePath: 'testuuid'
|
||||
};
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
fileExists = false;
|
||||
isExternalApp = false;
|
||||
writingContent = null;
|
||||
});
|
||||
|
||||
suite('setConfig, genStageWebappJSON, fillExternalAppManifest', function() {
|
||||
var webappManifest;
|
||||
|
||||
setup(function() {
|
||||
webappManifest = new app.ManifestBuilder();
|
||||
mockUtils.getFile = function(path) {
|
||||
return {
|
||||
leafName: path
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
test('setConfig', function() {
|
||||
webappManifest.setConfig(mockConfig);
|
||||
assert.equal(webappManifest.id, 1);
|
||||
assert.equal(webappManifest.stageDir, 'testStageDir');
|
||||
});
|
||||
|
||||
test('genStageWebappJSON ', function() {
|
||||
var testStageManifests = {test: 'test'};
|
||||
var writingFilePath = '';
|
||||
webappManifest.stageManifests = testStageManifests;
|
||||
webappManifest.stageDir = {
|
||||
path: 'test_build_stage'
|
||||
};
|
||||
mockUtils.getFile = function() {
|
||||
for (var i in arguments) {
|
||||
writingFilePath += ('/' + arguments[i]);
|
||||
}
|
||||
};
|
||||
webappManifest.genStageWebappJSON();
|
||||
assert.equal(writingContent,
|
||||
JSON.stringify(testStageManifests, null, 2) + '\n');
|
||||
assert.equal(writingFilePath, '/test_build_stage/webapps_stage.json');
|
||||
mockUtils.getFile = null;
|
||||
});
|
||||
|
||||
test('fillExternalAppManifest', function() {
|
||||
var test_uuid = 'testuuid';
|
||||
webappManifest.INSTALL_TIME = 'INSTALL_TIME';
|
||||
webappManifest.UPDATE_TIME = 'UPDATE_TIME';
|
||||
mockUtils.generateUUID = function() {
|
||||
return test_uuid;
|
||||
};
|
||||
webappManifest.setConfig(mockConfig);
|
||||
webappManifest.fillExternalAppManifest(mockWebapp);
|
||||
|
||||
assert.deepEqual(webappManifest.stageManifests, {
|
||||
'sourceDirectoryName': {
|
||||
originalManifest: mockWebapp.manifest,
|
||||
origin: 'app://' + test_uuid,
|
||||
manifestURL: mockWebapp.metaData.manifestURL,
|
||||
installOrigin: mockWebapp.metaData.installOrigin,
|
||||
receipt: null,
|
||||
installTime: 'INSTALL_TIME',
|
||||
updateTime: 'UPDATE_TIME',
|
||||
removable: mockWebapp.metaData.removable,
|
||||
localId: 1,
|
||||
etag: mockWebapp.metaData.etag,
|
||||
packageEtag: mockWebapp.metaData.packageEtag,
|
||||
appStatus: mockWebapp.appStatus,
|
||||
webappTargetDirName: test_uuid
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test('genManifest, when it is external webapp', function() {
|
||||
isExternalApp = false;
|
||||
webappManifest.INSTALL_TIME = 'INSTALL_TIME';
|
||||
webappManifest.UPDATE_TIME = 'UPDATE_TIME';
|
||||
webappManifest.setConfig(mockConfig);
|
||||
webappManifest.genManifest(mockWebapp);
|
||||
|
||||
assert.deepEqual(webappManifest.stageManifests, {
|
||||
'sourceDirectoryName': {
|
||||
originalManifest: mockWebapp.manifest,
|
||||
origin: mockWebapp.url,
|
||||
manifestURL: mockWebapp.url + '/manifest.webapp',
|
||||
installOrigin: mockWebapp.url,
|
||||
receipt: null,
|
||||
installTime: 'INSTALL_TIME',
|
||||
updateTime: 'UPDATE_TIME',
|
||||
localId: 1,
|
||||
appStatus: mockWebapp.appStatus,
|
||||
webappTargetDirName: mockWebapp.domain
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test('genManifest, when it is not external webapp', function() {
|
||||
isExternalApp = false;
|
||||
webappManifest.INSTALL_TIME = 'INSTALL_TIME';
|
||||
webappManifest.UPDATE_TIME = 'UPDATE_TIME';
|
||||
webappManifest.setConfig(mockConfig);
|
||||
webappManifest.genManifest(mockWebapp);
|
||||
|
||||
assert.deepEqual(webappManifest.stageManifests, {
|
||||
'sourceDirectoryName': {
|
||||
originalManifest: mockWebapp.manifest,
|
||||
origin: mockWebapp.url,
|
||||
manifestURL: mockWebapp.url + '/manifest.webapp',
|
||||
installOrigin: mockWebapp.url,
|
||||
receipt: null,
|
||||
installTime: 'INSTALL_TIME',
|
||||
updateTime: 'UPDATE_TIME',
|
||||
localId: 1,
|
||||
appStatus: mockWebapp.appStatus,
|
||||
webappTargetDirName: mockWebapp.domain
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
501
gaia/build/test/unit/webapp_optimize_test.js
Executable file
501
gaia/build/test/unit/webapp_optimize_test.js
Executable file
|
|
@ -0,0 +1,501 @@
|
|||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire');
|
||||
var path = require('path');
|
||||
var mockUtils = require('./mock_utils.js');
|
||||
var CrossCompatPromise = require('es6-promise').Promise;
|
||||
|
||||
suite('webapp-optimize.js', function() {
|
||||
var app;
|
||||
var mockConfig;
|
||||
var mockJsmin;
|
||||
var mockL20n;
|
||||
var mockFile;
|
||||
var isFileRemoved = false;
|
||||
var removedFilePath = [];
|
||||
var isFileExist = false;
|
||||
var writeFile = null;
|
||||
var writeFileContent = null;
|
||||
var fileChildren = {};
|
||||
var mockDoc;
|
||||
var MockDom;
|
||||
var mockoptimizeConfig;
|
||||
var createdDOMs = [];
|
||||
var modifiedDOMs = [];
|
||||
var hasAttributeFlag = {};
|
||||
var domDataSet = {};
|
||||
var removeDomChildren = [];
|
||||
var isSubjectToBranding = false;
|
||||
setup(function() {
|
||||
mockJsmin = function(content) {
|
||||
return {
|
||||
code: 'minified-' + content
|
||||
};
|
||||
};
|
||||
|
||||
mockL20n = {
|
||||
getView: function() {
|
||||
return {
|
||||
serializeResources: function() {
|
||||
return CrossCompatPromise.resolve(
|
||||
[{$i: 'test-id', $v: 'testIdContent'}]);
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
app = proxyquire.noCallThru().load(
|
||||
'../../webapp-optimize', {
|
||||
'./l10n/l20n': mockL20n,
|
||||
'./utils': mockUtils,
|
||||
'./jsmin': mockJsmin
|
||||
});
|
||||
|
||||
mockFile = {
|
||||
remove: function(recursive) {
|
||||
isFileExist = false;
|
||||
isFileRemoved = true;
|
||||
},
|
||||
exists: function() {
|
||||
return isFileExist;
|
||||
}
|
||||
};
|
||||
|
||||
var getFile = function() {
|
||||
var filePath = path.join.apply(this, arguments);
|
||||
return {
|
||||
remove: function() {
|
||||
isFileRemoved = true;
|
||||
removedFilePath.push(filePath);
|
||||
},
|
||||
clone: function() {
|
||||
return getFile(filePath);
|
||||
},
|
||||
get parent() {
|
||||
return getFile(filePath.substr(0, filePath.lastIndexOf('/')));
|
||||
},
|
||||
append: function(subPath) {
|
||||
filePath += '/' + subPath;
|
||||
},
|
||||
|
||||
setFileExists: function(flag) {
|
||||
isFileExist = flag || true;
|
||||
},
|
||||
|
||||
exists: function() {
|
||||
return isFileExist;
|
||||
},
|
||||
path: filePath,
|
||||
get leafName() {
|
||||
return filePath.substr(filePath.lastIndexOf('/') + 1);
|
||||
},
|
||||
children: fileChildren,
|
||||
getCurrentPath: function() {
|
||||
return filePath;
|
||||
}
|
||||
};
|
||||
};
|
||||
mockUtils.getFile = getFile;
|
||||
|
||||
mockUtils.gaia = {
|
||||
aggregatePrefix: 'gaia-test-prefix-',
|
||||
};
|
||||
|
||||
mockUtils.isSubjectToBranding = function(path) {
|
||||
return isSubjectToBranding;
|
||||
};
|
||||
|
||||
mockUtils.ls = function(files, recursiveFlag, exclusive) {
|
||||
files = files.children ?
|
||||
(files.children[files.getCurrentPath()] || []) : files;
|
||||
return files.filter(function(file) {
|
||||
if (exclusive) {
|
||||
return !exclusive.test(file.leafName);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
mockUtils.writeContent = function(file, content) {
|
||||
writeFileContent = content;
|
||||
writeFile = file;
|
||||
};
|
||||
|
||||
mockUtils.getFileContent = function(file) {
|
||||
return file.content || file.path;
|
||||
};
|
||||
|
||||
mockUtils.ensureFolderExists = function() {};
|
||||
|
||||
mockUtils.getExtension = function(path) {
|
||||
return path.split('.').pop();
|
||||
};
|
||||
|
||||
mockUtils.cloneJSON = function(obj) {
|
||||
return JSON.parse(JSON.stringify(obj));
|
||||
};
|
||||
|
||||
mockUtils.getFileAsDataURI = function(file) {
|
||||
return file.path + '-dataURI';
|
||||
};
|
||||
|
||||
mockUtils.jsComparator = function() {
|
||||
return true;
|
||||
};
|
||||
|
||||
mockUtils.getOsType = function() {
|
||||
return 'Unix';
|
||||
};
|
||||
|
||||
mockUtils.relativePath = function(from, to) {
|
||||
return to;
|
||||
};
|
||||
|
||||
mockConfig = {
|
||||
GAIA_DEFAULT_LOCALE: 'default-locale',
|
||||
GAIA_CONCAT_LOCALES: '1',
|
||||
GAIA_OPTIMIZE: '1',
|
||||
stageDir: 'testStageDir',
|
||||
DEBUG: '0',
|
||||
BUILD_APP_NAME: 'testAppName',
|
||||
OFFICIAL: '1',
|
||||
LOCALES_FILE: 'locale_file',
|
||||
GAIA_DIR: 'gaia_dir',
|
||||
BUILD_DEBUG: '0'
|
||||
};
|
||||
|
||||
MockDom = function(query){
|
||||
this.query = query;
|
||||
this.href = query + '-href';
|
||||
this.parentNode = this;
|
||||
this.parent = this;
|
||||
this.children = [];
|
||||
this.content = query + '-content';
|
||||
this.getAttribute = function(attr) {
|
||||
return query + '-' + attr;
|
||||
};
|
||||
this.innerHTML = query + '-innerHTML';
|
||||
this.removeAttribute = function(attr) {
|
||||
this.removedAttribute = attr;
|
||||
};
|
||||
this.querySelector = function(pat) {
|
||||
var dom = new MockDom(query + '/' + pat);
|
||||
dom.parent = this;
|
||||
return dom;
|
||||
};
|
||||
this.querySelectorAll = function(pat) {
|
||||
var dom = new MockDom(query + '/' + pat);
|
||||
// push this dom as default
|
||||
this.children.push(dom);
|
||||
return this.children;
|
||||
};
|
||||
this.appendChild = function(dom) {
|
||||
this.children.push(dom);
|
||||
};
|
||||
this.removeChild = function(dom) {
|
||||
removeDomChildren.push(dom);
|
||||
};
|
||||
this.ownerDocument = mockDoc;
|
||||
this.hasAttribute = function(attr) {
|
||||
return !!hasAttributeFlag[attr];
|
||||
};
|
||||
this.outerHTML = query + '-outerHTML';
|
||||
this.children = [];
|
||||
this.dataset = domDataSet;
|
||||
this.type = query + '-type';
|
||||
this.src = query + '-src';
|
||||
this.insertBefore = function(ele, pos) {
|
||||
modifiedDOMs.push(ele);
|
||||
return new MockDom(query + '/target-' + ele.query +'/sibling-' +
|
||||
(typeof pos === 'string' ? pos : pos.query));
|
||||
};
|
||||
this.nextSibling = query +'-nextSibling';
|
||||
createdDOMs.push(this);
|
||||
};
|
||||
|
||||
mockDoc = new MockDom('document');
|
||||
mockDoc.createElement = function(tag) {
|
||||
return new MockDom(mockDoc.query + '/' + tag);
|
||||
};
|
||||
mockDoc.doctype = {
|
||||
name: 'docName',
|
||||
publicId: 'publicId',
|
||||
systemId: 'systemId'
|
||||
};
|
||||
mockDoc.documentElement =
|
||||
new MockDom(mockDoc.query + '/documentElement');
|
||||
mockUtils.getDocument = function(content) {
|
||||
return mockDoc;
|
||||
};
|
||||
|
||||
mockoptimizeConfig = {
|
||||
'CONCAT_LOCALES_BLACKLIST': {
|
||||
'ignoreL10nOptimizeApp': '*'
|
||||
},
|
||||
'JS_AGGREGATION_BLACKLIST': {
|
||||
'jsAggregationBlackListApp': '*'
|
||||
},
|
||||
'INLINE_GLOBAL_VAR_WHITELIST': {
|
||||
'inlineWhiteListApp': ['test.html']
|
||||
},
|
||||
'INLINE_OPTIMIZE_WHITELIST': {
|
||||
'inlineWhiteListApp': ['test.html']
|
||||
},
|
||||
'CSS_AGGREGATION_BLACKLIST': {}
|
||||
};
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
isFileRemoved = false;
|
||||
isFileExist = false;
|
||||
fileChildren = {};
|
||||
writeFile = null;
|
||||
writeFileContent = null;
|
||||
removedFilePath.length = 0;
|
||||
createdDOMs.length = 0;
|
||||
hasAttributeFlag = {};
|
||||
domDataSet = {};
|
||||
removeDomChildren.length = 0;
|
||||
modifiedDOMs.length = 0;
|
||||
isSubjectToBranding = false;
|
||||
});
|
||||
|
||||
suite('WebappOptimize', function() {
|
||||
var webappOptimize;
|
||||
|
||||
setup(function() {
|
||||
webappOptimize = new app.WebappOptimize();
|
||||
});
|
||||
|
||||
test('execute, main function of webappOptimize', function() {
|
||||
var processFiles = [];
|
||||
webappOptimize.processFile = function(file) {
|
||||
processFiles.push(file);
|
||||
};
|
||||
var buildDirectoryFile = mockUtils.getFile('build_stage');
|
||||
fileChildren[buildDirectoryFile.leafName] = [
|
||||
mockUtils.getFile('test.html'),
|
||||
mockUtils.getFile('test.nothtml')
|
||||
];
|
||||
fileChildren[buildDirectoryFile.leafName + '/shared/pages'] = [
|
||||
mockUtils.getFile('testshared.html'),
|
||||
];
|
||||
webappOptimize.execute({
|
||||
config: mockConfig,
|
||||
webapp: {
|
||||
sourceDirectoryName: mockConfig.BUILD_APP_NAME,
|
||||
buildDirectoryFilePath: buildDirectoryFile.path
|
||||
},
|
||||
locales: ['en-test']
|
||||
});
|
||||
assert.equal(webappOptimize.numOfFiles, 2,
|
||||
'should have two file left');
|
||||
assert.equal(processFiles[0].leafName, 'test.html',
|
||||
'should process all html file');
|
||||
});
|
||||
});
|
||||
|
||||
suite('HTMLOptimizer', function() {
|
||||
var htmlOptimizer;
|
||||
var writeAggregatedConfig;
|
||||
setup(function() {
|
||||
var htmlFile = mockUtils.getFile('index.html');
|
||||
htmlOptimizer = new app.HTMLOptimizer({
|
||||
htmlFile: htmlFile,
|
||||
entries: {'en-test': []},
|
||||
webapp: {
|
||||
buildDirectoryFilePath: 'build_stage'
|
||||
},
|
||||
config: mockConfig,
|
||||
locales: ['en-test'],
|
||||
optimizeConfig: mockoptimizeConfig
|
||||
});
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
});
|
||||
|
||||
test('serializeL10nResources, prepare JSON AST files', function(done) {
|
||||
mockDoc.documentElement = {};
|
||||
htmlOptimizer.serializeL10nResources().then(function() {
|
||||
assert.deepEqual(htmlOptimizer.entries,
|
||||
{'en-test': [{$i: 'test-id', $v: 'testIdContent'}]});
|
||||
assert.equal(htmlOptimizer.entries['en-test'][0].$v,
|
||||
'testIdContent');
|
||||
}).then(done, done);
|
||||
});
|
||||
|
||||
test('embedHtmlImports', function() {
|
||||
htmlOptimizer.getFileByRelativePath = function(path) {
|
||||
return {
|
||||
content: 'content-' + path,
|
||||
file: mockUtils.getFile(path)
|
||||
};
|
||||
};
|
||||
htmlOptimizer.embedHtmlImports();
|
||||
assert.equal(createdDOMs[0].query, 'document',
|
||||
'should get document element first');
|
||||
assert.equal(createdDOMs[1].query, 'document/documentElement',
|
||||
'should get document element first');
|
||||
assert.equal(createdDOMs[2].query, 'document/link[rel="import"]',
|
||||
'should query [rel="import"]');
|
||||
assert.equal(createdDOMs[3].query, 'document/element',
|
||||
'should query element');
|
||||
assert.equal(createdDOMs[4].query, 'document/link[rel="import"]/template',
|
||||
'should remove child from [rel="import]');
|
||||
assert.equal(createdDOMs[5].query, 'document/element/template',
|
||||
'should query template from element');
|
||||
assert.equal(createdDOMs[6].removedAttribute, 'is',
|
||||
'should query [is]');
|
||||
assert.equal(createdDOMs[6].removedAttribute, 'is',
|
||||
'should remove is attribute');
|
||||
});
|
||||
|
||||
test('embedGlobals', function() {
|
||||
htmlOptimizer.webapp.sourceDirectoryName = 'inlineWhiteListApp';
|
||||
htmlOptimizer.htmlFile = mockUtils.getFile('test.html');
|
||||
htmlOptimizer.embededGlobals();
|
||||
assert.equal(createdDOMs[2].query, 'document/script',
|
||||
'should modify document/script');
|
||||
assert.equal(createdDOMs[2].innerHTML,
|
||||
'window.SYSTEM_MANIFEST="app://system.undefined/manifest.webapp";',
|
||||
'should modify its innerHTML');
|
||||
});
|
||||
|
||||
test('concatL10nResources', function() {
|
||||
htmlOptimizer.concatL10nResources();
|
||||
assert.equal(createdDOMs[2].query,
|
||||
'document/link[rel="localization"]',
|
||||
'should modify document/link[rel="localization"]');
|
||||
});
|
||||
|
||||
test('aggregateJsResources', function() {
|
||||
mockDoc.head = new MockDom(mockDoc.query + '/head');
|
||||
htmlOptimizer.getFileByRelativePath = function(path) {
|
||||
return {
|
||||
content: 'content-' + path
|
||||
};
|
||||
};
|
||||
htmlOptimizer.writeAggregatedContent = function(conf) {
|
||||
writeAggregatedConfig = conf;
|
||||
};
|
||||
htmlOptimizer.aggregateJsResources();
|
||||
assert.equal(createdDOMs[3].query, 'document/head/script[src]');
|
||||
assert.equal(createdDOMs[3].outerHTML,
|
||||
'<!-- document/head/script[src]-outerHTML -->',
|
||||
'should mark the original script link in html');
|
||||
assert.equal(writeAggregatedConfig.fileType, 'script');
|
||||
assert.equal(writeAggregatedConfig.content,
|
||||
'minified-; /* "document/head/script[src]-outerHTML ' +
|
||||
'"*/\n\ncontent-document/head/script[src]-src',
|
||||
'should write minified js content');
|
||||
assert.equal(writeAggregatedConfig.name,
|
||||
'gaia-test-prefix-index.js',
|
||||
'should name js with prefix');
|
||||
});
|
||||
|
||||
test('writeAggregatedContent', function() {
|
||||
// TODO should uncouple this from previous test
|
||||
htmlOptimizer.writeAggregatedContent(writeAggregatedConfig);
|
||||
assert.equal(createdDOMs[3].query, 'document/head/script[src]/' +
|
||||
'target-document/script/sibling-document/head/script[src]-nextSibling');
|
||||
});
|
||||
|
||||
test('aggregateJsResources does not aggregate async scripts', function() {
|
||||
mockDoc.head = new MockDom(mockDoc.query + '/head');
|
||||
mockDoc.head.children = [
|
||||
new MockDom('script1'),
|
||||
new MockDom('script2')
|
||||
];
|
||||
hasAttributeFlag.async = true;
|
||||
htmlOptimizer.getFileByRelativePath = function(path) {
|
||||
return {
|
||||
content: 'content-' + path
|
||||
};
|
||||
};
|
||||
htmlOptimizer.aggregateJsResources();
|
||||
assert.equal(createdDOMs[3].outerHTML,
|
||||
'script1-outerHTML',
|
||||
'should not change the script');
|
||||
assert.equal(createdDOMs[4].outerHTML,
|
||||
'script2-outerHTML',
|
||||
'should not change the script');
|
||||
assert.equal(createdDOMs[5].query, 'document/head/script[src]');
|
||||
assert.equal(createdDOMs[5].outerHTML,
|
||||
'document/head/script[src]-outerHTML',
|
||||
'should not change the script');
|
||||
});
|
||||
|
||||
test('inlineJsResources', function() {
|
||||
htmlOptimizer.webapp.sourceDirectoryName = 'inlineWhiteListApp';
|
||||
htmlOptimizer.htmlFile = mockUtils.getFile('test.html');
|
||||
htmlOptimizer.getFileByRelativePath = function(path) {
|
||||
return {
|
||||
content: 'content-' + path
|
||||
};
|
||||
};
|
||||
htmlOptimizer.inlineJsResources();
|
||||
assert.equal(createdDOMs[3].innerHTML,
|
||||
'minified-content-document/script[src]-src');
|
||||
assert.equal(removeDomChildren[0].query, 'document/script[src]');
|
||||
});
|
||||
|
||||
test('inlineCSSResources', function() {
|
||||
htmlOptimizer.webapp.sourceDirectoryName = 'inlineWhiteListApp';
|
||||
htmlOptimizer.htmlFile = mockUtils.getFile('test.html');
|
||||
htmlOptimizer.getFileByRelativePath = function(path) {
|
||||
return {
|
||||
content: 'content-' + path,
|
||||
file: mockUtils.getFile(path)
|
||||
};
|
||||
};
|
||||
htmlOptimizer.inlineCSSResources();
|
||||
assert.equal(createdDOMs[4].query, 'document/link[rel="stylesheet"]' +
|
||||
'/target-document/style/sibling-document/link[rel="stylesheet"]');
|
||||
assert.equal(modifiedDOMs[0].innerHTML,
|
||||
'content-document/link[rel="stylesheet"]-href');
|
||||
});
|
||||
|
||||
test('serializeNewHTMLDocumentOutput', function() {
|
||||
mockUtils.serializeDocument = function(doc) {
|
||||
return '<!DOCTYPE docName PUBLIC publicId systemId>\n' +
|
||||
'<html testnodename="testnodevalue">\n' +
|
||||
' document/documentElement-innerHTML\n' +
|
||||
'</html>\n';
|
||||
};
|
||||
htmlOptimizer.serializeNewHTMLDocumentOutput();
|
||||
assert.equal(writeFile.path, 'index.html');
|
||||
assert.equal(writeFileContent,
|
||||
'<!DOCTYPE docName PUBLIC publicId systemId>\n' +
|
||||
'<html testnodename="testnodevalue">\n' +
|
||||
' document/documentElement-innerHTML\n' +
|
||||
'</html>\n');
|
||||
});
|
||||
|
||||
test('getFileByRelativePath', function() {
|
||||
isSubjectToBranding = true;
|
||||
var path = '/test/foo.html';
|
||||
var result = htmlOptimizer.getFileByRelativePath(path);
|
||||
assert.equal(result.file.getCurrentPath(),
|
||||
'build_stage/test/official/foo.html');
|
||||
});
|
||||
|
||||
test('writeASTs', function() {
|
||||
isFileExist = true;
|
||||
var buildDirectoryFile = mockUtils.getFile('build_stage');
|
||||
htmlOptimizer.webapp.buildDirectoryFilePath = buildDirectoryFile.path;
|
||||
htmlOptimizer.entries =
|
||||
{'en-test': [{ $i: 'testId', $v: 'testIdContent'}]};
|
||||
fileChildren[buildDirectoryFile.leafName + '/locales-obj'] = [
|
||||
mockUtils.getFile('index.en-test.json')
|
||||
];
|
||||
htmlOptimizer.writeAST();
|
||||
assert.equal(writeFileContent, '[{"$i":"testId","$v":"testIdContent"}]',
|
||||
'should write locale content');
|
||||
assert.equal(writeFile.leafName, 'index.en-test.json',
|
||||
'should write locale content to this path');
|
||||
});
|
||||
});
|
||||
});
|
||||
477
gaia/build/test/unit/webapp_shared_test.js
Executable file
477
gaia/build/test/unit/webapp_shared_test.js
Executable file
|
|
@ -0,0 +1,477 @@
|
|||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var path = require('path');
|
||||
var proxyquire = require('proxyquire');
|
||||
var mockUtils = require('./mock_utils.js');
|
||||
|
||||
suite('webapp-shared.js', function() {
|
||||
var app;
|
||||
var testapp;
|
||||
var fileExists;
|
||||
var isDirectory;
|
||||
var isHidden;
|
||||
var isFile;
|
||||
var mRelativePath;
|
||||
setup(function() {
|
||||
app = proxyquire.noCallThru().load(
|
||||
'../../webapp-shared', {
|
||||
'./utils': mockUtils
|
||||
});
|
||||
fileExists = true;
|
||||
isDirectory = false;
|
||||
isHidden = false;
|
||||
isFile = true;
|
||||
var getFile = function() {
|
||||
var filePath = path.join.apply(this, arguments);
|
||||
var leafName = filePath.split('/').pop();
|
||||
return {
|
||||
isHidden: function() {
|
||||
return isHidden;
|
||||
},
|
||||
clone: function() {
|
||||
return getFile(filePath);
|
||||
},
|
||||
|
||||
append: function(subPath) {
|
||||
return getFile(filePath, subPath);
|
||||
},
|
||||
|
||||
setFileExists: function(flag) {
|
||||
fileExists = flag || true;
|
||||
},
|
||||
|
||||
exists: function() {
|
||||
return fileExists;
|
||||
},
|
||||
path: filePath,
|
||||
leafName: leafName,
|
||||
isDirectory: function() {
|
||||
return isDirectory;
|
||||
},
|
||||
isFile: function() {
|
||||
return isFile;
|
||||
}
|
||||
};
|
||||
};
|
||||
mockUtils.relativePath = function(path, subPath) {
|
||||
return mRelativePath || subPath;
|
||||
};
|
||||
|
||||
mockUtils.joinPath = function() {
|
||||
var path = '';
|
||||
for (var i in arguments) {
|
||||
path += (arguments[i] + '/');
|
||||
}
|
||||
return path.slice(0, -1);
|
||||
};
|
||||
|
||||
mockUtils.getFile = getFile;
|
||||
mockUtils.getFileContent = function(file) {
|
||||
return file;
|
||||
};
|
||||
|
||||
mockUtils.getFileAsDataURI = function(file) {
|
||||
return file.path;
|
||||
};
|
||||
|
||||
mockUtils.gaia = {
|
||||
getInstance: function(config) {
|
||||
return {
|
||||
webapps: [testapp]
|
||||
};
|
||||
}
|
||||
};
|
||||
var testBuildDirectoryFileUrl = 'testBuildDirectoryFileUrl';
|
||||
testapp = {
|
||||
buildDirectoryFileUrl: testBuildDirectoryFileUrl,
|
||||
domain: 'testDomain',
|
||||
buildDirectoryFile: mockUtils.getFile(testBuildDirectoryFileUrl),
|
||||
sourceDirectoryName: 'testSourceName'
|
||||
};
|
||||
});
|
||||
|
||||
suite('setOptions, pushFileByType, filterSharedUsage, ' +
|
||||
'filterSharedCSSImport, filterFileByExtenstion, ',
|
||||
function() {
|
||||
var webappShared;
|
||||
setup(function() {
|
||||
webappShared = new app.WebappShared();
|
||||
|
||||
mockUtils.resolve = function(file, baseLink) {
|
||||
var fileExist = true;
|
||||
return {
|
||||
exists: function() {
|
||||
return fileExist;
|
||||
},
|
||||
path: baseLink + '/' + file
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
test('setOptions', function () {
|
||||
testapp.buildDirectoryFilePath = 'testBuildDirectoryFileUrl';
|
||||
var options = {
|
||||
config: {
|
||||
GAIA_DISTRIBUTION_DIR: 'testDistributionDir',
|
||||
GAIA_DIR: 'testGaia',
|
||||
SETTINGS_PATH: 'testSettingsPath',
|
||||
LOCALES_FILE: 'testLocale'
|
||||
},
|
||||
gaia: 'gaia',
|
||||
webapp: testapp
|
||||
};
|
||||
webappShared.setOptions(options);
|
||||
assert.equal(webappShared.localesFile.path,
|
||||
options.config.GAIA_DIR + '/' + options.config.LOCALES_FILE);
|
||||
assert.equal(webappShared.buildDir.path,
|
||||
testapp.buildDirectoryFile.path);
|
||||
});
|
||||
|
||||
test('pushFileByType', function () {
|
||||
webappShared.used = {
|
||||
js: [],
|
||||
resources: [],
|
||||
styles: [],
|
||||
unstable_styles: [],
|
||||
locales: []
|
||||
};
|
||||
webappShared.config = {};
|
||||
webappShared.pushJS = function() {};
|
||||
webappShared.pushResource = function() {};
|
||||
webappShared.copyBuildingBlock = function() {};
|
||||
webappShared.pushLocale = function() {};
|
||||
|
||||
var testjs = 'testjs';
|
||||
webappShared.pushFileByType('js', testjs);
|
||||
assert.equal(webappShared.used.js[0], testjs, 'push testjs');
|
||||
|
||||
webappShared.pushFileByType('js', testjs);
|
||||
assert.equal(webappShared.used.js[1], undefined, 'push testjs again');
|
||||
|
||||
var resources = 'testResources';
|
||||
webappShared.pushFileByType('resources', resources);
|
||||
assert.equal(webappShared.used.resources[0], resources,
|
||||
'push resources');
|
||||
|
||||
var style = 'teststyle';
|
||||
webappShared.pushFileByType('style', style + '.css');
|
||||
assert.equal(webappShared.used.styles[0], style,
|
||||
'push style');
|
||||
|
||||
var unstable_styles = 'teststyle_unstable';
|
||||
webappShared.pushFileByType('style_unstable', unstable_styles + '.css');
|
||||
assert.equal(webappShared.used.unstable_styles[0], unstable_styles,
|
||||
'push unstable_styles');
|
||||
|
||||
var localeName = 'date';
|
||||
webappShared.pushFileByType('locales',
|
||||
localeName + '/date.{locale}.properties');
|
||||
assert.equal(webappShared.used.locales[0], localeName,
|
||||
'push locales');
|
||||
});
|
||||
|
||||
test('filterSharedUsage', function() {
|
||||
var csslink = 'link.css';
|
||||
var jslink = 'link.js';
|
||||
var content =
|
||||
'test \n <link rel="stylesheet" type="text/css" href="shared/style/' +
|
||||
csslink + '"> \n <script defer src="/shared/js/' +
|
||||
jslink + '"></script> testttt \n';
|
||||
var result = [];
|
||||
webappShared.pushFileByType = function(kind, path) {
|
||||
result.push({kind: kind, path: path});
|
||||
};
|
||||
webappShared.filterSharedUsage(content);
|
||||
assert.deepEqual(result, [
|
||||
{kind: 'style', path: csslink} ,
|
||||
{kind: 'js', path: jslink}]);
|
||||
});
|
||||
|
||||
test('filterSharedCSSImport', function() {
|
||||
var csslink = 'test.css';
|
||||
var content = '@import "shared/style/' + csslink + '";\n';
|
||||
var result = [];
|
||||
webappShared.pushFileByType = function(kind, path) {
|
||||
result.push({kind: kind, path: path});
|
||||
};
|
||||
webappShared.filterSharedCSSImport(content);
|
||||
assert.deepEqual(result, [
|
||||
{kind: 'style', path: csslink}
|
||||
]);
|
||||
});
|
||||
|
||||
test('filterFileByExtenstion', function() {
|
||||
var htmlResult = webappShared.filterFileByExtenstion(
|
||||
'html', {
|
||||
isFile: function() {
|
||||
return true;
|
||||
},
|
||||
leafName: 'text.html'
|
||||
});
|
||||
assert.equal(htmlResult, true);
|
||||
var cssResult = webappShared.filterFileByExtenstion(
|
||||
'css', {
|
||||
isFile: function() {
|
||||
return true;
|
||||
},
|
||||
leafName: 'text.css'
|
||||
});
|
||||
assert.equal(cssResult, true);
|
||||
var failResult = webappShared.filterFileByExtenstion(
|
||||
'txt', {
|
||||
isFile: function() {
|
||||
return true;
|
||||
},
|
||||
leafName: 'text.js'
|
||||
});
|
||||
assert.equal(failResult, false);
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
fileExists = true;
|
||||
webappShared = null;
|
||||
});
|
||||
});
|
||||
|
||||
suite('customizeShared, copyShared, execute',
|
||||
function() {
|
||||
var webappShared;
|
||||
setup(function() {
|
||||
webappShared = new app.WebappShared();
|
||||
});
|
||||
|
||||
test('customizeShared', function() {
|
||||
var result = [];
|
||||
var gaia_shared = {
|
||||
'js': ['test1.js'],
|
||||
'style': ['test2.css']
|
||||
};
|
||||
|
||||
mockUtils.getFileContent = function() {
|
||||
return JSON.stringify(gaia_shared);
|
||||
};
|
||||
webappShared.webapp = {
|
||||
buildDirectoryFilePath: 'test'
|
||||
};
|
||||
webappShared.pushFileByType = function(kind, path) {
|
||||
result.push({kind: kind, path: path});
|
||||
};
|
||||
webappShared.customizeShared();
|
||||
assert.deepEqual(result, [
|
||||
{kind: 'js', path: gaia_shared.js[0]},
|
||||
{kind: 'style', path: gaia_shared.style[0]}
|
||||
]);
|
||||
});
|
||||
|
||||
test('copyShared', function() {
|
||||
var result = [];
|
||||
|
||||
webappShared.filterFileByExtenstion = function(type, file) {
|
||||
return file.indexOf(type) !== -1;
|
||||
};
|
||||
webappShared.filterSharedUsage = function(file) {
|
||||
result.push(file);
|
||||
};
|
||||
webappShared.filterSharedCSSImport = function(file) {
|
||||
result.push(file);
|
||||
};
|
||||
webappShared.customizeShared = function() {};
|
||||
|
||||
webappShared.config = {
|
||||
BUILD_APP_NAME: 'testApp'
|
||||
};
|
||||
webappShared.webapp = {
|
||||
sourceDirectoryName: 'testApp2',
|
||||
sourceDirectoryFilePath: 'test'
|
||||
};
|
||||
assert.equal(webappShared.copyShared(), undefined,
|
||||
'config.BUILD_APP_NAME is\'nt *, we only accept one webapp');
|
||||
|
||||
webappShared.webapp.sourceDirectoryName =
|
||||
webappShared.config.BUILD_APP_NAME;
|
||||
mockUtils.isExternalApp = function() {
|
||||
return true;
|
||||
};
|
||||
assert.equal(webappShared.copyShared(), undefined,
|
||||
'external app');
|
||||
|
||||
mockUtils.isExternalApp = function() {
|
||||
return false;
|
||||
};
|
||||
var expected = ['testfile.html', 'teststyle.css'];
|
||||
var testfiles = ['testfile.html', 'teststyle.css', 'testimg.png'];
|
||||
mockUtils.ls = function() {
|
||||
return testfiles;
|
||||
};
|
||||
webappShared.copyShared();
|
||||
assert.deepEqual(result, expected,
|
||||
'external app');
|
||||
});
|
||||
|
||||
test('execute', function() {
|
||||
webappShared.setOptions = function(){};
|
||||
webappShared.copyShared = function(){};
|
||||
webappShared.execute();
|
||||
});
|
||||
teardown(function() {
|
||||
delete mockUtils.ls;
|
||||
delete mockUtils.isExternalApp;
|
||||
delete mockUtils.getFileContent;
|
||||
delete mockUtils.copyDirTo;
|
||||
delete mockUtils.copyFileTo;
|
||||
});
|
||||
});
|
||||
|
||||
suite('pushLocale, pushResource, pushJS and copyBuildingBlock', function() {
|
||||
var webappShared;
|
||||
var result = [];
|
||||
var lsFiles;
|
||||
var sharedFilePath;
|
||||
setup(function() {
|
||||
webappShared = new app.WebappShared();
|
||||
sharedFilePath = 'testshared';
|
||||
webappShared.config = {
|
||||
GAIA_DIR: 'GAIA_DIR'
|
||||
};
|
||||
webappShared.gaia = {
|
||||
sharedFolder: mockUtils.getFile(sharedFilePath)
|
||||
};
|
||||
webappShared.moveToBuildDir = function(file, targetPath) {
|
||||
result.push({file: file, path: targetPath});
|
||||
};
|
||||
mockUtils.ls = function() {
|
||||
return lsFiles;
|
||||
};
|
||||
});
|
||||
|
||||
test('pushLocale', function() {
|
||||
var localePath = 'testlocale';
|
||||
var lsContentFilePath = 'testfile';
|
||||
|
||||
lsFiles = [
|
||||
{path: webappShared.config.GAIA_DIR + '/' + lsContentFilePath}
|
||||
];
|
||||
webappShared.pushLocale(localePath);
|
||||
assert.equal(result[0].path, 'shared/locales/' + localePath);
|
||||
assert.equal(result[0].file.path, sharedFilePath + '/locales/' +
|
||||
localePath);
|
||||
assert.equal(result[1].path, lsContentFilePath);
|
||||
});
|
||||
|
||||
test('pushResource', function() {
|
||||
var languagesPath = 'languages.json';
|
||||
webappShared.localesFile = 'testlocales';
|
||||
webappShared.pushResource(languagesPath);
|
||||
assert.equal(result[0].path, 'shared/resources/languages.json');
|
||||
assert.equal(result[0].file, webappShared.localesFile);
|
||||
|
||||
result.length = 0;
|
||||
var brandingPath = 'brandingPath';
|
||||
lsFiles = [{
|
||||
leafName: brandingPath + '@2x.png',
|
||||
path: 'shared/resources/' + brandingPath +
|
||||
'@2x.png'
|
||||
}];
|
||||
webappShared.pushResource(brandingPath + '.png');
|
||||
assert.equal(result[0].path, 'shared/resources/' + brandingPath +
|
||||
'@2x.png');
|
||||
|
||||
result.length = 0;
|
||||
isDirectory = true;
|
||||
var sharedFilePath = 'testgaia/apps';
|
||||
var relativePath = '/testRelative';
|
||||
lsFiles = [{path: sharedFilePath + relativePath}];
|
||||
webappShared.gaia = {
|
||||
sharedFolder: mockUtils.getFile(sharedFilePath)
|
||||
};
|
||||
webappShared.pushResource(sharedFilePath + relativePath);
|
||||
assert.equal(result[0].path, 'shared' + relativePath);
|
||||
|
||||
result.length = 0;
|
||||
isDirectory = false;
|
||||
webappShared.gaia.distributionDir = 'testdistributionDir';
|
||||
webappShared.pushResource('media/ringtones/');
|
||||
assert.equal(result[0].path, 'ringtones');
|
||||
});
|
||||
|
||||
test('pushJS', function() {
|
||||
var jsFile = 'testjs.js';
|
||||
webappShared.gaia = {
|
||||
sharedFolder: mockUtils.getFile(jsFile)
|
||||
};
|
||||
webappShared.pushJS(jsFile);
|
||||
assert.equal(result[0].path, 'shared/js/' + jsFile);
|
||||
});
|
||||
|
||||
test('pushElements', function() {
|
||||
var elementFile = 'testelemnt.html';
|
||||
webappShared.gaia = {
|
||||
sharedFolder: mockUtils.getFile(elementFile)
|
||||
};
|
||||
webappShared.pushElements(elementFile);
|
||||
assert.equal(result[0].path, 'shared/elements/' + elementFile);
|
||||
assert.equal(result.length, 1);
|
||||
|
||||
// Test for various supported installs of component files
|
||||
// Note: this test isn't as real as I would like it to be as the exists()
|
||||
// function is stubbed always.
|
||||
elementFile = 'gaia_component/script.js';
|
||||
var testFiles = [
|
||||
'elements/gaia_component/style.css',
|
||||
'elements/gaia_component/css',
|
||||
'elements/gaia_component/js',
|
||||
'elements/gaia_component/images'
|
||||
];
|
||||
|
||||
result.length = 0;
|
||||
webappShared.gaia = {
|
||||
sharedFolder: mockUtils.getFile('')
|
||||
};
|
||||
webappShared.pushElements(elementFile);
|
||||
assert.equal(result[0].path, 'shared/elements/' + elementFile);
|
||||
assert.equal(result[1].path, 'shared/' + testFiles[0]);
|
||||
assert.equal(result[2].path, 'shared/' + testFiles[1]);
|
||||
assert.equal(result[3].path, 'shared/' + testFiles[2]);
|
||||
assert.equal(result[4].path, 'shared/' + testFiles[3]);
|
||||
});
|
||||
|
||||
test('copyBuildingBlock', function() {
|
||||
var blockName = 'stable_test';
|
||||
var dirName = 'test_dir';
|
||||
lsFiles = [];
|
||||
webappShared.copyBuildingBlock(blockName, dirName);
|
||||
assert.equal(result[0].path, 'shared/' + dirName + '/' +
|
||||
blockName + '.css');
|
||||
|
||||
result.length = 0;
|
||||
lsFiles = [
|
||||
{
|
||||
getRelativeDescriptor: function() {
|
||||
return blockName + '2.css';
|
||||
},
|
||||
isDirectory: function() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
];
|
||||
mRelativePath = blockName + '2.css';
|
||||
webappShared.copyBuildingBlock(blockName, dirName);
|
||||
assert.equal(result[1].path, 'shared/' + dirName + '/' +
|
||||
blockName + '2.css');
|
||||
mRelativePath = null;
|
||||
});
|
||||
|
||||
test('copySharedPage', function() {
|
||||
var path = 'import/test_page.html';
|
||||
webappShared.copyPage(path);
|
||||
assert.equal(result[0].path, 'shared/pages' + '/' + path);
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
lsFiles.length = 0;
|
||||
result.length = 0;
|
||||
delete mockUtils.ls;
|
||||
});
|
||||
});
|
||||
});
|
||||
224
gaia/build/test/unit/webapp_zip_test.js
Executable file
224
gaia/build/test/unit/webapp_zip_test.js
Executable file
|
|
@ -0,0 +1,224 @@
|
|||
'use strict';
|
||||
|
||||
var assert = require('chai').assert;
|
||||
var proxyquire = require('proxyquire');
|
||||
var mockUtils = require('./mock_utils.js');
|
||||
var fsPath = require('path');
|
||||
|
||||
suite('webapp-zip.js', function() {
|
||||
var app;
|
||||
var mockOptions;
|
||||
var zipFilePath;
|
||||
var zipMode;
|
||||
var fileExists = false;
|
||||
var filePath;
|
||||
var isFile = false;
|
||||
var isDirectory = false;
|
||||
var isHidden = false;
|
||||
|
||||
setup(function() {
|
||||
app = proxyquire.noCallThru().load(
|
||||
'../../webapp-zip', {
|
||||
'./utils': mockUtils
|
||||
});
|
||||
var GetFile = function(filePath) {
|
||||
this.path = filePath;
|
||||
this.append = function(subPath) {
|
||||
this.path += ('/' + subPath);
|
||||
};
|
||||
this.clone = function() {
|
||||
return new GetFile(this.path);
|
||||
};
|
||||
this.leafName = fsPath.basename(this.path);
|
||||
this.parent = this;
|
||||
this.exists = function() {
|
||||
return fileExists;
|
||||
};
|
||||
this.isHidden = function() {
|
||||
return isHidden;
|
||||
};
|
||||
this.isFile = function() {
|
||||
return isFile;
|
||||
};
|
||||
this.isDirectory = function() {
|
||||
return isDirectory;
|
||||
};
|
||||
};
|
||||
mockUtils.getFile = function() {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
filePath = fsPath.join.apply(fsPath, args);
|
||||
return new GetFile(filePath);
|
||||
};
|
||||
|
||||
mockUtils.createZip = function(zipPath) {
|
||||
zipFilePath = zipPath;
|
||||
return {};
|
||||
};
|
||||
|
||||
mockUtils.getCompression = function(type) {
|
||||
return type;
|
||||
};
|
||||
|
||||
mockUtils.ensureFolderExists = function() {
|
||||
};
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
app = null;
|
||||
mockOptions = null;
|
||||
zipFilePath = null;
|
||||
zipMode = null;
|
||||
filePath = null;
|
||||
fileExists = false;
|
||||
isFile = false;
|
||||
isDirectory = false;
|
||||
isHidden = false;
|
||||
});
|
||||
|
||||
suite('setOptions, getCompression, and isExcludeFromZip',
|
||||
function() {
|
||||
var mockOptions;
|
||||
var webappZip;
|
||||
setup(function() {
|
||||
mockOptions = {
|
||||
webapp: {
|
||||
buildDirectoryFilePath: 'testBuildDirectoryFile',
|
||||
profileDirectoryFilePath: 'testTargetDir/testDomain',
|
||||
domain: 'testDomain'
|
||||
},
|
||||
targetDir: mockUtils.getFile('testTargetDir')
|
||||
};
|
||||
webappZip = new app.WebappZip();
|
||||
});
|
||||
|
||||
test('setOptions', function() {
|
||||
webappZip.setOptions(mockOptions);
|
||||
assert.equal(zipFilePath, 'testTargetDir/testDomain/application.zip');
|
||||
});
|
||||
|
||||
test('getCompression', function() {
|
||||
var pathInZip = 'pathInZip';
|
||||
webappZip.options = {
|
||||
webapp: {
|
||||
metaData: {
|
||||
external: false,
|
||||
zip: {}
|
||||
}
|
||||
}
|
||||
};
|
||||
webappZip.options.webapp.metaData.zip.mmap_files = [pathInZip];
|
||||
assert.equal(webappZip.getCompression(pathInZip), 'none');
|
||||
|
||||
// we don't compress jpg file.
|
||||
pathInZip = 'pathInZip.jpg';
|
||||
delete webappZip.options.webapp.metaData;
|
||||
assert.equal(webappZip.getCompression(pathInZip), 'none');
|
||||
|
||||
pathInZip = 'pathInZip.png';
|
||||
assert.equal(webappZip.getCompression(pathInZip), 'best');
|
||||
});
|
||||
|
||||
test('isExcludedFromZip', function() {
|
||||
var file = mockUtils.getFile('locales');
|
||||
isFile = true;
|
||||
fileExists = true;
|
||||
webappZip.options = {
|
||||
GAIA_CONCAT_LOCALES: '1',
|
||||
webapp: {
|
||||
sourceDirectoryName: 'testSourceDirectory'
|
||||
}
|
||||
};
|
||||
webappZip.options.webapp.buildDirectoryFilePath = 'test';
|
||||
assert.equal(webappZip.isExcludedFromZip(file), true,
|
||||
'Ignore l10n files if they have been inlined or concatenated');
|
||||
|
||||
file = mockUtils.getFile('locales-obj');
|
||||
webappZip.options.GAIA_CONCAT_LOCALES = '0';
|
||||
assert.equal(webappZip.isExcludedFromZip(file), true,
|
||||
'Ignore l10n files if they have been inlined or concatenated');
|
||||
|
||||
file = mockUtils.getFile('testapppath/test');
|
||||
webappZip.options.webapp.buildDirectoryFilePath = 'testapppath';
|
||||
assert.equal(webappZip.isExcludedFromZip(file), true,
|
||||
'Ignore test file');
|
||||
file = mockUtils.getFile('testapppath/views/test/file.js');
|
||||
webappZip.options.webapp.buildDirectoryFilePath = 'testapppath';
|
||||
assert.equal(webappZip.isExcludedFromZip(file), true,
|
||||
'Ignore nested test file');
|
||||
file = mockUtils.getFile('testapppath/.git');
|
||||
assert.equal(webappZip.isExcludedFromZip(file), true,
|
||||
'Ignore .git file');
|
||||
file = mockUtils.getFile('testapppath/.unknown');
|
||||
assert.equal(webappZip.isExcludedFromZip(file), false,
|
||||
'other cases');
|
||||
|
||||
fileExists = false;
|
||||
file = mockUtils.getFile('testapppath/.unknown');
|
||||
assert.equal(webappZip.isExcludedFromZip(file), true,
|
||||
'file not exists');
|
||||
fileExists = true;
|
||||
isHidden = true;
|
||||
file = mockUtils.getFile('testapppath/.unknown');
|
||||
assert.equal(webappZip.isExcludedFromZip(file), true,
|
||||
'file is hidden');
|
||||
});
|
||||
});
|
||||
|
||||
suite('addToZip', function() {
|
||||
var webappZip;
|
||||
var isExcludedFromZip;
|
||||
var testResult;
|
||||
|
||||
setup(function() {
|
||||
fileExists = true;
|
||||
isExcludedFromZip = false;
|
||||
mockUtils.addFileToZip = function(zip, pathInZip, file, compression) {
|
||||
testResult = {
|
||||
zip: zip,
|
||||
pathInZip: pathInZip,
|
||||
file: file,
|
||||
compression: compression
|
||||
};
|
||||
};
|
||||
webappZip = new app.WebappZip();
|
||||
webappZip.options = {
|
||||
GAIA_DEFAULT_LOCALE: 'en-US-test',
|
||||
webapp: {
|
||||
buildDirectoryFilePath: 'testBuildDir'
|
||||
}
|
||||
};
|
||||
webappZip.isExcludedFromZip = function() {
|
||||
return isExcludedFromZip;
|
||||
};
|
||||
webappZip.getCompression = function() {
|
||||
return '1';
|
||||
};
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
testResult = null;
|
||||
});
|
||||
|
||||
test('file is hiddenr or is set excluded from zip', function() {
|
||||
var testFile = mockUtils.getFile('testfile');
|
||||
isHidden = true;
|
||||
isExcludedFromZip = false;
|
||||
assert.equal(webappZip.addToZip(testFile), undefined, 'file is hidden');
|
||||
|
||||
isHidden = false;
|
||||
isExcludedFromZip = true;
|
||||
assert.equal(webappZip.addToZip(testFile), undefined,
|
||||
'file is not hidden, but from excluded list');
|
||||
});
|
||||
|
||||
test('add localize html file', function() {
|
||||
var testFile = mockUtils.getFile('testBuildDir/testFile.html');
|
||||
isFile = true;
|
||||
fileExists = true;
|
||||
webappZip.addToZip(testFile);
|
||||
assert.equal(testResult.pathInZip, 'testFile.html');
|
||||
assert.equal(testResult.file.path,
|
||||
'testBuildDir/testFile.html.en-US-test');
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue