tor-browser

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

browser_telemetry_video_hardware_decoding_support.js (2974B)


      1 /**
      2 * This test is used to ensure that the scalar which indicates whether hardware
      3 * decoding is supported for a specific video codec type can be recorded
      4 * correctly.
      5 */
      6 "use strict";
      7 
      8 add_task(async function setupTestingPref() {
      9  await SpecialPowers.pushPrefEnv({
     10    set: [
     11      // In order to test av1 in the chrome process, see https://bit.ly/3oF0oan
     12      ["media.rdd-process.enabled", false],
     13    ],
     14  });
     15 });
     16 
     17 const ALL_SCALAR = "media.video_hardware_decoding_support";
     18 const HD_SCALAR = "media.video_hd_hardware_decoding_support";
     19 
     20 add_task(async function testVideoCodecs() {
     21  // There are still other video codecs, but we only care about these popular
     22  // codec types.
     23  const testFiles = [
     24    { fileName: "gizmo.mp4", type: "video/avc" },
     25    { fileName: "gizmo.webm", type: "video/vp9" },
     26    { fileName: "bipbop_short_vp8.webm", type: "video/vp8" },
     27    { fileName: "av1.mp4", type: "video/av1" },
     28    { fileName: "bunny_hd_5s.mp4", type: "video/avc", hd: true },
     29  ];
     30 
     31  for (const file of testFiles) {
     32    const { fileName, type, hd } = file;
     33    let video = document.createElement("video");
     34    video.src = GetTestWebBasedURL(fileName);
     35    await video.play();
     36    let snapshot = Services.telemetry.getSnapshotForKeyedScalars(
     37      "main",
     38      false
     39    ).parent;
     40    ok(
     41      snapshot.hasOwnProperty(ALL_SCALAR),
     42      `Found stored scalar '${ALL_SCALAR}'`
     43    );
     44    ok(
     45      snapshot[ALL_SCALAR].hasOwnProperty(type),
     46      `Found key '${type}' in '${ALL_SCALAR}'`
     47    );
     48    if (hd) {
     49      ok(
     50        snapshot.hasOwnProperty(HD_SCALAR),
     51        `HD video '${fileName}' should record a scalar '${HD_SCALAR}'`
     52      );
     53      ok(
     54        snapshot[HD_SCALAR].hasOwnProperty(type),
     55        `Found key '${type}' in '${HD_SCALAR}'`
     56      );
     57    } else {
     58      ok(
     59        !snapshot.hasOwnProperty(HD_SCALAR),
     60        `SD video won't store a scalar '${HD_SCALAR}'`
     61      );
     62    }
     63    video.src = "";
     64    Services.telemetry.clearScalars();
     65  }
     66 });
     67 
     68 add_task(async function testAudioCodecs() {
     69  const testFiles = [
     70    "small-shot.ogg",
     71    "small-shot.m4a",
     72    "small-shot.mp3",
     73    "small-shot.flac",
     74  ];
     75  for (const file of testFiles) {
     76    let audio = document.createElement("audio");
     77    info(GetTestWebBasedURL(file));
     78    audio.src = GetTestWebBasedURL(file);
     79    await audio.play();
     80    let snapshot = Services.telemetry.getSnapshotForKeyedScalars(
     81      "main",
     82      false
     83    ).parent;
     84    ok(
     85      !snapshot ||
     86        (!snapshot.hasOwnProperty(ALL_SCALAR) &&
     87          !snapshot.hasOwnProperty(HD_SCALAR)),
     88      `Did not record scalar for ${file}`
     89    );
     90    audio.src = "";
     91  }
     92 });
     93 
     94 /**
     95 * Return a web-based URL for a given file based on the testing directory.
     96 *
     97 * @param {string} fileName
     98 *        file that caller wants its web-based url
     99 */
    100 function GetTestWebBasedURL(fileName) {
    101  return (
    102    getRootDirectory(gTestPath).replace(
    103      "chrome://mochitests/content",
    104      "http://example.org"
    105    ) + fileName
    106  );
    107 }