diff --git a/lib/core/base/audit.js b/lib/core/base/audit.js index d9f80598f8..c07b66818f 100644 --- a/lib/core/base/audit.js +++ b/lib/core/base/audit.js @@ -144,7 +144,7 @@ Audit.prototype.run = function (context, options, resolve, reject) { 'use strict'; this.validateOptions(options); - axe._tree = axe.utils.getFlattenedTree(document.body); //cache the flattened tree + axe._tree = axe.utils.getFlattenedTree(document.documentElement); //cache the flattened tree var q = axe.utils.queue(); this.rules.forEach(function (rule) { if (axe.utils.ruleShouldRun(rule, context, options)) { diff --git a/lib/core/utils/flattened-tree.js b/lib/core/utils/flattened-tree.js index 8d7aabb38a..2fc6b192a6 100644 --- a/lib/core/utils/flattened-tree.js +++ b/lib/core/utils/flattened-tree.js @@ -123,6 +123,9 @@ axe.utils.getFlattenedTree = function (node, shadowId) { axe.utils.getNodeFromTree = function (vNode, node) { var found; + if (vNode.actualNode === node) { + return vNode; + } vNode.children.forEach((candidate) => { var retVal; diff --git a/test/checks/navigation/region.js b/test/checks/navigation/region.js index 7a2c35328e..4ce4aa5d1c 100644 --- a/test/checks/navigation/region.js +++ b/test/checks/navigation/region.js @@ -95,7 +95,7 @@ describe('region', function () { }); it('ignores native landmark elements with an overwriting role', function () { - var checkArgs = checkSetup('
'); + var checkArgs = checkSetup('
Content
'); assert.isFalse(checks.region.evaluate.apply(checkContext, checkArgs)); assert.lengthOf(checkContext._relatedNodes, 1); diff --git a/test/commons/dom/is-in-text-block.js b/test/commons/dom/is-in-text-block.js index f89519bb19..20574d0ba6 100644 --- a/test/commons/dom/is-in-text-block.js +++ b/test/commons/dom/is-in-text-block.js @@ -143,7 +143,7 @@ describe('dom.isInTextBlock', function () { assert.isFalse(axe.commons.dom.isInTextBlock(link)); }); - (shadowSupport ? it : xit)('can reach outside a shadow tree', function () { + (shadowSupport.v1 ? it : xit)('can reach outside a shadow tree', function () { var div = document.createElement('div'); div.innerHTML = 'Some paragraph with text '; var shadow = div.querySelector('span').attachShadow({ mode: 'open' }); diff --git a/test/core/utils/flattened-tree.js b/test/core/utils/flattened-tree.js index f8121c219e..279a4af8a6 100644 --- a/test/core/utils/flattened-tree.js +++ b/test/core/utils/flattened-tree.js @@ -231,6 +231,12 @@ if (shadowSupport.v1) { assert.equal(node, vNode.actualNode); assert.equal(vNode.actualNode.textContent, '1'); }); + it('should find the virtual node if it is the very top of the tree', function () { + var virtualDOM = axe.utils.getFlattenedTree(fixture); + var vNode = axe.utils.getNodeFromTree(virtualDOM[0], virtualDOM[0].actualNode); + assert.isDefined(vNode); + assert.equal(virtualDOM[0].actualNode, vNode.actualNode); + }); }); }