-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Seekable from source handlers #2376
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import Flash from '../../../src/js/tech/flash.js'; | ||
import { createTimeRange } from '../../../src/js/utils/time-ranges.js'; | ||
import document from 'global/document'; | ||
|
||
q.module('Flash'); | ||
|
@@ -30,14 +31,17 @@ test('currentTime', function() { | |
// Mock out a Flash instance to avoid creating the swf object | ||
let mockFlash = { | ||
el_: { | ||
vjs_setProperty: function(prop, val){ | ||
vjs_setProperty(prop, val){ | ||
setPropVal = val; | ||
}, | ||
vjs_getProperty: function(){ | ||
vjs_getProperty(){ | ||
return getPropVal; | ||
} | ||
}, | ||
seeking: function(){ | ||
seekable(){ | ||
return createTimeRange(5, 1000); | ||
}, | ||
seeking(){ | ||
return seeking; | ||
} | ||
}; | ||
|
@@ -57,6 +61,15 @@ test('currentTime', function() { | |
result = getCurrentTime.call(mockFlash); | ||
equal(result, 20, 'currentTime is retrieved from the lastSeekTarget while seeking'); | ||
notEqual(result, getPropVal, 'currentTime is not retrieved from the element while seeking'); | ||
|
||
// clamp seeks to seekable | ||
setCurrentTime.call(mockFlash, 1001); | ||
result = getCurrentTime.call(mockFlash); | ||
equal(result, mockFlash.seekable().end(0), 'clamped to the seekable end'); | ||
|
||
setCurrentTime.call(mockFlash, 1); | ||
result = getCurrentTime.call(mockFlash); | ||
equal(result, mockFlash.seekable().start(0), 'clamped to the seekable start'); | ||
}); | ||
|
||
test('dispose removes the object element even before ready fires', function() { | ||
|
@@ -141,3 +154,10 @@ test('seekable', function() { | |
result = seekable.call(mockFlash); | ||
equal(result.length, mockFlash.duration_, 'seekable is empty with a zero duration'); | ||
}); | ||
|
||
// fake out the <object> interaction but leave all the other logic intact | ||
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. What's your thoughts on this type of mock vs the 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. This was an experiment. It implicitly pulls in more logic from the Flash tech than the 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. So I've actually been moving in the opposite direction, trying to require less code that's unrelated to the test to execute. With the Player and Tech mocks like this one, errors in those classes cause half the tests in the suite to fail. The other way requires more setup but it's also pretty explicit about what the function expects. Though if the class you're mocking changes, I guess you could miss issues around that. So not sure which is better or if there's a middle ground. |
||
class MockFlash extends Flash { | ||
constructor() { | ||
super({}); | ||
} | ||
} |
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.
Wait what? We can use this outside of classes?
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.
:)
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.
These are shorthand for functions. They're different from the methods in classes. Notice how there's a comma between them but not in classes.
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.
Ah, I see.