Bug 1091463 - wait for all expected markers from docshell. r=paul

This commit is contained in:
Tom Tromey 2014-11-14 10:57:00 +01:00
parent 17b3d982fe
commit ce3b7ee396
2 changed files with 9 additions and 10 deletions

View File

@ -43,13 +43,13 @@ let test = Task.async(function*() {
docShell.popProfileTimelineMarkers();
info("Running the test setup function");
let onMarkers = waitForMarkers(docShell);
let onMarkers = waitForDOMMarkers(docShell, 5);
setup();
info("Waiting for new markers on the docShell");
let markers = yield onMarkers;
info("Running the test check function");
check(markers.filter(m => m.name == "DOMEvent"));
check(markers);
}
info("Stop recording");
@ -73,21 +73,20 @@ function openUrl(url) {
});
}
function waitForMarkers(docshell) {
function waitForDOMMarkers(docshell, numExpected) {
return new Promise(function(resolve, reject) {
let waitIterationCount = 0;
let maxWaitIterationCount = 10; // Wait for 2sec maximum
let markers = [];
let interval = setInterval(() => {
let markers = docshell.popProfileTimelineMarkers();
if (markers.length > 0) {
let newMarkers = docshell.popProfileTimelineMarkers();
markers = [...markers, ...newMarkers.filter(m => m.name == "DOMEvent")];
if (markers.length >= numExpected
|| waitIterationCount > maxWaitIterationCount) {
clearInterval(interval);
resolve(markers);
}
if (waitIterationCount > maxWaitIterationCount) {
clearInterval(interval);
resolve([]);
}
waitIterationCount++;
}, 200);
});

View File

@ -14,7 +14,7 @@
xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
// Nothing.
dump("ReadyState = " + xhr.readyState + "\n");
};
xhr.open("get", theURL, true);
xhr.send();