summaryrefslogtreecommitdiffstats
path: root/dom/media/autoplay/test/mochitest/test_autoplay_policy_activation.html
blob: eae266030e4e65f812654d45178029b3332601ed (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<!DOCTYPE HTML>
<html>
  <head>
    <title>Autoplay policy test</title>
    <script src="/tests/SimpleTest/SimpleTest.js"></script>
    <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    <script type="text/javascript" src="manifest.js"></script>
    <script type="text/javascript" src="AutoplayTestUtils.js"></script>
  </head>
  <body>
    <pre id="test">
      <script>

        // Tests that videos can only play audibly in windows/frames
        // which have been activated by same-origin user gesture.

        gTestPrefs.push(["media.autoplay.default", SpecialPowers.Ci.nsIAutoplay.BLOCKED],
                        ["media.autoplay.blocking_policy", 0]);

        SpecialPowers.pushPrefEnv({'set': gTestPrefs}, () => {
          runTest();
        });

        let test_cases = [
          {
            name: "inaudible playback in unactivated same-origin iframe in activated parent -> allowed",
            muted: true,
            same_origin_child: true,
            activated_from: "parent",
            play_from: "child",
            should_play: true,
          },

          {
            name: "inaudible playback in unactivated same-origin iframe in unactivated parent -> allowed",
            muted: true,
            same_origin_child: true,
            activated_from: "none",
            play_from: "child",
            should_play: true,
          },

          {
            name: "audible playback in unactivated same-origin iframe in activated parent -> allowed",
            muted: false,
            same_origin_child: true,
            activated_from: "parent",
            play_from: "child",
            should_play: true,
          },

          {
            name: "audible playback in unactivated same-origin iframe in unactivated parent -> blocked",
            muted: false,
            same_origin_child: true,
            activated_from: "none",
            play_from: "child",
            should_play: false,
          },

          {
            name: "inaudible playback in unactivated cross-origin iframe in activated parent -> allowed",
            muted: true,
            same_origin_child: false,
            activated_from: "parent",
            play_from: "child",
            should_play: true,
          },

          {
            name: "inaudible playback in unactivated cross-origin iframe in unactivated parent -> allowed",
            muted: true,
            same_origin_child: false,
            activated_from: "none",
            play_from: "child",
            should_play: true,
          },

          {
            name: "audible playback in unactivated cross-origin iframe in activated parent -> allowed",
            muted: false,
            same_origin_child: false,
            activated_from: "parent",
            play_from: "child",
            should_play: true,
          },

          {
            name: "audible playback in unactivated cross-origin iframe in unactivated parent -> blocked",
            muted: false,
            same_origin_child: false,
            activated_from: "none",
            play_from: "child",
            should_play: false,
          },

          {
            name: "audible playback in activated cross-origin iframe -> allowed",
            muted: false,
            same_origin_child: false,
            activated_from: "child",
            play_from: "child",
            should_play: true,
          },

          {
            name: "audible playback in activated document -> allowed",
            muted: false,
            activated_from: "parent",
            play_from: "parent",
            should_play: true,
          },

          {
            name: "audible playback in unactivated document -> blocked",
            muted: false,
            activated_from: "none",
            play_from: "parent",
            should_play: false,
          },

          {
            name: "audible playback in activated document (via cross-origin child) -> allowed",
            muted: false,
            same_origin_child: false,
            activated_from: "child",
            play_from: "parent",
            should_play: true,
          },

          {
            name: "audible playback in activated document (via same-origin child) -> allowed",
            muted: false,
            same_origin_child: true,
            activated_from: "child",
            play_from: "parent",
            should_play: true,
          },

          {
            name: "inaudible playback in activated document -> allowed",
            muted: true,
            activated_from: "parent",
            play_from: "parent",
            should_play: true,
          },

          {
            name: "inaudible playback in unactivated document -> allowed",
            muted: true,
            activated_from: "none",
            play_from: "parent",
            should_play: true,
          },

        ];

        let child_url = "file_autoplay_policy_activation_window.html";

        async function runTest() {
          for (const test_case of test_cases) {
            // Run each test in a new window, to ensure its user gesture
            // activation state isn't tainted by preceeding tests.
            let child = window.open(child_url, "", "width=500,height=500");
            await once(child, "load");
            child.postMessage(test_case, window.origin);
            let result = await nextWindowMessage();
            SimpleTest.is(result.data.allowedToPlay, test_case.should_play, "allowed - " + test_case.name);
            SimpleTest.is(result.data.played, test_case.should_play, "played - " + test_case.name);
            child.close();
          }
          SimpleTest.finish();
        }

        SimpleTest.waitForExplicitFinish();

      </script>
    </pre>
  </body>
</html>