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