OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:html'; | 6 import 'dart:html'; |
7 | 7 |
8 import 'package:expect/minitest.dart'; | 8 import 'package:expect/minitest.dart'; |
9 | 9 |
10 class Mock { | 10 class Mock { |
11 noSuchMethod(Invocation i) => document; | 11 noSuchMethod(Invocation i) { |
| 12 if (this is Window) return document; |
| 13 if (this is FileList) return new MockFile(); |
| 14 return null; |
| 15 } |
12 } | 16 } |
13 | 17 |
14 @proxy | 18 @proxy |
15 class MockBodyElement extends Mock implements BodyElement { | 19 class MockBodyElement extends Mock implements BodyElement { |
16 Node append(Node e) => e; | 20 Node append(Node e) => e; |
17 } | 21 } |
18 | 22 |
19 class _EventListeners { | 23 class _EventListeners { |
20 Stream<Event> get onBlur => new Stream.fromIterable([]); | 24 Stream<Event> get onBlur => new Stream.fromIterable([]); |
21 } | 25 } |
(...skipping 10 matching lines...) Expand all Loading... |
32 Stream<Event> get onBeforeUnload => new Stream.fromIterable([]); | 36 Stream<Event> get onBeforeUnload => new Stream.fromIterable([]); |
33 | 37 |
34 String name = "MOCK_NAME"; | 38 String name = "MOCK_NAME"; |
35 } | 39 } |
36 | 40 |
37 @proxy | 41 @proxy |
38 class MockLocation extends Mock implements Location { | 42 class MockLocation extends Mock implements Location { |
39 String href = "MOCK_HREF"; | 43 String href = "MOCK_HREF"; |
40 } | 44 } |
41 | 45 |
| 46 @proxy |
| 47 class MockFileList extends Mock implements FileList {} |
| 48 |
| 49 @proxy |
| 50 class MockFile extends Mock implements File {} |
| 51 |
42 main() { | 52 main() { |
43 test('is', () { | 53 test('is', () { |
44 var win = new MockWindow(); | 54 var win = new MockWindow(); |
45 expect(win is Window, isTrue); | 55 expect(win is Window, isTrue); |
46 }); | 56 }); |
47 | 57 |
48 test('getter', () { | 58 test('getter', () { |
49 var win = new MockWindow(); | 59 var win = new MockWindow(); |
50 expect(win.document, equals(document)); | 60 expect(win.document, equals(document)); |
51 }); | 61 }); |
(...skipping 19 matching lines...) Expand all Loading... |
71 HtmlDocument doc = new MockHtmlDocument(); | 81 HtmlDocument doc = new MockHtmlDocument(); |
72 expect(doc.body.append(null), equals(null)); | 82 expect(doc.body.append(null), equals(null)); |
73 }); | 83 }); |
74 | 84 |
75 test('mixin', () { | 85 test('mixin', () { |
76 Window win = new MockWindow(); | 86 Window win = new MockWindow(); |
77 expect(win.onBlur is Stream, isTrue, reason: 'onBlur should be a stream'); | 87 expect(win.onBlur is Stream, isTrue, reason: 'onBlur should be a stream'); |
78 HtmlDocument doc = new MockHtmlDocument(); | 88 HtmlDocument doc = new MockHtmlDocument(); |
79 expect(doc.onBlur is Stream, isTrue, reason: 'onBlur should be a stream'); | 89 expect(doc.onBlur is Stream, isTrue, reason: 'onBlur should be a stream'); |
80 }); | 90 }); |
| 91 |
| 92 test('operator', () { |
| 93 var fileList = new MockFileList(); |
| 94 expect(fileList[1] is File, isTrue); |
| 95 }); |
81 } | 96 } |
OLD | NEW |