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

/**
 * Tests that Picture-in-Picture "move toggle" context menu item
 * successfully changes preference.
 */
add_task(async () => {
  let videoID = "with-controls";
  await BrowserTestUtils.withNewTab(
    {
      url: TEST_PAGE,
      gBrowser,
    },
    async browser => {
      await ensureVideosReady(browser);

      await SpecialPowers.spawn(browser, [videoID], async videoID => {
        await content.document.getElementById(videoID).play();
      });

      const TOGGLE_POSITION_PREF =
        "media.videocontrols.picture-in-picture.video-toggle.position";
      const TOGGLE_POSITION_RIGHT = "right";
      const TOGGLE_POSITION_LEFT = "left";

      await SpecialPowers.pushPrefEnv({
        set: [[TOGGLE_POSITION_PREF, TOGGLE_POSITION_RIGHT]],
      });

      let contextMoveToggle = document.getElementById(
        "context_MovePictureInPictureToggle"
      );
      contextMoveToggle.click();
      let position = Services.prefs.getStringPref(
        TOGGLE_POSITION_PREF,
        TOGGLE_POSITION_RIGHT
      );

      Assert.ok(
        position === TOGGLE_POSITION_LEFT,
        "Picture-in-Picture toggle position value should be 'left'."
      );

      contextMoveToggle.click();
      position = Services.prefs.getStringPref(
        TOGGLE_POSITION_PREF,
        TOGGLE_POSITION_RIGHT
      );

      Assert.ok(
        position === TOGGLE_POSITION_RIGHT,
        "Picture-in-Picture toggle position value should be 'right'."
      );
    }
  );
});