Bug 717566 - Remove use of parseFromStream in xpcshell head.js and android robocop_head.js. r=jmaher
--- a/dom/base/test/unit/test_range.js
+++ b/dom/base/test/unit/test_range.js
@@ -168,17 +168,20 @@ function getRange(aSourceNode, aFragment
}
/**
* Get the document for a given path, and clean it up for our tests.
*
* @param aPath The path to the local document.
*/
function getParsedDocument(aPath) {
- var doc = do_parse_document(aPath, "application/xml");
+ return do_parse_document(aPath, "application/xml").then(processParsedDocument);
+}
+
+function processParsedDocument(doc) {
do_check_true(doc.documentElement.localName != "parsererror");
do_check_true(doc instanceof C_i.nsIDOMXPathEvaluator);
do_check_true(doc instanceof C_i.nsIDOMDocument);
// Clean out whitespace.
var walker = doc.createTreeWalker(doc,
C_i.nsIDOMNodeFilter.SHOW_TEXT |
C_i.nsIDOMNodeFilter.SHOW_CDATA_SECTION,
@@ -209,17 +212,20 @@ function getParsedDocument(aPath) {
return doc;
}
/**
* Run the extraction tests.
*/
function run_extract_test() {
var filePath = "test_delete_range.xml";
- var doc = getParsedDocument(filePath);
+ getParsedDocument(filePath).then(do_extract_test);
+}
+
+function do_extract_test(doc) {
var tests = doc.getElementsByTagName("test");
// Run our deletion, extraction tests.
for (var i = 0; i < tests.length; i++) {
dump("Configuring for test " + i + "\n");
var currentTest = tests.item(i);
// Validate the test is properly formatted for what this harness expects.
@@ -328,17 +334,20 @@ function run_extract_test() {
}
}
/**
* Miscellaneous tests not covered above.
*/
function run_miscellaneous_tests() {
var filePath = "test_delete_range.xml";
- var doc = getParsedDocument(filePath);
+ getParsedDocument(filePath).then(do_miscellaneous_tests);
+}
+
+function do_miscellaneous_tests(doc) {
var tests = doc.getElementsByTagName("test");
// Let's try some invalid inputs to our DOM range and see what happens.
var currentTest = tests.item(0);
var baseSource = currentTest.firstChild;
var baseResult = baseSource.nextSibling;
var baseExtract = baseResult.nextSibling;
--- a/dom/base/test/unit/test_xmlserializer.js
+++ b/dom/base/test/unit/test_xmlserializer.js
@@ -2,69 +2,81 @@
/* 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/. */
function xmlEncode(aFile, aFlags, aCharset) {
if(aFlags == undefined) aFlags = 0;
if(aCharset == undefined) aCharset = "UTF-8";
- var doc = do_parse_document(aFile, "text/xml");
-
- var encoder = Components.classes["@mozilla.org/layout/documentEncoder;1?type=text/xml"]
- .createInstance(nsIDocumentEncoder);
- encoder.setCharset(aCharset);
- encoder.init(doc, "text/xml", aFlags);
- return encoder.encodeToString();
+ return do_parse_document(aFile, "text/xml").then(doc => {
+ var encoder = Components.classes["@mozilla.org/layout/documentEncoder;1?type=text/xml"]
+ .createInstance(nsIDocumentEncoder);
+ encoder.setCharset(aCharset);
+ encoder.init(doc, "text/xml", aFlags);
+ return encoder.encodeToString();
+ });
}
function run_test()
{
var result, expected;
const de = Components.interfaces.nsIDocumentEncoder;
- result = xmlEncode("1_original.xml", de.OutputLFLineBreak);
- expected =loadContentFile("1_result.xml");
- do_check_eq(expected, result);
+ xmlEncode("1_original.xml", de.OutputLFLineBreak).then(result => {
+ expected = loadContentFile("1_result.xml");
+ do_check_eq(expected, result);
+ });
- result = xmlEncode("2_original.xml", de.OutputLFLineBreak);
- expected = loadContentFile("2_result_1.xml");
- do_check_eq(expected, result);
+ xmlEncode("2_original.xml", de.OutputLFLineBreak).then(result => {
+ expected = loadContentFile("2_result_1.xml");
+ do_check_eq(expected, result);
+ });
- result = xmlEncode("2_original.xml", de.OutputCRLineBreak);
- expected = expected.replace(/\n/g, "\r");
- do_check_eq(expected, result);
+ xmlEncode("2_original.xml", de.OutputCRLineBreak).then(result => {
+ expected = expected.replace(/\n/g, "\r");
+ do_check_eq(expected, result);
+ });
- result = xmlEncode("2_original.xml", de.OutputLFLineBreak | de.OutputCRLineBreak);
- expected = expected.replace(/\r/mg, "\r\n");
- do_check_eq(expected, result);
+ xmlEncode("2_original.xml", de.OutputLFLineBreak | de.OutputCRLineBreak).then(result => {
+ expected = expected.replace(/\r/mg, "\r\n");
+ do_check_eq(expected, result);
+ });
- result = xmlEncode("2_original.xml", de.OutputLFLineBreak | de.OutputFormatted);
- expected = loadContentFile("2_result_2.xml");
- do_check_eq(expected, result);
+ xmlEncode("2_original.xml", de.OutputLFLineBreak | de.OutputFormatted).then(result => {
+ expected = loadContentFile("2_result_2.xml");
+ do_check_eq(expected, result);
+ });
- result = xmlEncode("2_original.xml", de.OutputLFLineBreak | de.OutputFormatted | de.OutputWrap);
- expected = loadContentFile("2_result_3.xml");
- do_check_eq(expected, result);
+ xmlEncode("2_original.xml", de.OutputLFLineBreak | de.OutputFormatted | de.OutputWrap).then(result => {
+ expected = loadContentFile("2_result_3.xml");
+ do_check_eq(expected, result);
+ });
- result = xmlEncode("2_original.xml", de.OutputLFLineBreak | de.OutputWrap);
- expected = loadContentFile("2_result_4.xml");
- do_check_eq(expected, result);
+ xmlEncode("2_original.xml", de.OutputLFLineBreak | de.OutputWrap).then(result => {
+ expected = loadContentFile("2_result_4.xml");
+ do_check_eq(expected, result);
+ });
- result = xmlEncode("3_original.xml", de.OutputLFLineBreak | de.OutputFormatted | de.OutputWrap);
- expected = loadContentFile("3_result.xml");
- do_check_eq(expected, result);
+ xmlEncode("3_original.xml", de.OutputLFLineBreak | de.OutputFormatted | de.OutputWrap).then(result => {
+ expected = loadContentFile("3_result.xml");
+ do_check_eq(expected, result);
+ });
- result = xmlEncode("3_original.xml", de.OutputLFLineBreak | de.OutputWrap);
- expected = loadContentFile("3_result_2.xml");
- do_check_eq(expected, result);
+ xmlEncode("3_original.xml", de.OutputLFLineBreak | de.OutputWrap).then(result => {
+ expected = loadContentFile("3_result_2.xml");
+ do_check_eq(expected, result);
+ });
// tests on namespaces
- var doc = do_parse_document("4_original.xml", "text/xml");
+ do_parse_document("4_original.xml", "text/xml").then(run_namespace_tests);
+}
+function run_namespace_tests(doc) {
+ const de = Components.interfaces.nsIDocumentEncoder;
var encoder = Components.classes["@mozilla.org/layout/documentEncoder;1?type=text/xml"]
.createInstance(nsIDocumentEncoder);
encoder.setCharset("UTF-8");
encoder.init(doc, "text/xml", de.OutputLFLineBreak);
result = encoder.encodeToString();
expected = loadContentFile("4_result_1.xml");
do_check_eq(expected, result);
@@ -92,10 +104,9 @@ function run_test()
expected = loadContentFile("4_result_5.xml");
do_check_eq(expected, result);
encoder.init(doc, "text/xml", de.OutputLFLineBreak | de.OutputWrap);
encoder.setWrapColumn(40);
result = encoder.encodeToString();
expected = loadContentFile("4_result_6.xml");
do_check_eq(expected, result);
-
}
--- a/mobile/android/tests/browser/robocop/robocop_head.js
+++ b/mobile/android/tests/browser/robocop/robocop_head.js
@@ -620,53 +620,16 @@ function do_get_cwd() {
function do_load_manifest(path) {
var lf = do_get_file(path);
const nsIComponentRegistrar = Components.interfaces.nsIComponentRegistrar;
do_check_true(Components.manager instanceof nsIComponentRegistrar);
Components.manager.autoRegister(lf);
}
/**
- * Parse a DOM document.
- *
- * @param aPath File path to the document.
- * @param aType Content type to use in DOMParser.
- *
- * @return nsIDOMDocument from the file.
- */
-function do_parse_document(aPath, aType) {
- switch (aType) {
- case "application/xhtml+xml":
- case "application/xml":
- case "text/xml":
- break;
-
- default:
- do_throw("type: expected application/xhtml+xml, application/xml or text/xml," +
- " got '" + aType + "'",
- Components.stack.caller);
- }
-
- var lf = do_get_file(aPath);
- const C_i = Components.interfaces;
- const parserClass = "@mozilla.org/xmlextras/domparser;1";
- const streamClass = "@mozilla.org/network/file-input-stream;1";
- var stream = Components.classes[streamClass]
- .createInstance(C_i.nsIFileInputStream);
- stream.init(lf, -1, -1, C_i.nsIFileInputStream.CLOSE_ON_EOF);
- var parser = Components.classes[parserClass]
- .createInstance(C_i.nsIDOMParser);
- var doc = parser.parseFromStream(stream, null, lf.fileSize, aType);
- parser = null;
- stream = null;
- lf = null;
- return doc;
-}
-
-/**
* Registers a function that will run when the test harness is done running all
* tests.
*
* @param aFunction
* The function to be called when the test harness has finished running.
*/
function do_register_cleanup(func) {
_dump("TEST-INFO | " + _TEST_FILE + " | " +
--- a/testing/xpcshell/head.js
+++ b/testing/xpcshell/head.js
@@ -18,16 +18,17 @@ var _pendingTimers = [];
var _profileInitialized = false;
// Register the testing-common resource protocol early, to have access to its
// modules.
_register_modules_protocol_handler();
var _Promise = Components.utils.import("resource://gre/modules/Promise.jsm", {}).Promise;
var _PromiseTestUtils = Components.utils.import("resource://testing-common/PromiseTestUtils.jsm", {}).PromiseTestUtils;
+Components.utils.importGlobalProperties(["XMLHttpRequest"]);
// Support a common assertion library, Assert.jsm.
var AssertCls = Components.utils.import("resource://testing-common/Assert.jsm", null).Assert;
// Pass a custom report function for xpcshell-test style reporting.
var Assert = new AssertCls(function(err, message, stack) {
if (err) {
do_report_result(false, err.message, err.stack);
} else {
@@ -1093,30 +1094,31 @@ function do_parse_document(aPath, aType)
break;
default:
do_throw("type: expected application/xhtml+xml, application/xml or text/xml," +
" got '" + aType + "'",
Components.stack.caller);
}
- var lf = do_get_file(aPath);
- const C_i = Components.interfaces;
- const parserClass = "@mozilla.org/xmlextras/domparser;1";
- const streamClass = "@mozilla.org/network/file-input-stream;1";
- var stream = Components.classes[streamClass]
- .createInstance(C_i.nsIFileInputStream);
- stream.init(lf, -1, -1, C_i.nsIFileInputStream.CLOSE_ON_EOF);
- var parser = Components.classes[parserClass]
- .createInstance(C_i.nsIDOMParser);
- var doc = parser.parseFromStream(stream, null, lf.fileSize, aType);
- parser = null;
- stream = null;
- lf = null;
- return doc;
+ let file = do_get_file(aPath),
+ ios = Components.classes['@mozilla.org/network/io-service;1']
+ .getService(Components.interfaces.nsIIOService),
+ url = ios.newFileURI(file).spec;
+ file = null;
+ return new Promise((resolve, reject) => {
+ let xhr = new XMLHttpRequest();
+ xhr.open("GET", url);
+ xhr.responseType = "document";
+ xhr.onerror = reject;
+ xhr.onload = () => {
+ resolve(xhr.response);
+ };
+ xhr.send();
+ });
}
/**
* Registers a function that will run when the test harness is done running all
* tests.
*
* @param aFunction
* The function to be called when the test harness has finished running.