diff --git a/lib/core/utils/send-command-to-frame.js b/lib/core/utils/send-command-to-frame.js index 78dff468b4..fb17e30d69 100644 --- a/lib/core/utils/send-command-to-frame.js +++ b/lib/core/utils/send-command-to-frame.js @@ -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, () => { diff --git a/test/core/utils/collect-results-from-frames.js b/test/core/utils/collect-results-from-frames.js index a71d86aacc..70aade1881 100644 --- a/test/core/utils/collect-results-from-frames.js +++ b/test/core/utils/collect-results-from-frames.js @@ -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); @@ -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'; }; @@ -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(); } ); @@ -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'; }; @@ -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(); } );