Skip to content

Commit 45aeb90

Browse files
OrKoNDevtools-frontend LUCI CQ
authored and
Devtools-frontend LUCI CQ
committed
Migrate TextEditor to be an e2e test
This interaction test is more like an e2e test verifying that TextEditor component works e2e. This CL migrates the test to be an e2e test using an editor instance in Snippets. Drive-by: made --bail to be a boolean arg to make it not swallow the first test file. Bug: 402372244 Change-Id: I4efcf29c549633bc8478419ab5b94e0804dee1ef Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6434109 Commit-Queue: Alex Rudenko <alexrudenko@chromium.org> Auto-Submit: Alex Rudenko <alexrudenko@chromium.org> Reviewed-by: Simon Zünd <szuend@chromium.org>
1 parent ab14ad5 commit 45aeb90

File tree

13 files changed

+139
-180
lines changed

13 files changed

+139
-180
lines changed

front_end/ui/components/docs/BUILD.gn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ group("docs") {
5454
"./style_property_editor",
5555
"./survey_link",
5656
"./switch",
57-
"./text_editor",
5857
"./text_prompt",
5958
"./theme_colors",
6059
"./tooltip",

front_end/ui/components/docs/text_editor/BUILD.gn

Lines changed: 0 additions & 24 deletions
This file was deleted.

front_end/ui/components/docs/text_editor/basic.html

Lines changed: 0 additions & 28 deletions
This file was deleted.

front_end/ui/components/docs/text_editor/basic.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

front_end/ui/components/text_editor/BUILD.gn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ devtools_entrypoint("bundle") {
4545
]
4646

4747
visibility = [
48-
"../../../../test/interactions/text_editor/*",
48+
"../../../../test/e2e_non_hosted/*",
4949
"../../legacy/components/*",
5050
]
5151
visibility += default_components_visibility

test/e2e_non_hosted/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ node_ts_library("tests") {
1818
"assertion",
1919
"elements",
2020
"performance",
21+
"sources",
2122
"targets",
2223
"webaudio",
2324
]

test/e2e_non_hosted/shared/frontend-helper.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type * as puppeteer from 'puppeteer-core';
66

77
import {AsyncScope} from '../../conductor/async-scope.js';
88
import {installPageErrorHandlers} from '../../conductor/events.js';
9+
import {platform} from '../../conductor/platform.js';
910
import {TestConfig} from '../../conductor/test_config.js';
1011

1112
import {PageWrapper} from './page-wrapper.js';
@@ -202,6 +203,47 @@ export class DevToolsPage extends PageWrapper {
202203
return new Promise<void>(resolve => setTimeout(resolve, duration));
203204
}
204205

206+
async typeText(text: string) {
207+
await this.page.keyboard.type(text);
208+
await this.drainFrontendTaskQueue();
209+
}
210+
211+
async pressKey(key: puppeteer.KeyInput, modifiers?: {control?: boolean, alt?: boolean, shift?: boolean}) {
212+
if (modifiers) {
213+
if (modifiers.control) {
214+
if (platform === 'mac') {
215+
// Use command key on mac
216+
await this.page.keyboard.down('Meta');
217+
} else {
218+
await this.page.keyboard.down('Control');
219+
}
220+
}
221+
if (modifiers.alt) {
222+
await this.page.keyboard.down('Alt');
223+
}
224+
if (modifiers.shift) {
225+
await this.page.keyboard.down('Shift');
226+
}
227+
}
228+
await this.page.keyboard.press(key);
229+
if (modifiers) {
230+
if (modifiers.shift) {
231+
await this.page.keyboard.up('Shift');
232+
}
233+
if (modifiers.alt) {
234+
await this.page.keyboard.up('Alt');
235+
}
236+
if (modifiers.control) {
237+
if (platform === 'mac') {
238+
// Use command key on mac
239+
await this.page.keyboard.up('Meta');
240+
} else {
241+
await this.page.keyboard.up('Control');
242+
}
243+
}
244+
}
245+
}
246+
205247
async click(selector: string, options?: ClickOptions) {
206248
return await this.performActionOnSelector(
207249
selector,
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
# Copyright 2020 The Chromium Authors. All rights reserved.
1+
# Copyright 2024 The Chromium Authors. All rights reserved.
22
# Use of this source code is governed by a BSD-style license that can be
33
# found in the LICENSE file.
44

55
import("../../../scripts/build/typescript/typescript.gni")
66

7-
node_ts_library("text_editor") {
8-
sources = [ "text_editor_test.ts" ]
7+
ts_e2e_library("sources") {
8+
sources = [ "text-editor_test.ts" ]
99

1010
deps = [
1111
"../../../front_end/ui/components/text_editor:bundle",
1212
"../../e2e/helpers",
13-
"../../shared",
14-
"../helpers",
13+
"../shared",
1514
]
1615
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
5+
import {assert} from 'chai';
6+
import type {ElementHandle} from 'puppeteer-core';
7+
8+
import type * as TextEditor from '../../../front_end/ui/components/text_editor/text_editor.js';
9+
import type {DevToolsPage} from '../shared/frontend-helper.js';
10+
11+
describe('text editor', () => {
12+
async function getEditorContent(textEditor: ElementHandle<TextEditor.TextEditor.TextEditor>): Promise<string> {
13+
return await textEditor.evaluate(node => node.state.doc.toString());
14+
}
15+
16+
async function getEditorSelection(textEditor: ElementHandle<TextEditor.TextEditor.TextEditor>):
17+
Promise<{anchor: number, head: number}> {
18+
return JSON.parse(await textEditor.evaluate(node => {
19+
const {anchor, head} = node.state.selection.main;
20+
return JSON.stringify({anchor, head});
21+
}));
22+
}
23+
24+
async function openSnippet(devToolsPage: DevToolsPage) {
25+
await devToolsPage.click('aria/Sources');
26+
const sources = await devToolsPage.waitForAria('Sources panel');
27+
await devToolsPage.click('aria/More tabs', {root: sources});
28+
await devToolsPage.click('aria/Snippets');
29+
await devToolsPage.click('aria/New snippet');
30+
}
31+
32+
it('can insert and delete some text', async ({devToolsPage}) => {
33+
await openSnippet(devToolsPage);
34+
35+
const textEditor = await devToolsPage.waitFor('devtools-text-editor');
36+
37+
await devToolsPage.click('.cm-content', {root: textEditor});
38+
await devToolsPage.typeText('Some text here');
39+
40+
assert.strictEqual(await getEditorContent(textEditor), 'Some text here');
41+
42+
await devToolsPage.pressKey('Backspace');
43+
await devToolsPage.pressKey('Backspace');
44+
45+
assert.strictEqual(await getEditorContent(textEditor), 'Some text he');
46+
47+
await devToolsPage.pressKey('S', {
48+
control: true,
49+
});
50+
});
51+
52+
it('binds the expected keys', async ({devToolsPage}) => {
53+
await openSnippet(devToolsPage);
54+
55+
const textEditor = await devToolsPage.waitFor('devtools-text-editor');
56+
57+
await devToolsPage.click('.cm-content', {root: textEditor});
58+
await devToolsPage.typeText('one two');
59+
const ctrlOrAlt = process.platform === 'darwin' ? {alt: true} : {control: true};
60+
61+
await devToolsPage.pressKey('ArrowLeft');
62+
assert.strictEqual((await getEditorSelection(textEditor)).head, 6);
63+
await devToolsPage.pressKey('ArrowLeft', ctrlOrAlt);
64+
assert.strictEqual((await getEditorSelection(textEditor)).head, 4);
65+
await devToolsPage.pressKey('Home');
66+
assert.strictEqual((await getEditorSelection(textEditor)).head, 0);
67+
68+
await devToolsPage.pressKey('ArrowRight');
69+
assert.strictEqual((await getEditorSelection(textEditor)).head, 1);
70+
await devToolsPage.pressKey('ArrowRight', ctrlOrAlt);
71+
assert.strictEqual((await getEditorSelection(textEditor)).head, 3);
72+
await devToolsPage.pressKey('End', {control: true});
73+
assert.strictEqual((await getEditorSelection(textEditor)).head, 7);
74+
75+
await devToolsPage.typeText(' three');
76+
assert.strictEqual(await getEditorContent(textEditor), 'one two three');
77+
await devToolsPage.pressKey('Z', {control: true});
78+
assert.strictEqual(await getEditorContent(textEditor), 'one two');
79+
await devToolsPage.pressKey('Z', {control: true});
80+
assert.strictEqual(await getEditorContent(textEditor), '');
81+
82+
await devToolsPage.pressKey('S', {
83+
control: true,
84+
});
85+
});
86+
});

test/interactions/BUILD.gn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ node_ts_library("tests") {
1717
"helpers",
1818
"panels/explain",
1919
"panels/performance/timeline",
20-
"text_editor",
2120
"tree_outline",
2221
"ui/components",
2322
]

test/interactions/text_editor/text_editor_test.ts

Lines changed: 0 additions & 68 deletions
This file was deleted.

test/run.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const options = commandLineArgs(yargs(process.argv.slice(2)))
2424
.options('skip-ninja', {type: 'boolean', desc: 'Skip rebuilding'})
2525
.options('debug-driver', {type: 'boolean', hidden: true, desc: 'Debug the driver part of tests'})
2626
.options('verbose', {alias: 'v', type: 'count', desc: 'Increases the log level'})
27-
.options('bail', {alias: 'b', desc: ' bail after first test failure'})
27+
.options('bail', {type: 'boolean', alias: 'b', desc: ' bail after first test failure'})
2828
.options('auto-watch', {
2929
desc: 'watch changes to files and run tests automatically on file change (only for unit tests)'
3030
})

test/shared/helper.ts

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -111,47 +111,14 @@ export const doubleClick =
111111
};
112112

113113
export const typeText = async (text: string) => {
114-
const {frontend} = getBrowserAndPages();
115-
await frontend.keyboard.type(text);
116-
await drainFrontendTaskQueue();
114+
const {devToolsPage} = getBrowserAndPagesWrappers();
115+
await devToolsPage.typeText(text);
117116
};
118117

119118
export const pressKey =
120119
async (key: puppeteer.KeyInput, modifiers?: {control?: boolean, alt?: boolean, shift?: boolean}) => {
121-
const {frontend} = getBrowserAndPages();
122-
if (modifiers) {
123-
if (modifiers.control) {
124-
if (platform === 'mac') {
125-
// Use command key on mac
126-
await frontend.keyboard.down('Meta');
127-
} else {
128-
await frontend.keyboard.down('Control');
129-
}
130-
}
131-
if (modifiers.alt) {
132-
await frontend.keyboard.down('Alt');
133-
}
134-
if (modifiers.shift) {
135-
await frontend.keyboard.down('Shift');
136-
}
137-
}
138-
await frontend.keyboard.press(key);
139-
if (modifiers) {
140-
if (modifiers.shift) {
141-
await frontend.keyboard.up('Shift');
142-
}
143-
if (modifiers.alt) {
144-
await frontend.keyboard.up('Alt');
145-
}
146-
if (modifiers.control) {
147-
if (platform === 'mac') {
148-
// Use command key on mac
149-
await frontend.keyboard.up('Meta');
150-
} else {
151-
await frontend.keyboard.up('Control');
152-
}
153-
}
154-
}
120+
const {devToolsPage} = getBrowserAndPagesWrappers();
121+
await devToolsPage.pressKey(key, modifiers);
155122
};
156123

157124
export const pasteText = async (text: string) => {

0 commit comments

Comments
 (0)