Fix improper implementation of getKeyboardEvent

Bug: Issue 5088
Change-Id: Iee82c135230f78f823c25982aaeba1ea6ece1709
This commit is contained in:
Kasper Nilsson 2016-12-07 18:02:34 -08:00
parent 62f911698d
commit d01ad017e4
11 changed files with 40 additions and 11 deletions

View File

@ -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 See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
--> -->
<link rel="import" href="../bower_components/polymer/polymer.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"> <link rel="import" href="../../bower_components/iron-a11y-keys-behavior/iron-a11y-keys-behavior.html">
<script> <script>
(function(window) { (function(window) {
'use strict'; 'use strict';
var getKeyboardEvent = function(e) { 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 = { var KeyboardShortcutBehaviorImpl = {
modifierPressed: function(e) { modifierPressed: function(e) {
e = getKeyboardEvent(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; return e.altKey || e.ctrlKey || e.metaKey || e.shiftKey;
}, },

View File

@ -42,6 +42,7 @@ limitations under the License.
suite('keyboard-shortcut-behavior tests', function() { suite('keyboard-shortcut-behavior tests', function() {
var element; var element;
var overlay; var overlay;
var sandbox;
suiteSetup(function() { suiteSetup(function() {
// Define a Polymer element that uses this behavior. // Define a Polymer element that uses this behavior.
@ -58,6 +59,11 @@ limitations under the License.
setup(function() { setup(function() {
element = fixture('basic'); element = fixture('basic');
overlay = fixture('within-overlay'); overlay = fixture('within-overlay');
sandbox = sinon.sandbox.create();
});
teardown(function() {
sandbox.restore();
}); });
test('doesnt block kb shortcuts for non-whitelisted els', function(done) { test('doesnt block kb shortcuts for non-whitelisted els', function(done) {
@ -101,5 +107,25 @@ limitations under the License.
MockInteractions.keyDownOn(divEl, 75, null, 'k'); 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> </script>

View File

@ -15,7 +15,7 @@ limitations under the License.
--> -->
<link rel="import" href="../../../bower_components/polymer/polymer.html"> <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="../../../behaviors/rest-client-behavior.html">
<link rel="import" href="../../../styles/gr-change-list-styles.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"> <link rel="import" href="../../shared/gr-rest-api-interface/gr-rest-api-interface.html">

View File

@ -16,7 +16,7 @@ limitations under the License.
<link rel="import" href="../../../bower_components/polymer/polymer.html"> <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/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="../../../behaviors/rest-client-behavior.html">
<link rel="import" href="../../shared/gr-account-link/gr-account-link.html"> <link rel="import" href="../../shared/gr-account-link/gr-account-link.html">
<link rel="import" href="../../shared/gr-select/gr-select.html"> <link rel="import" href="../../shared/gr-select/gr-select.html">

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. 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-patch-set-behavior/gr-patch-set-behavior.html">
<link rel="import" href="../../../behaviors/gr-url-encoding-behavior.html"> <link rel="import" href="../../../behaviors/gr-url-encoding-behavior.html">
<link rel="import" href="../../../bower_components/polymer/polymer.html"> <link rel="import" href="../../../bower_components/polymer/polymer.html">

View File

@ -15,7 +15,7 @@ limitations under the License.
--> -->
<link rel="import" href="../../../behaviors/gr-url-encoding-behavior.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="../../../bower_components/polymer/polymer.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-autocomplete/gr-autocomplete.html">
<link rel="import" href="../../shared/gr-button/gr-button.html"> <link rel="import" href="../../shared/gr-button/gr-button.html">

View File

@ -17,7 +17,7 @@ limitations under the License.
<link rel="import" href="../../../bower_components/polymer/polymer.html"> <link rel="import" href="../../../bower_components/polymer/polymer.html">
<link rel="import" href="../../../bower_components/iron-dropdown/iron-dropdown.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/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="../../../behaviors/rest-client-behavior.html">
<link rel="import" href="../../shared/gr-button/gr-button.html"> <link rel="import" href="../../shared/gr-button/gr-button.html">
<link rel="import" href="../../shared/gr-overlay/gr-overlay.html"> <link rel="import" href="../../shared/gr-overlay/gr-overlay.html">

View File

@ -15,7 +15,7 @@ limitations under the License.
--> -->
<link rel="import" href="../../../bower_components/polymer/polymer.html"> <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"> <dom-module id="gr-selection-action-box">
<template> <template>

View File

@ -15,7 +15,7 @@ limitations under the License.
--> -->
<link rel="import" href="../bower_components/polymer/polymer.html"> <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="../styles/app-theme.html">
<link rel="import" href="./core/gr-error-manager/gr-error-manager.html"> <link rel="import" href="./core/gr-error-manager/gr-error-manager.html">

View File

@ -16,7 +16,7 @@ limitations under the License.
<link rel="import" href="../../../bower_components/polymer/polymer.html"> <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/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"> <dom-module id="gr-button">
<template strip-whitespace> <template strip-whitespace>

View File

@ -110,6 +110,7 @@ limitations under the License.
'gr-patch-set-behavior/gr-patch-set-behavior_test.html', 'gr-patch-set-behavior/gr-patch-set-behavior_test.html',
'gr-path-list-behavior/gr-path-list-behavior_test.html', 'gr-path-list-behavior/gr-path-list-behavior_test.html',
].forEach(function(file) { ].forEach(function(file) {
// Behaviors do not utilize the DOM, so no shadow DOM test is necessary.
file = behaviorsPath + file; file = behaviorsPath + file;
testFiles.push(file); testFiles.push(file);
}); });