dom/browser-element/mochitest/priority/test_Preallocated.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_Preallocated.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,81 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +Test that the preallocated process starts up with priority BACKGROUND.
     1.8 +-->
     1.9 +<head>
    1.10 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.11 +  <script type="application/javascript" src="../browserElementTestHelpers.js"></script>
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.13 +</head>
    1.14 +<body>
    1.15 +
    1.16 +<script type="application/javascript;version=1.7">
    1.17 +"use strict";
    1.18 +
    1.19 +SimpleTest.waitForExplicitFinish();
    1.20 +browserElementTestHelpers.setEnabledPref(true);
    1.21 +browserElementTestHelpers.addPermission();
    1.22 +browserElementTestHelpers.enableProcessPriorityManager();
    1.23 +
    1.24 +var preallocationEnabledPref = null;
    1.25 +try {
    1.26 +  preallocationEnabledPref = SpecialPowers.getBoolPref('dom.ipc.processPrelaunch.enabled');
    1.27 +}
    1.28 +catch(e) {
    1.29 +  preallocationEnabledPref = null;
    1.30 +}
    1.31 +
    1.32 +var childID = null;
    1.33 +
    1.34 +var cleanedUp = false;
    1.35 +function cleanUp()
    1.36 +{
    1.37 +  if (cleanedUp) {
    1.38 +    return;
    1.39 +  }
    1.40 +
    1.41 +  cleanedUp = true;
    1.42 +
    1.43 +  if (preallocationEnabledPref === null) {
    1.44 +    SpecialPowers.clearUserPref('dom.ipc.processPrelaunch.enabled');
    1.45 +  } else {
    1.46 +    SpecialPowers.setBoolPref('dom.ipc.processPrelaunch.enabled',
    1.47 +                              preallocationEnabledPref);
    1.48 +  }
    1.49 +}
    1.50 +
    1.51 +// Even if this test times out, we still want to run cleanUp so as to set the
    1.52 +// pref back.
    1.53 +addEventListener('unload', cleanUp);
    1.54 +
    1.55 +function runTest()
    1.56 +{
    1.57 +  if (preallocationEnabledPref) {
    1.58 +    ok(false, "dom.ipc.processPrelaunch.enabled must be " +
    1.59 +              "false for this test to work.");
    1.60 +    SimpleTest.finish();
    1.61 +    return;
    1.62 +  }
    1.63 +
    1.64 +  // Ensure that the preallocated process initially gets BACKGROUND priority.
    1.65 +  // That's it.
    1.66 +  expectProcessCreated().then(function(childID) {
    1.67 +    return expectPriorityChange(childID, 'PREALLOC', 'CPU_LOW');
    1.68 +  }).then(function() {
    1.69 +    // We need to set the pref asynchoronously or the preallocated process won't
    1.70 +    // be shut down.
    1.71 +    SimpleTest.executeSoon(function(){
    1.72 +      cleanUp();
    1.73 +      SimpleTest.finish();
    1.74 +    });
    1.75 +  });
    1.76 +
    1.77 +  // Setting this pref to true should cause us to prelaunch a process.
    1.78 +  SpecialPowers.setBoolPref('dom.ipc.processPrelaunch.enabled', true);
    1.79 +}
    1.80 +
    1.81 +addEventListener('testready', runTest);
    1.82 +</script>
    1.83 +</body>
    1.84 +</html>

mercurial