Navigation Menu

Skip to content

Commit

Permalink
add tests for getElementsByTagName, and remove bogus global assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
client9 committed Apr 2, 2010
1 parent 4235826 commit 3b08f4e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/dom/node.js
Expand Up @@ -471,8 +471,10 @@ __extend__(Node.prototype, {
// delegate to _getElementsByTagNameRecursive
// recurse childNodes
var nodelist = new NodeList(__ownerDocument__(this));
for(var i = 0; i < this.childNodes.length; i++) {
nodeList = __getElementsByTagNameRecursive__(this.childNodes.item(i), tagname, nodelist);
for (var i = 0; i < this.childNodes.length; i++) {
__getElementsByTagNameRecursive__(this.childNodes.item(i),
tagname,
nodelist);
}
return nodelist;
},
Expand Down
17 changes: 17 additions & 0 deletions test/specs/dom/spec.js
Expand Up @@ -664,6 +664,7 @@ test('compareDocumentPosition', function(){
var domparser = new DOMParser();

module('DOMParser');

test('parseFromString', function(){

var root,
Expand Down Expand Up @@ -707,6 +708,7 @@ test('parseFromString', function(){
'<farm sound="oink"><pig/><cow/><horse/></farm>', 'text/xml');
root = doc.documentElement;
equals(root.nodeName, 'farm', 'root.nodeName');
ok(root.hasAttribute('sound'), 'hasAttribute');
equals(xmlserializer.serializeToString(root),
'<farm sound="oink"><pig/><cow/><horse/></farm>', 'serializeToString');

Expand Down Expand Up @@ -820,3 +822,18 @@ test('parseFromString', function(){
</farm>', 'serializeToString');

});

test('getElementsByTagName', function() {
var nodes, doc;
doc = domparser.parseFromString(
'<root><div><div>123</div></div><div></div></root>'
);

nodes = doc.getElementsByTagName('*');
equals(nodes.length, 4, 'all elements');
nodes = doc.getElementsByTagName('root');
equals(nodes.length, 1, 'non-recursive');
nodes = doc.getElementsByTagName('div');
equals(nodes.length, 3, 'recursive');
});

0 comments on commit 3b08f4e

Please sign in to comment.