Bug 1126004 - Make JS callers of ios.newChannel call ios.newChannel2 in toolkit/components/places -tests (r=mak)

This commit is contained in:
Christoph Kerschbaumer 2015-02-06 13:54:45 -08:00
parent 0a5e6b3b13
commit 51db0efbba
4 changed files with 61 additions and 25 deletions

View File

@ -30,26 +30,33 @@ function test() {
});
function getIconFile(aCallback) {
NetUtil.asyncFetch(favIconLocation, function(inputStream, status) {
if (!Components.isSuccessCode(status)) {
ok(false, "Could not get the icon file");
// Handle error.
return;
}
NetUtil.asyncFetch2(
favIconLocation,
function(inputStream, status) {
if (!Components.isSuccessCode(status)) {
ok(false, "Could not get the icon file");
// Handle error.
return;
}
// Check the returned size versus the expected size.
let size = inputStream.available();
favIconData = NetUtil.readInputStreamToString(inputStream, size);
is(size, favIconData.length, "Check correct icon size");
// Check that the favicon loaded correctly before starting the actual tests.
is(favIconData.length, 344, "Check correct icon length (344)");
// Check the returned size versus the expected size.
let size = inputStream.available();
favIconData = NetUtil.readInputStreamToString(inputStream, size);
is(size, favIconData.length, "Check correct icon size");
// Check that the favicon loaded correctly before starting the actual tests.
is(favIconData.length, 344, "Check correct icon length (344)");
if (aCallback) {
aCallback();
} else {
finish();
}
});
if (aCallback) {
aCallback();
} else {
finish();
}
},
null, // aLoadingNode
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_IMAGE);
}
function testNormal(aWindow, aCallback) {

View File

@ -58,15 +58,26 @@ function run_test()
getService(Ci.nsIIOService);
// Test that the default icon has the content type of image/png.
let (channel = ios.newChannelFromURI(fs.defaultFavicon)) {
let (channel = ios.newChannelFromURI2(fs.defaultFavicon,
null, // aLoadingNode
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_IMAGE)) {
channel.asyncOpen(new streamListener("image/png"), null);
do_test_pending();
}
// Test URI that we don't know anything about. Will end up being the default
// icon, so expect image/png.
let (channel = ios.newChannel(moz_anno_favicon_prefix + "http://mozilla.org",
null, null)) {
let (channel = ios.newChannel2(moz_anno_favicon_prefix + "http://mozilla.org",
null,
null,
null, // aLoadingNode
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_IMAGE)) {
channel.asyncOpen(new streamListener("image/png"), null);
do_test_pending();
}
@ -78,8 +89,14 @@ function run_test()
(Date.now() + 60 * 60 * 24 * 1000) * 1000);
// Open the channel
let channel = ios.newChannel(moz_anno_favicon_prefix + testURI.spec, null,
null);
let channel = ios.newChannel2(moz_anno_favicon_prefix + testURI.spec,
null,
null,
null, // aLoadingNode
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_IMAGE);
channel.asyncOpen(new streamListener("image/png"), null);
do_test_pending();
}

View File

@ -62,7 +62,12 @@ function PathHandler(aMeta, aResponse, aChannelEvent, aRedirURL) {
function run_test() {
do_test_pending();
var chan = NetUtil.ioService.newChannelFromURI(uri(PERMA_REDIR_URL));
var chan = NetUtil.ioService.newChannelFromURI2(uri(PERMA_REDIR_URL),
null, // aLoadingNode
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
var listener = new ChannelListener();
chan.notificationCallbacks = listener;
chan.asyncOpen(listener, null);

View File

@ -19,11 +19,18 @@
<pre id="test">
<script class="testbody" type="text/javascript">
Cu.import("resource://gre/modules/Services.jsm");
/** Test for Bug 411966 **/
addVisits(typedURI, function() {
histsvc.markPageAsTyped(typedURI);
var clickedLinkChannel = ios.newChannelFromURI(clickedLinkURI);
var clickedLinkChannel = ios.newChannelFromURI2(clickedLinkURI,
null, // aLoadingNode
Services.scriptSecurityManager.getSystemPrincipal(),
null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER);
clickedLinkChannel.QueryInterface(Ci.nsIHttpChannel).referrer = typedURI;
var listener = new StreamListener(clickedLinkChannel, checkDB);
clickedLinkChannel.notificationCallbacks = listener;