Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 library InnerFrameTest; | |
| 2 import '../../pkg/unittest/lib/unittest.dart'; | |
| 3 import '../../pkg/unittest/lib/html_config.dart'; | |
| 4 import 'dart:html'; | |
| 5 | |
| 6 main() { | |
| 7 if (window != window.top) { | |
| 8 // Child frame. | |
| 9 | |
| 10 // The child's frame should not be able to access its parent's | |
| 11 // document. | |
| 12 | |
| 13 window.onMessage.listen((Event e) { | |
|
blois
2013/03/04 19:30:05
This test is horribly broken because of the nestin
| |
| 14 switch (e.data) { | |
| 15 case 'frameElement': { | |
| 16 // Check window.frameElement. | |
| 17 try { | |
| 18 var parentDocument = window.frameElement.document; | |
| 19 var div = parentDocument.$dom_createElement("div"); | |
| 20 div.id = "illegalFrameElement"; | |
| 21 parentDocument.body.nodes.add(div); | |
| 22 expect(false, isTrue, reason: 'Should not reach here.'); | |
| 23 } on NoSuchMethodError catch (e) { | |
| 24 // Expected. | |
| 25 window.top.postMessage('pass_frameElement', '*'); | |
| 26 } catch (e) { | |
| 27 window.top.postMessage('fail_frameElement', '*'); | |
| 28 } | |
| 29 return; | |
| 30 } | |
| 31 case 'top': { | |
| 32 // Check window.top. | |
| 33 try { | |
| 34 final top = window.top; | |
| 35 var parentDocument = top.document; | |
| 36 var div = parentDocument.$dom_createElement("div"); | |
| 37 div.id = "illegalTop"; | |
| 38 parentDocument.body.nodes.add(div); | |
| 39 expect(false, isTrue, reason: 'Should not reach here.'); | |
| 40 } on NoSuchMethodError catch (e) { | |
| 41 // Expected. | |
| 42 window.top.postMessage('pass_top', '*'); | |
| 43 } catch (e) { | |
| 44 window.top.postMessage('fail_top', '*'); | |
| 45 } | |
| 46 return; | |
| 47 } | |
| 48 case 'parent': { | |
| 49 // Check window.parent. | |
| 50 try { | |
| 51 final parent = window.parent; | |
| 52 var parentDocument = parent.document; | |
| 53 var div = parentDocument.$dom_createElement("div"); | |
| 54 div.id = "illegalParent"; | |
| 55 parentDocument.body.nodes.add(div); | |
| 56 expect(false, isTrue, reason: 'Should not reach here.'); | |
| 57 } on NoSuchMethodError catch (e) { | |
| 58 // Expected. | |
| 59 window.top.postMessage('pass_parent', '*'); | |
| 60 } catch (e) { | |
| 61 window.top.postMessage('fail_parent', '*'); | |
| 62 } | |
| 63 return; | |
| 64 } | |
| 65 } | |
| 66 }); | |
| 67 } | |
| 68 | |
| 69 // Parent / test frame | |
| 70 useHtmlConfiguration(); | |
| 71 | |
| 72 final iframe = new Element.tag('iframe'); | |
| 73 iframe.src = window.location.href; | |
| 74 var child; | |
| 75 | |
| 76 test('prepare', () { | |
| 77 iframe.onLoad.listen(expectAsync1((e) { child = iframe.contentWindow;})); | |
| 78 document.body.nodes.add(iframe); | |
| 79 }); | |
| 80 | |
| 81 final validate = (testName, verify) { | |
| 82 final expectedVerify = expectAsync0(verify); | |
| 83 window.onMessage.listen((e) { | |
| 84 guardAsync(() { | |
| 85 if (e.data == 'pass_$testName') { | |
| 86 expectedVerify(); | |
| 87 } | |
| 88 expect(e.data, isNot(equals('fail_$testName'))); | |
| 89 }); | |
| 90 }); | |
| 91 child.postMessage(testName, '*'); | |
| 92 }; | |
| 93 | |
| 94 test('frameElement', () { | |
| 95 validate('frameElement', () { | |
| 96 var div = document.query('#illegalFrameElement'); | |
| 97 | |
| 98 // Ensure that this parent frame was not modified by its child. | |
| 99 expect(div, isNull); | |
| 100 }); | |
| 101 }); | |
| 102 | |
| 103 test('top', () { | |
| 104 validate('top', () { | |
| 105 var div = document.query('#illegalTop'); | |
| 106 | |
| 107 // Ensure that this parent frame was not modified by its child. | |
| 108 expect(div, isNull); | |
| 109 }); | |
| 110 }); | |
| 111 | |
| 112 test('parent', () { | |
| 113 validate('parent', () { | |
| 114 var div = document.query('#illegalParent'); | |
| 115 | |
| 116 // Ensure that this parent frame was not modified by its child. | |
| 117 expect(div, isNull); | |
| 118 }); | |
| 119 }); | |
| 120 } | |
| OLD | NEW |