summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webaudio/the-audio-api/the-audiocontext-interface/audiocontext-not-fully-active.html
blob: e4f6001eda3e295b69b6989680e04bd67412f7a6 (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
<!doctype html>
<title>Test AudioContext construction when document is not fully active</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="/common/get-host-info.sub.js"></script>
<body></body>
<script>
const dir = location.pathname.replace(/\/[^\/]*$/, '/');
const helper = dir + 'resources/not-fully-active-helper.sub.html?childsrc=';
const remote_helper = get_host_info().HTTP_NOTSAMESITE_ORIGIN + helper;
const blank_url = get_host_info().ORIGIN + '/common/blank.html';

const load_content = (frame, src) => {
  if (src == undefined) {
    frame.srcdoc = '<html></html>';
  } else {
    frame.src = src;
  }
  return new Promise(resolve => frame.onload = () => resolve(frame));
};
const append_iframe = (src) => {
  const frame = document.createElement('iframe');
  document.body.appendChild(frame);
  return load_content(frame, src);
};
const remote_op = (win, op) => {
  win.postMessage(op, '*');
  return new Promise(resolve => window.onmessage = e => {
    if (e.data == 'DONE ' + op) resolve();
  });
};
const test_constructor_throws = async (win, deactivate) => {
  const {AudioContext, DOMException} = win;
  await deactivate();
  assert_throws_dom("InvalidStateError", DOMException,
                    () => new AudioContext());
};

promise_test(async () => {
  const frame = await append_iframe();
  return test_constructor_throws(frame.contentWindow, () => frame.remove());
}, "removed frame");
promise_test(async () => {
  const frame = await append_iframe();
  return test_constructor_throws(frame.contentWindow,
                                 () => load_content(frame));
}, "navigated frame");
promise_test(async () => {
  const frame = await append_iframe(helper + blank_url);
  const inner = frame.contentWindow.frames[0];
  return test_constructor_throws(inner, () => frame.remove());
}, "frame in removed frame");
promise_test(async () => {
  const frame = await append_iframe(helper + blank_url);
  const inner = frame.contentWindow.frames[0];
  return test_constructor_throws(inner, () => load_content(frame));
}, "frame in navigated frame");
promise_test(async () => {
  const frame = await append_iframe(remote_helper + blank_url);
  const inner = frame.contentWindow.frames[0];
  return test_constructor_throws(inner, () => frame.remove());
}, "frame in removed remote-site frame");
promise_test(async () => {
  const frame = await append_iframe(remote_helper + blank_url);
  const inner = frame.contentWindow.frames[0];
  return test_constructor_throws(inner, () => load_content(frame));
}, "frame in navigated remote-site frame");
promise_test(async () => {
  const outer = (await append_iframe(remote_helper + blank_url)).contentWindow;
  const inner = outer.frames[0];
  return test_constructor_throws(inner,
                                 () => remote_op(outer, 'REMOVE FRAME'));
}, "removed frame in remote-site frame");
promise_test(async () => {
  const outer = (await append_iframe(remote_helper + blank_url)).contentWindow;
  const inner = outer.frames[0];
  return test_constructor_throws(inner,
                                 () => remote_op(outer, 'NAVIGATE FRAME'));
}, "navigated frame in remote-site frame");
promise_test(async () => {
  const url = remote_helper + helper + blank_url;
  const outer = (await append_iframe(url)).contentWindow;
  const inner = outer.frames[0].frames[0];
  return test_constructor_throws(inner,
                                 () => remote_op(outer, 'REMOVE FRAME'));
}, "frame in removed remote-site frame in remote-site frame");
promise_test(async () => {
  const url = remote_helper + helper + blank_url;
  const outer = (await append_iframe(url)).contentWindow;
  const inner = outer.frames[0].frames[0];
  return test_constructor_throws(inner,
                                 () => remote_op(outer, 'NAVIGATE FRAME'));
}, "frame in navigated remote-site frame in remote-site frame");
</script>