Bug 1090759 - Part 3. Fix tests broken by DOM Promise's asyncness r=smaug

This commit is contained in:
Kan-Ru Chen (陳侃如) 2014-10-31 10:39:14 +08:00
Родитель 4fc798d590
Коммит 630d892dd6
16 изменённых файлов: 89 добавлений и 86 удалений

Просмотреть файл

@ -111,7 +111,8 @@ const browserElementTestHelpers = {
// Returns a promise which is resolved when a subprocess is created. The
// argument to resolve() is the childID of the subprocess.
function expectProcessCreated() {
function expectProcessCreated(/* optional */ initialPriority,
/* optional */ initialCPUPriority) {
return new Promise(function(resolve, reject) {
var observed = false;
browserElementTestHelpers.addProcessPriorityObserver(
@ -126,7 +127,13 @@ function expectProcessCreated() {
var childID = parseInt(data);
ok(true, 'Got new process, id=' + childID);
resolve(childID);
if (initialPriority) {
expectPriorityChange(childID, initialPriority, initialCPUPriority).then(function() {
resolve(childID);
});
} else {
resolve(childID);
}
}
);
});
@ -134,8 +141,9 @@ function expectProcessCreated() {
// Just like expectProcessCreated(), except we'll call ok(false) if a second
// process is created.
function expectOnlyOneProcessCreated() {
var p = expectProcessCreated();
function expectOnlyOneProcessCreated(/* optional */ initialPriority,
/* optional */ initialCPUPriority) {
var p = expectProcessCreated(initialPriority, initialCPUPriority);
p.then(function() {
expectProcessCreated().then(function(childID) {
ok(false, 'Got unexpected process creation, childID=' + childID);

Просмотреть файл

@ -24,16 +24,15 @@ function runTest() {
iframe.src = 'file_Audio.html';
var childID = null;
expectOnlyOneProcessCreated().then(function(chid) {
childID = chid;
return Promise.all(
[expectPriorityChange(childID, 'FOREGROUND'),
expectMozbrowserEvent(iframe, 'loadend'),
expectMozbrowserEvent(iframe, 'showmodalprompt').then(function(e) {
is(e.detail.message, 'onplay', 'showmodalprompt message');
})]
);
}).then(function() {
Promise.all([
expectOnlyOneProcessCreated("FOREGROUND").then(function(chid) {
childID = chid;
}),
expectMozbrowserEvent(iframe, 'loadend'),
expectMozbrowserEvent(iframe, 'showmodalprompt').then(function(e) {
is(e.detail.message, 'onplay', 'showmodalprompt message');
})
]).then(function() {
// Send the child process into the background. Because it's playing audio,
// it should get priority BACKGROUND_PERCEIVABLE, not vanilla BACKGROUND.
var p = expectPriorityChange(childID, 'BACKGROUND_PERCEIVABLE');

Просмотреть файл

@ -26,13 +26,12 @@ function runTest() {
iframe.src = browserElementTestHelpers.emptyPage1;
var childID = null;
expectOnlyOneProcessCreated().then(function(chid) {
childID = chid;
}).then(function() {
return expectPriorityChange(childID, 'FOREGROUND');
}).then(function() {
return expectMozbrowserEvent(iframe, 'loadend');
}).then(function() {
Promise.all([
expectOnlyOneProcessCreated('FOREGROUND').then(function(chid) {
childID = chid;
}),
expectMozbrowserEvent(iframe, 'loadend')
]).then(function() {
var p = expectPriorityChange(childID, 'BACKGROUND');
// We wait until mozbrowserloadend before calling setVisible, because

Просмотреть файл

@ -28,12 +28,12 @@ function runTest() {
var iframe2 = null;
var childID = null;
expectProcessCreated().then(function(chid) {
childID = chid;
return expectPriorityChange(childID, 'FOREGROUND');
}).then(function() {
return expectMozbrowserEvent(iframe1, 'openwindow');
}).then(function() {
Promise.all([
expectProcessCreated('FOREGROUND').then(function(chid) {
childID = chid;
}),
expectMozbrowserEvent(iframe1, 'openwindow')
]).then(function() {
var p = expectPriorityChange(childID, 'BACKGROUND');
iframe1.setVisible(false);
return p;

Просмотреть файл

@ -30,9 +30,8 @@ function runTest() {
iframe.src = browserElementTestHelpers.emptyPage1;
var childID = null;
expectOnlyOneProcessCreated().then(function(chid) {
expectOnlyOneProcessCreated('FOREGROUND_HIGH').then(function(chid) {
childID = chid;
return expectPriorityChange(childID, 'FOREGROUND_HIGH');
}).then(function() {
// We go back to foreground when the wake lock taken on behalf of our new
// process times out.

Просмотреть файл

@ -42,12 +42,12 @@ function runTest() {
iframe.src = browserElementTestHelpers.emptyPage1;
var childID = null;
expectOnlyOneProcessCreated().then(function(chid) {
childID = chid;
return Promise.all(
[expectPriorityChange(childID, 'FOREGROUND'),
expectMozbrowserEvent(iframe, 'loadend')]);
}).then(function() {
Promise.all([
expectOnlyOneProcessCreated('FOREGROUND').then(function(chid) {
childID = chid;
}),
expectMozbrowserEvent(iframe, 'loadend')
]).then(function() {
var p = expectPriorityChange(childID, 'BACKGROUND_PERCEIVABLE');
iframe.setVisible(false);
return p;

Просмотреть файл

@ -89,19 +89,23 @@ function runTest() {
}
}
return Promise.all(
[expectMozbrowserEvent(iframe, 'showmodalprompt').then(checkAlertInfo),
expectPriorityChange(childID, priority).then(checkGracePeriod)]
).then(function(results) {
return Promise.all([
new Promise(function(resolve, reject) {
iframe.addEventListener('mozbrowsershowmodalprompt', function check(e) {
iframe.removeEventListener('mozbrowsershowmodalprompt', check);
resolve(checkAlertInfo(e));
});
}),
expectPriorityChange(childID, priority).then(checkGracePeriod)
]).then(function(results) {
// checkAlertInfo returns the function to call to unblock the alert.
// It comes to us as the first element of the results array.
results[0]();
});
}
expectProcessCreated().then(function(chid) {
expectProcessCreated('FOREGROUND').then(function(chid) {
childID = chid;
return expectPriorityChange(childID, 'FOREGROUND');
}).then(function() {
return expectAlertAndPriorityChange(0, 'FOREGROUND_HIGH');
}).then(function() {

Просмотреть файл

@ -34,9 +34,8 @@ function runTest() {
var lock = null;
var p = null;
expectProcessCreated().then(function(chid) {
expectProcessCreated('FOREGROUND', 'CPU_NORMAL').then(function(chid) {
childID = chid;
return expectPriorityChange(childID, 'FOREGROUND', 'CPU_NORMAL');
}).then(function() {
// Create a new, high-priority iframe.
highPriorityIframe = document.createElement('iframe');

Просмотреть файл

@ -33,9 +33,8 @@ function runTest() {
var highPriorityIframe = null;
var childID = null;
expectProcessCreated().then(function(chid) {
expectProcessCreated('FOREGROUND', 'CPU_NORMAL').then(function(chid) {
childID = chid;
return expectPriorityChange(childID, 'FOREGROUND', 'CPU_NORMAL');
}).then(function() {
// Create a new, high-priority iframe.
highPriorityIframe = document.createElement('iframe');

Просмотреть файл

@ -26,13 +26,12 @@ function runTest() {
iframe.src = browserElementTestHelpers.emptyPage1;
var childID = null;
expectOnlyOneProcessCreated().then(function(chid) {
childID = chid;
}).then(function() {
return expectPriorityChange(childID, 'FOREGROUND_KEYBOARD');
}).then(function() {
return expectMozbrowserEvent(iframe, 'loadend');
}).then(function() {
Promise.all([
expectOnlyOneProcessCreated('FOREGROUND_KEYBOARD').then(function(chid) {
childID = chid;
}),
expectMozbrowserEvent(iframe, 'loadend')
]).then(function() {
var p = expectPriorityChange(childID, 'BACKGROUND');
/* We wait until mozbrowserloadend before calling setVisible, because

Просмотреть файл

@ -26,16 +26,19 @@ function runTest() {
var childID = null;
var iframe2;
expectProcessCreated().then(function(chid) {
childID = chid;
return expectPriorityChange(childID, 'FOREGROUND');
}).then(function() {
return expectMozbrowserEvent(iframe, 'openwindow');
}).then(function(e) {
iframe2 = e.detail.frameElement;
document.body.appendChild(iframe2);
return expectMozbrowserEvent(iframe2, 'loadend');
}).then(function() {
Promise.all([
expectProcessCreated('FOREGROUND').then(function(chid) {
childID = chid;
}),
new Promise(function(resolve, reject) {
iframe.addEventListener('mozbrowseropenwindow', function(e) {
iframe2 = e.detail.frameElement;
var p = expectMozbrowserEvent(iframe2, 'loadend');
document.body.appendChild(iframe2);
resolve(p);
});
})
]).then(function() {
// At this point, the child process has been set to FOREGROUND, and the popup
// opened by file_MultipleFrames has finished loading.
//

Просмотреть файл

@ -50,9 +50,8 @@ function runTest() {
// outer iframe runs in-process (because it has remote=false).
var childID = null;
Promise.all(
[expectOnlyOneProcessCreated().then(function(child) {
[expectOnlyOneProcessCreated('FOREGROUND').then(function(child) {
childID = child;
return expectPriorityChange(childID, 'FOREGROUND');
}),
expectMozbrowserEvent(iframe, 'loadend')]
).then(function() {

Просмотреть файл

@ -60,9 +60,7 @@ function runTest()
// Ensure that the preallocated process initially gets BACKGROUND priority.
// That's it.
expectProcessCreated().then(function(childID) {
return expectPriorityChange(childID, 'PREALLOC', 'CPU_LOW');
}).then(function() {
expectProcessCreated('PREALLOC', 'CPU_LOW').then(function() {
// We need to set the pref asynchoronously or the preallocated process won't
// be shut down.
SimpleTest.executeSoon(function(){

Просмотреть файл

@ -36,9 +36,7 @@ function runTest() {
iframe.setAttribute('mozbrowser', true);
iframe.src = browserElementTestHelpers.emptyPage1;
expectProcessCreated().then(function(childID) {
return expectPriorityChange(childID, 'FOREGROUND');
}).then(SimpleTest.finish);
expectProcessCreated('FOREGROUND').then(SimpleTest.finish);
document.body.appendChild(iframe);
}

Просмотреть файл

@ -24,12 +24,12 @@ function runTest() {
iframe.src = browserElementTestHelpers.emptyPage1;
var childID = null;
expectOnlyOneProcessCreated().then(function(chid) {
childID = chid;
return Promise.all(
[expectPriorityChange(childID, 'FOREGROUND'),
expectMozbrowserEvent(iframe, 'loadend')]);
}).then(function() {
Promise.all([
expectOnlyOneProcessCreated('FOREGROUND').then(function(chid) {
childID = chid;
}),
expectMozbrowserEvent(iframe, 'loadend')
]).then(function() {
// Mark the frame as not visible. This should cause its priority to drop
// to BACKGROUND.
var p = expectPriorityChange(childID, 'BACKGROUND');

Просмотреть файл

@ -44,16 +44,15 @@ function runTest() {
}).then(finishOnce);
var childID = null;
expectOnlyOneProcessCreated().then(function(chid) {
childID = chid;
return Promise.all(
[expectPriorityChange(childID, 'FOREGROUND'),
expectMozbrowserEvent(iframe, 'loadend'),
expectMozbrowserEvent(iframe, 'showmodalprompt').then(function(e) {
is(e.detail.message, 'ready');
})
]);
}).then(function() {
Promise.all([
expectOnlyOneProcessCreated('FOREGROUND').then(function(chid) {
childID = chid;
}),
expectMozbrowserEvent(iframe, 'loadend'),
expectMozbrowserEvent(iframe, 'showmodalprompt').then(function(e) {
is(e.detail.message, 'ready');
})
]).then(function() {
// Fire a low-memory notification once the process goes into the background
// due to the setVisible(false) call below.
expectPriorityChange(childID, 'BACKGROUND').then(function() {