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