Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core(entity-classification): classify unknown urls as "unattributable" #15009

Merged
merged 1 commit into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion core/computed/entity-classification.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ class EntityClassification {
*/
function isFirstParty(url) {
const entityUrl = entityByUrl.get(url);
if (!entityUrl) throw new Error('A url not in devtoolsLog was used for first-party check.');
return entityUrl === firstParty;
}

Expand Down
6 changes: 3 additions & 3 deletions core/test/computed/entity-classification-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ describe('Entity Classification computed artifact', () => {
// Make sure only valid network urls with a domain is recognized.
expect(entities).toEqual(['third-party.com']);
expect(result.entityByUrl.size).toBe(1);
// A url that's not present in devtoolsLogs would throw an exception.
expect(() => result.isFirstParty('chrome://version'))
.toThrow('A url not in devtoolsLog was used for first-party check.');
// First party check fails for non-DT-log URLs.
expect(result.isFirstParty('chrome-extension://abcdefghijklmnopqrstuvwxyz/foo/bar.js')).toEqual(false);
expect(result.isFirstParty('chrome://new-tab-page')).toEqual(false);
});
});
36 changes: 36 additions & 0 deletions report/test/renderer/details-renderer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,42 @@ describe('DetailsRenderer', () => {
);
});

it(`marks chrome:// and chrome-extension:// urls as unattributable`, () => {
const el = renderer.render({
type: tableType,
headings: [
{key: 'url', valueType: 'url', label: 'URL'},
{key: 'totalBytes', valueType: 'bytes', label: 'Size (KiB)'},
{key: 'wastedBytes', valueType: 'bytes', label: 'Potential Savings (KiB)'},
],
items: [
{url: 'https://example.com/1', totalBytes: 100, wastedBytes: 500, entity: 'example.com'},
{url: 'https://cdn.com/1', totalBytes: 300, wastedBytes: 700, entity: 'cdn.com'},
{url: 'https://cdn.com/2', totalBytes: 400, wastedBytes: 800, entity: 'cdn.com'},
{url: 'chrome-extension://abcdefghijklmnopqrstuvwxyz/foo/bar.js', totalBytes: 300, wastedBytes: 700},
{url: 'chrome://new-tab-page', totalBytes: 300, wastedBytes: 700},
{url: 'Unattributable', totalBytes: 500, wastedBytes: 500}, // entity not marked.
],
});

assert.deepStrictEqual(
[...el.querySelectorAll('.lh-row--group')[0].children].map(td => td.textContent),
['example.com Cat 1st party', '0.1 KiB', '0.5 KiB'],
'did not render 1st party grouped row correctly'
);
assert.deepStrictEqual(
[...el.querySelectorAll('.lh-row--group')[1].children].map(td => td.textContent),
['cdn.com CDN', '0.7 KiB', '1.5 KiB'],
'did not render CDN category row correctly'
);
assert.deepStrictEqual(
[...el.querySelectorAll('.lh-row--group')[2].children].map(td => td.textContent),
['Unattributable', '1.1 KiB', '1.9 KiB'],
'did not render all Unattributable row'
);
assert.equal(el.querySelectorAll('tr').length, 10, `did not render ${tableType} rows`);
});

it('does not group if entity classification is absent', () => {
const el = renderer.render({
type: tableType,
Expand Down