OLD | NEW |
(Empty) | |
| 1 <html> |
| 2 <body> |
| 3 <script type='application/javascript' src='../../../../../dart/pkg/unittest/lib/
test_controller.js'></script> |
| 4 <script type=application/dart> |
| 5 import 'package:unittest/unittest.dart'; |
| 6 import 'package:unittest/html_config.dart'; |
| 7 import 'dart:async'; |
| 8 import 'dart:html'; |
| 9 |
| 10 main() { |
| 11 useHtmlConfiguration(true); |
| 12 |
| 13 final sameOriginIFrame = new Element.tag('iframe'); |
| 14 sameOriginIFrame.src = 'resources/cross-frame-access-iframe.html'; |
| 15 |
| 16 final crossOriginIFrame = new Element.tag('iframe'); |
| 17 crossOriginIFrame.src = 'data:text/html, <p>test iframe</p>'; |
| 18 |
| 19 test('WaitForFramesLoad', () { |
| 20 var sub1 = null; |
| 21 var sub2 = null; |
| 22 var frameLoaded1 = expectAsync((Event e) { sub1.cancel(); }); |
| 23 var frameLoaded2 = expectAsync((Event e) { sub2.cancel(); }); |
| 24 sub1 = sameOriginIFrame.onLoad.listen(frameLoaded1); |
| 25 document.body.nodes.add(sameOriginIFrame); |
| 26 sub2 = crossOriginIFrame.onLoad.listen(frameLoaded2); |
| 27 document.body.nodes.add(crossOriginIFrame); |
| 28 }); |
| 29 |
| 30 test('Window', () { |
| 31 testWindow(sameOriginIFrame.contentWindow); |
| 32 testWindow(crossOriginIFrame.contentWindow); |
| 33 }); |
| 34 |
| 35 test('History', () { |
| 36 testHistory(sameOriginIFrame.contentWindow.history); |
| 37 testHistory(crossOriginIFrame.contentWindow.history); |
| 38 }); |
| 39 |
| 40 test('Location', () { |
| 41 testLocation(sameOriginIFrame.contentWindow.location); |
| 42 testLocation(crossOriginIFrame.contentWindow.location); |
| 43 }); |
| 44 |
| 45 test('IFrameElement', () { |
| 46 testIFrameElement(sameOriginIFrame); |
| 47 testIFrameElement(crossOriginIFrame); |
| 48 }); |
| 49 } |
| 50 |
| 51 testWindow(WindowBase targetWindow) { |
| 52 // Not allowed methods. |
| 53 expect(() => targetWindow.alert('test'), throws); |
| 54 expect(() => targetWindow.onLoad.listen((Event e) {}), throws); |
| 55 expect(() => |
| 56 targetWindow.find('test', true, true, true, true, true, true), throws); |
| 57 |
| 58 // Not allowed properties. |
| 59 expect(() => targetWindow.contentDocument, throws); |
| 60 expect(() => targetWindow.frameElement, throws); |
| 61 expect(() => targetWindow.localStorage, throws); |
| 62 expect(() => targetWindow.console, throws); |
| 63 |
| 64 // Allowed methods. |
| 65 targetWindow.close(); |
| 66 |
| 67 // Allowed properties. |
| 68 expect(targetWindow.location, isNotNull); |
| 69 expect(targetWindow.history, isNotNull); |
| 70 expect(targetWindow.parent, isNotNull); |
| 71 } |
| 72 |
| 73 testHistory(HistoryBase history) { |
| 74 // Not allowed properties. |
| 75 expect(() => history.length, throws); |
| 76 |
| 77 // Not allowed methods. |
| 78 window.history.pushState('test', 'test', 'test'); |
| 79 expect(() => history.pushState('test', 'test', 'test'), throws); |
| 80 window.history.replaceState('test', 'test', 'test'); |
| 81 expect(() => history.replaceState('test', 'test', 'test'), throws); |
| 82 |
| 83 // Allowed method. |
| 84 history.back(); |
| 85 history.forward(); |
| 86 history.go(-1); |
| 87 } |
| 88 |
| 89 testLocation(LocationBase location) { |
| 90 // Not allowed properties. |
| 91 expect(() => location.href, throws); |
| 92 expect(() => location.protocol, throws); |
| 93 expect(() => location.host = 'test', throws); |
| 94 expect(() => location.origin, throws); |
| 95 |
| 96 // Not allowed methods. |
| 97 expect(() => location.assign('http://www.webkit.org'), throws); |
| 98 expect(() => location.reload(), throws); |
| 99 expect(() => location.getParameter('test'), throws); |
| 100 |
| 101 // Allowed properties. |
| 102 var subscription = null; |
| 103 subscription = window.onMessage.listen(expectAsync((Event e) { |
| 104 subscription.cancel(); |
| 105 expect(e.data, equals('navigated')); |
| 106 Timer.run(expectAsync((){})); |
| 107 })); |
| 108 location.href = 'data:text/html, <script>parent.postMessage("navigated", "*")<
${"/script>"}'; |
| 109 } |
| 110 |
| 111 testIFrameElement(IFrameElement iframe) { |
| 112 expect(() => iframe.contentDocument, throws); |
| 113 expect(() => iframe.getSVGDocument(), throws); |
| 114 } |
| 115 </script> |
| 116 |
| 117 </body> |
| 118 </html> |
OLD | NEW |