Commit acb92056 authored by Alexandre Poirot's avatar Alexandre Poirot
Browse files

Bug 1778803 - [devtools] Fix browser_target_command_scope_flag.js...

Bug 1778803 - [devtools] Fix browser_target_command_scope_flag.js intermittent. r=devtools-reviewers,nchevobbe

It is always tricky to test the Browser Toolbox codepaths as you may have various targets
related to previous test/tasks which are being destroyed in middle of the test.
Here some target related to previous task were removed in middle of this assertion.

It is better to test for actual deterministic content we are expecting rather than counting targets.

Differential Revision: https://phabricator.services.mozilla.com/D210668
parent ae80322d
Loading
Loading
Loading
Loading
+34 −26
Original line number Original line Diff line number Diff line
@@ -77,10 +77,10 @@ add_task(async function () {
    }
    }
  }
  }


  const newTabProcessID =
  const firstTabProcessID =
    gBrowser.selectedTab.linkedBrowser.browsingContext.currentWindowGlobal
    gBrowser.selectedTab.linkedBrowser.browsingContext.currentWindowGlobal
      .osPid;
      .osPid;
  const newTabInnerWindowId =
  const firstTabInnerWindowId =
    gBrowser.selectedTab.linkedBrowser.browsingContext.currentWindowGlobal
    gBrowser.selectedTab.linkedBrowser.browsingContext.currentWindowGlobal
      .innerWindowId;
      .innerWindowId;


@@ -89,7 +89,7 @@ add_task(async function () {
    [...targets].find(
    [...targets].find(
      target =>
      target =>
        target.targetType == TYPES.PROCESS &&
        target.targetType == TYPES.PROCESS &&
        target.processID == newTabProcessID
        target.processID == firstTabProcessID
    )
    )
  );
  );


@@ -98,12 +98,10 @@ add_task(async function () {
    [...targets].find(
    [...targets].find(
      target =>
      target =>
        target.targetType == TYPES.FRAME &&
        target.targetType == TYPES.FRAME &&
        target.innerWindowId == newTabInnerWindowId
        target.innerWindowId == firstTabInnerWindowId
    )
    )
  );
  );


  let multiprocessTargetCount = targets.size;

  info("Disable multiprocess debugging");
  info("Disable multiprocess debugging");
  await pushPref("devtools.browsertoolbox.scope", "parent-process");
  await pushPref("devtools.browsertoolbox.scope", "parent-process");


@@ -133,6 +131,12 @@ add_task(async function () {
    url: TEST_URL,
    url: TEST_URL,
    forceNewProcess: true,
    forceNewProcess: true,
  });
  });
  const secondTabProcessID =
    gBrowser.selectedTab.linkedBrowser.browsingContext.currentWindowGlobal
      .osPid;
  const secondTabInnerWindowId =
    gBrowser.selectedTab.linkedBrowser.browsingContext.currentWindowGlobal
      .innerWindowId;


  await wait(1000);
  await wait(1000);
  is(
  is(
@@ -144,33 +148,37 @@ add_task(async function () {
  info("Re-enable multiprocess debugging");
  info("Re-enable multiprocess debugging");
  await pushPref("devtools.browsertoolbox.scope", "everything");
  await pushPref("devtools.browsertoolbox.scope", "everything");


  // The second tab relates to one content process target and one window global target
  await waitFor(() => {
  multiprocessTargetCount += 2;
    return [...targets].some(
      target =>
        target.targetType == TYPES.PROCESS &&
        target.processID == firstTabProcessID
    );
  }, "Wait for the first tab content process target to be available again");


  await waitFor(
  await waitFor(() => {
    () => targets.size == multiprocessTargetCount,
    return [...targets].some(
    "Wait for all targets we used to have before disable multiprocess debugging"
      target =>
        target.targetType == TYPES.FRAME &&
        target.innerWindowId == firstTabInnerWindowId
    );
    );
  }, "Wait for the first tab frame target to be available again");


  info("Wait for the tab content process target to be available again");
  await waitFor(() => {
  ok(
    return [...targets].some(
    [...targets].some(
      target =>
      target =>
        target.targetType == TYPES.PROCESS &&
        target.targetType == TYPES.PROCESS &&
        target.processID == newTabProcessID
        target.processID == secondTabProcessID
    ),
    "We have the tab content process target"
    );
    );
  }, "Wait for the second tab content process target to be available again");


  info("Wait for the tab window global target to be available again");
  await waitFor(() => {
  ok(
    return [...targets].some(
    [...targets].some(
      target =>
      target =>
        target.targetType == TYPES.FRAME &&
        target.targetType == TYPES.FRAME &&
        target.innerWindowId == newTabInnerWindowId
        target.innerWindowId == secondTabInnerWindowId
    ),
    "We have the tab window global target"
    );
    );
  }, "Wait for the second tab frame target to be available again");


  info("Open a third tab in a new content process");
  info("Open a third tab in a new content process");
  await BrowserTestUtils.openNewForegroundTab({
  await BrowserTestUtils.openNewForegroundTab({