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

Side by Side Diff: tests/html/element_test.dart

Issue 11046025: Adding synchronous measurement methods to Element. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Re-adding mistakenly removed Element.rect API. Created 8 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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('ElementTest'); 5 #library('ElementTest');
6 #import('../../pkg/unittest/unittest.dart'); 6 #import('../../pkg/unittest/unittest.dart');
7 #import('../../pkg/unittest/html_config.dart'); 7 #import('../../pkg/unittest/html_config.dart');
8 #import('dart:html'); 8 #import('dart:html');
9 9
10 expectLargeRect(ClientRect rect) { 10 expectLargeRect(ClientRect rect) {
11 Expect.equals(rect.top, 0); 11 Expect.equals(rect.top, 0);
12 Expect.equals(rect.left, 0); 12 Expect.equals(rect.left, 0);
13 Expect.isTrue(rect.width > 100); 13 Expect.isTrue(rect.width > 100);
14 Expect.isTrue(rect.height > 100); 14 Expect.isTrue(rect.height > 100);
15 Expect.equals(rect.bottom, rect.top + rect.height); 15 Expect.equals(rect.bottom, rect.top + rect.height);
16 Expect.equals(rect.right, rect.left + rect.width); 16 Expect.equals(rect.right, rect.left + rect.width);
17 } 17 }
18 18
19 void testEventHelper(EventListenerList listenerList, String type, 19 void testEventHelper(EventListenerList listenerList, String type,
20 [Function registerOnEventListener = null]) { 20 [Function registerOnEventListener = null]) {
21 testMultipleEventHelper(listenerList, [type], registerOnEventListener);
22 }
23
24 // Allows testing where we polyfill different browsers firing different events.
25 void testMultipleEventHelper(EventListenerList listenerList, List<String> types,
26 [Function registerOnEventListener = null]) {
21 bool firedWhenAddedToListenerList = false; 27 bool firedWhenAddedToListenerList = false;
22 bool firedOnEvent = false; 28 bool firedOnEvent = false;
23 listenerList.add((e) { 29 listenerList.add((e) {
24 firedWhenAddedToListenerList = true; 30 firedWhenAddedToListenerList = true;
25 }); 31 });
26 if (registerOnEventListener != null) { 32 if (registerOnEventListener != null) {
27 registerOnEventListener((e) { 33 registerOnEventListener((e) {
28 firedOnEvent = true; 34 firedOnEvent = true;
29 }); 35 });
30 } 36 }
31 final event = new Event(type); 37 for (var type in types) {
32 listenerList.dispatch(event); 38 final event = new Event(type);
39 listenerList.dispatch(event);
40 }
33 41
34 Expect.isTrue(firedWhenAddedToListenerList); 42 Expect.isTrue(firedWhenAddedToListenerList);
35 if (registerOnEventListener != null) { 43 if (registerOnEventListener != null) {
36 Expect.isTrue(firedOnEvent); 44 Expect.isTrue(firedOnEvent);
37 } 45 }
38 } 46 }
39 47
40 void testConstructorHelper(String tag, String htmlSnippet, 48 void testConstructorHelper(String tag, String htmlSnippet,
41 String expectedText, Function isExpectedClass) { 49 String expectedText, Function isExpectedClass) {
42 Expect.isTrue(isExpectedClass(new Element.tag(tag))); 50 Expect.isTrue(isExpectedClass(new Element.tag(tag)));
(...skipping 25 matching lines...) Expand all
68 final element = new Element.tag("div"); 76 final element = new Element.tag("div");
69 element.style.width = '200px'; 77 element.style.width = '200px';
70 element.style.height = '200px'; 78 element.style.height = '200px';
71 container.elements.add(element); 79 container.elements.add(element);
72 document.body.elements.add(container); 80 document.body.elements.add(container);
73 81
74 element.rect.then(expectAsync1((rect) { 82 element.rect.then(expectAsync1((rect) {
75 expectLargeRect(rect.client); 83 expectLargeRect(rect.client);
76 expectLargeRect(rect.offset); 84 expectLargeRect(rect.offset);
77 expectLargeRect(rect.scroll); 85 expectLargeRect(rect.scroll);
78 Expect.equals(rect.bounding.left, 8); 86 expect(rect.bounding.left, 8);
79 Expect.equals(rect.bounding.top, 8); 87 expect(rect.bounding.top, 8);
80 Expect.isTrue(rect.clientRects.length > 0); 88 expect(rect.clientRects.length, greaterThan(0));
81 container.remove(); 89 container.remove();
82 })); 90 }));
83 }); 91 });
84 92
93 test('client position synchronous', () {
94 final container = new Element.tag("div");
95 container.style.position = 'absolute';
96 container.style.top = '8px';
97 container.style.left = '8px';
98 final element = new Element.tag("div");
99 element.style.width = '200px';
100 element.style.height = '200px';
101 container.elements.add(element);
102 document.body.elements.add(container);
103
104 expect(element.clientWidth, greaterThan(100));
105 expect(element.clientHeight, greaterThan(100));
106 expect(element.offsetWidth, greaterThan(100));
107 expect(element.offsetHeight, greaterThan(100));
108 expect(element.scrollWidth, greaterThan(100));
109 expect(element.scrollHeight, greaterThan(100));
110 expect(element.getBoundingClientRect().left, 8);
111 expect(element.getBoundingClientRect().top, 8);
112 container.remove();
113 });
114
85 group('constructors', () { 115 group('constructors', () {
86 test('error', () { 116 test('error', () {
87 Expect.throws(() => new Element.html('<br/><br/>'), 117 Expect.throws(() => new Element.html('<br/><br/>'),
88 (e) => e is ArgumentError); 118 (e) => e is ArgumentError);
89 }); 119 });
90 120
91 test('.html has no parent', () => 121 test('.html has no parent', () =>
92 Expect.isNull(new Element.html('<br/>').parent)); 122 Expect.isNull(new Element.html('<br/>').parent));
93 123
94 test('a', () => testConstructorHelper('a', '<a>foo</a>', 'foo', 124 test('a', () => testConstructorHelper('a', '<a>foo</a>', 'foo',
(...skipping 20 matching lines...) Expand all
115 (element) => element is ButtonElement)); 145 (element) => element is ButtonElement));
116 test('canvas', () => testConstructorHelper('canvas', 146 test('canvas', () => testConstructorHelper('canvas',
117 '<canvas>foo</canvas>', 'foo', 147 '<canvas>foo</canvas>', 'foo',
118 (element) => element is CanvasElement)); 148 (element) => element is CanvasElement));
119 test('dl', () => testConstructorHelper('dl', '<dl>foo</dl>', 'foo', 149 test('dl', () => testConstructorHelper('dl', '<dl>foo</dl>', 'foo',
120 (element) => element is DListElement)); 150 (element) => element is DListElement));
121 // TODO(jacobr): WebKit doesn't yet support the DataList class. 151 // TODO(jacobr): WebKit doesn't yet support the DataList class.
122 // test('datalist', () => testConstructorHelper('datalist', 152 // test('datalist', () => testConstructorHelper('datalist',
123 // '<datalist>foo</datalist>', 'foo', 153 // '<datalist>foo</datalist>', 'foo',
124 // (element) => element is DataListElement)); 154 // (element) => element is DataListElement));
125 test('details', () => testConstructorHelper('details',
126 '<details>foo</details>', 'foo',
127 (element) => element is DetailsElement));
128 test('div', () => testConstructorHelper('div', '<div>foo</div>', 'foo', 155 test('div', () => testConstructorHelper('div', '<div>foo</div>', 'foo',
129 (element) => element is DivElement)); 156 (element) => element is DivElement));
130 test('embed', () => testConstructorHelper('embed',
131 '<embed>foo</embed>', '',
132 (element) => element is EmbedElement));
133 test('fieldset', () => testConstructorHelper('fieldset', 157 test('fieldset', () => testConstructorHelper('fieldset',
134 '<fieldset>foo</fieldset>', 'foo', 158 '<fieldset>foo</fieldset>', 'foo',
135 (element) => element is FieldSetElement)); 159 (element) => element is FieldSetElement));
136 test('font', () => testConstructorHelper('font', '<font>foo</font>', 'foo', 160 test('font', () => testConstructorHelper('font', '<font>foo</font>', 'foo',
137 (element) => element is FontElement)); 161 (element) => element is FontElement));
138 test('form', () => testConstructorHelper('form', '<form>foo</form>', 'foo', 162 test('form', () => testConstructorHelper('form', '<form>foo</form>', 'foo',
139 (element) => element is FormElement)); 163 (element) => element is FormElement));
140 test('hr', () => testConstructorHelper('hr', '<hr>', '', 164 test('hr', () => testConstructorHelper('hr', '<hr>', '',
141 (element) => element is HRElement)); 165 (element) => element is HRElement));
142 test('head', () => testConstructorHelper('head', 166 test('head', () => testConstructorHelper('head',
(...skipping 11 matching lines...) Expand all
154 (element) => element is HeadingElement)); 178 (element) => element is HeadingElement));
155 test('h6', () => testConstructorHelper('h6', '<h6>foo</h6>', 'foo', 179 test('h6', () => testConstructorHelper('h6', '<h6>foo</h6>', 'foo',
156 (element) => element is HeadingElement)); 180 (element) => element is HeadingElement));
157 test('iframe', () => testConstructorHelper('iframe', 181 test('iframe', () => testConstructorHelper('iframe',
158 '<iframe>foo</iframe>', 'foo', 182 '<iframe>foo</iframe>', 'foo',
159 (element) => element is IFrameElement)); 183 (element) => element is IFrameElement));
160 test('img', () => testConstructorHelper('img', '<img>', '', 184 test('img', () => testConstructorHelper('img', '<img>', '',
161 (element) => element is ImageElement)); 185 (element) => element is ImageElement));
162 test('input', () => testConstructorHelper('input', '<input/>', '', 186 test('input', () => testConstructorHelper('input', '<input/>', '',
163 (element) => element is InputElement)); 187 (element) => element is InputElement));
164 test('keygen', () => testConstructorHelper('keygen', '<keygen>', '',
165 (element) => element is KeygenElement));
166 test('li', () => testConstructorHelper('li', '<li>foo</li>', 'foo', 188 test('li', () => testConstructorHelper('li', '<li>foo</li>', 'foo',
167 (element) => element is LIElement)); 189 (element) => element is LIElement));
168 test('label', () => testConstructorHelper('label', 190 test('label', () => testConstructorHelper('label',
169 '<label>foo</label>', 'foo', 191 '<label>foo</label>', 'foo',
170 (element) => element is LabelElement)); 192 (element) => element is LabelElement));
171 test('legend', () => testConstructorHelper('legend', 193 test('legend', () => testConstructorHelper('legend',
172 '<legend>foo</legend>', 'foo', 194 '<legend>foo</legend>', 'foo',
173 (element) => element is LegendElement)); 195 (element) => element is LegendElement));
174 test('link', () => testConstructorHelper('link', '<link>', '', 196 test('link', () => testConstructorHelper('link', '<link>', '',
175 (element) => element is LinkElement)); 197 (element) => element is LinkElement));
176 test('map', () => testConstructorHelper('map', '<map>foo</map>', 'foo', 198 test('map', () => testConstructorHelper('map', '<map>foo</map>', 'foo',
177 (element) => element is MapElement)); 199 (element) => element is MapElement));
178 test('marquee', () => testConstructorHelper('marquee',
179 '<marquee>foo</marquee>', 'foo',
180 (element) => element is MarqueeElement));
181 test('menu', () => testConstructorHelper('menu', '<menu>foo</menu>', 'foo', 200 test('menu', () => testConstructorHelper('menu', '<menu>foo</menu>', 'foo',
182 (element) => element is MenuElement)); 201 (element) => element is MenuElement));
183 test('meta', () => testConstructorHelper('meta', '<meta>', '', 202 test('meta', () => testConstructorHelper('meta', '<meta>', '',
184 (element) => element is MetaElement)); 203 (element) => element is MetaElement));
185 test('meter', () => testConstructorHelper('meter',
186 '<meter>foo</meter>', 'foo',
187 (element) => element is MeterElement));
188 test('del', () => testConstructorHelper('del', '<del>foo</del>', 'foo', 204 test('del', () => testConstructorHelper('del', '<del>foo</del>', 'foo',
189 (element) => element is ModElement)); 205 (element) => element is ModElement));
190 test('ins', () => testConstructorHelper('ins', '<ins>foo</ins>', 'foo', 206 test('ins', () => testConstructorHelper('ins', '<ins>foo</ins>', 'foo',
191 (element) => element is ModElement)); 207 (element) => element is ModElement));
192 test('ol', () => testConstructorHelper('ol', '<ol>foo</ol>', 'foo', 208 test('ol', () => testConstructorHelper('ol', '<ol>foo</ol>', 'foo',
193 (element) => element is OListElement)); 209 (element) => element is OListElement));
194 test('object', () => testConstructorHelper('object',
195 '<object>foo</object>', 'foo',
196 (element) => element is ObjectElement));
197 test('optgroup', () => testConstructorHelper('optgroup', 210 test('optgroup', () => testConstructorHelper('optgroup',
198 '<optgroup>foo</optgroup>', 'foo', 211 '<optgroup>foo</optgroup>', 'foo',
199 (element) => element is OptGroupElement)); 212 (element) => element is OptGroupElement));
200 test('option', () => testConstructorHelper('option', 213 test('option', () => testConstructorHelper('option',
201 '<option>foo</option>', 'foo', 214 '<option>foo</option>', 'foo',
202 (element) => element is OptionElement)); 215 (element) => element is OptionElement));
203 test('output', () => testConstructorHelper('output', 216 test('output', () => testConstructorHelper('output',
204 '<output>foo</output>', 'foo', 217 '<output>foo</output>', 'foo',
205 (element) => element is OutputElement)); 218 (element) => element is OutputElement));
206 test('p', () => testConstructorHelper('p', '<p>foo</p>', 'foo', 219 test('p', () => testConstructorHelper('p', '<p>foo</p>', 'foo',
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 element, 'mousemove', listener, true)); 380 element, 'mousemove', listener, true));
368 testEventHelper(on.mouseOut, 'mouseout', 381 testEventHelper(on.mouseOut, 'mouseout',
369 (listener) => Testing.addEventListener( 382 (listener) => Testing.addEventListener(
370 element, 'mouseout', listener, true)); 383 element, 'mouseout', listener, true));
371 testEventHelper(on.mouseOver, 'mouseover', 384 testEventHelper(on.mouseOver, 'mouseover',
372 (listener) => Testing.addEventListener( 385 (listener) => Testing.addEventListener(
373 element, 'mouseover', listener, true)); 386 element, 'mouseover', listener, true));
374 testEventHelper(on.mouseUp, 'mouseup', 387 testEventHelper(on.mouseUp, 'mouseup',
375 (listener) => Testing.addEventListener( 388 (listener) => Testing.addEventListener(
376 element, 'mouseup', listener, true)); 389 element, 'mouseup', listener, true));
377 testEventHelper(on.mouseWheel, 'mousewheel', 390 // Browsers have different events that they use, so fire all variants.
391 testMultipleEventHelper(on.mouseWheel,
392 ['mousewheel', 'wheel', 'DOMMouseScroll'],
378 (listener) => Testing.addEventListener( 393 (listener) => Testing.addEventListener(
379 element, 'mousewheel', listener, true)); 394 element, 'mousewheel', listener, true));
380 testEventHelper(on.paste, 'paste', 395 testEventHelper(on.paste, 'paste',
381 (listener) => Testing.addEventListener( 396 (listener) => Testing.addEventListener(
382 element, 'paste', listener, true)); 397 element, 'paste', listener, true));
383 testEventHelper(on.reset, 'reset', 398 testEventHelper(on.reset, 'reset',
384 (listener) => Testing.addEventListener( 399 (listener) => Testing.addEventListener(
385 element, 'reset', listener, true)); 400 element, 'reset', listener, true));
386 testEventHelper(on.scroll, 'scroll', 401 testEventHelper(on.scroll, 'scroll',
387 (listener) => Testing.addEventListener( 402 (listener) => Testing.addEventListener(
(...skipping 16 matching lines...) Expand all
404 testEventHelper(on.touchEnd, 'touchend', 419 testEventHelper(on.touchEnd, 'touchend',
405 (listener) => Testing.addEventListener( 420 (listener) => Testing.addEventListener(
406 element, 'touchend', listener, true)); 421 element, 'touchend', listener, true));
407 testEventHelper(on.touchLeave, 'touchleave'); 422 testEventHelper(on.touchLeave, 'touchleave');
408 testEventHelper(on.touchMove, 'touchmove', 423 testEventHelper(on.touchMove, 'touchmove',
409 (listener) => Testing.addEventListener( 424 (listener) => Testing.addEventListener(
410 element, 'touchmove', listener, true)); 425 element, 'touchmove', listener, true));
411 testEventHelper(on.touchStart, 'touchstart', 426 testEventHelper(on.touchStart, 'touchstart',
412 (listener) => Testing.addEventListener( 427 (listener) => Testing.addEventListener(
413 element, 'touchstart', listener, true)); 428 element, 'touchstart', listener, true));
414 testEventHelper(on.transitionEnd, 'webkitTransitionEnd');
415 testEventHelper(on.fullscreenChange, 'webkitfullscreenchange',
416 (listener) => Testing.addEventListener(element,
417 'webkitfullscreenchange', listener, true));
418 }); 429 });
419 430
420 group('attributes', () { 431 group('attributes', () {
421 test('manipulation', () { 432 test('manipulation', () {
422 final element = new Element.html( 433 final element = new Element.html(
423 '''<div class="foo" style="overflow: hidden" data-foo="bar" 434 '''<div class="foo" style="overflow: hidden" data-foo="bar"
424 data-foo2="bar2" dir="rtl"> 435 data-foo2="bar2" dir="rtl">
425 </div>'''); 436 </div>''');
426 final attributes = element.attributes; 437 final attributes = element.attributes;
427 Expect.equals(attributes['class'], 'foo'); 438 Expect.equals(attributes['class'], 'foo');
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 }); 740 });
730 741
731 test('getRange', () { 742 test('getRange', () {
732 var range = makeElList().getRange(1, 2); 743 var range = makeElList().getRange(1, 2);
733 Expect.isTrue(range is List<Element>); 744 Expect.isTrue(range is List<Element>);
734 Expect.isTrue(range[0] is ImageElement); 745 Expect.isTrue(range[0] is ImageElement);
735 Expect.isTrue(range[1] is InputElement); 746 Expect.isTrue(range[1] is InputElement);
736 }); 747 });
737 }); 748 });
738 } 749 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698