summaryrefslogtreecommitdiffstats
path: root/ipc/glue/test/browser/browser_utility_audioDecodeCrash.js
blob: 1662ba06f3cdaa8bc421438107ab70471b6a4869 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

async function getAudioDecoderPid(expectation) {
  info("Finding a running AudioDecoder");

  const actor = expectation.replace("Utility ", "");

  let audioDecoderProcess = (await ChromeUtils.requestProcInfo()).children.find(
    p =>
      p.type === "utility" &&
      p.utilityActors.find(a => a.actorName === `audioDecoder_${actor}`)
  );
  ok(
    audioDecoderProcess,
    `Found the AudioDecoder ${actor} process at ${audioDecoderProcess.pid}`
  );
  return audioDecoderProcess.pid;
}

async function crashDecoder(expectation) {
  const audioPid = await getAudioDecoderPid(expectation);
  Assert.greater(audioPid, 0, `Found an audio decoder ${audioPid}`);
  const actorIsAudioDecoder = actorNames => {
    return actorNames
      .split(",")
      .some(actorName => actorName.trim().startsWith("audio-decoder-"));
  };
  info(`Crashing audio decoder ${audioPid}`);
  await crashSomeUtility(audioPid, actorIsAudioDecoder);
}

async function runTest(src, withClose, expectation) {
  info(`Add media tabs: ${src}`);
  let tab = await addMediaTab(src);

  info("Play tab");
  await play(tab, expectation.process, expectation.decoder);

  info("Crash decoder");
  await crashDecoder(expectation.process);

  if (withClose) {
    info("Stop tab");
    await stop(tab);

    info("Remove tab");
    await BrowserTestUtils.removeTab(tab);

    info("Create tab again");
    tab = await addMediaTab(src);
  }

  info("Play tab again");
  await play(tab, expectation.process, expectation.decoder);

  info("Stop tab");
  await stop(tab);

  info("Remove tab");
  await BrowserTestUtils.removeTab(tab);
}

add_setup(async function setup() {
  await SpecialPowers.pushPrefEnv({
    set: [["media.utility-process.enabled", true]],
  });
});

async function testAudioCrash(withClose) {
  info(`Running tests for audio decoder process crashing: ${withClose}`);

  SimpleTest.expectChildProcessCrash();

  const platform = Services.appinfo.OS;

  for (let { src, expectations } of audioTestData()) {
    if (!(platform in expectations)) {
      info(`Skipping ${src} for ${platform}`);
      continue;
    }

    await runTest(src, withClose, expectations[platform]);
  }
}

add_task(async function testAudioCrashSimple() {
  await testAudioCrash(false);
});

add_task(async function testAudioCrashClose() {
  await testAudioCrash(true);
});