Bug 1807268 - Re-enable verifyShowClipboardSuggestionsToggleTest UI test r=jajohnson
[gecko.git] / netwerk / test / unit / test_simple.js
blob98f1d3ee3e1dd24e4dda9762d069facc772ab030
1 //
2 //  Simple HTTP test: fetches page
3 //
5 // Note: sets Cc and Ci variables
6 "use strict";
8 const { HttpServer } = ChromeUtils.importESModule(
9   "resource://testing-common/httpd.sys.mjs"
12 var httpserver = new HttpServer();
13 var testpath = "/simple";
14 var httpbody = "0123456789";
16 var dbg = 0;
17 if (dbg) {
18   print("============== START ==========");
21 function run_test() {
22   setup_test();
23   do_test_pending();
26 function setup_test() {
27   if (dbg) {
28     print("============== setup_test: in");
29   }
30   httpserver.registerPathHandler(testpath, serverHandler);
31   httpserver.start(-1);
32   var channel = setupChannel(testpath);
33   // ChannelListener defined in head_channels.js
34   channel.asyncOpen(new ChannelListener(checkRequest, channel));
35   if (dbg) {
36     print("============== setup_test: out");
37   }
40 function setupChannel(path) {
41   var chan = NetUtil.newChannel({
42     uri: "http://localhost:" + httpserver.identity.primaryPort + path,
43     loadUsingSystemPrincipal: true,
44   });
45   chan.QueryInterface(Ci.nsIHttpChannel);
46   chan.requestMethod = "GET";
47   return chan;
50 function serverHandler(metadata, response) {
51   if (dbg) {
52     print("============== serverHandler: in");
53   }
54   response.setHeader("Content-Type", "text/plain", false);
55   response.bodyOutputStream.write(httpbody, httpbody.length);
56   if (dbg) {
57     print("============== serverHandler: out");
58   }
61 function checkRequest(request, data) {
62   if (dbg) {
63     print("============== checkRequest: in");
64   }
65   Assert.equal(data, httpbody);
66   httpserver.stop(do_test_finished);
67   if (dbg) {
68     print("============== checkRequest: out");
69   }