tor-browser

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

browser_devices.js (1876B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const {
      7  getDevices,
      8  getDeviceString,
      9  addDevice,
     10  removeLocalDevices,
     11 } = require("resource://devtools/client/shared/devices.js");
     12 
     13 registerCleanupFunction(async () => {
     14  await removeLocalDevices();
     15 });
     16 
     17 add_task(async function () {
     18  let devices = await getDevices();
     19 
     20  let types = [...devices.keys()];
     21  ok(!!types.length, `Found ${types.length} device types.`);
     22 
     23  for (const type of types) {
     24    const string = getDeviceString(type);
     25    ok(
     26      typeof string === "string" &&
     27        !!string.length &&
     28        string != `device.${type}`,
     29      `Able to localize "${type}": "${string}"`
     30    );
     31 
     32    ok(
     33      !!devices.get(type).length,
     34      `Found ${devices.get(type).length} ${type} devices`
     35    );
     36  }
     37 
     38  const type1 = types[0];
     39  const type1DeviceCount = devices.get(type1).length;
     40 
     41  const device1 = {
     42    name: "SquarePhone",
     43    width: 320,
     44    height: 320,
     45    pixelRatio: 2,
     46    userAgent: "Mozilla/5.0 (Mobile; rv:42.0)",
     47    touch: true,
     48    firefoxOS: true,
     49  };
     50  addDevice(device1, types[0]);
     51  devices = await getDevices();
     52 
     53  is(
     54    devices.get(type1).length,
     55    type1DeviceCount + 1,
     56    `Added new device of type "${type1}".`
     57  );
     58  ok(
     59    devices.get(type1).find(d => d.name === device1.name),
     60    "Found the new device."
     61  );
     62 
     63  const type2 = "appliances";
     64  const device2 = {
     65    name: "Mr Freezer",
     66    width: 800,
     67    height: 600,
     68    pixelRatio: 5,
     69    userAgent: "Mozilla/5.0 (Appliance; rv:42.0)",
     70    touch: true,
     71    firefoxOS: true,
     72  };
     73 
     74  const typeCount = types.length;
     75  addDevice(device2, type2);
     76  devices = await getDevices();
     77  types = [...devices.keys()];
     78 
     79  is(types.length, typeCount + 1, `Added device type "${type2}".`);
     80  is(devices.get(type2).length, 1, `Added new "${type2}" device`);
     81 });