-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Keyboard events and ARIA markup added to speed control #2381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jmclaus
merged 1 commit into
master
from
jmclaus/feature_video_speed_control_improved_a11y
Feb 10, 2014
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,12 +53,6 @@ | |
| 'aria-disabled': 'false' | ||
| }); | ||
| }); | ||
|
|
||
| it('bind to change video speed link', function () { | ||
| expect($('.video_speeds a')).toHandleWith( | ||
| 'click', state.videoSpeedControl.changeVideoSpeed | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe('when running on touch based device', function () { | ||
|
|
@@ -73,71 +67,184 @@ | |
| }); | ||
|
|
||
| describe('when running on non-touch based device', function () { | ||
| var speedControl, speedEntries, | ||
| KEY = $.ui.keyCode, | ||
|
|
||
| keyPressEvent = function(key) { | ||
| return $.Event('keydown', {keyCode: key}); | ||
| }, | ||
|
|
||
| tabBackPressEvent = function() { | ||
| return $.Event('keydown', | ||
| {keyCode: KEY.TAB, shiftKey: true}); | ||
| }, | ||
|
|
||
| tabForwardPressEvent = function() { | ||
| return $.Event('keydown', | ||
| {keyCode: KEY.TAB, shiftKey: false}); | ||
| }, | ||
|
|
||
| // Get previous element in array or cyles back to the last | ||
| // if it is the first. | ||
| previousSpeed = function(index) { | ||
| return speedEntries.eq(index < 1 ? | ||
| speedEntries.length - 1 : | ||
| index - 1); | ||
| }, | ||
|
|
||
| // Get next element in array or cyles back to the first if | ||
| // it is the last. | ||
| nextSpeed = function(index) { | ||
| return speedEntries.eq(index >= speedEntries.length-1 ? | ||
| 0 : | ||
| index + 1); | ||
| }; | ||
|
|
||
| beforeEach(function () { | ||
| state = jasmine.initializePlayer(); | ||
| speedControl = $('div.speeds'); | ||
| speedEntries = speedControl.children('a'); | ||
| spyOn($.fn, 'focus').andCallThrough(); | ||
| }); | ||
|
|
||
| it('open the speed toggle on hover', function () { | ||
| $('.speeds').mouseenter(); | ||
| expect($('.speeds')).toHaveClass('open'); | ||
|
|
||
| $('.speeds').mouseleave(); | ||
| expect($('.speeds')).not.toHaveClass('open'); | ||
| }); | ||
|
|
||
| it('close the speed toggle on mouse out', function () { | ||
| $('.speeds').mouseenter().mouseleave(); | ||
|
|
||
| expect($('.speeds')).not.toHaveClass('open'); | ||
| }); | ||
|
|
||
| it('close the speed toggle on click', function () { | ||
| $('.speeds').mouseenter().click(); | ||
|
|
||
| expect($('.speeds')).not.toHaveClass('open'); | ||
| }); | ||
|
|
||
| // Tabbing depends on the following order: | ||
| // 1. Play anchor | ||
| // 2. Speed anchor | ||
| // 3. A number of speed entry anchors | ||
| // 4. Volume anchor | ||
| // If another focusable element is inserted or if the order is | ||
| // changed, things will malfunction as a flag, | ||
| // state.previousFocus, is set in the 1,3,4 elements and is | ||
| // used to determine the behavior of foucus() and blur() for | ||
| // the speed anchor. | ||
| it( | ||
| 'checks for a certain order in focusable elements in ' + | ||
| 'video controls', | ||
| function () | ||
| { | ||
| var foundFirst = false, | ||
| playIndex, speedIndex, firstSpeedEntry, lastSpeedEntry, | ||
| volumeIndex; | ||
|
|
||
| $('.video-controls').find('a, :focusable').each( | ||
| function (index) | ||
| { | ||
| if ($(this).hasClass('video_control')) { | ||
| playIndex = index; | ||
| } else if ($(this).parent().hasClass('speeds')) { | ||
| speedIndex = index; | ||
| } else if ($(this).hasClass('speed_link')) { | ||
| if (!foundFirst) { | ||
| firstSpeedEntry = index; | ||
| foundFirst = true; | ||
| } | ||
|
|
||
| lastSpeedEntry = index; | ||
| } else if ($(this).parent().hasClass('volume')) { | ||
| volumeIndex = index; | ||
| } | ||
| }); | ||
| it('open/close the speed menu on mouseenter/mouseleave', | ||
| function () { | ||
| speedControl.mouseenter(); | ||
| expect(speedControl).toHaveClass('open'); | ||
| speedControl.mouseleave(); | ||
| expect(speedControl).not.toHaveClass('open'); | ||
| }); | ||
|
|
||
| it('do not close the speed menu on mouseleave if a speed ' + | ||
| 'entry has focus', function () { | ||
| // Open speed meenu. Focus is on last speed entry. | ||
| speedControl.trigger(keyPressEvent(KEY.ENTER)); | ||
| speedControl.mouseenter().mouseleave(); | ||
| expect(speedControl).toHaveClass('open'); | ||
| }); | ||
|
|
||
| it('close the speed menu on click', function () { | ||
| speedControl.mouseenter().click(); | ||
| expect(speedControl).not.toHaveClass('open'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Strange behavior. What do you think? |
||
| }); | ||
|
|
||
| it('close the speed menu on outside click', function () { | ||
| speedControl.trigger(keyPressEvent(KEY.ENTER)); | ||
| $(window).click(); | ||
| expect(speedControl).not.toHaveClass('open'); | ||
| }); | ||
|
|
||
| it('open the speed menu on ENTER keydown', function () { | ||
| speedControl.trigger(keyPressEvent(KEY.ENTER)); | ||
| expect(speedControl).toHaveClass('open'); | ||
| expect(speedEntries.last().focus).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('open the speed menu on SPACE keydown', function () { | ||
| speedControl.trigger(keyPressEvent(KEY.SPACE)); | ||
| expect(speedControl).toHaveClass('open'); | ||
| expect(speedEntries.last().focus).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('open the speed menu on UP keydown', function () { | ||
| speedControl.trigger(keyPressEvent(KEY.UP)); | ||
| expect(speedControl).toHaveClass('open'); | ||
| expect(speedEntries.last().focus).toHaveBeenCalled(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use expect(speedEntries.last()).toBeFocused() |
||
| }); | ||
|
|
||
| it('close the speed menu on ESCAPE keydown', function () { | ||
| speedControl.trigger(keyPressEvent(KEY.ESCAPE)); | ||
| expect(speedControl).not.toHaveClass('open'); | ||
| }); | ||
|
|
||
| it('UP and DOWN keydown function as expected on speed entries', | ||
| function () { | ||
| // Iterate through list in both directions and check if | ||
| // things wrap up correctly. | ||
| var lastEntry = speedEntries.length-1, i; | ||
|
|
||
| // First open menu | ||
| speedControl.trigger(keyPressEvent(KEY.UP)); | ||
|
|
||
| // Iterate with UP key until we have looped. | ||
| for (i = lastEntry; i >= 0; i--) { | ||
| speedEntries.eq(i).trigger(keyPressEvent(KEY.UP)); | ||
| } | ||
|
|
||
| // Iterate with DOWN key until we have looped. | ||
| for (i = 0; i <= lastEntry; i++) { | ||
| speedEntries.eq(i).trigger(keyPressEvent(KEY.DOWN)); | ||
| } | ||
| // Test if each element has been called twice. | ||
| expect($.fn.focus.calls.length) | ||
| .toEqual(2*speedEntries.length); | ||
| }); | ||
|
|
||
| it('ESC keydown on speed entry closes menu', function () { | ||
| // First open menu. Focus is on last speed entry. | ||
| speedControl.trigger(keyPressEvent(KEY.UP)); | ||
| speedEntries.last().trigger(keyPressEvent(KEY.ESCAPE)); | ||
|
|
||
| expect(playIndex+1).toEqual(speedIndex); | ||
| expect(speedIndex+1).toEqual(firstSpeedEntry); | ||
| expect(lastSpeedEntry+1).toEqual(volumeIndex); | ||
| // Menu is closed and focus has been returned to speed | ||
| // control. | ||
| expect(speedControl).not.toHaveClass('open'); | ||
| expect(speedControl.focus).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('ENTER keydown on speed entry selects speed and closes menu', | ||
| function () { | ||
| // First open menu. | ||
| speedControl.trigger(keyPressEvent(KEY.UP)); | ||
| // Focus on 1.50x speed | ||
| speedEntries.eq(1).focus(); | ||
| speedEntries.eq(1).trigger(keyPressEvent(KEY.ENTER)); | ||
|
|
||
| // Menu is closed, focus has been returned to speed | ||
| // control and video speed is 1.50x. | ||
| expect(speedControl.focus).toHaveBeenCalled(); | ||
| expect($('.video_speeds li[data-speed="1.50"]')) | ||
| .toHaveClass('active'); | ||
| expect($('.speeds p.active')).toHaveHtml('1.50x'); | ||
| }); | ||
|
|
||
| it('SPACE keydown on speed entry selects speed and closes menu', | ||
| function () { | ||
| // First open menu. | ||
| speedControl.trigger(keyPressEvent(KEY.UP)); | ||
| // Focus on 1.50x speed | ||
| speedEntries.eq(1).focus(); | ||
| speedEntries.eq(1).trigger(keyPressEvent(KEY.SPACE)); | ||
|
|
||
| // Menu is closed, focus has been returned to speed | ||
| // control and video speed is 1.50x. | ||
| expect(speedControl.focus).toHaveBeenCalled(); | ||
| expect($('.video_speeds li[data-speed="1.50"]')) | ||
| .toHaveClass('active'); | ||
| expect($('.speeds p.active')).toHaveHtml('1.50x'); | ||
| }); | ||
|
|
||
| it('TAB + SHIFT keydown on speed entry closes menu and gives ' + | ||
| 'focus to Play/Pause control', function () { | ||
| // First open menu. Focus is on last speed entry. | ||
| speedControl.trigger(keyPressEvent(KEY.UP)); | ||
| speedEntries.last().trigger(tabBackPressEvent()); | ||
|
|
||
| // Menu is closed and focus has been given to Play/Pause | ||
| // control. | ||
| expect(state.videoControl.playPauseEl.focus) | ||
| .toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('TAB keydown on speed entry closes menu and gives focus ' + | ||
| 'to Volume control', function () { | ||
| // First open menu. Focus is on last speed entry. | ||
| speedControl.trigger(keyPressEvent(KEY.UP)); | ||
| speedEntries.last().trigger(tabForwardPressEvent()); | ||
|
|
||
| // Menu is closed and focus has been given to Volume | ||
| // control. | ||
| expect(state.videoVolumeControl.buttonEl.focus) | ||
| .toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
@@ -163,30 +270,6 @@ | |
| expect(state.videoSpeedControl.currentSpeed).toEqual(0.75); | ||
| }); | ||
| }); | ||
|
|
||
| describe( | ||
| 'make sure the speed control gets the focus afterwards', | ||
| function () | ||
| { | ||
| var anchor; | ||
|
|
||
| beforeEach(function () { | ||
| state = jasmine.initializePlayer(); | ||
| anchor= $('.speeds > a').first(); | ||
| state.videoSpeedControl.setSpeed(1.0); | ||
| spyOnEvent(anchor, 'focus'); | ||
| }); | ||
|
|
||
| it('when the speed is the same', function () { | ||
| $('li[data-speed="1.0"] a').click(); | ||
| expect('focus').toHaveBeenTriggeredOn(anchor); | ||
| }); | ||
|
|
||
| it('when the speed is not the same', function () { | ||
| $('li[data-speed="0.75"] a').click(); | ||
| expect('focus').toHaveBeenTriggeredOn(anchor); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('onSpeedChange', function () { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test can be removed. The same things are tested in the previous test.