summaryrefslogtreecommitdiffstats
path: root/dom/media/test/test_error_on_404.html
blob: 8f82b8a07e6252d0442ee0b1c62da6765c29ea80 (plain)
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
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=476731
-->
<head>
  <title>Test for Bug 476731</title>
  <script 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=476731">Mozilla Bug </a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 476731 **/

var videos = [];

function FinishedLoads() {
  if (!videos.length)
    return false;
  for (var i=0; i<videos.length; ++i) {
    if (videos[i]._loadedData) {
      // A video loadeddata, it should have 404'd. Signal the end of the test
      // so the error will be reported.
      return true;
    }
    if (!videos[i]._loadError) {
      return false;
    }
  }
  return true;
}

function loadError(evt) {
  var v = evt.target;
  is(v._loadError, false, "Shouldn't receive multiple error events for " + v.src);
  v._loadError = true;
  is(v._loadStart, true, "Receive loadstart for " + v.src);
  is(v._loadedData, false, "Shouldn't receive loadeddata for " + v.src);
  if (FinishedLoads(videos))
    SimpleTest.finish();
}

function loadedData(evt) {
  evt.target._loadedData = true;
}

function loadStart(evt) {
  evt.target._loadStart = true;
}

// Create all video objects.
for (var i=0; i<g404Tests.length; ++i) {
  var v = document.createElement("video");
  v.preload = "metadata";
  var test = g404Tests[i];
  if (!v.canPlayType(test.type)) {
    continue;
   }
   v.src = test.name;
   v._loadedData = false;
   v._loadStart = false;
   v._loadError = false;
   v.addEventListener("error", loadError);
   v.addEventListener("loadstart", loadStart);
   v.addEventListener("loadeddata", loadedData);
   document.body.appendChild(v); // Will start load.
   videos.push(v);
}

if (!videos.length) {
  todo(false, "No types supported");
} else {
  SimpleTest.waitForExplicitFinish();
}
</script>
</pre>
</body>
</html>