summaryrefslogtreecommitdiffstats
path: root/dom/svg/test/test_SVGStringList.xhtml
blob: faba904376f811b56a3f77773b4f3d33dd7c326e (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
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
<html xmlns="http://www.w3.org/1999/xhtml">
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=724993-->
<head>
  <title>Tests specific to SVGStringList</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=724993">Mozilla Bug 724993</a>
<p id="display"></p>
<div id="content" style="display:none;">
<svg id="svg" xmlns="http://www.w3.org/2000/svg" width="100" height="100">
  <g id="g" requiredExtensions="foo bar baz"/>
</svg>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
<![CDATA[

SimpleTest.waitForExplicitFinish();

/*
This file runs a series of SVGStringList specific tests. Generic SVGXxxList
tests can be found in test_SVGxxxList.xhtml. Anything that can be generalized
to other list types belongs there.
*/

function initializeThrowsFor(stringList, value) {
  try {
    stringList.initialize(value);
  } catch (e) {
    return true;
  }
  return false;
}

function insertItemBeforeThrowsFor(stringList, value) {
  try {
    stringList.insertItemBefore(value, 0);
  } catch (e) {
    return true;
  }
  return false;
}

function replaceItemThrowsFor(stringList, value) {
  try {
    stringList.replaceItem(value, 0);
  } catch (e) {
    return true;
  }
  return false;
}

function appendItemThrowsFor(stringList, value) {
  try {
    stringList.appendItem(value);
  } catch (e) {
    return true;
  }
  return false;
}

function run_tests() {
  var g = document.getElementById("g");
  var strings = g.requiredExtensions;

  // sanity check:
  is(strings.numberOfItems, 3, "numberOfItems should be 3");


  ok(!initializeThrowsFor(strings, null),
     "SVGStringList.initialize() should not throw when passed null");
  ok(initializeThrowsFor(strings, ""),
     "SVGStringList.initialize() should throw when passed the empty string");
  is(strings.length, 0, "length should be 0");

  ok(!insertItemBeforeThrowsFor(strings, null),
     "SVGStringList.insertItemBefore() should not throw when passed null");
  ok(insertItemBeforeThrowsFor(strings, ""),
     "SVGStringList.insertItemBefore() should throw when passed the empty string");
  is(strings.length, 1, "length should be 1");

  ok(!replaceItemThrowsFor(strings, null),
     "SVGStringList.replaceItem() should not throw when passed null");
  ok(replaceItemThrowsFor(strings, ""),
     "SVGStringList.replaceItem() should throw when passed the empty string");
  is(strings.length, 1, "length should be 1");

  ok(!appendItemThrowsFor(strings, null),
     "SVGStringList.appendItem() should not throw when passed null");
  ok(appendItemThrowsFor(strings, ""),
     "SVGStringList.appendItem() should throw when passed the empty string");
  is(strings.length, 2, "length should be 2");


  // more sanity checks:
  ok(!initializeThrowsFor(strings, "valid-string"),
     "SVGStringList.initialize() should not throw when passed a valid string");
  ok(!insertItemBeforeThrowsFor(strings, "valid-string"),
     "SVGStringList.insertItemBefore() should not throw when passed a valid string");
  ok(!replaceItemThrowsFor(strings, "valid-string"),
     "SVGStringList.replaceItem() should not throw when passed a valid string");
  ok(!appendItemThrowsFor(strings, "valid-string"),
     "SVGStringList.appendItem() should not throw when passed a valid string");
  is(strings.length, 3, "numberOfItems should be 3");

  SimpleTest.finish();
}

window.addEventListener("load", run_tests);

]]>
</script>
</pre>
</body>
</html>