toolkit/content/tests/widgets/test_videocontrols.html

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <head>
michael@0 4 <title>Video controls test</title>
michael@0 5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 6 <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
michael@0 7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 8 </head>
michael@0 9 <body>
michael@0 10 <p id="display"></p>
michael@0 11
michael@0 12 <div id="content">
michael@0 13 <video width="320" height="240" id="video" controls mozNoDynamicControls preload="auto"></video>
michael@0 14 </div>
michael@0 15
michael@0 16 <pre id="test">
michael@0 17 <script class="testbody" type="text/javascript">
michael@0 18
michael@0 19 /*
michael@0 20 * Positions of the UI elements, relative to the upper-left corner of the
michael@0 21 * <video> box.
michael@0 22 */
michael@0 23 const videoWidth = 320;
michael@0 24 const videoHeight = 240;
michael@0 25 const videoDuration = 3.8329999446868896;
michael@0 26
michael@0 27 const playButtonWidth = 28;
michael@0 28 const playButtonHeight = 28;
michael@0 29 const muteButtonWidth = 33;
michael@0 30 const muteButtonHeight = 28;
michael@0 31 const durationWidth = 34;
michael@0 32 const fullscreenButtonWidth = document.mozFullScreenEnabled ? 28 : 0;
michael@0 33 const volumeSliderWidth = 32;
michael@0 34 const scrubberWidth = videoWidth - playButtonWidth - durationWidth - muteButtonWidth - volumeSliderWidth - fullscreenButtonWidth;
michael@0 35 const scrubberHeight = 28;
michael@0 36
michael@0 37 // Play button is on the bottom-left
michael@0 38 const playButtonCenterX = 0 + Math.round(playButtonWidth / 2);
michael@0 39 const playButtonCenterY = videoHeight - Math.round(playButtonHeight / 2);
michael@0 40 // Mute button is on the bottom-right before the full screen button and volume slider
michael@0 41 const muteButtonCenterX = videoWidth - Math.round(muteButtonWidth / 2) - volumeSliderWidth - fullscreenButtonWidth;
michael@0 42 const muteButtonCenterY = videoHeight - Math.round(muteButtonHeight / 2);
michael@0 43 // Scrubber bar is between the play and mute buttons. We don't need it's
michael@0 44 // X center, just the offset of its box.
michael@0 45 const scrubberOffsetX = 0 + playButtonWidth;
michael@0 46 const scrubberCenterY = videoHeight - Math.round(scrubberHeight / 2);
michael@0 47
michael@0 48 function runTest(event) {
michael@0 49 ok(true, "----- test #" + testnum + " -----");
michael@0 50
michael@0 51 switch (testnum) {
michael@0 52 /*
michael@0 53 * Check operation of play/pause/mute/unmute buttons.
michael@0 54 */
michael@0 55 case 1:
michael@0 56 // Check initial state upon load
michael@0 57 is(event.type, "canplaythrough", "checking event type");
michael@0 58 is(video.paused, true, "checking video play state");
michael@0 59 is(video.muted, false, "checking video mute state");
michael@0 60
michael@0 61 // Click the play button
michael@0 62 synthesizeMouse(video, playButtonCenterX, playButtonCenterY, { });
michael@0 63 break;
michael@0 64
michael@0 65 case 2:
michael@0 66 is(event.type, "play", "checking event type");
michael@0 67 is(video.paused, false, "checking video play state");
michael@0 68 is(video.muted, false, "checking video mute state");
michael@0 69
michael@0 70 // Click the pause button
michael@0 71 synthesizeMouse(video, playButtonCenterX, playButtonCenterY, { });
michael@0 72 break;
michael@0 73
michael@0 74 case 3:
michael@0 75 is(event.type, "pause", "checking event type");
michael@0 76 is(video.paused, true, "checking video play state");
michael@0 77 is(video.muted, false, "checking video mute state");
michael@0 78
michael@0 79 // Click the mute button
michael@0 80 synthesizeMouse(video, muteButtonCenterX, muteButtonCenterY, { });
michael@0 81 break;
michael@0 82
michael@0 83 case 4:
michael@0 84 is(event.type, "volumechange", "checking event type");
michael@0 85 is(video.paused, true, "checking video play state");
michael@0 86 is(video.muted, true, "checking video mute state");
michael@0 87
michael@0 88 // Click the unmute button
michael@0 89 synthesizeMouse(video, muteButtonCenterX, muteButtonCenterY, { });
michael@0 90 break;
michael@0 91
michael@0 92 /*
michael@0 93 * Bug 470596: Make sure that having CSS border or padding doesn't
michael@0 94 * break the controls (though it should move them)
michael@0 95 */
michael@0 96 case 5:
michael@0 97 is(event.type, "volumechange", "checking event type");
michael@0 98 is(video.paused, true, "checking video play state");
michael@0 99 is(video.muted, false, "checking video mute state");
michael@0 100
michael@0 101 video.style.border = "medium solid purple";
michael@0 102 video.style.borderWidth = "30px 40px 50px 60px";
michael@0 103 video.style.padding = "10px 20px 30px 40px";
michael@0 104 // totals: top: 40px, right: 60px, bottom: 80px, left: 100px
michael@0 105
michael@0 106 // Click the play button
michael@0 107 synthesizeMouse(video, 100 + playButtonCenterX, 40 + playButtonCenterY, { });
michael@0 108 break;
michael@0 109
michael@0 110 case 6:
michael@0 111 is(event.type, "play", "checking event type");
michael@0 112 is(video.paused, false, "checking video play state");
michael@0 113 is(video.muted, false, "checking video mute state");
michael@0 114 video.pause();
michael@0 115 break;
michael@0 116
michael@0 117 case 7:
michael@0 118 is(event.type, "pause", "checking event type");
michael@0 119 is(video.paused, true, "checking video play state");
michael@0 120 is(video.muted, false, "checking video mute state");
michael@0 121
michael@0 122 // Click the mute button
michael@0 123 synthesizeMouse(video, 100 + muteButtonCenterX, 40 + muteButtonCenterY, { });
michael@0 124 break;
michael@0 125
michael@0 126 case 8:
michael@0 127 is(event.type, "volumechange", "checking event type");
michael@0 128 is(video.paused, true, "checking video play state");
michael@0 129 is(video.muted, true, "checking video mute state");
michael@0 130 // Clear the style set in test 5.
michael@0 131 video.style.border = "";
michael@0 132 video.style.borderWidth = "";
michael@0 133 video.style.padding = "";
michael@0 134
michael@0 135 video.muted = false;
michael@0 136 break;
michael@0 137
michael@0 138 /*
michael@0 139 * Previous tests have moved playback postion, reset it to 0.
michael@0 140 */
michael@0 141 case 9:
michael@0 142 is(event.type, "volumechange", "checking event type");
michael@0 143 is(video.paused, true, "checking video play state");
michael@0 144 is(video.muted, false, "checking video mute state");
michael@0 145 ok(true, "video position is at " + video.currentTime);
michael@0 146 video.currentTime = 0.0;
michael@0 147 break;
michael@0 148
michael@0 149 case 10:
michael@0 150 is(event.type, "seeking", "checking event type");
michael@0 151 ok(true, "video position is at " + video.currentTime);
michael@0 152 break;
michael@0 153
michael@0 154 /*
michael@0 155 * Drag the slider's thumb to the halfway point with the mouse.
michael@0 156 */
michael@0 157 case 11:
michael@0 158 is(event.type, "seeked", "checking event type");
michael@0 159 ok(true, "video position is at " + video.currentTime);
michael@0 160 // Bug 477434 -- sometimes we get 0.098999 here instead of 0!
michael@0 161 // is(video.currentTime, 0.0, "checking playback position");
michael@0 162
michael@0 163 var beginDragX = scrubberOffsetX;
michael@0 164 var endDragX = scrubberOffsetX + (scrubberWidth / 2);
michael@0 165 synthesizeMouse(video, beginDragX, scrubberCenterY, { type: "mousedown", button: 0 });
michael@0 166 synthesizeMouse(video, endDragX, scrubberCenterY, { type: "mousemove", button: 0 });
michael@0 167 synthesizeMouse(video, endDragX, scrubberCenterY, { type: "mouseup", button: 0 });
michael@0 168 break;
michael@0 169
michael@0 170 case 12:
michael@0 171 is(event.type, "seeking", "checking event type");
michael@0 172 ok(true, "video position is at " + video.currentTime);
michael@0 173 break;
michael@0 174
michael@0 175 /*
michael@0 176 * Click the slider at the 1/4 point with the mouse (jump backwards)
michael@0 177 */
michael@0 178 case 13:
michael@0 179 is(event.type, "seeked", "checking event type");
michael@0 180 ok(true, "video position is at " + video.currentTime);
michael@0 181 var expectedTime = videoDuration / 2;
michael@0 182 ok(Math.abs(video.currentTime - expectedTime) < 0.1, "checking expected playback position");
michael@0 183
michael@0 184 synthesizeMouse(video, scrubberOffsetX + (scrubberWidth / 4), scrubberCenterY, { });
michael@0 185 break;
michael@0 186
michael@0 187 case 14:
michael@0 188 is(event.type, "seeking", "checking event type");
michael@0 189 ok(true, "video position is at " + video.currentTime);
michael@0 190 break;
michael@0 191
michael@0 192 case 15:
michael@0 193 is(event.type, "seeked", "checking event type");
michael@0 194 ok(true, "video position is at " + video.currentTime);
michael@0 195 // The scrubber currently just jumps towards the nearest pageIncrement point, not
michael@0 196 // precisely to the point clicked. So, expectedTime isn't (videoDuration / 4).
michael@0 197 // We should end up at 1.733, but sometimes we end up at 1.498. I guess
michael@0 198 // it's timing depending if the <scale> things it's click-and-hold, or a
michael@0 199 // single click. So, just make sure we end up less that the previous
michael@0 200 // position.
michael@0 201 lastPosition = (videoDuration / 2) - 0.1;
michael@0 202 ok(video.currentTime < lastPosition, "checking expected playback position");
michael@0 203
michael@0 204 SimpleTest.finish();
michael@0 205 break;
michael@0 206
michael@0 207 default:
michael@0 208 throw "unexpected test #" + testnum + " w/ event " + event.type;
michael@0 209 }
michael@0 210
michael@0 211 testnum++;
michael@0 212 }
michael@0 213
michael@0 214
michael@0 215 var testnum = 1;
michael@0 216 var video = document.getElementById("video");
michael@0 217
michael@0 218 function canplaythroughevent(event) {
michael@0 219 video.removeEventListener("canplaythrough", canplaythroughevent, false);
michael@0 220 // Other events expected by the test.
michael@0 221 video.addEventListener("play", runTest, false);
michael@0 222 video.addEventListener("pause", runTest, false);
michael@0 223 video.addEventListener("volumechange", runTest, false);
michael@0 224 video.addEventListener("seeking", runTest, false);
michael@0 225 video.addEventListener("seeked", runTest, false);
michael@0 226 // Begin the test.
michael@0 227 runTest(event);
michael@0 228 }
michael@0 229
michael@0 230 function startMediaLoad() {
michael@0 231 // Kick off test once video has loaded, in its canplaythrough event handler.
michael@0 232 video.src = "seek_with_sound.ogg";
michael@0 233 video.addEventListener("canplaythrough", canplaythroughevent, false);
michael@0 234 }
michael@0 235
michael@0 236 function loadevent(event) {
michael@0 237 SpecialPowers.pushPrefEnv({"set": [["media.cache_size", 40000]]}, startMediaLoad);
michael@0 238 }
michael@0 239
michael@0 240 window.addEventListener("load", loadevent, false);
michael@0 241
michael@0 242 SimpleTest.waitForExplicitFinish();
michael@0 243
michael@0 244 </script>
michael@0 245 </pre>
michael@0 246 </body>
michael@0 247 </html>

mercurial