8000 jsdom/test/level2/core.js at 9.3.0 · dominicrico/jsdom · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
6857 lines (5729 loc) · 220 KB

core.js

File metadata and controls

6857 lines (5729 loc) · 220 KB
var testcase = require('nodeunit').testCase;
// NB: these tests have been modified to be compliant with the modern DOM, instead of the "DOM Level 2" they were
// written for. Check the revision history.
// The "getOwnerElement()" will return the Element node this attribute is attached to or null if this attribute is not in use.
// @author IBM
// @author Neil Delima
// @see http://www.w3.org/TR/DOM-Level-2-Core/core#Attr-ownerElement
exports['attrgetownerelement'] = testcase({
setUp: function(cb){
this.doc = require('./core/files/staffNS.xml').staffNS();
cb();
},
tearDown: function(cb){
this.doc = undefined;
delete(this.doc);
cb();
},
// Create a new element and attribute node, attach the attribute to the element. Check the value of owner element of the new attribute node
attrgetownerelement02: function(test) {
var element = this.doc.createElement("root");
var attr = this.doc.createAttributeNS("http://www.w3.org/DOM/L1","L1:att");
element.setAttributeNodeNS(attr);
test.equal(attr.ownerElement.nodeName.toLowerCase(), 'root');
test.done();
},
// Create a new attribute node for this document node. Since the newly attribute is not in use its owner element should be null.
attrgetownerelement03: function(test) {
var attr = this.doc.createAttributeNS("http://www.w3.org/DOM","dom:attr");
test.equal(attr.ownerElement, null, 'should be null')
test.done();
},
// Retreive an element and its attributes. Then remove the element and check the name of the ownerElement of attribute of the attribute "street".
// @see http://www.w3.org/Bugs/Public/show_bug.cgi?id=259
attrgetownerelement05: function(test) {
var element = this.doc.getElementsByTagNameNS("*","address").item(1);
element.parentNode.removeChild(element);
var attr = element.attributes.getNamedItemNS(null, "street");
test.equal(attr.ownerElement.nodeName, 'address');
test.done();
}
})
exports['createAttributeNS'] = testcase({
/**
*
The "createAttributeNS(namespaceURI,qualifiedName)" method for a
Document should raise NAMESPACE_ERR DOMException
if qualifiedName is malformed.
Invoke method createAttributeNS(namespaceURI,qualifiedName) on
the XMLNS Document with namespaceURI being "http://www.ecommerce.org/",
qualifiedName as "prefix::local". Method should raise
NAMESPACE_ERR DOMException.
* @author NIST
* @author Mary Brady
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='NAMESPACE_ERR'])
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#ID-DocCrAttrNS
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-DocCrAttrNS')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='NAMESPACE_ERR'])
*/
createAttributeNS01: function(test) {
var success;
var namespaceURI = "http://www.ecommerce.org/";
var malformedName = "prefix::local";
var newAttr;
var doc = require('./core/files/staffNS.xml').staffNS();
{
success = false;
try {
newAttr = doc.createAttributeNS(namespaceURI,malformedName);
}
catch(ex) {
success = (typeof(ex.code) != 'undefined' && ex.code == 14);
}
test.ok(success, 'throw_NAMESPACE_ERR');
}
test.done();
},
/**
*
The "createAttributeNS(namespaceURI,qualifiedName)" method for a
Document should raise NAMESPACE_ERR DOMException
if qualifiedName has a prefix and namespaceURI is null.
Invoke method createAttributeNS(namespaceURI,qualifiedName) on this document
with namespaceURI being null and qualifiedName contains the prefix "person".
Method should raise NAMESPACE_ERR DOMException.
* @author NIST
* @author Mary Brady
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='NAMESPACE_ERR'])
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#ID-DocCrAttrNS
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-DocCrAttrNS')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='NAMESPACE_ERR'])
*/
createAttributeNS02: function(test) {
var success;
var namespaceURI = null;
var qualifiedName = "prefix:local";
var newAttr;
var doc = require('./core/files/staffNS.xml').staffNS();
{
success = false;
try {
newAttr = doc.createAttributeNS(namespaceURI,qualifiedName);
}
catch(ex) {
success = (typeof(ex.code) != 'undefined' && ex.code == 14);
}
test.ok(success, 'throw_NAMESPACE_ERR');
}
test.done();
},
/**
*
The "createAttributeNS(namespaceURI,qualifiedName)" method for a
Document should raise INVALID_CHARACTER_ERR DOMException
if qualifiedName contains an illegal character.
Invoke method createAttributeNS(namespaceURI,qualifiedName) on this document
with qualifiedName containing an illegal character from illegalChars[].
Method should raise INVALID_CHARACTER_ERR DOMException for all
characters in illegalChars[].
* @author NIST
* @author Mary Brady
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#ID-DocCrAttrNS
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-DocCrAttrNS')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='INVALID_CHARACTER_ERR'])
*/
createAttributeNS03: function(test) {
var success;
var namespaceURI = "http://www.wedding.com/";
var qualifiedName;
var newAttr;
illegalQNames = new Array();
illegalQNames[0] = "person:{";
illegalQNames[1] = "person:}";
illegalQNames[2] = "person:~";
illegalQNames[3] = "person:'";
illegalQNames[4] = "person:!";
illegalQNames[5] = "person:@";
illegalQNames[6] = "person:#";
illegalQNames[7] = "person:$";
illegalQNames[8] = "person:%";
illegalQNames[9] = "person:^";
illegalQNames[10] = "person:&";
illegalQNames[11] = "person:*";
illegalQNames[12] = "person:(";
illegalQNames[13] = "person:)";
illegalQNames[14] = "person:+";
illegalQNames[15] = "person:=";
illegalQNames[16] = "person:[";
illegalQNames[17] = "person:]";
illegalQNames[18] = "person:\\";
illegalQNames[19] = "person:/";
illegalQNames[20] = "person:;";
illegalQNames[21] = "person:`";
illegalQNames[22] = "person:<";
illegalQNames[23] = "person:>";
illegalQNames[24] = "person:,";
illegalQNames[25] = "person:a ";
illegalQNames[26] = "person:\"";
var doc = require('./core/files/staffNS.xml').staffNS();
for(var indexN10090 = 0;indexN10090 < illegalQNames.length; indexN10090++) {
qualifiedName = illegalQNames[indexN10090];
{
success = false;
try {
newAttr = doc.createAttributeNS(namespaceURI,qualifiedName);
}
catch(ex) {
success = (typeof(ex.code) != 'undefined' && ex.code == 5);
}
test.ok(success, 'throw_INVALID_CHARACTER_ERR');
}
}
test.done();
},
/**
*
The "createAttributeNS(namespaceURI,qualifiedName)" method for a
Document should raise NAMESPACE_ERR DOMException
if qualifiedName has the "xml" prefix and namespaceURI is different
from "http://www.w3.org/XML/1998/namespace".
Invoke method createAttributeNS(namespaceURI,qualifiedName) on this document
with qualifiedName being "xml:attr1 and namespaceURI equals
the string "http://www.w3.org/XML/1998/namespaces" (which differs from the required
string "http://www.w3.org/XML/1998/namespace").
Method should raise NAMESPACE_ERR DOMException.
* @author NIST
* @author Mary Brady
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='NAMESPACE_ERR'])
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#ID-DocCrAttrNS
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-DocCrAttrNS')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='NAMESPACE_ERR'])
*/
createAttributeNS04: function(test) {
var success;
var namespaceURI = "http://www.w3.org/XML/1998/namespaces";
var qualifiedName = "xml:attr1";
var newAttr;
var doc = require('./core/files/staffNS.xml').staffNS();
{
success = false;
try {
newAttr = doc.createAttributeNS(namespaceURI,qualifiedName);
}
catch(ex) {
success = (typeof(ex.code) != 'undefined' && ex.code == 14);
}
test.ok(success, 'throw_NAMESPACE_ERR');
}
test.done();
},
/**
*
The "createAttributeNS(namespaceURI,qualifiedName)" method for a
Document should return a new Attr object given that all parameters are
valid and correctly formed.
Invoke method createAttributeNS(namespaceURI,qualifiedName) on this document with
parameters equal "http://www.ecommerce.org/" and "ecom:local"
respectively. Method should return a new Attr object whose name is "ecom:local".
* @author NIST
* @author Mary Brady
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#ID-1112119403
*/
createAttributeNS05: function(test) {
var success;
var namespaceURI = "http://www.ecommerce.org/";
var qualifiedName = "econm:local";
var newAttr;
var attrName;
var doc = require('./core/files/staffNS.xml').staffNS();
newAttr = doc.createAttributeNS(namespaceURI,qualifiedName);
attrName = newAttr.name;
test.done();
},
/**
*
Document.createAttributeNS with an empty qualified name should cause an INVALID_CHARACTER_ERR.
* @author Curt Arnold
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#ID-DocCrAttrNS
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-DocCrAttrNS')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='INVALID_CHARACTER_ERR'])
* @see http://www.w3.org/Bugs/Public/show_bug.cgi?id=525
*/
createAttributeNS06: function(test) {
var success;
var namespaceURI = "http://www.example.com/";
var qualifiedName;
var newAttr;
var doc = require('../level1/core/files/hc_staff.xml').hc_staff();
{
success = false;
try {
newAttr = doc.createAttributeNS(namespaceURI,"");
}
catch(ex) {
success = (typeof(ex.code) != 'undefined' && ex.code == 5);
}
test.ok(success, 'throw_INVALID_CHARACTER_ERR');
}
test.done();
}
})
exports['createDocument'] = testcase({
/**
*
The "createDocument(namespaceURI,qualifiedName,doctype)" method for a
DOMImplementation should raise NAMESPACE_ERR DOMException
if parameter qualifiedName is malformed.
Retrieve the DOMImplementation on the XMLNS Document.
Invoke method createDocument(namespaceURI,qualifiedName,doctype)
on the retrieved DOMImplementation with namespaceURI being
the literal string "http://www.ecommerce.org/", qualifiedName as
"prefix::local", and doctype as null. Method should raise
NAMESPACE_ERR DOMException.
* @author NIST
* @author Mary Brady
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='NAMESPACE_ERR'])
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#Level-2-Core-DOM-createDocument
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('Level-2-Core-DOM-createDocument')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='NAMESPACE_ERR'])
*/
createDocument01: function(test) {
var success;
var namespaceURI = "http://www.ecommerce.org/";
var malformedName = "prefix::local";
var docType = null;
var domImpl;
var aNewDoc;
var doc = require('./core/files/staffNS.xml').staffNS();
domImpl = doc.implementation;
{
success = false;
try {
aNewDoc = domImpl.createDocument(namespaceURI,malformedName,docType);
}
catch(ex) {
success = (typeof(ex.code) != 'undefined' && ex.code == 14);
}
test.ok(success, 'throw_NAMESPACE_ERR');
}
test.done();
},
/**
*
The "createDocument(namespaceURI,qualifiedName,doctype)" method for a
DOMImplementation should raise NAMESPACE_ERR DOMException
if qualifiedName has a prefix and namespaceURI is null.
Invoke method createDocument(namespaceURI,qualifiedName,doctype) on
this domimplementation with namespaceURI being null and qualifiedName
equals "k:local". Method should raise NAMESPACE_ERR DOMException.
* @author NIST
* @author Mary Brady
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='NAMESPACE_ERR'])
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#Level-2-Core-DOM-createDocument
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('Level-2-Core-DOM-createDocument')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='NAMESPACE_ERR'])
*/
createDocument02: function(test) {
var success;
var namespaceURI = null;
var qualifiedName = "k:local";
var docType = null;
var domImpl;
var aNewDoc;
var doc = require('./core/files/staffNS.xml').staffNS();
domImpl = doc.implementation;
{
success = false;
try {
aNewDoc = domImpl.createDocument(namespaceURI,qualifiedName,docType);
}
catch(ex) {
success = (typeof(ex.code) != 'undefined' && ex.code == 14);
}
test.ok(success, 'throw_NAMESPACE_ERR');
}
test.done();
},
/**
*
The "createDocument(namespaceURI,qualifiedName,doctype)" method for a
DOMImplementation should raise INVALID_CHARACTER_ERR DOMException
if parameter qualifiedName contains an illegal character.
Invoke method createDocument(namespaceURI,qualifiedName,doctype) on
this domimplementation with namespaceURI equals "http://www.ecommerce.org/schema",
doctype is null and qualifiedName contains an illegal character from
illegalChars[]. Method should raise INVALID_CHARACTER_ERR DOMException
for all characters in illegalChars[].
* @author NIST
* @author Mary Brady
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#
*/
createDocument05: function(test) {
var success;
var namespaceURI = "http://www.ecommerce.org/schema";
var qualifiedName;
var docType = null;
var domImpl;
var aNewDoc;
var charact;
illegalQNames = new Array();
illegalQNames[0] = "namespaceURI:{";
illegalQNames[1] = "namespaceURI:}";
illegalQNames[2] = "namespaceURI:~";
illegalQNames[3] = "namespaceURI:'";
illegalQNames[4] = "namespaceURI:!";
illegalQNames[5] = "namespaceURI:@";
illegalQNames[6] = "namespaceURI:#";
illegalQNames[7] = "namespaceURI:$";
illegalQNames[8] = "namespaceURI:%";
illegalQNames[9] = "namespaceURI:^";
illegalQNames[10] = "namespaceURI:&";
illegalQNames[11] = "namespaceURI:*";
illegalQNames[12] = "namespaceURI:(";
illegalQNames[13] = "namespaceURI:)";
illegalQNames[14] = "namespaceURI:+";
illegalQNames[15] = "namespaceURI:=";
illegalQNames[16] = "namespaceURI:[";
illegalQNames[17] = "namespaceURI:]";
illegalQNames[18] = "namespaceURI:\\";
illegalQNames[19] = "namespaceURI:/";
illegalQNames[20] = "namespaceURI:;";
illegalQNames[21] = "namespaceURI:`";
illegalQNames[22] = "namespaceURI:<";
illegalQNames[23] = "namespaceURI:>";
illegalQNames[24] = "namespaceURI:,";
illegalQNames[25] = "namespaceURI:a ";
illegalQNames[26] = "namespaceURI:\"";
var doc = require('./core/files/staffNS.xml').staffNS();
for(var indexN1009A = 0;indexN1009A < illegalQNames.length; indexN1009A++) {
qualifiedName = illegalQNames[indexN1009A];
domImpl = doc.implementation;
{
success = false;
try {
aNewDoc = domImpl.createDocument(namespaceURI,qualifiedName,docType);
}
catch(ex) {
success = (typeof(ex.code) != 'undefined' && ex.code == 5);
}
test.ok(success, 'throw_INVALID_CHARACTER_ERR');
}
}
test.done();
},
/**
*
The "createDocument(namespaceURI,qualifiedName,doctype)" method for a
DOMImplementation should raise NAMESPACE_ERR DOMException
if qualifiedName has the "xml" prefix and namespaceURI different from
"http://www.w3.org/XML/1998/namespace"
Invoke method createDocument(namespaceURI,qualifiedName,doctype) on
this domimplementation with qualifiedName "xml:local"
and namespaceURI as the string
"http://www.ecommerce.org/schema" (which is different from the required
"http://www.w3.org/XML/1998/namespace"). Method should raise
NAMESPACE_ERR DOMException.
* @author NIST
* @author Mary Brady
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='NAMESPACE_ERR'])
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#Level-2-Core-DOM-createDocument
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('Level-2-Core-DOM-createDocument')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='NAMESPACE_ERR'])
*/
createDocument06: function(test) {
var success;
var namespaceURI = "http://ecommerce.org/schema";
var qualifiedName = "xml:local";
var docType = null;
var domImpl;
var aNewDoc;
var doc = require('./core/files/staffNS.xml').staffNS();
domImpl = doc.implementation;
{
success = false;
try {
aNewDoc = domImpl.createDocument(namespaceURI,qualifiedName,docType);
}
catch(ex) {
success = (typeof(ex.code) != 'undefined' && ex.code == 14);
}
test.ok(success, 'throw_NAMESPACE_ERR');
}
test.done();
},
/**
*
The "createDocument(namespaceURI,qualifiedName,doctype)" method for a
DOMImplementation should return a new xml Document object of the
specified type with its document element given that all parameters are
valid and correctly formed.
Invoke method createDocument(namespaceURI,qualifiedName,doctype) on
this domimplementation. namespaceURI is "http://www.ecommerce.org/schema"
qualifiedName is "y:x" and doctype is null.
Method should return a new xml Document as specified by the listed parameters.
* @author NIST
* @author Mary Brady
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#Level-2-Core-DOM-createDocument
*/
createDocument07: function(test) {
var success;
var namespaceURI = "http://www.ecommerce.org/schema";
var qualifiedName = "y:x";
var docType = null;
var domImpl;
var aNewDoc;
var nodeName;
var nodeValue;
var doc = require('./core/files/staffNS.xml').staffNS();
domImpl = doc.implementation;
aNewDoc = domImpl.createDocument(namespaceURI,qualifiedName,docType);
nodeName = aNewDoc.nodeName;
nodeValue = aNewDoc.nodeValue;
test.equal(nodeName, "#document", "nodeName");
test.equal(nodeValue, null, 'nodeValue should not be null');
test.done();
},
/**
*
DOMImplementation.createDocument with an empty qualified name should not create a document element.
* @author Curt Arnold
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#
* @see http://www.w3.org/Bugs/Public/show_bug.cgi?id=525
*/
createDocument08: function(test) {
var success;
var namespaceURI = "http://www.example.org/schema";
var docType = null;
var domImpl;
var aNewDoc;
var charact;
var doc = require('./core/files/staffNS.xml').staffNS();
domImpl = doc.implementation;
aNewDoc = domImpl.createDocument(namespaceURI,"",docType);
test.equal(aNewDoc.documentElement, null);
test.done();
}
})
exports['createDocumentType'] = testcase({
/**
*
The "createDocumentType(qualifiedName,publicId,systemId)" method for a
DOMImplementation should raise NAMESPACE_ERR DOMException if
qualifiedName is malformed.
Retrieve the DOMImplementation on the XMLNS Document.
Invoke method createDocumentType(qualifiedName,publicId,systemId)
on the retrieved DOMImplementation with qualifiedName being the literal
string "prefix::local", publicId as "STAFF", and systemId as "staff".
Method should raise NAMESPACE_ERR DOMException.
* @author NIST
* @author Mary Brady
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='NAMESPACE_ERR'])
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#Level-2-Core-DOM-createDocType
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('Level-2-Core-DOM-createDocType')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='NAMESPACE_ERR'])
*/
createDocumentType01: function(test) {
var success;
var publicId = "STAFF";
var systemId = "staff.xml";
var malformedName = "prefix::local";
var domImpl;
var newType;
var doc = require('./core/files/staffNS.xml').staffNS();
domImpl = doc.implementation;
{
success = false;
try {
newType = domImpl.createDocumentType(malformedName,publicId,systemId);
}
catch(ex) {
success = (typeof(ex.code) != 'undefined' && ex.code == 14);
}
test.ok(success, 'throw_NAMESPACE_ERR');
}
test.done();
},
/**
*
The "createDocumentType(qualifiedName,publicId,systemId)" method for a
DOMImplementation should raise INVALID_CHARACTER_ERR DOMException if
qualifiedName contains an illegal character.
Invoke method createDocumentType(qualifiedName,publicId,systemId) on
this domimplementation with qualifiedName containing an illegal character
from illegalChars[]. Method should raise INVALID_CHARACTER_ERR
DOMException for all characters in illegalChars[].
* @author NIST
* @author Mary Brady
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#Level-2-Core-DOM-createDocType
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('Level-2-Core-DOM-createDocType')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='INVALID_CHARACTER_ERR'])
*/
createDocumentType02: function(test) {
var success;
var publicId = "http://www.localhost.com/";
var systemId = "myDoc.dtd";
var qualifiedName;
var docType = null;
var domImpl;
illegalQNames = new Array();
illegalQNames[0] = "edi:{";
illegalQNames[1] = "edi:}";
illegalQNames[2] = "edi:~";
illegalQNames[3] = "edi:'";
illegalQNames[4] = "edi:!";
illegalQNames[5] = "edi:@";
illegalQNames[6] = "edi:#";
illegalQNames[7] = "edi:$";
illegalQNames[8] = "edi:%";
illegalQNames[9] = "edi:^";
illegalQNames[10] = "edi:&";
illegalQNames[11] = "edi:*";
illegalQNames[12] = "edi:(";
illegalQNames[13] = "edi:)";
illegalQNames[14] = "edi:+";
illegalQNames[15] = "edi:=";
illegalQNames[16] = "edi:[";
illegalQNames[17] = "edi:]";
illegalQNames[18] = "edi:\\";
illegalQNames[19] = "edi:/";
illegalQNames[20] = "edi:;";
illegalQNames[21] = "edi:`";
illegalQNames[22] = "edi:<";
illegalQNames[23] = "edi:>";
illegalQNames[24] = "edi:,";
illegalQNames[25] = "edi:a ";
illegalQNames[26] = "edi:\"";
var doc = require('./core/files/staffNS.xml').staffNS();
for(var indexN1009A = 0;indexN1009A < illegalQNames.length; indexN1009A++) {
qualifiedName = illegalQNames[indexN1009A];
domImpl = doc.implementation;
{
success = false;
try {
docType = domImpl.createDocumentType(qualifiedName,publicId,systemId);
}
catch(ex) {
success = (typeof(ex.code) != 'undefined' && ex.code == 5);
}
test.ok(success, 'throw_INVALID_CHARACTER_ERR');
}
}
test.done();
},
/**
*
The "createDocumentType(qualifiedName,publicId,systemId)" method for a
DOMImplementation should return a new DocumentType node
given that qualifiedName is valid and correctly formed.
Invoke method createDocumentType(qualifiedName,publicId,systemId) on
this domimplementation with qualifiedName "prefix:myDoc".
Method should return a new DocumentType node.
* @author NIST
* @author Mary Brady
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#Level-2-Core-DOM-createDocType
*/
createDocumentType03: function(test) {
var success;
var namespaceURI = "http://ecommerce.org/schema";
var qualifiedName = "prefix:myDoc";
var publicId = "http://www.localhost.com";
var systemId = "myDoc.dtd";
var domImpl;
var newType = null;
var nodeName;
var nodeValue;
var doc = require('./core/files/staffNS.xml').staffNS();
domImpl = doc.implementation;
newType = domImpl.createDocumentType(qualifiedName,publicId,systemId);
nodeName = newType.nodeName;
test.equal(nodeName, "prefix:myDoc", "nodeName");
nodeValue = newType.nodeValue;
test.equal(nodeValue, null, 'nodeValue should not be null');
test.done();
},
/**
*
DOMImplementation.createDocumentType with an empty name should cause an INVALID_CHARACTER_ERR.
* @author Curt Arnold
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#Level-2-Core-DOM-createDocType
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('Level-2-Core-DOM-createDocType')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='INVALID_CHARACTER_ERR'])
* @see http://www.w3.org/Bugs/Public/show_bug.cgi?id=525
*/
createDocumentType04: function(test) {
var success;
var publicId = "http://www.example.com/";
var systemId = "myDoc.dtd";
var qualifiedName;
var docType = null;
var domImpl = require('./core/files/staffNS.xml').staffNS().implementation;
{
success = false;
try {
docType = domImpl.createDocumentType("",publicId,systemId);
}
catch(ex) {
success = (typeof(ex.code) != 'undefined' && ex.code == 5);
}
test.ok(success, 'throw_INVALID_CHARACTER_ERR');
}
test.done();
}
})
exports['createElementNS'] = testcase({
/**
*
The "createElementNS(namespaceURI,qualifiedName)" method for a
Document should raise NAMESPACE_ERR DOMException if
qualifiedName is malformed.
Invoke method createElementNS(namespaceURI,qualifiedName) on
the XMLNS Document with namespaceURI being the literal string
"http://www.ecommerce.org/", and qualifiedName as "prefix::local".
Method should raise NAMESPACE_ERR DOMException.
* @author NIST
* @author Mary Brady
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='NAMESPACE_ERR'])
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#ID-DocCrElNS
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-DocCrElNS')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='NAMESPACE_ERR'])
*/
createElementNS01: function(test) {
var success;
var namespaceURI = "http://www.ecommerce.org/";
var malformedName = "prefix::local";
var newElement;
var doc = require('./core/files/staffNS.xml').staffNS();
{
success = false;
try {
newElement = doc.createElementNS(namespaceURI,malformedName);
}
catch(ex) {
success = (typeof(ex.code) != 'undefined' && ex.code == 14);
}
test.ok(success, 'throw_NAMESPACE_ERR');
}
test.done();
},
/**
*
The "createElementNS(namespaceURI,qualifiedName)" method for a
Document should raise NAMESPACE_ERR DOMException if
qualifiedName has a prefix and namespaceURI is null.
Invoke method createElementNS(namespaceURI,qualifiedName) on this document
with namespaceURI being null and qualifiedName being "elem:attr1".
Method should raise NAMESPACE_ERR DOMException.
* @author NIST
* @author Mary Brady
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='NAMESPACE_ERR'])
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#ID-DocCrElNS
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-DocCrElNS')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='NAMESPACE_ERR'])
*/
createElementNS02: function(test) {
var success;
var namespaceURI = null;
var qualifiedName = "prefix:local";
var newElement;
var doc = require('./core/files/staffNS.xml').staffNS();
{
success = false;
try {
newElement = doc.createElementNS(namespaceURI,qualifiedName);
}
catch(ex) {
success = (typeof(ex.code) != 'undefined' && ex.code == 14);
}
test.ok(success, 'throw_NAMESPACE_ERR');
}
test.done();
},
/**
*
The "createElementNS(namespaceURI,qualifiedName)" method for a
Document should raise INVALID_CHARACTER_ERR DOMException if
qualifiedName contains an illegal character.
Invoke method createElementNS(namespaceURI,qualifiedName) on this document
with qualifiedName containing an illegal character from illegalChars[].
Method should raise INVALID_CHARACTER_ERR DOMException for all characters
in illegalChars[].
* @author NIST
* @author Mary Brady
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#ID-DocCrElNS
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-DocCrElNS')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='INVALID_CHARACTER_ERR'])
*/
createElementNS03: function(test) {
var success;
var namespaceURI = "http://www.wedding.com/";
var qualifiedName;
var done;
var newElement;
var charact;
illegalQNames = new Array();
illegalQNames[0] = "person:{";
illegalQNames[1] = "person:}";
illegalQNames[2] = "person:~";
illegalQNames[3] = "person:'";
illegalQNames[4] = "person:!";
illegalQNames[5] = "person:@";
illegalQNames[6] = "person:#";
illegalQNames[7] = "person:$";
illegalQNames[8] = "person:%";
illegalQNames[9] = "person:^";
illegalQNames[10] = "person:&";
illegalQNames[11] = "person:*";
illegalQNames[12] = "person:(";
illegalQNames[13] = "person:)";
illegalQNames[14] = "person:+";
illegalQNames[15] = "person:=";
illegalQNames[16] = "person:[";
illegalQNames[17] = "person:]";
illegalQNames[18] = "person:\\";
illegalQNames[19] = "person:/";
illegalQNames[20] = "person:;";
illegalQNames[21] = "person:`";
illegalQNames[22] = "person:<";
illegalQNames[23] = "person:>";
illegalQNames[24] = "person:,";
illegalQNames[25] = "person:a ";
illegalQNames[26] = "person:\"";
var doc = require('./core/files/staffNS.xml').staffNS();
for(var indexN10098 = 0;indexN10098 < illegalQNames.length; indexN10098++) {
qualifiedName = illegalQNames[indexN10098];
{
success = false;
try {
newElement = doc.createElementNS(namespaceURI,qualifiedName);
}
catch(ex) {
success = (typeof(ex.code) != 'undefined' && ex.code == 5);
}
test.ok(success, 'throw_INVALID_CHARACTER_ERR');
}
}
test.done();
},
/**
*
The "createElementNS(namespaceURI,qualifiedName") method for
a Document should raise NAMESPACE_ERR DOMException if the
qualifiedName has an "xml" prefix and the namespaceURI is different
from http://www.w3.org/XML/1998/namespace".
Invoke method createElementNS(namespaceURI,qualifiedName) on this document
with qualifiedName being "xml:element1" and namespaceURI equals the string
"http://www.w3.org/XML/1997/namespace" (which differs from the required
string "http://www.w3.org/XML/1998/namespace").
Method should raise NAMESPACE_ERR DOMException.
* @author NIST
* @author Mary Brady
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='NAMESPACE_ERR'])
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#ID-DocCrElNS
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-DocCrElNS')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='NAMESPACE_ERR'])
*/
createElementNS04: function(test) {
var success;
var namespaceURI = "http://www.w3.org/XML/1998/namespaces";
var qualifiedName = "xml:element1";
var newElement;
var doc = require('./core/files/staffNS.xml').staffNS();
{
success = false;
try {
newElement = doc.createElementNS(namespaceURI,qualifiedName);
}
catch(ex) {
success = (typeof(ex.code) != 'undefined' && ex.code == 14);
}
test.ok(success, 'throw_NAMESPACE_ERR');
}
test.done();
},
/**
*
The "createElementNS(namespaceURI,qualifiedName)" method for a
Document should return a new Element object given that all parameters
are valid and correctly formed.
Invoke method createElementNS(namespaceURI,qualifiedName on this document
with namespaceURI as "http://www.nist.gov" and qualifiedName as "gov:faculty".
Method should return a new Element object whose name is "gov:faculty".
* @author NIST
* @author Mary Brady
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#ID-104682815
*/
createElementNS05: function(test) {
var success;
var namespaceURI = "http://www.nist.gov";
var qualifiedName = "gov:faculty";
var newElement;
var elementName;
var doc = require('./core/files/staffNS.xml').staffNS();
newElement = doc.createElementNS(namespaceURI,qualifiedName);
elementName = newElement.tagName;
test.equal(elementName, qualifiedName, "throw_Equals");
test.done();
},
/**
*
Document.createElementNS with an empty qualified name should cause an INVALID_CHARACTER_ERR.
* @author Curt Arnold
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#ID-DocCrElNS
* @see http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-DocCrElNS')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='INVALID_CHARACTER_ERR'])
* @see http://www.w3.org/Bugs/Public/show_bug.cgi?id=525
*/
createElementNS06: function(test) {
var success;
var namespaceURI = "http://www.example.com/";
var qualifiedName;
var done;
var newElement;
var charact;
var doc = require('../level1/core/files/hc_staff.xml').hc_staff();
{
success = false;
try {
newElement = doc.createElementNS(namespaceURI,"");
}
catch(ex) {
success = (typeof(ex.code) != 'undefined' && ex.code == 5);
}
test.ok(success, 'throw_INVALID_CHARACTER_ERR');
0