Bug 1462806 - Extract is value from nsXMLContentSink r=smaug

Nodes copied from DOMParser document fragment would need to be
created with the proper custom element data.

CustomElementRegistry::IsCustomElementEnabled() is changed to allow
it to run in the test document.

MozReview-Commit-ID: 4GACDR8FIc7

--HG--
extra : rebase_source : 39da41dd1ca56bf62043418c503c526e2895254f
This commit is contained in:
Timothy Guan-tin Chien 2018-05-20 10:23:46 +08:00
Родитель cf07f127bc
Коммит e84b173ee2
4 изменённых файлов: 80 добавлений и 11 удалений

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

@ -300,7 +300,7 @@ CustomElementRegistry::IsCustomElementEnabled(nsIDocument* aDoc)
return true;
}
return XRE_IsParentProcess() && nsContentUtils::AllowXULXBLForPrincipal(aDoc->NodePrincipal());
return XRE_IsParentProcess() && aDoc->AllowXULXBL();
}
NS_IMETHODIMP

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

@ -14,6 +14,20 @@
<![CDATA[
SimpleTest.waitForExplicitFinish();
var gXULDOMParser = new DOMParser();
gXULDOMParser.forceEnableXULXBL();
function parseXULToFragment(str) {
let doc = gXULDOMParser.parseFromString(`
<box xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">${str}</box>`,
"application/xml");
// We use a range here so that we don't access the inner DOM elements from
// JavaScript before they are imported and inserted into a document.
let range = doc.createRange();
range.selectNodeContents(doc.firstChild);
return range.extractContents();
}
class TestCustomElement extends XULElement {
constructor() {
super();
@ -85,18 +99,25 @@
document.querySelector("#content").appendChild(element3);
is(element3.textContent, "foo", "Should have set the textContent");
ok(element3 instanceof TestCustomElement, "Should be an instance of TestCustomElement");
}
function parserBasicElementUpgrade() {
let element4 = document.getElementById("element4");
is(element4.textContent, "foo",
"Parser should have instantiated the custom element.");
document.querySelector("#content").appendChild(parseXULToFragment(`<test-custom-element />`));
let element4 = document.querySelector("#content").lastChild;
is(element4.localName, "test-custom-element", "Should see the right tag");
is(element4.namespaceURI, XUL_NS, "Should have set the right namespace");
is(element4.textContent, "foo", "Should have set the textContent");
ok(element4 instanceof TestCustomElement, "Should be an instance of TestCustomElement");
}
function parserBasicElementUpgrade() {
let element = document.getElementById("element4");
is(element.textContent, "foo",
"Parser should have instantiated the custom element.");
ok(element instanceof TestCustomElement, "Should be an instance of TestCustomElement");
}
function tagNameWithoutDash() {
let element5 = document.getElementById("element5");
ok(element5 instanceof TestWithoutDash, "Should be an instance of TestWithoutDash");
let element = document.getElementById("element5");
ok(element instanceof TestWithoutDash, "Should be an instance of TestWithoutDash");
}
function upgradeAfterDefine() {
@ -141,6 +162,13 @@
document.querySelector("#content").appendChild(element3);
is(element3.textContent, "baz", "Should have set the textContent");
ok(element3 instanceof TestCustomBuiltInElement, "Should be an instance of TestCustomBuiltInElement");
document.querySelector("#content").appendChild(parseXULToFragment(`<axulelement is="test-built-in-element" />`))
let element4 = document.querySelector("#content").lastChild;
is(element4.localName, "axulelement", "Should see the right tag");
is(element4.namespaceURI, XUL_NS, "Should have set the right namespace");
is(element4.textContent, "baz", "Should have set the textContent");
ok(element4 instanceof TestCustomBuiltInElement, "Should be an instance of TestCustomBuiltInElement");
}
function parserBasicElementUpgradeBuiltIn() {
@ -172,6 +200,13 @@
document.querySelector("#content").appendChild(element3);
is(element3.textContent, "quuz", "Should have set the textContent");
ok(element3 instanceof TestPopupExtendElement, "Should be an instance of TestPopupExtendElement");
document.querySelector("#content").appendChild(parseXULToFragment(`<popup is="test-popup-extend" />`))
let element4 = document.querySelector("#content").lastChild;
is(element4.localName, "popup", "Should see the right tag");
is(element4.namespaceURI, XUL_NS, "Should have set the right namespace");
is(element4.textContent, "quuz", "Should have set the textContent");
ok(element4 instanceof TestPopupExtendElement, "Should be an instance of TestPopupExtendElement");
}
function parserSubclassElementUpgradeBuiltIn() {
@ -247,6 +282,14 @@
is(element3.textContent, "quux", "Should have set the textContent");
ok(element3 instanceof TestWithoutDashExtended, "Should be an instance of TestWithoutDashExtended");
ok(element3 instanceof TestWithoutDash, "Should be an instance of TestWithoutDash");
document.querySelector("#content").appendChild(parseXULToFragment(`<testwithoutdash is="testwithoutdash-extended" />`))
let element4 = document.querySelector("#content").lastChild;
is(element4.localName, "testwithoutdash", "Should see the right tag");
is(element4.namespaceURI, XUL_NS, "Should have set the right namespace");
is(element4.textContent, "quux", "Should have set the textContent");
ok(element4 instanceof TestWithoutDashExtended, "Should be an instance of TestWithoutDashExtended");
ok(element4 instanceof TestWithoutDash, "Should be an instance of TestWithoutDash");
}
function nonCustomElementCreate() {

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

@ -461,6 +461,24 @@ nsXMLContentSink::SetParser(nsParserBase* aParser)
return NS_OK;
}
static bool
FindIsAttrValue(const char16_t** aAtts, const char16_t** aResult)
{
RefPtr<nsAtom> prefix, localName;
for (; *aAtts; aAtts += 2) {
int32_t nameSpaceID;
nsContentUtils::SplitExpatName(aAtts[0], getter_AddRefs(prefix),
getter_AddRefs(localName), &nameSpaceID);
if (nameSpaceID == kNameSpaceID_None && localName == nsGkAtoms::is) {
*aResult = aAtts[1];
return true;
}
}
return false;
}
nsresult
nsXMLContentSink::CreateElement(const char16_t** aAtts, uint32_t aAttsCount,
mozilla::dom::NodeInfo* aNodeInfo, uint32_t aLineNumber,
@ -475,7 +493,17 @@ nsXMLContentSink::CreateElement(const char16_t** aAtts, uint32_t aAttsCount,
RefPtr<mozilla::dom::NodeInfo> ni = aNodeInfo;
RefPtr<Element> content;
const char16_t* is = nullptr;
if ((aNodeInfo->NamespaceEquals(kNameSpaceID_XHTML) ||
aNodeInfo->NamespaceEquals(kNameSpaceID_XUL)) &&
FindIsAttrValue(aAtts, &is)) {
const nsDependentString isStr(is);
rv = NS_NewElement(getter_AddRefs(content), ni.forget(), aFromParser, &isStr);
} else {
rv = NS_NewElement(getter_AddRefs(content), ni.forget(), aFromParser);
}
NS_ENSURE_SUCCESS(rv, rv);
if (aNodeInfo->Equals(nsGkAtoms::script, kNameSpaceID_XHTML)

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

@ -1,4 +1,2 @@
[parser-uses-create-an-element-for-a-token-svg.svg]
[XML parser should create custom built-in elements.]
expected: FAIL