Commit 5b898ede authored by Rob Wu's avatar Rob Wu
Browse files

Bug 1482983 - Fix intermittent test failure in test_ext_webrequest_frameId.html r=rpl

The test was getting stuck because it was expecting a favicon.ico
request that never happened. The test logic was copied from
test_ext_webrequest_filter.html which suffers from exactly the same
issue. Since the favicon.ico test was meant to serve as a regression
test, this patch fixes only one of the two tests.

Differential Revision: https://phabricator.services.mozilla.com/D174505
parent 5b6cd149
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -325,7 +325,6 @@ skip-if =
 os == 'android' && debug || tsan # bug 1452348. tsan: bug 1612707
 os == 'linux' && bits == 64 && !debug && xorigin # Bug 1756023
[test_ext_webrequest_frameId.html]
skip-if = os == 'linux' # Bug 1482983 caused by Bug 1480951
[test_ext_webrequest_getSecurityInfo.html]
skip-if =
  http3
+16 −16
Original line number Diff line number Diff line
@@ -17,6 +17,12 @@ let extensionData = {
  },
  background() {
    browser.webRequest.onBeforeRequest.addListener(details => {
      if (details.url.endsWith("/favicon.ico")) {
        // We don't care about favicon.ico in this test. It is hard to control
        // whether the request happens.
        browser.test.log(`Ignoring favicon request: ${details.url}`);
        return;
      }
      browser.test.sendMessage("onBeforeRequest", details);
    }, {urls: ["<all_urls>"]}, ["blocking"]);

@@ -116,21 +122,7 @@ let expected = {
  },
};

if (AppConstants.platform != "android") {
  expected["favicon.ico"] = {
    type: "image",
    toplevel: true,
    origin: "file_simple_xhr.html",
    cached: false,
  };
}

function checkDetails(details) {
  // See bug 1471387
  if (details.originUrl == "about:newtab") {
    return;
  }

  let url = new URL(details.url);
  let filename = url.pathname.split("/").pop();
  ok(filename in expected, `Should be expecting a request for ${filename}`);
@@ -177,6 +169,7 @@ function checkDetails(details) {
    is(details.frameId, parent.subframeId, "expect load in subframe");
    is(details.parentFrameId, parent.parentId, "expect subframe parent");
  }
  return filename;
}

add_task(async function test_webRequest_main_frame() {
@@ -194,8 +187,15 @@ add_task(async function test_webRequest_main_frame() {
  let a = addLink(`file_simple_xhr.html?topframe=true&nocache=${Math.random()}`);
  a.click();

  for (let i = 0; i < Object.keys(expected).length; i++) {
    checkDetails(await extension.awaitMessage("onBeforeRequest"));
  let remaining = new Set(Object.keys(expected));
  let totalExpectedCount = remaining.size;
  for (let i = 0; i < totalExpectedCount; i++) {
    info(`Waiting for request ${i} out of ${totalExpectedCount}`);
    info(`Expecting one of: ${Array.from(remaining)}`);
    let details = await extension.awaitMessage("onBeforeRequest");
    info(`Checking details for request ${i}: ${JSON.stringify(details)}`);
    let filename = checkDetails(details);
    ok(remaining.delete(filename), `Got only one request for ${filename}`);
  }

  await extension.awaitMessage("tab-created");