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.
michael@0 | 1 | /** Test for Bug 357450 **/ |
michael@0 | 2 | |
michael@0 | 3 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 4 | |
michael@0 | 5 | function testGetElements (root, classtestCount) { |
michael@0 | 6 | |
michael@0 | 7 | ok(root.getElementsByClassName, "getElementsByClassName exists"); |
michael@0 | 8 | is(typeof(root.getElementsByClassName), "function", "getElementsByClassName is a function"); |
michael@0 | 9 | |
michael@0 | 10 | var nodes = root.getElementsByClassName("f"); |
michael@0 | 11 | |
michael@0 | 12 | is(typeof(nodes.item), "function"); |
michael@0 | 13 | is(typeof(nodes.length), "number"); |
michael@0 | 14 | is(nodes.length, 0, "string with no matching class should get an empty list"); |
michael@0 | 15 | |
michael@0 | 16 | nodes = root.getElementsByClassName("foo"); |
michael@0 | 17 | ok(nodes, "should have nodelist object"); |
michael@0 | 18 | |
michael@0 | 19 | // HTML5 says ints are allowed in class names |
michael@0 | 20 | // should match int class |
michael@0 | 21 | |
michael@0 | 22 | nodes = root.getElementsByClassName("1"); |
michael@0 | 23 | is(nodes[0], $('int-class'), "match integer class name"); |
michael@0 | 24 | nodes = root.getElementsByClassName([1]); |
michael@0 | 25 | is(nodes[0], $('int-class'), "match integer class name 2"); |
michael@0 | 26 | nodes = root.getElementsByClassName(["1 junk"]); |
michael@0 | 27 | |
michael@0 | 28 | is(nodes.length, 0, "two classes, but no elements have both"); |
michael@0 | 29 | |
michael@0 | 30 | nodes = root.getElementsByClassName("test1"); |
michael@0 | 31 | is(nodes[0], $('test1'), "Id and class name turn up the same node"); |
michael@0 | 32 | nodes = root.getElementsByClassName("test1 test2"); |
michael@0 | 33 | is(nodes.length, 0, "two classes, but no elements have both"); |
michael@0 | 34 | |
michael@0 | 35 | // WHATWG examples |
michael@0 | 36 | nodes = document.getElementById('example').getElementsByClassName('aaa'); |
michael@0 | 37 | is(nodes.length, 2, "returns 2 elements"); |
michael@0 | 38 | |
michael@0 | 39 | nodes = document.getElementById('example').getElementsByClassName('ccc bbb') |
michael@0 | 40 | is(nodes.length, 1, "only match elements that have all the classes specified in that array. tokenize string arg.") |
michael@0 | 41 | is(nodes[0], $('p3'), "matched tokenized string"); |
michael@0 | 42 | |
michael@0 | 43 | nodes = document.getElementById('example').getElementsByClassName(''); |
michael@0 | 44 | is(nodes.length, 0, "class name with empty string shouldn't return nodes"); |
michael@0 | 45 | |
michael@0 | 46 | nodes = root.getElementsByClassName({}); |
michael@0 | 47 | ok(nodes, "bogus arg shouldn't be null"); |
michael@0 | 48 | is(typeof(nodes.item), "function"); |
michael@0 | 49 | is(typeof(nodes.length), "number"); |
michael@0 | 50 | is(nodes.length, 0, "bogus arg should get an empty nodelist"); |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | addLoadEvent(function() { |
michael@0 | 54 | if (document.getElementsByName) { |
michael@0 | 55 | var anchorNodes = document.getElementsByName("nametest"); |
michael@0 | 56 | is(anchorNodes.length, 1, "getElementsByName still works"); |
michael@0 | 57 | is(anchorNodes[0].getAttribute("name"), "nametest", |
michael@0 | 58 | "getElementsByName still works"); |
michael@0 | 59 | } |
michael@0 | 60 | testGetElements($("content"), 1); |
michael@0 | 61 | testGetElements(document.documentElement, 3); |
michael@0 | 62 | testGetElements(document, 3); |
michael@0 | 63 | }); |
michael@0 | 64 | addLoadEvent(SimpleTest.finish); |