| 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:html'; | 6 import 'dart:html'; |
| 6 | 7 |
| 7 import 'package:expect/minitest.dart'; | 8 import 'package:expect/minitest.dart'; |
| 8 | 9 |
| 9 class Mock { | 10 class Mock { |
| 10 noSuchMethod(Invocation i) => document; | 11 noSuchMethod(Invocation i) => document; |
| 11 } | 12 } |
| 12 | 13 |
| 13 @proxy | 14 @proxy |
| 14 class MockWindow extends Mock implements Window {} | 15 class MockBodyElement extends Mock implements BodyElement { |
| 16 Node append(Node e) => e; |
| 17 } |
| 18 |
| 19 @proxy |
| 20 class MockHtmlDocument extends Mock implements HtmlDocument { |
| 21 BodyElement get body => new MockBodyElement(); |
| 22 } |
| 23 |
| 24 @proxy |
| 25 class MockWindow extends Mock implements Window { |
| 26 Stream<Event> get onBeforeUnload => new Stream.fromIterable([]); |
| 27 |
| 28 String name = "MOCK_NAME"; |
| 29 } |
| 30 |
| 31 @proxy |
| 32 class MockLocation extends Mock implements Location { |
| 33 String href = "MOCK_HREF"; |
| 34 } |
| 15 | 35 |
| 16 main() { | 36 main() { |
| 17 test('is', () { | 37 test('is', () { |
| 18 var win = new MockWindow(); | 38 var win = new MockWindow(); |
| 19 expect(win is Window, isTrue); | 39 expect(win is Window, isTrue); |
| 20 }); | 40 }); |
| 21 | 41 |
| 22 test('getter', () { | 42 test('getter', () { |
| 23 var win = new MockWindow(); | 43 var win = new MockWindow(); |
| 24 expect(win.document, equals(document)); | 44 expect(win.document, equals(document)); |
| 25 }); | 45 }); |
| 46 |
| 47 test('override', () { |
| 48 Window win = new MockWindow(); |
| 49 expect(win.onBeforeUnload != null, isTrue); |
| 50 expect(win.name, equals("MOCK_NAME")); |
| 51 }); |
| 52 |
| 53 test('override', () { |
| 54 var loc1 = new MockLocation(); |
| 55 Location loc2 = loc1; |
| 56 dynamic loc3 = loc1; |
| 57 expect(loc1.href, equals("MOCK_HREF")); |
| 58 loc1.href = "RESET"; |
| 59 expect(loc2.href, equals("RESET")); |
| 60 loc2.href = "RESET2"; |
| 61 expect(loc3.href, equals("RESET2")); |
| 62 }); |
| 63 |
| 64 test('method', () { |
| 65 HtmlDocument doc = new MockHtmlDocument(); |
| 66 expect(doc.body.append(null), equals(null)); |
| 67 }); |
| 26 } | 68 } |
| OLD | NEW |