1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/test/unit/test_bug894586.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,114 @@ 1.4 +/* 1.5 + * Tests for bug 894586: nsSyncLoadService::PushSyncStreamToListener 1.6 + * should not fail for channels of unknown size 1.7 + */ 1.8 + 1.9 +Cu.import("resource://gre/modules/Services.jsm"); 1.10 +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); 1.11 + 1.12 +function ProtocolHandler() { 1.13 + this.uri = Cc["@mozilla.org/network/simple-uri;1"]. 1.14 + createInstance(Ci.nsIURI); 1.15 + this.uri.spec = this.scheme + ":dummy"; 1.16 + this.uri.QueryInterface(Ci.nsIMutable).mutable = false; 1.17 +} 1.18 + 1.19 +ProtocolHandler.prototype = { 1.20 + /** nsIProtocolHandler */ 1.21 + get scheme() "x-bug894586", 1.22 + get defaultPort() -1, 1.23 + get protocolFlags() Ci.nsIProtocolHandler.URI_NORELATIVE | 1.24 + Ci.nsIProtocolHandler.URI_NOAUTH | 1.25 + Ci.nsIProtocolHandler.URI_IS_UI_RESOURCE | 1.26 + Ci.nsIProtocolHandler.URI_IS_LOCAL_RESOURCE | 1.27 + Ci.nsIProtocolHandler.URI_NON_PERSISTABLE | 1.28 + Ci.nsIProtocolHandler.URI_SYNC_LOAD_IS_OK, 1.29 + newURI: function(aSpec, aOriginCharset, aBaseURI) this.uri, 1.30 + newChannel: function(aURI) this, 1.31 + allowPort: function(port, scheme) port != -1, 1.32 + 1.33 + /** nsIChannel */ 1.34 + get originalURI() this.uri, 1.35 + get URI() this.uri, 1.36 + owner: null, 1.37 + notificationCallbacks: null, 1.38 + get securityInfo() null, 1.39 + get contentType() "text/css", 1.40 + set contentType(val) void(0), 1.41 + contentCharset: "UTF-8", 1.42 + get contentLength() -1, 1.43 + set contentLength(val) { 1.44 + throw Components.Exception("Setting content length", NS_ERROR_NOT_IMPLEMENTED); 1.45 + }, 1.46 + open: function() { 1.47 + var file = do_get_file("test_bug894586.js", false); 1.48 + do_check_true(file.exists()); 1.49 + var url = Services.io.newFileURI(file); 1.50 + return Services.io.newChannelFromURI(url).open(); 1.51 + }, 1.52 + asyncOpen: function(aListener, aContext) { 1.53 + throw Components.Exception("Not implemented", 1.54 + Cr.NS_ERROR_NOT_IMPLEMENTED); 1.55 + }, 1.56 + contentDisposition: Ci.nsIChannel.DISPOSITION_INLINE, 1.57 + get contentDispositionFilename() { 1.58 + throw Components.Exception("No file name", 1.59 + Cr.NS_ERROR_NOT_AVAILABLE); 1.60 + }, 1.61 + get contentDispositionHeader() { 1.62 + throw Components.Exception("No header", 1.63 + Cr.NS_ERROR_NOT_AVAILABLE); 1.64 + }, 1.65 + 1.66 + /** nsIRequest */ 1.67 + get name() this.uri.spec, 1.68 + isPending: function() false, 1.69 + get status() Cr.NS_OK, 1.70 + cancel: function(status) {}, 1.71 + loadGroup: null, 1.72 + loadFlags: Ci.nsIRequest.LOAD_NORMAL | 1.73 + Ci.nsIRequest.INHIBIT_CACHING | 1.74 + Ci.nsIRequest.LOAD_BYPASS_CACHE, 1.75 + 1.76 + /** nsIFactory */ 1.77 + createInstance: function(aOuter, aIID) { 1.78 + if (aOuter) { 1.79 + throw Components.Exception("createInstance no aggregation", 1.80 + Cr.NS_ERROR_NO_AGGREGATION); 1.81 + } 1.82 + return this.QueryInterface(aIID); 1.83 + }, 1.84 + lockFactory: function() {}, 1.85 + 1.86 + /** nsISupports */ 1.87 + QueryInterface: XPCOMUtils.generateQI([Ci.nsIProtocolHandler, 1.88 + Ci.nsIRequest, 1.89 + Ci.nsIChannel, 1.90 + Ci.nsIFactory]), 1.91 + classID: Components.ID("{16d594bc-d9d8-47ae-a139-ea714dc0c35c}") 1.92 +}; 1.93 + 1.94 +/** 1.95 + * Attempt a sync load; we use the stylesheet service to do this for us, 1.96 + * based on the knowledge that it forces a sync load under the hood. 1.97 + */ 1.98 +function run_test() 1.99 +{ 1.100 + var handler = new ProtocolHandler(); 1.101 + var registrar = Components.manager. 1.102 + QueryInterface(Ci.nsIComponentRegistrar); 1.103 + registrar.registerFactory(handler.classID, "", 1.104 + "@mozilla.org/network/protocol;1?name=" + handler.scheme, 1.105 + handler); 1.106 + try { 1.107 + var ss = Cc["@mozilla.org/content/style-sheet-service;1"]. 1.108 + getService(Ci.nsIStyleSheetService); 1.109 + ss.loadAndRegisterSheet(handler.uri, Ci.nsIStyleSheetService.AGENT_SHEET); 1.110 + do_check_true(ss.sheetRegistered(handler.uri, Ci.nsIStyleSheetService.AGENT_SHEET)); 1.111 + } finally { 1.112 + registrar.unregisterFactory(handler.classID, handler); 1.113 + } 1.114 +} 1.115 + 1.116 +// vim: set et ts=2 : 1.117 +