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

Commit

Permalink
Merge pull request #20983 from KevinGrandon/bug_1030200_collection_er…
Browse files Browse the repository at this point in the history
…ror_localization

Bug 1030200 - [vertical] Smart Collection name is not localized in offline-webresults error message
  • Loading branch information
KevinGrandon committed Jun 25, 2014
2 parents 2713048 + 5933810 commit 77ca53a
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 18 deletions.
7 changes: 7 additions & 0 deletions apps/collection/js/objects.js
Expand Up @@ -76,6 +76,13 @@
};

BaseCollection.prototype = {

get localizedName() {
// l10n prefix taken from /shared/locales/collection_categories
var l10nId = 'collection-categoryId-' + this.categoryId;
return navigator.mozL10n.get(l10nId) || this.name;
},

// get a fresh copy of editable properties from db
// useful when a background task (like NativeInfo) updates the db while
// a running process has a collection object reference
Expand Down
4 changes: 2 additions & 2 deletions apps/collection/js/view_apps.js
Expand Up @@ -56,7 +56,7 @@
loading(false);

var msg = navigator.mozL10n.get('offline-webresults', {
collectionName: collection.name
collectionName: collection.localizedName
});
elements.offlineMessage.innerHTML = msg;
elements.offline.classList.add('show');
Expand All @@ -72,7 +72,7 @@
collection.addWebResults(response.response.apps);
collection.render(grid);

}, onResponse);
}, onOffline);

This comment has been minimized.

Copy link
@ranbena

ranbena Jun 26, 2014

@KevinGrandon We should discuss this change.

}

function loading(should) {
Expand Down
16 changes: 5 additions & 11 deletions apps/collection/js/view_collection.js
Expand Up @@ -14,24 +14,21 @@
name: document.getElementById('name')
};

function getLocalizedName(collection) {
// l10n prefix taken from /shared/locales/collection_categories
var l10nId = 'collection-categoryId-' + collection.categoryId;
return navigator.mozL10n.get(l10nId) || collection.name;
}

function updateTitle(element, collection) {
element.textContent = getLocalizedName(collection);
element.textContent = collection.localizedName;
}

function HandleView(activity) {
loading();

var data = activity.source.data;

// create collection object
var collection = BaseCollection.create(data);

// XXX: in 2.1 we can use a better approach of just setting the l10n id
// see Bug 992473
var l10nUpdateHander = updateTitle.bind(this, elements.name, data);
var l10nUpdateHander = updateTitle.bind(this, elements.name, collection);
navigator.mozL10n.ready(l10nUpdateHander);
window.addEventListener('localized', l10nUpdateHander);

Expand All @@ -45,9 +42,6 @@
activity.postResult('close');
});

// create collection object
var collection = BaseCollection.create(data);

loading(false);

/* jshint -W031 */
Expand Down
3 changes: 2 additions & 1 deletion apps/collection/test/unit/view_collection_test.js
Expand Up @@ -56,7 +56,8 @@ suite('view > ', function() {

test('renders a collection', function(done) {

var renderStub = this.sinon.stub(BaseCollection, 'create');
var renderStub = this.sinon.stub(BaseCollection, 'create')
.returns({});

navigator.mozSetMessageHandler.mTrigger('activity', {
source: {
Expand Down
23 changes: 23 additions & 0 deletions apps/verticalhome/test/marionette/collection_test.js
Expand Up @@ -99,6 +99,29 @@ marionette('Vertical - Collection', function() {
client.waitFor(function() {
return expected === collectionIcon.text();
});

server.failAll();

// Now verify the translation inside of the offline message
collectionIcon.tap();

client.switchToFrame();
client.apps.switchToApp(Collection.URL);

var offlineMessage = client.helper.waitForElement(
selectors.offlineMessage);

// Collections named are stubbed in gaia properties. See:
// shared/locales/collection_categories/collection_categories.fr.properties
assert.ok(offlineMessage.text().indexOf(expected) !== -1);

server.unfailAll();

client.executeScript(function() {
window.dispatchEvent(new CustomEvent('online'));
});

client.helper.waitForElementToDisappear(offlineMessage);
});

test('pin collection web result', function() {
Expand Down
20 changes: 20 additions & 0 deletions apps/verticalhome/test/marionette/eme_server/child.js
Expand Up @@ -12,6 +12,7 @@ var fsPath = require('path');
var EventEmitter = require('events').EventEmitter;

function writeJSON(res, object) {
object = object || {};
var json = JSON.stringify(object);
res.writeHead(200, {
'Content-Length': Buffer.byteLength(json),
Expand All @@ -36,6 +37,7 @@ function EmeServer(root, routes) {
this.root = root;
this.routes = routes;
this._settings = {};
this.fail = false;
}

EmeServer.prototype = {
Expand All @@ -44,6 +46,14 @@ EmeServer.prototype = {
requestHandler: function() {
var routes = this.routes;
return function(req, res) {
// Fail requests
if (req.url.indexOf('/settings') !== 0 && this.fail) {
process.nextTick(function() {
req.socket.destroy();
});
return;
}

var handler = routes[req.url] || routes['*'];
// routes are always invoked with the context of the server.
return handler.call(this, req, res);
Expand Down Expand Up @@ -73,6 +83,16 @@ var emeServer = new EmeServer(process.argv[2], {
writeJSON(res, json);
},

'/settings/failAll': function(req, res) {
this.fail = true;
writeJSON(res);
},

'/settings/unfailAll': function(req, res) {
this.fail = false;
writeJSON(res);
},

/**
* Catch all handler which serves up static assets.
*/
Expand Down
35 changes: 34 additions & 1 deletion apps/verticalhome/test/marionette/eme_server/parent.js
Expand Up @@ -2,6 +2,24 @@
/* global module, __dirname */
var fork = require('child_process').fork;

/**
* Issue a POST request via marionette.
*/
function post(client, url, json) {
json = json || {};
// must run in chrome so we can do cross domain xhr
client = client.scope({ context: 'chrome' });
return client.executeAsyncScript(function(url, json) {
var xhr = new XMLHttpRequest();
xhr.open('POST', url, true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onload = function() {
marionetteScriptFinished(xhr.response);
};
xhr.send(json);
}, [url, JSON.stringify(json)]);
}

function EmeServer(root, marionette, port, proc) {
this.root = root;
this.marionette = marionette;
Expand All @@ -13,7 +31,22 @@ EmeServer.prototype = {
close: function(callback) {
this.process.kill();
this.process.once('exit', callback.bind(this, null));
}
},

/**
* Indicate to the server that all requests should be given a response with
* headers but then the socket should be closed shortly after that time.
*/
failAll: function() {
return post(this.marionette, this.url + '/settings/failAll');
},

/**
* Allow requests to to proceed without failure after calling `.failAll`.
*/
unfailAll: function() {
return post(this.marionette, this.url + '/settings/unfailAll');
},
};

/**
Expand Down
4 changes: 3 additions & 1 deletion apps/verticalhome/test/marionette/lib/collection.js
Expand Up @@ -31,7 +31,9 @@ Collection.Selectors = {
firstWebResultPinned: 'gaia-grid .divider + .icon',

allDividers: 'gaia-grid .divider',
allIcons: 'gaia-grid .icon'
allIcons: 'gaia-grid .icon',

offlineMessage: '#offline-message'
};

Collection.prototype = {
Expand Down
4 changes: 2 additions & 2 deletions apps/verticalhome/test/marionette/server/parent.js
Expand Up @@ -3,8 +3,8 @@
var fork = require('child_process').fork;

/**
issue a POST request via marionette
*/
* Issue a POST request via marionette.
*/
function post(client, url, json) {
// must run in chrome so we can do cross domain xhr
client = client.scope({ context: 'chrome' });
Expand Down

0 comments on commit 77ca53a

Please sign in to comment.