netwerk/test/unit/test_bug894586.js

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

michael@0 1 /*
michael@0 2 * Tests for bug 894586: nsSyncLoadService::PushSyncStreamToListener
michael@0 3 * should not fail for channels of unknown size
michael@0 4 */
michael@0 5
michael@0 6 Cu.import("resource://gre/modules/Services.jsm");
michael@0 7 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
michael@0 8
michael@0 9 function ProtocolHandler() {
michael@0 10 this.uri = Cc["@mozilla.org/network/simple-uri;1"].
michael@0 11 createInstance(Ci.nsIURI);
michael@0 12 this.uri.spec = this.scheme + ":dummy";
michael@0 13 this.uri.QueryInterface(Ci.nsIMutable).mutable = false;
michael@0 14 }
michael@0 15
michael@0 16 ProtocolHandler.prototype = {
michael@0 17 /** nsIProtocolHandler */
michael@0 18 get scheme() "x-bug894586",
michael@0 19 get defaultPort() -1,
michael@0 20 get protocolFlags() Ci.nsIProtocolHandler.URI_NORELATIVE |
michael@0 21 Ci.nsIProtocolHandler.URI_NOAUTH |
michael@0 22 Ci.nsIProtocolHandler.URI_IS_UI_RESOURCE |
michael@0 23 Ci.nsIProtocolHandler.URI_IS_LOCAL_RESOURCE |
michael@0 24 Ci.nsIProtocolHandler.URI_NON_PERSISTABLE |
michael@0 25 Ci.nsIProtocolHandler.URI_SYNC_LOAD_IS_OK,
michael@0 26 newURI: function(aSpec, aOriginCharset, aBaseURI) this.uri,
michael@0 27 newChannel: function(aURI) this,
michael@0 28 allowPort: function(port, scheme) port != -1,
michael@0 29
michael@0 30 /** nsIChannel */
michael@0 31 get originalURI() this.uri,
michael@0 32 get URI() this.uri,
michael@0 33 owner: null,
michael@0 34 notificationCallbacks: null,
michael@0 35 get securityInfo() null,
michael@0 36 get contentType() "text/css",
michael@0 37 set contentType(val) void(0),
michael@0 38 contentCharset: "UTF-8",
michael@0 39 get contentLength() -1,
michael@0 40 set contentLength(val) {
michael@0 41 throw Components.Exception("Setting content length", NS_ERROR_NOT_IMPLEMENTED);
michael@0 42 },
michael@0 43 open: function() {
michael@0 44 var file = do_get_file("test_bug894586.js", false);
michael@0 45 do_check_true(file.exists());
michael@0 46 var url = Services.io.newFileURI(file);
michael@0 47 return Services.io.newChannelFromURI(url).open();
michael@0 48 },
michael@0 49 asyncOpen: function(aListener, aContext) {
michael@0 50 throw Components.Exception("Not implemented",
michael@0 51 Cr.NS_ERROR_NOT_IMPLEMENTED);
michael@0 52 },
michael@0 53 contentDisposition: Ci.nsIChannel.DISPOSITION_INLINE,
michael@0 54 get contentDispositionFilename() {
michael@0 55 throw Components.Exception("No file name",
michael@0 56 Cr.NS_ERROR_NOT_AVAILABLE);
michael@0 57 },
michael@0 58 get contentDispositionHeader() {
michael@0 59 throw Components.Exception("No header",
michael@0 60 Cr.NS_ERROR_NOT_AVAILABLE);
michael@0 61 },
michael@0 62
michael@0 63 /** nsIRequest */
michael@0 64 get name() this.uri.spec,
michael@0 65 isPending: function() false,
michael@0 66 get status() Cr.NS_OK,
michael@0 67 cancel: function(status) {},
michael@0 68 loadGroup: null,
michael@0 69 loadFlags: Ci.nsIRequest.LOAD_NORMAL |
michael@0 70 Ci.nsIRequest.INHIBIT_CACHING |
michael@0 71 Ci.nsIRequest.LOAD_BYPASS_CACHE,
michael@0 72
michael@0 73 /** nsIFactory */
michael@0 74 createInstance: function(aOuter, aIID) {
michael@0 75 if (aOuter) {
michael@0 76 throw Components.Exception("createInstance no aggregation",
michael@0 77 Cr.NS_ERROR_NO_AGGREGATION);
michael@0 78 }
michael@0 79 return this.QueryInterface(aIID);
michael@0 80 },
michael@0 81 lockFactory: function() {},
michael@0 82
michael@0 83 /** nsISupports */
michael@0 84 QueryInterface: XPCOMUtils.generateQI([Ci.nsIProtocolHandler,
michael@0 85 Ci.nsIRequest,
michael@0 86 Ci.nsIChannel,
michael@0 87 Ci.nsIFactory]),
michael@0 88 classID: Components.ID("{16d594bc-d9d8-47ae-a139-ea714dc0c35c}")
michael@0 89 };
michael@0 90
michael@0 91 /**
michael@0 92 * Attempt a sync load; we use the stylesheet service to do this for us,
michael@0 93 * based on the knowledge that it forces a sync load under the hood.
michael@0 94 */
michael@0 95 function run_test()
michael@0 96 {
michael@0 97 var handler = new ProtocolHandler();
michael@0 98 var registrar = Components.manager.
michael@0 99 QueryInterface(Ci.nsIComponentRegistrar);
michael@0 100 registrar.registerFactory(handler.classID, "",
michael@0 101 "@mozilla.org/network/protocol;1?name=" + handler.scheme,
michael@0 102 handler);
michael@0 103 try {
michael@0 104 var ss = Cc["@mozilla.org/content/style-sheet-service;1"].
michael@0 105 getService(Ci.nsIStyleSheetService);
michael@0 106 ss.loadAndRegisterSheet(handler.uri, Ci.nsIStyleSheetService.AGENT_SHEET);
michael@0 107 do_check_true(ss.sheetRegistered(handler.uri, Ci.nsIStyleSheetService.AGENT_SHEET));
michael@0 108 } finally {
michael@0 109 registrar.unregisterFactory(handler.classID, handler);
michael@0 110 }
michael@0 111 }
michael@0 112
michael@0 113 // vim: set et ts=2 :
michael@0 114

mercurial