tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_online_http_webkit.html (2779B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1248897
      5 The intent of this file is to test a successfull speech recognition request and
      6 that audio is being properly encoded
      7 -->
      8 <head>
      9  <meta charset="utf-8">
     10  <title>Test for Bug 1248897 -- Online speech service</title>
     11  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     12  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     13  <script type="application/javascript" src="head.js"></script>
     14 </head>
     15 <body>
     16 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1248897">Mozilla Bug 1248897</a>
     17 <p id="display"></p>
     18 <div id="content" style="display: none">
     19 
     20 </div>
     21 <pre id="test">
     22 <script type="text/javascript">
     23  SimpleTest.waitForExplicitFinish();
     24 
     25  async function validateRawAudio(buffer) {
     26    const ac = new AudioContext();
     27    const decodedData = await ac.decodeAudioData(buffer);
     28    const source = ac.createBufferSource();
     29    source.buffer = decodedData;
     30    source.loop = true;
     31    const analyser = ac.createAnalyser();
     32    analyser.smoothingTimeConstant = 0.2;
     33    analyser.fftSize = 1024;
     34    source.connect(analyser);
     35    const binIndexForFrequency = frequency =>
     36      1 + Math.round(frequency * analyser.fftSize / ac.sampleRate);
     37    source.start();
     38    const data = new Uint8Array(analyser.frequencyBinCount);
     39    const start = performance.now();
     40    while (true) {
     41      if (performance.now() - start > 10000) {
     42        return false;
     43      }
     44      analyser.getByteFrequencyData(data);
     45      if (data[binIndexForFrequency(200)] < 50 &&
     46          data[binIndexForFrequency(440)] > 180 &&
     47          data[binIndexForFrequency(1000)] < 50) {
     48        return true;
     49      }
     50      await new Promise(r => requestAnimationFrame(r));
     51    }
     52  }
     53 
     54  async function verifyEncodedAudio(requestUrl) {
     55    try {
     56      const response = await fetch(requestUrl);
     57      const buffer = await response.arrayBuffer();
     58      ok(await validateRawAudio(buffer), "Audio encoding is valid");
     59    } catch(e) {
     60      ok(false, e);
     61    } finally {
     62      SimpleTest.finish();
     63    }
     64  }
     65 
     66  performTest({
     67    eventsToRequest: {},
     68    expectedEvents: {
     69      "start": null,
     70      "audiostart": null,
     71      "audioend": null,
     72      "end": null,
     73      "result": () => verifyEncodedAudio("http_requesthandler.sjs?save"),
     74      "speechstart": null,
     75      "speechend": null
     76    },
     77    audioSampleFile: "sinoid+hello.ogg",
     78    prefs: [["media.webspeech.recognition.enable", true],
     79            ["media.webspeech.service.endpoint",
     80              "http://mochi.test:8888/tests/dom/media/webspeech/recognition/test/http_requesthandler.sjs"],
     81            ["media.webspeech.recognition.timeout", 100000]],
     82    webkit: true
     83  });
     84 </script>
     85 </pre>
     86 </body>
     87 </html>