Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/inspector-unit/soft-context-menu.js

Issue 2824023002: DevTools: Use FocusRestorer in SoftContextMenu (Closed)
Patch Set: Add a test Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 var menu = new UI.SoftContextMenu([{
2 type: 'item',
3 label: 'First',
4 enabled: true
5 },
6 {
7 type: 'subMenu',
8 label: 'Second',
9 enabled: true,
10 subItems: [
11 {type: 'subMenu', label: 'Child 1', enabled: true, subItems: [{type: 'item', label: 'Grandchild', id: 'Grandchild', enabled: true}]},
12 {type: 'item', label: 'Child 2', enabled: true},
13 {type: 'item', label: 'Child 3', enabled: true},
14 {type: 'item', label: 'Child 4', enabled: true}
15 ]
16 },
17 {
18 type: 'separator',
19 },{
20 type: 'item',
21 label: 'Third',
22 enabled: true
23 }], item => TestRunner.addResult('Item Selected: ' + item));
24
25 var initialFocusedElement = UI.inspectorView.element.createChild('div');
26 initialFocusedElement.textContent = 'Initial Focused Element';
27 initialFocusedElement.tabIndex = -1;
28 initialFocusedElement.focus();
29
30 dumpContextMenu();
31 menu.show(document, new AnchorBox(50, 50, 0, 0));
32 dumpContextMenu();
33 pressKey('ArrowDown');
34 pressKey('ArrowDown');
35 pressKey('ArrowDown');
36 pressKey('ArrowUp');
37 pressKey('ArrowUp');
38 pressKey('ArrowUp');
39 pressKey('ArrowDown');
40 TestRunner.addResult('Enter Submenu');
41 pressKey('ArrowRight');
42 pressKey('ArrowDown');
43 pressKey('ArrowDown');
44 pressKey('ArrowDown');
45 TestRunner.addResult('Leave Submenu ArrowLeft');
46 pressKey('ArrowLeft');
47 pressKey('ArrowRight');
48 TestRunner.addResult('Leave Submenu Escape');
49 pressKey('Escape');
50 TestRunner.addResult('Enter Sub-Submenu');
51 pressKey(' ');
52 pressKey('Enter');
53 pressKey('Enter');
54 TestRunner.completeTest();
55
56 function pressKey(key) {
57 var element = document.deepActiveElement();
58 if (!element)
59 return;
60 element.dispatchEvent(TestRunner.createKeyEvent(key));
61 dumpContextMenu();
62 }
63
64 function dumpContextMenu() {
65 if (initialFocusedElement.hasFocus()) {
66 TestRunner.addResult('Initial focused element has focus');
67 return;
68 }
69 var selection = '';
70 var subMenu = menu;
71 var activeElement = document.deepActiveElement();
72 do {
73 if (selection)
74 selection += ' -> ';
75 if (subMenu._contextMenuElement === activeElement)
76 selection += '[';
77 if (subMenu._highlightedMenuItemElement)
78 selection += subMenu._highlightedMenuItemElement.textContent.replace(/[^A- z0-9 ]/g, '');
79 else
80 selection += 'null'
81 if (subMenu._contextMenuElement === activeElement)
82 selection += ']';
83 }
84 while (subMenu = subMenu._subMenu)
85 TestRunner.addResult(selection);
86 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698