netwerk/test/unit/test_bug455311.js

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

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

mercurial