1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/test/test_bug357450.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,64 @@ 1.4 +/** Test for Bug 357450 **/ 1.5 + 1.6 +SimpleTest.waitForExplicitFinish(); 1.7 + 1.8 +function testGetElements (root, classtestCount) { 1.9 + 1.10 + ok(root.getElementsByClassName, "getElementsByClassName exists"); 1.11 + is(typeof(root.getElementsByClassName), "function", "getElementsByClassName is a function"); 1.12 + 1.13 + var nodes = root.getElementsByClassName("f"); 1.14 + 1.15 + is(typeof(nodes.item), "function"); 1.16 + is(typeof(nodes.length), "number"); 1.17 + is(nodes.length, 0, "string with no matching class should get an empty list"); 1.18 + 1.19 + nodes = root.getElementsByClassName("foo"); 1.20 + ok(nodes, "should have nodelist object"); 1.21 + 1.22 + // HTML5 says ints are allowed in class names 1.23 + // should match int class 1.24 + 1.25 + nodes = root.getElementsByClassName("1"); 1.26 + is(nodes[0], $('int-class'), "match integer class name"); 1.27 + nodes = root.getElementsByClassName([1]); 1.28 + is(nodes[0], $('int-class'), "match integer class name 2"); 1.29 + nodes = root.getElementsByClassName(["1 junk"]); 1.30 + 1.31 + is(nodes.length, 0, "two classes, but no elements have both"); 1.32 + 1.33 + nodes = root.getElementsByClassName("test1"); 1.34 + is(nodes[0], $('test1'), "Id and class name turn up the same node"); 1.35 + nodes = root.getElementsByClassName("test1 test2"); 1.36 + is(nodes.length, 0, "two classes, but no elements have both"); 1.37 + 1.38 + // WHATWG examples 1.39 + nodes = document.getElementById('example').getElementsByClassName('aaa'); 1.40 + is(nodes.length, 2, "returns 2 elements"); 1.41 + 1.42 + nodes = document.getElementById('example').getElementsByClassName('ccc bbb') 1.43 + is(nodes.length, 1, "only match elements that have all the classes specified in that array. tokenize string arg.") 1.44 + is(nodes[0], $('p3'), "matched tokenized string"); 1.45 + 1.46 + nodes = document.getElementById('example').getElementsByClassName(''); 1.47 + is(nodes.length, 0, "class name with empty string shouldn't return nodes"); 1.48 + 1.49 + nodes = root.getElementsByClassName({}); 1.50 + ok(nodes, "bogus arg shouldn't be null"); 1.51 + is(typeof(nodes.item), "function"); 1.52 + is(typeof(nodes.length), "number"); 1.53 + is(nodes.length, 0, "bogus arg should get an empty nodelist"); 1.54 +} 1.55 + 1.56 +addLoadEvent(function() { 1.57 + if (document.getElementsByName) { 1.58 + var anchorNodes = document.getElementsByName("nametest"); 1.59 + is(anchorNodes.length, 1, "getElementsByName still works"); 1.60 + is(anchorNodes[0].getAttribute("name"), "nametest", 1.61 + "getElementsByName still works"); 1.62 + } 1.63 + testGetElements($("content"), 1); 1.64 + testGetElements(document.documentElement, 3); 1.65 + testGetElements(document, 3); 1.66 +}); 1.67 +addLoadEvent(SimpleTest.finish);