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

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

Issue 23055008: Making almost all dom_ methods private. Exceptions will be addressed in a later CL. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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
« no previous file with comments | « tests/html/element_test.dart ('k') | tools/dom/dom.json » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 NodeTest; 5 library NodeTest;
6 import '../../pkg/unittest/lib/unittest.dart'; 6 import '../../pkg/unittest/lib/unittest.dart';
7 import '../../pkg/unittest/lib/html_individual_config.dart'; 7 import '../../pkg/unittest/lib/html_individual_config.dart';
8 import 'dart:html'; 8 import 'dart:html';
9 import 'dart:svg' as svg; 9 import 'dart:svg' as svg;
10 10
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 328
329 testUnsupported('fillRange', () { 329 testUnsupported('fillRange', () {
330 makeNodeWithChildren().nodes.fillRange(0, 1, null); 330 makeNodeWithChildren().nodes.fillRange(0, 1, null);
331 }); 331 });
332 332
333 testUnsupported('setAll', () { 333 testUnsupported('setAll', () {
334 makeNodeWithChildren().nodes.setAll(0, [new InputElement()]); 334 makeNodeWithChildren().nodes.setAll(0, [new InputElement()]);
335 }); 335 });
336 }); 336 });
337 337
338 group('NodeList', () {
339 // Tests for methods on the DOM class 'NodeList'.
340 //
341 // There are two interesting things that are checked here from the viewpoint
342 // of the dart2js implementation of a 'native' class:
343 //
344 // 1. Some methods are implementated from by 'Object' or 'Interceptor';
345 // some of these tests simply check that a method can be called.
346 // 2. Some methods are implemented by mixins.
347
348 List<Node> makeNodeList() =>
349 (new Element.html("<div>Foo<br/><!--baz--><br/><br/></div>"))
350 .$dom_getElementsByTagName('br');
351 // Our WebKit-derived bindings declare getElementsByTagName as returning
352 // NodeList.
353 //
354 // WebKit browsers returns NodeList.
355 // Firefox and IE return HtmlCollection.
356 // This is messed-up since the two types are disjoint. We could make
357 // HtmlCollection extend NodeList but we would require better optimizations
358 // to recognize when NodeList_methods can be used.
359
360 test('trueNodeList', () {
361 var nodes = makeNodeList();
362 expect(nodes is NodeList || nodes is HtmlCollection, true);
363 });
364
365 test('hashCode', () {
366 var nodes = makeNodeList();
367 var hash = nodes.hashCode;
368 final int N = 1000;
369 int matchCount = 0;
370 for (int i = 0; i < N; i++) {
371 if (makeNodeList().hashCode == hash) matchCount++;
372 }
373 expect(matchCount, lessThan(N));
374 });
375
376 test('operator==', () {
377 var a = [makeNodeList(), makeNodeList(), null];
378 for (int i = 0; i < a.length; i++) {
379 for (int j = 0; j < a.length; j++) {
380 expect(i == j, a[i] == a[j]);
381 }
382 }
383 });
384
385 test('runtimeType', () {
386 var nodes1 = makeNodeList();
387 var nodes2 = makeNodeList();
388 var type1 = nodes1.runtimeType;
389 var type2 = nodes2.runtimeType;
390 expect(type1 == type2, true);
391 String name = '$type1';
392 if (name.length > 3) {
393 expect(name.contains('NodeList') || name.contains('HtmlCollection'),
394 true);
395 }
396 });
397
398 test('first', () {
399 var nodes = makeNodeList();
400 expect(nodes.first, isBRElement);
401 });
402
403 test('last', () {
404 var nodes = makeNodeList();
405 expect(nodes.last, isBRElement);
406 });
407
408 test('where', () {
409 var filtered = makeNodeList().where((n) => n is BRElement).toList();
410 expect(filtered.length, 3);
411 expect(filtered[0], isBRElement);
412 expect(filtered, isNodeList);
413 });
414
415 test('sublist', () {
416 var range = makeNodeList().sublist(1, 3);
417 expect(range.length, 2);
418 expect(range[0], isBRElement);
419 expect(range[1], isBRElement);
420 });
421
422 });
423
424 group('iterating', () { 338 group('iterating', () {
425 test('NodeIterator', () { 339 test('NodeIterator', () {
426 var root = makeNodeWithChildren(); 340 var root = makeNodeWithChildren();
427 var nodeIterator = new NodeIterator(root, NodeFilter.SHOW_COMMENT); 341 var nodeIterator = new NodeIterator(root, NodeFilter.SHOW_COMMENT);
428 expect(nodeIterator.nextNode(), isComment); 342 expect(nodeIterator.nextNode(), isComment);
429 expect(nodeIterator.nextNode(), isNull); 343 expect(nodeIterator.nextNode(), isNull);
430 }); 344 });
431 345
432 test('TreeWalker', () { 346 test('TreeWalker', () {
433 var root = makeNodeWithChildren(); 347 var root = makeNodeWithChildren();
434 var treeWalker = new TreeWalker(root, NodeFilter.SHOW_COMMENT); 348 var treeWalker = new TreeWalker(root, NodeFilter.SHOW_COMMENT);
435 expect(treeWalker.nextNode(), isComment); 349 expect(treeWalker.nextNode(), isComment);
436 expect(treeWalker.nextNode(), isNull); 350 expect(treeWalker.nextNode(), isNull);
437 }); 351 });
438 }); 352 });
439 } 353 }
OLDNEW
« no previous file with comments | « tests/html/element_test.dart ('k') | tools/dom/dom.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698