| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library XMLDocumentTest; | 5 library XMLDocumentTest; |
| 6 import '../../pkg/unittest/lib/unittest.dart'; | 6 import '../../pkg/unittest/lib/unittest.dart'; |
| 7 import '../../pkg/unittest/lib/html_config.dart'; | 7 import '../../pkg/unittest/lib/html_config.dart'; |
| 8 import 'dart:html'; | 8 import 'dart:html'; |
| 9 | 9 |
| 10 main() { | 10 main() { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 // FilteredElementList is tested more thoroughly in DocumentFragmentTests. | 40 // FilteredElementList is tested more thoroughly in DocumentFragmentTests. |
| 41 group('children', () { | 41 group('children', () { |
| 42 test('filters out non-element nodes', () { | 42 test('filters out non-element nodes', () { |
| 43 final doc = new XMLDocument.xml("<xml>1<a/><b/>2<c/>3<d/></xml>"); | 43 final doc = new XMLDocument.xml("<xml>1<a/><b/>2<c/>3<d/></xml>"); |
| 44 expect(doc.children.map((e) => e.tagName), ["a", "b", "c", "d"]); | 44 expect(doc.children.map((e) => e.tagName), ["a", "b", "c", "d"]); |
| 45 }); | 45 }); |
| 46 | 46 |
| 47 test('overwrites nodes when set', () { | 47 test('overwrites nodes when set', () { |
| 48 final doc = new XMLDocument.xml("<xml>1<a/><b/>2<c/>3<d/></xml>"); | 48 final doc = new XMLDocument.xml("<xml>1<a/><b/>2<c/>3<d/></xml>"); |
| 49 doc.children = [new XMLElement.tag('x'), new XMLElement.tag('y')]; | 49 doc.children = [new XMLElement.tag('x'), new XMLElement.tag('y')]; |
| 50 expect(doc.outerHTML, "<xml><x></x><y></y></xml>"); | 50 expect(doc.outerHtml, "<xml><x></x><y></y></xml>"); |
| 51 }); | 51 }); |
| 52 }); | 52 }); |
| 53 | 53 |
| 54 group('classes', () { | 54 group('classes', () { |
| 55 XMLDocument makeDocumentWithClasses() => | 55 XMLDocument makeDocumentWithClasses() => |
| 56 new XMLDocument.xml("<xml class='foo bar baz'></xml>"); | 56 new XMLDocument.xml("<xml class='foo bar baz'></xml>"); |
| 57 | 57 |
| 58 Set<String> makeClassSet() => makeDocumentWithClasses().classes; | 58 Set<String> makeClassSet() => makeDocumentWithClasses().classes; |
| 59 | 59 |
| 60 Set<String> extractClasses(Document doc) { | 60 Set<String> extractClasses(Document doc) { |
| 61 final match = new RegExp('class="([^"]+)"').firstMatch(doc.outerHTML); | 61 final match = new RegExp('class="([^"]+)"').firstMatch(doc.outerHtml); |
| 62 return new Set.from(match[1].split(' ')); | 62 return new Set.from(match[1].split(' ')); |
| 63 } | 63 } |
| 64 | 64 |
| 65 test('affects the "class" attribute', () { | 65 test('affects the "class" attribute', () { |
| 66 final doc = makeDocumentWithClasses(); | 66 final doc = makeDocumentWithClasses(); |
| 67 doc.classes.add('qux'); | 67 doc.classes.add('qux'); |
| 68 expect(extractClasses(doc), ["foo", "bar", "baz", "qux"]); | 68 expect(extractClasses(doc), ["foo", "bar", "baz", "qux"]); |
| 69 }); | 69 }); |
| 70 | 70 |
| 71 test('is affected by the "class" attribute', () { | 71 test('is affected by the "class" attribute', () { |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 }); | 391 }); |
| 392 | 392 |
| 393 test('set', () { | 393 test('set', () { |
| 394 final doc = makeDocument(); | 394 final doc = makeDocument(); |
| 395 doc.dir = 'foo'; | 395 doc.dir = 'foo'; |
| 396 expect(doc.attributes['dir'], 'foo'); | 396 expect(doc.attributes['dir'], 'foo'); |
| 397 }); | 397 }); |
| 398 }); | 398 }); |
| 399 }); | 399 }); |
| 400 | 400 |
| 401 test('set innerHTML', () { | 401 test('set innerHtml', () { |
| 402 final doc = makeDocument(); | 402 final doc = makeDocument(); |
| 403 doc.innerHTML = "<foo>Bar<baz/></foo>"; | 403 doc.innerHtml = "<foo>Bar<baz/></foo>"; |
| 404 expect(doc.nodes.length, 1); | 404 expect(doc.nodes.length, 1); |
| 405 final node = doc.nodes[0]; | 405 final node = doc.nodes[0]; |
| 406 expect(node, isXMLElement); | 406 expect(node, isXMLElement); |
| 407 expect(node.tagName, 'foo'); | 407 expect(node.tagName, 'foo'); |
| 408 expect(node.nodes[0].text, 'Bar'); | 408 expect(node.nodes[0].text, 'Bar'); |
| 409 expect(node.nodes[1].tagName, 'baz'); | 409 expect(node.nodes[1].tagName, 'baz'); |
| 410 }); | 410 }); |
| 411 | 411 |
| 412 test('get innerHTML/outerHTML', () { | 412 test('get innerHtml/outerHtml', () { |
| 413 final doc = makeDocument(); | 413 final doc = makeDocument(); |
| 414 expect(doc.innerHTML, "<foo></foo><bar></bar>"); | 414 expect(doc.innerHtml, "<foo></foo><bar></bar>"); |
| 415 doc.nodes.clear(); | 415 doc.nodes.clear(); |
| 416 doc.nodes.addAll([new Text("foo"), new XMLElement.xml("<a>bar</a>")]); | 416 doc.nodes.addAll([new Text("foo"), new XMLElement.xml("<a>bar</a>")]); |
| 417 expect(doc.innertHTML, "foo<a>bar</a>"); | 417 expect(doc.innerHtml, "foo<a>bar</a>"); |
| 418 expect(doc.outerHTML, "<xml>foo<a>bar</a></xml>"); | 418 expect(doc.outerHtml, "<xml>foo<a>bar</a></xml>"); |
| 419 }); | 419 }); |
| 420 | 420 |
| 421 test('query', () { | 421 test('query', () { |
| 422 final doc = makeDocument(); | 422 final doc = makeDocument(); |
| 423 expect(doc.query('foo').tagName, 'foo'); | 423 expect(doc.query('foo').tagName, 'foo'); |
| 424 expect(doc.query('baz'), isNull); | 424 expect(doc.query('baz'), isNull); |
| 425 }); | 425 }); |
| 426 | 426 |
| 427 test('queryAll', () { | 427 test('queryAll', () { |
| 428 final doc = new XMLDocument.xml( | 428 final doc = new XMLDocument.xml( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 440 // expect(doc.matchesSelector('html'), isFalse); | 440 // expect(doc.matchesSelector('html'), isFalse); |
| 441 // }); | 441 // }); |
| 442 | 442 |
| 443 group('insertAdjacentElement', () { | 443 group('insertAdjacentElement', () { |
| 444 getDoc() => new XMLDocument.xml("<xml><a>foo</a></xml>"); | 444 getDoc() => new XMLDocument.xml("<xml><a>foo</a></xml>"); |
| 445 | 445 |
| 446 test('beforeBegin does nothing', () { | 446 test('beforeBegin does nothing', () { |
| 447 final doc = getDoc(); | 447 final doc = getDoc(); |
| 448 expect(doc.insertAdjacentElement("beforeBegin", new XMLElement.tag("b")), | 448 expect(doc.insertAdjacentElement("beforeBegin", new XMLElement.tag("b")), |
| 449 isNull); | 449 isNull); |
| 450 expect(doc.innerHTML, "<a>foo</a>"); | 450 expect(doc.innerHtml, "<a>foo</a>"); |
| 451 }); | 451 }); |
| 452 | 452 |
| 453 test('afterEnd does nothing', () { | 453 test('afterEnd does nothing', () { |
| 454 final doc = getDoc(); | 454 final doc = getDoc(); |
| 455 expect(doc.insertAdjacentElement("afterEnd", new XMLElement.tag("b")), | 455 expect(doc.insertAdjacentElement("afterEnd", new XMLElement.tag("b")), |
| 456 isNull); | 456 isNull); |
| 457 expect(doc.innerHTML, "<a>foo</a>"); | 457 expect(doc.innerHtml, "<a>foo</a>"); |
| 458 }); | 458 }); |
| 459 | 459 |
| 460 test('afterBegin inserts the element', () { | 460 test('afterBegin inserts the element', () { |
| 461 final doc = getDoc(); | 461 final doc = getDoc(); |
| 462 final el = new XMLElement.tag("b"); | 462 final el = new XMLElement.tag("b"); |
| 463 expect(doc.insertAdjacentElement("afterBegin", el), el); | 463 expect(doc.insertAdjacentElement("afterBegin", el), el); |
| 464 expect(doc.innerHTML, "<b></b><a>foo</a>"); | 464 expect(doc.innerHtml, "<b></b><a>foo</a>"); |
| 465 }); | 465 }); |
| 466 | 466 |
| 467 test('beforeEnd inserts the element', () { | 467 test('beforeEnd inserts the element', () { |
| 468 final doc = getDoc(); | 468 final doc = getDoc(); |
| 469 final el = new XMLElement.tag("b"); | 469 final el = new XMLElement.tag("b"); |
| 470 expect(doc.insertAdjacentElement("beforeEnd", el), el); | 470 expect(doc.insertAdjacentElement("beforeEnd", el), el); |
| 471 expect(doc.innerHTML, "<a>foo</a><b></b>"); | 471 expect(doc.innerHtml, "<a>foo</a><b></b>"); |
| 472 }); | 472 }); |
| 473 }); | 473 }); |
| 474 | 474 |
| 475 group('insertAdjacentText', () { | 475 group('insertAdjacentText', () { |
| 476 getDoc() => new XMLDocument.xml("<xml><a>foo</a></xml>"); | 476 getDoc() => new XMLDocument.xml("<xml><a>foo</a></xml>"); |
| 477 | 477 |
| 478 test('beforeBegin does nothing', () { | 478 test('beforeBegin does nothing', () { |
| 479 final doc = getDoc(); | 479 final doc = getDoc(); |
| 480 doc.insertAdjacentText("beforeBegin", "foo"); | 480 doc.insertAdjacentText("beforeBegin", "foo"); |
| 481 expect(doc.innerHTML, "<a>foo</a>"); | 481 expect(doc.innerHtml, "<a>foo</a>"); |
| 482 }); | 482 }); |
| 483 | 483 |
| 484 test('afterEnd does nothing', () { | 484 test('afterEnd does nothing', () { |
| 485 final doc = getDoc(); | 485 final doc = getDoc(); |
| 486 doc.insertAdjacentText("afterEnd", "foo"); | 486 doc.insertAdjacentText("afterEnd", "foo"); |
| 487 expect(doc.innerHTML, "<a>foo</a>"); | 487 expect(doc.innerHtml, "<a>foo</a>"); |
| 488 }); | 488 }); |
| 489 | 489 |
| 490 test('afterBegin inserts the text', () { | 490 test('afterBegin inserts the text', () { |
| 491 final doc = getDoc(); | 491 final doc = getDoc(); |
| 492 doc.insertAdjacentText("afterBegin", "foo"); | 492 doc.insertAdjacentText("afterBegin", "foo"); |
| 493 expect(doc.innerHTML, "foo<a>foo</a>"); | 493 expect(doc.innerHtml, "foo<a>foo</a>"); |
| 494 }); | 494 }); |
| 495 | 495 |
| 496 test('beforeEnd inserts the text', () { | 496 test('beforeEnd inserts the text', () { |
| 497 final doc = getDoc(); | 497 final doc = getDoc(); |
| 498 doc.insertAdjacentText("beforeEnd", "foo"); | 498 doc.insertAdjacentText("beforeEnd", "foo"); |
| 499 expect(doc.innerHTML, "<a>foo</a>foo"); | 499 expect(doc.innerHtml, "<a>foo</a>foo"); |
| 500 }); | 500 }); |
| 501 }); | 501 }); |
| 502 | 502 |
| 503 group('insertAdjacentHTML', () { | 503 group('insertAdjacentHtml', () { |
| 504 getDoc() => new XMLDocument.xml("<xml><a>foo</a></xml>"); | 504 getDoc() => new XMLDocument.xml("<xml><a>foo</a></xml>"); |
| 505 | 505 |
| 506 test('beforeBegin does nothing', () { | 506 test('beforeBegin does nothing', () { |
| 507 final doc = getDoc(); | 507 final doc = getDoc(); |
| 508 doc.insertAdjacentHTML("beforeBegin", "foo<b/>"); | 508 doc.insertAdjacentHtml("beforeBegin", "foo<b/>"); |
| 509 expect(doc.innerHTML, "<a>foo</a>"); | 509 expect(doc.innerHtml, "<a>foo</a>"); |
| 510 }); | 510 }); |
| 511 | 511 |
| 512 test('afterEnd does nothing', () { | 512 test('afterEnd does nothing', () { |
| 513 final doc = getDoc(); | 513 final doc = getDoc(); |
| 514 doc.insertAdjacentHTML("afterEnd", "<b/>foo"); | 514 doc.insertAdjacentHtml("afterEnd", "<b/>foo"); |
| 515 expect(doc.innerHTML, "<a>foo</a>"); | 515 expect(doc.innerHtml, "<a>foo</a>"); |
| 516 }); | 516 }); |
| 517 | 517 |
| 518 test('afterBegin inserts the HTML', () { | 518 test('afterBegin inserts the HTML', () { |
| 519 final doc = getDoc(); | 519 final doc = getDoc(); |
| 520 doc.insertAdjacentHTML("afterBegin", "foo<b/>"); | 520 doc.insertAdjacentHtml("afterBegin", "foo<b/>"); |
| 521 expect(doc.innerHTML, "foo<b></b><a>foo</a>"); | 521 expect(doc.innerHtml, "foo<b></b><a>foo</a>"); |
| 522 }); | 522 }); |
| 523 | 523 |
| 524 test('beforeEnd inserts the HTML', () { | 524 test('beforeEnd inserts the HTML', () { |
| 525 final doc = getDoc(); | 525 final doc = getDoc(); |
| 526 doc.insertAdjacentHTML("beforeEnd", "<b/>foo"); | 526 doc.insertAdjacentHtml("beforeEnd", "<b/>foo"); |
| 527 expect(doc.innerHTML, "<a>foo</a><b></b>foo"); | 527 expect(doc.innerHtml, "<a>foo</a><b></b>foo"); |
| 528 }); | 528 }); |
| 529 }); | 529 }); |
| 530 | 530 |
| 531 group('default values', () { | 531 group('default values', () { |
| 532 test('default rect values', () { | 532 test('default rect values', () { |
| 533 makeDocument().rect.then(expectAsync1((ElementRect rect) { | 533 makeDocument().rect.then(expectAsync1((ElementRect rect) { |
| 534 expectEmptyRect(rect.client); | 534 expectEmptyRect(rect.client); |
| 535 expectEmptyRect(rect.offset); | 535 expectEmptyRect(rect.offset); |
| 536 expectEmptyRect(rect.scroll); | 536 expectEmptyRect(rect.scroll); |
| 537 expectEmptyRect(rect.bounding); | 537 expectEmptyRect(rect.bounding); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 test('manifest', () => expect(makeDocument().manifest), ''); | 611 test('manifest', () => expect(makeDocument().manifest), ''); |
| 612 }); | 612 }); |
| 613 | 613 |
| 614 test('unsupported operations', () { | 614 test('unsupported operations', () { |
| 615 expectUnsupported(() { makeDocument().body = new XMLElement.tag('xml'); }); | 615 expectUnsupported(() { makeDocument().body = new XMLElement.tag('xml'); }); |
| 616 expectUnsupported(() => makeDocument().cookie); | 616 expectUnsupported(() => makeDocument().cookie); |
| 617 expectUnsupported(() { makeDocument().cookie = 'foo'; }); | 617 expectUnsupported(() { makeDocument().cookie = 'foo'; }); |
| 618 expectUnsupported(() { makeDocument().manifest = 'foo'; }); | 618 expectUnsupported(() { makeDocument().manifest = 'foo'; }); |
| 619 }); | 619 }); |
| 620 } | 620 } |
| OLD | NEW |