Skip to content

Add test fixture for media event bubbling #12004

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
merged 1 commit into from
Jan 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added fixtures/dom/public/test.mp4
Binary file not shown.
1 change: 1 addition & 0 deletions fixtures/dom/src/components/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class Header extends React.Component {
<option value="/error-handling">Error Handling</option>
<option value="/event-pooling">Event Pooling</option>
<option value="/custom-elements">Custom Elements</option>
<option value="/media-events">Media Events</option>
</select>
</label>
<label htmlFor="react_version">
Expand Down
3 changes: 3 additions & 0 deletions fixtures/dom/src/components/fixtures/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import DateInputFixtures from './date-inputs';
import ErrorHandling from './error-handling';
import EventPooling from './event-pooling';
import CustomElementFixtures from './custom-elements';
import MediaEventsFixtures from './media-events';

const React = window.React;

Expand Down Expand Up @@ -43,6 +44,8 @@ function FixturesPage() {
return <EventPooling />;
case '/custom-elements':
return <CustomElementFixtures />;
case '/media-events':
return <MediaEventsFixtures />;
default:
return <p>Please select a test fixture.</p>;
}
Expand Down
121 changes: 121 additions & 0 deletions fixtures/dom/src/components/fixtures/media-events/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import FixtureSet from '../../FixtureSet';
import TestCase from '../../TestCase';

const React = window.React;

export default class MediaEvents extends React.Component {
state = {
playbackRate: 2,
events: {
onCanPlay: false,
onCanPlayThrough: false,
onDurationChange: false,
onEmptied: false,
onEnded: false,
onError: false,
onLoadedData: false,
onLoadedMetadata: false,
onLoadStart: false,
onPause: false,
onPlay: false,
onPlaying: false,
onProgress: false,
onRateChange: false,
onSeeked: false,
onSeeking: false,
onSuspend: false,
onTimeUpdate: false,
onVolumeChange: false,
onWaiting: false,
},
};

updatePlaybackRate = () => {
this.video.playbackRate = 2;
};

setVideo = el => {
this.video = el;
};

eventDidFire(event) {
this.setState({
events: Object.assign({}, this.state.events, {[event]: true}),
});
}

getProgress() {
const events = Object.keys(this.state.events);
const total = events.length;
const fired = events.filter(type => this.state.events[type]).length;

return fired / total;
}

render() {
const events = Object.keys(this.state.events);
const handlers = events.reduce((events, event) => {
events[event] = this.eventDidFire.bind(this, event);
return events;
}, {});

return (
<FixtureSet title="Media Events" description="">
<TestCase
title="Event bubbling"
description="Media events should synthetically bubble">
<TestCase.Steps>
<li>Play the loaded video</li>
<li>Pause the loaded video</li>
<li>Play the failing video</li>
<li>Drag the track bar</li>
<li>Toggle the volume button</li>
<li>
<button onClick={this.updatePlaybackRate}>
Click this button to increase playback rate
</button>
</li>
</TestCase.Steps>

<p className="footnote">
Note: This test does not confirm <code>onStalled</code>,{' '}
<code>onAbort</code>, or <code>onEncrypted</code>
</p>

<TestCase.ExpectedResult>
All events in the table below should be marked as "true".
</TestCase.ExpectedResult>

<section {...handlers}>
<video src="/test.mp4" width="300" controls ref={this.setVideo} />
<video src="/missing.mp4" width="300" controls />
<p className="footnote">
Note: The second video will not load. This is intentional.
</p>
</section>
<hr />
<section>
<h3>Events</h3>
<p>The following events should bubble:</p>
<table>
<tbody>{events.map(this.renderOutcome, this)}</tbody>
</table>
</section>
</TestCase>
</FixtureSet>
);
}

renderOutcome(event) {
let fired = this.state.events[event];

return (
<tr key={event}>
<td>
<b>{event}</b>
</td>
<td style={{color: fired ? null : 'red'}}>{`${fired}`}</td>
</tr>
);
}
}