Chromium Code Reviews| Index: pkg/mutation_observer/test/mutation_observer_test.dart |
| diff --git a/pkg/mutation_observer/test/mutation_observer_test.dart b/pkg/mutation_observer/test/mutation_observer_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7c633efc7893446272cf4cc127887babee7fb703 |
| --- /dev/null |
| +++ b/pkg/mutation_observer/test/mutation_observer_test.dart |
| @@ -0,0 +1,115 @@ |
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +library mutation_observer_test; |
| + |
| +import 'dart:html'; |
| +import 'package:unittest/unittest.dart'; |
| +import 'package:unittest/html_individual_config.dart'; |
| + |
| +main() { |
| + useHtmlIndividualConfiguration(); |
| + |
| + // Load the MutationObserver polyfill. |
| + HttpRequest.getString('/root_dart/pkg/mutation_observer/lib/' |
| + 'mutation_observer.js').then((code) { |
| + |
| + // Force MutationObserver polyfill to be used so we can test it, even in |
| + // browsers with native support. |
| + document.head.children.add(new ScriptElement() |
| + ..text = 'window.MutationObserver = void 0;' |
|
Jennifer Messerly
2013/07/30 18:05:20
This test is no longer run on CSP because it force
|
| + 'window.WebKitMutationObserver = void 0;' |
| + '$code'); |
| + |
| + testMutationObserver(); |
| + }); |
| +} |
| + |
| +/** |
| + * Test suite for Mutation Observers. This is just a small set of sanity |
| + * checks, not a complete test suite. |
| + */ |
| +testMutationObserver() { |
|
Jennifer Messerly
2013/07/30 03:27:24
most of this test taken from dart:html version
|
| + group('supported', () { |
| + test('supported', () { |
| + expect(MutationObserver.supported, true, reason: 'polyfill loaded.'); |
| + }); |
| + }); |
| + |
| + group('childList', () { |
| + mutationCallback(count, expectation) { |
| + var done = false; |
| + var nodes = []; |
| + |
| + callback(mutations, observer) { |
| + for (MutationRecord mutation in mutations) { |
| + for (Node node in mutation.addedNodes) { |
| + nodes.add(node); |
| + } |
| + } |
| + if (nodes.length >= count) { |
| + done = true; |
| + expect(nodes.length, count); |
| + expect(nodes, expectation); |
| + } |
| + } |
| + |
| + return expectAsyncUntil2(callback, () => done); |
| + } |
| + |
| + test('empty options is syntax error', () { |
| + var mutationObserver = new MutationObserver( |
| + (mutations, observer) { expect(false, isTrue, |
| + reason: 'Should not be reached'); }); |
| + expect(() { mutationObserver.observe(document, {}); }, |
| + throws); |
| + }); |
| + |
| + test('direct-parallel options-named', () { |
| + var container = new DivElement(); |
| + var div1 = new DivElement(); |
| + var div2 = new DivElement(); |
| + var mutationObserver = new MutationObserver( |
| + mutationCallback(2, orderedEquals([div1, div2]))); |
| + mutationObserver.observe(container, childList: true); |
| + |
| + container.append(div1); |
| + container.append(div2); |
| + }); |
| + |
| + test('direct-nested options-named', () { |
| + var container = new DivElement(); |
| + var div1 = new DivElement(); |
| + var div2 = new DivElement(); |
| + var mutationObserver = |
| + new MutationObserver(mutationCallback(1, orderedEquals([div1]))); |
| + mutationObserver.observe(container, childList: true); |
| + |
| + container.append(div1); |
| + div1.append(div2); |
| + }); |
| + |
| + test('subtree options-named', () { |
| + var container = new DivElement(); |
| + var div1 = new DivElement(); |
| + var div2 = new DivElement(); |
| + var mutationObserver = new MutationObserver( |
| + mutationCallback(2, orderedEquals([div1, div2]))); |
| + mutationObserver.observe(container, childList: true, subtree: true); |
| + |
| + container.append(div1); |
| + div1.append(div2); |
| + }); |
| + |
| + test('mutation event', () { |
| + // 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
|
| + var event = new MutationEvent('something', prevValue: 'prev', |
| + newValue: 'new', attrName: 'attr'); |
| + expect(event is MutationEvent, isTrue); |
| + expect(event.prevValue, 'prev'); |
| + expect(event.newValue, 'new'); |
| + expect(event.attrName, 'attr'); |
| + }); |
| + }); |
| +} |