Mathias Bynens | 7472956 | 2020-03-19 15:13:02 | [diff] [blame] | 1 | // Copyright 2020 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Alex Rudenko | e92fe9d | 2023-01-30 13:12:23 | [diff] [blame] | 5 | import { |
| 6 | click, |
| 7 | clickElement, |
| 8 | scrollElementIntoView, |
| 9 | waitFor, |
| 10 | waitForAria, |
| 11 | waitForFunction, |
| 12 | } from '../../shared/helper.js'; |
Mathias Bynens | 7472956 | 2020-03-19 15:13:02 | [diff] [blame] | 13 | |
Simon Zünd | ad3042b | 2022-11-16 06:44:35 | [diff] [blame] | 14 | export const openPanelViaMoreTools = async (panelTitle: string) => { |
Mathias Bynens | 7472956 | 2020-03-19 15:13:02 | [diff] [blame] | 15 | // Head to the triple dot menu. |
Alex Rudenko | e92fe9d | 2023-01-30 13:12:23 | [diff] [blame] | 16 | await click('aria/Customize and control DevTools'); |
Mathias Bynens | 7472956 | 2020-03-19 15:13:02 | [diff] [blame] | 17 | |
Johan Bay | f04b99c | 2020-11-03 15:38:41 | [diff] [blame] | 18 | // Open the “More Tools” option. |
Simon Zünd | ad3042b | 2022-11-16 06:44:35 | [diff] [blame] | 19 | const moreTools = await waitForAria('More tools[role="menuitem"]'); |
Johan Bay | f04b99c | 2020-11-03 15:38:41 | [diff] [blame] | 20 | await moreTools.hover(); |
Mathias Bynens | 7472956 | 2020-03-19 15:13:02 | [diff] [blame] | 21 | |
Johan Bay | f04b99c | 2020-11-03 15:38:41 | [diff] [blame] | 22 | // Click the desired menu item |
Alex Rudenko | e92fe9d | 2023-01-30 13:12:23 | [diff] [blame] | 23 | await click(`aria/${panelTitle}[role="menuitem"]`); |
Johan Bay | f04b99c | 2020-11-03 15:38:41 | [diff] [blame] | 24 | |
| 25 | // Wait for the corresponding panel to appear. |
Simon Zünd | ad3042b | 2022-11-16 06:44:35 | [diff] [blame] | 26 | await waitForAria(`${panelTitle} panel[role="tabpanel"]`); |
Mathias Bynens | 7472956 | 2020-03-19 15:13:02 | [diff] [blame] | 27 | }; |
Sigurd Schneider | 92a1bd8 | 2020-06-16 10:28:57 | [diff] [blame] | 28 | |
| 29 | export const openSettingsTab = async (tabTitle: string) => { |
Brian Cui | 69ed1bc | 2020-08-26 23:18:09 | [diff] [blame] | 30 | const gearIconSelector = '.toolbar-button[aria-label="Settings"]'; |
Sigurd Schneider | 92a1bd8 | 2020-06-16 10:28:57 | [diff] [blame] | 31 | const settingsMenuSelector = `.tabbed-pane-header-tab[aria-label="${tabTitle}"]`; |
| 32 | const panelSelector = `.view-container[aria-label="${tabTitle} panel"]`; |
| 33 | |
Brian Cui | 69ed1bc | 2020-08-26 23:18:09 | [diff] [blame] | 34 | // Click on the Settings Gear toolbar icon. |
| 35 | await click(gearIconSelector); |
Sigurd Schneider | 92a1bd8 | 2020-06-16 10:28:57 | [diff] [blame] | 36 | |
Brian Cui | 69ed1bc | 2020-08-26 23:18:09 | [diff] [blame] | 37 | // Click on the Settings tab and wait for the panel to appear. |
Sigurd Schneider | 92a1bd8 | 2020-06-16 10:28:57 | [diff] [blame] | 38 | await waitFor(settingsMenuSelector); |
Sigurd Schneider | 92a1bd8 | 2020-06-16 10:28:57 | [diff] [blame] | 39 | await click(settingsMenuSelector); |
| 40 | await waitFor(panelSelector); |
| 41 | }; |
Patrick Brosset | f398c10 | 2020-10-14 07:35:08 | [diff] [blame] | 42 | |
Eric Leese | a6533f0 | 2022-07-19 15:33:04 | [diff] [blame] | 43 | export const closeSettings = async () => { |
| 44 | await click('.dialog-close-button'); |
| 45 | }; |
| 46 | |
PhistucK | 257ad69 | 2022-08-29 14:36:19 | [diff] [blame] | 47 | export const togglePreferenceInSettingsTab = async (label: string, shouldBeChecked?: boolean) => { |
Patrick Brosset | f398c10 | 2020-10-14 07:35:08 | [diff] [blame] | 48 | await openSettingsTab('Preferences'); |
Kim-Anh Tran | cd25216 | 2021-06-16 11:41:40 | [diff] [blame] | 49 | |
PhistucK | 257ad69 | 2022-08-29 14:36:19 | [diff] [blame] | 50 | const selector = `[aria-label="${label}"]`; |
Kim-Anh Tran | cd25216 | 2021-06-16 11:41:40 | [diff] [blame] | 51 | await scrollElementIntoView(selector); |
| 52 | const preference = await waitFor(selector); |
| 53 | |
| 54 | const value = await preference.evaluate(checkbox => (checkbox as HTMLInputElement).checked); |
| 55 | |
PhistucK | 257ad69 | 2022-08-29 14:36:19 | [diff] [blame] | 56 | if (value !== shouldBeChecked) { |
Alex Rudenko | e92fe9d | 2023-01-30 13:12:23 | [diff] [blame] | 57 | await clickElement(preference); |
Kim-Anh Tran | cd25216 | 2021-06-16 11:41:40 | [diff] [blame] | 58 | |
PhistucK | 257ad69 | 2022-08-29 14:36:19 | [diff] [blame] | 59 | await waitForFunction(async () => { |
| 60 | const newValue = await preference.evaluate(checkbox => (checkbox as HTMLInputElement).checked); |
| 61 | return newValue !== value; |
| 62 | }); |
| 63 | } |
Kim-Anh Tran | cd25216 | 2021-06-16 11:41:40 | [diff] [blame] | 64 | |
Eric Leese | a6533f0 | 2022-07-19 15:33:04 | [diff] [blame] | 65 | await closeSettings(); |
| 66 | }; |
| 67 | |
| 68 | export const setIgnoreListPattern = async (pattern: string) => { |
| 69 | await openSettingsTab('Ignore List'); |
| 70 | await click('[aria-label="Add filename pattern"]'); |
Eric Leese | 9441d87 | 2022-09-23 09:19:31 | [diff] [blame] | 71 | const textBox = await waitFor('[aria-label="Add Pattern"]'); |
Alex Rudenko | e92fe9d | 2023-01-30 13:12:23 | [diff] [blame] | 72 | await clickElement(textBox); |
Eric Leese | a6533f0 | 2022-07-19 15:33:04 | [diff] [blame] | 73 | await textBox.type(pattern); |
| 74 | await textBox.type('\n'); |
| 75 | await waitFor(`[title="Ignore scripts whose names match '${pattern}'"]`); |
| 76 | await closeSettings(); |
Patrick Brosset | f398c10 | 2020-10-14 07:35:08 | [diff] [blame] | 77 | }; |
Eric Leese | 9441d87 | 2022-09-23 09:19:31 | [diff] [blame] | 78 | |
| 79 | export const toggleIgnoreListing = async (enable: boolean) => { |
| 80 | await openSettingsTab('Ignore List'); |
| 81 | const enabledPattern = '.ignore-list-options:not(.ignore-listing-disabled)'; |
| 82 | const disabledPattern = '.ignore-list-options.ignore-listing-disabled'; |
| 83 | await waitFor(enable ? disabledPattern : enabledPattern); |
Elorm Coch | 34ad334 | 2023-06-06 20:15:59 | [diff] [blame^] | 84 | await click('[title="Enable Ignore Listing"]'); |
Eric Leese | 9441d87 | 2022-09-23 09:19:31 | [diff] [blame] | 85 | await waitFor(enable ? enabledPattern : disabledPattern); |
| 86 | await closeSettings(); |
| 87 | }; |