Skip to content

Commit b422fec

Browse files
authored
Add test fixture for media event bubbling (#12004)
We want to start refactoring some of the event constants, but we don't have a great way to confirm media events work as intended. This commit adds a new DOM test fixture to verify that media events bubble.
1 parent 4501996 commit b422fec

File tree

4 files changed

+125
-0
lines changed

4 files changed

+125
-0
lines changed

fixtures/dom/public/test.mp4

1.79 MB
Binary file not shown.

fixtures/dom/src/components/Header.js

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class Header extends React.Component {
6363
<option value="/error-handling">Error Handling</option>
6464
<option value="/event-pooling">Event Pooling</option>
6565
<option value="/custom-elements">Custom Elements</option>
66+
<option value="/media-events">Media Events</option>
6667
</select>
6768
</label>
6869
<label htmlFor="react_version">

fixtures/dom/src/components/fixtures/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import DateInputFixtures from './date-inputs';
1010
import ErrorHandling from './error-handling';
1111
import EventPooling from './event-pooling';
1212
import CustomElementFixtures from './custom-elements';
13+
import MediaEventsFixtures from './media-events';
1314

1415
const React = window.React;
1516

@@ -43,6 +44,8 @@ function FixturesPage() {
4344
return <EventPooling />;
4445
case '/custom-elements':
4546
return <CustomElementFixtures />;
47+
case '/media-events':
48+
return <MediaEventsFixtures />;
4649
default:
4750
return <p>Please select a test fixture.</p>;
4851
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
import FixtureSet from '../../FixtureSet';
2+
import TestCase from '../../TestCase';
3+
4+
const React = window.React;
5+
6+
export default class MediaEvents extends React.Component {
7+
state = {
8+
playbackRate: 2,
9+
events: {
10+
onCanPlay: false,
11+
onCanPlayThrough: false,
12+
onDurationChange: false,
13+
onEmptied: false,
14+
onEnded: false,
15+
onError: false,
16+
onLoadedData: false,
17+
onLoadedMetadata: false,
18+
onLoadStart: false,
19+
onPause: false,
20+
onPlay: false,
21+
onPlaying: false,
22+
onProgress: false,
23+
onRateChange: false,
24+
onSeeked: false,
25+
onSeeking: false,
26+
onSuspend: false,
27+
onTimeUpdate: false,
28+
onVolumeChange: false,
29+
onWaiting: false,
30+
},
31+
};
32+
33+
updatePlaybackRate = () => {
34+
this.video.playbackRate = 2;
35+
};
36+
37+
setVideo = el => {
38+
this.video = el;
39+
};
40+
41+
eventDidFire(event) {
42+
this.setState({
43+
events: Object.assign({}, this.state.events, {[event]: true}),
44+
});
45+
}
46+
47+
getProgress() {
48+
const events = Object.keys(this.state.events);
49+
const total = events.length;
50+
const fired = events.filter(type => this.state.events[type]).length;
51+
52+
return fired / total;
53+
}
54+
55+
render() {
56+
const events = Object.keys(this.state.events);
57+
const handlers = events.reduce((events, event) => {
58+
events[event] = this.eventDidFire.bind(this, event);
59+
return events;
60+
}, {});
61+
62+
return (
63+
<FixtureSet title="Media Events" description="">
64+
<TestCase
65+
title="Event bubbling"
66+
description="Media events should synthetically bubble">
67+
<TestCase.Steps>
68+
<li>Play the loaded video</li>
69+
<li>Pause the loaded video</li>
70+
<li>Play the failing video</li>
71+
<li>Drag the track bar</li>
72+
<li>Toggle the volume button</li>
73+
<li>
74+
<button onClick={this.updatePlaybackRate}>
75+
Click this button to increase playback rate
76+
</button>
77+
</li>
78+
</TestCase.Steps>
79+
80+
<p className="footnote">
81+
Note: This test does not confirm <code>onStalled</code>,{' '}
82+
<code>onAbort</code>, or <code>onEncrypted</code>
83+
</p>
84+
85+
<TestCase.ExpectedResult>
86+
All events in the table below should be marked as "true".
87+
</TestCase.ExpectedResult>
88+
89+
<section {...handlers}>
90+
<video src="/test.mp4" width="300" controls ref={this.setVideo} />
91+
<video src="/missing.mp4" width="300" controls />
92+
<p className="footnote">
93+
Note: The second video will not load. This is intentional.
94+
</p>
95+
</section>
96+
<hr />
97+
<section>
98+
<h3>Events</h3>
99+
<p>The following events should bubble:</p>
100+
<table>
101+
<tbody>{events.map(this.renderOutcome, this)}</tbody>
102+
</table>
103+
</section>
104+
</TestCase>
105+
</FixtureSet>
106+
);
107+
}
108+
109+
renderOutcome(event) {
110+
let fired = this.state.events[event];
111+
112+
return (
113+
<tr key={event}>
114+
<td>
115+
<b>{event}</b>
116+
</td>
117+
<td style={{color: fired ? null : 'red'}}>{`${fired}`}</td>
118+
</tr>
119+
);
120+
}
121+
}

0 commit comments

Comments
 (0)