Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: test/codegen/lib/html/htmlelement_test.dart

Issue 1930043002: Add all dart:html tests from the sdk to test/codegen. (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 library ElementTest;
2 import 'package:unittest/unittest.dart';
3 import 'package:unittest/html_config.dart';
4 import 'dart:html';
5 import 'utils.dart';
6
7 main() {
8 useHtmlConfiguration();
9 test('InnerHTML', () {
10 Element element = new Element.tag('div');
11 element.id = 'test';
12 element.innerHtml = 'Hello World';
13 document.body.append(element);
14
15 element = document.query('#test');
16 expect(element.innerHtml, 'Hello World');
17 element.remove();
18 });
19 test('HTMLTable', () {
20 Element table = new Element.tag('table');
21
22 TableRowElement row = new Element.tag('tr');
23 table.append(row);
24
25 row.append(new Element.tag('td'));
26 row.append(new Element.tag('td'));
27
28 expect(row.cells.length, 2);
29
30 TableRowElement headerRow = table.rows[0];
31 expect(headerRow.cells.length, 2);
32 });
33 test('dataset', () {
34 Element div = new Element.tag('div');
35
36 expect(div.dataset.isEmpty, isTrue);
37 expect(div.dataset['foo'], isNull);
38 expect(div.dataset.isEmpty, isTrue);
39
40 div.dataset['foo'] = 'foo-value';
41 expect(div.dataset['foo'], 'foo-value');
42 expect(div.dataset.isEmpty, isFalse);
43
44 expect(div.dataset.containsValue('foo-value'), isTrue);
45 expect(div.dataset.containsValue('bar-value'), isFalse);
46 expect(div.dataset.containsKey('foo'), isTrue);
47 expect(div.dataset.containsKey('bar'), isFalse);
48
49 bool hasBeenInvoked;
50 String f() {
51 hasBeenInvoked = true;
52 return 'bar-value';
53 }
54
55 hasBeenInvoked = false;
56 expect(div.dataset.putIfAbsent('bar', f), 'bar-value');
57 expect(hasBeenInvoked, isTrue);
58
59 hasBeenInvoked = false;
60 expect(div.dataset.putIfAbsent('bar', f), 'bar-value');
61 expect(hasBeenInvoked, isFalse);
62
63 final keys = <String> [];
64 final values = <String> [];
65 div.dataset.forEach((String key, String value) {
66 keys.add(key);
67 values.add(value);
68 });
69 expect(keys, unorderedEquals(['foo', 'bar']));
70 expect(values, unorderedEquals(['foo-value', 'bar-value']));
71
72 expect(new List<String>.from(div.dataset.keys),
73 unorderedEquals(['foo', 'bar']));
74 expect(new List<String>.from(div.dataset.values),
75 unorderedEquals(['foo-value', 'bar-value']));
76
77 expect(div.dataset.length, 2);
78 expect(div.dataset.isEmpty, isFalse);
79
80 expect(div.dataset.remove('qux'), isNull);
81 expect(div.dataset.length, 2);
82 expect(div.dataset.isEmpty, isFalse);
83
84 expect(div.dataset.remove('foo'), 'foo-value');
85 expect(div.dataset.length, 1);
86 expect(div.dataset.isEmpty, isFalse);
87
88 div.dataset.clear();
89 expect(div.dataset.length, 0);
90 expect(div.dataset.isEmpty, isTrue);
91
92 Element otherDiv = new Element.html(
93 '<div id="dataDiv" data-my-message="Hello World"></div>',
94 treeSanitizer: new NullTreeSanitizer());
95 expect(otherDiv.dataset.containsKey('myMessage'), isTrue);
96
97 Element anotherDiv = new Element.html(
98 '<div id="dataDiv" data-eggs="bacon"></div>',
99 treeSanitizer: new NullTreeSanitizer());
100 expect(anotherDiv.dataset.containsKey('eggs'), isTrue);
101 });
102 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698