File: suspend-resume.html

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (129 lines) | stat: -rw-r--r-- 3,769 bytes parent folder | download | duplicates (10)
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
<!doctype html>
<html>
  <head>
    <title>Test suspend/resume</title>
    <style type="text/css">
      header {
        margin: 20px 0;
      }
      #results {
        white-space: pre;
        font-family: monospace;
      }
    </style>
  </head>

  <body>
    <h1>Test suspend/resume</h1>

    <p>Press "Start" button to start the test using a single oscillator.</p>
    <p>Then press "Suspend" or "Resume" buttons as desired.  "Suspend" should stop the audio.
    "Resume" should resume the audio immediately.</p>

    <p>Some tests to run:</p>

    <ul>
      <li>Suspend/Resume Test
        <ol>
          <li>Press "Start test"; audio should be heard.</li>
          <li>Press "Suspend" multiple times.  The first press should stop the audio.  Each
          subsequent press should do nothing, but the console should show that each press is
          resolved successfully.
          </li>
          <li>Press "Resume".  The first press should resume audio immediately.  Each subsequent
          press should do nothing, but the console should show that each press is resolved
          successfully.
          </li>
          <li>Press "Stop test" to stop the test; audio should stop.</li>
        </ol>
      </li>
      <li>Closed Test
        <ol>
          <li>Press "Start test"; audio should be heard.</li>
          <li>Press "Stop test"; audio should stop</li>
          <li>Press "Suspend" or "Resume".  Each press should result in a rejected promise
          immediately with an error that suspend or resume is invalid on a closed context.
          </li>
        </ol>
      </li>
    </ul>
    
    <p>See <a href="crbug.com/476429">issue 476429</a></p>

    <button onclick="startTest()">Start test</button>
    <button onclick="stopTest()">Stop test</button>
    <button onclick="suspend()">Suspend</button>
    <button onclick="resume()">Resume</button>

    <header>Results</header>
    <div id="results"></div>

    <script>
      // This is loosely based on the test from isue 476429.
      var context;
      var osc;

      var nextSuspendID = 0;
      var nextResumeID = 0;

      function startTest() {
        try {
          context = new AudioContext() || webkitAudioContext();
        } catch (e) {
          log("Neither AudioContext nor webkitAudioContext found");
          return;
        }

        if (!context.suspend || !context.resume) {
          log("AudioContext lacks suspend/resume support");
          return;
        }

        osc = context.createOscillator();
        osc.connect(context.destination);
        osc.start();
      }

      function suspend() {
        var suspendID = nextSuspendID++;
        log("suspend request: " + suspendID);
        context.suspend()
          .then(function() {
            log("suspend resolved: " + suspendID);
          }, function(e) {
            log("suspend rejected: " + suspendID + "; error: " + e);
          });
      }

      function resume() {
        var resumeID = nextResumeID++;
        log("resume request: " + resumeID);
        context.resume()
          .then(function() {
            log("resume resolved: " + resumeID);
          }, function(e) {
            log("resume rejected: " + resumeID + "; error: " + e);
          });
      }

      function stopTest() {
        if (context) {
          osc.stop();
          osc = null;
          context.close()
            .then(function() {
              log("Context closed.");
            }, function(e) {
              log("Unable to close context: " + e);
            });
        }
      }

      function log(message) {
        console.log(message);
        var results = document.querySelector("#results");
        results.textContent += message + "\n";
      }
    </script>
  </body>
</html>