Skip to content

Commit

Permalink
fix(axe.run): add option to increase iframe ping timeout (#3233)
Browse files Browse the repository at this point in the history
  • Loading branch information
straker committed Oct 22, 2021
1 parent 5925898 commit 023f356
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/core/utils/send-command-to-frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function sendCommandToFrame(node, parameters, resolve, reject) {
reject(err('No response from frame', node));
}
}, 0);
}, 500);
}, parameters.options?.pingWaitTime ?? 500);

// send 'axe.ping' to the frame
respondable(win, 'axe.ping', null, undefined, () => {
Expand Down
89 changes: 81 additions & 8 deletions test/core/utils/collect-results-from-frames.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ describe('axe.utils.collectResultsFromFrames', function() {
var Context = axe._thisWillBeDeletedDoNotUse.base.Context;
var fixture = document.getElementById('fixture');
var noop = function() {};
var origSetTimeout = window.setTimeout;

function contextSetup(scope) {
var context = new Context(scope);
Expand All @@ -14,20 +15,95 @@ describe('axe.utils.collectResultsFromFrames', function() {
}

afterEach(function() {
window.setTimeout = origSetTimeout;
fixture.innerHTML = '';
axe._tree = undefined;
axe._selectorData = undefined;
});

it('should timeout after 60s', function(done) {
var orig = window.setTimeout;
it('should timeout the ping request after 500ms', function(done) {
this.timeout = 1000;

var timeoutSet = false;
window.setTimeout = function(fn, to) {
if (to === 500) {
timeoutSet = true;
fn();
} else {
// ping timeout
return origSetTimeout(fn, to);
}
return 'cats';
};

var frame = document.createElement('iframe');
frame.addEventListener('load', function() {
var context = contextSetup(document);

axe.utils.collectResultsFromFrames(
context,
{},
'stuff',
'morestuff',
function() {
assert.isTrue(timeoutSet);
done();
},
noop
);
});

frame.id = 'level0';
frame.src = '../mock/frames/results-timeout.html';
fixture.appendChild(frame);
});

it('should override the ping timeout with `options.pingWaitTime`, if provided', function(done) {
this.timeout = 1000;

var timeoutSet = false;
window.setTimeout = function(fn, to) {
if (to === 90000) {
timeoutSet = true;
fn();
} else {
// ping timeout
return origSetTimeout(fn, to);
}
return 'cats';
};

var frame = document.createElement('iframe');
frame.addEventListener('load', function() {
var context = contextSetup(document);
var params = { pingWaitTime: 90000 };

axe.utils.collectResultsFromFrames(
context,
params,
'stuff',
'morestuff',
function() {
assert.isTrue(timeoutSet);
done();
},
noop
);
});

frame.id = 'level0';
frame.src = '../mock/frames/results-timeout.html';
fixture.appendChild(frame);
});

it('should timeout the start request after 60s', function(done) {
window.setTimeout = function(fn, to) {
if (to === 60000) {
assert.ok('timeout set');
fn();
} else {
// ping timeout
return orig(fn, to);
return origSetTimeout(fn, to);
}
return 'cats';
};
Expand All @@ -44,7 +120,6 @@ describe('axe.utils.collectResultsFromFrames', function() {
function(err) {
assert.instanceOf(err, Error);
assert.equal(err.message.split(/: /)[0], 'Axe in frame timed out');
window.setTimeout = orig;
done();
}
);
Expand All @@ -55,15 +130,14 @@ describe('axe.utils.collectResultsFromFrames', function() {
fixture.appendChild(frame);
});

it('should override the timeout with `options.frameWaitTime`, if provided', function(done) {
var orig = window.setTimeout;
it('should override the start timeout with `options.frameWaitTime`, if provided', function(done) {
window.setTimeout = function(fn, to) {
if (to === 90000) {
assert.ok('timeout set');
fn();
} else {
// ping timeout
return orig(fn, to);
return origSetTimeout(fn, to);
}
return 'cats';
};
Expand All @@ -82,7 +156,6 @@ describe('axe.utils.collectResultsFromFrames', function() {
function(err) {
assert.instanceOf(err, Error);
assert.equal(err.message.split(/: /)[0], 'Axe in frame timed out');
window.setTimeout = orig;
done();
}
);
Expand Down

0 comments on commit 023f356

Please sign in to comment.