summaryrefslogtreecommitdiffstats
path: root/netwerk/test/unit_ipc/test_httpcancel_wrap.js
blob: f56d0e198bb1befd4180e933ea581ee33d28f4c4 (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
"use strict";

const ReferrerInfo = Components.Constructor(
  "@mozilla.org/referrer-info;1",
  "nsIReferrerInfo",
  "init"
);

let observer = null;

function run_test() {
  do_await_remote_message("register-observer").then(() => {
    observer = {
      QueryInterface: ChromeUtils.generateQI(["nsIObserver"]),

      observe(subject, topic, data) {
        subject = subject.QueryInterface(Ci.nsIRequest);
        subject.cancel(Cr.NS_BINDING_ABORTED);

        // ENSURE_CALLED_BEFORE_CONNECT: setting values should still work
        try {
          subject.QueryInterface(Ci.nsIHttpChannel);
          let currentReferrer = subject.getRequestHeader("Referer");
          Assert.equal(currentReferrer, "http://site1.com/");
          let uri = Services.io.newURI("http://site2.com");
          subject.referrerInfo = new ReferrerInfo(
            Ci.nsIReferrerInfo.EMPTY,
            true,
            uri
          );
        } catch (ex) {
          do_throw("Exception: " + ex);
        }
      },
    };

    Services.obs.addObserver(observer, "http-on-modify-request");
    do_send_remote_message("register-observer-done");
  });

  do_await_remote_message("unregister-observer").then(() => {
    Services.obs.removeObserver(observer, "http-on-modify-request");

    do_send_remote_message("unregister-observer-done");
  });

  run_test_in_child("../unit/test_httpcancel.js");
}