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

Commit

Permalink
Bug 832376 - The default icon doesn't appear when manifest has an inv…
Browse files Browse the repository at this point in the history
…alid icon URL - stays in "downloading" mode r=daleharvey a=tef+

- fix homescreen tests, had to change the TextOverflowDetective for that
- Don't use the stored old rendered icon if it's not a proper blob.
  • Loading branch information
julienw committed Jan 23, 2013
1 parent c1b8f38 commit a9f8b47
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 10 deletions.
30 changes: 21 additions & 9 deletions apps/homescreen/js/page.js
Expand Up @@ -183,8 +183,9 @@ Icon.prototype = {
},

loadCachedIcon: function icon_loadCachedImage() {
if ('oldRenderedIcon' in this.descriptor) {
this.renderBlob(this.descriptor.oldRenderedIcon);
var oldRenderedIcon = this.descriptor.oldRenderedIcon;
if (oldRenderedIcon && oldRenderedIcon instanceof Blob) {
this.renderBlob(oldRenderedIcon);
} else {
this.loadImageData();
}
Expand Down Expand Up @@ -823,14 +824,25 @@ dockProto.getChildren = function dk_getChildren() {
HTMLCollection.prototype.indexOf = Array.prototype.indexOf;

const TextOverflowDetective = (function() {
var iconFakeWrapperWidht = document.querySelector('#fake-icon-name-wrapper').
offsetWidth;
var iconFakeLabel = document.querySelector('#fake-icon-name');

return {
check: function od_check(text) {
iconFakeLabel.textContent = text;
return iconFakeLabel.offsetWidth >= iconFakeWrapperWidht;
var iconFakeWrapperWidth;
var iconFakeLabel;

function init() {
var fakeIconName = document.querySelector('#fake-icon-name-wrapper');
iconFakeWrapperWidth = fakeIconName.offsetWidth;
iconFakeLabel = document.querySelector('#fake-icon-name');
}

function check(text) {
if (! iconFakeLabel || ! iconFakeWrapperWidth) {
init();
}
iconFakeLabel.textContent = text;
return iconFakeLabel.offsetWidth >= iconFakeWrapperWidth;
}

return {
check: check
};
})();
62 changes: 61 additions & 1 deletion apps/homescreen/test/unit/page_test.js
@@ -1,3 +1,5 @@
'use strict';

requireApp('homescreen/test/unit/mock_app.js');
requireApp('homescreen/test/unit/mock_xmlhttprequest.js');
requireApp('homescreen/test/unit/mock_grid_manager.js');
Expand All @@ -19,7 +21,7 @@ mocksForHomescreenPageTest.forEach(function(mockName) {
suite('page.js >', function() {
var mocksHelper;

var SMALL_TIMEOUT = 100;
var containerNode;

suiteSetup(function() {
mocksHelper = new MocksHelper(mocksForHomescreenPageTest);
Expand All @@ -28,10 +30,23 @@ suite('page.js >', function() {

setup(function() {
mocksHelper.setup();

var fakeIconMarkup =
'<div id="fake-icon">' +
'<span id="fake-icon-name-wrapper" class="labelWrapper">' +
'<span id="fake-icon-name"></span>' +
'</span>' +
'</div>';

containerNode = document.createElement('div');
containerNode.innerHTML = fakeIconMarkup;
document.body.appendChild(containerNode);
});

teardown(function() {
mocksHelper.teardown();

containerNode.parentNode.removeChild(containerNode);
});

suiteTeardown(function() {
Expand Down Expand Up @@ -136,6 +151,51 @@ suite('page.js >', function() {
});
});

suite('http url icon, wrong old rendered icon >', function() {
var anIconAsHttpUrl = 'http://some.icon.name/icon.png';

setup(function() {
var app = new MockApp();
descriptor = {
manifestURL: app.manifestURL,
name: app.name,
icon: anIconAsHttpUrl,
oldRenderedIcon: undefined
};

icon = new Icon(descriptor, app);
});

suite('XHR works fine >', function() {
setup(function() {
icon.render(iconsContainer);
});

test('icon should be rendered', function() {
// note: this doesn't test if the icon is actually displayed
// but merely that we don't fail somewhere
assert.equal(iconsContainer.querySelectorAll('li').length, 1);
});

test('should load the icon with XHR', function() {
assert.equal(MockXMLHttpRequest.mLastOpenedUrl, anIconAsHttpUrl);
});
});


suite('XHR throws an exception >', function() {
setup(function() {
MockXMLHttpRequest.mThrowAtNextSend();
icon.render(iconsContainer);
});
test('icon should still be rendered', function() {
// note: this doesn't test if the icon is actually displayed
// but merely that we don't fail somewhere
assert.equal(iconsContainer.querySelectorAll('li').length, 1);
});
});
});


});

Expand Down

0 comments on commit a9f8b47

Please sign in to comment.