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

--HG--
extra : rebase_source : cd0237553198182b00ff9c667a17271b23464567
This commit is contained in:
Xidorn Quan 2017-09-12 14:28:27 +10:00
Родитель be5b995e78
Коммит a0f7c55075
3 изменённых файлов: 54 добавлений и 1 удалений

Просмотреть файл

@ -463,7 +463,7 @@ DOMParser::SetUpDocument(DocumentFlavor aFlavor, nsIDOMDocument** aResult)
// 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();
}

Просмотреть файл

@ -174,6 +174,7 @@ skip-if = !stylo # This is a stylo test; gecko isn't deterministic here
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]

Просмотреть файл

@ -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>