tor-browser

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

browser_private_browsing_eme_persistent_state.js (1703B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 /*
      6 * This test ensures that navigator.requestMediaKeySystemAccess() requests
      7 * to run EME with persistent state are rejected in private browsing windows.
      8 * Bug 1334111.
      9 */
     10 
     11 const TEST_URL =
     12  getRootDirectory(gTestPath).replace(
     13    "chrome://mochitests/content",
     14    "https://example.com"
     15  ) + "empty_file.html";
     16 
     17 async function isEmePersistentStateSupported(mode) {
     18  let win = await BrowserTestUtils.openNewBrowserWindow(mode);
     19  let tab = await BrowserTestUtils.openNewForegroundTab(win.gBrowser, TEST_URL);
     20  let persistentStateSupported = await SpecialPowers.spawn(
     21    tab.linkedBrowser,
     22    [],
     23    async function () {
     24      try {
     25        let config = [
     26          {
     27            initDataTypes: ["webm"],
     28            videoCapabilities: [{ contentType: 'video/webm; codecs="vp9"' }],
     29            persistentState: "required",
     30          },
     31        ];
     32        await content.navigator.requestMediaKeySystemAccess(
     33          "org.w3.clearkey",
     34          config
     35        );
     36      } catch (ex) {
     37        return false;
     38      }
     39      return true;
     40    }
     41  );
     42 
     43  await BrowserTestUtils.closeWindow(win);
     44 
     45  return persistentStateSupported;
     46 }
     47 
     48 add_task(async function test() {
     49  is(
     50    await isEmePersistentStateSupported({ private: true }),
     51    true,
     52    "EME persistentState *SHOULD* be supported in private browsing window."
     53  );
     54  is(
     55    await isEmePersistentStateSupported({ private: false }),
     56    true,
     57    "EME persistentState *SHOULD* be supported in non private browsing window."
     58  );
     59 });