Skip to content
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.

Commit

Permalink
Merge pull request #150 from davidhsv/#149
Browse files Browse the repository at this point in the history
#149 Be able to evaluate page with iframes
  • Loading branch information
ckundo committed Jul 8, 2015
2 parents 9183b21 + 83e5af1 commit ff9c479
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
14 changes: 7 additions & 7 deletions dist/js/axs_testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -1288,11 +1288,11 @@ axs.properties.getTextFromAriaLabelledby = function(a, b) {
};
axs.properties.getTextFromHostLanguageAttributes = function(a, b, c, d) {
if (axs.browserUtils.matchSelector(a, "img") && a.hasAttribute("alt")) {
var e = {type:"string", valid:!0};
e.text = a.getAttribute("alt");
c ? e.unused = !0 : c = e.text;
b.alt = e;
}
var e = {type:"string", valid:!0};
e.text = a.getAttribute("alt");
c ? e.unused = !0 : c = e.text;
b.alt = e;
}
if (axs.browserUtils.matchSelector(a, 'input:not([type="hidden"]):not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), video:not([disabled])') && !d) {
if (a.hasAttribute("id")) {
d = document.querySelectorAll('label[for="' + a.id + '"]');
Expand Down Expand Up @@ -1330,8 +1330,8 @@ axs.properties.getLastWord = function(a) {
axs.properties.getTextProperties = function(a) {
var b = {}, c = axs.properties.findTextAlternatives(a, b, !1, !0);
if (0 == Object.keys(b).length && ((a = axs.utils.asElement(a)) && axs.browserUtils.matchSelector(a, "img") && (b.alt = {valid:!1, errorMessage:"No alt value provided"}, a = a.src, "string" == typeof a && (c = a.split("/").pop(), b.filename = {text:c})), !c)) {
return null;
}
return null;
}
b.hasProperties = Boolean(Object.keys(b).length);
b.computedText = c;
b.lastWord = axs.properties.getLastWord(c);
Expand Down
8 changes: 8 additions & 0 deletions src/js/AuditRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ axs.AuditRule.collectMatchingElements = function(node, matcher, collection,
}
}
}

//If it is a iframe, get the contentDocument
if (element && element.localName == 'iframe' && element.contentDocument) {
axs.AuditRule.collectMatchingElements(element.contentDocument,
matcher,
collection,
opt_shadowRoot);
}
// If it is neither the parent of a ShadowRoot, a <content> element, nor
// a <shadow> element recurse normally.
var child = node.firstChild;
Expand Down
10 changes: 10 additions & 0 deletions test/js/audit-rule-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@
equal(matched.length, DIV_COUNT);
});

test("Iframe with simple DOM", function () {
var ifrm = document.createElement("IFRAME");
var container = document.getElementById('qunit-fixture');
container.appendChild(ifrm);
ifrm.contentDocument.body.appendChild(buildTestDom());
var matched = [];
axs.AuditRule.collectMatchingElements(container, matcher, matched);
equal(matched.length, DIV_COUNT);
});

test("With shadow DOM with no content insertion point", function () {
var container = document.getElementById('qunit-fixture');
container.appendChild(buildTestDom());
Expand Down
3 changes: 3 additions & 0 deletions tools/runner/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ var page = require('webpage').create(),
system = require('system'),
url;

// disabling so we can get the document root from iframes (http -> https)
page.settings.webSecurityEnabled = false;

if (system.args.length !== 2) {
console.log('Usage: phantomjs audit.js URL');
phantom.exit();
Expand Down

0 comments on commit ff9c479

Please sign in to comment.