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

Unified 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: ptal Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/codegen/lib/html/mouse_event_test.dart ('k') | test/codegen/lib/html/native_gc_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/codegen/lib/html/mutationobserver_test.dart
diff --git a/test/codegen/lib/html/mutationobserver_test.dart b/test/codegen/lib/html/mutationobserver_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..e2de7e0afacb78b6be179d18a7b300c7b027d12f
--- /dev/null
+++ b/test/codegen/lib/html/mutationobserver_test.dart
@@ -0,0 +1,112 @@
+// Copyright (c) 2011, 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 mutationobserver_test;
+import 'package:unittest/unittest.dart';
+import 'package:unittest/html_individual_config.dart';
+import 'dart:html';
+
+// Due to https://code.google.com/p/chromium/issues/detail?id=329103
+// mutationObservers sometimes do not fire if the node being observed is GCed
+// so we keep around references to all nodes we have created mutation
+// observers for.
+var keepAlive = [];
+
+/**
+ * Test suite for Mutation Observers. This is just a small set of sanity
+ * checks, not a complete test suite.
+ */
+main() {
+ useHtmlIndividualConfiguration();
+
+ group('supported', () {
+ test('supported', () {
+ expect(MutationObserver.supported, true);
+ });
+ });
+
+ var expectation = MutationObserver.supported ? returnsNormally : throws;
+
+ 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);
+ }
+ }
+
+ // If it's not supported, don't block waiting for it.
+ if (!MutationObserver.supported) {
+ return () => done;
+ }
+
+ return expectAsyncUntil(callback, () => done);
+ }
+
+ test('empty options is syntax error', () {
+ expect(() {
+ var mutationObserver = new MutationObserver(
+ (mutations, observer) { expect(false, isTrue,
+ reason: 'Should not be reached'); });
+ expect(() { mutationObserver.observe(document, {}); },
+ throws);
+ }, expectation);
+ });
+
+ test('direct-parallel options-named', () {
+ expect(() {
+ var container = new DivElement();
+ keepAlive.add(container);
+ 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);
+ }, expectation);
+ });
+
+ test('direct-nested options-named', () {
+ expect(() {
+ var container = new DivElement();
+ keepAlive.add(container);
+ 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);
+ }, expectation);
+ });
+
+ test('subtree options-named', () {
+ expect(() {
+ var container = new DivElement();
+ keepAlive.add(container);
+ 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);
+ }, expectation);
+ });
+ });
+}
« no previous file with comments | « test/codegen/lib/html/mouse_event_test.dart ('k') | test/codegen/lib/html/native_gc_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698