Follow-on fix for bug 457825. Use sheet principal for agent and user sheets. r=dbaron...
[wine-gecko.git] / netwerk / test / unit / test_redirect_caching.js
blob1fda7c4abb6c5134a051b819f93f2e6e2baba70b
1 do_import_script("netwerk/test/httpserver/httpd.js");
3 var httpserver = null;
4 // Need to randomize, because apparently no one clears our cache
5 var randomPath = "/redirect/" + Math.random();
6 var randomURI = "http://localhost:4444" + randomPath;
8 function make_channel(url, callback, ctx) {
9   var ios = Cc["@mozilla.org/network/io-service;1"].
10             getService(Ci.nsIIOService);
11   return ios.newChannel(url, "", null);
14 const responseBody = "response body";
16 function redirectHandler(metadata, response)
18   response.setStatusLine(metadata.httpVersion, 301, "Moved");
19   response.setHeader("Location", "http://localhost:4444/content", false);
20   return;
23 function contentHandler(metadata, response)
25   response.setHeader("Content-Type", "text/plain");
26   response.bodyOutputStream.write(responseBody, responseBody.length);
29 function firstTimeThrough(request, buffer)
31   do_check_eq(buffer, responseBody);
32   var chan = make_channel(randomURI);
33   chan.loadFlags |= Ci.nsICachingChannel.LOAD_ONLY_FROM_CACHE;
34   chan.asyncOpen(new ChannelListener(finish_test, null), null);
37 function finish_test(request, buffer)
39   httpserver.stop();
40   do_check_eq(buffer, responseBody);
41   do_test_finished();
44 function run_test()
46   httpserver = new nsHttpServer();
47   httpserver.registerPathHandler(randomPath, redirectHandler);
48   httpserver.registerPathHandler("/content", contentHandler);
49   httpserver.start(4444);
51   var chan = make_channel(randomURI);
52   chan.asyncOpen(new ChannelListener(firstTimeThrough, null), null);
53   do_test_pending();