Commit 86ddef65 authored by Maggie Cai's avatar Maggie Cai Committed by Commit Bot

Settings: Implement heuristic for finding site group favicon.

Currently the favicon shown for etld+1 is simply using the favicon of
the first origin. This CL implement heuristic for finding a good
favicon.
The rules are:
1. Find the origin with format "www.etld+1".
2. If there is no origin with format "www.etld+1", find the origin with
largest storage, and use the number of cookies as tie breaker.

BUG=930626,835712

Change-Id: I374e079568020a7a6df6ec80e65736c29eead9ba
Reviewed-on: https://chromium-review.googlesource.com/c/1475561Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarPatti <patricialor@chromium.org>
Commit-Queue: Maggie Cai <mxcai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#634397}
parent a52f490d
...@@ -199,14 +199,34 @@ Polymer({ ...@@ -199,14 +199,34 @@ Polymer({
/** /**
* Get an appropriate favicon that represents this group of eTLD+1 sites as a * Get an appropriate favicon that represents this group of eTLD+1 sites as a
* whole. * whole.
* @param {SiteGroup} siteGroup The eTLD+1 group of origins. * @param {!SiteGroup} siteGroup The eTLD+1 group of origins.
* @return {string} URL that is used for fetching the favicon * @return {string} URL that is used for fetching the favicon
* @private * @private
*/ */
getSiteGroupIcon_: function(siteGroup) { getSiteGroupIcon_: function(siteGroup) {
// TODO(https://crbug.com/835712): Implement heuristic for finding a good const origins = siteGroup.origins;
// favicon. assert(origins);
return siteGroup.origins[0].origin; assert(origins.length >= 1);
if (origins.length == 1) {
return origins[0].origin;
}
// If we can find a origin with format "www.etld+1", use the favicon of this
// origin. Otherwise find the origin with largest storage, and use the
// number of cookies as a tie breaker.
for (const originInfo of origins) {
if (this.toUrl(originInfo.origin).host == 'www.' + siteGroup.etldPlus1) {
return originInfo.origin;
}
}
const getMaxStorage = (max, originInfo) => {
return (
max.usage > originInfo.usage ||
(max.usage == originInfo.usage &&
max.numCookies > originInfo.numCookies) ?
max :
originInfo);
};
return origins.reduce(getMaxStorage, origins[0]).origin;
}, },
/** /**
......
...@@ -240,4 +240,48 @@ suite('SiteEntry', function() { ...@@ -240,4 +240,48 @@ suite('SiteEntry', function() {
}); });
}); });
test('favicon with www.etld+1 chosen for site group', function() {
// Clone this object to avoid propagating changes made in this test.
const testSiteGroup = JSON.parse(JSON.stringify(TEST_MULTIPLE_SITE_GROUP));
testSiteGroup.origins[0].usage = 0;
testSiteGroup.origins[1].usage = 1274;
testSiteGroup.origins[2].usage = 74622;
testElement.siteGroup = testSiteGroup;
Polymer.dom.flush();
assertEquals(
testElement.$.collapseParent.querySelector('site-favicon').url,
'https://www.example.com');
});
test('favicon with largest storage chosen for site group', function() {
// Clone this object to avoid propagating changes made in this test.
const testSiteGroup = JSON.parse(JSON.stringify(TEST_MULTIPLE_SITE_GROUP));
testSiteGroup.origins[0].usage = 0;
testSiteGroup.origins[1].usage = 1274;
testSiteGroup.origins[2].usage = 74622;
testSiteGroup.origins[1].origin = 'https://abc.example.com';
testElement.siteGroup = testSiteGroup;
Polymer.dom.flush();
assertEquals(
testElement.$.collapseParent.querySelector('site-favicon').url,
'https://login.example.com');
});
test('favicon with largest cookies number chosen for site group', function() {
// Clone this object to avoid propagating changes made in this test.
const testSiteGroup = JSON.parse(JSON.stringify(TEST_MULTIPLE_SITE_GROUP));
testSiteGroup.origins[0].usage = 0;
testSiteGroup.origins[1].usage = 1274;
testSiteGroup.origins[2].usage = 1274;
testSiteGroup.origins[0].numCookies = 10;
testSiteGroup.origins[1].numCookies = 3;
testSiteGroup.origins[2].numCookies = 1;
testSiteGroup.origins[1].origin = 'https://abc.example.com';
testElement.siteGroup = testSiteGroup;
Polymer.dom.flush();
assertEquals(
testElement.$.collapseParent.querySelector('site-favicon').url,
'https://abc.example.com');
});
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment