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

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 Test that high-priority processes downgrade the CPU priority of regular
     5 processes.
     7 This is just like test_HighPriorityDowngrade, except instead of waiting for the
     8 high-priority process's wake lock to expire, we kill the process by removing
     9 its iframe from the DOM.
    10 -->
    11 <head>
    12   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    13   <script type="application/javascript" src="../browserElementTestHelpers.js"></script>
    14   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    15 </head>
    16 <body>
    18 <script type="application/javascript;version=1.7">
    19 "use strict";
    21 SimpleTest.waitForExplicitFinish();
    22 browserElementTestHelpers.setEnabledPref(true);
    23 browserElementTestHelpers.addPermission();
    24 browserElementTestHelpers.enableProcessPriorityManager();
    25 SpecialPowers.addPermission("embed-apps", true, document);
    27 function runTest() {
    28   var iframe = document.createElement('iframe');
    29   iframe.setAttribute('mozbrowser', true);
    31   iframe.src = browserElementTestHelpers.emptyPage1;
    33   var highPriorityIframe = null;
    34   var childID = null;
    36   expectProcessCreated().then(function(chid) {
    37     childID = chid;
    38     return expectPriorityChange(childID, 'FOREGROUND', 'CPU_NORMAL');
    39   }).then(function() {
    40     // Create a new, high-priority iframe.
    41     highPriorityIframe = document.createElement('iframe');
    42     highPriorityIframe.setAttribute('mozbrowser', true);
    43     highPriorityIframe.setAttribute('expecting-system-message', true);
    44     highPriorityIframe.setAttribute('mozapptype', 'critical');
    45     highPriorityIframe.setAttribute('mozapp', 'http://example.org/manifest.webapp');
    46     highPriorityIframe.src = browserElementTestHelpers.emptyPage2;
    48     var p = Promise.all(
    49       [expectPriorityChange(childID, 'FOREGROUND', 'CPU_LOW'),
    50        expectMozbrowserEvent(highPriorityIframe, 'loadend')]
    51     );
    53     document.body.appendChild(highPriorityIframe);
    55     return p;
    56   }).then(function() {
    57     // Killing the high-priority iframe should cause our CPU priority to go back
    58     // up to regular.
    59     var p = expectPriorityChange(childID, 'FOREGROUND', 'CPU_NORMAL');
    60     document.body.removeChild(highPriorityIframe);
    61     return p;
    62   }).then(SimpleTest.finish);
    64   document.body.appendChild(iframe);
    65 }
    67 addEventListener('testready', function() {
    68   // Cause the CPU wake lock taken on behalf of the high-priority process never
    69   // to time out during this test.
    70   SpecialPowers.pushPrefEnv(
    71     {set: [["dom.ipc.systemMessageCPULockTimeoutSec", 1000]]},
    72     runTest);
    73 });
    75 </script>
    76 </body>
    77 </html>

mercurial