Fix improper implementation of getKeyboardEvent
Bug: Issue 5088 Change-Id: Iee82c135230f78f823c25982aaeba1ea6ece1709
This commit is contained in:
parent
62f911698d
commit
d01ad017e4
|
@ -13,20 +13,22 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<link rel="import" href="../bower_components/polymer/polymer.html">
|
||||
<link rel="import" href="../bower_components/iron-a11y-keys-behavior/iron-a11y-keys-behavior.html">
|
||||
<link rel="import" href="../../bower_components/polymer/polymer.html">
|
||||
<link rel="import" href="../../bower_components/iron-a11y-keys-behavior/iron-a11y-keys-behavior.html">
|
||||
|
||||
<script>
|
||||
(function(window) {
|
||||
'use strict';
|
||||
|
||||
var getKeyboardEvent = function(e) {
|
||||
return Polymer.dom(e.detail ? e.detail.keyboardEvent : e).event;
|
||||
return Polymer.dom(e.detail ? e.detail.keyboardEvent : e);
|
||||
};
|
||||
|
||||
var KeyboardShortcutBehaviorImpl = {
|
||||
modifierPressed: function(e) {
|
||||
e = getKeyboardEvent(e);
|
||||
// When e is a keyboardEvent, e.event is not null.
|
||||
if (e.event) { e = e.event; }
|
||||
return e.altKey || e.ctrlKey || e.metaKey || e.shiftKey;
|
||||
},
|
||||
|
|
@ -42,6 +42,7 @@ limitations under the License.
|
|||
suite('keyboard-shortcut-behavior tests', function() {
|
||||
var element;
|
||||
var overlay;
|
||||
var sandbox;
|
||||
|
||||
suiteSetup(function() {
|
||||
// Define a Polymer element that uses this behavior.
|
||||
|
@ -58,6 +59,11 @@ limitations under the License.
|
|||
setup(function() {
|
||||
element = fixture('basic');
|
||||
overlay = fixture('within-overlay');
|
||||
sandbox = sinon.sandbox.create();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
sandbox.restore();
|
||||
});
|
||||
|
||||
test('doesn’t block kb shortcuts for non-whitelisted els', function(done) {
|
||||
|
@ -101,5 +107,25 @@ limitations under the License.
|
|||
MockInteractions.keyDownOn(divEl, 75, null, 'k');
|
||||
});
|
||||
|
||||
test('modifierPressed returns accurate values', function() {
|
||||
var spy = sandbox.spy(element, 'modifierPressed');
|
||||
element._handleKey = function(e) {
|
||||
element.modifierPressed(e);
|
||||
};
|
||||
MockInteractions.keyDownOn(element, 75, 'shift', 'k');
|
||||
assert.isTrue(spy.lastCall.returnValue);
|
||||
MockInteractions.keyDownOn(element, 75, null, 'k');
|
||||
assert.isFalse(spy.lastCall.returnValue);
|
||||
MockInteractions.keyDownOn(element, 75, 'ctrl', 'k');
|
||||
assert.isTrue(spy.lastCall.returnValue);
|
||||
MockInteractions.keyDownOn(element, 75, null, 'k');
|
||||
assert.isFalse(spy.lastCall.returnValue);
|
||||
MockInteractions.keyDownOn(element, 75, 'meta', 'k');
|
||||
assert.isTrue(spy.lastCall.returnValue);
|
||||
MockInteractions.keyDownOn(element, 75, null, 'k');
|
||||
assert.isFalse(spy.lastCall.returnValue);
|
||||
MockInteractions.keyDownOn(element, 75, 'alt', 'k');
|
||||
assert.isTrue(spy.lastCall.returnValue);
|
||||
});
|
||||
});
|
||||
</script>
|
|
@ -15,7 +15,7 @@ limitations under the License.
|
|||
-->
|
||||
|
||||
<link rel="import" href="../../../bower_components/polymer/polymer.html">
|
||||
<link rel="import" href="../../../behaviors/keyboard-shortcut-behavior.html">
|
||||
<link rel="import" href="../../../behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.html">
|
||||
<link rel="import" href="../../../behaviors/rest-client-behavior.html">
|
||||
<link rel="import" href="../../../styles/gr-change-list-styles.html">
|
||||
<link rel="import" href="../../shared/gr-rest-api-interface/gr-rest-api-interface.html">
|
||||
|
|
|
@ -16,7 +16,7 @@ limitations under the License.
|
|||
|
||||
<link rel="import" href="../../../bower_components/polymer/polymer.html">
|
||||
<link rel="import" href="../../../behaviors/gr-patch-set-behavior/gr-patch-set-behavior.html">
|
||||
<link rel="import" href="../../../behaviors/keyboard-shortcut-behavior.html">
|
||||
<link rel="import" href="../../../behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.html">
|
||||
<link rel="import" href="../../../behaviors/rest-client-behavior.html">
|
||||
<link rel="import" href="../../shared/gr-account-link/gr-account-link.html">
|
||||
<link rel="import" href="../../shared/gr-select/gr-select.html">
|
||||
|
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
-->
|
||||
|
||||
<link rel="import" href="../../../behaviors/keyboard-shortcut-behavior.html">
|
||||
<link rel="import" href="../../../behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.html">
|
||||
<link rel="import" href="../../../behaviors/gr-patch-set-behavior/gr-patch-set-behavior.html">
|
||||
<link rel="import" href="../../../behaviors/gr-url-encoding-behavior.html">
|
||||
<link rel="import" href="../../../bower_components/polymer/polymer.html">
|
||||
|
|
|
@ -15,7 +15,7 @@ limitations under the License.
|
|||
-->
|
||||
|
||||
<link rel="import" href="../../../behaviors/gr-url-encoding-behavior.html">
|
||||
<link rel="import" href="../../../behaviors/keyboard-shortcut-behavior.html">
|
||||
<link rel="import" href="../../../behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.html">
|
||||
<link rel="import" href="../../../bower_components/polymer/polymer.html">
|
||||
<link rel="import" href="../../shared/gr-autocomplete/gr-autocomplete.html">
|
||||
<link rel="import" href="../../shared/gr-button/gr-button.html">
|
||||
|
|
|
@ -17,7 +17,7 @@ limitations under the License.
|
|||
<link rel="import" href="../../../bower_components/polymer/polymer.html">
|
||||
<link rel="import" href="../../../bower_components/iron-dropdown/iron-dropdown.html">
|
||||
<link rel="import" href="../../../behaviors/gr-url-encoding-behavior.html">
|
||||
<link rel="import" href="../../../behaviors/keyboard-shortcut-behavior.html">
|
||||
<link rel="import" href="../../../behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.html">
|
||||
<link rel="import" href="../../../behaviors/rest-client-behavior.html">
|
||||
<link rel="import" href="../../shared/gr-button/gr-button.html">
|
||||
<link rel="import" href="../../shared/gr-overlay/gr-overlay.html">
|
||||
|
|
|
@ -15,7 +15,7 @@ limitations under the License.
|
|||
-->
|
||||
|
||||
<link rel="import" href="../../../bower_components/polymer/polymer.html">
|
||||
<link rel="import" href="../../../behaviors/keyboard-shortcut-behavior.html">
|
||||
<link rel="import" href="../../../behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.html">
|
||||
|
||||
<dom-module id="gr-selection-action-box">
|
||||
<template>
|
||||
|
|
|
@ -15,7 +15,7 @@ limitations under the License.
|
|||
-->
|
||||
|
||||
<link rel="import" href="../bower_components/polymer/polymer.html">
|
||||
<link rel="import" href="../behaviors/keyboard-shortcut-behavior.html">
|
||||
<link rel="import" href="../behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.html">
|
||||
<link rel="import" href="../styles/app-theme.html">
|
||||
|
||||
<link rel="import" href="./core/gr-error-manager/gr-error-manager.html">
|
||||
|
|
|
@ -16,7 +16,7 @@ limitations under the License.
|
|||
|
||||
<link rel="import" href="../../../bower_components/polymer/polymer.html">
|
||||
<link rel="import" href="../../../behaviors/gr-tooltip-behavior/gr-tooltip-behavior.html">
|
||||
<link rel="import" href="../../../behaviors/keyboard-shortcut-behavior.html">
|
||||
<link rel="import" href="../../../behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.html">
|
||||
|
||||
<dom-module id="gr-button">
|
||||
<template strip-whitespace>
|
||||
|
|
|
@ -110,6 +110,7 @@ limitations under the License.
|
|||
'gr-patch-set-behavior/gr-patch-set-behavior_test.html',
|
||||
'gr-path-list-behavior/gr-path-list-behavior_test.html',
|
||||
].forEach(function(file) {
|
||||
// Behaviors do not utilize the DOM, so no shadow DOM test is necessary.
|
||||
file = behaviorsPath + file;
|
||||
testFiles.push(file);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue