Commit 6c2b5689 authored by Joey Arhar's avatar Joey Arhar Committed by Commit Bot

[DevTools] Add support for filtering blob urls in NetworkLog

Bug: 607240
Change-Id: I2595c44cdb80a9abc9098bd66fb38145b697a6d0
Reviewed-on: https://chromium-review.googlesource.com/c/1447231
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#628407}
parent 73ebda83
...@@ -46,10 +46,17 @@ Common.ParsedURL = class { ...@@ -46,10 +46,17 @@ Common.ParsedURL = class {
this.folderPathComponents = ''; this.folderPathComponents = '';
this.lastPathComponent = ''; this.lastPathComponent = '';
const match = url.match(Common.ParsedURL._urlRegex()); const isBlobUrl = this.url.startsWith('blob:');
const urlToMatch = isBlobUrl ? url.substring(5) : url;
const match = urlToMatch.match(Common.ParsedURL._urlRegex());
if (match) { if (match) {
this.isValid = true; this.isValid = true;
this.scheme = match[2].toLowerCase(); if (isBlobUrl) {
this._blobInnerScheme = match[2].toLowerCase();
this.scheme = 'blob';
} else {
this.scheme = match[2].toLowerCase();
}
this.user = match[3]; this.user = match[3];
this.host = match[4]; this.host = match[4];
this.port = match[5]; this.port = match[5];
...@@ -61,6 +68,10 @@ Common.ParsedURL = class { ...@@ -61,6 +68,10 @@ Common.ParsedURL = class {
this.scheme = 'data'; this.scheme = 'data';
return; return;
} }
if (this.url.startsWith('blob:')) {
this.scheme = 'blob';
return;
}
if (this.url === 'about:blank') { if (this.url === 'about:blank') {
this.scheme = 'about'; this.scheme = 'about';
return; return;
...@@ -296,6 +307,8 @@ Common.ParsedURL = class { ...@@ -296,6 +307,8 @@ Common.ParsedURL = class {
if (this.isDataURL()) if (this.isDataURL())
return this.dataURLDisplayName(); return this.dataURLDisplayName();
if (this.isBlobURL())
return this.url;
if (this.isAboutBlank()) if (this.isAboutBlank())
return this.url; return this.url;
...@@ -333,6 +346,13 @@ Common.ParsedURL = class { ...@@ -333,6 +346,13 @@ Common.ParsedURL = class {
return this.scheme === 'data'; return this.scheme === 'data';
} }
/**
* @return {boolean}
*/
isBlobURL() {
return this.url.startsWith('blob:');
}
/** /**
* @return {string} * @return {string}
*/ */
...@@ -355,7 +375,8 @@ Common.ParsedURL = class { ...@@ -355,7 +375,8 @@ Common.ParsedURL = class {
securityOrigin() { securityOrigin() {
if (this.isDataURL()) if (this.isDataURL())
return 'data:'; return 'data:';
return this.scheme + '://' + this.domain(); const scheme = this.isBlobURL() ? this._blobInnerScheme : this.scheme;
return scheme + '://' + this.domain();
} }
/** /**
......
...@@ -116,6 +116,7 @@ Network.NetworkLogView = class extends UI.VBox { ...@@ -116,6 +116,7 @@ Network.NetworkLogView = class extends UI.VBox {
this._dataURLFilterUI = new UI.CheckboxFilterUI( this._dataURLFilterUI = new UI.CheckboxFilterUI(
'hide-data-url', Common.UIString('Hide data URLs'), true, this._networkHideDataURLSetting); 'hide-data-url', Common.UIString('Hide data URLs'), true, this._networkHideDataURLSetting);
this._dataURLFilterUI.addEventListener(UI.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this); this._dataURLFilterUI.addEventListener(UI.FilterUI.Events.FilterChanged, this._filterChanged.bind(this), this);
this._dataURLFilterUI.element().title = ls`Hides data: and blob: URLs`;
filterBar.addFilter(this._dataURLFilterUI); filterBar.addFilter(this._dataURLFilterUI);
const filterItems = const filterItems =
...@@ -1351,7 +1352,7 @@ Network.NetworkLogView = class extends UI.VBox { ...@@ -1351,7 +1352,7 @@ Network.NetworkLogView = class extends UI.VBox {
const categoryName = request.resourceType().category().title; const categoryName = request.resourceType().category().title;
if (!this._resourceCategoryFilterUI.accept(categoryName)) if (!this._resourceCategoryFilterUI.accept(categoryName))
return false; return false;
if (this._dataURLFilterUI.checked() && request.parsedURL.isDataURL()) if (this._dataURLFilterUI.checked() && (request.parsedURL.isDataURL() || request.parsedURL.isBlobURL()))
return false; return false;
if (request.statusText === 'Service Worker Fallback Required') if (request.statusText === 'Service Worker Fallback Required')
return false; return false;
......
...@@ -553,6 +553,9 @@ SDK.NetworkRequest = class extends Common.Object { ...@@ -553,6 +553,9 @@ SDK.NetworkRequest = class extends Common.Object {
if (this._parsedURL.isDataURL()) { if (this._parsedURL.isDataURL()) {
this._name = this._parsedURL.dataURLDisplayName(); this._name = this._parsedURL.dataURLDisplayName();
this._path = ''; this._path = '';
} else if (this._parsedURL.isBlobURL()) {
this._name = this._parsedURL.url;
this._path = '';
} else if (this._parsedURL.isAboutBlank()) { } else if (this._parsedURL.isAboutBlank()) {
this._name = this._parsedURL.url; this._name = this._parsedURL.url;
this._path = ''; this._path = '';
......
...@@ -39,4 +39,10 @@ Found results: 1 ...@@ -39,4 +39,10 @@ Found results: 1
filterText: -is:from-cache filterText: -is:from-cache
Found results: 3 Found results: 3
hide data URLs unchecked
Found results: 6
hide data URLs checked
Found results: 4
...@@ -9,17 +9,20 @@ ...@@ -9,17 +9,20 @@
await NetworkTestRunner.clearNetworkCache(); await NetworkTestRunner.clearNetworkCache();
async function makeFetchPromise(url) {
return new Promise(resolve => {
NetworkTestRunner.makeFetch(url, {}, resolve);
});
}
NetworkTestRunner.recordNetwork(); NetworkTestRunner.recordNetwork();
NetworkTestRunner.makeFetch('resources/style.css', {}, ensureAllResources); await makeFetchPromise('resources/style.css');
NetworkTestRunner.makeFetch('resources/abe.png', {}, () => { await makeFetchPromise('resources/abe.png');
// Ensures result is cached. await makeFetchPromise('resources/abe.png'); // Ensure result is cached.
NetworkTestRunner.makeFetch('resources/abe.png', {}, ensureAllResources); await makeFetchPromise('missing/foo.bar');
ensureAllResources();
});
NetworkTestRunner.makeFetch('missing/foo.bar', {}, ensureAllResources);
var filterChecks = [ const filterChecks = [
'-.css', '-.css',
'-.png', '-.png',
'css', 'css',
...@@ -35,34 +38,44 @@ ...@@ -35,34 +38,44 @@
'-is:from-cache', '-is:from-cache',
]; ];
var resourceCount = 0; for (const filterText of filterChecks) {
var totalResourceCount = 4; TestRunner.addResult('filterText: ' + filterText);
function ensureAllResources() { setNetworkLogFilter(filterText);
if (++resourceCount >= totalResourceCount) printNetworkLog();
checkFilters();
} }
setNetworkLogFilter('');
await TestRunner.evaluateInPageAsync(
`fetch('data:;base64,c2VuZGluZyB0aGlzIHV0Zi04IHN0cmluZyBhcyBhIGJpbmFyeSBtZXNzYWdlLi4u')`);
await TestRunner.evaluateInPageAsync(
`fetch(URL.createObjectURL(new Blob(new Uint8Array([1, 2, 3, 4]))))`);
UI.panels.network._networkLogView._filterChanged(null);
function checkFilters() { TestRunner.addResult('hide data URLs unchecked');
for (var filterText of filterChecks) { printNetworkLog();
TestRunner.addResult('filterText: ' + filterText);
setNetworkLogFilter(filterText);
var nodes = UI.panels.network._networkLogView.flatNodesList(); UI.panels.network._networkLogView._dataURLFilterUI.setChecked(true);
var foundNodesCount = 0; UI.panels.network._networkLogView._filterChanged(null);
for (var i = 0; i < nodes.length; i++) { TestRunner.addResult('hide data URLs checked');
if (!nodes[i][Network.NetworkLogView._isFilteredOutSymbol]) printNetworkLog();
foundNodesCount++;
}
TestRunner.addResult('Found results: ' + foundNodesCount); TestRunner.completeTest();
TestRunner.addResult('');
function printNetworkLog() {
const nodes = UI.panels.network._networkLogView.flatNodesList();
let foundNodesCount = 0;
for (let i = 0; i < nodes.length; i++) {
if (!nodes[i][Network.NetworkLogView._isFilteredOutSymbol])
foundNodesCount++;
} }
TestRunner.completeTest();
TestRunner.addResult('Found results: ' + foundNodesCount);
TestRunner.addResult('');
} }
/** /**
* @param {string} value * @param {string} value
*/ */
function setNetworkLogFilter(value) { function setNetworkLogFilter(value) {
UI.panels.network._networkLogView._textFilterUI.setValue(value); UI.panels.network._networkLogView._textFilterUI.setValue(value);
UI.panels.network._networkLogView._filterChanged(null); // event not used in this method, so passing null UI.panels.network._networkLogView._filterChanged(null); // event not used in this method, so passing null
......
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