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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
<html xmlns="http://www.w3.org/1999/xhtml">
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=515116
-->
<head>
<title>Tests specific to SVGLengthList</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="MutationEventChecker.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=515116">Mozilla Bug 515116</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">
<text id="text" x="10cm 20cm 30mc"/>
<rect id="rect" x="40" y="50"/>
<text id="text2" x="60"/>
</svg>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
<![CDATA[
SimpleTest.waitForExplicitFinish();
/*
This file runs a series of SVGLengthList specific tests. Generic SVGXxxList
tests can be found in test_SVGxxxList.xhtml. Anything that can be generalized
to other list types belongs there.
*/
function run_tests()
{
document.getElementById('svg').pauseAnimations();
var text = document.getElementById("text");
var lengths = text.x.baseVal;
is(lengths.numberOfItems, 0, 'Checking numberOfItems');
// Test mutation events
// --- Initialization
eventChecker = new MutationEventChecker;
eventChecker.watchAttr(text, "x");
eventChecker.expect("modify");
text.textContent = "abc";
text.setAttribute("x", "10 20 30");
is(lengths.numberOfItems, 3, 'Checking numberOfItems');
// -- Actual changes
eventChecker.expect("modify modify modify modify modify");
lengths[0].value = 8;
lengths[0].valueInSpecifiedUnits = 9;
lengths[0].valueAsString = "10";
lengths[0].convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_CM);
lengths[0].newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_MM, 11);
// -- Redundant changes
eventChecker.expect("modify");
lengths[0].valueAsString = "10";
eventChecker.expect("");
lengths[0].value = 10;
lengths[0].valueInSpecifiedUnits = 10;
lengths[0].valueAsString = "10";
lengths[0].convertToSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_NUMBER);
lengths[0].newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_NUMBER, 10);
// -- Invalid attribute
eventChecker.expect("modify");
text.setAttribute("x", ",20");
is(lengths.numberOfItems, 0, 'Checking that parsing stops at invalid token');
// -- Attribute removal
eventChecker.expect("remove");
text.removeAttribute("x");
// -- Non-existent attribute removal
eventChecker.expect("");
text.removeAttribute("x");
text.removeAttributeNS(null, "x");
eventChecker.finish();
// Test that the addition of an owned SVGLength to an SVGLengthList creates a
// copy of the SVGLength, and an unowned SVGLength does not make a copy
var text2 = document.getElementById("text2");
var rect = document.getElementById("rect");
var subtests = [
function initialize(aItem) {
text.removeAttribute("x");
return lengths.initialize(aItem);
},
function insertItemBefore(aItem) {
text.removeAttribute("x");
return lengths.insertItemBefore(aItem, 0);
},
function replaceItem(aItem) {
text.setAttribute("x", "10");
return lengths.replaceItem(aItem, 0);
},
function appendItem(aItem) {
text.removeAttribute("x");
return lengths.appendItem(aItem);
}
];
subtests.forEach(function(aFunction) {
// -- Adding an unowned SVGLength
var name = aFunction.name;
var existingItem = document.getElementById("svg").createSVGLength();
var newItem = aFunction(existingItem);
is(newItem, lengths.getItem(0), name + " return value is correct when passed an unowned object");
is(newItem, existingItem, name + " did not make a copy when passed an unowned object");
});
subtests.forEach(function(aFunction) {
// -- Adding an SVGLength that is a baseVal
var name = aFunction.name;
var existingItem = rect.x.baseVal;
var newItem = aFunction(existingItem);
is(newItem, lengths.getItem(0), name + " return value is correct when passed a baseVal");
isnot(newItem, existingItem, name + " made a copy when passed a baseVal");
is(newItem.value, existingItem.value, name + " made a copy with the right values when passed a baseVal");
is(rect.x.baseVal, existingItem, name + " left the original object alone when passed a baseVal");
});
subtests.forEach(function(aFunction) {
// -- Adding an SVGLength that is an animVal
var name = aFunction.name;
var existingItem = rect.x.animVal;
var newItem = aFunction(existingItem);
is(newItem, lengths.getItem(0), name + " return value is correct when passed an animVal");
isnot(newItem, existingItem, name + " made a copy when passed an animVal");
is(newItem.value, existingItem.value, name + " made a copy with the right values when passed an animVal");
is(rect.x.animVal, existingItem, name + " left the original object alone when passed an animVal");
});
subtests.forEach(function(aFunction) {
// -- Adding an SVGLength that is in a baseVal list
var name = aFunction.name;
var existingItem = text2.x.baseVal.getItem(0);
var newItem = aFunction(existingItem);
is(newItem, lengths.getItem(0), name + " return value is correct when passed a baseVal list item");
isnot(newItem, existingItem, name + " made a copy when passed a baseVal list item");
is(newItem.value, existingItem.value, name + " made a copy with the right values when passed a baseVal list item");
is(text2.x.baseVal.getItem(0), existingItem, name + " left the original object alone when passed a baseVal list item");
});
subtests.forEach(function(aFunction) {
// -- Adding an SVGLength that is in a animVal list
var name = aFunction.name;
var existingItem = text2.x.animVal.getItem(0);
var newItem = aFunction(existingItem);
is(newItem, lengths.getItem(0), name + " return value is correct when passed a animVal list item");
isnot(newItem, existingItem, name + " made a copy when passed a animVal list item");
is(newItem.value, existingItem.value, name + " made a copy with the right values when passed a animVal list item");
is(text2.x.animVal.getItem(0), existingItem, name + " left the original object alone when passed a animVal list item");
});
SimpleTest.finish();
}
window.addEventListener("load", run_tests, false);
]]>
</script>
</pre>
</body>
</html>
|