dom/browser-element/mochitest/priority/test_HighPriorityDowngrade2.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/browser-element/mochitest/priority/test_HighPriorityDowngrade2.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,77 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +Test that high-priority processes downgrade the CPU priority of regular
     1.8 +processes.
     1.9 +
    1.10 +This is just like test_HighPriorityDowngrade, except instead of waiting for the
    1.11 +high-priority process's wake lock to expire, we kill the process by removing
    1.12 +its iframe from the DOM.
    1.13 +-->
    1.14 +<head>
    1.15 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.16 +  <script type="application/javascript" src="../browserElementTestHelpers.js"></script>
    1.17 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.18 +</head>
    1.19 +<body>
    1.20 +
    1.21 +<script type="application/javascript;version=1.7">
    1.22 +"use strict";
    1.23 +
    1.24 +SimpleTest.waitForExplicitFinish();
    1.25 +browserElementTestHelpers.setEnabledPref(true);
    1.26 +browserElementTestHelpers.addPermission();
    1.27 +browserElementTestHelpers.enableProcessPriorityManager();
    1.28 +SpecialPowers.addPermission("embed-apps", true, document);
    1.29 +
    1.30 +function runTest() {
    1.31 +  var iframe = document.createElement('iframe');
    1.32 +  iframe.setAttribute('mozbrowser', true);
    1.33 +
    1.34 +  iframe.src = browserElementTestHelpers.emptyPage1;
    1.35 +
    1.36 +  var highPriorityIframe = null;
    1.37 +  var childID = null;
    1.38 +
    1.39 +  expectProcessCreated().then(function(chid) {
    1.40 +    childID = chid;
    1.41 +    return expectPriorityChange(childID, 'FOREGROUND', 'CPU_NORMAL');
    1.42 +  }).then(function() {
    1.43 +    // Create a new, high-priority iframe.
    1.44 +    highPriorityIframe = document.createElement('iframe');
    1.45 +    highPriorityIframe.setAttribute('mozbrowser', true);
    1.46 +    highPriorityIframe.setAttribute('expecting-system-message', true);
    1.47 +    highPriorityIframe.setAttribute('mozapptype', 'critical');
    1.48 +    highPriorityIframe.setAttribute('mozapp', 'http://example.org/manifest.webapp');
    1.49 +    highPriorityIframe.src = browserElementTestHelpers.emptyPage2;
    1.50 +
    1.51 +    var p = Promise.all(
    1.52 +      [expectPriorityChange(childID, 'FOREGROUND', 'CPU_LOW'),
    1.53 +       expectMozbrowserEvent(highPriorityIframe, 'loadend')]
    1.54 +    );
    1.55 +
    1.56 +    document.body.appendChild(highPriorityIframe);
    1.57 +
    1.58 +    return p;
    1.59 +  }).then(function() {
    1.60 +    // Killing the high-priority iframe should cause our CPU priority to go back
    1.61 +    // up to regular.
    1.62 +    var p = expectPriorityChange(childID, 'FOREGROUND', 'CPU_NORMAL');
    1.63 +    document.body.removeChild(highPriorityIframe);
    1.64 +    return p;
    1.65 +  }).then(SimpleTest.finish);
    1.66 +
    1.67 +  document.body.appendChild(iframe);
    1.68 +}
    1.69 +
    1.70 +addEventListener('testready', function() {
    1.71 +  // Cause the CPU wake lock taken on behalf of the high-priority process never
    1.72 +  // to time out during this test.
    1.73 +  SpecialPowers.pushPrefEnv(
    1.74 +    {set: [["dom.ipc.systemMessageCPULockTimeoutSec", 1000]]},
    1.75 +    runTest);
    1.76 +});
    1.77 +
    1.78 +</script>
    1.79 +</body>
    1.80 +</html>

mercurial