content/media/test/test_play_twice.html

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <head>
michael@0 4 <title>Test playback of media files that should play OK</title>
michael@0 5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 7 <script type="text/javascript" src="manifest.js"></script>
michael@0 8 </head>
michael@0 9 <body>
michael@0 10 <pre id="test">
michael@0 11 <script class="testbody" type="text/javascript">
michael@0 12
michael@0 13 var manager = new MediaTestManager;
michael@0 14
michael@0 15 function startTest(test, token) {
michael@0 16 var v = document.createElement('video');
michael@0 17 v.preload = "metadata";
michael@0 18 v.token = token;
michael@0 19 manager.started(token);
michael@0 20 v.src = test.name;
michael@0 21 v.name = test.name;
michael@0 22 v.playingCount = 0;
michael@0 23 var check = function(test, v) { return function() {
michael@0 24 checkMetadata(test.name, v, test);
michael@0 25 }}(test, v);
michael@0 26 var noLoad = function(test, v) { return function() {
michael@0 27 ok(false, test.name + " should not fire 'load' event");
michael@0 28 }}(test, v);
michael@0 29 var checkEnded = function(test, v) { return function() {
michael@0 30 if (test.duration) {
michael@0 31 ok(Math.abs(v.currentTime - test.duration) < 0.1,
michael@0 32 test.name + " current time at end: " + v.currentTime);
michael@0 33 }
michael@0 34 is(v.readyState, v.HAVE_CURRENT_DATA, test.name + " checking readyState");
michael@0 35 ok(v.readyState != v.NETWORK_LOADED, test.name + " shouldn't report NETWORK_LOADED");
michael@0 36 ok(v.ended, test.name + " checking playback has ended");
michael@0 37 ok(v.playingCount > 0, "Expect at least one playing event");
michael@0 38 v.playingCount = 0;
michael@0 39 if (v._playedOnce && v.seenSuspend) {
michael@0 40 v.parentNode.removeChild(v);
michael@0 41 manager.finished(v.token);
michael@0 42 } else {
michael@0 43 v._playedOnce = true;
michael@0 44 v.play();
michael@0 45 }
michael@0 46 }}(test, v);
michael@0 47 var checkSuspended = function(test, v) { return function() {
michael@0 48 if (v.seenSuspend)
michael@0 49 return;
michael@0 50
michael@0 51 v.seenSuspend = true;
michael@0 52 ok(true, test.name + " got suspend");
michael@0 53 if (v._playedOnce && v.seenSuspend) {
michael@0 54 v.parentNode.removeChild(v);
michael@0 55 manager.finished(v.token);
michael@0 56 }
michael@0 57 }}(test, v);
michael@0 58 var checkPlaying = function(test, v) { return function() {
michael@0 59 is(test.name, v.name, "Should be testing file we think we're testing...");
michael@0 60 v.playingCount++;
michael@0 61 }}(test, v);
michael@0 62 v.addEventListener("load", noLoad, false);
michael@0 63 v.addEventListener("loadedmetadata", check, false);
michael@0 64 v.addEventListener("playing", checkPlaying, false);
michael@0 65
michael@0 66 // We should get "ended" and "suspend" events for every resource
michael@0 67 v.addEventListener("ended", checkEnded, false);
michael@0 68 v.addEventListener("suspend", checkSuspended, false);
michael@0 69
michael@0 70 document.body.appendChild(v);
michael@0 71 v.play();
michael@0 72 }
michael@0 73
michael@0 74 manager.runTests(gReplayTests, startTest);
michael@0 75
michael@0 76 </script>
michael@0 77 </pre>
michael@0 78 </body>
michael@0 79 </html>

mercurial