summaryrefslogtreecommitdiffstats
path: root/remote/test/browser/browser_httpd.js
blob: 1176ba941778068e83619c26becc09f82c54afe9 (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

add_task(async function json_version() {
  await RemoteAgent.listen(`http://localhost:0`);

  const { userAgent } = Cc[
    "@mozilla.org/network/protocol;1?name=http"
  ].getService(Ci.nsIHttpProtocolHandler);

  const json = await requestJSON("/version");
  is(
    json.Browser,
    `${Services.appinfo.name}/${Services.appinfo.version}`,
    "Browser name and version found"
  );
  is(json["Protocol-Version"], "1.0", "Protocol version found");
  is(json["User-Agent"], userAgent, "User agent found");
  is(json["V8-Version"], "1.0", "V8 version found");
  is(json["WebKit-Version"], "1.0", "Webkit version found");
  is(
    json.webSocketDebuggerUrl,
    RemoteAgent.targets.getMainProcessTarget().wsDebuggerURL,
    "Websocket URL for main process target found"
  );
});

function requestJSON(path) {
  const url = `http://${RemoteAgent.debuggerAddress}`;

  return new Promise(resolve => {
    var xhr = new XMLHttpRequest();
    xhr.open("GET", `${url}/json${path}`);
    xhr.responseType = "json";
    xhr.onloadend = () => {
      resolve(xhr.response);
    };
    xhr.send();
  });
}