tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_utility_audioDecodeCrash.js (2457B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 async function getAudioDecoderPid(expectation) {
      7  info("Finding a running AudioDecoder");
      8 
      9  const actor = expectation.replace("Utility ", "");
     10 
     11  let audioDecoderProcess = (await ChromeUtils.requestProcInfo()).children.find(
     12    p =>
     13      p.type === "utility" &&
     14      p.utilityActors.find(a => a.actorName === `audioDecoder_${actor}`)
     15  );
     16  ok(
     17    audioDecoderProcess,
     18    `Found the AudioDecoder ${actor} process at ${audioDecoderProcess.pid}`
     19  );
     20  return audioDecoderProcess.pid;
     21 }
     22 
     23 async function crashDecoder(expectation) {
     24  const audioPid = await getAudioDecoderPid(expectation);
     25  Assert.greater(audioPid, 0, `Found an audio decoder ${audioPid}`);
     26  const actorIsAudioDecoder = actorNames => {
     27    return actorNames
     28      .split(",")
     29      .some(actorName => actorName.trim().startsWith("audio-decoder-"));
     30  };
     31  info(`Crashing audio decoder ${audioPid}`);
     32  await crashSomeUtility(audioPid, actorIsAudioDecoder);
     33 }
     34 
     35 async function runTest(src, withClose, expectation) {
     36  info(`Add media tabs: ${src}`);
     37  let tab = await addMediaTab(src);
     38 
     39  info("Play tab");
     40  await play(tab, expectation.process, expectation.decoder);
     41 
     42  info("Crash decoder");
     43  await crashDecoder(expectation.process);
     44 
     45  if (withClose) {
     46    info("Stop tab");
     47    await stop(tab);
     48 
     49    info("Remove tab");
     50    await BrowserTestUtils.removeTab(tab);
     51 
     52    info("Create tab again");
     53    tab = await addMediaTab(src);
     54  }
     55 
     56  info("Play tab again");
     57  await play(tab, expectation.process, expectation.decoder);
     58 
     59  info("Stop tab");
     60  await stop(tab);
     61 
     62  info("Remove tab");
     63  await BrowserTestUtils.removeTab(tab);
     64 }
     65 
     66 add_setup(async function setup() {
     67  await SpecialPowers.pushPrefEnv({
     68    set: [["test.wait300msAfterTabSwitch", true]],
     69  });
     70 });
     71 
     72 async function testAudioCrash(withClose) {
     73  info(`Running tests for audio decoder process crashing: ${withClose}`);
     74 
     75  SimpleTest.expectChildProcessCrash();
     76 
     77  const platform = Services.appinfo.OS;
     78 
     79  for (let { src, expectations } of audioTestData()) {
     80    if (!(platform in expectations)) {
     81      info(`Skipping ${src} for ${platform}`);
     82      continue;
     83    }
     84 
     85    await runTest(src, withClose, expectations[platform]);
     86  }
     87 }
     88 
     89 add_task(async function testAudioCrashSimple() {
     90  await testAudioCrash(false);
     91 });
     92 
     93 add_task(async function testAudioCrashClose() {
     94  await testAudioCrash(true);
     95 });