summaryrefslogtreecommitdiffstats
path: root/devtools/client/shared/test/browser_devices.js
blob: 3585c9b720f9579f43b347dc3f283aebdb2c8f77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const {
  getDevices,
  getDeviceString,
  addDevice,
} = require("devtools/client/shared/devices");

add_task(async function() {
  Services.prefs.setCharPref(
    "devtools.devices.url",
    TEST_URI_ROOT + "browser_devices.json"
  );

  let devices = await getDevices();

  is(devices.TYPES.length, 1, "Found 1 device type.");

  const type1 = devices.TYPES[0];

  is(devices[type1].length, 2, "Found 2 devices of type #1.");

  const string = getDeviceString(type1);
  ok(
    typeof string === "string" && string.length > 0,
    "Able to localize type #1."
  );

  const device1 = {
    name: "SquarePhone",
    width: 320,
    height: 320,
    pixelRatio: 2,
    userAgent: "Mozilla/5.0 (Mobile; rv:42.0)",
    touch: true,
    firefoxOS: true,
  };
  addDevice(device1, type1);
  devices = await getDevices();

  is(devices[type1].length, 3, "Added new device of type #1.");
  ok(
    devices[type1].filter(d => d.name === device1.name),
    "Found the new device."
  );

  const type2 = "appliances";
  const device2 = {
    name: "Mr Freezer",
    width: 800,
    height: 600,
    pixelRatio: 5,
    userAgent: "Mozilla/5.0 (Appliance; rv:42.0)",
    touch: true,
    firefoxOS: true,
  };
  addDevice(device2, type2);
  devices = await getDevices();

  is(devices.TYPES.length, 2, "Added device type #2.");
  is(devices[type2].length, 1, "Added new device of type #2.");
});