From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- dom/base/test/unit/test_xhr_document.js | 42 +++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 dom/base/test/unit/test_xhr_document.js (limited to 'dom/base/test/unit/test_xhr_document.js') diff --git a/dom/base/test/unit/test_xhr_document.js b/dom/base/test/unit/test_xhr_document.js new file mode 100644 index 000000000..5a090d598 --- /dev/null +++ b/dom/base/test/unit/test_xhr_document.js @@ -0,0 +1,42 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +var Cc = Components.classes; +var Ci = Components.interfaces; +var Cu = Components.utils; + +Cu.import("resource://testing-common/httpd.js"); +Cu.import("resource://gre/modules/NetUtil.jsm"); + +var server = new HttpServer(); +server.start(-1); + +var docbody = ''; + +function handler(metadata, response) { + let body = NetUtil.readInputStreamToString(metadata.bodyInputStream, + metadata.bodyInputStream.available()); + response.setStatusLine(metadata.httpVersion, 200, "OK"); + response.write(body, body.length); +} + +function run_test() { + do_test_pending(); + server.registerPathHandler("/foo", handler); + + var parser = Cc["@mozilla.org/xmlextras/domparser;1"].createInstance(Ci.nsIDOMParser); + parser.init(); + let doc = parser.parseFromString(docbody, "text/html"); + let xhr = Cc['@mozilla.org/xmlextras/xmlhttprequest;1'].createInstance(Ci.nsIXMLHttpRequest); + xhr.onload = function() { + do_check_eq(xhr.responseText, docbody); + server.stop(do_test_finished); + }; + xhr.onerror = function() { + do_check_false(false); + server.stop(do_test_finished); + }; + xhr.open("POST", "http://localhost:" + server.identity.primaryPort + "/foo", true); + xhr.send(doc); +} -- cgit v1.2.3