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

Side by Side Diff: chrome/test/data/webui/extensions/extension_shortcut_input_test.js

Issue 2101933005: [MD Extensions] Implement keyboard shortcuts page (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Michael's Created 4 years, 5 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 // Copyright 2016 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 /** @fileoverview Suite of tests for extension-keyboard-shortcuts. */
6 cr.define('extension_shortcut_input_tests', function() {
7 /** @enum {string} */
8 var TestNames = {
9 Basic: 'basic',
10 };
11
12 function registerTests() {
13 suite('ExtensionShortcutInputTest', function() {
14 /** @type {extensions.ShortcutInput} */
15 var input;
16 setup(function() {
17 PolymerTest.clearBody();
18 input = new extensions.ShortcutInput();
19 input.commandName = 'Command';
20 input.item = 'itemid';
21 document.body.appendChild(input);
22 Polymer.dom.flush();
23 });
24
25 test(assert(TestNames.Basic), function() {
26 var field = input.$['input'];
27 var fieldText = function() { return field.textContent.trim(); };
28 expectEquals('Not set', fieldText());
29
30 // Click the input. Capture should start.
31 {
32 let startCaptureListener = new extension_test_util.ListenerMock();
33 startCaptureListener.addListener(input, 'shortcut-capture-started');
34 MockInteractions.tap(field);
35 startCaptureListener.verify();
36 }
37 expectEquals('Type a shortcut', fieldText());
38 expectTrue(input.capturing_);
39
40 // Press ctrl.
41 MockInteractions.keyDownOn(field, 17, ['ctrl']);
42 expectEquals('Ctrl', fieldText());
43 expectTrue(input.capturing_);
44 // Add shift.
45 MockInteractions.keyDownOn(field, 16, ['ctrl', 'shift']);
46 expectEquals('Ctrl+Shift', fieldText());
47 expectTrue(input.capturing_);
48 // Remove shift.
49 MockInteractions.keyUpOn(field, 16, ['ctrl']);
50 expectEquals('Ctrl', fieldText());
51 // Add alt (ctrl + alt is invalid).
52 MockInteractions.keyDownOn(field, 18, ['ctrl', 'alt']);
53 expectEquals('invalid', fieldText());
54 expectTrue(input.capturing_);
55 // Remove alt.
56 MockInteractions.keyUpOn(field, 18, ['ctrl']);
57 expectEquals('Ctrl', fieldText());
58 expectTrue(input.capturing_);
59 {
60 // Add 'A'. Once a valid shortcut is typed (like Ctrl+A), it is
61 // committed.
62 let updatedListener = new extension_test_util.ListenerMock();
63 updatedListener.addListener(input, 'shortcut-updated',
64 {keybinding: 'Ctrl+A',
65 item: 'itemid',
66 commandName: 'Command'});
67 updatedListener.addListener(input, 'shortcut-capture-ended');
68 MockInteractions.keyDownOn(field, 65, ['ctrl']);
69 updatedListener.verify();
70 }
71 expectEquals('Ctrl+A', fieldText());
72 expectFalse(input.capturing_);
73 expectEquals('Ctrl+A', input.shortcut);
74
75 {
76 // Test clearing the shortcut.
77 let updatedListener = new extension_test_util.ListenerMock();
78 updatedListener.addListener(input, 'shortcut-updated',
79 {keybinding: '',
80 item: 'itemid',
81 commandName: 'Command'});
82 MockInteractions.tap(input.$['clear']);
83 updatedListener.verify();
84 }
85 expectEquals('', input.shortcut);
86
87 MockInteractions.tap(field);
88 {
89 // Test ending capture using the escape key.
90 expectTrue(input.capturing_);
91 let captureEndedListener = new extension_test_util.ListenerMock();
92 captureEndedListener.addListener(input, 'shortcut-capture-ended');
93 MockInteractions.keyDownOn(field, 27); // Escape key.
94 expectFalse(input.capturing_);
95 captureEndedListener.verify();
96 }
97 });
98 });
99 }
100
101 return {
102 registerTests: registerTests,
103 TestNames: TestNames,
104 };
105 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698