Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /** Test for Bug 357450 **/
3 SimpleTest.waitForExplicitFinish();
5 function testGetElements (root, classtestCount) {
7 ok(root.getElementsByClassName, "getElementsByClassName exists");
8 is(typeof(root.getElementsByClassName), "function", "getElementsByClassName is a function");
10 var nodes = root.getElementsByClassName("f");
12 is(typeof(nodes.item), "function");
13 is(typeof(nodes.length), "number");
14 is(nodes.length, 0, "string with no matching class should get an empty list");
16 nodes = root.getElementsByClassName("foo");
17 ok(nodes, "should have nodelist object");
19 // HTML5 says ints are allowed in class names
20 // should match int class
22 nodes = root.getElementsByClassName("1");
23 is(nodes[0], $('int-class'), "match integer class name");
24 nodes = root.getElementsByClassName([1]);
25 is(nodes[0], $('int-class'), "match integer class name 2");
26 nodes = root.getElementsByClassName(["1 junk"]);
28 is(nodes.length, 0, "two classes, but no elements have both");
30 nodes = root.getElementsByClassName("test1");
31 is(nodes[0], $('test1'), "Id and class name turn up the same node");
32 nodes = root.getElementsByClassName("test1 test2");
33 is(nodes.length, 0, "two classes, but no elements have both");
35 // WHATWG examples
36 nodes = document.getElementById('example').getElementsByClassName('aaa');
37 is(nodes.length, 2, "returns 2 elements");
39 nodes = document.getElementById('example').getElementsByClassName('ccc bbb')
40 is(nodes.length, 1, "only match elements that have all the classes specified in that array. tokenize string arg.")
41 is(nodes[0], $('p3'), "matched tokenized string");
43 nodes = document.getElementById('example').getElementsByClassName('');
44 is(nodes.length, 0, "class name with empty string shouldn't return nodes");
46 nodes = root.getElementsByClassName({});
47 ok(nodes, "bogus arg shouldn't be null");
48 is(typeof(nodes.item), "function");
49 is(typeof(nodes.length), "number");
50 is(nodes.length, 0, "bogus arg should get an empty nodelist");
51 }
53 addLoadEvent(function() {
54 if (document.getElementsByName) {
55 var anchorNodes = document.getElementsByName("nametest");
56 is(anchorNodes.length, 1, "getElementsByName still works");
57 is(anchorNodes[0].getAttribute("name"), "nametest",
58 "getElementsByName still works");
59 }
60 testGetElements($("content"), 1);
61 testGetElements(document.documentElement, 3);
62 testGetElements(document, 3);
63 });
64 addLoadEvent(SimpleTest.finish);