Bug 1931425 - Limit how often moz-label's #setStyles runs r=reusable-components-revie...
[gecko.git] / netwerk / test / unit / test_bug455311.js
blob284fcf0ac70dbee39dc5766d2998367378b68df8
1 "use strict";
3 function getUrlLinkFile() {
4 if (mozinfo.os == "win") {
5 return do_get_file("test_link.url");
7 if (mozinfo.os == "linux") {
8 return do_get_file("test_link.desktop");
10 do_throw("Unexpected platform");
11 return null;
14 const ios = Services.io;
16 function NotificationCallbacks(origURI, newURI) {
17 this._origURI = origURI;
18 this._newURI = newURI;
20 NotificationCallbacks.prototype = {
21 QueryInterface: ChromeUtils.generateQI([
22 "nsIInterfaceRequestor",
23 "nsIChannelEventSink",
24 ]),
25 getInterface(iid) {
26 return this.QueryInterface(iid);
28 asyncOnChannelRedirect(oldChan, newChan) {
29 Assert.equal(oldChan.URI.spec, this._origURI.spec);
30 Assert.equal(oldChan.URI, this._origURI);
31 Assert.equal(oldChan.originalURI.spec, this._origURI.spec);
32 Assert.equal(oldChan.originalURI, this._origURI);
33 Assert.equal(newChan.originalURI.spec, this._newURI.spec);
34 Assert.equal(newChan.originalURI, newChan.URI);
35 Assert.equal(newChan.URI.spec, this._newURI.spec);
36 throw Components.Exception("", Cr.NS_ERROR_ABORT);
40 function RequestObserver(origURI, newURI, nextTest) {
41 this._origURI = origURI;
42 this._newURI = newURI;
43 this._nextTest = nextTest;
45 RequestObserver.prototype = {
46 QueryInterface: ChromeUtils.generateQI([
47 "nsIRequestObserver",
48 "nsIStreamListener",
49 ]),
50 onStartRequest(req) {
51 var chan = req.QueryInterface(Ci.nsIChannel);
52 Assert.equal(chan.URI.spec, this._origURI.spec);
53 Assert.equal(chan.URI, this._origURI);
54 Assert.equal(chan.originalURI.spec, this._origURI.spec);
55 Assert.equal(chan.originalURI, this._origURI);
57 onDataAvailable() {
58 do_throw("Unexpected call to onDataAvailable");
60 onStopRequest(req, status) {
61 var chan = req.QueryInterface(Ci.nsIChannel);
62 try {
63 Assert.equal(chan.URI.spec, this._origURI.spec);
64 Assert.equal(chan.URI, this._origURI);
65 Assert.equal(chan.originalURI.spec, this._origURI.spec);
66 Assert.equal(chan.originalURI, this._origURI);
67 Assert.equal(status, Cr.NS_ERROR_ABORT);
68 Assert.ok(!chan.isPending());
69 } catch (e) {}
70 this._nextTest();
74 function test_cancel(linkURI, newURI) {
75 var chan = NetUtil.newChannel({
76 uri: linkURI,
77 loadUsingSystemPrincipal: true,
78 });
79 Assert.equal(chan.URI, linkURI);
80 Assert.equal(chan.originalURI, linkURI);
81 chan.asyncOpen(new RequestObserver(linkURI, newURI, do_test_finished));
82 Assert.ok(chan.isPending());
83 chan.cancel(Cr.NS_ERROR_ABORT);
84 Assert.ok(chan.isPending());
87 function test_channel(linkURI, newURI) {
88 const chan = NetUtil.newChannel({
89 uri: linkURI,
90 loadUsingSystemPrincipal: true,
91 });
92 Assert.equal(chan.URI, linkURI);
93 Assert.equal(chan.originalURI, linkURI);
94 chan.notificationCallbacks = new NotificationCallbacks(linkURI, newURI);
95 chan.asyncOpen(
96 new RequestObserver(linkURI, newURI, () => test_cancel(linkURI, newURI))
98 Assert.ok(chan.isPending());
101 function run_test() {
102 if (mozinfo.os != "win" && mozinfo.os != "linux") {
103 return;
106 let link = getUrlLinkFile();
107 let linkURI;
108 if (link.isSymlink()) {
109 let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
110 file.initWithPath(link.target);
111 linkURI = ios.newFileURI(file);
112 } else {
113 linkURI = ios.newFileURI(link);
116 do_test_pending();
117 test_channel(linkURI, ios.newURI("http://www.mozilla.org/"));
119 if (mozinfo.os != "win") {
120 return;
123 link = do_get_file("test_link.lnk");
124 test_channel(
125 ios.newFileURI(link),
126 ios.newURI("file:///Z:/moz-nonexistent/index.html")