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

Commit

Permalink
Bug 1066347 - merge pull request #29422 from zbraniecki:1066347-separ…
Browse files Browse the repository at this point in the history
…ate-json-files-per-html-file to mozilla-b2g:master
  • Loading branch information
mozilla-autolander-deprecated committed Apr 10, 2015
2 parents 749b6eb + 0ee3b6f commit 6e403db
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 150 deletions.
Expand Up @@ -123,7 +123,7 @@ marionette('Contacts > Activities', function() {
var duplicateHeader = client.helper.
waitForElement(selectors.duplicateHeader);
var expectedResult = subject.l10n(
'/locales-obj/en-US.json',
'/locales-obj/contacts.matching_contacts.en-US.json',
'duplicatesFoundTitle');

assert.equal(duplicateHeader.text(), expectedResult);
Expand Down Expand Up @@ -151,7 +151,7 @@ marionette('Contacts > Activities', function() {

var confirmMsg = client.findElement(selectors.confirmBody);
var expectedResult = subject.l10n(
'/locales-obj/en-US.json',
'/locales-obj/contacts.index.en-US.json',
'noContactsActivity2');
assert.equal(confirmMsg.text(), expectedResult);
});
Expand Down Expand Up @@ -188,7 +188,7 @@ marionette('Contacts > Activities', function() {
.text();

var expectedResult = subject.l10n(
'/locales-obj/en-US.json',
'/locales-obj/contacts.index.en-US.json',
'no_contact_phones');
assert.equal(confirmText, expectedResult);
});
Expand Down
6 changes: 3 additions & 3 deletions apps/communications/contacts/test/marionette/ice_test.js
Expand Up @@ -214,7 +214,7 @@ marionette('Contacts > ICE contacts', function() {
.text();

var expectedResult = subject.l10n(
'/locales-obj/en-US.json',
'/locales-obj/contacts.index.en-US.json',
'ICERepeatedContact');
assert.equal(confirmText, expectedResult);
});
Expand All @@ -227,7 +227,7 @@ marionette('Contacts > ICE contacts', function() {
.text();

var expectedResult = subject.l10n(
'/locales-obj/en-US.json',
'/locales-obj/contacts.index.en-US.json',
'ICEContactNoNumber');

assert.equal(confirmText, expectedResult);
Expand Down Expand Up @@ -275,7 +275,7 @@ marionette('Contacts > ICE contacts', function() {
var confirmBody = client.helper.waitForElement(selectors.confirmBody);

var expectedResult = subject.l10n(
'/locales-obj/en-US.json',
'/locales-obj/contacts.index.en-US.json',
'ICEContactDelTelAll');

assert.equal(confirmBody.text(), expectedResult);
Expand Down
Expand Up @@ -56,7 +56,7 @@ marionette('Vertical - Collection', function() {
// XXX: Loading this locale file seems to no longer work.
// Hardcode the expected value for now.
var expected = home.l10n(
'/locales-obj/qps-ploc.json',
'/locales-obj/index.qps-ploc.json',
// XXX: harcoded number 376 taken from the fixture
'collection-categoryId-376'
);
Expand Down
Expand Up @@ -45,7 +45,7 @@ marionette('Vertical - Collection', function() {
server.unfailAll();

var expectedMsg = home.l10n(
'/locales-obj/en-US.json',
'/locales-obj/index.en-US.json',
'network-error-message'
);

Expand Down
7 changes: 7 additions & 0 deletions build/l10n/l10n.js
Expand Up @@ -157,6 +157,13 @@
navigator.mozL10n.translateDocument = L10n.translateDocument;

navigator.mozL10n.getAST = function() {
// if we don't have any resources we want to inform the client that
// there should be no AST for this file, which is different from
// returning an empty AST
if (this.ctx.resLinks.length === 0) {
return null;
}

var ast = [];

// en-US is the de facto source locale of Gaia
Expand Down
2 changes: 1 addition & 1 deletion build/test/integration/multilocale_test.js
Expand Up @@ -15,7 +15,7 @@ suite('Multilocale integration tests', function() {
function makeHelper(localesFilePath, localesDir, concat, done) {
var settingsZipPath = path.join(process.cwd(), 'profile', 'webapps',
'settings.gaiamobile.org', 'application.zip');
var cnPathInZip = 'locales-obj/zh-CN.json';
var cnPathInZip = 'locales-obj/index.zh-CN.json';
var cnSettingsProperties = 'locales/settings.zh-CN.properties';
var langPathInZip = 'shared/resources/languages.json';

Expand Down
4 changes: 2 additions & 2 deletions build/test/integration/pseudolocalizations_test.js
Expand Up @@ -18,8 +18,8 @@ suite('buildtime pseudolocalizations', function() {
var zipPath = path.join(process.cwd(), 'profile', 'webapps',
'system.gaiamobile.org', 'application.zip');
var zip = new AdmZip(zipPath);
var enUSFileInZip = zip.getEntry('locales-obj/en-US.json');
var qpsPlocPathInZip = 'locales-obj/qps-ploc.json';
var enUSFileInZip = zip.getEntry('locales-obj/index.en-US.json');
var qpsPlocPathInZip = 'locales-obj/index.qps-ploc.json';
var qpsPlocFileInZip = zip.getEntry(qpsPlocPathInZip);

assert.isNotNull(
Expand Down
5 changes: 5 additions & 0 deletions build/test/unit/mock_utils.js
Expand Up @@ -109,6 +109,11 @@ 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) {
Expand Down
73 changes: 21 additions & 52 deletions build/test/unit/webapp_optimize_test.js
Expand Up @@ -273,43 +273,6 @@ suite('webapp-optimize.js', function() {
webappOptimize = new app.WebappOptimize();
});

test('HTMLProcessed, when all HTMLs have been proceeded ', function() {
var numOfFiles = webappOptimize.numOfFiles = 10;
var writeASTsCalled = 0;

webappOptimize.writeASTs = function() {
writeASTsCalled++;
};

isFileExist = true;
for (var i = 0; i < numOfFiles; i++) {
webappOptimize.HTMLProcessed([mockFile]);
}

assert.equal(writeASTsCalled, 1,
'HTMLProcessed should only be called once');
// assert.equal(isFileRemoved, true, 'file should be removed');
});

test('writeASTs', function() {
isFileExist = true;
webappOptimize.config = mockConfig;

var buildDirectoryFile = mockUtils.getFile('build_stage');
webappOptimize.webapp = {
buildDirectoryFilePath: buildDirectoryFile.path,
asts: {'en-test': [{ $i: 'testId', $v: 'testIdContent'}]}
};
fileChildren[buildDirectoryFile.leafName + '/locales-obj'] = [
mockUtils.getFile('en-test.json')
];
webappOptimize.writeASTs();
assert.equal(writeFileContent, '[{"$i":"testId","$v":"testIdContent"}]',
'should write locale content');
assert.equal(writeFile.leafName, 'en-test.json',
'should write locale content to this path');
});

test('execute, main function of webappOptimize', function() {
var processFiles = [];
webappOptimize.processFile = function(file) {
Expand All @@ -331,8 +294,6 @@ suite('webapp-optimize.js', function() {
},
locales: ['en-test']
});
assert.deepEqual(webappOptimize.webapp.asts, {},
'should create an empty asts for webapp');
assert.equal(webappOptimize.numOfFiles, 2,
'should have two file left');
assert.equal(processFiles[0].leafName, 'test.html',
Expand All @@ -342,23 +303,19 @@ suite('webapp-optimize.js', function() {

suite('HTMLOptimizer', function() {
var htmlOptimizer;
var doneFiles;
var writeAggregatedConfig;
setup(function() {
var htmlFile = mockUtils.getFile('test-index.html');
var htmlFile = mockUtils.getFile('index.html');
htmlOptimizer = new app.HTMLOptimizer({
htmlFile: htmlFile,
asts: {'en-test': []},
webapp: {
asts: {'en-test': []},
buildDirectoryFilePath: 'build_stage'
},
config: mockConfig,
win: mockWin,
locales: ['en-test'],
optimizeConfig: mockoptimizeConfig,
callback: function(files) {
doneFiles = files;
}
optimizeConfig: mockoptimizeConfig
});
});

Expand All @@ -372,10 +329,7 @@ suite('webapp-optimize.js', function() {
htmlOptimizer._optimize = function() {
_optimizeCalled = true;
};
htmlOptimizer.files = ['test'];
htmlOptimizer.process();
assert.deepEqual(doneFiles, htmlOptimizer.files,
'should return file list when all files are processed');
mockoptimizeConfig
.L10N_OPTIMIZATION_BLACKLIST.ignoreL10nOptimizeApp = false;
htmlOptimizer.process();
Expand All @@ -391,7 +345,7 @@ suite('webapp-optimize.js', function() {
htmlOptimizer._proceedLocales();
assert.deepEqual(htmlOptimizer.asts,
{'en-test': [{$i: 'test-id', $v: 'testIdContent'}]});
assert.equal(htmlOptimizer.webapp.asts['en-test'][0].$v,
assert.equal(htmlOptimizer.asts['en-test'][0].$v,
'testIdContent');
});

Expand Down Expand Up @@ -460,7 +414,7 @@ suite('webapp-optimize.js', function() {
'"*/\n\ncontent-document/head/script[src]-src',
'should write minified js content');
assert.equal(writeAggregatedConfig.name,
'gaia-test-prefix-test-index.js',
'gaia-test-prefix-index.js',
'should name js with prefix');
});

Expand Down Expand Up @@ -534,7 +488,7 @@ suite('webapp-optimize.js', function() {
'</html>\n';
};
htmlOptimizer.serializeNewHTMLDocumentOutput();
assert.equal(writeFile.path, 'test-index.html');
assert.equal(writeFile.path, 'index.html');
assert.equal(writeFileContent,
'<!DOCTYPE docName PUBLIC publicId systemId>\n' +
'<html testnodename="testnodevalue">\n' +
Expand All @@ -549,5 +503,20 @@ suite('webapp-optimize.js', function() {
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.asts = {'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');
});
});
});

0 comments on commit 6e403db

Please sign in to comment.