| <!DOCTYPE html> |
| <title>Test media loading behaviour with different "preload" values.</title> |
| <script src="../resources/testharness.js"></script> |
| <script src="../resources/testharnessreport.js"></script> |
| <script> |
| var movies = [ |
| // should not buffer, "preload" is "none". |
| { preload: "none", shouldBuffer: false, autoPlay: false }, |
| // should buffer because "autoplay" is set. |
| { preload: "none", shouldBuffer: true, autoPlay: true }, |
| // should buffer, because load() is called. |
| { preload: "none", shouldBuffer: true, autoPlay: false, load: "" }, |
| // should buffer, because play() is called. |
| { preload: "none", shouldBuffer: true, autoPlay: false, play: "" }, |
| // should buffer because "preload" is "metadata". |
| { preload: "metadata", shouldBuffer: true, autoPlay: false }, |
| // should buffer because "preload" is "auto". |
| { preload: "auto", shouldBuffer: true, autoPlay: false } |
| ]; |
| |
| for (var movie of movies) { |
| async_test(function(t) { |
| var video = document.createElement("video"); |
| video.onerror = t.step_func(function() {}); |
| video.onloadstart = t.step_func(function() {}); |
| video.onplay = t.step_func(function() {}); |
| |
| video.onloadedmetadata = t.step_func_done(function() { |
| assert_true(movie.shouldBuffer); |
| }); |
| |
| setupAttribute("preload", movie.preload); |
| setupAttribute("autoplay", movie.autoPlay); |
| video.src = "content/test.ogv"; |
| |
| if (movie.hasOwnProperty("play")) |
| video.play(); |
| else if (movie.hasOwnProperty("load")) |
| video.load(); |
| |
| if (!movie.shouldBuffer) { |
| setTimeout(function() { |
| // start playback, which should force data to load. |
| movie.shouldBuffer = true; |
| video.play(); |
| }, 200); |
| } |
| |
| function setupAttribute(attr, value) { |
| if (value) |
| video.setAttribute(attr, value); |
| else |
| video.removeAttribute(attr); |
| } |
| }); |
| } |
| </script> |