OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2014 Google Inc. All rights reserved. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style |
| 5 * license that can be found in the LICENSE file or at |
| 6 * https://developers.google.com/open-source/licenses/bsd |
| 7 */ |
| 8 |
| 9 part of charted.test.core; |
| 10 |
| 11 testNamespace() { |
| 12 test('Namespace should parse known namespace prefixes', () { |
| 13 List namespaces = [ |
| 14 {'prefix':'svg', 'tag':'g', 'uri':'http://www.w3.org/2000/svg' }, |
| 15 {'prefix':'xhtml', 'tag':'div', 'uri':'http://www.w3.org/1999/xhtml'} |
| 16 ]; |
| 17 List namespacesWithoutTag = [ |
| 18 {'prefix':'xlink', 'uri':'http://www.w3.org/1999/xlink' }, |
| 19 {'prefix':'xml', 'uri':'http://www.w3.org/XML/1998/namespace'}, |
| 20 {'prefix':'xmlns', 'uri':'http://www.w3.org/2000/xmlns/'} |
| 21 ]; |
| 22 |
| 23 namespaces.forEach((var item) { |
| 24 var prefixedTag = '${item['prefix']}:${item['tag']}', |
| 25 ns = new Namespace(prefixedTag); |
| 26 expect(ns.namespaceUri, equals(item['uri'])); |
| 27 expect(ns.localName, equals(item['tag'])); |
| 28 }); |
| 29 |
| 30 namespacesWithoutTag.forEach((var item) { |
| 31 var prefixedTag = '${item['prefix']}', |
| 32 ns = new Namespace(prefixedTag); |
| 33 expect(ns.namespaceUri, equals(item['uri'])); |
| 34 }); |
| 35 }); |
| 36 |
| 37 test('When namespace is not specified, only localName is set', () { |
| 38 var ns = new Namespace('div'); |
| 39 expect(ns.namespaceUri, isNull); |
| 40 expect(ns.localName, equals('div')); |
| 41 }); |
| 42 |
| 43 group('Namespace::createChildElement()', () { |
| 44 test('should create elements with ' |
| 45 'parent\'s namespace when mentioned tag does not have prefix', () { |
| 46 Element parent = new Element.tag('div'), |
| 47 parent2 = document.createElementNS( |
| 48 'http://www.w3.org/2000/svg', 'div'), |
| 49 child = Namespace.createChildElement('div', parent), |
| 50 child2 = Namespace.createChildElement('div', parent2); |
| 51 |
| 52 expect(parent.namespaceUri, equals(child.namespaceUri)); |
| 53 expect(parent2.namespaceUri, equals(child2.namespaceUri)); |
| 54 }); |
| 55 |
| 56 test('should use the right namespace Uri ' |
| 57 'when tag is prefixed with common namespace prefixes', () { |
| 58 Element parent = new Element.tag('div'), |
| 59 child = Namespace.createChildElement('xhtml:div', parent), |
| 60 child2 = Namespace.createChildElement('svg:div', parent); |
| 61 expect(child.namespaceUri, equals('http://www.w3.org/1999/xhtml')); |
| 62 expect(child2.namespaceUri, equals('http://www.w3.org/2000/svg')); |
| 63 }); |
| 64 }); |
| 65 } |
OLD | NEW |