Index: runtime/observatory/tests/observatory_ui/vm_connect_target_test.dart |
diff --git a/runtime/observatory/tests/observatory_ui/vm_connect_target_test.dart b/runtime/observatory/tests/observatory_ui/vm_connect_target_test.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6c7317b8cdd3264e7fb821b9161a3ae4ea776a0f |
--- /dev/null |
+++ b/runtime/observatory/tests/observatory_ui/vm_connect_target_test.dart |
@@ -0,0 +1,98 @@ |
+// Copyright (c) 2015, 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. |
+import 'dart:html'; |
+import 'dart:async'; |
+import 'package:unittest/unittest.dart'; |
+import 'package:observatory/service_html.dart'; |
+import 'package:observatory/src/elements/vm_connect_target.dart'; |
+ |
+import 'helpers/webcomponents.dart'; |
+ |
+main() async { |
+ await loadWebComponents(); |
+ VmConnectTargetElement.tag.ensureRegistration(); |
+ |
+ WebSocketVMTarget t; |
+ setUp(() { |
+ t = new WebSocketVMTarget("a network address"); |
+ }); |
+ group('instantiation', () { |
+ group('target: valid', () { |
+ test('no other parameters', () { |
+ final VmConnectTargetElement e = new VmConnectTargetElement(t); |
+ expect(e, isNotNull, reason: 'element correctly created'); |
+ expect(e.target, t, reason: 'target not setted'); |
+ expect(e.current, isFalse, reason: 'default to not current'); |
+ }); |
+ test('isCurrent: false', () { |
+ final VmConnectTargetElement e = new VmConnectTargetElement(t, |
+ current:false); |
+ expect(e, isNotNull, reason: 'element correctly created'); |
+ expect(e.target, t, reason: 'target not setted'); |
+ expect(e.current, isFalse, reason: 'default to not current'); |
+ }); |
+ test('isCurrent: true', () { |
+ final VmConnectTargetElement e = new VmConnectTargetElement(t, |
+ current:true); |
+ expect(e, isNotNull, reason: 'element correctly created'); |
+ expect(e.target, t, reason: 'target not setted'); |
+ expect(e.current, isTrue, reason: 'default to not current'); |
+ }); |
+ }); |
+ }); |
+ test('elements created after attachment', () { |
+ final VmConnectTargetElement e = new VmConnectTargetElement(t); |
+ expect(e.children.length, isZero, |
+ reason: 'is empty'); |
+ document.body.append(e); |
+ expect(e.children.length, isNonZero, |
+ reason: 'has elements'); |
+ e.remove(); |
+ }); |
+ group('events are fired', () { |
+ VmConnectTargetElement e; |
+ StreamSubscription sub; |
+ setUp(() { |
+ e = new VmConnectTargetElement(t); |
+ document.body.append(e); |
+ }); |
+ tearDown(() { |
+ sub.cancel(); |
+ e.remove(); |
+ }); |
+ test('onConnect events (DOM)', () async { |
+ sub = e.onConnect.listen(expectAsync((WebSocketVMTargetEvent event) { |
+ expect(event, isNotNull, reason: 'event is passed'); |
+ expect(event.target, t, reason: 'target is the same'); |
+ }, count: 1, reason: 'event is fired')); |
+ e.querySelector('a').click(); |
+ }); |
+ test('onConnect events (code)', () async { |
+ sub = e.onConnect.listen(expectAsync((WebSocketVMTargetEvent event) { |
+ expect(event, isNotNull, reason: 'event is passed'); |
+ expect(event.target, t, reason: 'target is the same'); |
+ }, count: 1, reason: 'event is fired')); |
+ e.connect(); |
+ }); |
+ test('onRemove events (DOM)', () async { |
+ sub = e.onDelete.listen(expectAsync((WebSocketVMTargetEvent event) { |
+ expect(event, isNotNull, reason: 'event is passed'); |
+ expect(event.target, t, reason: 'target is the same'); |
+ }, count: 1, reason: 'event is fired')); |
+ e.querySelector('button').click(); |
+ }); |
+ test('onRemove events (code)', () async { |
+ sub = e.onDelete.listen(expectAsync((WebSocketVMTargetEvent event) { |
+ expect(event, isNotNull, reason: 'event is passed'); |
+ expect(event.target, t, reason: 'target is the same'); |
+ }, count: 1, reason: 'event is fired')); |
+ e.delete(); |
+ }); |
+ test('navigation after connect', () async { |
+ sub = window.onPopState.listen(expectAsync((_) {}, count: 1, |
+ reason: 'event is fired')); |
+ e.querySelector('a').click(); |
+ }); |
+ }); |
+} |