1 <html xmlns=
"http://www.w3.org/1999/xhtml">
3 https://bugzilla.mozilla.org/show_bug.cgi?id=515116
6 <title>Tests specific to SVGLengthList
</title>
7 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
8 <script type=
"text/javascript" src=
"MutationEventChecker.js"></script>
9 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css" />
12 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=515116">Mozilla Bug
515116</a>
14 <div id=
"content" style=
"display:none;">
15 <svg id=
"svg" xmlns=
"http://www.w3.org/2000/svg" width=
"100" height=
"100">
16 <text id=
"text" x=
"10cm 20cm 30mc"/>
17 <rect id=
"rect" x=
"40" y=
"50"/>
18 <text id=
"text2" x=
"60"/>
22 <script class=
"testbody" type=
"text/javascript">
25 SimpleTest.waitForExplicitFinish();
28 This file runs a series of SVGLengthList specific tests. Generic SVGXxxList
29 tests can be found in test_SVGxxxList.xhtml. Anything that can be generalized
30 to other list types belongs there.
33 function run_tests() {
34 document.getElementById(
"svg").pauseAnimations();
36 var text = document.getElementById(
"text");
37 var lengths = text.x.baseVal;
39 is(lengths.numberOfItems,
0,
"Checking numberOfItems");
41 // Test mutation events
43 var eventChecker = new MutationEventChecker;
44 eventChecker.watchAttr(text,
"x");
45 eventChecker.expect(
"modify");
46 text.textContent =
"abc";
47 text.setAttribute(
"x",
"10 20 30");
48 is(lengths.numberOfItems,
3,
"Checking numberOfItems");
50 eventChecker.expect(
"modify modify modify modify modify");
52 lengths[
0].valueInSpecifiedUnits =
9;
53 lengths[
0].valueAsString =
"10";
54 lengths[
0].convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_CM);
55 lengths[
0].newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_MM,
11);
56 // -- Redundant changes
57 eventChecker.expect(
"modify");
58 lengths[
0].valueAsString =
"10";
59 eventChecker.expect(
"");
60 lengths[
0].value =
10;
61 lengths[
0].valueInSpecifiedUnits =
10;
62 lengths[
0].valueAsString =
"10";
63 lengths[
0].convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_NUMBER);
64 lengths[
0].newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_NUMBER,
10);
65 // -- Invalid attribute
66 eventChecker.expect(
"modify");
67 text.setAttribute(
"x",
",20");
68 is(lengths.numberOfItems,
0,
"Checking that parsing stops at invalid token");
69 // -- Attribute removal
70 eventChecker.expect(
"remove");
71 text.removeAttribute(
"x");
72 // -- Non-existent attribute removal
73 eventChecker.expect(
"");
74 text.removeAttribute(
"x");
75 text.removeAttributeNS(null,
"x");
76 eventChecker.finish();
78 // Test that the addition of an owned SVGLength to an SVGLengthList creates a
79 // copy of the SVGLength, and an unowned SVGLength does not make a copy
80 var text2 = document.getElementById(
"text2");
81 var rect = document.getElementById(
"rect");
83 function initialize(aItem) {
84 text.removeAttribute(
"x");
85 return lengths.initialize(aItem);
87 function insertItemBefore(aItem) {
88 text.removeAttribute(
"x");
89 return lengths.insertItemBefore(aItem,
0);
91 function replaceItem(aItem) {
92 text.setAttribute(
"x",
"10");
93 return lengths.replaceItem(aItem,
0);
95 function appendItem(aItem) {
96 text.removeAttribute(
"x");
97 return lengths.appendItem(aItem);
100 subtests.forEach(function(aFunction) {
101 // -- Adding an unowned SVGLength
102 var name = aFunction.name;
103 var existingItem = document.getElementById(
"svg").createSVGLength();
104 var newItem = aFunction(existingItem);
105 is(newItem, lengths.getItem(
0), name +
" return value is correct when passed an unowned object");
106 is(newItem, existingItem, name +
" did not make a copy when passed an unowned object");
108 subtests.forEach(function(aFunction) {
109 // -- Adding an SVGLength that is a baseVal
110 var name = aFunction.name;
111 var existingItem = rect.x.baseVal;
112 var newItem = aFunction(existingItem);
113 is(newItem, lengths.getItem(
0), name +
" return value is correct when passed a baseVal");
114 isnot(newItem, existingItem, name +
" made a copy when passed a baseVal");
115 is(newItem.value, existingItem.value, name +
" made a copy with the right values when passed a baseVal");
116 is(rect.x.baseVal, existingItem, name +
" left the original object alone when passed a baseVal");
118 subtests.forEach(function(aFunction) {
119 // -- Adding an SVGLength that is an animVal
120 var name = aFunction.name;
121 var existingItem = rect.x.animVal;
122 var newItem = aFunction(existingItem);
123 is(newItem, lengths.getItem(
0), name +
" return value is correct when passed an animVal");
124 isnot(newItem, existingItem, name +
" made a copy when passed an animVal");
125 is(newItem.value, existingItem.value, name +
" made a copy with the right values when passed an animVal");
126 is(rect.x.animVal, existingItem, name +
" left the original object alone when passed an animVal");
128 subtests.forEach(function(aFunction) {
129 // -- Adding an SVGLength that is in a baseVal list
130 var name = aFunction.name;
131 var existingItem = text2.x.baseVal.getItem(
0);
132 var newItem = aFunction(existingItem);
133 is(newItem, lengths.getItem(
0), name +
" return value is correct when passed a baseVal list item");
134 isnot(newItem, existingItem, name +
" made a copy when passed a baseVal list item");
135 is(newItem.value, existingItem.value, name +
" made a copy with the right values when passed a baseVal list item");
136 is(text2.x.baseVal.getItem(
0), existingItem, name +
" left the original object alone when passed a baseVal list item");
138 subtests.forEach(function(aFunction) {
139 // -- Adding an SVGLength that is in a animVal list
140 var name = aFunction.name;
141 var existingItem = text2.x.animVal.getItem(
0);
142 var newItem = aFunction(existingItem);
143 is(newItem, lengths.getItem(
0), name +
" return value is correct when passed a animVal list item");
144 isnot(newItem, existingItem, name +
" made a copy when passed a animVal list item");
145 is(newItem.value, existingItem.value, name +
" made a copy with the right values when passed a animVal list item");
146 is(text2.x.animVal.getItem(
0), existingItem, name +
" left the original object alone when passed a animVal list item");
152 window.addEventListener(
"load",
153 () =
> SpecialPowers.pushPrefEnv({
"set": [[
"dom.mutation_events.enabled", true]]}, run_tests));