From f75b6dc79c232a8287901ffc79d5d0b3a5ff9137 Mon Sep 17 00:00:00 2001 From: Dave Camp Date: Mon, 10 Jun 2013 21:18:18 -0700 Subject: [PATCH] Bug 883599 - Fix the inspector actor's nextSibling and previousSibling requests. r=paul --- toolkit/devtools/server/actors/inspector.js | 8 +++--- .../mochitest/test_inspector-traversal.html | 27 ++++++++++++++++++- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/toolkit/devtools/server/actors/inspector.js b/toolkit/devtools/server/actors/inspector.js index 7dc92f7a82a..be0fe43f960 100644 --- a/toolkit/devtools/server/actors/inspector.js +++ b/toolkit/devtools/server/actors/inspector.js @@ -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), /** diff --git a/toolkit/devtools/server/tests/mochitest/test_inspector-traversal.html b/toolkit/devtools/server/tests/mochitest/test_inspector-traversal.html index fa125c8c86c..fb31388ffa3 100644 --- a/toolkit/devtools/server/tests/mochitest/test_inspector-traversal.html +++ b/toolkit/devtools/server/tests/mochitest/test_inspector-traversal.html @@ -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 => {