Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | Components.utils.import("resource://testing-common/httpd.js"); |
michael@0 | 6 | |
michael@0 | 7 | var server = new HttpServer(); |
michael@0 | 8 | server.start(-1); |
michael@0 | 9 | |
michael@0 | 10 | const SERVER_PORT = server.identity.primaryPort; |
michael@0 | 11 | const HTTP_BASE = "http://localhost:" + SERVER_PORT; |
michael@0 | 12 | const redirectPath = "/redirect"; |
michael@0 | 13 | const headerCheckPath = "/headerCheck"; |
michael@0 | 14 | const redirectURL = HTTP_BASE + redirectPath; |
michael@0 | 15 | const headerCheckURL = HTTP_BASE + headerCheckPath; |
michael@0 | 16 | |
michael@0 | 17 | function redirectHandler(metadata, response) { |
michael@0 | 18 | response.setStatusLine(metadata.httpVersion, 302, "Found"); |
michael@0 | 19 | response.setHeader("Location", headerCheckURL, false); |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | function headerCheckHandler(metadata, response) { |
michael@0 | 23 | try { |
michael@0 | 24 | let headerValue = metadata.getHeader("X-Custom-Header"); |
michael@0 | 25 | do_check_eq(headerValue, "present"); |
michael@0 | 26 | } catch(e) { |
michael@0 | 27 | do_throw("No header present after redirect"); |
michael@0 | 28 | } |
michael@0 | 29 | try { |
michael@0 | 30 | metadata.getHeader("X-Unwanted-Header"); |
michael@0 | 31 | do_throw("Unwanted header present after redirect"); |
michael@0 | 32 | } catch (x) { |
michael@0 | 33 | } |
michael@0 | 34 | response.setStatusLine(metadata.httpVersion, 200, "OK"); |
michael@0 | 35 | response.setHeader("Content-Type", "text/plain"); |
michael@0 | 36 | response.write(""); |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | function run_test() { |
michael@0 | 40 | server.registerPathHandler(redirectPath, redirectHandler); |
michael@0 | 41 | server.registerPathHandler(headerCheckPath, headerCheckHandler); |
michael@0 | 42 | |
michael@0 | 43 | do_test_pending(); |
michael@0 | 44 | var request = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"] |
michael@0 | 45 | .createInstance(Components.interfaces.nsIXMLHttpRequest); |
michael@0 | 46 | request.open("GET", redirectURL, true); |
michael@0 | 47 | request.setRequestHeader("X-Custom-Header", "present"); |
michael@0 | 48 | request.addEventListener("readystatechange", function() { |
michael@0 | 49 | if (request.readyState == 4) { |
michael@0 | 50 | do_check_eq(request.status, 200); |
michael@0 | 51 | server.stop(do_test_finished); |
michael@0 | 52 | } |
michael@0 | 53 | }, false); |
michael@0 | 54 | request.send(); |
michael@0 | 55 | try { |
michael@0 | 56 | request.setRequestHeader("X-Unwanted-Header", "present"); |
michael@0 | 57 | do_throw("Shouldn't be able to set a header after send"); |
michael@0 | 58 | } catch (x) { |
michael@0 | 59 | } |
michael@0 | 60 | } |