Thu, 15 Jan 2015 15:55:04 +0100
Back out 97036ab72558 which inappropriately compared turds to third parties.
michael@0 | 1 | const isWindows = ("@mozilla.org/windows-registry-key;1" in Cc); |
michael@0 | 2 | const isLinux = ("@mozilla.org/gnome-gconf-service;1" in Cc); |
michael@0 | 3 | |
michael@0 | 4 | function getLinkFile() |
michael@0 | 5 | { |
michael@0 | 6 | if (isWindows) { |
michael@0 | 7 | return do_get_file("test_link.url"); |
michael@0 | 8 | } |
michael@0 | 9 | if (isLinux) { |
michael@0 | 10 | return do_get_file("test_link.desktop"); |
michael@0 | 11 | } |
michael@0 | 12 | do_throw("Unexpected platform"); |
michael@0 | 13 | return null; |
michael@0 | 14 | } |
michael@0 | 15 | |
michael@0 | 16 | const ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); |
michael@0 | 17 | var link; |
michael@0 | 18 | var linkURI; |
michael@0 | 19 | const newURI = ios.newURI("http://www.mozilla.org/", null, null); |
michael@0 | 20 | |
michael@0 | 21 | function NotificationCallbacks(origURI, newURI) |
michael@0 | 22 | { |
michael@0 | 23 | this._origURI = origURI; |
michael@0 | 24 | this._newURI = newURI; |
michael@0 | 25 | } |
michael@0 | 26 | NotificationCallbacks.prototype = { |
michael@0 | 27 | QueryInterface: function(iid) |
michael@0 | 28 | { |
michael@0 | 29 | if (iid.equals(Ci.nsISupports) || |
michael@0 | 30 | iid.equals(Ci.nsIInterfaceRequestor) || |
michael@0 | 31 | iid.equals(Ci.nsIChannelEventSink)) { |
michael@0 | 32 | return this; |
michael@0 | 33 | } |
michael@0 | 34 | throw Cr.NS_ERROR_NO_INTERFACE; |
michael@0 | 35 | }, |
michael@0 | 36 | getInterface: function (iid) |
michael@0 | 37 | { |
michael@0 | 38 | return this.QueryInterface(iid); |
michael@0 | 39 | }, |
michael@0 | 40 | asyncOnChannelRedirect: function(oldChan, newChan, flags, callback) |
michael@0 | 41 | { |
michael@0 | 42 | do_check_eq(oldChan.URI.spec, this._origURI.spec); |
michael@0 | 43 | do_check_eq(oldChan.URI, this._origURI); |
michael@0 | 44 | do_check_eq(oldChan.originalURI.spec, this._origURI.spec); |
michael@0 | 45 | do_check_eq(oldChan.originalURI, this._origURI); |
michael@0 | 46 | do_check_eq(newChan.originalURI.spec, this._newURI.spec); |
michael@0 | 47 | do_check_eq(newChan.originalURI, newChan.URI); |
michael@0 | 48 | do_check_eq(newChan.URI.spec, this._newURI.spec); |
michael@0 | 49 | throw Cr.NS_ERROR_ABORT; |
michael@0 | 50 | } |
michael@0 | 51 | }; |
michael@0 | 52 | |
michael@0 | 53 | function RequestObserver(origURI, newURI, nextTest) |
michael@0 | 54 | { |
michael@0 | 55 | this._origURI = origURI; |
michael@0 | 56 | this._newURI = newURI; |
michael@0 | 57 | this._nextTest = nextTest; |
michael@0 | 58 | } |
michael@0 | 59 | RequestObserver.prototype = { |
michael@0 | 60 | QueryInterface: function(iid) |
michael@0 | 61 | { |
michael@0 | 62 | if (iid.equals(Ci.nsISupports) || |
michael@0 | 63 | iid.equals(Ci.nsIRequestObserver) || |
michael@0 | 64 | iid.equals(Ci.nsIStreamListener)) { |
michael@0 | 65 | return this; |
michael@0 | 66 | } |
michael@0 | 67 | throw Cr.NS_ERROR_NO_INTERFACE; |
michael@0 | 68 | }, |
michael@0 | 69 | onStartRequest: function (req, ctx) |
michael@0 | 70 | { |
michael@0 | 71 | var chan = req.QueryInterface(Ci.nsIChannel); |
michael@0 | 72 | do_check_eq(chan.URI.spec, this._origURI.spec); |
michael@0 | 73 | do_check_eq(chan.URI, this._origURI); |
michael@0 | 74 | do_check_eq(chan.originalURI.spec, this._origURI.spec); |
michael@0 | 75 | do_check_eq(chan.originalURI, this._origURI); |
michael@0 | 76 | }, |
michael@0 | 77 | onDataAvailable: function(req, ctx, stream, offset, count) |
michael@0 | 78 | { |
michael@0 | 79 | do_throw("Unexpected call to onDataAvailable"); |
michael@0 | 80 | }, |
michael@0 | 81 | onStopRequest: function (req, ctx, status) |
michael@0 | 82 | { |
michael@0 | 83 | var chan = req.QueryInterface(Ci.nsIChannel); |
michael@0 | 84 | try { |
michael@0 | 85 | do_check_eq(chan.URI.spec, this._origURI.spec); |
michael@0 | 86 | do_check_eq(chan.URI, this._origURI); |
michael@0 | 87 | do_check_eq(chan.originalURI.spec, this._origURI.spec); |
michael@0 | 88 | do_check_eq(chan.originalURI, this._origURI); |
michael@0 | 89 | do_check_eq(status, Cr.NS_ERROR_ABORT); |
michael@0 | 90 | do_check_false(chan.isPending()); |
michael@0 | 91 | } catch(e) {} |
michael@0 | 92 | this._nextTest(); |
michael@0 | 93 | } |
michael@0 | 94 | }; |
michael@0 | 95 | |
michael@0 | 96 | function test_cancel() |
michael@0 | 97 | { |
michael@0 | 98 | var chan = ios.newChannelFromURI(linkURI); |
michael@0 | 99 | do_check_eq(chan.URI, linkURI); |
michael@0 | 100 | do_check_eq(chan.originalURI, linkURI); |
michael@0 | 101 | chan.asyncOpen(new RequestObserver(linkURI, newURI, do_test_finished), null); |
michael@0 | 102 | do_check_true(chan.isPending()); |
michael@0 | 103 | chan.cancel(Cr.NS_ERROR_ABORT); |
michael@0 | 104 | do_check_true(chan.isPending()); |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | function run_test() |
michael@0 | 108 | { |
michael@0 | 109 | if (!isWindows && !isLinux) { |
michael@0 | 110 | return; |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | link = getLinkFile(); |
michael@0 | 114 | linkURI = ios.newFileURI(link); |
michael@0 | 115 | |
michael@0 | 116 | do_test_pending(); |
michael@0 | 117 | |
michael@0 | 118 | var chan = ios.newChannelFromURI(linkURI); |
michael@0 | 119 | do_check_eq(chan.URI, linkURI); |
michael@0 | 120 | do_check_eq(chan.originalURI, linkURI); |
michael@0 | 121 | chan.notificationCallbacks = new NotificationCallbacks(linkURI, newURI); |
michael@0 | 122 | chan.asyncOpen(new RequestObserver(linkURI, newURI, test_cancel), null); |
michael@0 | 123 | do_check_true(chan.isPending()); |
michael@0 | 124 | } |