blob: c3d0bed3d4865b29fd14d2cf894a00efe82e10b6 (
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
|
<body>
<pre id="error-log"></pre>
<span id="container" style="color: green">
</span>
<div style="display: none">
<span id="1">
1 (black)
</span>
<span id="2">
2 (green)
</span>
<span id="3">
3 (green)
</span>
<span id="4">
4 (black)
</span>
</div>
<span id="status" style="color: red">
FAILURE
</span>
</body>
<script>
if (window.testRunner)
testRunner.dumpAsText();
// verify all standard cases
document.getElementById("container").insertAdjacentElement("beforeBegin", document.getElementById("1"));
document.getElementById("container").insertAdjacentElement("afterBegin", document.getElementById("2"));
document.getElementById("container").insertAdjacentElement("beforeEnd", document.getElementById("3"));
document.getElementById("container").insertAdjacentElement("afterEnd", document.getElementById("4"));
function assertThrows(func) {
var testPassed = false;
try {
func();
document.getElementById("error-log").textContent += "Expected exception missing.\n";
} catch (e) {
document.getElementById("error-log").textContent += "Caught expected exception: " + e + "\n";
testPassed = true;
}
return testPassed;
}
// check that exceptions are thrown as required
var passes = true;
passes = assertThrows(function() {
// should throw SyntaxError
document.getElementById("container").insertAdjacentElement("blah", document.getElementById("1"));
}) && passes;
passes = assertThrows(function() {
// should throw TypeError
document.getElementById("container").insertAdjacentElement("beforeEnd", null);
}) && passes;
passes = assertThrows(function() {
// should throw TypeError
document.getElementById("container").insertAdjacentElement("beforeEnd");
}) && passes;
passes = assertThrows(function() {
// should throw TypeError
document.getElementById("container").insertAdjacentElement();
}) && passes;
var elt = document.createElement("div");
passes = passes && (elt.insertAdjacentElement("beforeBegin", document.createElement("p")) == null);
if (passes) {
document.getElementById("status").style.color = "green";
document.getElementById("status").innerHTML = "<br><br>PASS";
}
</script>
|