Skip to content

Commit

Permalink
Merge pull request #469 from hypothesis/frame-test-fix
Browse files Browse the repository at this point in the history
Adding waitForFrameObserver in frame manipulation tests
  • Loading branch information
sean-roberts authored Jun 27, 2017
2 parents 054f818 + 357d4ef commit eb093f7
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions src/annotator/test/integration/multi-frame-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var proxyquire = require('proxyquire');
var isLoaded = require('../../util/frame-util').isLoaded;

var FRAME_ADD_WAIT = require('../../frame-observer').DEBOUNCE_WAIT + 10;
var FRAME_DEBOUNCE_WAIT = require('../../frame-observer').DEBOUNCE_WAIT + 10;

describe('CrossFrame multi-frame scenario', function () {
var fakeAnnotationSync;
Expand All @@ -16,6 +16,10 @@ describe('CrossFrame multi-frame scenario', function () {

var sandbox = sinon.sandbox.create();

var waitForFrameObserver = function(cb){
return setTimeout(cb, FRAME_DEBOUNCE_WAIT);
};

beforeEach(function () {
fakeBridge = {
createChannel: sandbox.stub(),
Expand Down Expand Up @@ -139,13 +143,13 @@ describe('CrossFrame multi-frame scenario', function () {

return new Promise(function (resolve) {
// Yield to let the DOM and CrossFrame catch up
setTimeout(function () {
waitForFrameObserver(function () {
isLoaded(frame, function () {
assert(frame.contentDocument.body.hasChildNodes(),
'expected dynamically added frame to be modified');
resolve();
});
}, FRAME_ADD_WAIT);
});
});
});

Expand All @@ -159,15 +163,15 @@ describe('CrossFrame multi-frame scenario', function () {

return new Promise(function (resolve) {
// Yield to let the DOM and CrossFrame catch up
setTimeout(function () {
waitForFrameObserver(function () {
frame.remove();

// Yield again
setTimeout(function () {
waitForFrameObserver(function () {
assert.calledWith(fakeBridge.call, 'destroyFrame');
resolve();
}, 0);
}, 0);
});
});
});
});

Expand All @@ -188,19 +192,21 @@ describe('CrossFrame multi-frame scenario', function () {
frame.remove();

// Yield to let the DOM and CrossFrame catch up
setTimeout(function () {
waitForFrameObserver(function () {

// Add the frame again
container.appendChild(frame);

// Yield again
setTimeout(function () {
waitForFrameObserver(function () {

isLoaded(frame, function () {
assert(frame.contentDocument.body.hasChildNodes(),
'expected dynamically added frame to be modified');
resolve();
});
}, FRAME_ADD_WAIT);
}, 0);
});
});
});
});
});
Expand All @@ -216,30 +222,30 @@ describe('CrossFrame multi-frame scenario', function () {

return new Promise(function (resolve) {
// Yield to let the DOM and CrossFrame catch up
setTimeout(function () {
waitForFrameObserver(function () {
isLoaded(frame, function () {
assert(frame.contentDocument.body.hasChildNodes(),
'expected dynamically added frame to be modified');

frame.remove();

// Yield again
setTimeout(function () {
waitForFrameObserver(function () {
// Add the frame again
container.appendChild(frame);

// Yield
setTimeout(function () {
waitForFrameObserver(function () {
isLoaded(frame, function () {
assert(frame.contentDocument.body.hasChildNodes(),
'expected dynamically added frame to be modified');
resolve();
});
}, FRAME_ADD_WAIT);
}, 0);
});
});
});
}, FRAME_ADD_WAIT);
});
});
});

});
});

0 comments on commit eb093f7

Please sign in to comment.