dom/media/tests/mochitest/test_dataChannel_hostnameObfuscationWhitelist.html
author Julien Cristau <jcristau@mozilla.com>
Mon, 30 Dec 2019 13:35:18 +0000
changeset 508486 9672864a4e788fef5f55e3aae14e415923c38cd1
parent 501308 0163a2b9ca5ca939aa9f5b3c1ae139ee33814c0a
permissions -rw-r--r--
Bug 1605861 - test fix. r=dminor Differential Revision: https://phabricator.services.mozilla.com/D58368

<!DOCTYPE HTML>
<html>
<head>
  <script type="application/javascript" src="pc.js"></script>
</head>
<body>
<pre id="test">
<script type="application/javascript">
  createHTML({
    bug: "1592620",
    title: "Whitelist to disable hostname obfuscation"
  });

  async function testWhitelist(options, whitelistEntry, shouldBeObfuscated) {
    let test = new PeerConnectionTest(options);
    addInitialDataChannel(test.chain);

    if (whitelistEntry !== null) {
      await SpecialPowers.pushPrefEnv({
        set: [
          ["media.peerconnection.ice.obfuscate_host_addresses.whitelist",
           whitelistEntry]
        ]
      });
    }

    test.chain.insertAfter('PC_LOCAL_WAIT_FOR_ICE_CONNECTED', [
      async function CHECK_LOCAL_CANDIDATES() {
        const stats = await test.pcLocal.getStats();
        stats.forEach(s => {
          if (s.type === 'local-candidate') {
            if (shouldBeObfuscated) {
              ok(s.address.includes(".local"), "address should be obfuscated");
            } else {
              ok(!s.address.includes(".local"), "address should not be obfuscated");
            }
          }
        });
      }]);

    // This inlines test.run(), to allow for multiple tests to run.
    test.updateChainSteps();
    await test.chain.execute();
    await test.close();
  }

  runNetworkTest(async (options) => {
    await SpecialPowers.pushPrefEnv({
      set: [["media.peerconnection.ice.obfuscate_host_addresses", true]]
    });
    await testWhitelist(options, null, true);
    await testWhitelist(options, "", true);
    await testWhitelist(options, "example.com", true);
    await testWhitelist(options, "mochi.test", false);
    await testWhitelist(options, "example.com,mochi.test", false);
    await testWhitelist(options, "*.test", false);

    networkTestFinished();
  });

</script>
</pre>
</body>
</html>