mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 15:23:51 +00:00
Bug 1487113 - nsICacheInfoChannel.preferAlternativeDataType() should expose alt-data as optional if required - tests, r=valentin
Differential Revision: https://phabricator.services.mozilla.com/D20201 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
52efd15b05
commit
aff51ab9f6
@ -20,7 +20,7 @@ XPCOMUtils.defineLazyGetter(this, "URL", function() {
|
||||
|
||||
var httpServer = null;
|
||||
|
||||
function make_channel(url, callback, ctx) {
|
||||
function make_channel(url) {
|
||||
return NetUtil.newChannel({uri: url, loadUsingSystemPrincipal: true});
|
||||
}
|
||||
|
||||
@ -90,10 +90,10 @@ function openAltChannel()
|
||||
var cc = chan.QueryInterface(Ci.nsICacheInfoChannel);
|
||||
cc.preferAlternativeDataType(altContentType, "", true);
|
||||
|
||||
chan.asyncOpen(listener);
|
||||
chan.asyncOpen(altDataListener);
|
||||
}
|
||||
|
||||
var listener = {
|
||||
var altDataListener = {
|
||||
buffer: "",
|
||||
onStartRequest: function(request, context) { },
|
||||
onDataAvailable: function(request, context, stream, offset, count) {
|
||||
@ -114,6 +114,54 @@ var listener = {
|
||||
Assert.equal(cc.alternativeDataType, altContentType);
|
||||
Assert.equal(this.buffer.length, altContent.length);
|
||||
Assert.equal(this.buffer, altContent);
|
||||
httpServer.stop(do_test_finished);
|
||||
openAltChannelWithOriginalContent();
|
||||
},
|
||||
};
|
||||
|
||||
function openAltChannelWithOriginalContent()
|
||||
{
|
||||
var chan = make_channel(URL);
|
||||
var cc = chan.QueryInterface(Ci.nsICacheInfoChannel);
|
||||
cc.preferAlternativeDataType(altContentType, "", false);
|
||||
|
||||
chan.asyncOpen(originalListener);
|
||||
}
|
||||
|
||||
var originalListener = {
|
||||
buffer: "",
|
||||
onStartRequest: function(request, context) { },
|
||||
onDataAvailable: function(request, context, stream, offset, count) {
|
||||
let string = NetUtil.readInputStreamToString(stream, count);
|
||||
this.buffer += string;
|
||||
},
|
||||
onStopRequest: function(request, context, status) {
|
||||
var cc = request.QueryInterface(Ci.nsICacheInfoChannel);
|
||||
Assert.equal(cc.alternativeDataType, altContentType);
|
||||
Assert.equal(this.buffer.length, responseContent.length);
|
||||
Assert.equal(this.buffer, responseContent);
|
||||
testAltDataStream(cc);
|
||||
},
|
||||
};
|
||||
|
||||
function testAltDataStream(cc)
|
||||
{
|
||||
cc.getAltDataInputStream(altContentType, {
|
||||
onInputStreamReady: function(aInputStream) {
|
||||
executeSoon(() => readAltDataInputStream(aInputStream));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function readAltDataInputStream(aInputStream)
|
||||
{
|
||||
// We expect the async stream length to match the expected content.
|
||||
// If the test times out, it's probably because of this.
|
||||
try {
|
||||
let data = read_stream(aInputStream, altContent.length);
|
||||
Assert.equal(data, altContent);
|
||||
httpServer.stop(do_test_finished);
|
||||
} catch (e) {
|
||||
equal(e.result, Cr.NS_BASE_STREAM_WOULD_BLOCK);
|
||||
executeSoon(() => readAltDataInputStream(aInputStream));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user