1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/test/unit/test_bug455311.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,124 @@ 1.4 +const isWindows = ("@mozilla.org/windows-registry-key;1" in Cc); 1.5 +const isLinux = ("@mozilla.org/gnome-gconf-service;1" in Cc); 1.6 + 1.7 +function getLinkFile() 1.8 +{ 1.9 + if (isWindows) { 1.10 + return do_get_file("test_link.url"); 1.11 + } 1.12 + if (isLinux) { 1.13 + return do_get_file("test_link.desktop"); 1.14 + } 1.15 + do_throw("Unexpected platform"); 1.16 + return null; 1.17 +} 1.18 + 1.19 +const ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); 1.20 +var link; 1.21 +var linkURI; 1.22 +const newURI = ios.newURI("http://www.mozilla.org/", null, null); 1.23 + 1.24 +function NotificationCallbacks(origURI, newURI) 1.25 +{ 1.26 + this._origURI = origURI; 1.27 + this._newURI = newURI; 1.28 +} 1.29 +NotificationCallbacks.prototype = { 1.30 + QueryInterface: function(iid) 1.31 + { 1.32 + if (iid.equals(Ci.nsISupports) || 1.33 + iid.equals(Ci.nsIInterfaceRequestor) || 1.34 + iid.equals(Ci.nsIChannelEventSink)) { 1.35 + return this; 1.36 + } 1.37 + throw Cr.NS_ERROR_NO_INTERFACE; 1.38 + }, 1.39 + getInterface: function (iid) 1.40 + { 1.41 + return this.QueryInterface(iid); 1.42 + }, 1.43 + asyncOnChannelRedirect: function(oldChan, newChan, flags, callback) 1.44 + { 1.45 + do_check_eq(oldChan.URI.spec, this._origURI.spec); 1.46 + do_check_eq(oldChan.URI, this._origURI); 1.47 + do_check_eq(oldChan.originalURI.spec, this._origURI.spec); 1.48 + do_check_eq(oldChan.originalURI, this._origURI); 1.49 + do_check_eq(newChan.originalURI.spec, this._newURI.spec); 1.50 + do_check_eq(newChan.originalURI, newChan.URI); 1.51 + do_check_eq(newChan.URI.spec, this._newURI.spec); 1.52 + throw Cr.NS_ERROR_ABORT; 1.53 + } 1.54 +}; 1.55 + 1.56 +function RequestObserver(origURI, newURI, nextTest) 1.57 +{ 1.58 + this._origURI = origURI; 1.59 + this._newURI = newURI; 1.60 + this._nextTest = nextTest; 1.61 +} 1.62 +RequestObserver.prototype = { 1.63 + QueryInterface: function(iid) 1.64 + { 1.65 + if (iid.equals(Ci.nsISupports) || 1.66 + iid.equals(Ci.nsIRequestObserver) || 1.67 + iid.equals(Ci.nsIStreamListener)) { 1.68 + return this; 1.69 + } 1.70 + throw Cr.NS_ERROR_NO_INTERFACE; 1.71 + }, 1.72 + onStartRequest: function (req, ctx) 1.73 + { 1.74 + var chan = req.QueryInterface(Ci.nsIChannel); 1.75 + do_check_eq(chan.URI.spec, this._origURI.spec); 1.76 + do_check_eq(chan.URI, this._origURI); 1.77 + do_check_eq(chan.originalURI.spec, this._origURI.spec); 1.78 + do_check_eq(chan.originalURI, this._origURI); 1.79 + }, 1.80 + onDataAvailable: function(req, ctx, stream, offset, count) 1.81 + { 1.82 + do_throw("Unexpected call to onDataAvailable"); 1.83 + }, 1.84 + onStopRequest: function (req, ctx, status) 1.85 + { 1.86 + var chan = req.QueryInterface(Ci.nsIChannel); 1.87 + try { 1.88 + do_check_eq(chan.URI.spec, this._origURI.spec); 1.89 + do_check_eq(chan.URI, this._origURI); 1.90 + do_check_eq(chan.originalURI.spec, this._origURI.spec); 1.91 + do_check_eq(chan.originalURI, this._origURI); 1.92 + do_check_eq(status, Cr.NS_ERROR_ABORT); 1.93 + do_check_false(chan.isPending()); 1.94 + } catch(e) {} 1.95 + this._nextTest(); 1.96 + } 1.97 +}; 1.98 + 1.99 +function test_cancel() 1.100 +{ 1.101 + var chan = ios.newChannelFromURI(linkURI); 1.102 + do_check_eq(chan.URI, linkURI); 1.103 + do_check_eq(chan.originalURI, linkURI); 1.104 + chan.asyncOpen(new RequestObserver(linkURI, newURI, do_test_finished), null); 1.105 + do_check_true(chan.isPending()); 1.106 + chan.cancel(Cr.NS_ERROR_ABORT); 1.107 + do_check_true(chan.isPending()); 1.108 +} 1.109 + 1.110 +function run_test() 1.111 +{ 1.112 + if (!isWindows && !isLinux) { 1.113 + return; 1.114 + } 1.115 + 1.116 + link = getLinkFile(); 1.117 + linkURI = ios.newFileURI(link); 1.118 + 1.119 + do_test_pending(); 1.120 + 1.121 + var chan = ios.newChannelFromURI(linkURI); 1.122 + do_check_eq(chan.URI, linkURI); 1.123 + do_check_eq(chan.originalURI, linkURI); 1.124 + chan.notificationCallbacks = new NotificationCallbacks(linkURI, newURI); 1.125 + chan.asyncOpen(new RequestObserver(linkURI, newURI, test_cancel), null); 1.126 + do_check_true(chan.isPending()); 1.127 +}