blob: 842f202f8282e1d3901c098136601a1a4f755c6a [file] [log] [blame]
<!DOCTYPE html>
<script src="../../resources/js-test.js"></script>
<script>
description("Test that calling createElementNS() throws an error when http://www.w3.org/TR/dom/#dom-document-createelementns says it should.");
// Spec: http://www.w3.org/TR/dom/#dom-document-createelementns
// Step 5.
shouldThrow("document.createElementNS(null, 'foo:bar')", '"NamespaceError: Failed to execute \'createElementNS\' on \'Document\': The namespace URI provided (\'\') is not valid for the qualified name provided (\'foo:bar\')."');
// Step 6.
shouldNotThrow("document.createElementNS('http://www.w3.org/XML/1998/namespace', 'xml:abc')");
shouldBe("document.createElementNS('http://www.w3.org/XML/1998/namespace', 'xml:abc').namespaceURI", '"http://www.w3.org/XML/1998/namespace"');
shouldBe("document.createElementNS('http://www.w3.org/XML/1998/namespace', 'xml:abc').nodeName", '"xml:abc"');
shouldBe("document.createElementNS('http://www.w3.org/XML/1998/namespace', 'xml:abc').prefix", '"xml"');
shouldBe("document.createElementNS('http://www.w3.org/XML/1998/namespace', 'xml:abc').localName", '"abc"');
shouldThrow("document.createElementNS('http://www.w3.org/not-XML/1998/namespace', 'xml:abc')", '"NamespaceError: Failed to execute \'createElementNS\' on \'Document\': The namespace URI provided (\'http://www.w3.org/not-XML/1998/namespace\') is not valid for the qualified name provided (\'xml:abc\')."');
// Step 7.
shouldNotThrow("document.createElementNS('http://www.w3.org/2000/xmlns/', 'xmlns')");
shouldBe("document.createElementNS('http://www.w3.org/2000/xmlns/', 'xmlns').namespaceURI", '"http://www.w3.org/2000/xmlns/"');
shouldBe("document.createElementNS('http://www.w3.org/2000/xmlns/', 'xmlns').nodeName", '"xmlns"');
shouldBe("document.createElementNS('http://www.w3.org/2000/xmlns/', 'xmlns').prefix", 'null');
shouldBe("document.createElementNS('http://www.w3.org/2000/xmlns/', 'xmlns').localName", '"xmlns"');
shouldThrow("document.createElementNS('http://www.w3.org/2000/not-xmlns/', 'xmlns')", '"NamespaceError: Failed to execute \'createElementNS\' on \'Document\': The namespace URI provided (\'http://www.w3.org/2000/not-xmlns/\') is not valid for the qualified name provided (\'xmlns\')."');
shouldNotThrow("document.createElementNS('http://www.w3.org/2000/xmlns/', 'xmlns:abc', 'http://wwww.example.org')");
shouldBe("document.createElementNS('http://www.w3.org/2000/xmlns/', 'xmlns:abc').namespaceURI", '"http://www.w3.org/2000/xmlns/"');
shouldBe("document.createElementNS('http://www.w3.org/2000/xmlns/', 'xmlns:abc').nodeName", '"xmlns:abc"');
shouldBe("document.createElementNS('http://www.w3.org/2000/xmlns/', 'xmlns:abc').prefix", '"xmlns"');
shouldBe("document.createElementNS('http://www.w3.org/2000/xmlns/', 'xmlns:abc').localName", '"abc"');
shouldThrow("document.createElementNS('http://www.w3.org/2000/not-xmlns/', 'xmlns:abc', 'http://wwww.example.org')", '"NamespaceError: Failed to execute \'createElementNS\' on \'Document\': The namespace URI provided (\'http://www.w3.org/2000/not-xmlns/\') is not valid for the qualified name provided (\'xmlns:abc\')."');
// Step 8.
shouldThrow("document.createElementNS('http://www.w3.org/2000/xmlns/', 'badprefix:xmlns')", '"NamespaceError: Failed to execute \'createElementNS\' on \'Document\': The namespace URI provided (\'http://www.w3.org/2000/xmlns/\') is not valid for the qualified name provided (\'badprefix:xmlns\')."');
shouldThrow("document.createElementNS('http://www.w3.org/2000/xmlns/', 'notxmlns')", '"NamespaceError: Failed to execute \'createElementNS\' on \'Document\': The namespace URI provided (\'http://www.w3.org/2000/xmlns/\') is not valid for the qualified name provided (\'notxmlns\')."');
</script>