| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 |
| 6 expectLargeRect(ClientRect rect) { |
| 7 Expect.equals(rect.top, 0); |
| 8 Expect.equals(rect.left, 0); |
| 9 Expect.isTrue(rect.width > 100); |
| 10 Expect.isTrue(rect.height > 100); |
| 11 Expect.equals(rect.bottom, rect.top + rect.height); |
| 12 Expect.equals(rect.right, rect.left + rect.width); |
| 13 } |
| 14 |
| 15 void testEventHelper(EventListenerList listenerList, String type, |
| 16 [Function registerOnEventListener = null]) { |
| 17 bool firedWhenAddedToListenerList = false; |
| 18 bool firedOnEvent = false; |
| 19 listenerList.add((e) { |
| 20 firedWhenAddedToListenerList = true; |
| 21 }); |
| 22 if (registerOnEventListener != null) { |
| 23 registerOnEventListener((e) { |
| 24 firedOnEvent = true; |
| 25 }); |
| 26 } |
| 27 final event = new Event(type); |
| 28 listenerList.dispatch(event); |
| 29 |
| 30 Expect.isTrue(firedWhenAddedToListenerList); |
| 31 if (registerOnEventListener != null) { |
| 32 Expect.isTrue(firedOnEvent); |
| 33 } |
| 34 } |
| 35 |
| 36 void testConstructorHelper(String tag, String htmlSnippet, |
| 37 String expectedText, Function isExpectedClass) { |
| 38 Expect.isTrue(isExpectedClass(new Element.tag(tag))); |
| 39 final elementFromSnippet = new Element.html(htmlSnippet); |
| 40 Expect.isTrue(isExpectedClass(elementFromSnippet)); |
| 41 Expect.equals(elementFromSnippet.text, expectedText); |
| 42 } |
| 43 |
| 44 void testElement() { |
| 45 asyncTest('computedStyle', 1, () { |
| 46 final element = document.body; |
| 47 element.computedStyle.then((style) { |
| 48 Expect.equals(style.getPropertyValue('left'), 'auto'); |
| 49 callbackDone(); |
| 50 }); |
| 51 }); |
| 52 |
| 53 asyncTest('rect', 1, () { |
| 54 final element = document.body; |
| 55 element.rect.then((rect) { |
| 56 expectLargeRect(rect.client); |
| 57 expectLargeRect(rect.offset); |
| 58 expectLargeRect(rect.scroll); |
| 59 Expect.equals(rect.bounding.left, 8); |
| 60 Expect.equals(rect.bounding.top, 8); |
| 61 Expect.isTrue(rect.clientRects.length > 0); |
| 62 callbackDone(); |
| 63 }); |
| 64 }); |
| 65 |
| 66 group('constructors', () { |
| 67 test('a', () => testConstructorHelper('a', '<a>foo</a>', 'foo', |
| 68 (element) => element is AnchorElement)); |
| 69 test('area', () => testConstructorHelper('area', '<area>foo</area>', '', |
| 70 (element) => element is AreaElement)); |
| 71 // TODO(jacobr): audio tags cause tests to segfault when using dartium. |
| 72 // b/5522106. |
| 73 // test('audio', () => testConstructorHelper('audio', |
| 74 // '<audio>foo</audio>', 'foo', |
| 75 // (element) => element is AudioElement)); |
| 76 test('br', () => testConstructorHelper('br', '<br>', '', |
| 77 (element) => element is BRElement)); |
| 78 test('base', () => testConstructorHelper('base', '<base>foo</base>', '', |
| 79 (element) => element is BaseElement)); |
| 80 test('blockquote', () => testConstructorHelper('blockquote', |
| 81 '<blockquote>foo</blockquote>', 'foo', |
| 82 (element) => element is QuoteElement)); |
| 83 test('body', () => testConstructorHelper('body', |
| 84 '<body><div>foo</div></body>', 'foo', |
| 85 (element) => element is BodyElement)); |
| 86 test('button', () => testConstructorHelper('button', |
| 87 '<button>foo</button>', 'foo', |
| 88 (element) => element is ButtonElement)); |
| 89 test('canvas', () => testConstructorHelper('canvas', |
| 90 '<canvas>foo</canvas>', 'foo', |
| 91 (element) => element is CanvasElement)); |
| 92 test('dl', () => testConstructorHelper('dl', '<dl>foo</dl>', 'foo', |
| 93 (element) => element is DListElement)); |
| 94 // TODO(jacobr): WebKit doesn't yet support the DataList class. |
| 95 // test('datalist', () => testConstructorHelper('datalist', |
| 96 // '<datalist>foo</datalist>', 'foo', |
| 97 // (element) => element is DataListElement)); |
| 98 test('details', () => testConstructorHelper('details', |
| 99 '<details>foo</details>', 'foo', |
| 100 (element) => element is DetailsElement)); |
| 101 test('div', () => testConstructorHelper('div', '<div>foo</div>', 'foo', |
| 102 (element) => element is DivElement)); |
| 103 test('embed', () => testConstructorHelper('embed', |
| 104 '<embed>foo</embed>', '', |
| 105 (element) => element is EmbedElement)); |
| 106 test('fieldset', () => testConstructorHelper('fieldset', |
| 107 '<fieldset>foo</fieldset>', 'foo', |
| 108 (element) => element is FieldSetElement)); |
| 109 test('font', () => testConstructorHelper('font', '<font>foo</font>', 'foo', |
| 110 (element) => element is FontElement)); |
| 111 test('form', () => testConstructorHelper('form', '<form>foo</form>', 'foo', |
| 112 (element) => element is FormElement)); |
| 113 test('hr', () => testConstructorHelper('hr', '<hr>', '', |
| 114 (element) => element is HRElement)); |
| 115 test('head', () => testConstructorHelper('head', |
| 116 '<head><script>foo;</script></head>', 'foo;', |
| 117 (element) => element is HeadElement)); |
| 118 test('h1', () => testConstructorHelper('h1', '<h1>foo</h1>', 'foo', |
| 119 (element) => element is HeadingElement)); |
| 120 test('h2', () => testConstructorHelper('h2', '<h2>foo</h2>', 'foo', |
| 121 (element) => element is HeadingElement)); |
| 122 test('h3', () => testConstructorHelper('h3', '<h3>foo</h3>', 'foo', |
| 123 (element) => element is HeadingElement)); |
| 124 test('h4', () => testConstructorHelper('h4', '<h4>foo</h4>', 'foo', |
| 125 (element) => element is HeadingElement)); |
| 126 test('h5', () => testConstructorHelper('h5', '<h5>foo</h5>', 'foo', |
| 127 (element) => element is HeadingElement)); |
| 128 test('h6', () => testConstructorHelper('h6', '<h6>foo</h6>', 'foo', |
| 129 (element) => element is HeadingElement)); |
| 130 test('iframe', () => testConstructorHelper('iframe', |
| 131 '<iframe>foo</iframe>', 'foo', |
| 132 (element) => element is IFrameElement)); |
| 133 test('img', () => testConstructorHelper('img', '<img>', '', |
| 134 (element) => element is ImageElement)); |
| 135 test('input', () => testConstructorHelper('input', '<input/>', '', |
| 136 (element) => element is InputElement)); |
| 137 test('keygen', () => testConstructorHelper('keygen', '<keygen>', '', |
| 138 (element) => element is KeygenElement)); |
| 139 test('li', () => testConstructorHelper('li', '<li>foo</li>', 'foo', |
| 140 (element) => element is LIElement)); |
| 141 test('label', () => testConstructorHelper('label', |
| 142 '<label>foo</label>', 'foo', |
| 143 (element) => element is LabelElement)); |
| 144 test('legend', () => testConstructorHelper('legend', |
| 145 '<legend>foo</legend>', 'foo', |
| 146 (element) => element is LegendElement)); |
| 147 test('link', () => testConstructorHelper('link', '<link>', '', |
| 148 (element) => element is LinkElement)); |
| 149 test('map', () => testConstructorHelper('map', '<map>foo</map>', 'foo', |
| 150 (element) => element is MapElement)); |
| 151 test('marquee', () => testConstructorHelper('marquee', |
| 152 '<marquee>foo</marquee>', 'foo', |
| 153 (element) => element is MarqueeElement)); |
| 154 test('menu', () => testConstructorHelper('menu', '<menu>foo</menu>', 'foo', |
| 155 (element) => element is MenuElement)); |
| 156 test('meta', () => testConstructorHelper('meta', '<meta>', '', |
| 157 (element) => element is MetaElement)); |
| 158 test('meter', () => testConstructorHelper('meter', |
| 159 '<meter>foo</meter>', 'foo', |
| 160 (element) => element is MeterElement)); |
| 161 test('del', () => testConstructorHelper('del', '<del>foo</del>', 'foo', |
| 162 (element) => element is ModElement)); |
| 163 test('ins', () => testConstructorHelper('ins', '<ins>foo</ins>', 'foo', |
| 164 (element) => element is ModElement)); |
| 165 test('ol', () => testConstructorHelper('ol', '<ol>foo</ol>', 'foo', |
| 166 (element) => element is OListElement)); |
| 167 test('object', () => testConstructorHelper('object', |
| 168 '<object>foo</object>', 'foo', |
| 169 (element) => element is ObjectElement)); |
| 170 test('optgroup', () => testConstructorHelper('optgroup', |
| 171 '<optgroup>foo</optgroup>', 'foo', |
| 172 (element) => element is OptGroupElement)); |
| 173 test('option', () => testConstructorHelper('option', |
| 174 '<option>foo</option>', 'foo', |
| 175 (element) => element is OptionElement)); |
| 176 test('output', () => testConstructorHelper('output', |
| 177 '<output>foo</output>', 'foo', |
| 178 (element) => element is OutputElement)); |
| 179 test('p', () => testConstructorHelper('p', '<p>foo</p>', 'foo', |
| 180 (element) => element is ParagraphElement)); |
| 181 test('param', () => testConstructorHelper('param', '<param>', '', |
| 182 (element) => element is ParamElement)); |
| 183 test('pre', () => testConstructorHelper('pre', '<pre>foo</pre>', 'foo', |
| 184 (element) => element is PreElement)); |
| 185 test('progress', () => testConstructorHelper('progress', |
| 186 '<progress>foo</progress>', 'foo', |
| 187 (element) => element is ProgressElement)); |
| 188 test('q', () => testConstructorHelper('q', '<q>foo</q>', 'foo', |
| 189 (element) => element is QuoteElement)); |
| 190 test('script', () => testConstructorHelper('script', |
| 191 '<script>foo</script>', 'foo', |
| 192 (element) => element is ScriptElement)); |
| 193 test('select', () => testConstructorHelper('select', |
| 194 '<select>foo</select>', 'foo', |
| 195 (element) => element is SelectElement)); |
| 196 // TODO(jacobr): audio tags cause tests to segfault when using dartium. |
| 197 // b/5522106. |
| 198 // test('source', () => testConstructorHelper('source', '<source>', '', |
| 199 // (element) => element is SourceElement)); |
| 200 test('span', () => testConstructorHelper('span', '<span>foo</span>', 'foo', |
| 201 (element) => element is SpanElement)); |
| 202 test('style', () => testConstructorHelper('style', |
| 203 '<style>foo</style>', 'foo', |
| 204 (element) => element is StyleElement)); |
| 205 test('caption', () => testConstructorHelper('caption', |
| 206 '<caption>foo</caption>', 'foo', |
| 207 (element) => element is TableCaptionElement)); |
| 208 test('td', () => testConstructorHelper('td', '<td>foo</td>', 'foo', |
| 209 (element) => element is TableCellElement)); |
| 210 test('colgroup', () => testConstructorHelper('colgroup', |
| 211 '<colgroup></colgroup>', '', |
| 212 (element) => element is TableColElement)); |
| 213 test('col', () => testConstructorHelper('col', '<col></col>', '', |
| 214 (element) => element is TableColElement)); |
| 215 test('table', () => testConstructorHelper('table', |
| 216 '<table><caption>foo</caption></table>', 'foo', |
| 217 (element) => element is TableElement)); |
| 218 test('tr', () => testConstructorHelper('tr', |
| 219 '<tr><td>foo</td></tr>', 'foo', |
| 220 (element) => element is TableRowElement)); |
| 221 test('tbody', () => testConstructorHelper('tbody', |
| 222 '<tbody><tr><td>foo</td></tr></tbody>', 'foo', |
| 223 (element) => element is TableSectionElement)); |
| 224 test('tfoot', () => testConstructorHelper('tfoot', |
| 225 '<tfoot><tr><td>foo</td></tr></tfoot>', 'foo', |
| 226 (element) => element is TableSectionElement)); |
| 227 test('thead', () => testConstructorHelper('thead', |
| 228 '<thead><tr><td>foo</td></tr></thead>', 'foo', |
| 229 (element) => element is TableSectionElement)); |
| 230 test('textarea', () => testConstructorHelper('textarea', |
| 231 '<textarea>foo</textarea>', 'foo', |
| 232 (element) => element is TextAreaElement)); |
| 233 test('title', () => testConstructorHelper('title', |
| 234 '<title>foo</title>', 'foo', |
| 235 (element) => element is TitleElement)); |
| 236 // TODO(jacobr): audio tags cause tests to segfault when using dartium. |
| 237 // b/5522106. |
| 238 // test('track', () => testConstructorHelper('track', '<track>', '', |
| 239 // (element) => element is TrackElement)); |
| 240 test('ul', () => testConstructorHelper('ul', '<ul>foo</ul>', 'foo', |
| 241 (element) => element is UListElement)); |
| 242 // TODO(jacobr): video tags cause tests to segfault when using dartium. |
| 243 // b/5522106. |
| 244 // test('video', () => testConstructorHelper('video', |
| 245 // '<video>foo</video>', 'foo', |
| 246 // (element) => element is VideoElement)); |
| 247 // TODO(jacobr): this test is broken until Dartium fixes b/5521083 |
| 248 // test('someunknown', () => testConstructorHelper('someunknown', |
| 249 // '<someunknown>foo</someunknown>', 'foo', |
| 250 // (element) => element is UnknownElement)); |
| 251 }); |
| 252 |
| 253 test('eventListeners', () { |
| 254 final element = new Element.tag('div'); |
| 255 final on = element.on; |
| 256 final rawElement = unwrapDomObject(element); |
| 257 |
| 258 testEventHelper(on.abort, 'abort', |
| 259 (listener) => rawElement.onabort = listener); |
| 260 testEventHelper(on.beforeCopy, 'beforecopy', |
| 261 (listener) => rawElement.onbeforecopy = listener); |
| 262 testEventHelper(on.beforeCut, 'beforecut', |
| 263 (listener) => rawElement.onbeforecut = listener); |
| 264 testEventHelper(on.beforePaste, 'beforepaste', |
| 265 (listener) => rawElement.onbeforepaste = listener); |
| 266 testEventHelper(on.blur, 'blur', |
| 267 (listener) => rawElement.onblur = listener); |
| 268 testEventHelper(on.change, 'change', |
| 269 (listener) => rawElement.onchange = listener); |
| 270 testEventHelper(on.click, 'click', |
| 271 (listener) => rawElement.onclick = listener); |
| 272 testEventHelper(on.contextMenu, 'contextmenu', |
| 273 (listener) => rawElement.oncontextmenu = listener); |
| 274 testEventHelper(on.copy, 'copy', |
| 275 (listener) => rawElement.oncopy = listener); |
| 276 testEventHelper(on.cut, 'cut', |
| 277 (listener) => rawElement.oncut = listener); |
| 278 testEventHelper(on.dblClick, 'dblclick', |
| 279 (listener) => rawElement.ondblclick = listener); |
| 280 testEventHelper(on.drag, 'drag', |
| 281 (listener) => rawElement.ondrag = listener); |
| 282 testEventHelper(on.dragEnd, 'dragend', |
| 283 (listener) => rawElement.ondragend = listener); |
| 284 testEventHelper(on.dragEnter, 'dragenter', |
| 285 (listener) => rawElement.ondragenter = listener); |
| 286 testEventHelper(on.dragLeave, 'dragleave', |
| 287 (listener) => rawElement.ondragleave = listener); |
| 288 testEventHelper(on.dragOver, 'dragover', |
| 289 (listener) => rawElement.ondragover = listener); |
| 290 testEventHelper(on.dragStart, 'dragstart', |
| 291 (listener) => rawElement.ondragstart = listener); |
| 292 testEventHelper(on.drop, 'drop', |
| 293 (listener) => rawElement.ondrop = listener); |
| 294 testEventHelper(on.error, 'error', |
| 295 (listener) => rawElement.onerror = listener); |
| 296 testEventHelper(on.focus, 'focus', |
| 297 (listener) => rawElement.onfocus = listener); |
| 298 testEventHelper(on.input, 'input', |
| 299 (listener) => rawElement.oninput = listener); |
| 300 testEventHelper(on.invalid, 'invalid', |
| 301 (listener) => rawElement.oninvalid = listener); |
| 302 testEventHelper(on.keyDown, 'keydown', |
| 303 (listener) => rawElement.onkeydown = listener); |
| 304 testEventHelper(on.keyPress, 'keypress', |
| 305 (listener) => rawElement.onkeypress = listener); |
| 306 testEventHelper(on.keyUp, 'keyup', |
| 307 (listener) => rawElement.onkeyup = listener); |
| 308 testEventHelper(on.load, 'load', |
| 309 (listener) => rawElement.onload = listener); |
| 310 testEventHelper(on.mouseDown, 'mousedown', |
| 311 (listener) => rawElement.onmousedown = listener); |
| 312 testEventHelper(on.mouseMove, 'mousemove', |
| 313 (listener) => rawElement.onmousemove = listener); |
| 314 testEventHelper(on.mouseOut, 'mouseout', |
| 315 (listener) => rawElement.onmouseout = listener); |
| 316 testEventHelper(on.mouseOver, 'mouseover', |
| 317 (listener) => rawElement.onmouseover = listener); |
| 318 testEventHelper(on.mouseUp, 'mouseup', |
| 319 (listener) => rawElement.onmouseup = listener); |
| 320 testEventHelper(on.mouseWheel, 'mousewheel', |
| 321 (listener) => rawElement.onmousewheel = listener); |
| 322 testEventHelper(on.paste, 'paste', |
| 323 (listener) => rawElement.onpaste = listener); |
| 324 testEventHelper(on.reset, 'reset', |
| 325 (listener) => rawElement.onreset = listener); |
| 326 testEventHelper(on.scroll, 'scroll', |
| 327 (listener) => rawElement.onscroll = listener); |
| 328 testEventHelper(on.search, 'search', |
| 329 (listener) => rawElement.onsearch = listener); |
| 330 testEventHelper(on.select, 'select', |
| 331 (listener) => rawElement.onselect = listener); |
| 332 testEventHelper(on.selectStart, 'selectstart', |
| 333 (listener) => rawElement.onselectstart = listener); |
| 334 testEventHelper(on.submit, 'submit', |
| 335 (listener) => rawElement.onsubmit = listener); |
| 336 testEventHelper(on.touchCancel, 'touchcancel', |
| 337 (listener) => rawElement.ontouchcancel = listener); |
| 338 testEventHelper(on.touchEnd, 'touchend', |
| 339 (listener) => rawElement.ontouchend = listener); |
| 340 testEventHelper(on.touchLeave, 'touchleave'); |
| 341 testEventHelper(on.touchMove, 'touchmove', |
| 342 (listener) => rawElement.ontouchmove = listener); |
| 343 testEventHelper(on.touchStart, 'touchstart', |
| 344 (listener) => rawElement.ontouchstart = listener); |
| 345 testEventHelper(on.transitionEnd, 'webkitTransitionEnd'); |
| 346 testEventHelper(on.fullscreenChange, 'webkitfullscreenchange', |
| 347 (listener) => rawElement.onwebkitfullscreenchange = listener); |
| 348 }); |
| 349 |
| 350 test('attributes', () { |
| 351 final element = new Element.html( |
| 352 '''<div class="foo" style="overflow: hidden" data-foo="bar" |
| 353 data-foo2="bar2" dir="rtl"> |
| 354 </div>'''); |
| 355 final attributes = element.attributes; |
| 356 Expect.equals(attributes['class'], 'foo'); |
| 357 Expect.equals(attributes['style'], 'overflow: hidden'); |
| 358 Expect.equals(attributes['data-foo'], 'bar'); |
| 359 Expect.equals(attributes['data-foo2'], 'bar2'); |
| 360 Expect.equals(attributes.length, 5); |
| 361 Expect.equals(element.dataAttributes.length, 2); |
| 362 element.dataAttributes['foo'] = 'baz'; |
| 363 Expect.equals(element.dataAttributes['foo'], 'baz'); |
| 364 Expect.equals(attributes['data-foo'], 'baz'); |
| 365 attributes['data-foo2'] = 'baz2'; |
| 366 Expect.equals(attributes['data-foo2'], 'baz2'); |
| 367 Expect.equals(element.dataAttributes['foo2'], 'baz2'); |
| 368 Expect.equals(attributes['dir'], 'rtl'); |
| 369 |
| 370 // TODO(jacobr): determine why these tests are causing segfaults in dartium |
| 371 // element.dataAttributes.remove('foo2'); |
| 372 // Expect.equals(attributes.length, 4); |
| 373 // Expect.equals(dataAttributes.length, 1); |
| 374 // attributes.remove('style'); |
| 375 // Expect.equals(attributes.length, 3); |
| 376 // element.dataAttributes['foo3'] = 'baz3'; |
| 377 // Expect.equals(dataAttributes.length, 2); |
| 378 // Expect.equals(attributes.length, 4); |
| 379 // attributes['style'] = 'width: 300px;'; |
| 380 // Expect.equals(attributes.length, 5);*/ |
| 381 }); |
| 382 } |
| OLD | NEW |