зеркало из https://github.com/mozilla/gecko-dev.git
Bug 892371 - Add mochitests covering LRU priority adjustments for both foreground and background processes. r=khuey
This commit is contained in:
Родитель
243ffd8828
Коммит
8988e8ef03
|
@ -51,6 +51,7 @@ const browserElementTestHelpers = {
|
|||
enableProcessPriorityManager: function() {
|
||||
this._setPrefs(
|
||||
['dom.ipc.processPriorityManager.BACKGROUND.LRUPoolLevels', 2],
|
||||
['dom.ipc.processPriorityManager.FOREGROUND.LRUPoolLevels', 2],
|
||||
['dom.ipc.processPriorityManager.testMode', true],
|
||||
['dom.ipc.processPriorityManager.enabled', true]
|
||||
);
|
||||
|
@ -188,27 +189,36 @@ function expectPriorityChange(childID, expectedPriority) {
|
|||
}
|
||||
|
||||
// Returns a promise which is resolved or rejected the next time the
|
||||
// process childID changes its priority. We resolve if the LRU parameter
|
||||
// matches expectedLRU and we reject otherwise.
|
||||
// process childID changes its priority. We resolve if the expectedPriority
|
||||
// matches the priority and the LRU parameter matches expectedLRU and we
|
||||
// reject otherwise.
|
||||
|
||||
function expectPriorityWithLRUSet(childID, expectedLRU) {
|
||||
function expectPriorityWithLRUSet(childID, expectedPriority, expectedLRU) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
|
||||
var observed = false;
|
||||
browserElementTestHelpers.addProcessPriorityObserver(
|
||||
'process-priority-with-LRU-set',
|
||||
function(subject, topic, data) {
|
||||
if (observed) {
|
||||
return;
|
||||
}
|
||||
|
||||
var [id, priority, lru] = data.split(":");
|
||||
if (id != childID) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure we run the is() calls in this observer only once,
|
||||
// otherwise we'll expect /every/ priority/LRU change to match
|
||||
// expectedPriority/expectedLRU.
|
||||
observed = true;
|
||||
|
||||
is(lru, expectedLRU,
|
||||
'Expected LRU ' + lru +
|
||||
' of childID ' + childID +
|
||||
' to change to ' + expectedLRU);
|
||||
|
||||
if (lru == expectedLRU) {
|
||||
if ((priority == expectedPriority) && (lru == expectedLRU)) {
|
||||
resolve();
|
||||
} else {
|
||||
reject();
|
||||
|
|
|
@ -14,6 +14,7 @@ support-files = file_HighPriority.html
|
|||
[test_BackgroundLRU.html]
|
||||
[test_Audio.html]
|
||||
support-files = file_Audio.html silence.ogg
|
||||
[test_ForegroundLRU.html]
|
||||
[test_Keyboard.html]
|
||||
[test_MultipleFrames.html]
|
||||
support-files = file_MultipleFrames.html
|
||||
|
|
|
@ -46,19 +46,22 @@ function runTest() {
|
|||
document.body.appendChild(iframe2);
|
||||
|
||||
// At this point, we should have iframe1 in background already.
|
||||
// We wait until another one is set to background, too.
|
||||
// Once there are two in background, the first one (LRU order)
|
||||
// should have 'backgroundLRU' equals 1
|
||||
var p = expectPriorityWithLRUSet(childID, '1');
|
||||
// We wait until another process goes into the background, too.
|
||||
// Once there are two in background, the first one should have its LRU
|
||||
// adjustment value increased to 1.
|
||||
var p = expectPriorityWithLRUSet(childID, 'BACKGROUND', '1');
|
||||
iframe2.setVisible(false);
|
||||
|
||||
return p;
|
||||
|
||||
}).then(function() {
|
||||
// Don't call removeChild immediately after calling setVisible.
|
||||
// setVisible on remote browser is async method, so we should wait
|
||||
// until it sends to the child process.
|
||||
// When iframe2 is removed iframe1's LRU value should be decreased again.
|
||||
var p = expectPriorityWithLRUSet(childID, 'BACKGROUND', '0');
|
||||
|
||||
document.body.removeChild(iframe2);
|
||||
|
||||
return p;
|
||||
}).then(function() {
|
||||
SimpleTest.finish();
|
||||
});
|
||||
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
Test that creating three foreground processes causes the LRU value of the
|
||||
oldest one to be increased by one. Also test that the LRU value is decreased
|
||||
again when the younger processes go into the background.
|
||||
-->
|
||||
<head>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="application/javascript" src="../browserElementTestHelpers.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<script type="application/javascript;version=1.7">
|
||||
"use strict";
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
browserElementTestHelpers.setEnabledPref(true);
|
||||
browserElementTestHelpers.addPermission();
|
||||
browserElementTestHelpers.enableProcessPriorityManager();
|
||||
SpecialPowers.addPermission("embed-apps", true, document);
|
||||
|
||||
function runTest() {
|
||||
var iframe1 = document.createElement('iframe');
|
||||
iframe1.setAttribute('mozbrowser', true);
|
||||
iframe1.src = 'file_MultipleFrames.html';
|
||||
|
||||
var iframe2 = null;
|
||||
var childID = null;
|
||||
|
||||
// Wait for the first process to be created.
|
||||
Promise.all([
|
||||
expectProcessCreated('FOREGROUND').then(function(chid) {
|
||||
childID = chid;
|
||||
}),
|
||||
expectMozbrowserEvent(iframe1, 'openwindow')
|
||||
]).then(function() {
|
||||
// Then wait for the second one.
|
||||
var p = expectProcessCreated('FOREGROUND');
|
||||
|
||||
iframe2 = document.createElement('iframe');
|
||||
iframe2.setAttribute('mozbrowser', true);
|
||||
iframe2.setAttribute('mozapp', 'http://example.org/manifest.webapp');
|
||||
iframe2.src = browserElementTestHelpers.emptyPage1;
|
||||
|
||||
document.body.appendChild(iframe2);
|
||||
|
||||
return p;
|
||||
}).then(function() {
|
||||
// Then wait for the third one and for the first one's LRU value to be
|
||||
// increased by one.
|
||||
var p = Promise.all([
|
||||
expectProcessCreated('FOREGROUND'),
|
||||
expectPriorityWithLRUSet(childID, 'FOREGROUND', 1)
|
||||
]);
|
||||
|
||||
document.body.appendChild(iframe2);
|
||||
|
||||
return p;
|
||||
}).then(function() {
|
||||
// Now hide the second and third processes, this will send them into the
|
||||
// background and make the first process LRU value to be decreased.
|
||||
var p = expectPriorityWithLRUSet(childID, 'FOREGROUND', 0)
|
||||
|
||||
iframe2.setVisible(false);
|
||||
|
||||
return p;
|
||||
}).then(function() {
|
||||
SimpleTest.finish();
|
||||
});
|
||||
|
||||
document.body.appendChild(iframe1);
|
||||
}
|
||||
|
||||
addEventListener('testready', runTest);
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче