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