Bug 1398619 - Correctly inherit backend for document created by DOMParser, and add test for it. r?bholley
The old code doesn't work because mScriptHandlingObject is a nsWeakPtr,
which cannot be casted to nsPIDOMWindowInner directly.
Since scriptHandlingObject is a strong reference to the same object, we
can just try casting that.
MozReview-Commit-ID: JRBs5N6xxc0
--- a/dom/base/DOMParser.cpp
+++ b/dom/base/DOMParser.cpp
@@ -458,17 +458,17 @@ DOMParser::SetUpDocument(DocumentFlavor
nsCOMPtr<nsIPrincipal> prin = NullPrincipal::Create();
rv = Init(prin, nullptr, nullptr, scriptHandlingObject);
NS_ENSURE_SUCCESS(rv, rv);
}
// Try to inherit a style backend.
auto styleBackend = StyleBackendType::None;
- nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(mScriptHandlingObject);
+ nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(scriptHandlingObject);
if (window && window->GetExtantDoc()) {
styleBackend = window->GetExtantDoc()->GetStyleBackendType();
}
NS_ASSERTION(mPrincipal, "Must have principal by now");
NS_ASSERTION(mDocumentURI, "Must have document URI by now");
return NS_NewDOMDocument(aResult, EmptyString(), EmptyString(), nullptr,
--- a/layout/style/test/mochitest.ini
+++ b/layout/style/test/mochitest.ini
@@ -169,16 +169,17 @@ skip-if = !stylo # This is a stylo test;
[test_ch_ex_no_infloops.html]
[test_change_hint_optimizations.html]
[test_clip-path_polygon.html]
[test_color_rounding.html]
[test_compute_data_with_start_struct.html]
skip-if = toolkit == 'android'
[test_computed_style.html]
[test_computed_style_bfcache_display_none.html]
+[test_computed_style_in_created_document.html]
[test_computed_style_min_size_auto.html]
[test_computed_style_no_pseudo.html]
[test_computed_style_prefs.html]
[test_condition_text.html]
[test_condition_text_assignment.html]
[test_contain_formatting_context.html]
[test_counter_descriptor_storage.html]
[test_counter_style.html]
new file mode 100644
--- /dev/null
+++ b/layout/style/test/test_computed_style_in_created_document.html
@@ -0,0 +1,52 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Test for bug 1398619</title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
+</head>
+<body>
+<script>
+SimpleTest.waitForExplicitFinish();
+let referenceFontSize = getComputedStyle(document.body).fontSize;
+
+function checkComputedStyle(desc, doc) {
+ try {
+ let fontSize = getComputedStyle(doc.body).fontSize;
+ is(fontSize, referenceFontSize, `${desc}: get computed font-size`);
+ } catch (e) {
+ ok(false, `${desc}: fail to get computed font-size, ${e}`);
+ }
+}
+
+async function runTest() {
+ // DOMParser
+ {
+ let parser = new DOMParser();
+ let doc = parser.parseFromString("<body>", "text/html");
+ checkComputedStyle("DOMParser", doc);
+ }
+ // DOMImplementation
+ {
+ let doc = document.implementation.createHTMLDocument("");
+ checkComputedStyle("DOMImplementation", doc);
+ }
+ // XMLHttpRequest
+ {
+ let xhr = new XMLHttpRequest();
+ xhr.open("GET", "empty.html");
+ xhr.responseType = "document";
+ let promise = new Promise(resolve => {
+ xhr.onload = resolve;
+ });
+ xhr.send();
+ await promise;
+ checkComputedStyle("XMLHttpRequest", xhr.responseXML);
+ }
+}
+runTest()
+ .catch(e => ok(false, `Exception: ${e}`))
+ .then(() => SimpleTest.finish());
+</script>
+</body>
+</html>