"use strict";
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
const quick_open_helpers_js_1 = require("../helpers/quick_open-helpers.js");
const settings_helpers_js_1 = require("../helpers/settings-helpers.js");
const settings_shortcuts_helpers_js_1 = require("../helpers/settings-shortcuts-helpers.js");
describe('Shortcuts Settings tab', () => {
    it('should update when the shortcuts preset is changed ', async ({ devToolsPage }) => {
        await (0, settings_helpers_js_1.openSettingsTab)('Shortcuts', devToolsPage);
        await (0, settings_shortcuts_helpers_js_1.selectKeyboardShortcutPreset)('vsCode', devToolsPage);
        await (0, settings_shortcuts_helpers_js_1.waitForVSCodeShortcutPreset)(devToolsPage);
        const shortcutsShortcuts = await (0, settings_shortcuts_helpers_js_1.shortcutsForAction)('Show Shortcuts', devToolsPage);
        const settingsShortcuts = await (0, settings_shortcuts_helpers_js_1.shortcutsForAction)('Settings', devToolsPage);
        const pauseShortcuts = await (0, settings_shortcuts_helpers_js_1.shortcutsForAction)('Pause script execution', devToolsPage);
        chai_1.assert.deepEqual(shortcutsShortcuts, settings_shortcuts_helpers_js_1.VS_CODE_SHORTCUTS_SHORTCUTS);
        chai_1.assert.deepEqual(settingsShortcuts, settings_shortcuts_helpers_js_1.VS_CODE_SETTINGS_SHORTCUTS);
        chai_1.assert.deepEqual(pauseShortcuts, settings_shortcuts_helpers_js_1.VS_CODE_PAUSE_SHORTCUTS);
    });
    it('should apply new shortcuts when the preset is changed', async ({ devToolsPage }) => {
        await (0, settings_helpers_js_1.openSettingsTab)('Shortcuts', devToolsPage);
        await (0, settings_shortcuts_helpers_js_1.selectKeyboardShortcutPreset)('vsCode', devToolsPage);
        await (0, settings_shortcuts_helpers_js_1.waitForVSCodeShortcutPreset)(devToolsPage);
        // close the settings dialog
        await devToolsPage.page.keyboard.press('Escape');
        // use a newly-enabled shortcut to open the command menu
        await devToolsPage.page.keyboard.press('F1');
        await devToolsPage.waitFor(quick_open_helpers_js_1.QUICK_OPEN_SELECTOR);
        // make sure the command menu reflects the new shortcuts
        await devToolsPage.page.keyboard.type('Show Shortcuts');
        await devToolsPage.drainTaskQueue();
        const shortcutsItemText = await (0, quick_open_helpers_js_1.getSelectedItemText)(devToolsPage);
        chai_1.assert.strictEqual(shortcutsItemText, settings_shortcuts_helpers_js_1.VS_CODE_SHORTCUTS_QUICK_OPEN_TEXT);
    });
    it('should allow users to open the shortcut editor and view the current shortcut', async ({ devToolsPage }) => {
        await (0, settings_helpers_js_1.openSettingsTab)('Shortcuts', devToolsPage);
        await (0, settings_shortcuts_helpers_js_1.editShortcutListItem)('Toggle Console', devToolsPage);
        const shortcutInputsText = await (0, settings_shortcuts_helpers_js_1.shortcutInputValues)(devToolsPage);
        chai_1.assert.deepEqual(shortcutInputsText, settings_shortcuts_helpers_js_1.CONSOLE_SHORTCUT_INPUT_TEXT);
    });
    it('should allow users to open the shortcut editor and change and add shortcuts', async ({ devToolsPage }) => {
        await (0, settings_helpers_js_1.openSettingsTab)('Shortcuts', devToolsPage);
        await (0, settings_shortcuts_helpers_js_1.editShortcutListItem)('Toggle Console', devToolsPage);
        await devToolsPage.pressKey('1', { control: true });
        await (0, settings_shortcuts_helpers_js_1.clickAddShortcutLink)(devToolsPage);
        await (0, settings_shortcuts_helpers_js_1.waitForEmptyShortcutInput)(devToolsPage);
        await devToolsPage.pressKey('2', { control: true });
        const shortcutInputsText = await (0, settings_shortcuts_helpers_js_1.shortcutInputValues)(devToolsPage);
        chai_1.assert.deepEqual(shortcutInputsText, settings_shortcuts_helpers_js_1.CONTROL_1_CONTROL_2_SHORTCUT_INPUTS_TEXT);
        await (0, settings_shortcuts_helpers_js_1.clickShortcutConfirmButton)(devToolsPage);
        await devToolsPage.waitForNoElementsWithTextContent(settings_shortcuts_helpers_js_1.ADD_SHORTCUT_LINK_TEXT);
        const shortcuts = await (0, settings_shortcuts_helpers_js_1.shortcutsForAction)('Toggle Console', devToolsPage);
        chai_1.assert.deepEqual(shortcuts, settings_shortcuts_helpers_js_1.CONTROL_1_CONTROL_2_SHORTCUT_DISPLAY_TEXT);
    });
    it('should allow users to open shortcut editor and change and reset shortcuts', async ({ devToolsPage }) => {
        await (0, settings_helpers_js_1.openSettingsTab)('Shortcuts', devToolsPage);
        const defaultShortcuts = await (0, settings_shortcuts_helpers_js_1.shortcutsForAction)('Start recording events', devToolsPage);
        await (0, settings_shortcuts_helpers_js_1.editShortcutListItem)('Start recording events', devToolsPage);
        await devToolsPage.pressKey('1', { control: true });
        await (0, settings_shortcuts_helpers_js_1.clickAddShortcutLink)(devToolsPage);
        await (0, settings_shortcuts_helpers_js_1.waitForEmptyShortcutInput)(devToolsPage);
        await devToolsPage.pressKey('2', { control: true });
        await (0, settings_shortcuts_helpers_js_1.clickShortcutConfirmButton)(devToolsPage);
        await devToolsPage.waitForNoElementsWithTextContent(settings_shortcuts_helpers_js_1.ADD_SHORTCUT_LINK_TEXT);
        const modifiedShortcuts = await (0, settings_shortcuts_helpers_js_1.shortcutsForAction)('Start recording events', devToolsPage);
        chai_1.assert.deepEqual(modifiedShortcuts, settings_shortcuts_helpers_js_1.CONTROL_1_CONTROL_2_SHORTCUT_DISPLAY_TEXT);
        await (0, settings_shortcuts_helpers_js_1.editShortcutListItem)('Start recording events', devToolsPage);
        await (0, settings_shortcuts_helpers_js_1.clickShortcutResetButton)(devToolsPage);
        await (0, settings_shortcuts_helpers_js_1.clickShortcutConfirmButton)(devToolsPage);
        await devToolsPage.waitForNoElementsWithTextContent(settings_shortcuts_helpers_js_1.ADD_SHORTCUT_LINK_TEXT);
        const shortcuts = await (0, settings_shortcuts_helpers_js_1.shortcutsForAction)('Start recording events', devToolsPage);
        chai_1.assert.deepEqual(shortcuts, defaultShortcuts, 'Default shortcuts weren\'t restored correctly');
    });
    it('should allow users to open the shortcut editor and delete and reset shortcuts', async ({ devToolsPage }) => {
        await (0, settings_helpers_js_1.openSettingsTab)('Shortcuts', devToolsPage);
        await (0, settings_shortcuts_helpers_js_1.editShortcutListItem)('Toggle Console', devToolsPage);
        await devToolsPage.pressKey('1', { control: true });
        await (0, settings_shortcuts_helpers_js_1.clickAddShortcutLink)(devToolsPage);
        await (0, settings_shortcuts_helpers_js_1.waitForEmptyShortcutInput)(devToolsPage);
        await devToolsPage.pressKey('2', { control: true });
        const shortcutInputsText = await (0, settings_shortcuts_helpers_js_1.shortcutInputValues)(devToolsPage);
        chai_1.assert.deepEqual(shortcutInputsText, settings_shortcuts_helpers_js_1.CONTROL_1_CONTROL_2_SHORTCUT_INPUTS_TEXT);
        await (0, settings_shortcuts_helpers_js_1.clickShortcutDeleteButton)(0, devToolsPage);
        let shortcutInputTextAfterDeletion;
        await devToolsPage.waitForFunction(async () => {
            shortcutInputTextAfterDeletion = await (0, settings_shortcuts_helpers_js_1.shortcutInputValues)(devToolsPage);
            return shortcutInputTextAfterDeletion.length === 1;
        });
        chai_1.assert.deepEqual(shortcutInputTextAfterDeletion, settings_shortcuts_helpers_js_1.CONTROL_2_SHORTCUT_INPUT_TEXT);
        await (0, settings_shortcuts_helpers_js_1.clickShortcutResetButton)(devToolsPage);
        const shortcutInputTextAfterReset = await (0, settings_shortcuts_helpers_js_1.shortcutInputValues)(devToolsPage);
        chai_1.assert.deepEqual(shortcutInputTextAfterReset, settings_shortcuts_helpers_js_1.CONSOLE_SHORTCUT_INPUT_TEXT);
        await (0, settings_shortcuts_helpers_js_1.clickShortcutConfirmButton)(devToolsPage);
        await devToolsPage.waitForNoElementsWithTextContent(settings_shortcuts_helpers_js_1.ADD_SHORTCUT_LINK_TEXT);
        const shortcuts = await (0, settings_shortcuts_helpers_js_1.shortcutsForAction)('Toggle Console', devToolsPage);
        chai_1.assert.deepEqual(shortcuts, settings_shortcuts_helpers_js_1.CONSOLE_SHORTCUT_DISPLAY_TEXT);
    });
    it('should allow users to cancel an edit and discard their changes to shortcuts', async ({ devToolsPage }) => {
        await (0, settings_helpers_js_1.openSettingsTab)('Shortcuts', devToolsPage);
        await (0, settings_shortcuts_helpers_js_1.editShortcutListItem)('Toggle Console', devToolsPage);
        await devToolsPage.pressKey('1', { control: true });
        await (0, settings_shortcuts_helpers_js_1.clickAddShortcutLink)(devToolsPage);
        await (0, settings_shortcuts_helpers_js_1.waitForEmptyShortcutInput)(devToolsPage);
        await devToolsPage.pressKey('2', { control: true });
        const shortcutInputsText = await (0, settings_shortcuts_helpers_js_1.shortcutInputValues)(devToolsPage);
        chai_1.assert.deepEqual(shortcutInputsText, settings_shortcuts_helpers_js_1.CONTROL_1_CONTROL_2_SHORTCUT_INPUTS_TEXT);
        await (0, settings_shortcuts_helpers_js_1.clickShortcutCancelButton)(devToolsPage);
        await devToolsPage.waitForNoElementsWithTextContent(settings_shortcuts_helpers_js_1.ADD_SHORTCUT_LINK_TEXT);
        const shortcuts = await (0, settings_shortcuts_helpers_js_1.shortcutsForAction)('Toggle Console', devToolsPage);
        chai_1.assert.deepEqual(shortcuts, settings_shortcuts_helpers_js_1.CONSOLE_SHORTCUT_DISPLAY_TEXT);
    });
    it('should allow users to set a multi-keypress shortcut (chord)', async ({ devToolsPage }) => {
        await (0, settings_helpers_js_1.openSettingsTab)('Shortcuts', devToolsPage);
        await (0, settings_shortcuts_helpers_js_1.editShortcutListItem)('Toggle Console', devToolsPage);
        await devToolsPage.pressKey('1', { control: true });
        await devToolsPage.pressKey('2', { control: true });
        const shortcutInputsText = await (0, settings_shortcuts_helpers_js_1.shortcutInputValues)(devToolsPage);
        chai_1.assert.deepEqual(shortcutInputsText, settings_shortcuts_helpers_js_1.CONTROL_1_CONTROL_2_CHORD_INPUT_TEXT);
        await (0, settings_shortcuts_helpers_js_1.clickShortcutConfirmButton)(devToolsPage);
        await devToolsPage.waitForNoElementsWithTextContent(settings_shortcuts_helpers_js_1.ADD_SHORTCUT_LINK_TEXT);
        const shortcuts = await (0, settings_shortcuts_helpers_js_1.shortcutsForAction)('Toggle Console', devToolsPage);
        chai_1.assert.deepEqual(shortcuts, settings_shortcuts_helpers_js_1.CONTROL_1_CONTROL_2_CHORD_DISPLAY_TEXT);
    });
    it('should display the physical key that is pressed rather than special characters', async ({ devToolsPage }) => {
        await (0, settings_helpers_js_1.openSettingsTab)('Shortcuts', devToolsPage);
        await (0, settings_shortcuts_helpers_js_1.editShortcutListItem)('Toggle Console', devToolsPage);
        await devToolsPage.pressKey('c', { control: true, alt: true });
        const shortcutInputsText = await (0, settings_shortcuts_helpers_js_1.shortcutInputValues)(devToolsPage);
        chai_1.assert.deepEqual(shortcutInputsText, settings_shortcuts_helpers_js_1.CONTROL_ALT_C_SHORTCUT_INPUT_TEXT);
    });
    it('should allow users to set a new shortcut after the chord timeout', async ({ devToolsPage }) => {
        await (0, settings_helpers_js_1.openSettingsTab)('Shortcuts', devToolsPage);
        await (0, settings_shortcuts_helpers_js_1.editShortcutListItem)('Toggle Console', devToolsPage);
        await devToolsPage.pressKey('1', { control: true });
        await devToolsPage.timeout(settings_shortcuts_helpers_js_1.SHORTCUT_CHORD_TIMEOUT * 1.2);
        await devToolsPage.pressKey('2', { control: true });
        const shortcutInputsText = await (0, settings_shortcuts_helpers_js_1.shortcutInputValues)(devToolsPage);
        chai_1.assert.deepEqual(shortcutInputsText, settings_shortcuts_helpers_js_1.CONTROL_2_SHORTCUT_INPUT_TEXT);
        await (0, settings_shortcuts_helpers_js_1.clickShortcutConfirmButton)(devToolsPage);
        await devToolsPage.waitForNoElementsWithTextContent(settings_shortcuts_helpers_js_1.ADD_SHORTCUT_LINK_TEXT);
        const shortcuts = await (0, settings_shortcuts_helpers_js_1.shortcutsForAction)('Toggle Console', devToolsPage);
        chai_1.assert.deepEqual(shortcuts, settings_shortcuts_helpers_js_1.CONTROL_2_SHORTCUT_DISPLAY_TEXT);
    });
});
//# sourceMappingURL=shortcut_settings.test.js.map