Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
michael@0 | 1 | |
michael@0 | 2 | Cu.import("resource://testing-common/httpd.js"); |
michael@0 | 3 | |
michael@0 | 4 | var httpserver = new HttpServer(); |
michael@0 | 5 | var testpath = "/simple"; |
michael@0 | 6 | var httpbody = "<?xml version='1.0' ?><root>0123456789</root>"; |
michael@0 | 7 | |
michael@0 | 8 | function createXHR(async) |
michael@0 | 9 | { |
michael@0 | 10 | var xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"] |
michael@0 | 11 | .createInstance(Ci.nsIXMLHttpRequest); |
michael@0 | 12 | xhr.open("GET", "http://localhost:" + |
michael@0 | 13 | httpserver.identity.primaryPort + testpath, async); |
michael@0 | 14 | return xhr; |
michael@0 | 15 | } |
michael@0 | 16 | |
michael@0 | 17 | function checkResults(xhr) |
michael@0 | 18 | { |
michael@0 | 19 | if (xhr.readyState != 4) |
michael@0 | 20 | return false; |
michael@0 | 21 | |
michael@0 | 22 | do_check_eq(xhr.status, 200); |
michael@0 | 23 | do_check_eq(xhr.responseText, httpbody); |
michael@0 | 24 | |
michael@0 | 25 | var root_node = xhr.responseXML.getElementsByTagName('root').item(0); |
michael@0 | 26 | do_check_eq(root_node.firstChild.data, "0123456789"); |
michael@0 | 27 | return true; |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | function run_test() |
michael@0 | 31 | { |
michael@0 | 32 | httpserver.registerPathHandler(testpath, serverHandler); |
michael@0 | 33 | httpserver.start(-1); |
michael@0 | 34 | |
michael@0 | 35 | // Test sync XHR sending |
michael@0 | 36 | var sync = createXHR(false); |
michael@0 | 37 | sync.send(null); |
michael@0 | 38 | checkResults(sync); |
michael@0 | 39 | |
michael@0 | 40 | // Test async XHR sending |
michael@0 | 41 | let async = createXHR(true); |
michael@0 | 42 | async.addEventListener("readystatechange", function(event) { |
michael@0 | 43 | if (checkResults(async)) |
michael@0 | 44 | httpserver.stop(do_test_finished); |
michael@0 | 45 | }, false); |
michael@0 | 46 | async.send(null); |
michael@0 | 47 | do_test_pending(); |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | function serverHandler(metadata, response) |
michael@0 | 51 | { |
michael@0 | 52 | response.setHeader("Content-Type", "text/xml", false); |
michael@0 | 53 | response.bodyOutputStream.write(httpbody, httpbody.length); |
michael@0 | 54 | } |