Commit d99b4a41 authored by Noemi Erli's avatar Noemi Erli
Browse files

Backed out 2 changesets (bug 1743044) for causing failures in browser_resources_sources.js

Backed out changeset dd0d0dabb482 (bug 1743044)
Backed out changeset 1ec7edd8a8e6 (bug 1743044)
parent 854a806a
Loading
Loading
Loading
Loading
+6 −10
Original line number Diff line number Diff line
@@ -28,6 +28,9 @@ const {
const {
  WatchpointMap,
} = require("devtools/server/actors/utils/watchpoint-map");
const {
  getDebuggerSourceURL,
} = require("devtools/server/actors/utils/source-url");

const { logEvent } = require("devtools/server/actors/utils/logEvent");

@@ -1437,16 +1440,9 @@ const ThreadActor = ActorClassWithSpec(threadSpec, {
    for (const source of sources) {
      this._addSource(source);

      // The following check should match the filtering done by `findSourceURLs`:
      // https://searchfox.org/mozilla-central/rev/ac7a567f036e1954542763f4722fbfce041fb752/js/src/debugger/Debugger.cpp#2406-2409
      // Otherwise we may populate `urlMap` incorrectly and resurrect sources that weren't GCed,
      // and spawn duplicated SourceActors/Debugger.Source for the same actual source.
      // `findSourceURLs` uses !introductionScript check as that allows to identify <script>'s
      // loaded from the HTML page. This boolean will be defined only when the <script> tag
      // is added by Javascript code at runtime.
      // https://searchfox.org/mozilla-central/rev/3d03a3ca09f03f06ef46a511446537563f62a0c6/devtools/docs/user/debugger-api/debugger.source/index.rst#113
      if (!source.introductionScript) {
        urlMap[source.url]--;
      const url = getDebuggerSourceURL(source);
      if (url) {
        urlMap[url]--;
      }
    }

+13 −116
Original line number Diff line number Diff line
@@ -4,9 +4,6 @@
"use strict";

// Test the ResourceCommand API around SOURCE.
//
// We cover each Spidermonkey Debugger Source's `introductionType`:
// https://searchfox.org/mozilla-central/rev/4c184ca81b28f1ccffbfd08f465709b95bcb4aa1/js/src/doc/Debugger/Debugger.Source.md#172-213

const ResourceCommand = require("devtools/shared/commands/resource/resource-command");

@@ -34,15 +31,7 @@ add_task(async function() {
      targets.push(targetFront);
    },
  });
  if (isEveryFrameTargetEnabled()) {
    is(targets.length, 4, "Got expected number of targets");
  } else {
    is(
      targets.length,
      3,
      "Got expected number of targets (without fission, nor EFT)"
    );
  }
  is(targets.length, 3, "Got expected number of targets");

  info("Check already available resources");
  const availableResources = [];
@@ -52,77 +41,26 @@ add_task(async function() {

  const expectedExistingResources = [
    {
      description: "eval",
      sourceForm: {
        introductionType: "eval",
        sourceMapBaseURL:
          "https://example.com/browser/devtools/shared/commands/resource/tests/sources.html",
        url: null,
        isBlackBoxed: false,
        sourceMapURL: null,
        extensionName: null,
      },
      sourceContent: {
        contentType: "text/javascript",
        source: "this.global = function evalFunction() {}",
      },
    },
    {
      description: "new Function()",
      sourceForm: {
        introductionType: "Function",
        sourceMapBaseURL:
          "https://example.com/browser/devtools/shared/commands/resource/tests/sources.html",
        url: null,
        isBlackBoxed: false,
        sourceMapURL: null,
        extensionName: null,
      },
      sourceContent: {
        contentType: "text/javascript",
        source: "return 42;",
      },
    },
    {
      description: "DOM Timer",
      sourceForm: {
        introductionType: "domTimer",
        sourceMapBaseURL:
          "https://example.com/browser/devtools/shared/commands/resource/tests/sources.html",
        url: null,
        isBlackBoxed: false,
        sourceMapURL: null,
        extensionName: null,
      },
      sourceContent: {
        contentType: "text/javascript",
        /* the domTimer is prefixed by many empty lines in order to be positioned at the same line
           as in the HTML file where setTimeout is called.
           This is probably done by SourceActor.actualText().
           So the array size here, should be updated to match the line number of setTimeout call */
        source: new Array(39).join("\n") + `console.log("timeout")`,
      },
    },
    {
      description: "Event Handler",
      description: "independent js file",
      sourceForm: {
        introductionType: "eventHandler",
        introductionType: "scriptElement",
        sourceMapBaseURL:
          "https://example.com/browser/devtools/shared/commands/resource/tests/sources.html",
        url: null,
          "https://example.com/browser/devtools/shared/commands/resource/tests/sources.js",
        url:
          "https://example.com/browser/devtools/shared/commands/resource/tests/sources.js",
        isBlackBoxed: false,
        sourceMapURL: null,
        extensionName: null,
      },
      sourceContent: {
        contentType: "text/javascript",
        source: "console.log('link')",
        source: "/* eslint-disable */\nfunction scriptSource() {}\n",
      },
    },
    {
      description: "inline JS inserted at runtime",
      description: "eval",
      sourceForm: {
        introductionType: "scriptElement", // This is an injectedScript at SpiderMonkey level, but is translated into scriptElement by SourceActor.form()
        introductionType: "eval",
        sourceMapBaseURL:
          "https://example.com/browser/devtools/shared/commands/resource/tests/sources.html",
        url: null,
@@ -132,13 +70,13 @@ add_task(async function() {
      },
      sourceContent: {
        contentType: "text/javascript",
        source: "console.log('inline-script')",
        source: "this.global = function evalFunction() {}",
      },
    },
    {
      description: "inline JS",
      sourceForm: {
        introductionType: "scriptElement", // This is an inlineScript at SpiderMonkey level, but is translated into scriptElement by SourceActor.form()
        introductionType: "scriptElement",
        sourceMapBaseURL:
          "https://example.com/browser/devtools/shared/commands/resource/tests/sources.html",
        url:
@@ -186,49 +124,7 @@ add_task(async function() {
        source: "/* eslint-disable */\nfunction serviceWorkerSource() {}\n",
      },
    },
    {
      description: "independent js file",
      sourceForm: {
        introductionType: "scriptElement", // This is an srcScript at SpiderMonkey level, but is translated into scriptElement by SourceActor.form()
        sourceMapBaseURL:
          "https://example.com/browser/devtools/shared/commands/resource/tests/sources.js",
        url:
          "https://example.com/browser/devtools/shared/commands/resource/tests/sources.js",
        isBlackBoxed: false,
        sourceMapURL: null,
        extensionName: null,
      },
      sourceContent: {
        contentType: "text/javascript",
        source: "/* eslint-disable */\nfunction scriptSource() {}\n",
      },
    },
    {
      description: "javascript URL",
      sourceForm: {
        introductionType: "javascriptURL",
        sourceMapBaseURL: isEveryFrameTargetEnabled()
          ? "about:blank"
          : "https://example.com/browser/devtools/shared/commands/resource/tests/sources.html",
        url: null,
        isBlackBoxed: false,
        sourceMapURL: null,
        extensionName: null,
      },
      sourceContent: {
        contentType: "text/javascript",
        source: "666",
      },
    },
  ];

  // Some sources may be created after the document is done loading (like eventHandler usecase)
  // so we may be received *after* watchResource resolved
  await waitFor(
    () => availableResources.length >= expectedExistingResources.length,
    "Got all the sources"
  );

  await assertResources(availableResources, expectedExistingResources);

  await targetCommand.stopListening();
@@ -253,6 +149,8 @@ async function assertResources(resources, expected) {
}

async function assertResource(source, expected) {
  info(`Checking resource "#${expected.description}"`);

  is(
    source.resourceType,
    ResourceCommand.TYPES.SOURCE,
@@ -275,7 +173,6 @@ async function assertResource(source, expected) {
    matchingExpected,
    `This source was expected with source content being "${sourceContent.source}"`
  );
  info(`Found "#${matchingExpected.description}"`);
  assertObject(
    sourceContent,
    matchingExpected.sourceContent,
+1 −30
Original line number Diff line number Diff line
@@ -6,46 +6,17 @@
    <meta charset="utf-8"/>
  </head>
  <body>
    <!-- introductionType=eventHandler -->
    <div onclick="console.log('link')">link</div>

    <!-- introductionType=inlineScript mapped to scriptElement -->
    <script type="text/javascript">
      "use strict";
      /* eslint-disable */
      function inlineSource() {}

      // introductionType=eval
      // Assign it to a global in order to avoid it being GCed
      eval("this.global = function evalFunction() {}");

      // introductionType=Function
      // Also assign to a global to avoid being GCed
      this.global2 = new Function("return 42;");

      // introductionType=injectedScript mapped to scriptElement
      const script = document.createElement("script");
      script.textContent = "console.log('inline-script')";
      document.documentElement.appendChild(script);

      // introductionType=Worker, but ends up being null on SourceActor's form
      // Assign the worker to a global variable in order to avoid
      // having it be GCed.
      this.worker = new Worker("worker-sources.js");

      window.registrationPromise = navigator.serviceWorker.register("service-worker-sources.js");

      // introductionType=domTimer
      setTimeout(`console.log("timeout")`, 0);

      // introductionType=eventHandler
      window.addEventListener("DOMContentLoaded", () => {
        document.querySelector("div[onclick]").click();
      });
    </script>
    <!-- introductionType=srcScript mapped to scriptElement -->
     <script src="sources.js"></script>
    <!-- introductionType=javascriptURL -->
    <iframe src="javascript:666"></iframe>
  </body>
</html>