gecko-dev/dom/browser-element/mochitest/priority/test_MultipleFrames.html

71 строка
2.2 KiB
HTML

<!DOCTYPE HTML>
<html>
<!--
Test that when we remove one of a process's frames from the DOM, the process's
priority is recomputed.
-->
<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();
// ProcessPriorityManager requires at least one process in foreground
// so that other processes can transit freely between foreground and
// background.
function setupTest() {
var foreground = document.createElement('iframe');
foreground.setAttribute('mozbrowser', true);
foreground.src = browserElementTestHelpers.emptyPage;
expectMozbrowserEvent(foreground, 'loadend').then(runTest);
document.body.appendChild(foreground);
}
function runTest() {
var iframe = document.createElement('iframe');
iframe.setAttribute('mozbrowser', true);
iframe.src = 'file_MultipleFrames.html';
var childID = null;
var iframe2;
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.
//
// Now setVisible(false) the popup frame and remove the popup frame from the
// DOM. This should cause the process to take on BACKGROUND priority.
var p = expectPriorityChange(childID, 'BACKGROUND');
iframe.setVisible(false);
document.body.removeChild(iframe2);
return p;
}).then(SimpleTest.finish);
document.body.appendChild(iframe);
}
addEventListener('testready', setupTest);
</script>
</body>
</html>