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

Unified Diff: test/codegen/lib/html/event_customevent_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/element_types_test.dart ('k') | test/codegen/lib/html/event_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/codegen/lib/html/event_customevent_test.dart
diff --git a/test/codegen/lib/html/event_customevent_test.dart b/test/codegen/lib/html/event_customevent_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..cbda1a78774b416d7a8077e4240853307d7d704f
--- /dev/null
+++ b/test/codegen/lib/html/event_customevent_test.dart
@@ -0,0 +1,86 @@
+// Copyright (c) 2012, 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 EventCustomEventTest;
+
+import 'package:unittest/unittest.dart';
+import 'package:unittest/html_config.dart';
+import 'dart:html';
+import 'dart:js' as js;
+
+class DartPayloadData {
+ final dartValue;
+
+ DartPayloadData(this.dartValue);
+}
+
+main() {
+ useHtmlConfiguration();
+
+ test('custom events', () {
+ var provider = new EventStreamProvider<CustomEvent>('foo');
+ var el = new DivElement();
+
+ var fired = false;
+ provider.forTarget(el).listen((ev) {
+ fired = true;
+ expect(ev.detail, {'type': 'detail'});
+ });
+
+ var ev = new CustomEvent('foo', canBubble: false, cancelable: false,
+ detail: {'type': 'detail'});
+ el.dispatchEvent(ev);
+ expect(fired, isTrue);
+ });
+
+ test('custom events from JS', () {
+ var scriptContents = '''
+ var event = document.createEvent("CustomEvent");
+ event.initCustomEvent("js_custom_event", true, true, {type: "detail"});
+ window.dispatchEvent(event);
+ ''';
+
+ var fired = false;
+ window.on['js_custom_event'].listen((ev) {
+ fired = true;
+ expect(ev.detail, {'type': 'detail'});
+ });
+
+ var script = new ScriptElement();
+ script.text = scriptContents;
+ document.body.append(script);
+
+ expect(fired, isTrue);
+ });
+
+ test('custom events to JS', () {
+ expect(js.context['gotDartEvent'], isNull);
+ var scriptContents = '''
+ window.addEventListener('dart_custom_event', function(e) {
+ if (e.detail == 'dart_message') {
+ e.preventDefault();
+ window.gotDartEvent = true;
+ }
+ window.console.log('here' + e.detail);
+ }, false);''';
+
+ document.body.append(new ScriptElement()..text = scriptContents);
+
+ var event = new CustomEvent('dart_custom_event', detail: 'dart_message');
+ window.dispatchEvent(event);
+ expect(js.context['gotDartEvent'], isTrue);
+ });
+
+ test('custom data to Dart', () {
+ var data = new DartPayloadData(666);
+ var event = new CustomEvent('dart_custom_data_event', detail: data);
+
+ var future = window.on['dart_custom_data_event'].first.then((_) {
+ expect(event.detail.dartValue, 666);
+ });
+
+ document.body.dispatchEvent(event);
+ return future;
+ });
+}
« no previous file with comments | « test/codegen/lib/html/element_types_test.dart ('k') | test/codegen/lib/html/event_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698