Bug 521359. Our tests should not depend on NETWORK_LOADED or the media 'load' event. r=doublec

This commit is contained in:
Robert O'Callahan 2009-10-10 00:48:33 +13:00
parent 6c601aeedb
commit 1b090d96ec
13 changed files with 44 additions and 107 deletions

View File

@ -5,14 +5,11 @@
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<script type="text/javascript" src="use_large_cache.js"></script>
<script type="text/javascript" src="manifest.js"></script>
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
var testsWaiting = 0;
for (var i = 0; i < gAudioTests.length; ++i) {
var test = gAudioTests[i];
var a1 = new Audio();
@ -20,20 +17,8 @@ for (var i = 0; i < gAudioTests.length; ++i) {
continue;
is(a1.getAttribute("autobuffer"), "autobuffer", "Autobuffer automatically set");
a1.addEventListener('load', function(event) {
is(event.target.networkState, HTMLMediaElement.NETWORK_LOADED,
"Audio " + event.target.currentSrc + " loaded");
--testsWaiting;
if (testsWaiting == 0) {
SimpleTest.finish();
}
}, false);
a1.src = test.name;
a1.load();
++testsWaiting;
is(a1.src, "", "Src set?");
}
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>

View File

@ -1,18 +1,15 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Media test: Audio Constructor Test 1</title>
<title>Media test: Audio Constructor Test 2</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<script type="text/javascript" src="use_large_cache.js"></script>
<script type="text/javascript" src="manifest.js"></script>
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
var testsWaiting = 0;
var tmpAudio = new Audio();
for (var i = 0; i < gAudioTests.length; ++i) {
var test = gAudioTests[i];
@ -21,19 +18,8 @@ for (var i = 0; i < gAudioTests.length; ++i) {
var a1 = new Audio(test.name);
is(a1.getAttribute("autobuffer"), "autobuffer", "Autobuffer automatically set");
a1.addEventListener('load', function(event) {
is(event.target.networkState, HTMLMediaElement.NETWORK_LOADED,
"Audio " + event.target.currentSrc + " loaded");
--testsWaiting;
if (testsWaiting == 0) {
SimpleTest.finish();
}
}, false);
a1.load();
++testsWaiting;
is(a1.src.match("/[^/]+$"), "/" + test.name, "src OK");
}
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>

View File

@ -26,34 +26,37 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=479863
<pre id="test">
<script type="application/javascript">
var suspends = {};
var loads = {};
var totalLoadEvents = 0;
var expectedLoadEvents = 6;
function loaded(event) {
loads[event.target.id] = true;
ok(true, "Loaded " + event.target.id);
++totalLoadEvents;
if (totalLoadEvents == expectedLoadEvents) {
ok(suspends.v1, "v1 should have suspended");
ok(!suspends.v2, "v2 should not have suspended");
ok(!suspends.v3, "v3 should not have suspended");
ok(suspends.v4, "v4 should have suspended");
ok(suspends.v5, "v5 should have suspended");
ok(suspends.v6, "v6 should have suspended");
SimpleTest.finish();
}
var suspendCount = {};
var expectedSuspendCount = {v1:2, v2:1, v3:1, v4:2, v5:2, v6:2};
var totalSuspendCount = 0;
for (var i = 0; i < expectedSuspendCount.length; ++i) {
totalSuspendCount += expectedSuspendCount[i];
}
function suspended(event) {
// If the element suspends the download, it should not then be able to
// complete it, so we should be stuck in NETWORK_IDLE even though this
// even though this event handler could run a long time after the actual
// suspend.
is(event.target.networkState, event.target.NETWORK_IDLE,
// event handler could run a long time after the actual suspend.
var expectedState = event.type == "load" ? event.target.NETWORK_LOADED
: event.target.NETWORK_IDLE;
is(event.target.networkState, expectedState,
event.target.id + " suspended networkState");
suspends[event.target.id] = true;
suspendCount[event.target.id]++;
--totalSuspendCount;
if (totalSuspendCount == 0) {
// We're done.
for (var i = 1; i <= 6; ++i) {
var id = "v" + i;
is(suspendCount[id], expectedSuspendCount[id], "Suspend count for " + id);
}
SimpleTest.finish();
}
if (suspendCount[event.target.id] > 1)
return;
if (event.target.id == "v1") {
event.target.autobuffer = true;
} else if (event.target.id == "v4") {
@ -65,21 +68,15 @@ function suspended(event) {
}
}
function logEvent(event) {
dump(event.type + " " + event.target.id + "\n");
}
var key = Math.random();
var eventList = ["metadataloaded", "loadeddata", "playing", "load", "stalled", "suspend", "ended"];
for (var i = 1; i <= expectedLoadEvents; ++i) {
for (var i = 1; i <= 6; ++i) {
var id = "v" + i;
suspends[id] = loads[id] = false;
var v = document.getElementById(id);
suspendCount[id] = 0;
v.addEventListener("suspend", suspended, false);
v.addEventListener("load", loaded, false);
for (var n = 0; n < eventList.length; ++n) {
v.addEventListener(eventList[n], logEvent, false);
}
// Treat "load" as "suspend" for now, it means the same thing: we
// stopped the download.
v.addEventListener("load", suspended, false);
v.src = "seek.ogv?key=" + key + "&id=" + id;
}
SimpleTest.waitForExplicitFinish();

View File

@ -15,7 +15,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=486646
<script class="testbody" type="text/javascript">
function loaded() {
var vid = document.getElementById("vid");
ok(vid.networkState == vid.NETWORK_LOADED, "networkState must be == NETWORK_LOADED");
ok(vid.readyState >= vid.HAVE_CURRENT_DATA, "readyState must be >= HAVE_CURRENT_DATA");
var ctx = document.getElementById("can").getContext("2d");
@ -37,9 +36,9 @@ SimpleTest.waitForExplicitFinish();
<video id="vid"
src="320x240.ogv"
style="display: none;"
autobuffer
autoplay
onerror="event.stopPropagation();"
onload="loaded();">
onended="loaded();">
</video>
<canvas id="can"
width="320"

View File

@ -40,6 +40,6 @@ SimpleTest.waitForExplicitFinish();
</script>
</pre>
<video id='v' src='seek.ogv' oncanplaythrough='canPlayThrough()' onseeking='startSeeking()'
autobuffer onload='start()'></video>
autobuffer onloadedmetadata='start()'></video>
</body>
</html>

View File

@ -31,7 +31,7 @@ is(HTMLElement.MEDIA_ERR_SRC_NOT_SUPPORTED, undefined);
is(HTMLMediaElement.NETWORK_EMPTY, 0);
is(HTMLMediaElement.NETWORK_IDLE, 1);
is(HTMLMediaElement.NETWORK_LOADING, 2);
is(HTMLMediaElement.NETWORK_LOADED, 3);
todo_is(HTMLMediaElement.NETWORK_LOADED, undefined);
is(HTMLMediaElement.NETWORK_NO_SOURCE, 4);
is(HTMLMediaElement.HAVE_NOTHING, 0);
is(HTMLMediaElement.HAVE_METADATA, 1);
@ -45,7 +45,6 @@ is(HTMLMediaElement.MEDIA_ERR_SRC_NOT_SUPPORTED, undefined);
is(HTMLVideoElement.NETWORK_EMPTY, undefined);
is(HTMLVideoElement.NETWORK_IDLE, undefined);
is(HTMLVideoElement.NETWORK_LOADING, undefined);
is(HTMLVideoElement.NETWORK_LOADED, undefined);
is(HTMLVideoElement.NETWORK_NO_SOURCE, undefined);
is(HTMLVideoElement.HAVE_NOTHING, undefined);
is(HTMLVideoElement.HAVE_METADATA, undefined);

View File

@ -67,7 +67,7 @@ function createVideo(id) {
var v = document.createElement("video");
v.id = id;
if (gLog) {
var gEventTypes = [ 'loadstart', 'progress', 'suspend', 'load', 'abort', 'error', 'emptied', 'stalled', 'play', 'pause', 'loadedmetadata', 'loadeddata', 'waiting', 'playing', 'canplay', 'canplaythrough', 'seeking', 'seeked', 'timeupdate', 'ended', 'ratechange', 'durationchange', 'volumechange' ];
var gEventTypes = [ 'loadstart', 'progress', 'suspend', 'abort', 'error', 'emptied', 'stalled', 'play', 'pause', 'loadedmetadata', 'loadeddata', 'waiting', 'playing', 'canplay', 'canplaythrough', 'seeking', 'seeked', 'timeupdate', 'ended', 'ratechange', 'durationchange', 'volumechange' ];
function listener(evt) {
log('event ' + evt.target.id + " " + evt.type);
}

View File

@ -41,7 +41,7 @@ function fileUriToSrc(path, mustExist) {
return f.path;
}
var gEventTypes = [ 'loadstart', 'progress', 'suspend', 'load', 'abort', 'error', 'emptied', 'stalled', 'play', 'pause', 'loadedmetadata', 'loadeddata', 'waiting', 'playing', 'canplay', 'canplaythrough', 'seeking', 'seeked', 'timeupdate', 'ended', 'ratechange', 'durationchange', 'volumechange' ];
var gEventTypes = [ 'loadstart', 'progress', 'suspend', 'abort', 'error', 'emptied', 'stalled', 'play', 'pause', 'loadedmetadata', 'loadeddata', 'waiting', 'playing', 'canplay', 'canplaythrough', 'seeking', 'seeked', 'timeupdate', 'ended', 'ratechange', 'durationchange', 'volumechange' ];
var gMedia = null;

View File

@ -8,7 +8,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=479859
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript" src="use_large_cache.js"></script>
<script type="application/javascript" src="manifest.js"></script>
</head>
<body>
@ -26,7 +25,7 @@ function log(msg) {
// We don't track: progress, canplay, canplaythrough and stalled events,
// as these can be delivered out of order, and/or multiple times.
var gEventTypes = [ 'loadstart', 'load', 'abort', 'error', 'emptied', 'play',
var gEventTypes = [ 'loadstart', 'abort', 'error', 'emptied', 'play',
'pause', 'loadedmetadata', 'loadeddata', 'waiting', 'playing', 'seeking',
'seeked', 'timeupdate', 'ended', 'ratechange', 'durationchange', 'volumechange' ];
@ -81,7 +80,7 @@ var gTests = [
document.body.appendChild(gMedia);
gMedia.src = src;
},
expectedEvents: ['loadstart', 'durationchange', 'loadedmetadata', 'loadeddata', 'load']
expectedEvents: ['loadstart', 'durationchange', 'loadedmetadata', 'loadeddata']
}, {
// Test 1: adding video to doc, then adding source.
create:
@ -89,7 +88,7 @@ var gTests = [
document.body.appendChild(gMedia);
addSource(src, type);
},
expectedEvents: ['loadstart', 'durationchange', 'loadedmetadata', 'loadeddata', 'load']
expectedEvents: ['loadstart', 'durationchange', 'loadedmetadata', 'loadeddata']
}, {
// Test 2: video with multiple source, the first of which are bad, we should load the last.
create:
@ -99,7 +98,7 @@ var gTests = [
addSource("404b", type);
addSource(src, type);
},
expectedEvents: ['loadstart', 'durationchange', 'loadedmetadata', 'loadeddata', 'load']
expectedEvents: ['loadstart', 'durationchange', 'loadedmetadata', 'loadeddata']
}, {
// Test 3: video with bad src, good <source>, ensure that <source> aren't used.
create:
@ -124,7 +123,7 @@ var gTests = [
false);
document.body.appendChild(gMedia);
},
expectedEvents: ['loadstart', 'error', 'durationchange', 'loadedmetadata', 'loadeddata', 'load']
expectedEvents: ['loadstart', 'error', 'durationchange', 'loadedmetadata', 'loadeddata']
}, {
// Test 5: video with only 1 bad source, let it fail to load, then prepend
// a good <source> to the video, it shouldn't be selected, because the

View File

@ -11,8 +11,6 @@
<script src="use_large_cache.js"></script>
<script class="testbody" type="text/javascript">
var completed = false;
var load_count = 0;
var last_progress = false;
var last_progress_total = 0;
function on_loadedmetadata() {
@ -30,24 +28,16 @@ function do_progress(e) {
last_progress_total = e.loaded;
ok(e.loaded <= e.total, "Check progress in bounds: " + e.loaded);
is(e.total, 285310, "Check progress total");
last_progress = e.loaded;
}
function do_ended() {
dump('test_progress1: do_ended\n');
ok(!completed, "Check for duplicate ended event");
completed = true;
is(last_progress, 285310, "Last progress event size");
is(load_count, 1, "load event raised");
SimpleTest.finish();
}
function do_load(e) {
load_count++;
dump('test_progress1: do_loaded ' + e.loaded + "\n");
}
function do_timeupdate() {
var v = document.getElementById('v');
dump('test_progress1: timeupdate: ' + v.currentTime + "\n");
@ -65,7 +55,6 @@ SimpleTest.waitForExplicitFinish();
onloadedmetadata='on_loadedmetadata()'
onended='do_ended()'
ontimeupdate='do_timeupdate()'
onload='do_load(event)'
onplay='do_play()'
onprogress='do_progress(event)'>
</video>

View File

@ -12,7 +12,6 @@
<script class="testbody" type="text/javascript">
// Test progress events with wav backend
var completed = false;
var last_progress = false;
var last_progress_total = 0;
function on_loadedmetadata() {
@ -27,13 +26,11 @@ function do_progress(e) {
last_progress_total = e.loaded;
ok(e.loaded <= e.total, "Check progress in bounds: " + e.loaded);
is(e.total, 102444, "Check progress total");
last_progress = e.loaded;
}
function do_ended() {
ok(!completed, "Check for duplicate ended event");
completed = true;
is(last_progress, 102444, "Last progress event size");
SimpleTest.finish();
}

View File

@ -13,8 +13,6 @@
// Same as test_progress1 but uses a smaller file to test resource loaded
// before metadata loaded is fired.
var completed = false;
var load_count = 0;
var last_progress = false;
var last_progress_total = 0;
function on_loadedmetadata() {
@ -32,23 +30,15 @@ function do_progress(e) {
last_progress_total = e.loaded;
ok(e.loaded <= e.total, "Check progress in bounds: " + e.loaded);
is(e.total, 28942, "Check progress total");
last_progress = e.loaded;
}
function do_ended() {
dump('test_progress3: do_ended\n');
ok(!completed, "Check for duplicate ended event");
completed = true;
is(last_progress, 28942, "Last progress event size");
is(load_count, 1, "load event raised");
SimpleTest.finish();
}
function do_load(e) {
load_count++;
dump('test_progress3: do_loaded ' + e.loaded + "\n");
}
function do_timeupdate() {
var v = document.getElementById('v');
dump('test_progress3: timeupdate: ' + v.currentTime + "\n");
@ -66,7 +56,6 @@ SimpleTest.waitForExplicitFinish();
onloadedmetadata='on_loadedmetadata()'
onended='do_ended()'
ontimeupdate='do_timeupdate()'
onload='do_load(event)'
onplay='do_play()'
onprogress='do_progress(event)'>
</video>

View File

@ -14,7 +14,6 @@
// Same as test_progress2 but uses a smaller file to test resource loaded
// before metadata loaded is fired.
var completed = false;
var last_progress = false;
var last_progress_total = 0;
function on_loadedmetadata() {
@ -29,13 +28,11 @@ function do_progress(e) {
last_progress_total = e.loaded;
ok(e.loaded <= e.total, "Check progress in bounds: " + e.loaded);
is(e.total, 11069, "Check progress total");
last_progress = e.loaded;
}
function do_ended() {
ok(!completed, "Check for duplicate ended event");
completed = true;
is(last_progress, 11069, "Last progress event size");
SimpleTest.finish();
}