Bug 1232899 - Convert JS callsites to use open2 within netwerk/test (r=mcmanus)

This commit is contained in:
Christoph Kerschbaumer 2015-12-17 12:47:01 -08:00
Родитель 55c5c7efa6
Коммит a09beee411
5 изменённых файлов: 27 добавлений и 53 удалений

Просмотреть файл

@ -4,7 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Cu.import("resource://testing-common/httpd.js");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/NetUtil.jsm");
const gDashboard = Cc['@mozilla.org/network/dashboard;1']
.getService(Ci.nsIDashboard);
@ -85,14 +85,9 @@ function run_test() {
let uri = ioService.newURI("http://localhost:" + gHttpServer.identity.primaryPort,
null, null);
let channel = ioService.newChannelFromURI2(uri,
null, // aLoadingNode
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
let channel = NetUtil.newChannel({uri: uri, loadUsingSystemPrincipal: true});
channel.open();
channel.open2();
gServerSocket.init(-1, true, -1);

Просмотреть файл

@ -5,6 +5,7 @@
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/NetUtil.jsm");
var contentSecManager = Cc["@mozilla.org/contentsecuritymanager;1"]
.getService(Ci.nsIContentSecurityManager);
@ -74,12 +75,7 @@ ProtocolHandler.prototype = {
var file = do_get_file("test_bug894586.js", false);
do_check_true(file.exists());
var url = Services.io.newFileURI(file);
return Services.io.newChannelFromURI2(url,
null, // aLoadingNode
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER).open();
return NetUtil.newChannel({uri: url, loadUsingSystemPrincipal: true}).open2();
},
open2: function() {
// throws an error if security checks fail

Просмотреть файл

@ -1,5 +1,5 @@
// test that things that are expected to be in gre-resources are still there
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/NetUtil.jsm");
var ios = Cc["@mozilla.org/network/io-service;1"]. getService(Ci.nsIIOService);
@ -13,16 +13,12 @@ function wrapInputStream(input)
}
function check_file(file) {
var channel = ios.newChannel2("resource://gre-resources/"+file,
null,
null,
null, // aLoadingNode
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
var channel = NetUtil.newChannel({
uri: "resource://gre-resources/"+file,
loadUsingSystemPrincipal: true
});
try {
let instr = wrapInputStream(channel.open());
let instr = wrapInputStream(channel.open2());
do_check_true(instr.read(1024).length > 0)
} catch (e) {
do_throw("Failed to read " + file + " from gre-resources:"+e)

Просмотреть файл

@ -1,5 +1,5 @@
// Tests bug 304414
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/NetUtil.jsm");
const PR_RDONLY = 0x1; // see prio.h
@ -69,12 +69,10 @@ function stream_from_channel(file) {
var ios = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var uri = ios.newFileURI(file);
return ios.newChannelFromURI2(uri,
null, // aLoadingNode
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER).open();
return NetUtil.newChannel({
uri: uri,
loadUsingSystemPrincipal: true
}).open2();
}
function run_test() {

Просмотреть файл

@ -2,7 +2,7 @@
// See https://bugzilla.mozilla.org/show_bug.cgi?id=372486
Cu.import("resource://testing-common/httpd.js");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/NetUtil.jsm");
const NS_ERROR_IN_PROGRESS = 0x804b000f;
const NS_ERROR_ALREADY_OPENED = 0x804b0049;
@ -22,28 +22,17 @@ var httpserv = null;
// Utility functions
function makeChan(url) {
var ios = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService);
return chan = ios.newChannel2(url,
null,
null,
null, // aLoadingNode
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER)
.QueryInterface(Ci.nsIChannel);
return chan = NetUtil.newChannel({uri: url, loadUsingSystemPrincipal: true})
.QueryInterface(Ci.nsIChannel);
}
function new_file_channel(file) {
var ios = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService);
return ios.newChannelFromURI2(ios.newFileURI(file),
null, // aLoadingNode
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
return NetUtil.newChannel({
uri: ios.newFileURI(file),
loadUsingSystemPrincipal: true
});
}
@ -64,13 +53,13 @@ function check_throws(closure, error) {
function check_open_throws(error) {
check_throws(function() {
chan.open(listener, null);
chan.open2(listener);
}, error);
}
function check_async_open_throws(error) {
check_throws(function() {
chan.asyncOpen(listener, null);
chan.asyncOpen2(listener);
}, error);
}
@ -102,13 +91,13 @@ function after_channel_closed() {
function test_channel(createChanClosure) {
// First, synchronous reopening test
chan = createChanClosure();
var inputStream = chan.open();
var inputStream = chan.open2();
check_open_throws(NS_ERROR_IN_PROGRESS);
check_async_open_throws([NS_ERROR_IN_PROGRESS, NS_ERROR_ALREADY_OPENED]);
// Then, asynchronous one
chan = createChanClosure();
chan.asyncOpen(listener, null);
chan.asyncOpen2(listener);
check_open_throws(NS_ERROR_IN_PROGRESS);
check_async_open_throws(NS_ERROR_IN_PROGRESS);
}