summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/siteIdentity/browser_tab_sharing_state.js
blob: 6c6ba57c55c0ee5d7f9916e299b27ed4c39b2fa6 (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
96
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

/**
 * Tests gBrowser#updateBrowserSharing
 */
add_task(async function testBrowserSharingStateSetter() {
  const WEBRTC_TEST_STATE = {
    camera: 0,
    microphone: 1,
    paused: false,
    sharing: "microphone",
    showMicrophoneIndicator: true,
    showScreenSharingIndicator: "",
    windowId: 0,
  };

  const WEBRTC_TEST_STATE2 = {
    camera: 1,
    microphone: 1,
    paused: false,
    sharing: "camera",
    showCameraIndicator: true,
    showMicrophoneIndicator: true,
    showScreenSharingIndicator: "",
    windowId: 1,
  };

  await BrowserTestUtils.withNewTab("https://example.com", async browser => {
    let tab = gBrowser.selectedTab;
    is(tab._sharingState, undefined, "No sharing state initially.");
    ok(!tab.hasAttribute("sharing"), "No tab sharing attribute initially.");

    // Set an active sharing state for webrtc
    gBrowser.updateBrowserSharing(browser, { webRTC: WEBRTC_TEST_STATE });
    Assert.deepEqual(
      tab._sharingState,
      { webRTC: WEBRTC_TEST_STATE },
      "Should have correct webRTC sharing state."
    );
    is(
      tab.getAttribute("sharing"),
      WEBRTC_TEST_STATE.sharing,
      "Tab sharing attribute reflects webRTC sharing state."
    );

    // Set sharing state for geolocation
    gBrowser.updateBrowserSharing(browser, { geo: true });
    Assert.deepEqual(
      tab._sharingState,
      {
        webRTC: WEBRTC_TEST_STATE,
        geo: true,
      },
      "Should have sharing state for both webRTC and geolocation."
    );
    is(
      tab.getAttribute("sharing"),
      WEBRTC_TEST_STATE.sharing,
      "Geolocation sharing doesn't update the tab sharing attribute."
    );

    // Update webRTC sharing state
    gBrowser.updateBrowserSharing(browser, { webRTC: WEBRTC_TEST_STATE2 });
    Assert.deepEqual(
      tab._sharingState,
      { geo: true, webRTC: WEBRTC_TEST_STATE2 },
      "Should have updated webRTC sharing state while maintaining geolocation state."
    );
    is(
      tab.getAttribute("sharing"),
      WEBRTC_TEST_STATE2.sharing,
      "Tab sharing attribute reflects webRTC sharing state."
    );

    // Clear webRTC sharing state
    gBrowser.updateBrowserSharing(browser, { webRTC: null });
    Assert.deepEqual(
      tab._sharingState,
      { geo: true, webRTC: null },
      "Should only have sharing state for geolocation."
    );
    ok(
      !tab.hasAttribute("sharing"),
      "Ending webRTC sharing should remove tab sharing attribute."
    );

    // Clear geolocation sharing state
    gBrowser.updateBrowserSharing(browser, { geo: null });
    Assert.deepEqual(tab._sharingState, { geo: null, webRTC: null });
    ok(
      !tab.hasAttribute("sharing"),
      "Tab sharing attribute should not be set."
    );
  });
});