summaryrefslogtreecommitdiffstats
path: root/devtools/server/tests/mochitest/test_device.html
blob: d678f185fb567bad5b9263538c267b17699b10b8 (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<!DOCTYPE HTML>
<html>
<!--
Bug 895360 - [app manager] Device meta data actor
-->
<head>
  <meta charset="utf-8">
  <title>Mozilla Bug</title>
  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
</head>
<body>
<pre id="test">
<script>

window.onload = function() {
  var Cu = Components.utils;
  var Cc = Components.classes;
  var Ci = Components.interfaces;

  Cu.import("resource://gre/modules/PermissionsTable.jsm");
  var {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
  var {DebuggerClient} = require("devtools/shared/client/main");
  var {DebuggerServer} = require("devtools/server/main");
  var Services = require("Services");

  SimpleTest.waitForExplicitFinish();

  var {getDeviceFront} = require("devtools/shared/fronts/device");

  if (!DebuggerServer.initialized) {
    DebuggerServer.init();
    DebuggerServer.addBrowserActors();
  }

  var client = new DebuggerClient(DebuggerServer.connectPipe());
  client.connect().then(function onConnect() {
    client.listTabs(function onListTabs(aResponse) {
      var d = getDeviceFront(client, aResponse);

      var desc, permissions;
      var appInfo = Services.appinfo;
      var utils = window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);


      var localDesc = {
        appid: appInfo.ID,
        vendor: appInfo.vendor,
        name: appInfo.name,
        version: appInfo.version,
        appbuildid: appInfo.appBuildID,
        platformbuildid: appInfo.platformBuildID,
        platformversion: appInfo.platformVersion,
        geckobuildid: appInfo.platformBuildID,
        geckoversion: appInfo.platformVersion,
        useragent: window.navigator.userAgent,
        locale: Cc["@mozilla.org/chrome/chrome-registry;1"].getService(Ci.nsIXULChromeRegistry).getSelectedLocale("global"),
        os: appInfo.OS,
        processor: appInfo.XPCOMABI.split("-")[0],
        compiler: appInfo.XPCOMABI.split("-")[1],
        dpi: utils.displayDPI,
        width: window.screen.width,
        height: window.screen.height
      }

      function checkValues() {
        for (var key in localDesc) {
          is(desc[key], localDesc[key], "valid field (" + key + ")");
        }

        var currProfD = Services.dirsvc.get("ProfD", Ci.nsIFile);
        var profileDir = currProfD.path;
        ok(profileDir.indexOf(desc.profile.length > 0 && desc.profile) != -1, "valid profile name");

        var a = JSON.stringify(PermissionsTable);
        var b = JSON.stringify(permissions.rawPermissionsTable);

        is(a, b, "Permissions Tables is valid");

        client.close().then(() => {
          DebuggerServer.destroy();
          SimpleTest.finish()
        });
      }


      d.getDescription().then((v) => desc = v)
      .then(() => d.getRawPermissionsTable())
      .then((json) => permissions = json)
      .then(checkValues);

    });
  });

}
</script>
</pre>
</body>
</html>