OLD | NEW |
1 import 'dart:html'; | 1 import 'dart:html'; |
2 | 2 |
3 import 'package:expect/minitest.dart'; | 3 import 'package:expect/minitest.dart'; |
4 | 4 |
5 main() { | 5 main() { |
6 var isWindowBase = predicate((x) => x is WindowBase, 'is a WindowBase'); | 6 var isWindowBase = predicate((x) => x is WindowBase, 'is a WindowBase'); |
7 var isWindow = predicate((x) => x is Window, 'is a Window'); | 7 var isWindow = predicate((x) => x is Window, 'is a Window'); |
8 var isLocationBase = predicate((x) => x is LocationBase, 'is a LocationBase'); | 8 var isLocationBase = predicate((x) => x is LocationBase, 'is a LocationBase'); |
9 var isLocation = | 9 var isLocation = predicate((x) => x is Location, 'is a Location'); |
10 predicate((x) => x is Location, 'is a Location'); | |
11 var isHistoryBase = predicate((x) => x is HistoryBase, 'is a HistoryBase'); | 10 var isHistoryBase = predicate((x) => x is HistoryBase, 'is a HistoryBase'); |
12 var isHistory = predicate((x) => x is History, 'is a History'); | 11 var isHistory = predicate((x) => x is History, 'is a History'); |
13 | 12 |
14 final iframe = new IFrameElement(); | 13 final iframe = new IFrameElement(); |
15 document.body.append(iframe); | 14 document.body.append(iframe); |
16 | 15 |
17 test('window', () { | 16 test('window', () { |
18 expect(window, isWindow); | 17 expect(window, isWindow); |
19 expect(window.document, document); | 18 expect(window.document, document); |
20 }); | 19 }); |
21 | 20 |
22 test('iframe', () { | 21 test('iframe', () { |
23 final frameWindow = iframe.contentWindow; | 22 final frameWindow = iframe.contentWindow; |
24 expect(frameWindow, isWindowBase); | 23 expect(frameWindow, isWindowBase); |
25 //TODO(gram) The next test should be written as: | 24 //TODO(gram) The next test should be written as: |
26 // expect(frameWindow, isNot(isWindow)); | 25 // expect(frameWindow, isNot(isWindow)); |
27 // but that will cause problems now until is/is! work | 26 // but that will cause problems now until is/is! work |
28 // properly in dart2js instead of always returning true. | 27 // properly in dart2js instead of always returning true. |
29 expect(frameWindow is! Window, isTrue); | 28 expect(frameWindow is! Window, isTrue); |
30 expect(frameWindow.parent, isWindow); | 29 expect(frameWindow.parent, isWindow); |
31 | 30 |
32 // Ensure that the frame's document is inaccessible via window. | 31 // Ensure that the frame's document is inaccessible via window. |
33 expect(() => frameWindow.document, throws); | 32 expect(() => frameWindow.document, throws); |
34 }); | 33 }); |
35 | 34 |
36 test('contentDocument', () { | 35 test('contentDocument', () { |
37 // Ensure that the frame's document is inaccessible. | 36 // Ensure that the frame's document is inaccessible. |
38 expect(() => iframe.contentDocument, throws); | 37 expect(() => iframe.contentDocument, throws); |
39 }); | 38 }); |
40 | 39 |
41 test('location', () { | 40 test('location', () { |
42 expect(window.location, isLocation); | 41 expect(window.location, isLocation); |
43 final frameLocation = iframe.contentWindow.location; | 42 final frameLocation = iframe.contentWindow.location; |
44 expect(frameLocation, isLocationBase); | 43 expect(frameLocation, isLocationBase); |
45 // TODO(gram) Similar to the above, the next test should be: | 44 // TODO(gram) Similar to the above, the next test should be: |
46 // expect(frameLocation, isNot(isLocation)); | 45 // expect(frameLocation, isNot(isLocation)); |
47 expect(frameLocation is! Location, isTrue); | 46 expect(frameLocation is! Location, isTrue); |
48 | 47 |
49 expect(() => frameLocation.href, throws); | 48 expect(() => frameLocation.href, throws); |
50 expect(() => frameLocation.hash, throws); | 49 expect(() => frameLocation.hash, throws); |
51 | 50 |
52 final frameParentLocation = iframe.contentWindow.parent.location; | 51 final frameParentLocation = iframe.contentWindow.parent.location; |
53 expect(frameParentLocation, isLocation); | 52 expect(frameParentLocation, isLocation); |
54 }); | 53 }); |
55 | 54 |
56 test('history', () { | 55 test('history', () { |
57 expect(window.history, isHistory); | 56 expect(window.history, isHistory); |
58 final frameHistory = iframe.contentWindow.history; | 57 final frameHistory = iframe.contentWindow.history; |
59 expect(frameHistory, isHistoryBase); | 58 expect(frameHistory, isHistoryBase); |
60 // See earlier comments. | 59 // See earlier comments. |
61 //expect(frameHistory, isNot(isHistory)); | 60 //expect(frameHistory, isNot(isHistory)); |
62 expect(frameHistory is! History, isTrue); | 61 expect(frameHistory is! History, isTrue); |
63 | 62 |
64 // Valid methods. | 63 // Valid methods. |
65 frameHistory.forward(); | 64 frameHistory.forward(); |
66 | 65 |
67 expect(() => frameHistory.length, throws); | 66 expect(() => frameHistory.length, throws); |
68 | 67 |
69 final frameParentHistory = iframe.contentWindow.parent.history; | 68 final frameParentHistory = iframe.contentWindow.parent.history; |
70 expect(frameParentHistory, isHistory); | 69 expect(frameParentHistory, isHistory); |
71 }); | 70 }); |
72 } | 71 } |
OLD | NEW |