mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 06:43:32 +00:00
Bug 1087744: Make JS callers of ios.newChannel call ios.newChannel2 in toolkit/ - tests (r=gijs)
This commit is contained in:
parent
d5dc59ac0e
commit
7082ffe2b7
@ -6,6 +6,7 @@ const Ci = Components.interfaces;
|
||||
const Cu = Components.utils;
|
||||
|
||||
Cu.import("resource://testing-common/httpd.js");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
const PATH = "/file.meh";
|
||||
var httpserver = new HttpServer();
|
||||
@ -70,8 +71,16 @@ function setupChannel(url, flags)
|
||||
{
|
||||
var ios = Components.classes["@mozilla.org/network/io-service;1"].
|
||||
getService(Ci.nsIIOService);
|
||||
var chan = ios.newChannel("http://localhost:" +
|
||||
httpserver.identity.primaryPort + url, "", null);
|
||||
let uri = "http://localhost:" +
|
||||
httpserver.identity.primaryPort + url;
|
||||
var chan = ios.newChannel2(uri,
|
||||
"",
|
||||
null,
|
||||
null, // aLoadingNode
|
||||
Services.scriptSecurityManager.getSystemPrincipal(),
|
||||
null, // aTriggeringPrincipal
|
||||
Ci.nsILoadInfo.SEC_NORMAL,
|
||||
Ci.nsIContentPolicy.TYPE_MEDIA);
|
||||
chan.loadFlags |= flags;
|
||||
var httpChan = chan.QueryInterface(Components.interfaces.nsIHttpChannel);
|
||||
return httpChan;
|
||||
|
@ -12,6 +12,7 @@ var BinaryOutputStream = CC("@mozilla.org/binaryoutputstream;1",
|
||||
"setOutputStream");
|
||||
|
||||
Cu.import("resource://testing-common/httpd.js");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
var httpserver = new HttpServer();
|
||||
|
||||
@ -70,8 +71,15 @@ var listener = {
|
||||
function setupChannel(url) {
|
||||
var ios = Components.classes["@mozilla.org/network/io-service;1"].
|
||||
getService(Ci.nsIIOService);
|
||||
var chan = ios.newChannel("http://localhost:" +
|
||||
httpserver.identity.primaryPort + url, "", null);
|
||||
var chan = ios.newChannel2("http://localhost:" +
|
||||
httpserver.identity.primaryPort + url,
|
||||
"",
|
||||
null,
|
||||
null, // aLoadingNode
|
||||
Services.scriptSecurityManager.getSystemPrincipal(),
|
||||
null, // aTriggeringPrincipal
|
||||
Ci.nsILoadInfo.SEC_NORMAL,
|
||||
Ci.nsIContentPolicy.TYPE_MEDIA);
|
||||
var httpChan = chan.QueryInterface(Components.interfaces.nsIHttpChannel);
|
||||
return httpChan;
|
||||
}
|
||||
|
@ -54,7 +54,8 @@ function reference_fetch_file(path, test) {
|
||||
do_print("Fetching file " + path);
|
||||
let deferred = Promise.defer();
|
||||
let file = new FileUtils.File(path);
|
||||
NetUtil.asyncFetch(file,
|
||||
NetUtil.asyncFetch2(
|
||||
file,
|
||||
function(stream, status) {
|
||||
if (!Components.isSuccessCode(status)) {
|
||||
deferred.reject(status);
|
||||
@ -72,7 +73,13 @@ function reference_fetch_file(path, test) {
|
||||
} else {
|
||||
deferred.resolve(result);
|
||||
}
|
||||
});
|
||||
},
|
||||
null, // aLoadingNode
|
||||
Services.scriptSecurityManager.getSystemPrincipal(),
|
||||
null, // aTriggeringPrincipal
|
||||
Ci.nsILoadInfo.SEC_NORMAL,
|
||||
Ci.nsIContentPolicy.TYPE_OTHER);
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
Components.utils.import("resource://gre/modules/osfile.jsm");
|
||||
Components.utils.import("resource://gre/modules/FileUtils.jsm");
|
||||
Components.utils.import("resource://gre/modules/NetUtil.jsm");
|
||||
Components.utils.import("resource://gre/modules/Services.jsm");
|
||||
Components.utils.import("resource://gre/modules/Promise.jsm");
|
||||
Components.utils.import("resource://gre/modules/Task.jsm");
|
||||
|
||||
@ -28,7 +29,8 @@ let EXISTING_FILE = "test_osfile_async_copy.js";
|
||||
let reference_fetch_file = function reference_fetch_file(path) {
|
||||
let promise = Promise.defer();
|
||||
let file = new FileUtils.File(path);
|
||||
NetUtil.asyncFetch(file,
|
||||
NetUtil.asyncFetch2(
|
||||
file,
|
||||
function(stream, status) {
|
||||
if (!Components.isSuccessCode(status)) {
|
||||
promise.reject(status);
|
||||
@ -46,7 +48,13 @@ let reference_fetch_file = function reference_fetch_file(path) {
|
||||
} else {
|
||||
promise.resolve(result);
|
||||
}
|
||||
});
|
||||
},
|
||||
null, // aLoadingNode
|
||||
Services.scriptSecurityManager.getSystemPrincipal(),
|
||||
null, // aTriggeringPrincipal
|
||||
Ci.nsILoadInfo.SEC_NORMAL,
|
||||
Ci.nsIContentPolicy.TYPE_OTHER);
|
||||
|
||||
return promise.promise;
|
||||
};
|
||||
|
||||
|
@ -159,7 +159,15 @@ var resolveCallback = SpecialPowers.wrapCallbackObject({
|
||||
// The proxyChannel needs to move to at least on-modify-request to
|
||||
// have valid ProxyInfo, but we use OnStartRequest during startup()
|
||||
// for simplicity.
|
||||
proxyChannel = ioService.newChannel(proxiedHost, null, null);
|
||||
proxyChannel = ioService.newChannel2(proxiedHost,
|
||||
null,
|
||||
null,
|
||||
null, // aLoadingNode
|
||||
SpecialPowers.Services.
|
||||
scriptSecurityManager.getSystemPrincipal(),
|
||||
null, // aTriggeringPrincipal
|
||||
Ci.nsILoadInfo.SEC_NORMAL,
|
||||
Ci.nsIContentPolicy.TYPE_OTHER);
|
||||
proxyChannel.asyncOpen(SpecialPowers.wrapCallbackObject(new proxyChannelListener()), null);
|
||||
}
|
||||
});
|
||||
@ -891,8 +899,24 @@ function doTests() {
|
||||
is(uname.value, "fill2user", "Checking returned username");
|
||||
is(pword.value, "fill2pass", "Checking returned password");
|
||||
|
||||
var channel1 = ioService.newChannel("http://example.com", null, null);
|
||||
var channel2 = ioService.newChannel("http://example2.com", null, null);
|
||||
var channel1 = ioService.newChannel2("http://example.com",
|
||||
null,
|
||||
null,
|
||||
null, // aLoadingNode
|
||||
SpecialPowers.Services.
|
||||
scriptSecurityManager.getSystemPrincipal(),
|
||||
null, // aTriggeringPrincipal
|
||||
Ci.nsILoadInfo.SEC_NORMAL,
|
||||
Ci.nsIContentPolicy.TYPE_OTHER);
|
||||
var channel2 = ioService.newChannel2("http://example2.com",
|
||||
null,
|
||||
null,
|
||||
null, // aLoadingNode
|
||||
SpecialPowers.Services.
|
||||
scriptSecurityManager.getSystemPrincipal(),
|
||||
null, // aTriggeringPrincipal
|
||||
Ci.nsILoadInfo.SEC_NORMAL,
|
||||
Ci.nsIContentPolicy.TYPE_OTHER);
|
||||
|
||||
var level = Ci.nsIAuthPrompt2.LEVEL_NONE;
|
||||
|
||||
|
@ -1165,7 +1165,14 @@ function runTests() {
|
||||
// promptAuth already tested via password manager but do a few specific things here.
|
||||
|
||||
|
||||
var channel = ioService.newChannel("http://example.com", null, null);
|
||||
var channel = ioService.newChannel2("http://example.com",
|
||||
null,
|
||||
null,
|
||||
null, // aLoadingNode
|
||||
SpecialPowers.Services.scriptSecurityManager.getSystemPrincipal(),
|
||||
null, // aTriggeringPrincipal
|
||||
Ci.nsILoadInfo.SEC_NORMAL,
|
||||
Ci.nsIContentPolicy.TYPE_OTHER);
|
||||
var level = Ci.nsIAuthPrompt2.LEVEL_NONE;
|
||||
var authinfo = {
|
||||
username : "",
|
||||
|
@ -38,12 +38,19 @@ add_test(function test_addParam() {
|
||||
engine.addParam("param-name", "param-value", null);
|
||||
|
||||
function readAsyncFile(aFile, aCallback) {
|
||||
NetUtil.asyncFetch(aFile, function(inputStream, status) {
|
||||
do_check_true(Components.isSuccessCode(status));
|
||||
NetUtil.asyncFetch2(
|
||||
aFile,
|
||||
function(inputStream, status) {
|
||||
do_check_true(Components.isSuccessCode(status));
|
||||
|
||||
let data = NetUtil.readInputStreamToString(inputStream, inputStream.available());
|
||||
aCallback(data);
|
||||
});
|
||||
let data = NetUtil.readInputStreamToString(inputStream, inputStream.available());
|
||||
aCallback(data);
|
||||
},
|
||||
null, // aLoadingNode
|
||||
Services.scriptSecurityManager.getSystemPrincipal(),
|
||||
null, // aTriggeringPrincipal
|
||||
Ci.nsILoadInfo.SEC_NORMAL,
|
||||
Ci.nsIContentPolicy.TYPE_DATAREQUEST);
|
||||
}
|
||||
|
||||
let observer = function(aSubject, aTopic, aData) {
|
||||
|
@ -66,7 +66,12 @@ function run_test() {
|
||||
function tryToSetCookie(obj) {
|
||||
let requestURI = Services.io.newURI(obj.request, null, null);
|
||||
let referrerURI = Services.io.newURI(obj.referrer, null, null);
|
||||
let requestChannel = Services.io.newChannelFromURI(requestURI);
|
||||
let requestChannel = Services.io.newChannelFromURI2(requestURI,
|
||||
null, // aLoadingNode
|
||||
Services.scriptSecurityManager.getSystemPrincipal(),
|
||||
null, // aTriggeringPrincipal
|
||||
Ci.nsILoadInfo.SEC_NORMAL,
|
||||
Ci.nsIContentPolicy.TYPE_OTHER);
|
||||
gCookieService.setCookieString(referrerURI, null, "Is there a cookie in my jar?", requestChannel);
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,14 @@ let CustomChromeProtocol = {
|
||||
|
||||
newChannel: function CCP_newChannel(aURI) {
|
||||
let url = "chrome:" + aURI.path;
|
||||
let ch = NetUtil.newChannel(url);
|
||||
let ch = NetUtil.newChannel2(url,
|
||||
null,
|
||||
null,
|
||||
null, // aLoadingNode
|
||||
Services.scriptSecurityManager.getSystemPrincipal(),
|
||||
null, // aTriggeringPrincipal
|
||||
Ci.nsILoadInfo.SEC_NORMAL,
|
||||
Ci.nsIContentPolicy.TYPE_OTHER);
|
||||
ch.originalURI = aURI;
|
||||
return ch;
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user