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