Commit cd606108 authored by Johannes Henkel's avatar Johannes Henkel Committed by Commit Bot

Starting point for porting BlockedByClient_NetworkObserver_Test to LayoutTests.

This test is currently in
headless/lib/headless_devtools_client_browsertests.cc.
I'm working on porting it to Javascript for easier maintenance.
This PR doesn't cover the entire test yet, so I'll follow up with
  more but figure it'd be good to check in a snapshot to begin with.

Bug: 838291
Change-Id: I647e0fef263adde129f7c12d48283708a4e84ca0
Reviewed-on: https://chromium-review.googlesource.com/1066940Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Commit-Queue: Johannes Henkel <johannes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#560371}
parent 4b089c4c
Tests that 'BlockedByClient' network interception is executed with blockedReason set to 'inspector' (=devtools).
request will be sent for http://127.0.0.1:8000/inspector-protocol/network/resources/to-be-blocked.html
blocking http://127.0.0.1:8000/inspector-protocol/network/resources/to-be-blocked.html
loading failed for http://127.0.0.1:8000/inspector-protocol/network/resources/to-be-blocked.html: blockedReason = inspector
request will be sent for http://127.0.0.1:8000/inspector-protocol/network/resources/page-with-subresource.html
continuing to load http://127.0.0.1:8000/inspector-protocol/network/resources/page-with-subresource.html
blocking http://127.0.0.1:8000/inspector-protocol/network/resources/to-be-blocked.jpg
request will be sent for http://127.0.0.1:8000/inspector-protocol/network/resources/to-be-blocked.jpg
loading failed for http://127.0.0.1:8000/inspector-protocol/network/resources/to-be-blocked.jpg: blockedReason = inspector
(async function(testRunner) {
var {page, session, dp} = await testRunner.startBlank(
`Tests that 'BlockedByClient' network interception is executed with blockedReason set to 'inspector' (=devtools).`);
await dp.Network.enable();
await dp.Page.enable();
await dp.Network.setRequestInterception({
patterns: [{ urlPattern: '*' }]
});
dp.Network.onRequestIntercepted(event => {
const url = event.params.request.url;
if (url.endsWith('page-with-subresource.html')) {
testRunner.log(`continuing to load ${url}`);
dp.Network.continueInterceptedRequest({
interceptionId: event.params.interceptionId,
});
} else {
testRunner.log(`blocking ${url}`);
dp.Network.continueInterceptedRequest({
interceptionId: event.params.interceptionId,
errorReason: 'BlockedByClient'
});
}
});
// We map the requestIds to URLs since these are stable within this test.
// Also this shows both the requests that we're blocking and the ones that
// continue.
const urlByRequestId = new Map();
dp.Network.onRequestWillBeSent(event => {
const requestId = event.params.requestId;
const url = event.params.request.url;
testRunner.log(`request will be sent for ${url}`);
urlByRequestId.set(event.params.requestId, event.params.request.url);
});
// Log the requests that are blocked, with the blockedReason indicating
// that they were blocked via the devtools protocol (inspector).
dp.Network.onLoadingFailed(event => {
const url = urlByRequestId.get(event.params.requestId);
const blockedReason = event.params.blockedReason;
testRunner.log(`loading failed for ${url}: blockedReason = ${blockedReason}`);
});
await dp.Runtime.enable();
// Test blocking a page. This page doesn't exist so it would 404 but that's
// OK because the interception / blocking happens before any network fetch
// would take place anyway.
await page.navigate('./resources/to-be-blocked.html');
// This page will not be blocked so it just passes through in the interception.
// The resource exists, and references to-be-blocked.jpg, a subresource.
await page.navigate('./resources/page-with-subresource.html');
testRunner.completeTest();
})
<!-- For testing subresource blocking in blocked-by-client-network-observer.js;
this page references a subresource which will be blocked in the test.
The image doesn't exist so this would 404 but it doesn't matter because
blocking happens before the resource gets fetched anyway. -->
<html><body><img src=to-be-blocked.jpg></body></html>
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