|
| 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