Bug 1438508 - Allows running brower_browser_toolbox_debugger.js more than once. r=jryans draft
authorAlexandre Poirot <poirot.alex@gmail.com>
Wed, 14 Feb 2018 09:54:03 -0800
changeset 755634 72feb314698dbe56366b3dddd1505bae531e53d8
parent 755632 4ce28c80ecb8312bf5b9038a4d5ef3b1038ee8d9
push id99224
push userbmo:poirot.alex@gmail.com
push dateThu, 15 Feb 2018 16:10:56 +0000
reviewersjryans
bugs1438508
milestone60.0a1
Bug 1438508 - Allows running brower_browser_toolbox_debugger.js more than once. r=jryans The sandbox used in this test isn't immediately destroyed when the test finishes. So use a unique file name to always refer to the expected sandbox/file in this debugger test. MozReview-Commit-ID: FJYXPN0RQS2
devtools/client/framework/test/browser_browser_toolbox_debugger.js
devtools/client/framework/test/test_browser_toolbox_debugger.js
--- a/devtools/client/framework/test/browser_browser_toolbox_debugger.js
+++ b/devtools/client/framework/test/browser_browser_toolbox_debugger.js
@@ -27,20 +27,27 @@ add_task(function* runTest() {
       // On debug test runner, it takes more than the default time (20s)
       // to get a initialized console
       ["devtools.debugger.remote-timeout", 120000]
     ]};
     SpecialPowers.pushPrefEnv(options, done);
   });
 
   let s = Cu.Sandbox("http://mozilla.org");
+
+  // Use a unique id for the fake script name in order to be able to run
+  // this test more than once. That's because the Sandbox is not immediately
+  // destroyed and so the debugger would display only one file but not necessarily
+  // connected to the latest sandbox.
+  let id = new Date().getTime();
+
   // Pass a fake URL to evalInSandbox. If we just pass a filename,
   // Debugger is going to fail and only display root folder (`/`) listing.
   // But it won't try to fetch this url and use sandbox content as expected.
-  let testUrl = "http://mozilla.org/browser-toolbox-test.js";
+  let testUrl = `http://mozilla.org/browser-toolbox-test-${id}.js`;
   Cu.evalInSandbox("(" + function () {
     this.plop = function plop() {
       return 1;
     };
   } + ").call(this)", s, "1.8", testUrl, 0);
 
   // Execute the function every second in order to trigger the breakpoint
   let interval = setInterval(s.plop, 1000);
@@ -112,17 +119,17 @@ add_task(function* runTest() {
   // We remove its import of shared-head, which isn't available in browser toolbox process
   // And isn't needed thanks to testHead's symbols
   debuggerHead = debuggerHead.replace(/Services.scriptloader.loadSubScript[^\)]*\);/, "");
 
   // Finally, fetch the debugger test script that is going to be execute in the browser
   // toolbox process
   let testScript = (yield fetch(testScriptURL)).content;
   let source =
-    "try {" + testHead + debuggerHead + testScript + "} catch (e) {" +
+    "try { let testUrl = \""+testUrl+"\";" + testHead + debuggerHead + testScript + "} catch (e) {" +
     "  dump('Exception: '+ e + ' at ' + e.fileName + ':' + " +
     "       e.lineNumber + '\\nStack: ' + e.stack + '\\n');" +
     "}";
   env.set("MOZ_TOOLBOX_TEST_SCRIPT", source);
   registerCleanupFunction(() => {
     env.set("MOZ_TOOLBOX_TEST_SCRIPT", "");
   });
 
--- a/devtools/client/framework/test/test_browser_toolbox_debugger.js
+++ b/devtools/client/framework/test/test_browser_toolbox_debugger.js
@@ -1,14 +1,12 @@
 /* global toolbox */
 
 info(`START: ${new Error().lineNumber}`);
 
-let testUrl = "http://mozilla.org/browser-toolbox-test.js";
-
 Task.spawn(function* () {
   Services.prefs.clearUserPref("devtools.debugger.tabs")
   Services.prefs.clearUserPref("devtools.debugger.pending-selected-location")
 
   info("Waiting for debugger load");
   yield toolbox.selectTool("jsdebugger");
   let dbg = createDebuggerContext(toolbox);
   let window = dbg.win;
@@ -19,35 +17,38 @@ Task.spawn(function* () {
 
   info("Loaded, selecting the test script to debug");
   // First expand the domain
   let domain = [...document.querySelectorAll(".tree-node")].find(node => {
     return node.textContent.trim() == "mozilla.org";
   });
   let arrow = domain.querySelector(".arrow");
   arrow.click();
+
+  let fileName = testUrl.match(/browser-toolbox-test.*\.js/)[0];
+
   let script = [...document.querySelectorAll(".tree-node")].find(node => {
-    return node.textContent.includes("browser-toolbox-test.js");
+    return node.textContent.includes(fileName);
   });
   script = script.querySelector(".node");
   script.click();
 
   let onPaused = waitForPaused(dbg);
-  yield addBreakpoint(dbg, "browser-toolbox-test.js", 2);
+  yield addBreakpoint(dbg, fileName, 2);
 
   yield onPaused;
 
-  assertPausedLocation(dbg, "browser-toolbox-test.js", 2);
+  assertPausedLocation(dbg, fileName, 2);
 
   yield stepIn(dbg);
 
-  assertPausedLocation(dbg, "browser-toolbox-test.js", 3);
+  assertPausedLocation(dbg, fileName, 3);
 
   // Remove the breakpoint before resuming in order to prevent hitting the breakpoint
   // again during test closing.
-  let source = findSource(dbg, "browser-toolbox-test.js");
+  let source = findSource(dbg, fileName);
   yield removeBreakpoint(dbg, source.id, 2);
 
   yield resume(dbg);
 
   info("Close the browser toolbox");
   toolbox.destroy();
 });