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