Bug 1142229 - Part 1: Clean up and refactor test cases for the Nuwa process. r=mrbkap, a=bajaj
authorCervantes Yu <cyu@mozilla.com>
Thu, 09 Apr 2015 15:26:49 +0800
changeset 188815 b8551dbe2a7770ae75252bf229b555c58036cf6d
parent 188814 e2d1df868b7544a375a26d49cb1477a4896f6066
child 188816 3b992f3167108ed02dcdb3a27a829dcf74ecc8d8
push id857
push userryanvm@gmail.com
push dateFri, 10 Apr 2015 15:03:45 +0000
treeherdermozilla-b2g30_v1_4@0673402a88ac [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap, bajaj
bugs1142229
milestone30.0
Bug 1142229 - Part 1: Clean up and refactor test cases for the Nuwa process. r=mrbkap, a=bajaj
dom/ipc/PreallocatedProcessManager.cpp
dom/ipc/tests/test_NuwaProcessCreation.html
dom/ipc/tests/test_NuwaProcessDeadlock.html
--- a/dom/ipc/PreallocatedProcessManager.cpp
+++ b/dom/ipc/PreallocatedProcessManager.cpp
@@ -297,17 +297,17 @@ PreallocatedProcessManagerImpl::GetSpare
 /**
  * Publish a ContentParent to spare process list.
  */
 void
 PreallocatedProcessManagerImpl::PublishSpareProcess(ContentParent* aContent)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
-  if (Preferences::GetBool("dom.ipc.processPriorityManager.testMode")) {
+  if (Preferences::GetBool("dom.ipc.preallocatedProcessManager.testMode")) {
     AutoJSContext cx;
     nsCOMPtr<nsIMessageBroadcaster> ppmm =
       do_GetService("@mozilla.org/parentprocessmessagemanager;1");
     nsresult rv = ppmm->BroadcastAsyncMessage(
       NS_LITERAL_STRING("TEST-ONLY:nuwa-add-new-process"),
       JS::NullHandleValue, JS::NullHandleValue, cx, 1);
   }
 
@@ -351,17 +351,17 @@ PreallocatedProcessManagerImpl::IsNuwaRe
 
 void
 PreallocatedProcessManagerImpl::OnNuwaReady()
 {
   NS_ASSERTION(!mIsNuwaReady, "Multiple Nuwa processes created!");
   ProcessPriorityManager::SetProcessPriority(mPreallocatedAppProcess,
                                              hal::PROCESS_PRIORITY_MASTER);
   mIsNuwaReady = true;
-  if (Preferences::GetBool("dom.ipc.processPriorityManager.testMode")) {
+  if (Preferences::GetBool("dom.ipc.preallocatedProcessManager.testMode")) {
     AutoJSContext cx;
     nsCOMPtr<nsIMessageBroadcaster> ppmm =
       do_GetService("@mozilla.org/parentprocessmessagemanager;1");
     nsresult rv = ppmm->BroadcastAsyncMessage(
       NS_LITERAL_STRING("TEST-ONLY:nuwa-ready"),
       JS::NullHandleValue, JS::NullHandleValue, cx, 1);
   }
   NuwaFork();
--- a/dom/ipc/tests/test_NuwaProcessCreation.html
+++ b/dom/ipc/tests/test_NuwaProcessCreation.html
@@ -2,98 +2,66 @@
 <html>
 <!--
 Test if Nuwa process created successfully.
 -->
 <head>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
 </head>
-<body>
+<body onload="setup()">
 
 <script type="application/javascript;version=1.7">
 "use strict";
 
-SimpleTest.waitForExplicitFinish();
-
-function TestLoader() {}
-
-TestLoader.prototype = {
-  _waitingTask: 0,
-  onTestReady: null,
-  unlockTestReady: function() {
-    this._waitingTask--;
-    this._maybeLoadTest();
-  },
-  lockTestReady: function() {
-    this._waitingTask++;
-  },
-  _maybeLoadTest: function() {
-    if (this._waitingTask == 0) {
-      this.onTestReady();
-    }
-  }
-}
-
-var testLoader = new TestLoader();
-testLoader.lockTestReady();
-window.addEventListener('load', function() {
-  testLoader.unlockTestReady();
-});
-
-function setPref(pref, value) {
-  testLoader.lockTestReady();
-  if (value !== undefined && value !== null) {
-    SpecialPowers.pushPrefEnv({'set': [[pref, value]]}, function() { testLoader.unlockTestReady(); });
-  } else {
-    SpecialPowers.pushPrefEnv({'clear': [[pref]]}, function() { testLoader.unlockTestReady(); });
-  }
-}
-
-setPref('dom.ipc.processPriorityManager.testMode', true);
-setPref('dom.ipc.processPriorityManager.enabled', true);
-setPref('dom.ipc.processPriorityManager.backgroundLRUPoolLevels', 2);
-
 function runTest()
 {
-  // Shutdown preallocated process.
-  SpecialPowers.setBoolPref('dom.ipc.processPrelaunch.enabled', false);
+  info("Launch the Nuwa process");
   let cpmm = SpecialPowers.Cc["@mozilla.org/childprocessmessagemanager;1"]
                           .getService(SpecialPowers.Ci.nsISyncMessageSender);
   let seenNuwaReady = false;
   let msgHandler = {
     receiveMessage: function receiveMessage(msg) {
       msg = SpecialPowers.wrap(msg);
       if (msg.name == 'TEST-ONLY:nuwa-ready') {
         ok(true, "Got nuwa-ready");
         is(seenNuwaReady, false, "Already received nuwa ready");
         seenNuwaReady = true;
       } else if (msg.name == 'TEST-ONLY:nuwa-add-new-process') {
         ok(true, "Got nuwa-add-new-process");
         is(seenNuwaReady, true, "Receive nuwa-add-new-process before nuwa-ready");
-        testEnd();
+        shutdown();
       }
     }
   };
-  let timeout = setTimeout(function() {
-    ok(false, "Nuwa process is not launched");
-    testEnd();
-  }, 60000);
 
-  function testEnd() {
+  function shutdown() {
+    info("Shut down the test case");
     cpmm.removeMessageListener("TEST-ONLY:nuwa-ready", msgHandler);
     cpmm.removeMessageListener("TEST-ONLY:nuwa-add-new-process", msgHandler);
-    clearTimeout(timeout);
+
     SimpleTest.finish();
   }
 
   cpmm.addMessageListener("TEST-ONLY:nuwa-ready", msgHandler);
   cpmm.addMessageListener("TEST-ONLY:nuwa-add-new-process", msgHandler);
 
 
   // Setting this pref to true should cause us to prelaunch a process.
   SpecialPowers.setBoolPref('dom.ipc.processPrelaunch.enabled', true);
 }
 
-testLoader.onTestReady = runTest;
+function setup()
+{
+  info("Set up preferences for testing the Nuwa process.");
+  SimpleTest.waitForExplicitFinish();
+
+  SpecialPowers.pushPrefEnv({
+    'set': [
+      ['dom.ipc.processPrelaunch.enabled', false],
+      ['dom.ipc.preallocatedProcessManager.testMode', true]
+    ]
+  }, runTest);
+}
+
 </script>
 </body>
 </html>
--- a/dom/ipc/tests/test_NuwaProcessDeadlock.html
+++ b/dom/ipc/tests/test_NuwaProcessDeadlock.html
@@ -2,100 +2,67 @@
 <html>
 <!--
 Test if Nuwa process created successfully.
 -->
 <head>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
 </head>
-<body>
+<body onload="setup()">
 
 <script type="application/javascript;version=1.7">
 "use strict";
 
-SimpleTest.waitForExplicitFinish();
-
-function TestLoader() {}
-
-TestLoader.prototype = {
-  _waitingTask: 0,
-  onTestReady: null,
-  unlockTestReady: function() {
-    this._waitingTask--;
-    this._maybeLoadTest();
-  },
-  lockTestReady: function() {
-    this._waitingTask++;
-  },
-  _maybeLoadTest: function() {
-    if (this._waitingTask == 0) {
-      this.onTestReady();
-    }
-  }
-}
-
-var testLoader = new TestLoader();
-testLoader.lockTestReady();
-window.addEventListener('load', function() {
-  testLoader.unlockTestReady();
-});
-
-function setPref(pref, value) {
-  testLoader.lockTestReady();
-  if (value !== undefined && value !== null) {
-    SpecialPowers.pushPrefEnv({'set': [[pref, value]]}, function() { testLoader.unlockTestReady(); });
-  } else {
-    SpecialPowers.pushPrefEnv({'clear': [[pref]]}, function() { testLoader.unlockTestReady(); });
-  }
-}
-
-setPref('dom.ipc.processPriorityManager.testMode', true);
-setPref('dom.ipc.processPriorityManager.enabled', true);
-setPref('dom.ipc.processPriorityManager.backgroundLRUPoolLevels', 2);
-setPref('dom.ipc.processPrelaunch.testMode', true);  // For testing deadlock.
-
 function runTest()
 {
-  // Shutdown preallocated process.
-  SpecialPowers.setBoolPref('dom.ipc.processPrelaunch.enabled', false);
+  info("Launch the Nuwa process");
   let cpmm = SpecialPowers.Cc["@mozilla.org/childprocessmessagemanager;1"]
                           .getService(SpecialPowers.Ci.nsISyncMessageSender);
   let seenNuwaReady = false;
   let msgHandler = {
     receiveMessage: function receiveMessage(msg) {
       msg = SpecialPowers.wrap(msg);
       if (msg.name == 'TEST-ONLY:nuwa-ready') {
         ok(true, "Got nuwa-ready");
         is(seenNuwaReady, false, "Already received nuwa ready");
         seenNuwaReady = true;
       } else if (msg.name == 'TEST-ONLY:nuwa-add-new-process') {
         ok(true, "Got nuwa-add-new-process");
         is(seenNuwaReady, true, "Receive nuwa-add-new-process before nuwa-ready");
-        testEnd();
+        shutdown();
       }
     }
   };
-  let timeout = setTimeout(function() {
-    ok(false, "Nuwa process is not launched");
-    testEnd();
-  }, 90000);
 
-  function testEnd() {
+  function shutdown() {
+    info("Shut down the test case");
     cpmm.removeMessageListener("TEST-ONLY:nuwa-ready", msgHandler);
     cpmm.removeMessageListener("TEST-ONLY:nuwa-add-new-process", msgHandler);
-    clearTimeout(timeout);
-    setPref('dom.ipc.processPrelaunch.testMode', false);
+
     SimpleTest.finish();
   }
 
   cpmm.addMessageListener("TEST-ONLY:nuwa-ready", msgHandler);
   cpmm.addMessageListener("TEST-ONLY:nuwa-add-new-process", msgHandler);
 
 
   // Setting this pref to true should cause us to prelaunch a process.
   SpecialPowers.setBoolPref('dom.ipc.processPrelaunch.enabled', true);
 }
 
-testLoader.onTestReady = runTest;
+function setup()
+{
+  info("Set up preferences for testing deadlock in the Nuwa process.");
+  SimpleTest.waitForExplicitFinish();
+
+  SpecialPowers.pushPrefEnv({
+    'set': [
+      ['dom.ipc.processPrelaunch.enabled', false],
+      ['dom.ipc.preallocatedProcessManager.testMode', true],
+      ['dom.ipc.processPrelaunch.testMode', true]  // For testing deadlock
+    ]
+  }, runTest);
+}
+
 </script>
 </body>
 </html>