summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webaudio/the-audio-api/the-audionode-interface/different-contexts.html
blob: f763d3478784a3e4e7255d67726ec5cfdfad5214 (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
<!DOCTYPE html>
<html>
  <head>
    <title>
      Connections and disconnections with different contexts
    </title>
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
    <script src="/webaudio/resources/audit-util.js"></script>
    <script src="/webaudio/resources/audit.js"></script>
  </head>
  <body>
    <script>
      let audit = Audit.createTaskRunner();

      // Different contexts to be used for testing.
      let c1;
      let c2;

      audit.define(
          {label: 'setup', description: 'Contexts for testing'},
          (task, should) => {
            should(() => {c1 = new AudioContext()}, 'c1 = new AudioContext()')
                .notThrow();
            should(() => {c2 = new AudioContext()}, 'c2 = new AudioContext()')
                .notThrow();
            task.done();
          });

      audit.define(
          {label: 'Test 1', description: 'Connect nodes between contexts'},
          (task, should) => {
            let g1;
            let g2;
            should(
                () => {g1 = new GainNode(c1)}, 'Test 1: g1 = new GainNode(c1)')
                .notThrow();
            should(
                () => {g2 = new GainNode(c2)}, 'Test 1: g2 = new GainNode(c2)')
                .notThrow();
            should(() => {g2.connect(g1)}, 'Test 1: g2.connect(g1)')
                .throw(DOMException, 'InvalidAccessError');
            task.done();
          });

      audit.define(
          {label: 'Test 2', description: 'Connect AudioParam between contexts'},
          (task, should) => {
            let g1;
            let g2;
            should(
                () => {g1 = new GainNode(c1)}, 'Test 2: g1 = new GainNode(c1)')
                .notThrow();
            should(
                () => {g2 = new GainNode(c2)}, 'Test 2: g2 = new GainNode(c2)')
                .notThrow();
            should(() => {g2.connect(g1.gain)}, 'Test 2: g2.connect(g1.gain)')
                .throw(DOMException, 'InvalidAccessError');
            task.done();
          });

      audit.define(
          {label: 'Test 3', description: 'Disconnect nodes between contexts'},
          (task, should) => {
            let g1;
            let g2;
            should(
                () => {g1 = new GainNode(c1)}, 'Test 3: g1 = new GainNode(c1)')
                .notThrow();
            should(
                () => {g2 = new GainNode(c2)}, 'Test 3: g2 = new GainNode(c2)')
                .notThrow();
            should(() => {g2.disconnect(g1)}, 'Test 3: g2.disconnect(g1)')
                .throw(DOMException, 'InvalidAccessError');
            task.done();
          });

      audit.define(
          {
            label: 'Test 4',
            description: 'Disconnect AudioParam between contexts'
          },
          (task, should) => {
            let g1;
            let g2;
            should(
                () => {g1 = new GainNode(c1)}, 'Test 4: g1 = new GainNode(c1)')
                .notThrow();
            should(
                () => {g2 = new GainNode(c2)}, 'Test 4: g2 = new GainNode(c2)')
                .notThrow();
            should(
                () => {g2.disconnect(g1.gain)}, 'Test 4: g2.connect(g1.gain)')
                .throw(DOMException, 'InvalidAccessError');
            task.done();
          });

      audit.run();
    </script>
  </body>
</html>