summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/tabMediaIndicator/browser_sound_indicator_silent_video.js
blob: 8f0d6961caf156a83192760086c1287da38ea6d6 (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
const SILENT_PAGE = GetTestWebBasedURL("file_silentAudioTrack.html");
const ALMOST_SILENT_PAGE = GetTestWebBasedURL(
  "file_almostSilentAudioTrack.html"
);

function check_audio_playing_state(isPlaying) {
  let autoPlay = content.document.getElementById("autoplay");
  if (!autoPlay) {
    ok(false, "Can't get the audio element!");
  }

  is(
    autoPlay.paused,
    !isPlaying,
    "The playing state of autoplay audio is correct."
  );

  // wait for a while to make sure the video is playing and related event has
  // been dispatched (if any).
  let PLAYING_TIME_SEC = 0.5;
  ok(PLAYING_TIME_SEC < autoPlay.duration, "The playing time is valid.");

  return new Promise(resolve => {
    autoPlay.ontimeupdate = function () {
      if (autoPlay.currentTime > PLAYING_TIME_SEC) {
        resolve();
      }
    };
  });
}

add_task(async function should_not_show_sound_indicator_for_silent_video() {
  info("- open new foreground tab -");
  let tab = await BrowserTestUtils.openNewForegroundTab(
    window.gBrowser,
    "about:blank"
  );

  info("- tab should not have sound indicator before playing silent video -");
  await waitForTabSoundIndicatorDisappears(tab);

  info("- loading autoplay silent video -");
  BrowserTestUtils.loadURIString(tab.linkedBrowser, SILENT_PAGE);
  await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
  await SpecialPowers.spawn(
    tab.linkedBrowser,
    [true],
    check_audio_playing_state
  );

  info("- tab should not have sound indicator after playing silent video -");
  await waitForTabSoundIndicatorDisappears(tab);

  info("- remove tab -");
  BrowserTestUtils.removeTab(tab);
});

add_task(
  async function should_not_show_sound_indicator_for_almost_silent_video() {
    info("- open new foreground tab -");
    let tab = await BrowserTestUtils.openNewForegroundTab(
      window.gBrowser,
      "about:blank"
    );

    info(
      "- tab should not have sound indicator before playing almost silent video -"
    );
    await waitForTabSoundIndicatorDisappears(tab);

    info("- loading autoplay almost silent video -");
    BrowserTestUtils.loadURIString(tab.linkedBrowser, ALMOST_SILENT_PAGE);
    await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
    await SpecialPowers.spawn(
      tab.linkedBrowser,
      [true],
      check_audio_playing_state
    );

    info(
      "- tab should not have sound indicator after playing almost silent video -"
    );
    await waitForTabSoundIndicatorDisappears(tab);

    info("- remove tab -");
    BrowserTestUtils.removeTab(tab);
  }
);