From b60a4fdffcbb41ffabbc03cf4f2272d8dc908a31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alfonso=20Casta=C3=B1o?= Date: Wed, 21 Oct 2020 13:40:32 +0000 Subject: [PATCH] E2E test for report-only CSP issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New E2E test to verify that the status of the violation is blocked or report-only. DISABLE_THIRD_PARTY_CHECK= Bug: chromium:1139223, chromium:1124712 Change-Id: Ibf01624a069fb83013a8fa162235d307bc3e07ff Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2485086 Commit-Queue: Alfonso CastaƱo Reviewed-by: Sigurd Schneider --- test/e2e/helpers/issues-helpers.ts | 9 ++++++++ test/e2e/issues/BUILD.gn | 5 ++++- test/e2e/issues/report-only_test.ts | 22 +++++++++++++++++++ test/e2e/resources/network/BUILD.gn | 1 + .../network/csp-report-only.rawresponse | 12 ++++++++++ 5 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 test/e2e/issues/report-only_test.ts create mode 100644 test/e2e/resources/network/csp-report-only.rawresponse diff --git a/test/e2e/helpers/issues-helpers.ts b/test/e2e/helpers/issues-helpers.ts index 6b6af2e244..55630ac392 100644 --- a/test/e2e/helpers/issues-helpers.ts +++ b/test/e2e/helpers/issues-helpers.ts @@ -15,6 +15,8 @@ export const AFFECTED_ELEMENT_ICON = '.affected-resource-csp-info-node'; export const ELEMENT_REVEAL_ICON = '.element-reveal-icon'; export const ELEMENTS_PANEL_SELECTOR = '.panel[aria-label="elements"]'; export const SOURCES_LINK = '.affected-source-location > span'; +export const BLOCKED_STATUS = '.affected-resource-blocked-status'; +export const REPORT_ONLY_STATUS = '.affected-resource-report-only-status'; export async function navigateToIssuesTab() { await openPanelViaMoreTools('Issues'); @@ -32,6 +34,13 @@ export async function assertIssueTitle(issueMessage: string) { assert.strictEqual(selectedIssueMessage, issueMessage); } +export async function assertStatus(status: 'blocked'|'report-only') { + const classStatus = status === 'blocked' ? BLOCKED_STATUS : REPORT_ONLY_STATUS; + const issueMessageElement = await waitFor(classStatus); + const selectedIssueMessage = await issueMessageElement.evaluate(node => node.textContent); + assert.strictEqual(selectedIssueMessage, status); +} + export async function expandCategory() { const categoryElement = await waitFor(CATEGORY); const isCategoryExpanded = await categoryElement.evaluate(node => node.classList.contains('expanded')); diff --git a/test/e2e/issues/BUILD.gn b/test/e2e/issues/BUILD.gn index 03e49fb021..2aa9370f4f 100644 --- a/test/e2e/issues/BUILD.gn +++ b/test/e2e/issues/BUILD.gn @@ -5,7 +5,10 @@ import("../../../third_party/typescript/typescript.gni") node_ts_library("issues") { - sources = [ "group-by-categories_test.ts" ] + sources = [ + "group-by-categories_test.ts", + "report-only_test.ts", + ] deps = [ "../../shared", diff --git a/test/e2e/issues/report-only_test.ts b/test/e2e/issues/report-only_test.ts new file mode 100644 index 0000000000..6413408187 --- /dev/null +++ b/test/e2e/issues/report-only_test.ts @@ -0,0 +1,22 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import {goToResource} from '../../shared/helper.js'; +import {describe, it} from '../../shared/mocha-extensions.js'; +import {assertStatus, expandIssue, navigateToIssuesTab} from '../helpers/issues-helpers.js'; + +describe('The Issues tab report-only issues', async () => { + it('should report the violation as blocked', async () => { + await goToResource('elements/element-reveal-inline-issue.html'); + await navigateToIssuesTab(); + await expandIssue(); + await assertStatus('blocked'); + }); + it('should report the violation as report-only', async () => { + await goToResource('network/csp-report-only.rawresponse'); + await navigateToIssuesTab(); + await expandIssue(); + await assertStatus('report-only'); + }); +}); diff --git a/test/e2e/resources/network/BUILD.gn b/test/e2e/resources/network/BUILD.gn index 7249fb4ee4..4fa6686de1 100644 --- a/test/e2e/resources/network/BUILD.gn +++ b/test/e2e/resources/network/BUILD.gn @@ -7,6 +7,7 @@ import("../../../../scripts/build/ninja/copy.gni") copy_to_gen("network") { sources = [ "cacheable.rawresponse", + "csp-report-only.rawresponse", "last-modified.html", "last-modified.rawresponse", "resources-from-cache.html", diff --git a/test/e2e/resources/network/csp-report-only.rawresponse b/test/e2e/resources/network/csp-report-only.rawresponse new file mode 100644 index 0000000000..44cf7d20f9 --- /dev/null +++ b/test/e2e/resources/network/csp-report-only.rawresponse @@ -0,0 +1,12 @@ +200 +Content-Security-Policy-Report-Only: style-src 'self' +Date: Sun, 10 Oct 2010 23:26:07 GMT +Server: Apache/2.2.8 (Ubuntu) mod_ssl/2.2.8 OpenSSL/0.9.8g +Last-Modified: Sun, 26 Sep 2010 22:04:35 GMT +ETag: "csp-report-only.rawresponse" +Accept-Ranges: bytes +Content-Length: 58 +Connection: close +Content-Type: text/html; charset=utf-8 + + \ No newline at end of file