Bug 1059591 - Incorrectly formatted remotely hosted links causes new tab to be empty [r=adw]

Use catch handler of promises to default to empty array on exceptions.
This commit is contained in:
Ed Lee 2014-09-23 15:12:20 -07:00
Родитель ba84f1293f
Коммит f95a84c9c5
2 изменённых файлов: 21 добавлений и 3 удалений

Просмотреть файл

@ -369,7 +369,7 @@ let DirectoryLinksProvider = {
this._enhancedLinks.clear();
// all directory links have a frecency of DIRECTORY_FRECENCY
aCallback(rawLinks.map((link, position) => {
return rawLinks.map((link, position) => {
// Stash the enhanced image for the site
if (link.enhancedImageURI) {
this._enhancedLinks.set(NewTabUtils.extractSite(link.url), link);
@ -378,8 +378,11 @@ let DirectoryLinksProvider = {
link.frecency = DIRECTORY_FRECENCY;
link.lastVisitDate = rawLinks.length - position;
return link;
}));
});
});
}).catch(ex => {
Cu.reportError(ex);
return [];
}).then(aCallback);
},
init: function DirectoryLinksProvider_init() {

Просмотреть файл

@ -426,6 +426,21 @@ add_task(function test_DirectoryLinksProvider_getLinks_noLocaleData() {
yield promiseCleanDirectoryLinksProvider();
});
add_task(function test_DirectoryLinksProvider_getLinks_badData() {
let data = {
"en-US": {
"en-US": [{url: "http://example.com", title: "US"}],
},
};
let dataURI = 'data:application/json,' + JSON.stringify(data);
yield promiseSetupDirectoryLinksProvider({linksURL: dataURI});
// Make sure we get nothing for incorrectly formatted data
let links = yield fetchData();
do_check_eq(links.length, 0);
yield promiseCleanDirectoryLinksProvider();
});
add_task(function test_DirectoryLinksProvider_needsDownload() {
// test timestamping
DirectoryLinksProvider._lastDownloadMS = 0;