Chromium Code Reviews| Index: chrome/test/data/webui/extensions/extension_shortcut_input_test.js |
| diff --git a/chrome/test/data/webui/extensions/extension_shortcut_input_test.js b/chrome/test/data/webui/extensions/extension_shortcut_input_test.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b23aa47a5b3b5c515ad5ee0a55045b7cddbba9a0 |
| --- /dev/null |
| +++ b/chrome/test/data/webui/extensions/extension_shortcut_input_test.js |
| @@ -0,0 +1,106 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +/** @fileoverview Suite of tests for extension-keyboard-shortcuts. */ |
| +cr.define('extension_shortcut_input_tests', function() { |
| + /** @enum {string} */ |
| + var TestNames = { |
| + Basic: 'basic', |
| + }; |
| + |
| + function registerTests() { |
| + suite('ExtensionShortcutInputTest', function() { |
| + /** @type {extensions.ShortcutInput} */ |
| + var input; |
| + setup(function() { |
| + PolymerTest.clearBody(); |
| + input = new extensions.ShortcutInput(); |
| + input.set('commandName', 'Command'); |
|
michaelpg
2016/07/01 21:39:04
nit... input.foo = bar;
Devlin
2016/07/07 00:33:36
Done.
|
| + input.set('item', 'itemid'); |
| + document.body.appendChild(input); |
| + Polymer.dom.flush(); |
| + }); |
| + |
| + test(assert(TestNames.Basic), function() { |
| + var field = input.$['input']; |
| + var fieldText = function() { return field.textContent.trim(); }; |
| + expectEquals('Not set', fieldText()); |
| + |
| + // Click the input. Capture should start. |
| + { |
| + var startCaptureListener = new extension_test_util.ListenerMock(); |
|
michaelpg
2016/07/01 21:39:03
if you want to block-scope these, don't you need t
Devlin
2016/07/07 00:33:36
This was as much for readability as scoping, but y
|
| + startCaptureListener.addListener(input, 'shortcut-capture-started', |
| + {}); |
|
michaelpg
2016/07/01 21:39:04
looking at addListener, you could leave off these
Devlin
2016/07/07 00:33:36
Done.
|
| + MockInteractions.tap(field); |
| + startCaptureListener.verify(); |
| + } |
| + expectEquals('Type a shortcut', fieldText()); |
| + expectTrue(input.capturing_); |
| + |
| + // Press ctrl. |
| + MockInteractions.keyDownOn(field, 17, ['ctrl']); |
| + expectEquals('Ctrl', fieldText()); |
| + expectTrue(input.capturing_); |
| + // Add shift. |
| + MockInteractions.keyDownOn(field, 16, ['ctrl', 'shift']); |
| + expectEquals('Ctrl+Shift', fieldText()); |
| + expectTrue(input.capturing_); |
| + // Remove shift. |
| + MockInteractions.keyUpOn(field, 16, ['ctrl']); |
| + expectEquals('Ctrl', fieldText()); |
| + // Add alt (ctrl + alt is invalid). |
| + MockInteractions.keyDownOn(field, 18, ['ctrl', 'alt']); |
| + expectEquals('invalid', fieldText()); |
| + expectTrue(input.capturing_); |
| + // Remove alt. |
| + MockInteractions.keyUpOn(field, 18, ['ctrl']); |
| + expectEquals('Ctrl', fieldText()); |
| + expectTrue(input.capturing_); |
| + { |
| + // Add 'A'. Once a valid shortcut is typed (like Ctrl+A), it is |
| + // committed. |
| + var updatedListener = new extension_test_util.ListenerMock(); |
| + updatedListener.addListener(input, 'shortcut-updated', |
| + {keybinding: 'Ctrl+A', |
| + item: 'itemid', |
| + commandName: 'Command'}); |
| + updatedListener.addListener(input, 'shortcut-capture-ended', {}); |
| + MockInteractions.keyDownOn(field, 65, ['ctrl']); |
| + updatedListener.verify(); |
| + } |
| + expectEquals('Ctrl+A', fieldText()); |
| + expectFalse(input.capturing_); |
| + expectEquals('Ctrl+A', input.shortcut); |
| + |
| + { |
| + // Test clearing the shortcut. |
| + var updatedListener = new extension_test_util.ListenerMock(); |
| + updatedListener.addListener(input, 'shortcut-updated', |
| + {keybinding: '', |
| + item: 'itemid', |
| + commandName: 'Command'}); |
| + MockInteractions.tap(input.$['clear']); |
| + updatedListener.verify(); |
| + } |
| + expectEquals('', input.shortcut); |
| + |
| + MockInteractions.tap(field); |
| + { |
| + // Test ending capture using the escape key. |
| + expectTrue(input.capturing_); |
| + var captureEndedListener = new extension_test_util.ListenerMock(); |
| + captureEndedListener.addListener(input, 'shortcut-capture-ended', {}); |
| + MockInteractions.keyDownOn(field, 27); // Escape key. |
| + expectFalse(input.capturing_); |
| + captureEndedListener.verify(); |
| + } |
| + }); |
| + }); |
| + } |
| + |
| + return { |
| + registerTests: registerTests, |
| + TestNames: TestNames, |
| + }; |
| +}); |