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