summaryrefslogtreecommitdiffstats
path: root/dom/workers/test/navigator_worker.js
blob: 63853aef12abd885dd0865f7b48cf7e04e29c026 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
 * Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

// IMPORTANT: Do not change the list below without review from a DOM peer!
var supportedProps = [
  "appCodeName",
  "appName",
  "appVersion",
  "platform",
  "product",
  "userAgent",
  "onLine",
  "language",
  "languages",
  "hardwareConcurrency",
  { name: "storage", nightly: true },
];

self.onmessage = function(event) {
  if (!event || !event.data) {
    return;
  }

  startTest(event.data);
};

function startTest(channelData) {
  // Prepare the interface map showing if a propery should exist in this build.
  // For example, if interfaceMap[foo] = true means navigator.foo should exist.
  var interfaceMap = {};

  for (var prop of supportedProps) {
    if (typeof(prop) === "string") {
      interfaceMap[prop] = true;
      continue;
    }

    if (prop.nightly === !channelData.isNightly ||
        prop.release === !channelData.isRelease) {
      interfaceMap[prop.name] = false;
      continue;
    }

    interfaceMap[prop.name] = true;
  }

  for (var prop in navigator) {
    // Make sure the list is current!
    if (!interfaceMap[prop]) {
      throw "Navigator has the '" + prop + "' property that isn't in the list!";
    }
  }

  var obj;

  for (var prop in interfaceMap) {
    // Skip the property that is not supposed to exist in this build.
    if (!interfaceMap[prop]) {
      continue;
    }

    if (typeof navigator[prop] == "undefined") {
      throw "Navigator has no '" + prop + "' property!";
    }

    obj = { name:  prop };
    obj.value = navigator[prop];

    postMessage(JSON.stringify(obj));
  }

  obj = {
    name: "testFinished"
  };

  postMessage(JSON.stringify(obj));
}