tor-browser

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

test_speech_synthesis.html (3741B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1333641
      5 -->
      6 <head>
      7  <meta charset="utf-8">
      8  <title>Test for Bug 1333641</title>
      9  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     11  <script type="application/javascript">
     12 
     13  /** Test for Bug 1333641 */
     14  SimpleTest.waitForExplicitFinish();
     15  window.onload = setupSpeechSynthesis;
     16 
     17  // This function setup the speechSynthesis and flip 'privacy.resistFingerprinting'
     18  // after it has been setup correctly.
     19  function setupSpeechSynthesis() {
     20    window.speechSynthesis.addEventListener("voiceschanged", () => {
     21      isnot(window.speechSynthesis.getVoices().length, 0, "Voices added");
     22      SimpleTest.waitForFocus(() => {
     23        SpecialPowers.pushPrefEnv({"set":
     24          [["privacy.resistFingerprinting", true]],
     25        }, doGetVoicesTest);
     26      }, window);
     27    }, {once: true});
     28 
     29    is(window.speechSynthesis.getVoices().length, 0, "No voices added initially");
     30  }
     31 
     32  function doGetVoicesTest() {
     33    is(window.speechSynthesis.getVoices().length, 0,
     34       "There should be no voices after fingerprinting resistance is enabled.");
     35    doVoiceschangedEventTest();
     36  }
     37 
     38  function doVoiceschangedEventTest() {
     39    window.speechSynthesis.addEventListener("voiceschanged", () => {
     40      ok(false, "The voiceschanged event should not be fired.");
     41      doSpeakTestAsync();
     42    }, {once: true});
     43 
     44    window.addEventListener("TestEvent", () => {
     45      // If we receive this event without receiving a 'voiceschanged' event, this means
     46      // the voiceschanged event has been blocked correctly.
     47      ok(true, "Got the 'TestEvent' event.");
     48      doSpeakTestAsync();
     49    }, {once: true});
     50 
     51    // Notify 'synth-voices-changed' for triggering the voiceschanged event.
     52    SpecialPowers.Services.obs.notifyObservers(null, "synth-voices-changed");
     53    window.dispatchEvent(new CustomEvent("TestEvent"));
     54  }
     55 
     56  // This tests Speak() and its asynchronousness.
     57  function doSpeakTestAsync() {
     58    // For non-e10s, this test will always fail since the event will be triggered immediately
     59    // after speak() is called. So, new added events after speak() won't be called. We skip
     60    // this test if it is non-e10s.
     61    if (SpecialPowers.Services.appinfo.browserTabsRemoteAutostart) {
     62      let utterance = new window.SpeechSynthesisUtterance("Hello, world!");
     63      window.speechSynthesis.speak(utterance);
     64 
     65      utterance.addEventListener("start", () => {
     66        ok(false, "speechSynthesis should not start speaking if fingerprinting resistance is enabled.");
     67        doSpeakTestSync();
     68      }, {once: true});
     69 
     70      utterance.addEventListener("error", () => {
     71        ok(true, "speechSynthesis.speak should fail if fingerprinting resistance is enabled.");
     72        doSpeakTestSync();
     73      }, {once: true});
     74    } else {
     75      doSpeakTestSync();
     76    }
     77  }
     78 
     79  // This tests Speak() and its synchronousness.
     80  function doSpeakTestSync() {
     81    let utterance = new window.SpeechSynthesisUtterance("Hello, world!");
     82    utterance.addEventListener("start", () => {
     83      ok(false, "speechSynthesis should not start speaking if fingerprinting resistance is enabled.");
     84      SimpleTest.finish();
     85    }, {once: true});
     86 
     87    utterance.addEventListener("error", () => {
     88      ok(true, "speechSynthesis.speak should fail if fingerprinting resistance is enabled.");
     89      SimpleTest.finish();
     90    }, {once: true});
     91 
     92    window.speechSynthesis.speak(utterance);
     93  }
     94 
     95  </script>
     96 </head>
     97 <body>
     98 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a>
     99 <p id="display"></p>
    100 <div id="content" style="display: none">
    101 
    102 </div>
    103 <pre id="test"></pre>
    104 </body>
    105 </html>