blob: 99624e0289f19fea472251aef0b09a55abc5d885 [file] [log] [blame]
Mathias Bynens74729562020-03-19 15:13:021// 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 Rudenkoe92fe9d2023-01-30 13:12:235import {
6 click,
7 clickElement,
8 scrollElementIntoView,
9 waitFor,
10 waitForAria,
11 waitForFunction,
12} from '../../shared/helper.js';
Mathias Bynens74729562020-03-19 15:13:0213
Simon Zündad3042b2022-11-16 06:44:3514export const openPanelViaMoreTools = async (panelTitle: string) => {
Mathias Bynens74729562020-03-19 15:13:0215 // Head to the triple dot menu.
Alex Rudenkoe92fe9d2023-01-30 13:12:2316 await click('aria/Customize and control DevTools');
Mathias Bynens74729562020-03-19 15:13:0217
Johan Bayf04b99c2020-11-03 15:38:4118 // Open the “More Tools” option.
Simon Zündad3042b2022-11-16 06:44:3519 const moreTools = await waitForAria('More tools[role="menuitem"]');
Johan Bayf04b99c2020-11-03 15:38:4120 await moreTools.hover();
Mathias Bynens74729562020-03-19 15:13:0221
Johan Bayf04b99c2020-11-03 15:38:4122 // Click the desired menu item
Alex Rudenkoe92fe9d2023-01-30 13:12:2323 await click(`aria/${panelTitle}[role="menuitem"]`);
Johan Bayf04b99c2020-11-03 15:38:4124
25 // Wait for the corresponding panel to appear.
Simon Zündad3042b2022-11-16 06:44:3526 await waitForAria(`${panelTitle} panel[role="tabpanel"]`);
Mathias Bynens74729562020-03-19 15:13:0227};
Sigurd Schneider92a1bd82020-06-16 10:28:5728
29export const openSettingsTab = async (tabTitle: string) => {
Brian Cui69ed1bc2020-08-26 23:18:0930 const gearIconSelector = '.toolbar-button[aria-label="Settings"]';
Sigurd Schneider92a1bd82020-06-16 10:28:5731 const settingsMenuSelector = `.tabbed-pane-header-tab[aria-label="${tabTitle}"]`;
32 const panelSelector = `.view-container[aria-label="${tabTitle} panel"]`;
33
Brian Cui69ed1bc2020-08-26 23:18:0934 // Click on the Settings Gear toolbar icon.
35 await click(gearIconSelector);
Sigurd Schneider92a1bd82020-06-16 10:28:5736
Brian Cui69ed1bc2020-08-26 23:18:0937 // Click on the Settings tab and wait for the panel to appear.
Sigurd Schneider92a1bd82020-06-16 10:28:5738 await waitFor(settingsMenuSelector);
Sigurd Schneider92a1bd82020-06-16 10:28:5739 await click(settingsMenuSelector);
40 await waitFor(panelSelector);
41};
Patrick Brossetf398c102020-10-14 07:35:0842
Eric Leesea6533f02022-07-19 15:33:0443export const closeSettings = async () => {
44 await click('.dialog-close-button');
45};
46
PhistucK257ad692022-08-29 14:36:1947export const togglePreferenceInSettingsTab = async (label: string, shouldBeChecked?: boolean) => {
Patrick Brossetf398c102020-10-14 07:35:0848 await openSettingsTab('Preferences');
Kim-Anh Trancd252162021-06-16 11:41:4049
PhistucK257ad692022-08-29 14:36:1950 const selector = `[aria-label="${label}"]`;
Kim-Anh Trancd252162021-06-16 11:41:4051 await scrollElementIntoView(selector);
52 const preference = await waitFor(selector);
53
54 const value = await preference.evaluate(checkbox => (checkbox as HTMLInputElement).checked);
55
PhistucK257ad692022-08-29 14:36:1956 if (value !== shouldBeChecked) {
Alex Rudenkoe92fe9d2023-01-30 13:12:2357 await clickElement(preference);
Kim-Anh Trancd252162021-06-16 11:41:4058
PhistucK257ad692022-08-29 14:36:1959 await waitForFunction(async () => {
60 const newValue = await preference.evaluate(checkbox => (checkbox as HTMLInputElement).checked);
61 return newValue !== value;
62 });
63 }
Kim-Anh Trancd252162021-06-16 11:41:4064
Eric Leesea6533f02022-07-19 15:33:0465 await closeSettings();
66};
67
68export const setIgnoreListPattern = async (pattern: string) => {
69 await openSettingsTab('Ignore List');
70 await click('[aria-label="Add filename pattern"]');
Eric Leese9441d872022-09-23 09:19:3171 const textBox = await waitFor('[aria-label="Add Pattern"]');
Alex Rudenkoe92fe9d2023-01-30 13:12:2372 await clickElement(textBox);
Eric Leesea6533f02022-07-19 15:33:0473 await textBox.type(pattern);
74 await textBox.type('\n');
75 await waitFor(`[title="Ignore scripts whose names match '${pattern}'"]`);
76 await closeSettings();
Patrick Brossetf398c102020-10-14 07:35:0877};
Eric Leese9441d872022-09-23 09:19:3178
79export 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 Coch34ad3342023-06-06 20:15:5984 await click('[title="Enable Ignore Listing"]');
Eric Leese9441d872022-09-23 09:19:3185 await waitFor(enable ? enabledPattern : disabledPattern);
86 await closeSettings();
87};