Bug 1528276 - Add test for DebuggerServer.keepAlive;r=ochameau a=lizzard
authorJulian Descottes <jdescottes@mozilla.com>
Wed, 27 Feb 2019 17:08:43 +0000
changeset 516224 a8cd0839de6b06b2ed1c8fcf7bea7b2d1526574c
parent 516223 e089d94139746ea06377fb7f71df25e55e3edf69
child 516225 f50d84563bc574211361fca6fe90e67b0cdb8f14
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau, lizzard
bugs1528276
milestone66.0
Bug 1528276 - Add test for DebuggerServer.keepAlive;r=ochameau a=lizzard Depends on D20830 Differential Revision: https://phabricator.services.mozilla.com/D20831
devtools/server/tests/browser/browser_debugger_server.js
--- a/devtools/server/tests/browser/browser_debugger_server.js
+++ b/devtools/server/tests/browser/browser_debugger_server.js
@@ -1,59 +1,96 @@
 /* vim: set ft=javascript ts=2 et sw=2 tw=80: */
 /* Any copyright is dedicated to the Public Domain.
-   http://creativecommons.org/publicdomain/zero/1.0/ */
+ http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 // Test basic features of DebuggerServer
 
 add_task(async function() {
   // When running some other tests before, they may not destroy the main server.
   // Do it manually before running our tests.
   if (DebuggerServer.initialized) {
     DebuggerServer.destroy();
   }
 
   await testDebuggerServerInitialized();
+  await testDebuggerServerKeepAlive();
 });
 
 async function testDebuggerServerInitialized() {
   const browser = await addTab("data:text/html;charset=utf-8,foo");
   const tab = gBrowser.getTabForBrowser(browser);
 
   ok(!DebuggerServer.initialized,
-    "By default, the DebuggerServer isn't initialized in parent process");
-  await ContentTask.spawn(browser, null, function() {
-    const {require} = ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
-    const {DebuggerServer} = require("devtools/server/main");
-    ok(!DebuggerServer.initialized,
-      "By default, the DebuggerServer isn't initialized not in content process");
-  });
+     "By default, the DebuggerServer isn't initialized in parent process");
+  await assertServerInitialized(browser, false,
+    "By default, the DebuggerServer isn't initialized not in content process");
 
   const target = await TargetFactory.forTab(tab);
 
   ok(DebuggerServer.initialized,
-    "TargetFactory.forTab will initialize the DebuggerServer in parent process");
-  await ContentTask.spawn(browser, null, function() {
-    const {require} = ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
-    const {DebuggerServer} = require("devtools/server/main");
-    ok(DebuggerServer.initialized,
-      "TargetFactory.forTab will initialize the DebuggerServer in content process");
-  });
+     "TargetFactory.forTab will initialize the DebuggerServer in parent process");
+  await assertServerInitialized(browser, true,
+    "TargetFactory.forTab will initialize the DebuggerServer in content process");
 
   await target.destroy();
 
   // Disconnecting the client will remove all connections from both server,
   // in parent and content process. But only the one in the content process will be
   // destroyed.
   ok(DebuggerServer.initialized,
-    "Destroying the target doesn't destroy the DebuggerServer in the parent process");
-  await ContentTask.spawn(browser, null, function() {
+     "Destroying the target doesn't destroy the DebuggerServer in the parent process");
+  await assertServerInitialized(browser, false,
+    "But destroying the target ends up destroying the DebuggerServer in the content" +
+    " process");
+
+  gBrowser.removeCurrentTab();
+  DebuggerServer.destroy();
+}
+
+async function testDebuggerServerKeepAlive() {
+  const browser = await addTab("data:text/html;charset=utf-8,foo");
+  const tab = gBrowser.getTabForBrowser(browser);
+
+  await assertServerInitialized(browser, false, "Server not started in content process");
+
+  const target = await TargetFactory.forTab(tab);
+  await assertServerInitialized(browser, true, "Server started in content process");
+
+  info("Set DebuggerServer.keepAlive to true in the content process");
+  await setContentServerKeepAlive(browser, true);
+
+  info("Destroy the target, the content server should be kept alive");
+  await target.destroy();
+
+  await assertServerInitialized(browser, true, "Server still running in content process");
+
+  info("Set DebuggerServer.keepAlive back to false");
+  await setContentServerKeepAlive(browser, false);
+
+  info("Create and destroy a target again");
+  const newTarget = await TargetFactory.forTab(tab);
+  await newTarget.destroy();
+
+  await assertServerInitialized(browser, false, "Server stopped in content process");
+
+  gBrowser.removeCurrentTab();
+  DebuggerServer.destroy();
+}
+
+async function assertServerInitialized(browser, expected, message) {
+  const isInitialized = await ContentTask.spawn(browser, null, function() {
     const {require} = ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
     const {DebuggerServer} = require("devtools/server/main");
-    ok(!DebuggerServer.initialized,
-      "But destroying the target ends up destroying the DebuggerServer in the content" +
-      " process");
+    return DebuggerServer.initialized;
   });
+  is(isInitialized, expected, message);
+}
 
-  gBrowser.removeCurrentTab();
+async function setContentServerKeepAlive(browser, keepAlive, message) {
+  await ContentTask.spawn(browser, keepAlive, function(_keepAlive) {
+    const {require} = ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
+    const {DebuggerServer} = require("devtools/server/main");
+    DebuggerServer.keepAlive = _keepAlive;
+  });
 }