summaryrefslogtreecommitdiffstats
path: root/dom/svg/test/test_SVGPathSegList.xhtml
blob: 5b442676a12dd0b3defcce5b26403fd9ef71c698 (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
119
120
121
122
123
124
125
126
127
128
<html xmlns="http://www.w3.org/1999/xhtml">
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=611138
-->
<head>
  <title>Generic tests for SVG animated length lists</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=611138">Mozilla Bug 611138</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">
  <path id="path"/>
</svg>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
<![CDATA[

SimpleTest.waitForExplicitFinish();

/*
This file runs a series of SVGPathSegList 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 d;
  var seg;
  var path = document.getElementById("path");
  var list = path.pathSegList;

  // See https://bugzilla.mozilla.org/show_bug.cgi?id=611138
  // Here we are doing a replace with a segment (arc) that has more arguments
  // than the total number of arguments in the entire path + 2 (the +2
  // refering to the encoding of the segment types for the two segments).
  path.setAttribute('d', 'M0,0 L100,100');
  var arc = path.createSVGPathSegArcAbs(400, 0, 200, 200, 0, 1, 1);
  list.replaceItem(arc, 1);

  is(list.numberOfItems, 2, 'The length of the list should be the same after a valid replaceItem() call');
  is(list.getItem(1), arc, 'The inserted object should now be the object at the index being replaced');

  // Test whether and when we normalize the 'd' attribute:

  d = "  \n  M  10  ,  10  \n  L  20  10  \n  ";
  path.setAttribute('d', d);
  is(path.getAttribute('d'), d, "Values passed to setAttribute for the 'd' attribute should not be normalised");
  list.getItem(1).y = 20;
  isnot(path.getAttribute('d'), d, "The 'd' attribute should change when its underlying DOM list changes");

  // Test that path manipulations still work even when the path is invalid due
  // to it not starting with a moveto segment:

  path.setAttribute('d', 'M0,0 L1,1');
  is(list.numberOfItems, 2, 'setAttribute should result in two items')

  seg = list.getItem(1);
  list.removeItem(0);
  ok(list.numberOfItems == 1 && list.getItem(0) == seg,
    'If removeItem removes the initial moveto leaving an invalid path, the other items should still be left in the list')

  seg = path.createSVGPathSegLinetoAbs(1, 2);
  list.appendItem(seg);
  ok(list.numberOfItems == 2 && list.getItem(1) == seg,
    'appendItem should be able to append to an invalid path');

  seg = path.createSVGPathSegLinetoAbs(1, 2);
  list.replaceItem(seg, 1);
  ok(list.numberOfItems == 2 && list.getItem(1) == seg,
    'replaceItem should be able to replace items in an invalid path');

  seg = path.createSVGPathSegLinetoAbs(1, 2);
  list.insertItemBefore(seg, 1);
  ok(list.numberOfItems == 3 && list.getItem(1) == seg,
    'insertItemBefore should be able insert items into an invalid path');

  seg = path.createSVGPathSegLinetoAbs(1, 2);
  list.initialize(seg);
  ok(list.numberOfItems == 1 && list.getItem(0) == seg,
    'initialize should be able initialize an invalid path with a non-moveto item');

  // Test mutation events

  eventChecker = new MutationEventChecker;
  d = 'M0,0 L12,34'
  path.setAttribute('d', d);
  eventChecker.watchAttr(path, "d");

  // -- Actual changes
  eventChecker.expect("modify modify modify");
  list[0].x = 10;
  list[0].y = 5;
  path.setAttribute("d", "M20,5 L12,34");

  // -- Redundant changes
  eventChecker.expect("");
  list[0].x = 20;
  list[1].y = 34;
  path.setAttribute("d", "M20,5 L12,34");

  // -- Attribute removal
  eventChecker.expect("remove");
  path.removeAttribute("d");

  // -- Non-existent attribute removal
  eventChecker.expect("");
  path.removeAttribute("d");
  path.removeAttributeNS(null, "d");
  eventChecker.finish();

  SimpleTest.finish();
}

window.addEventListener("load", run_tests, false);

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