Commit be2b45dd authored by Trent Apted's avatar Trent Apted Committed by Commit Bot

CrOS: Consolidate keydown handlers in the audio player.

Currently media keys break in tablet mode, but a 'space' keypress in
the same mode works fine. Media keys are in a separate handler that
probably lost its plumbing when shadow dom was introduced in r592709.

Merge the two key handlers into the one that works, and add a test
for 'MediaPlayPause'.

Adds a mapping for '[' and ']' to control tracks since its easier to
test and there's no prior mapping. (Cmd+Shift+][ are next/previous
tab in Chrome Mac).

Bug: 899094
Change-Id: Ie57b9b0d497b1996566ea3a1842309f0191d8bff
Reviewed-on: https://chromium-review.googlesource.com/c/1298820Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Commit-Queue: Trent Apted <tapted@chromium.org>
Cr-Commit-Position: refs/heads/master@{#602965}
parent b880df2d
...@@ -7,6 +7,8 @@ Polymer({ ...@@ -7,6 +7,8 @@ Polymer({
listeners: { listeners: {
'toggle-pause-event': 'onTogglePauseEvent_', 'toggle-pause-event': 'onTogglePauseEvent_',
'next-track-event': 'onNextTrackEvent_',
'previous-track-event': 'onPreviousTrackEvent_',
'small-forward-skip-event': 'onSmallForwardSkipEvent_', 'small-forward-skip-event': 'onSmallForwardSkipEvent_',
'small-backword-skip-event': 'onSmallBackwordSkipEvent_', 'small-backword-skip-event': 'onSmallBackwordSkipEvent_',
'big-forward-skip-event': 'onBigForwardSkipEvent_', 'big-forward-skip-event': 'onBigForwardSkipEvent_',
...@@ -80,8 +82,6 @@ Polymer({ ...@@ -80,8 +82,6 @@ Polymer({
* element is ready. * element is ready.
*/ */
ready: function() { ready: function() {
this.addEventListener('keydown', this.onKeyDown_.bind(this));
this.$.audioController.addEventListener('dragging-changed', this.$.audioController.addEventListener('dragging-changed',
this.onDraggingChanged_.bind(this)); this.onDraggingChanged_.bind(this));
...@@ -411,27 +411,6 @@ Polymer({ ...@@ -411,27 +411,6 @@ Polymer({
} }
}, },
/**
* Invoked when the 'keydown' event is fired.
* @param {Event} event The event object.
*/
onKeyDown_: function(event) {
switch (event.key) {
case 'MediaTrackNext':
this.onControllerNextClicked();
break;
case 'MediaPlayPause':
this.playing = !this.playing;
break;
case 'MediaTrackPrevious':
this.onControllerPreviousClicked();
break;
case 'MediaStop':
// TODO: Define "Stop" behavior.
break;
}
},
/** /**
* Computes volume value for audio element. (should be in [0.0, 1.0]) * Computes volume value for audio element. (should be in [0.0, 1.0])
* @param {number} volume Volume which is set in the UI. ([0, 100]) * @param {number} volume Volume which is set in the UI. ([0, 100])
...@@ -480,4 +459,14 @@ Polymer({ ...@@ -480,4 +459,14 @@ Polymer({
onBigBackwordSkipEvent_: function(event) { onBigBackwordSkipEvent_: function(event) {
this.$.audioController.bigSkip(false); this.$.audioController.bigSkip(false);
}, },
/** @private */
onNextTrackEvent_: function(event) {
this.onControllerNextClicked();
},
/** @private */
onPreviousTrackEvent_: function(event) {
this.onControllerPreviousClicked();
},
}); });
...@@ -385,6 +385,7 @@ AudioPlayer.prototype.onKeyDown_ = function(event) { ...@@ -385,6 +385,7 @@ AudioPlayer.prototype.onKeyDown_ = function(event) {
case ' ': // Space case ' ': // Space
case 'k': case 'k':
case 'MediaPlayPause':
this.player_.dispatchEvent(new Event('toggle-pause-event')); this.player_.dispatchEvent(new Event('toggle-pause-event'));
break; break;
case 'ArrowUp': case 'ArrowUp':
...@@ -403,6 +404,17 @@ AudioPlayer.prototype.onKeyDown_ = function(event) { ...@@ -403,6 +404,17 @@ AudioPlayer.prototype.onKeyDown_ = function(event) {
case 'j': case 'j':
this.player_.dispatchEvent(new Event('big-backword-skip-event')); this.player_.dispatchEvent(new Event('big-backword-skip-event'));
break; break;
case ']':
case 'MediaTrackNext':
this.player_.dispatchEvent(new Event('next-track-event'));
break;
case '[':
case 'MediaTrackPrevious':
this.player_.dispatchEvent(new Event('previous-track-event'));
break;
case 'MediaStop':
// TODO: Define "Stop" behavior.
break;
} }
}; };
......
...@@ -33,41 +33,75 @@ function controlPanelQuery(query) { ...@@ -33,41 +33,75 @@ function controlPanelQuery(query) {
testcase.togglePlayState = function() { testcase.togglePlayState = function() {
var openAudio = launch('local', 'downloads', [ENTRIES.beautiful]); var openAudio = launch('local', 'downloads', [ENTRIES.beautiful]);
var appId; var appId;
return openAudio.then(function(args) { return openAudio
appId = args[0]; .then(function(args) {
}).then(function() { appId = args[0];
// Audio player should start playing automatically, })
return remoteCallAudioPlayer.waitForElement( .then(function() {
appId, 'audio-player[playing]'); // Audio player should start playing automatically,
}).then(function() { return remoteCallAudioPlayer.waitForElement(
// .. and the play button label should be 'Pause'. appId, 'audio-player[playing]');
return remoteCallAudioPlayer.waitForElement( })
appId, [controlPanelQuery('#play[aria-label="Pause"]')]); .then(function() {
}).then(function() { // .. and the play button label should be 'Pause'.
// Clicking on the play button should return remoteCallAudioPlayer.waitForElement(
return remoteCallAudioPlayer.callRemoteTestUtil( appId, [controlPanelQuery('#play[aria-label="Pause"]')]);
'fakeMouseClick', appId, [controlPanelQuery('#play')]); })
}).then(function() { .then(function() {
// ... change the audio playback state to pause,
return remoteCallAudioPlayer.waitForElement( // First test a media key, before any element may have acquired focus.
appId, 'audio-player:not([playing])'); return remoteCallAudioPlayer.fakeKeyDown(
}).then(function() { appId, null, 'MediaPlayPause', false, false, false);
// ... and the play button label should be 'Play'. })
return remoteCallAudioPlayer.waitForElement( .then(function(result) {
appId, [controlPanelQuery('#play[aria-label="Play"]')]); chrome.test.assertTrue(!!result, 'fakeKeyDown failed.');
}).then(function() { return remoteCallAudioPlayer.waitForElement(
// Clicking on the play button again should appId, 'audio-player:not([playing])');
return remoteCallAudioPlayer.callRemoteTestUtil( })
'fakeMouseClick', appId, [controlPanelQuery('#play')]); .then(function(element) {
}).then(function() { chrome.test.assertTrue(!!element);
// ... change the audio playback state to playing, return remoteCallAudioPlayer.fakeKeyDown(
return remoteCallAudioPlayer.waitForElement( appId, null, 'MediaPlayPause', false, false, false);
appId, 'audio-player[playing]'); })
}).then(function() { .then(function(result) {
// ... and the play button label should be 'Pause'. chrome.test.assertTrue(!!result, 'fakeKeyDown failed.');
return remoteCallAudioPlayer.waitForElement( return remoteCallAudioPlayer.waitForElement(
appId, [controlPanelQuery('#play[aria-label="Pause"]')]); appId, 'audio-player[playing]');
}); })
.then(function(element) {
chrome.test.assertTrue(!!element);
// Clicking on the play button should Play.
return remoteCallAudioPlayer.callRemoteTestUtil(
'fakeMouseClick', appId, [controlPanelQuery('#play')]);
})
.then(function(result) {
chrome.test.assertTrue(!!result, 'fakeMouseClick failed.');
// ... change the audio playback state to pause,
return remoteCallAudioPlayer.waitForElement(
appId, 'audio-player:not([playing])');
})
.then(function() {
// ... and the play button label should be 'Play'.
return remoteCallAudioPlayer.waitForElement(
appId, [controlPanelQuery('#play[aria-label="Play"]')]);
})
.then(function() {
// Clicking on the play button again should
return remoteCallAudioPlayer.callRemoteTestUtil(
'fakeMouseClick', appId, [controlPanelQuery('#play')]);
})
.then(function(result) {
chrome.test.assertTrue(!!result, 'fakeMouseClick failed.');
// ... change the audio playback state to playing,
return remoteCallAudioPlayer.waitForElement(
appId, 'audio-player[playing]');
})
.then(function() {
// ... and the play button label should be 'Pause'.
return remoteCallAudioPlayer.waitForElement(
appId, [controlPanelQuery('#play[aria-label="Pause"]')]);
});
}; };
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment