chromium/third_party/blink/web_tests/http/tests/inspector-protocol/issues/mixed-content-issue-creation-css.js

(async function(/** @type {import('test_runner').TestRunner} */ testRunner) {
  const {page, session, dp} = await testRunner.startBlank(
    `Verifies that mixed content issue is created from mixed content css.\n`);

  await dp.Network.enable();
  await dp.Audits.enable();

  let requestId;
  let frameId;
  let issues = [];
  let count = 0;
  let eventReceived = null;
  let allEventsReceived = new Promise(resolve => eventReceived = () => {if (++count == 3) resolve();
  });

  dp.Network.onRequestWillBeSent(event => {
    if (event.params.request.url === 'http://devtools.test:8000/inspector-protocol/resources/styles.css') {
      frameId = event.params.frameId;
      requestId = event.params.requestId;
      eventReceived();
    }
  });

  // We expect to receive two issues, one for a speculative prefetch and another for the actual fetch.
  dp.Audits.onIssueAdded(issue => {
    if (issue.params.issue.code !== 'MixedContentIssue') {
      return;
    }
    issues.push(issue.params);
    eventReceived();
  });

  await page.navigate('https://devtools.test:8443/inspector-protocol/resources/mixed-content-css.html');
  await allEventsReceived;

  // No sorting necessary, both issues are identical except requestId
  issues.forEach(issue => testRunner.log(issue, "Inspector issue: ", ["frameId", "requestId"]));

  const match = issues.find(issue =>
    issue.issue?.details?.mixedContentIssueDetails?.request?.requestId === requestId
    && issue.issue?.details?.mixedContentIssueDetails?.frame?.frameId === frameId
  );
  testRunner.log(`requestIds and frameIds match: ${!!match}`)
  testRunner.completeTest();
})