Bug 883599 - Fix the inspector actor's nextSibling and previousSibling requests. r=paul

This commit is contained in:
Dave Camp 2013-06-10 21:18:18 -07:00
parent 2f9475a47e
commit f75b6dc79c
2 changed files with 31 additions and 4 deletions

View File

@ -567,7 +567,7 @@ let traversalMethod = {
whatToShow: Option(1)
},
response: {
node: RetVal("domnode")
node: RetVal("domnode", {optional: true})
}
}
@ -1035,7 +1035,8 @@ var WalkerActor = protocol.ActorClass({
*/
nextSibling: method(function(node, options={}) {
let walker = documentWalker(node.rawNode, options.whatToShow || Ci.nsIDOMNodeFilter.SHOW_ALL);
return this._ref(walker.nextSibling());
let sibling = walker.nextSibling();
return sibling ? this._ref(sibling) : null;
}, traversalMethod),
/**
@ -1049,7 +1050,8 @@ var WalkerActor = protocol.ActorClass({
*/
previousSibling: method(function(node, options={}) {
let walker = documentWalker(node.rawNode, options.whatToShow || Ci.nsIDOMNodeFilter.SHOW_ALL);
return this._ref(walker.previousSibling());
let sibling = walker.previousSibling();
return sibling ? this._ref(sibling) : null;
}, traversalMethod),
/**

View File

@ -185,7 +185,32 @@ addTest(function testSiblings() {
ok(response.nodes[0] === gWalker.rootNode, "Document element is its own sibling.");
});
}).then(runNextTest));
})
});
addTest(function testNextSibling() {
promiseDone(gWalker.querySelector(gWalker.rootNode, "#y").then(y => {
is(y.id, "y", "Got the right node.");
return gWalker.nextSibling(y);
}).then(z => {
is(z.id, "z", "nextSibling got the next node.");
return gWalker.nextSibling(z);
}).then(nothing => {
is(nothing, null, "nextSibling on the last node returned null.");
}).then(runNextTest));
});
addTest(function testPreviousSibling() {
promiseDone(gWalker.querySelector(gWalker.rootNode, "#b").then(b => {
is(b.id, "b", "Got the right node.");
return gWalker.previousSibling(b);
}).then(a => {
is(a.id, "a", "nextSibling got the next node.");
return gWalker.previousSibling(a);
}).then(nothing => {
is(nothing, null, "previousSibling on the first node returned null.");
}).then(runNextTest));
});
addTest(function testFrameTraversal() {
promiseDone(gWalker.querySelector(gWalker.rootNode, "#childFrame").then(childFrame => {