-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdom_feature_test.html
114 lines (85 loc) · 4.16 KB
/
dom_feature_test.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>DOM Feature Test</title>
<link rel="stylesheet" href="/css/site.css" type="text/css" />
<link rel="stylesheet" href="/css/jasmine.css" type="text/css" />
<script type="text/javascript" src="/js/jasmine.js"></script>
<script type="text/javascript" src="/js/jasmine-html.js"></script>
<script type="text/javascript" src="/js/jasmine.junit_reporter.js"></script>
</head>
<body>
<div id="root">
<span class="foo">Foo</span>
<span class="foo">Bar</span>
<span class="foo">Baz</span>
</div>
<script type="text/javascript">
var reporter = new jasmine.JUnitReporter();
describe("DOM Element Selection", function() {
it("Should support getElementsByClassName", function() {
var elements = [];
try {
elements = document.getElementsByClassName('foo');
} catch (e) {
fail("Expected getElementsByClassName to be supported.");
}
expect(elements.length).toEqual(3);
});
});
describe("SVG", function() {
var ns = 'http://www.w3.org/2000/svg';
it("Should support the SVG namespace.", function() {
var svg = document.createElementNS(ns, 'svg');
expect(svg.nodeName.toLowerCase()).toEqual("svg");
});
it("Should create append an SVG element to the document.", function() {
var svg = document.createElementNS(ns, 'svg');
svg.setAttribute("width", "50px");
svg.setAttribute("height", "50px");
document.body.appendChild(svg);
var elts = document.getElementsByTagName('svg');
expect(elts.length).toEqual(1);
expect(elts[0]).toEqual(svg);
svg.parentNode.removeChild(svg);
});
it("Should create an ellipse and add it to the document.", function() {
var svg = document.createElementNS(ns, 'svg');
svg.setAttribute("width", "50px");
svg.setAttribute("height", "50px");
var ellipse = document.createElementNS(ns, 'ellipse');
ellipse.setAttribute("cx", "25");
ellipse.setAttribute("cy", "25");
ellipse.setAttribute("rx", "20");
ellipse.setAttribute("ry", "15");
ellipse.setAttribute("fill", "#000000");
svg.appendChild(ellipse);
document.body.appendChild(svg);
var elts = document.getElementsByTagName('ellipse');
expect(elts.length).toEqual(1);
expect(elts[0]).toEqual(ellipse);
expect(elts[0].parentNode).toEqual(svg);
svg.parentNode.removeChild(svg);
});
});
describe('UIEvent', function() {
it('Should support the creation and dispatch of mouse events.', function() {
var triggered = false;
var elt = document.getElementById('root');
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
elt.addEventListener('click', function(evt) {
expect(evt.type).toEqual('click');
triggered = true;
}, false);
elt.dispatchEvent(evt);
expect(triggered).toEqual(true);
});
});
jasmine.getEnv().addReporter(reporter);
jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
jasmine.getEnv().execute();
</script>
</body>
</html>