Bug 892371 - Add mochitests covering LRU priority adjustments for both foreground and background processes. r=khuey
authorGabriele Svelto <gsvelto@mozilla.com>
Tue, 10 Mar 2015 21:28:05 +0100
changeset 233372 a30c985bc8dd336683b1b65d672b08577909f89d
parent 233371 908eaacff6f499831472cfb923d91afd8b2e3d0b
child 233373 d34f33fae4e8b5deeb2938e5a81338f6aa69b2c8
push id28410
push userryanvm@gmail.com
push dateThu, 12 Mar 2015 22:06:36 +0000
treeherdermozilla-central@42afc7ef5ccb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs892371
milestone39.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 892371 - Add mochitests covering LRU priority adjustments for both foreground and background processes. r=khuey
dom/browser-element/mochitest/browserElementTestHelpers.js
dom/browser-element/mochitest/priority/mochitest.ini
dom/browser-element/mochitest/priority/test_BackgroundLRU.html
dom/browser-element/mochitest/priority/test_ForegroundLRU.html
--- a/dom/browser-element/mochitest/browserElementTestHelpers.js
+++ b/dom/browser-element/mochitest/browserElementTestHelpers.js
@@ -46,16 +46,17 @@ const browserElementTestHelpers = {
       this._firedTestReady = true;
       dispatchEvent(new Event("testready"));
     }
   },
 
   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]
     );
   },
 
   setEnabledPref: function(value) {
     this._setPref('dom.mozBrowserFramesEnabled', value);
   },
@@ -183,37 +184,46 @@ function expectPriorityChange(childID, e
           reject();
         }
       }
     );
   });
 }
 
 // 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();
         }
       }
     );
   });
 }
--- a/dom/browser-element/mochitest/priority/mochitest.ini
+++ b/dom/browser-element/mochitest/priority/mochitest.ini
@@ -9,16 +9,17 @@ skip-if = toolkit != "gtk2" || ((buildap
 [test_Simple.html]
 [test_Visibility.html]
 [test_HighPriority.html]
 support-files = file_HighPriority.html
 [test_Background.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
 [test_Preallocated.html]
 disabled = bug 968604, bug 987164
 [test_ExpectingSystemMessage.html]
 [test_ExpectingSystemMessage2.html]
 [test_NestedFrames.html]
--- a/dom/browser-element/mochitest/priority/test_BackgroundLRU.html
+++ b/dom/browser-element/mochitest/priority/test_BackgroundLRU.html
@@ -41,29 +41,32 @@ function runTest() {
     iframe2 = document.createElement('iframe');
     iframe2.setAttribute('mozbrowser', true);
     iframe2.setAttribute('mozapp', 'http://example.org/manifest.webapp');
     iframe2.src = browserElementTestHelpers.emptyPage1;
 
     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();
   });
 
   document.body.appendChild(iframe1);
 }
 
 addEventListener('testready', runTest);
 
new file mode 100644
--- /dev/null
+++ b/dom/browser-element/mochitest/priority/test_ForegroundLRU.html
@@ -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>