mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 14:22:01 +00:00
Bug 610654 - TEST-UNEXPECTED-FAIL (randomorange) r=bz a=test-only
This commit is contained in:
parent
7b7ce2df63
commit
2f7e196ec1
@ -6,23 +6,29 @@ function getCacheService() {
|
||||
.getService(Components.interfaces.nsICacheService);
|
||||
}
|
||||
|
||||
function setupChannel(suffix, flags) {
|
||||
function setupChannel(suffix, xRequest, flags) {
|
||||
var ios = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Ci.nsIIOService);
|
||||
var chan = ios.newChannel("http://localhost:4444" + suffix, "", null);
|
||||
if (flags)
|
||||
chan.loadFlags |= flags;
|
||||
return chan;
|
||||
|
||||
var httpChan = chan.QueryInterface(Components.interfaces.nsIHttpChannel);
|
||||
httpChan.setRequestHeader("x-request", xRequest, false);
|
||||
|
||||
return httpChan;
|
||||
}
|
||||
|
||||
function Listener(response, finalResponse) {
|
||||
function Listener(response, finalResponse, chainedHandler) {
|
||||
this._response = response;
|
||||
this._finalResponse = finalResponse;
|
||||
this._chainedHandler = chainedHandler;
|
||||
}
|
||||
Listener.prototype = {
|
||||
_response: null,
|
||||
_buffer: null,
|
||||
_finalResponse: false,
|
||||
_chainedHandler: undefined,
|
||||
|
||||
QueryInterface: function(iid) {
|
||||
if (iid.equals(Components.interfaces.nsIStreamListener) ||
|
||||
@ -39,12 +45,13 @@ Listener.prototype = {
|
||||
this._buffer = this._buffer.concat(read_stream(stream, count));
|
||||
},
|
||||
onStopRequest: function (request, ctx, status) {
|
||||
var expected = "Response"+this._response;
|
||||
do_check_eq(this._buffer, expected);
|
||||
do_check_eq(this._buffer, this._response);
|
||||
if (this._finalResponse)
|
||||
do_timeout(10, function() {
|
||||
httpserver.stop(do_test_finished);
|
||||
});
|
||||
if (this._chainedHandler != undefined)
|
||||
do_timeout(10, handlers[this._chainedHandler]);
|
||||
}
|
||||
};
|
||||
|
||||
@ -59,27 +66,30 @@ function run_test() {
|
||||
getCacheService().evictEntries(
|
||||
Components.interfaces.nsICache.STORE_ANYWHERE);
|
||||
|
||||
var ch0 = setupChannel("/bug596443", Ci.nsIRequest.LOAD_BYPASS_CACHE);
|
||||
ch0.asyncOpen(new Listener(0), null);
|
||||
var ch0 = setupChannel("/bug596443", "Response0", Ci.nsIRequest.LOAD_BYPASS_CACHE);
|
||||
ch0.asyncOpen(new Listener("Response0", true), null);
|
||||
|
||||
var ch1 = setupChannel("/bug596443", Ci.nsIRequest.LOAD_BYPASS_CACHE);
|
||||
ch1.asyncOpen(new Listener(1), null);
|
||||
var ch1 = setupChannel("/bug596443", "Response1", Ci.nsIRequest.LOAD_BYPASS_CACHE);
|
||||
ch1.asyncOpen(new Listener("Response1", false), null);
|
||||
|
||||
var ch2 = setupChannel("/bug596443");
|
||||
ch2.asyncOpen(new Listener(1, true), null); // Note param: we expect this to come from cache
|
||||
var ch2 = setupChannel("/bug596443", "Should not be used");
|
||||
ch2.asyncOpen(new Listener("Response1", false, 0), null); // Note param: we expect this to come from cache
|
||||
|
||||
do_test_pending();
|
||||
}
|
||||
|
||||
// Sequence is as follows:
|
||||
//
|
||||
// We call the handler for the second request, firing the on**** calls
|
||||
// for the request. Necko calls CacheEntryAvailable which fires the on****
|
||||
// calls for the third request. OnStopRequest for the third request calls
|
||||
// the handler for first request, which finishes the test.
|
||||
//
|
||||
function triggerHandlers() {
|
||||
do_timeout(100, function() {
|
||||
do_timeout(100, initialHandlers[1]);
|
||||
do_timeout(100, initialHandlers[0]);
|
||||
});
|
||||
do_timeout(100, handlers[1]);
|
||||
}
|
||||
|
||||
var initialHandlers = [];
|
||||
var handlerNo = 0;
|
||||
var handlers = [];
|
||||
function handler(metadata, response) {
|
||||
var func = function(body) {
|
||||
return function() {
|
||||
@ -92,9 +102,9 @@ function handler(metadata, response) {
|
||||
}};
|
||||
|
||||
response.processAsync();
|
||||
initialHandlers[handlerNo] = func("Response"+handlerNo);
|
||||
handlerNo++;
|
||||
var request = metadata.getHeader("x-request");
|
||||
handlers.push(func(request));
|
||||
|
||||
if (handlerNo > 1)
|
||||
if (handlers.length > 1)
|
||||
triggerHandlers();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user