summaryrefslogtreecommitdiffstats
path: root/toolkit/components/pictureinpicture/tests/browser_cannotTriggerFromContent.js
blob: 1ba93dbb8c01f20c69b823acd9ed64f18aa0c5bd (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * Tests that the MozTogglePictureInPicture event is ignored if
 * fired by unprivileged web content.
 */
add_task(async () => {
  await BrowserTestUtils.withNewTab(
    {
      url: TEST_PAGE,
      gBrowser,
    },
    async browser => {
      // For now, the easiest way to ensure that this didn't happen is to fail
      // if we receive the PictureInPicture:Request message.
      const MESSAGE = "PictureInPicture:Request";
      let sawMessage = false;
      let listener = () => {
        sawMessage = true;
      };
      browser.messageManager.addMessageListener(MESSAGE, listener);
      await SpecialPowers.spawn(browser, [], async () => {
        content.wrappedJSObject.fireEvents();
      });
      browser.messageManager.removeMessageListener(MESSAGE, listener);
      ok(!sawMessage, "Got PictureInPicture:Request message unexpectedly.");
    }
  );
});