Bug 1172164 - Don't allow the walker to start with a node that it doesn't recognize due to a filter;r=pbrosset

This commit is contained in:
Brian Grinstead 2015-06-09 11:06:28 -07:00
Родитель 4a85f58c6c
Коммит c12c02094f
2 изменённых файлов: 50 добавлений и 4 удалений

Просмотреть файл

@ -1295,7 +1295,9 @@ var WalkerActor = protocol.ActorClass({
getDocumentWalker: function(node, whatToShow) {
// Allow native anon content (like <video> controls) if preffed on
let nodeFilter = this.showAllAnonymousContent ? allAnonymousContentTreeWalkerFilter : standardTreeWalkerFilter;
let nodeFilter = this.showAllAnonymousContent
? allAnonymousContentTreeWalkerFilter
: standardTreeWalkerFilter;
return new DocumentWalker(node, this.rootWin, whatToShow, nodeFilter);
},
@ -1418,9 +1420,16 @@ var WalkerActor = protocol.ActorClass({
let nodeActors = [];
let newParents = new Set();
for (let node of nodes) {
// Be sure we deal with NodeActor only.
if (!(node instanceof NodeActor))
if (!(node instanceof NodeActor)) {
// If an anonymous node was passed in and we aren't supposed to know
// about it, then consult with the document walker as the source of
// truth about which elements exist.
if (!this.showAllAnonymousContent && LayoutHelpers.isAnonymous(node)) {
node = this.getDocumentWalker(node).currentNode;
}
node = this._ref(node);
}
this.ensurePathToRoot(node, newParents);
// If nodes may be an array of raw nodes, we're sure to only have
@ -3782,8 +3791,16 @@ function DocumentWalker(node, rootWin, whatToShow=Ci.nsIDOMNodeFilter.SHOW_ALL,
this.walker.showSubDocuments = true;
this.walker.showDocumentsAsNodes = true;
this.walker.init(rootWin.document, whatToShow);
this.walker.currentNode = node;
this.filter = filter;
// Make sure that the walker knows about the initial node (which could
// be skipped due to a filter). Note that simply calling parentNode()
// causes currentNode to be updated.
this.walker.currentNode = node;
while (node &&
this.filter(node) === Ci.nsIDOMNodeFilter.FILTER_SKIP) {
node = this.walker.parentNode();
}
}
DocumentWalker.prototype = {

Просмотреть файл

@ -13,10 +13,13 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=777674
<script type="application/javascript;version=1.8">
window.onload = function() {
Components.utils.import("resource://gre/modules/devtools/Loader.jsm");
const Ci = Components.interfaces;
const {Promise: promise} =
Components.utils.import("resource://gre/modules/Promise.jsm", {});
const {InspectorFront} =
devtools.require("devtools/server/actors/inspector");
const {_documentWalker} =
devtools.require("devtools/server/actors/inspector");
const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
Services.prefs.setBoolPref("dom.webcomponents.enabled", true);
@ -69,6 +72,32 @@ window.onload = function() {
runNextTest();
});
addAsyncTest(function* testNativeAnonymousStartingNode() {
info ("Tests attaching an element that a walker can't see.");
let serverConnection = gWalker.conn._transport._serverConnection;
let serverWalker = serverConnection.getActor(gWalker.actorID);
let docwalker = new _documentWalker(
gInspectee.querySelector("select"),
gInspectee.defaultView,
Ci.nsIDOMNodeFilter.SHOW_ALL,
() => {
return Ci.nsIDOMNodeFilter.FILTER_ACCEPT
}
);
let scrollbar = docwalker.lastChild();
is (scrollbar.tagName, "scrollbar", "An anonymous child has been fetched");
let node = yield serverWalker.attachElement(scrollbar);
ok (node, "A response has arrived");
ok (node.node, "A node is in the response");
is (node.node.rawNode.tagName, "SELECT",
"The node has changed to a parent that the walker recognizes");
runNextTest();
});
addAsyncTest(function* testPseudoElements() {
info ("Testing pseudo elements with walker.");