michael@0: /* michael@0: * Tests for bug 894586: nsSyncLoadService::PushSyncStreamToListener michael@0: * should not fail for channels of unknown size michael@0: */ michael@0: michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: Cu.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: michael@0: function ProtocolHandler() { michael@0: this.uri = Cc["@mozilla.org/network/simple-uri;1"]. michael@0: createInstance(Ci.nsIURI); michael@0: this.uri.spec = this.scheme + ":dummy"; michael@0: this.uri.QueryInterface(Ci.nsIMutable).mutable = false; michael@0: } michael@0: michael@0: ProtocolHandler.prototype = { michael@0: /** nsIProtocolHandler */ michael@0: get scheme() "x-bug894586", michael@0: get defaultPort() -1, michael@0: get protocolFlags() Ci.nsIProtocolHandler.URI_NORELATIVE | michael@0: Ci.nsIProtocolHandler.URI_NOAUTH | michael@0: Ci.nsIProtocolHandler.URI_IS_UI_RESOURCE | michael@0: Ci.nsIProtocolHandler.URI_IS_LOCAL_RESOURCE | michael@0: Ci.nsIProtocolHandler.URI_NON_PERSISTABLE | michael@0: Ci.nsIProtocolHandler.URI_SYNC_LOAD_IS_OK, michael@0: newURI: function(aSpec, aOriginCharset, aBaseURI) this.uri, michael@0: newChannel: function(aURI) this, michael@0: allowPort: function(port, scheme) port != -1, michael@0: michael@0: /** nsIChannel */ michael@0: get originalURI() this.uri, michael@0: get URI() this.uri, michael@0: owner: null, michael@0: notificationCallbacks: null, michael@0: get securityInfo() null, michael@0: get contentType() "text/css", michael@0: set contentType(val) void(0), michael@0: contentCharset: "UTF-8", michael@0: get contentLength() -1, michael@0: set contentLength(val) { michael@0: throw Components.Exception("Setting content length", NS_ERROR_NOT_IMPLEMENTED); michael@0: }, michael@0: open: function() { michael@0: var file = do_get_file("test_bug894586.js", false); michael@0: do_check_true(file.exists()); michael@0: var url = Services.io.newFileURI(file); michael@0: return Services.io.newChannelFromURI(url).open(); michael@0: }, michael@0: asyncOpen: function(aListener, aContext) { michael@0: throw Components.Exception("Not implemented", michael@0: Cr.NS_ERROR_NOT_IMPLEMENTED); michael@0: }, michael@0: contentDisposition: Ci.nsIChannel.DISPOSITION_INLINE, michael@0: get contentDispositionFilename() { michael@0: throw Components.Exception("No file name", michael@0: Cr.NS_ERROR_NOT_AVAILABLE); michael@0: }, michael@0: get contentDispositionHeader() { michael@0: throw Components.Exception("No header", michael@0: Cr.NS_ERROR_NOT_AVAILABLE); michael@0: }, michael@0: michael@0: /** nsIRequest */ michael@0: get name() this.uri.spec, michael@0: isPending: function() false, michael@0: get status() Cr.NS_OK, michael@0: cancel: function(status) {}, michael@0: loadGroup: null, michael@0: loadFlags: Ci.nsIRequest.LOAD_NORMAL | michael@0: Ci.nsIRequest.INHIBIT_CACHING | michael@0: Ci.nsIRequest.LOAD_BYPASS_CACHE, michael@0: michael@0: /** nsIFactory */ michael@0: createInstance: function(aOuter, aIID) { michael@0: if (aOuter) { michael@0: throw Components.Exception("createInstance no aggregation", michael@0: Cr.NS_ERROR_NO_AGGREGATION); michael@0: } michael@0: return this.QueryInterface(aIID); michael@0: }, michael@0: lockFactory: function() {}, michael@0: michael@0: /** nsISupports */ michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsIProtocolHandler, michael@0: Ci.nsIRequest, michael@0: Ci.nsIChannel, michael@0: Ci.nsIFactory]), michael@0: classID: Components.ID("{16d594bc-d9d8-47ae-a139-ea714dc0c35c}") michael@0: }; michael@0: michael@0: /** michael@0: * Attempt a sync load; we use the stylesheet service to do this for us, michael@0: * based on the knowledge that it forces a sync load under the hood. michael@0: */ michael@0: function run_test() michael@0: { michael@0: var handler = new ProtocolHandler(); michael@0: var registrar = Components.manager. michael@0: QueryInterface(Ci.nsIComponentRegistrar); michael@0: registrar.registerFactory(handler.classID, "", michael@0: "@mozilla.org/network/protocol;1?name=" + handler.scheme, michael@0: handler); michael@0: try { michael@0: var ss = Cc["@mozilla.org/content/style-sheet-service;1"]. michael@0: getService(Ci.nsIStyleSheetService); michael@0: ss.loadAndRegisterSheet(handler.uri, Ci.nsIStyleSheetService.AGENT_SHEET); michael@0: do_check_true(ss.sheetRegistered(handler.uri, Ci.nsIStyleSheetService.AGENT_SHEET)); michael@0: } finally { michael@0: registrar.unregisterFactory(handler.classID, handler); michael@0: } michael@0: } michael@0: michael@0: // vim: set et ts=2 : michael@0: