Backed out changeset b71c8c052463 (bug 1943846) for causing mass failures. CLOSED...
[gecko.git] / netwerk / test / unit / test_ohttp.js
blobb7bd2f1d067b247897bd4a4ae4cc3f419466ac5b
1 /* Any copyright is dedicated to the Public Domain.
2 * https://creativecommons.org/publicdomain/zero/1.0/ */
4 "use strict";
6 function test_known_config() {
7 let ohttp = Cc["@mozilla.org/network/oblivious-http;1"].getService(
8 Ci.nsIObliviousHttp
9 );
10 let encodedConfig = hexStringToBytes(
11 "0100209403aafe76dfd4568481e04e44b42d744287eae4070b50e48baa7a91a4e80d5600080001000100010003"
13 let request = hexStringToBytes(
14 "00034745540568747470730b6578616d706c652e636f6d012f"
16 let ohttpRequest = ohttp.encapsulateRequest(encodedConfig, request);
17 ok(ohttpRequest);
20 function test_with_server() {
21 let ohttp = Cc["@mozilla.org/network/oblivious-http;1"].getService(
22 Ci.nsIObliviousHttp
24 let server = ohttp.server();
25 ok(server.encodedConfig);
26 let request = hexStringToBytes(
27 "00034745540568747470730b6578616d706c652e636f6d012f"
29 let ohttpRequest = ohttp.encapsulateRequest(server.encodedConfig, request);
30 let ohttpResponse = server.decapsulate(ohttpRequest.encRequest);
31 ok(ohttpResponse);
32 deepEqual(ohttpResponse.request, request);
33 let response = hexStringToBytes("0140c8");
34 let encResponse = ohttpResponse.encapsulate(response);
35 deepEqual(ohttpRequest.response.decapsulate(encResponse), response);
38 function run_test() {
39 test_known_config();
40 test_with_server();