| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2015, 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 import 'dart:html'; |
| 5 import 'dart:async'; |
| 6 import 'package:unittest/unittest.dart'; |
| 7 import 'package:observatory/service_html.dart'; |
| 8 import 'package:observatory/src/elements/vm_connect_target.dart'; |
| 9 |
| 10 main() { |
| 11 WebSocketVMTarget t; |
| 12 setUp(() { |
| 13 VmConnectTargetElement.tag.ensureRegistration(); |
| 14 t = new WebSocketVMTarget("a network address"); |
| 15 }); |
| 16 group('instantiation', () { |
| 17 group('target: valid', () { |
| 18 test('no other parameters', () { |
| 19 final VmConnectTargetElement e = new VmConnectTargetElement(t); |
| 20 expect(e, isNotNull, reason: 'element correctly created'); |
| 21 expect(e.target, t, reason: 'target not setted'); |
| 22 expect(e.current, isFalse, reason: 'default to not current'); |
| 23 }); |
| 24 test('isCurrent: false', () { |
| 25 final VmConnectTargetElement e = new VmConnectTargetElement(t, |
| 26 current:false); |
| 27 expect(e, isNotNull, reason: 'element correctly created'); |
| 28 expect(e.target, t, reason: 'target not setted'); |
| 29 expect(e.current, isFalse, reason: 'default to not current'); |
| 30 }); |
| 31 test('isCurrent: true', () { |
| 32 final VmConnectTargetElement e = new VmConnectTargetElement(t, |
| 33 current:true); |
| 34 expect(e, isNotNull, reason: 'element correctly created'); |
| 35 expect(e.target, t, reason: 'target not setted'); |
| 36 expect(e.current, isTrue, reason: 'default to not current'); |
| 37 }); |
| 38 }); |
| 39 }); |
| 40 test('elements created after attachment', () { |
| 41 final VmConnectTargetElement e = new VmConnectTargetElement(t); |
| 42 expect(e.shadowRoot, isNotNull, reason: 'shadowRoot is created'); |
| 43 expect(e.shadowRoot.children.length, isZero, |
| 44 reason: 'shadowRoot is empty'); |
| 45 document.body.append(e); |
| 46 expect(e.shadowRoot.children.length, isNonZero, |
| 47 reason: 'shadowRoot has elements'); |
| 48 e.remove(); |
| 49 }); |
| 50 group('events are fired', () { |
| 51 VmConnectTargetElement e; |
| 52 StreamSubscription sub; |
| 53 setUp(() { |
| 54 e = new VmConnectTargetElement(t); |
| 55 document.body.append(e); |
| 56 }); |
| 57 tearDown(() { |
| 58 sub.cancel(); |
| 59 e.remove(); |
| 60 }); |
| 61 test('onConnect events (DOM)', () async { |
| 62 sub = e.onConnect.listen(expectAsync((WebSocketVMTargetEvent event) { |
| 63 expect(event, isNotNull, reason: 'event is passed'); |
| 64 expect(event.target, t, reason: 'target is the same'); |
| 65 }, count: 1, reason: 'event is fired')); |
| 66 e.shadowRoot.querySelector('a').click(); |
| 67 }); |
| 68 test('onConnect events (code)', () async { |
| 69 sub = e.onConnect.listen(expectAsync((WebSocketVMTargetEvent event) { |
| 70 expect(event, isNotNull, reason: 'event is passed'); |
| 71 expect(event.target, t, reason: 'target is the same'); |
| 72 }, count: 1, reason: 'event is fired')); |
| 73 e.connect(); |
| 74 }); |
| 75 test('onRemove events (DOM)', () async { |
| 76 sub = e.onDelete.listen(expectAsync((WebSocketVMTargetEvent event) { |
| 77 expect(event, isNotNull, reason: 'event is passed'); |
| 78 expect(event.target, t, reason: 'target is the same'); |
| 79 }, count: 1, reason: 'event is fired')); |
| 80 e.shadowRoot.querySelector('button').click(); |
| 81 }); |
| 82 test('onRemove events (code)', () async { |
| 83 sub = e.onDelete.listen(expectAsync((WebSocketVMTargetEvent event) { |
| 84 expect(event, isNotNull, reason: 'event is passed'); |
| 85 expect(event.target, t, reason: 'target is the same'); |
| 86 }, count: 1, reason: 'event is fired')); |
| 87 e.delete(); |
| 88 }); |
| 89 test('navigation after connect', () async { |
| 90 sub = window.onPopState.listen(expectAsync((_) {}, count: 1, |
| 91 reason: 'event is fired')); |
| 92 e.shadowRoot.querySelector('a').click(); |
| 93 }); |
| 94 }); |
| 95 } |
| OLD | NEW |