Commit 089c67c2 authored by tkent's avatar tkent Committed by Commit bot

[DOM] Fix null namespace handling in Node.isDefaultNamespace().

- Fix the implementation bug.
- Remove obsolete test in the legacy DOM conformance tests.
- Add tests for DocumentType node to WPT.

BUG=699812

Review-Url: https://codereview.chromium.org/2737273002
Cr-Commit-Position: refs/heads/master@{#456002}
parent ba3f171d
Test http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodeisdefaultnamespace03
Status Success
/*
Copyright © 2001-2004 World Wide Web Consortium,
(Massachusetts Institute of Technology, European Research Consortium
for Informatics and Mathematics, Keio University). All
Rights Reserved. This work is distributed under the W3C® Software License [1] in the
hope that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
*/
/**
* Gets URI that identifies the test.
* @return uri identifier of test
*/
function getTargetURI() {
return "http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodeisdefaultnamespace03";
}
var docsLoaded = -1000000;
var builder = null;
//
// This function is called by the testing framework before
// running the test suite.
//
// If there are no configuration exceptions, asynchronous
// document loading is started. Otherwise, the status
// is set to complete and the exception is immediately
// raised when entering the body of the test.
//
function setUpPage() {
setUpPageStatus = 'running';
try {
//
// creates test document builder, may throw exception
//
builder = createConfiguredBuilder();
setImplementationAttribute("namespaceAware", true);
docsLoaded = 0;
var docRef = null;
if (typeof(this.doc) != 'undefined') {
docRef = this.doc;
}
docsLoaded += preload(docRef, "doc", "hc_staff");
if (docsLoaded == 1) {
setUpPageStatus = 'complete';
}
} catch(ex) {
catchInitializationError(builder, ex);
setUpPageStatus = 'complete';
}
}
//
// This method is called on the completion of
// each asychronous load started in setUpTests.
//
// When every synchronous loaded document has completed,
// the page status is changed which allows the
// body of the test to be executed.
function loadComplete() {
if (++docsLoaded == 1) {
setUpPageStatus = 'complete';
}
}
/**
*
Using isDefaultNamespace on this DocumentType node with the value of the namespaceURI parameter
as null check if the value returned is false.
* @author IBM
* @author Neil Delima
* @see http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core#Node3-isDefaultNamespace
*/
function nodeisdefaultnamespace03() {
var success;
if(checkInitialization(builder, "nodeisdefaultnamespace03") != null) return;
var doc;
var docType;
var isDefault;
var nullNSURI = null;
var docRef = null;
if (typeof(this.doc) != 'undefined') {
docRef = this.doc;
}
doc = load(docRef, "doc", "hc_staff");
docType = doc.doctype;
isDefault = docType.isDefaultNamespace(nullNSURI);
assertFalse("nodeisdefaultnamespace03",isDefault);
}
function runTest() {
nodeisdefaultnamespace03();
}
<?xml version="1.0"?><?TEST-STYLE PIDATA?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"xhtml1-strict.dtd" [
<!ENTITY alpha "&#945;">
<!ENTITY beta "&#946;">
<!ENTITY gamma "&#947;">
<!ENTITY delta "&#948;">
<!ENTITY epsilon "&#949;">
<!ENTITY alpha "&#950;">
<!NOTATION notation1 PUBLIC "notation1File">
<!NOTATION notation2 SYSTEM "notation2File">
<!ATTLIST p
dir CDATA 'rtl'
xmlns:dmstc CDATA #IMPLIED
xmlns:nm CDATA #IMPLIED
xmlns:emp2 CDATA #IMPLIED>
<!ATTLIST html
xmlns:xsi CDATA #IMPLIED
xsi:schemaLocation CDATA #IMPLIED>
<!ATTLIST acronym xsi:noNamespaceSchemaLocation CDATA #IMPLIED>
<!ENTITY ent4 "<span xmlns='http://www.w3.org/1999/xhtml'>Element data</span><?PItarget PIdata?>">
<!ATTLIST span xmlns CDATA #IMPLIED>
]>
<!-- This is comment number 1.-->
<html xmlns='http://www.w3.org/1999/xhtml'
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3.org/1999/xhtml hc_staff.xsd"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/><title>hc_staff</title><script type="text/javascript" src="selfxhtml.js"/><script charset="UTF-8" type="text/javascript" src="nodeisdefaultnamespace03.js"/><script type='text/javascript'>function loadComplete() { startTest(); }</script></head><body onload="loadComplete()">
<p xmlns:dmstc="http://www.usa.com">
<em>EMP0001</em>
<strong>Margaret Martin</strong>
<code>Accountant</code>
<sup>56,000</sup>
<var>Female</var>
<acronym title="Yes" xsi:noNamespaceSchemaLocation="Yes">1230 North Ave. Dallas, Texas 98551</acronym>
</p>
<p xmlns:dmstc="http://www.usa.com">
<em>EMP0002</em>
<strong>Martha Raynolds
<![CDATA[This is a CDATASection with EntityReference number 2 &ent2;]]>
<![CDATA[This is an adjacent CDATASection with a reference to a tab &tab;]]></strong>
<code>Secretary</code>
<sup>35,000</sup>
<var>Female</var>
<acronym title="Yes" class="Yes" xsi:noNamespaceSchemaLocation="Yes">&beta; Dallas, &gamma;
98554</acronym>
</p>
<p xmlns:dmstc="http://www.netzero.com">
<em>EMP0003</em>
<strong>Roger
Jones</strong>
<code>Department Manager</code>
<sup>100,000</sup>
<var>&ent4;</var>
<acronym title="Yes" class="No" id="_98553" xsi:noNamespaceSchemaLocation="Yes">PO Box 27 Irving, texas 98553</acronym>
</p>
<p xmlns:nm="http://www.altavista.com">
<em>EMP0004</em>
<strong>Jeny Oconnor</strong>
<code>Personnel Director</code>
<sup>95,000</sup>
<var>Female</var>
<acronym title="Yes" class="Y&alpha;" id="_98556" xsi:noNamespaceSchemaLocation="Yes">27 South Road. Dallas, Texas 98556</acronym>
</p>
<p xmlns:emp2="http://www.nist.gov">
<em>EMP0005</em>
<strong>Robert Myers</strong>
<code>Computer Specialist</code>
<sup>90,000</sup>
<var>male</var>
<acronym title="Yes" class="Yes" xsi:noNamespaceSchemaLocation="Yes">1821 Nordic. Road, Irving Texas 98558</acronym>
</p>
</body></html>
This is a testharness.js-based test.
Found 58 tests; 54 PASS, 4 FAIL, 0 TIMEOUT, 0 NOTRUN.
PASS DocumentFragment should have null namespace, prefix null
PASS DocumentFragment should have null namespace, prefix ""
PASS DocumentFragment should have null namespace, prefix "foo"
PASS DocumentFragment should have null namespace, prefix "xmlns"
FAIL DocumentFragment is in default namespace, prefix null assert_equals: expected true but got false
FAIL DocumentFragment is in default namespace, prefix "" assert_equals: expected true but got false
PASS DocumentFragment is in default namespace, prefix "foo"
PASS DocumentFragment is in default namespace, prefix "xmlns"
PASS Element should have null namespace, prefix null
PASS Element should have null namespace, prefix ""
PASS Element should not have namespace matching prefix with namespaceURI value
PASS Element should not have XMLNS namespace
PASS Element has namespace URI matching prefix
FAIL Empty namespace is not default, prefix null assert_equals: expected true but got false
FAIL Empty namespace is not default, prefix "" assert_equals: expected true but got false
PASS fooNamespace is not default
PASS xmlns namespace is not default
PASS Element should have baz namespace, prefix null
PASS Element should have baz namespace, prefix ""
PASS Element does not has namespace with xlmns prefix
PASS Element has bar namespace
PASS Empty namespace is not default on fooElem, prefix null
PASS Empty namespace is not default on fooElem, prefix ""
PASS bar namespace is not default
PASS baz namespace is default
PASS Comment should inherit baz namespace
PASS Comment should inherit baz namespace
PASS Comment should inherit namespace URI matching prefix
PASS Comment should inherit bar namespace
PASS For comment, empty namespace is not default, prefix null
PASS For comment, empty namespace is not default, prefix ""
PASS For comment, fooNamespace is not default
PASS For comment, xmlns namespace is not default
PASS For comment, inherited bar namespace is not default
PASS For comment, inherited baz namespace is default
PASS Child element should inherit baz namespace
PASS Child element should have null namespace
PASS Child element should not have XMLNS namespace
PASS Child element has namespace URI matching prefix
PASS Empty namespace is not default for child, prefix null
PASS Empty namespace is not default for child, prefix ""
PASS fooNamespace is not default for child
PASS xmlns namespace is not default for child
PASS bar namespace is not default for child
PASS baz namespace is default for child
PASS childNamespace is default for child
PASS Document should have xhtml namespace, prefix null
PASS Document should have xhtml namespace, prefix ""
PASS Document has no namespace URI matching prefix
PASS Document has bar namespace
PASS For document, empty namespace is not default, prefix null
PASS For document, empty namespace is not default, prefix ""
PASS For document, fooNamespace is not default
PASS For document, xmlns namespace is not default
PASS For document, bar namespace is not default
PASS For document, baz namespace is not default
PASS For document, xhtml namespace is default
PASS Comment does not have bar namespace
Harness: the test ran to completion.
......@@ -32,7 +32,15 @@ isDefaultNamespace(frag, '', true, 'DocumentFragment is in default namespace, pr
isDefaultNamespace(frag, 'foo', false, 'DocumentFragment is in default namespace, prefix "foo"');
isDefaultNamespace(frag, 'xmlns', false, 'DocumentFragment is in default namespace, prefix "xmlns"');
var docType = document.doctype;
lookupNamespaceURI(docType, null, null, 'DocumentType should have null nemspace, prefix null');
lookupNamespaceURI(docType, '', null, 'DocumentType should have null namespace, prefix ""');
lookupNamespaceURI(docType, 'foo', null, 'DocumentType should have null namespace, prefix "foo"');
lookupNamespaceURI(docType, 'xmlns', null, 'DocumentType should have null namespace, prefix "xmlns"');
isDefaultNamespace(docType, null, true, 'DocumentType is in default namespace, prefix null');
isDefaultNamespace(docType, '', true, 'DocumentType is in default namespace, prefix ""');
isDefaultNamespace(docType, 'foo', false, 'DocumentType is in default namespace, prefix "foo"');
isDefaultNamespace(docType, 'xmlns', false, 'DocumentType is in default namespace, prefix "xmlns"');
var fooElem = document.createElementNS('fooNamespace', 'prefix:elem');
fooElem.setAttribute('bar', 'value');
......
......@@ -1165,45 +1165,19 @@ bool Node::isEqualNode(Node* other) const {
bool Node::isDefaultNamespace(
const AtomicString& namespaceURIMaybeEmpty) const {
// https://dom.spec.whatwg.org/#dom-node-isdefaultnamespace
// 1. If namespace is the empty string, then set it to null.
const AtomicString& namespaceURI =
namespaceURIMaybeEmpty.isEmpty() ? nullAtom : namespaceURIMaybeEmpty;
switch (getNodeType()) {
case kElementNode: {
const Element& element = toElement(*this);
if (element.prefix().isNull())
return element.namespaceURI() == namespaceURI;
AttributeCollection attributes = element.attributes();
for (const Attribute& attr : attributes) {
if (attr.localName() == xmlnsAtom)
return attr.value() == namespaceURI;
}
if (Element* parent = parentElement())
return parent->isDefaultNamespace(namespaceURI);
// 2. Let defaultNamespace be the result of running locate a namespace for
// context object using null.
const AtomicString& defaultNamespace = lookupNamespaceURI(String());
return false;
}
case kDocumentNode:
if (Element* de = toDocument(this)->documentElement())
return de->isDefaultNamespace(namespaceURI);
return false;
case kDocumentTypeNode:
case kDocumentFragmentNode:
return false;
case kAttributeNode: {
const Attr* attr = toAttr(this);
if (attr->ownerElement())
return attr->ownerElement()->isDefaultNamespace(namespaceURI);
return false;
}
default:
if (Element* parent = parentElement())
return parent->isDefaultNamespace(namespaceURI);
return false;
}
// 3. Return true if defaultNamespace is the same as namespace, and false
// otherwise.
return namespaceURI == defaultNamespace;
}
const AtomicString& Node::lookupPrefix(const AtomicString& namespaceURI) const {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment