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

Side by Side Diff: test/codegen/lib/html/mutationobserver_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 // 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 library mutationobserver_test;
6 import 'package:unittest/unittest.dart';
7 import 'package:unittest/html_individual_config.dart';
8 import 'dart:html';
9
10 // Due to https://code.google.com/p/chromium/issues/detail?id=329103
11 // mutationObservers sometimes do not fire if the node being observed is GCed
12 // so we keep around references to all nodes we have created mutation
13 // observers for.
14 var keepAlive = [];
15
16 /**
17 * Test suite for Mutation Observers. This is just a small set of sanity
18 * checks, not a complete test suite.
19 */
20 main() {
21 useHtmlIndividualConfiguration();
22
23 group('supported', () {
24 test('supported', () {
25 expect(MutationObserver.supported, true);
26 });
27 });
28
29 var expectation = MutationObserver.supported ? returnsNormally : throws;
30
31 group('childList', () {
32 mutationCallback(count, expectation) {
33 var done = false;
34 var nodes = [];
35
36 callback(mutations, observer) {
37 for (MutationRecord mutation in mutations) {
38 for (Node node in mutation.addedNodes) {
39 nodes.add(node);
40 }
41 }
42 if (nodes.length >= count) {
43 done = true;
44 expect(nodes.length, count);
45 expect(nodes, expectation);
46 }
47 }
48
49 // If it's not supported, don't block waiting for it.
50 if (!MutationObserver.supported) {
51 return () => done;
52 }
53
54 return expectAsyncUntil(callback, () => done);
55 }
56
57 test('empty options is syntax error', () {
58 expect(() {
59 var mutationObserver = new MutationObserver(
60 (mutations, observer) { expect(false, isTrue,
61 reason: 'Should not be reached'); });
62 expect(() { mutationObserver.observe(document, {}); },
63 throws);
64 }, expectation);
65 });
66
67 test('direct-parallel options-named', () {
68 expect(() {
69 var container = new DivElement();
70 keepAlive.add(container);
71 var div1 = new DivElement();
72 var div2 = new DivElement();
73 var mutationObserver = new MutationObserver(
74 mutationCallback(2, orderedEquals([div1, div2])));
75 mutationObserver.observe(container, childList: true);
76
77 container.append(div1);
78 container.append(div2);
79 }, expectation);
80 });
81
82 test('direct-nested options-named', () {
83 expect(() {
84 var container = new DivElement();
85 keepAlive.add(container);
86 var div1 = new DivElement();
87 var div2 = new DivElement();
88 var mutationObserver =
89 new MutationObserver(mutationCallback(1, orderedEquals([div1])));
90 mutationObserver.observe(container, childList: true);
91
92 container.append(div1);
93 div1.append(div2);
94 }, expectation);
95 });
96
97 test('subtree options-named', () {
98 expect(() {
99 var container = new DivElement();
100 keepAlive.add(container);
101 var div1 = new DivElement();
102 var div2 = new DivElement();
103 var mutationObserver = new MutationObserver(
104 mutationCallback(2, orderedEquals([div1, div2])));
105 mutationObserver.observe(container, childList: true, subtree: true);
106
107 container.append(div1);
108 div1.append(div2);
109 }, expectation);
110 });
111 });
112 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698