From c8a1268df576cfcb92e068ec059d83e2a2f6f663 Mon Sep 17 00:00:00 2001 From: Mathias Bynens Date: Fri, 26 Jun 2020 09:04:50 +0200 Subject: [PATCH] Add e2e test for fake eval in Console This patch ports the following layout test: https://source.chromium.org/chromium/chromium/src/+/master:third_party/blink/web_tests/http/tests/devtools/console/console-eval-fake.js;drc=78e2bc9c2def358a0745878ffc66ce85ee5221d8 CL removing the upstream test: https://chromium-review.googlesource.com/c/chromium/src/+/2270177 Bug: chromium:1099603 Change-Id: Id33fa12254d4bf10f4797aa1f54487a0b3acd4cb Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2270157 Reviewed-by: Peter Marshall Commit-Queue: Mathias Bynens --- test/e2e/console/console-eval-fake_test.ts | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 test/e2e/console/console-eval-fake_test.ts diff --git a/test/e2e/console/console-eval-fake_test.ts b/test/e2e/console/console-eval-fake_test.ts new file mode 100644 index 0000000000..897231a684 --- /dev/null +++ b/test/e2e/console/console-eval-fake_test.ts @@ -0,0 +1,51 @@ +// 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 {assert} from 'chai'; +import {describe, it} from 'mocha'; + +import {click, getBrowserAndPages, pasteText, step} from '../../shared/helper.js'; +import {CONSOLE_TAB_SELECTOR, focusConsolePrompt} from '../helpers/console-helpers.js'; +import {getCurrentConsoleMessages} from '../helpers/console-helpers.js'; + +describe('The Console Tab', async () => { + it('doesn’t break when global `eval` is overwritten', async () => { + const {frontend} = getBrowserAndPages(); + let messages: string[]; + + await step('navigate to the Console tab', async () => { + await click(CONSOLE_TAB_SELECTOR); + await focusConsolePrompt(); + }); + + await step('enter code that overwrites eval', async () => { + await pasteText(` + const foo = 'fooValue'; + globalThis.eval = 'non-function'; + `); + await frontend.keyboard.press('Enter'); + + // Wait for the console to be usable again. + await frontend.waitForFunction(() => { + return document.querySelectorAll('.console-user-command-result').length === 1; + }); + }); + + await step('enter a code snippet', async () => { + await pasteText('foo;'); + await frontend.keyboard.press('Enter'); + }); + + await step('retrieve the console log', async () => { + messages = await getCurrentConsoleMessages(); + }); + + await step('check that the expected output is logged', async () => { + assert.deepEqual(messages, [ + '"non-function"', + '"fooValue"', + ]); + }); + }); +});