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

Side by Side Diff: pkg/mutation_observer/test/mutation_observer_test.dart

Issue 21109007: add mutation observer polyfill package (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix for constructor property 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
OLDNEW
(Empty)
1 // Copyright (c) 2013, 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 mutation_observer_test;
6
7 import 'dart:html';
8 import 'package:unittest/unittest.dart';
9 import 'package:unittest/html_individual_config.dart';
10
11 main() {
12 useHtmlIndividualConfiguration();
13
14 // Load the MutationObserver polyfill.
15 HttpRequest.getString('/root_dart/pkg/mutation_observer/lib/'
16 'mutation_observer.js').then((code) {
17
18 // Force MutationObserver polyfill to be used so we can test it, even in
19 // browsers with native support.
20 document.head.children.add(new ScriptElement()
21 ..text = 'window.MutationObserver = void 0;'
Jennifer Messerly 2013/07/30 18:05:20 This test is no longer run on CSP because it force
22 'window.WebKitMutationObserver = void 0;'
23 '$code');
24
25 testMutationObserver();
26 });
27 }
28
29 /**
30 * Test suite for Mutation Observers. This is just a small set of sanity
31 * checks, not a complete test suite.
32 */
33 testMutationObserver() {
Jennifer Messerly 2013/07/30 03:27:24 most of this test taken from dart:html version
34 group('supported', () {
35 test('supported', () {
36 expect(MutationObserver.supported, true, reason: 'polyfill loaded.');
37 });
38 });
39
40 group('childList', () {
41 mutationCallback(count, expectation) {
42 var done = false;
43 var nodes = [];
44
45 callback(mutations, observer) {
46 for (MutationRecord mutation in mutations) {
47 for (Node node in mutation.addedNodes) {
48 nodes.add(node);
49 }
50 }
51 if (nodes.length >= count) {
52 done = true;
53 expect(nodes.length, count);
54 expect(nodes, expectation);
55 }
56 }
57
58 return expectAsyncUntil2(callback, () => done);
59 }
60
61 test('empty options is syntax error', () {
62 var mutationObserver = new MutationObserver(
63 (mutations, observer) { expect(false, isTrue,
64 reason: 'Should not be reached'); });
65 expect(() { mutationObserver.observe(document, {}); },
66 throws);
67 });
68
69 test('direct-parallel options-named', () {
70 var container = new DivElement();
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 });
80
81 test('direct-nested options-named', () {
82 var container = new DivElement();
83 var div1 = new DivElement();
84 var div2 = new DivElement();
85 var mutationObserver =
86 new MutationObserver(mutationCallback(1, orderedEquals([div1])));
87 mutationObserver.observe(container, childList: true);
88
89 container.append(div1);
90 div1.append(div2);
91 });
92
93 test('subtree options-named', () {
94 var container = new DivElement();
95 var div1 = new DivElement();
96 var div2 = new DivElement();
97 var mutationObserver = new MutationObserver(
98 mutationCallback(2, orderedEquals([div1, div2])));
99 mutationObserver.observe(container, childList: true, subtree: true);
100
101 container.append(div1);
102 div1.append(div2);
103 });
104
105 test('mutation event', () {
106 // Bug 8076 that not all optional params are optional in Dartium.
blois 2013/07/30 17:11:09 This bug probably does not affect this test.
Jennifer Messerly 2013/07/30 18:05:20 done, removed comment
107 var event = new MutationEvent('something', prevValue: 'prev',
108 newValue: 'new', attrName: 'attr');
109 expect(event is MutationEvent, isTrue);
110 expect(event.prevValue, 'prev');
111 expect(event.newValue, 'new');
112 expect(event.attrName, 'attr');
113 });
114 });
115 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698