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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: tests/html/element_test.dart
diff --git a/tests/html/element_test.dart b/tests/html/element_test.dart
index b89ffe0c9f78f4d122c492425e730de638f91b64..e311a7bcf42fab937b4ad597c8682bdd0c55c1d0 100644
--- a/tests/html/element_test.dart
+++ b/tests/html/element_test.dart
@@ -18,6 +18,12 @@ expectLargeRect(ClientRect rect) {
void testEventHelper(EventListenerList listenerList, String type,
[Function registerOnEventListener = null]) {
+ testMultipleEventHelper(listenerList, [type], registerOnEventListener);
+}
+
+// Allows testing where we polyfill different browsers firing different events.
+void testMultipleEventHelper(EventListenerList listenerList, List<String> types,
+ [Function registerOnEventListener = null]) {
bool firedWhenAddedToListenerList = false;
bool firedOnEvent = false;
listenerList.add((e) {
@@ -28,8 +34,10 @@ void testEventHelper(EventListenerList listenerList, String type,
firedOnEvent = true;
});
}
- final event = new Event(type);
- listenerList.dispatch(event);
+ for (var type in types) {
+ final event = new Event(type);
+ listenerList.dispatch(event);
+ }
Expect.isTrue(firedWhenAddedToListenerList);
if (registerOnEventListener != null) {
@@ -75,13 +83,35 @@ main() {
expectLargeRect(rect.client);
expectLargeRect(rect.offset);
expectLargeRect(rect.scroll);
- Expect.equals(rect.bounding.left, 8);
- Expect.equals(rect.bounding.top, 8);
- Expect.isTrue(rect.clientRects.length > 0);
+ expect(rect.bounding.left, 8);
+ expect(rect.bounding.top, 8);
+ expect(rect.clientRects.length, greaterThan(0));
container.remove();
}));
});
+ test('client position synchronous', () {
+ final container = new Element.tag("div");
+ container.style.position = 'absolute';
+ container.style.top = '8px';
+ container.style.left = '8px';
+ final element = new Element.tag("div");
+ element.style.width = '200px';
+ element.style.height = '200px';
+ container.elements.add(element);
+ document.body.elements.add(container);
+
+ expect(element.clientWidth, greaterThan(100));
+ expect(element.clientHeight, greaterThan(100));
+ expect(element.offsetWidth, greaterThan(100));
+ expect(element.offsetHeight, greaterThan(100));
+ expect(element.scrollWidth, greaterThan(100));
+ expect(element.scrollHeight, greaterThan(100));
+ expect(element.getBoundingClientRect().left, 8);
+ expect(element.getBoundingClientRect().top, 8);
+ container.remove();
+ });
+
group('constructors', () {
test('error', () {
Expect.throws(() => new Element.html('<br/><br/>'),
@@ -122,14 +152,8 @@ main() {
// test('datalist', () => testConstructorHelper('datalist',
// '<datalist>foo</datalist>', 'foo',
// (element) => element is DataListElement));
- test('details', () => testConstructorHelper('details',
- '<details>foo</details>', 'foo',
- (element) => element is DetailsElement));
test('div', () => testConstructorHelper('div', '<div>foo</div>', 'foo',
(element) => element is DivElement));
- test('embed', () => testConstructorHelper('embed',
- '<embed>foo</embed>', '',
- (element) => element is EmbedElement));
test('fieldset', () => testConstructorHelper('fieldset',
'<fieldset>foo</fieldset>', 'foo',
(element) => element is FieldSetElement));
@@ -161,8 +185,6 @@ main() {
(element) => element is ImageElement));
test('input', () => testConstructorHelper('input', '<input/>', '',
(element) => element is InputElement));
- test('keygen', () => testConstructorHelper('keygen', '<keygen>', '',
- (element) => element is KeygenElement));
test('li', () => testConstructorHelper('li', '<li>foo</li>', 'foo',
(element) => element is LIElement));
test('label', () => testConstructorHelper('label',
@@ -175,25 +197,16 @@ main() {
(element) => element is LinkElement));
test('map', () => testConstructorHelper('map', '<map>foo</map>', 'foo',
(element) => element is MapElement));
- test('marquee', () => testConstructorHelper('marquee',
- '<marquee>foo</marquee>', 'foo',
- (element) => element is MarqueeElement));
test('menu', () => testConstructorHelper('menu', '<menu>foo</menu>', 'foo',
(element) => element is MenuElement));
test('meta', () => testConstructorHelper('meta', '<meta>', '',
(element) => element is MetaElement));
- test('meter', () => testConstructorHelper('meter',
- '<meter>foo</meter>', 'foo',
- (element) => element is MeterElement));
test('del', () => testConstructorHelper('del', '<del>foo</del>', 'foo',
(element) => element is ModElement));
test('ins', () => testConstructorHelper('ins', '<ins>foo</ins>', 'foo',
(element) => element is ModElement));
test('ol', () => testConstructorHelper('ol', '<ol>foo</ol>', 'foo',
(element) => element is OListElement));
- test('object', () => testConstructorHelper('object',
- '<object>foo</object>', 'foo',
- (element) => element is ObjectElement));
test('optgroup', () => testConstructorHelper('optgroup',
'<optgroup>foo</optgroup>', 'foo',
(element) => element is OptGroupElement));
@@ -374,7 +387,9 @@ main() {
testEventHelper(on.mouseUp, 'mouseup',
(listener) => Testing.addEventListener(
element, 'mouseup', listener, true));
- testEventHelper(on.mouseWheel, 'mousewheel',
+ // Browsers have different events that they use, so fire all variants.
+ testMultipleEventHelper(on.mouseWheel,
+ ['mousewheel', 'wheel', 'DOMMouseScroll'],
(listener) => Testing.addEventListener(
element, 'mousewheel', listener, true));
testEventHelper(on.paste, 'paste',
@@ -411,10 +426,6 @@ main() {
testEventHelper(on.touchStart, 'touchstart',
(listener) => Testing.addEventListener(
element, 'touchstart', listener, true));
- testEventHelper(on.transitionEnd, 'webkitTransitionEnd');
- testEventHelper(on.fullscreenChange, 'webkitfullscreenchange',
- (listener) => Testing.addEventListener(element,
- 'webkitfullscreenchange', listener, true));
});
group('attributes', () {

Powered by Google App Engine
This is Rietveld 408576698