netwerk/test/unit/test_nojsredir.js

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 Cu.import("resource://testing-common/httpd.js");
michael@0 2
michael@0 3 var httpserver = new HttpServer();
michael@0 4 var index = 0;
michael@0 5 var tests = [
michael@0 6 {url : "/test/test",
michael@0 7 datalen : 16},
michael@0 8
michael@0 9 // Test that the http channel fails and the response body is suppressed
michael@0 10 // bug 255119
michael@0 11 {url: "/test/test",
michael@0 12 responseheader: [ "Location: javascript:alert()"],
michael@0 13 flags : CL_EXPECT_FAILURE,
michael@0 14 datalen : 0},
michael@0 15 ];
michael@0 16
michael@0 17 function setupChannel(url) {
michael@0 18 var ios = Components.classes["@mozilla.org/network/io-service;1"].
michael@0 19 getService(Ci.nsIIOService);
michael@0 20 var chan = ios.newChannel("http://localhost:" +
michael@0 21 httpserver.identity.primaryPort + url, "", null);
michael@0 22 return chan;
michael@0 23 }
michael@0 24
michael@0 25 function startIter() {
michael@0 26 var channel = setupChannel(tests[index].url);
michael@0 27 channel.asyncOpen(new ChannelListener(completeIter, channel, tests[index].flags), null);
michael@0 28 }
michael@0 29
michael@0 30 function completeIter(request, data, ctx) {
michael@0 31 do_check_true(data.length == tests[index].datalen);
michael@0 32 if (++index < tests.length) {
michael@0 33 startIter();
michael@0 34 } else {
michael@0 35 httpserver.stop(do_test_finished);
michael@0 36 }
michael@0 37 }
michael@0 38
michael@0 39 function run_test() {
michael@0 40 httpserver.registerPathHandler("/test/test", handler);
michael@0 41 httpserver.start(-1);
michael@0 42
michael@0 43 startIter();
michael@0 44 do_test_pending();
michael@0 45 }
michael@0 46
michael@0 47 function handler(metadata, response) {
michael@0 48 var body = "thequickbrownfox";
michael@0 49 response.setHeader("Content-Type", "text/plain", false);
michael@0 50
michael@0 51 var header = tests[index].responseheader;
michael@0 52 if (header != undefined) {
michael@0 53 for (var i = 0; i < header.length; i++) {
michael@0 54 var splitHdr = header[i].split(": ");
michael@0 55 response.setHeader(splitHdr[0], splitHdr[1], false);
michael@0 56 }
michael@0 57 }
michael@0 58
michael@0 59 response.setStatusLine(metadata.httpVersion, 302, "Redirected");
michael@0 60 response.bodyOutputStream.write(body, body.length);
michael@0 61 }
michael@0 62

mercurial