summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/tabMediaIndicator/browser_destroy_iframe.js
blob: f977d1d6649988543fb21f0252a10a112773677a (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
const EMPTY_PAGE_URL = GetTestWebBasedURL("file_empty.html");
const AUTPLAY_PAGE_URL = GetTestWebBasedURL("file_autoplay_media.html");
const CORS_AUTPLAY_PAGE_URL = GetTestWebBasedURL(
  "file_autoplay_media.html",
  true
);

/**
 * When an iframe that has audible media gets destroyed, if there is no other
 * audible playing media existing in the page, then the sound indicator should
 * disappear.
 */
add_task(async function testDestroyAudibleIframe() {
  const iframesURL = [AUTPLAY_PAGE_URL, CORS_AUTPLAY_PAGE_URL];
  for (let iframeURL of iframesURL) {
    info(`open a tab, create an iframe and load an autoplay media page inside`);
    const tab = await BrowserTestUtils.openNewForegroundTab(
      gBrowser,
      EMPTY_PAGE_URL
    );
    await createIframeAndLoadURL(tab, iframeURL);

    info(`sound indicator should appear because of audible playing media`);
    await waitForTabSoundIndicatorAppears(tab);

    info(`sound indicator should disappear after destroying iframe`);
    await removeIframe(tab);
    await waitForTabSoundIndicatorDisappears(tab);

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

function createIframeAndLoadURL(tab, url) {
  // eslint-disable-next-line no-shadow
  return SpecialPowers.spawn(tab.linkedBrowser, [url], async url => {
    const iframe = content.document.createElement("iframe");
    content.document.body.appendChild(iframe);
    iframe.src = url;
    info(`load ${url} for iframe`);
    await new Promise(r => (iframe.onload = r));
  });
}

function removeIframe(tab) {
  return SpecialPowers.spawn(tab.linkedBrowser, [], _ => {
    content.document.getElementsByTagName("iframe")[0].remove();
  });
}