test_bug894586.js (3303B)
1 /* 2 * Tests for bug 894586: nsSyncLoadService::PushSyncStreamToListener 3 * should not fail for channels of unknown size 4 */ 5 6 "use strict"; 7 8 var contentSecManager = Cc["@mozilla.org/contentsecuritymanager;1"].getService( 9 Ci.nsIContentSecurityManager 10 ); 11 12 function ProtocolHandler() { 13 this.uri = Cc["@mozilla.org/network/simple-uri-mutator;1"] 14 .createInstance(Ci.nsIURIMutator) 15 .setSpec(this.scheme + ":dummy") 16 .finalize(); 17 } 18 19 ProtocolHandler.prototype = { 20 /** nsIProtocolHandler */ 21 get scheme() { 22 return "x-bug894586"; 23 }, 24 newChannel(aURI, aLoadInfo) { 25 this.loadInfo = aLoadInfo; 26 return this; 27 }, 28 allowPort(port) { 29 return port != -1; 30 }, 31 32 /** nsIChannel */ 33 get originalURI() { 34 return this.uri; 35 }, 36 get URI() { 37 return this.uri; 38 }, 39 owner: null, 40 notificationCallbacks: null, 41 get securityInfo() { 42 return null; 43 }, 44 get contentType() { 45 return "text/css"; 46 }, 47 set contentType(val) {}, 48 contentCharset: "UTF-8", 49 get contentLength() { 50 return -1; 51 }, 52 set contentLength(val) { 53 throw Components.Exception( 54 "Setting content length", 55 Cr.NS_ERROR_NOT_IMPLEMENTED 56 ); 57 }, 58 open() { 59 // throws an error if security checks fail 60 contentSecManager.performSecurityCheck(this, null); 61 62 var file = do_get_file("test_bug894586.js", false); 63 Assert.ok(file.exists()); 64 var url = Services.io.newFileURI(file); 65 return NetUtil.newChannel({ 66 uri: url, 67 loadUsingSystemPrincipal: true, 68 }).open(); 69 }, 70 asyncOpen() { 71 throw Components.Exception("Not implemented", Cr.NS_ERROR_NOT_IMPLEMENTED); 72 }, 73 contentDisposition: Ci.nsIChannel.DISPOSITION_INLINE, 74 get contentDispositionFilename() { 75 throw Components.Exception("No file name", Cr.NS_ERROR_NOT_AVAILABLE); 76 }, 77 get contentDispositionHeader() { 78 throw Components.Exception("No header", Cr.NS_ERROR_NOT_AVAILABLE); 79 }, 80 81 /** nsIRequest */ 82 get name() { 83 return this.uri.spec; 84 }, 85 isPending: () => false, 86 get status() { 87 return Cr.NS_OK; 88 }, 89 cancel() {}, 90 loadGroup: null, 91 loadFlags: 92 Ci.nsIRequest.LOAD_NORMAL | 93 Ci.nsIRequest.INHIBIT_CACHING | 94 Ci.nsIRequest.LOAD_BYPASS_CACHE, 95 96 /** nsISupports */ 97 QueryInterface: ChromeUtils.generateQI([ 98 "nsIProtocolHandler", 99 "nsIRequest", 100 "nsIChannel", 101 ]), 102 }; 103 104 /** 105 * Attempt a sync load; we use the stylesheet service to do this for us, 106 * based on the knowledge that it forces a sync load under the hood. 107 */ 108 function run_test() { 109 var handler = new ProtocolHandler(); 110 111 Services.io.registerProtocolHandler( 112 handler.scheme, 113 handler, 114 Ci.nsIProtocolHandler.URI_NORELATIVE | 115 Ci.nsIProtocolHandler.URI_NOAUTH | 116 Ci.nsIProtocolHandler.URI_IS_UI_RESOURCE | 117 Ci.nsIProtocolHandler.URI_IS_LOCAL_RESOURCE | 118 Ci.nsIProtocolHandler.URI_NON_PERSISTABLE | 119 Ci.nsIProtocolHandler.URI_SYNC_LOAD_IS_OK, 120 -1 121 ); 122 try { 123 var ss = Cc["@mozilla.org/content/style-sheet-service;1"].getService( 124 Ci.nsIStyleSheetService 125 ); 126 ss.loadAndRegisterSheet(handler.uri, Ci.nsIStyleSheetService.AGENT_SHEET); 127 Assert.ok( 128 ss.sheetRegistered(handler.uri, Ci.nsIStyleSheetService.AGENT_SHEET) 129 ); 130 } finally { 131 Services.io.unregisterProtocolHandler(handler.scheme); 132 } 133 } 134 135 // vim: set et ts=2 :