Commit 6d981635 authored by Noemi Erli's avatar Noemi Erli
Browse files

Backed out 2 changesets (bug 1744942) for causing failures in...

Backed out 2 changesets (bug 1744942) for causing failures in browser_resources_sources.js CLOSED TREE

Backed out changeset 7cf66bf11b1b (bug 1744942)
Backed out changeset d42bdc0b8496 (bug 1744942)
parent 8cd9308e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ skip-if = os == "win"
[browser_dbg-scopes.js]
[browser_dbg-chrome-create.js]
skip-if = (verify && !debug && (os == 'linux'))
[browser_dbg-chrome-debugging.js]
[browser_dbg-command-click.js]
[browser_dbg-console.js]
[browser_dbg-console-async.js]
+63 −0
Original line number Diff line number Diff line
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */

/**
 * Tests that chrome debugging works.
 */

add_task(async function() {
  const client = initDevToolsClient();

  const [type] = await client.connect();
  is(type, "browser", "Root actor should identify itself as a browser.");

  const descriptorFront = await client.mainRoot.getMainProcess();
  const front = await descriptorFront.getTarget();
  const threadFront = await front.attachThread();

  gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, "about:mozilla");

  // listen for a new source and global
  const onFooDotComNewSource = new Promise(resolve => {
    function onNewSource(packet) {
      if (packet.source.url == "http://foo.com/") {
        threadFront.off("newSource", onNewSource);
        resolve(packet);
      }
    }
    threadFront.on("newSource", onNewSource);
  });

  // Force the creation of a new privileged source
  const systemPrincipal = Cc["@mozilla.org/systemprincipal;1"].createInstance(
    Ci.nsIPrincipal
  );
  const sandbox = Cu.Sandbox(systemPrincipal);
  Cu.evalInSandbox("function foo() {}", sandbox, null, "http://foo.com");

  const packet = await onFooDotComNewSource;
  ok(true, "Received the custom script source: " + packet.source.url);

  await client.close();
});

function initDevToolsClient() {
  const { DevToolsLoader } = ChromeUtils.import(
    "resource://devtools/shared/loader/Loader.jsm"
  );
  const customLoader = new DevToolsLoader({
    invisibleToDebugger: true,
  });
  const { DevToolsServer } = customLoader.require(
    "devtools/server/devtools-server"
  );
  const { DevToolsClient } = require("devtools/client/devtools-client");

  DevToolsServer.init();
  DevToolsServer.registerAllActors();
  DevToolsServer.allowChromeProcess = true;

  const transport = DevToolsServer.connectPipe();
  return new DevToolsClient(transport);
}
+7 −27
Original line number Diff line number Diff line
@@ -126,17 +126,14 @@ exports.CommandsFactory = {
  },

  /**
   * This method will spawn a special `DevToolsClient`
   * which is meant to debug the same Firefox instance
   * and especially be able to debug chrome code.
   * The chrome code typically runs in the system principal.
   * This principal is a singleton which is shared among most Firefox internal codebase
   * (JSM, privileged html documents, JS-XPCOM,...)
   * In order to be able to debug these script we need to connect to a special DevToolsServer
   * that runs in a dedicated and distinct system principal which is different from
   * the one shared with the rest of Firefox frontend codebase.
   * One method to handle the whole setup sequence to connect to RDP backend for the Browser Console.
   *
   * This will instantiate a special DevTools module loader for the DevToolsServer.
   * Then spawn a DevToolsClient to connect to it.
   * Get a Main Process Descriptor from it.
   * Finally spawn a commands object for this descriptor.
   */
  async spawnClientToDebugSystemPrincipal() {
  async forBrowserConsole() {
    // The Browser console ends up using the debugger in autocomplete.
    // Because the debugger can't be running in the same compartment than its debuggee,
    // we have to load the server in a dedicated Loader, flagged with
@@ -164,23 +161,6 @@ exports.CommandsFactory = {
    const client = new DevToolsClient(customDevToolsServer.connectPipe());
    await client.connect();

    return client;
  },

  /**
   * One method to handle the whole setup sequence to connect to RDP backend for the Browser Console.
   *
   * This will instantiate a special DevTools module loader for the DevToolsServer.
   * Then spawn a DevToolsClient to connect to it.
   * Get a Main Process Descriptor from it.
   * Finally spawn a commands object for this descriptor.
   */
  async forBrowserConsole() {
    // The Browser console ends up using the debugger in autocomplete.
    // Because the debugger can't be running in the same compartment than its debuggee,
    // we have to load the server in a dedicated Loader and so spawn a special client
    const client = await this.spawnClientToDebugSystemPrincipal();

    const descriptor = await client.mainRoot.getMainProcess();

    // Hack something in order to help TargetMixinFront to distinguish the BrowserConsole
+0 −67
Original line number Diff line number Diff line
@@ -279,73 +279,6 @@ add_task(async function testGarbagedCollectedSources() {
  });
});

/**
 * Assert that evaluating sources for a new global, in the parent process
 * using the shared system principal will spawn SOURCE resources.
 *
 * For this we use a special `commands` which replicate what browser console
 * and toolbox use.
 */
add_task(async function testParentProcessPrivilegedSources() {
  // Use a custom loader + server + client in order to spawn the server
  // in a distinct system compartment, so that it can see the system compartment
  // sandbox we are about to create in this test
  const client = await CommandsFactory.spawnClientToDebugSystemPrincipal();

  const commands = await CommandsFactory.forMainProcess({ client });
  await commands.targetCommand.startListening();
  const { resourceCommand } = commands;

  info("Check already available resources");
  const availableResources = [];
  await resourceCommand.watchResources([resourceCommand.TYPES.SOURCE], {
    onAvailable: resources => availableResources.push(...resources),
  });
  ok(
    availableResources.length > 0,
    "We get many sources reported from a multiprocess command"
  );

  // Clear the list of sources
  availableResources.length = 0;

  // Force the creation of a new privileged source
  const systemPrincipal = Cc["@mozilla.org/systemprincipal;1"].createInstance(
    Ci.nsIPrincipal
  );
  const sandbox = Cu.Sandbox(systemPrincipal);
  Cu.evalInSandbox("function foo() {}", sandbox, null, "http://foo.com");

  info("Wait for the sandbox source");
  await waitFor(() => {
    return availableResources.some(
      resource => resource.url == "http://foo.com/"
    );
  });

  const expectedResources = [
    {
      description: "privileged sandbox script",
      sourceForm: {
        introductionType: undefined,
        sourceMapBaseURL: "http://foo.com/",
        url: "http://foo.com/",
        isBlackBoxed: false,
        sourceMapURL: null,
        extensionName: null,
      },
      sourceContent: {
        contentType: "text/javascript",
        source: "function foo() {}",
      },
    },
  ];
  const matchingResource = availableResources.filter(resource =>
    resource.url.includes("http://foo.com")
  );
  await assertResources(matchingResource, expectedResources);
});

async function assertResources(resources, expected) {
  is(
    resources.length,