DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (409f3966645a)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=548523
-->
<head>
  <title>Test for Bug 548523</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  <script type="text/javascript" src="manifest.js"></script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=548523">Mozilla Bug 548523</a>
<p id="display"></p>
<div id="content" style="display: none">
  
</div>
<!-- <button onClick="SimpleTest.finish();">Finish</button> -->
<div>Tests complete: <span id="log" style="font-size: small;"></span></div>
<pre id="test">
<script type="application/javascript">

/** Test for Bug 548523 **/

SimpleTest.requestCompleteLog();
var manager = new MediaTestManager;

manager.onFinished = function() {
  is(gotLoadEvent, true, "Should not have delayed the load event indefinitely");
};

var test = getPlayableVideo(gSeekTests);
var baseName = test.name;
var gTest = test;
var bogusSrc = "bogus.duh";
var bogusType = "video/bogus";
var gotLoadEvent = false;
var finished = false;

addLoadEvent(function() {gotLoadEvent=true;});

function log(m) {
  var l = document.getElementById("log");
  l.innerHTML += m;
}

function maybeFinish(v, n) {
  if (v._finished) {
    return;
  }
  v._finished = true;
  log(n + ",");
  removeNodeAndSource(v);
  manager.finished(v.token);
}

function filename(uri) {
  return uri.substr(uri.lastIndexOf("/")+1);
}

// Every test must have a setup(v) function, and must call maybeFinish() when test is complete.
var tests = [
  {
    // 1. Add preload:none video with src to document. Load should halt at NETWORK_IDLE and HAVE_NOTHING,
    // after receiving a suspend event. Should not receive loaded events until after we call load().
    // Note the suspend event is explictly sent by our "stop the load" code, but other tests can't rely
    // on it for the preload:metadata case, as there can be multiple suspend events when loading metadata.
    suspend:
    function(e) {
      var v = e.target;
      is(v._gotLoadStart, true, "(1) Must get loadstart.");
      is(v._gotLoadedMetaData, false, "(1) Must not get loadedmetadata.");
      is(v.readyState, v.HAVE_NOTHING, "(1) ReadyState must be HAVE_NOTHING");
      // bug 962949
      // is(v.networkState, v.NETWORK_IDLE, "(1) NetworkState must be NETWORK_IDLE");
      maybeFinish(v, 1);
    },

    setup:
    function(v) {
      v._gotLoadStart = false;
      v._gotLoadedMetaData = false;
      v.preload = "none";
      v.addEventListener("loadedmetadata", function(e){v._gotLoadedMetaData = true;});
      v.addEventListener("loadstart", function(e){v._gotLoadStart = true;});
      v.addEventListener("suspend", this.suspend);
      v.src = test.name;
      document.body.appendChild(v); // Causes implicit load, which will be halted due to preload:none.
    },

    name: "test1",
  },
  {
    // 2. Add preload:metadata video with src to document. Should halt with NETWORK_IDLE, HAVE_CURRENT_DATA
    // after suspend event and after loadedmetadata.
    loadeddata:
    function(e) {
      var v = e.target;
      is(v._gotLoadStart, true, "(2) Must get loadstart.");
      is(v._gotLoadedMetaData, true, "(2) Must get loadedmetadata.");
      ok(v.readyState >= v.HAVE_CURRENT_DATA, "(2) ReadyState must be >= HAVE_CURRENT_DATA");
      // bug 962949
      // is(v.networkState, v.NETWORK_IDLE, "(2) NetworkState must be NETWORK_IDLE");
      maybeFinish(v, 2);
    },

    setup:
    function(v) {
      v._gotLoadStart = false;
      v._gotLoadedMetaData = false;
      v.preload = "metadata";
      v.addEventListener("loadstart", function(e){v._gotLoadStart = true;});
      v.addEventListener("loadedmetadata", function(e){v._gotLoadedMetaData = true;});
      v.addEventListener("loadeddata", this.loadeddata);
      v.src = test.name;
      document.body.appendChild(v); // Causes implicit load, which will be halted after
                                     // metadata due to preload:metadata.
    },

    name: "test2",
  },
  {
    // 3. Add preload:auto to document. Should receive canplaythrough eventually.
    canplaythrough:
    function(e) {
      var v = e.target;
      is(v._gotLoadStart, true, "(3) Must get loadstart.");
      is(v._gotLoadedMetaData, true, "(3) Must get loadedmetadata.");
      maybeFinish(v, 3);
    },

    setup:
    function(v) {
      v._gotLoadStart = false;
      v._gotLoadedMetaData = false;
      v.preload = "auto";
      v.addEventListener("loadstart", function(e){v._gotLoadStart = true;});
      v.addEventListener("loadedmetadata", function(e){v._gotLoadedMetaData = true;});
      v.addEventListener("canplaythrough", this.canplaythrough);
      v.src = test.name; // Causes implicit load.
      document.body.appendChild(v);
    },

    name: "test3",
  },
  {
    // 4. Add preload:none video to document. Call play(), should load then play through.
    suspend:
    function(e) {
      var v = e.target;
      if (v._gotSuspend) {
        return; // We can receive multiple suspend events, like the one after download completes.
      }
      v._gotSuspend = true;
      is(v._gotLoadStart, true, "(4) Must get loadstart.");
      is(v._gotLoadedMetaData, false, "(4) Must not get loadedmetadata.");
      is(v.readyState, v.HAVE_NOTHING, "(4) ReadyState must be HAVE_NOTHING");
      // bug 962949
      // is(v.networkState, v.NETWORK_IDLE, "(4) NetworkState must be NETWORK_IDLE");
      v.play(); // Should load and play through.
    },

    ended:
    function(e) {
      ok(true, "(4) Got playback ended");
      maybeFinish(e.target, 4);
    },

    setup:
    function(v) {
      v._gotLoadStart = false;
      v._gotLoadedMetaData = false;
      v._gotSuspend = false;
      v.preload = "none";
      v.addEventListener("loadedmetadata", function(e){v._gotLoadedMetaData = true;});
      v.addEventListener("loadstart", function(e){v._gotLoadStart = true;});
      v.addEventListener("suspend", this.suspend);
      v.addEventListener("ended", this.ended);
      v.src = test.name;
      document.body.appendChild(v);
    },

    name: "test4",
  },
  {
    // 5. preload:none video without resource, add to document, will implicitly start a
    // preload:none load. Add a src, it shouldn't load.
    suspend:
    function(e) {
      var v = e.target;
      is(v._gotLoadStart, true, "(5) Must get loadstart.");
      is(v._gotLoadedMetaData, false, "(5) Must not get loadedmetadata.");
      is(v.readyState, v.HAVE_NOTHING, "(5) ReadyState must be HAVE_NOTHING");
      // bug 962949
      // is(v.networkState, v.NETWORK_IDLE, "(5) NetworkState must be NETWORK_IDLE");
      maybeFinish(v, 5);
    },

    setup:
    function(v) {
      v._gotLoadStart = false;
      v._gotLoadedMetaData = false;
      v.preload = "none";
      v.addEventListener("loadedmetadata", function(e){v._gotLoadedMetaData = true;});
      v.addEventListener("loadstart", function(e){v._gotLoadStart = true;});
      v.addEventListener("suspend", this.suspend);
      document.body.appendChild(v); // Causes implicit load, which will be halted due to no resource.
      v.src = test.name; // Load should start, and halt at preload:none.
    },

    name: "test5",
  },
  {
    // 6. preload:none video without resource, add to document, will implicitly start a
    // preload:none load. Add a source, it shouldn't load.
    suspend:
    function(e) {
      var v = e.target;
      is(v._gotLoadStart, true, "(6) Must get loadstart.");
      is(v._gotLoadedMetaData, false, "(6) Must not get loadedmetadata.");
      is(v.readyState, v.HAVE_NOTHING, "(6) ReadyState must be HAVE_NOTHING");
      // bug 962949
      // is(v.networkState, v.NETWORK_IDLE, "(6) NetworkState must be NETWORK_IDLE");
      maybeFinish(v, 6);
    },

    setup:
    function(v) {
      v._gotLoadStart = false;
      v._gotLoadedMetaData = false;
      v.preload = "none";
      v.addEventListener("loadedmetadata", function(e){v._gotLoadedMetaData = true;});
      v.addEventListener("loadstart", function(e){v._gotLoadStart = true;});
      v.addEventListener("suspend", this.suspend);
      document.body.appendChild(v); // Causes implicit load, which will be halted due to no resource.
      var s = document.createElement("source");
      s.src = test.name;
      s.type = test.type;
      v.appendChild(s); // Load should start, and halt at preload:none.
    },

    name: "test6",
  },
  {
    // 7. create a preload:none document with multiple sources, the first of which is invalid.
    // Add to document, then play. It should load and play through the second source.
    suspend:
    function(e) {
      var v = e.target;
      if (v._gotSuspend) 
        return; // We can receive multiple suspend events, like the one after download completes.
      v._gotSuspend = true;
      is(v._gotLoadStart, true, "(7) Must get loadstart.");
      is(v._gotLoadedMetaData, false, "(7) Must not get loadedmetadata.");
      is(v.readyState, v.HAVE_NOTHING, "(7) ReadyState must be HAVE_NOTHING");
      // bug 962949
      // is(v.networkState, v.NETWORK_IDLE, "(7) NetworkState must be NETWORK_IDLE");
      v.play(); // Should load and play through.
    },

    ended:
    function(e) {
      ok(true, "(7) Got playback ended");
      var v = e.target;
      is(v._gotErrorEvent, true, "(7) Should get error event from first source load failure");      
      maybeFinish(v, 7);
    },

    setup:
    function(v) {
      v._gotLoadStart = false;
      v._gotLoadedMetaData = false;
      v.preload = "none";
      v._gotErrorEvent = false;
      v.addEventListener("loadedmetadata", function(e){v._gotLoadedMetaData = true;});
      v.addEventListener("loadstart", function(e){v._gotLoadStart = true;});
      v.addEventListener("suspend", this.suspend);
      v.addEventListener("ended", this.ended);
      var s1 = document.createElement("source");
      s1.src = "not-a-real-file.404"
      s1.type = test.type;
      s1.addEventListener("error", function(e){v._gotErrorEvent = true;});
      v.appendChild(s1);
      var s2 = document.createElement("source");
      s2.src = test.name;
      s2.type = test.type;
      v.appendChild(s2);
      document.body.appendChild(v); // Causes implicit load, which will be halt at preload:none on the second resource.
    },

    name: "test7",
  },
  {
    // 8. Change preload value from none to metadata should cause metadata to be loaded.
    loadeddata:
    function(e) {
      var v = e.target;
      is(v._gotLoadedMetaData, true, "(8) Must get loadedmetadata.");
      ok(v.readyState >= v.HAVE_CURRENT_DATA, "(8) ReadyState must be >= HAVE_CURRENT_DATA on suspend.");
      // bug 962949
      // is(v.networkState, v.NETWORK_IDLE, "(8) NetworkState must be NETWORK_IDLE when load is halted");
      maybeFinish(v, 8);
    },

    setup:
    function(v) {
      v._gotLoadedMetaData = false;
      v.preload = "none";
      v.addEventListener("loadstart", function(e){v.preload = "metadata";});
      v.addEventListener("loadedmetadata", function(e){v._gotLoadedMetaData = true;});
      v.addEventListener("loadeddata", this.loadeddata);
      v.src = test.name; // Causes implicit load.
      document.body.appendChild(v);
    },

    name: "test8",
  },
  /*{
    // 9. Change preload value from metadata to auto should cause entire media to be loaded.
    // For some reason we don't always receive the canplaythrough event, particuarly on this test.
    // We've disabled this test until bug 568402 is fixed.
    canplaythrough:
    function(e) {
      var v = e.target;
      is(v._gotLoadStart, true, "(9) Must get loadstart.");
      is(v._gotLoadedMetaData, true, "(9) Must get loadedmetadata.");
      maybeFinish(v, 9);
    },

    setup:
    function(v) {
      v._gotLoadStart = false;
      v._gotLoadedMetaData = false;
      v.preload = "metadata";
      v.addEventListener("loadstart", function(e){v._gotLoadStart = true;}, false);
      v.addEventListener("loadedmetadata", function(e){v._gotLoadedMetaData = true;}, false);
      v.addEventListener("loadeddata", function(){v.preload = "auto"}, false);
      v.addEventListener("canplaythrough", this.canplaythrough, false);
      v.src = test.name; // Causes implicit load.
      document.body.appendChild(v);
    },
  },*/
  {
    // 10. Change preload value from none to auto should cause entire media to be loaded.
    canplaythrough:
    function(e) {
      var v = e.target;
      is(v._gotLoadedMetaData, true, "(10) Must get loadedmetadata.");
      maybeFinish(v, 10);
    },

    setup:
    function(v) {
      v._gotLoadedMetaData = false;
      v.preload = "none";
      v.addEventListener("loadstart", function(e){v.preload = "auto";});
      v.addEventListener("loadedmetadata", function(e){v._gotLoadedMetaData = true;});
      v.addEventListener("canplaythrough", this.canplaythrough);
      v.src = test.name; // Causes implicit load.
      document.body.appendChild(v);
    },

    name: "test10",
  },
  {
    // 11. Change preload value from none to metadata should cause metadata to load.
    loadeddata:
    function(e) {
      var v = e.target;
      is(v._gotLoadedMetaData, true, "(11) Must get loadedmetadata.");
      ok(v.readyState >= v.HAVE_CURRENT_DATA, "(11) ReadyState must be >= HAVE_CURRENT_DATA.");
      // bug 962949
      // is(v.networkState, v.NETWORK_IDLE, "(11) NetworkState must be NETWORK_IDLE.");
      maybeFinish(v, 11);
    },

    setup:
    function(v) {
      v._gotLoadedMetaData = false;
      v.preload = "none";
      v.addEventListener("loadstart", function(e){v.preload = "metadata";});
      v.addEventListener("loadedmetadata", function(e){v._gotLoadedMetaData = true;});
      v.addEventListener("loadeddata", this.loadeddata);
      v.src = test.name; // Causes implicit load.
      document.body.appendChild(v);
    },

    name: "test11",
  },
  {
    // 13. Change preload value from auto to none after specifying a src
    // should load according to preload none, no buffering should have taken place
    suspend:
    function(e) {
      var v = e.target;
      is(v._gotLoadStart, true, "(13) Must get loadstart.");
      is(v._gotLoadedMetaData, false, "(13) Must not get loadedmetadata.");
      is(v.readyState, v.HAVE_NOTHING, "(13) ReadyState must be HAVE_NOTHING");
      // bug 962949
      // is(v.networkState, v.NETWORK_IDLE, "(13) NetworkState must be NETWORK_IDLE");
      maybeFinish(v, 13);
    },

    setup:
    function(v) {
      v._gotLoadStart = false;
      v._gotLoadedMetaData = false;
      v.preload = "auto";
      v.src = test.name;
      v.preload = "none";
      v.addEventListener("loadedmetadata", function(e){v._gotLoadedMetaData = true;});
      v.addEventListener("loadstart", function(e){v._gotLoadStart = true;});
      v.addEventListener("suspend", this.suspend);
      document.body.appendChild(v); // Causes implicit load, should load according to preload none
      var s = document.createElement("source");
    },

    name: "test13",
  },
  {
    // 14. Add preload:metadata video with src to document. Play(), should play through.
    loadeddata:
    function(e) {
      var v = e.target;
      is(v._gotLoadStart, true, "(14) Must get loadstart.");
      is(v._gotLoadedMetaData, true, "(14) Must get loadedmetadata.");
      ok(v.readyState >= v.HAVE_CURRENT_DATA, "(14) ReadyState must be >= HAVE_CURRENT_DATA");
      // bug 962949
      // is(v.networkState, v.NETWORK_IDLE, "(14) NetworkState must be NETWORK_IDLE");
      v.play();
    },

    ended:
    function(e) {
      ok(true, "(14) Got playback ended");
      var v = e.target;
      maybeFinish(v, 14);
    },

    setup:
    function(v) {
      v._gotLoadStart = false;
      v._gotLoadedMetaData = false;
      v.preload = "metadata";
      v.addEventListener("loadstart", function(e){v._gotLoadStart = true;});
      v.addEventListener("loadedmetadata", function(e){v._gotLoadedMetaData = true;});
      v.addEventListener("ended", this.ended);
      v.addEventListener("loadeddata", this.loadeddata);
      v.src = test.name;
      document.body.appendChild(v); // Causes implicit load, which will be halted after
                                     // metadata due to preload:metadata.
    },

    name: "test14",
  },
  {
    // 15. Autoplay should override preload:none.
    ended:
    function(e) {
      ok(true, "(15) Got playback ended.");
      var v = e.target;
      maybeFinish(v, 15);
    },

    setup:
    function(v) {
      v._gotLoadStart = false;
      v._gotLoadedMetaData = false;
      v.preload = "none";
      v.autoplay = true;
      v.addEventListener("loadstart", function(e){v._gotLoadStart = true;});
      v.addEventListener("loadedmetadata", function(e){v._gotLoadedMetaData = true;});
      v.addEventListener("ended", this.ended);
      v.src = test.name; // Causes implicit load.
      document.body.appendChild(v);

      // Log events for debugging.
      var events = ["suspend", "play", "canplay", "canplaythrough", "loadstart", "loadedmetadata",
                    "loadeddata", "playing", "ended", "error", "stalled", "emptied", "abort",
                    "waiting", "pause"];
      function logEvent(e) {
        var v = e.target;
        info(e.target.token + ": got " + e.type);
      }
      events.forEach(function(e) {
        v.addEventListener(e, logEvent);
      });
    },

    name: "test15",
  },
  {
    // 16. Autoplay should override preload:metadata.
    ended:
    function(e) {
      ok(true, "(16) Got playback ended.");
      var v = e.target;
      maybeFinish(v, 16);
    },

    setup:
    function(v) {
      v.preload = "metadata";
      v.autoplay = true;
      v.addEventListener("ended", this.ended);
      v.src = test.name; // Causes implicit load.
      document.body.appendChild(v);
    },

    name: "test16",
  },
  {
    // 17. On a preload:none video, adding autoplay should disable preload none, i.e. don't break autoplay!
    ended:
    function(e) {
      ok(true, "(17) Got playback ended.");
      var v = e.target;
      maybeFinish(v, 17);
    },

    setup:
    function(v) {
      v.addEventListener("ended", this.ended);
      v.preload = "none";
      document.body.appendChild(v); // Causes implicit load, which will be halted due to preload:none.
      v.autoplay = true;
      v.src = test.name;
    },

    name: "test17",
  },
  {
    // 18. On a preload='none' video, call play() before load algorithms's sync
    // has run, the play() call should override preload='none'.
    ended:
    function(e) {
      ok(true, "(18) Got playback ended.");
      var v = e.target;
      maybeFinish(v, 18);
    },

    setup:
    function(v) {
      v.addEventListener("ended", this.ended);
      v.preload = "none";
      v.src = test.name; // Schedules async section to continue load algorithm.
      document.body.appendChild(v);
      v.play(); // Should cause preload:none to be overridden.
    },

    name: "test18",
  },
  {
    // 19. Set preload='auto' on first video source then switching preload='none' and swapping the video source to another.
    // The second video should not start playing as it's preload state has been changed to 'none' from 'auto'
    setup:
    function(v) {
      v.preload = "auto";
      v.src = test.name;
      // add a listener for when the video has loaded, so we know preload auto has worked
      v.onloadedmetadata = function() {
        is(v.preload, "auto", "(19) preload is initially auto");
        // set preload state to none and switch video sources
        v.preload="none";
        v.src = test.name + "?asdf";

        v.onloadedmetadata = function() {
          ok(false, "(19) 'loadedmetadata' shouldn't fire when preload is none");
        }

        var ontimeout = function() {
          v.removeEventListener("suspend", onsuspend);
          ok(false, "(19) 'suspend' should've fired");
          maybeFinish(v, 19);
        }
        var cancel = setTimeout(ontimeout, 10000);

        var onsuspend = function() {
          v.removeEventListener("suspend", onsuspend);
          clearTimeout(cancel);
          is(v.readyState, 0, "(19) no buffering has taken place");
          maybeFinish(v, 19);
        }
        v.addEventListener("suspend", onsuspend);
      }
      document.body.appendChild(v);
    },

    name: "test19",
  }
];

var iterationCount = 0;
function startTest(test, token) {
  if (test == tests[0]) {
    ++iterationCount;
    info("iterationCount=" + iterationCount);
  }
  if (iterationCount == 2) {
    // Do this series of tests on logically different resources
    test.name = baseName + "?" + Math.floor(Math.random()*100000);
  }
  var v = document.createElement("video");
  v.token = token;
  test.setup(v);
  manager.started(token);
}

var twiceTests = tests.concat(tests);
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [["media.cache_size", 40000]]}, beginTest);
function beginTest() {
  manager.runTests(twiceTests, startTest);
}
</script>
</pre>
</body>
</html>