Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(480)

Side by Side Diff: tests/html/inner_frame_test.dart

Issue 11275054: Modified unittest to use new argument syntax. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 #library('InnerFrameTest'); 1 #library('InnerFrameTest');
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 if (window != window.top) { 7 if (window != window.top) {
8 // Child frame. 8 // Child frame.
9 9
10 // The child's frame should not be able to access its parent's 10 // The child's frame should not be able to access its parent's
11 // document. 11 // document.
12 12
13 window.on.message.add((Event e) { 13 window.on.message.add((Event e) {
14 switch (e.data) { 14 switch (e.data) {
15 case 'frameElement': { 15 case 'frameElement': {
16 // Check window.frameElement. 16 // Check window.frameElement.
17 try { 17 try {
18 var parentDocument = window.frameElement.document; 18 var parentDocument = window.frameElement.document;
19 var div = parentDocument.$dom_createElement("div"); 19 var div = parentDocument.$dom_createElement("div");
20 div.id = "illegalFrameElement"; 20 div.id = "illegalFrameElement";
21 parentDocument.body.nodes.add(div); 21 parentDocument.body.nodes.add(div);
22 Expect.fail('Should not reach here.'); 22 expect(false, isTrue, reason: 'Should not reach here.');
23 } on NoSuchMethodError catch (e) { 23 } on NoSuchMethodError catch (e) {
24 // Expected. 24 // Expected.
25 window.top.postMessage('pass_frameElement', '*'); 25 window.top.postMessage('pass_frameElement', '*');
26 } catch (e) { 26 } catch (e) {
27 window.top.postMessage('fail_frameElement', '*'); 27 window.top.postMessage('fail_frameElement', '*');
28 } 28 }
29 return; 29 return;
30 } 30 }
31 case 'top': { 31 case 'top': {
32 // Check window.top. 32 // Check window.top.
33 try { 33 try {
34 final top = window.top; 34 final top = window.top;
35 var parentDocument = top.document; 35 var parentDocument = top.document;
36 var div = parentDocument.$dom_createElement("div"); 36 var div = parentDocument.$dom_createElement("div");
37 div.id = "illegalTop"; 37 div.id = "illegalTop";
38 parentDocument.body.nodes.add(div); 38 parentDocument.body.nodes.add(div);
39 Expect.fail('Should not reach here.'); 39 expect(false, isTrue, reason: 'Should not reach here.');
40 } on NoSuchMethodError catch (e) { 40 } on NoSuchMethodError catch (e) {
41 // Expected. 41 // Expected.
42 window.top.postMessage('pass_top', '*'); 42 window.top.postMessage('pass_top', '*');
43 } catch (e) { 43 } catch (e) {
44 window.top.postMessage('fail_top', '*'); 44 window.top.postMessage('fail_top', '*');
45 } 45 }
46 return; 46 return;
47 } 47 }
48 case 'parent': { 48 case 'parent': {
49 // Check window.parent. 49 // Check window.parent.
50 try { 50 try {
51 final parent = window.parent; 51 final parent = window.parent;
52 var parentDocument = parent.document; 52 var parentDocument = parent.document;
53 var div = parentDocument.$dom_createElement("div"); 53 var div = parentDocument.$dom_createElement("div");
54 div.id = "illegalParent"; 54 div.id = "illegalParent";
55 parentDocument.body.nodes.add(div); 55 parentDocument.body.nodes.add(div);
56 Expect.fail('Should not reach here.'); 56 expect(false, isTrue, reason: 'Should not reach here.');
57 } on NoSuchMethodError catch (e) { 57 } on NoSuchMethodError catch (e) {
58 // Expected. 58 // Expected.
59 window.top.postMessage('pass_parent', '*'); 59 window.top.postMessage('pass_parent', '*');
60 } catch (e) { 60 } catch (e) {
61 window.top.postMessage('fail_parent', '*'); 61 window.top.postMessage('fail_parent', '*');
62 } 62 }
63 return; 63 return;
64 } 64 }
65 } 65 }
66 }); 66 });
(...skipping 11 matching lines...) Expand all
78 document.body.nodes.add(iframe); 78 document.body.nodes.add(iframe);
79 }); 79 });
80 80
81 final validate = (testName, verify) { 81 final validate = (testName, verify) {
82 final expectedVerify = expectAsync0(verify); 82 final expectedVerify = expectAsync0(verify);
83 window.on.message.add((e) { 83 window.on.message.add((e) {
84 guardAsync(() { 84 guardAsync(() {
85 if (e.data == 'pass_$testName') { 85 if (e.data == 'pass_$testName') {
86 expectedVerify(); 86 expectedVerify();
87 } 87 }
88 expect(e.data != 'fail_$testName'); 88 expect(e.data, isNot(equals('fail_$testName')));
89 }); 89 });
90 }); 90 });
91 child.postMessage(testName, '*'); 91 child.postMessage(testName, '*');
92 }; 92 };
93 93
94 test('frameElement', () { 94 test('frameElement', () {
95 validate('frameElement', () { 95 validate('frameElement', () {
96 var div = document.query('#illegalFrameElement'); 96 var div = document.query('#illegalFrameElement');
97 97
98 // Ensure that this parent frame was not modified by its child. 98 // Ensure that this parent frame was not modified by its child.
(...skipping 12 matching lines...) Expand all
111 111
112 test('parent', () { 112 test('parent', () {
113 validate('parent', () { 113 validate('parent', () {
114 var div = document.query('#illegalParent'); 114 var div = document.query('#illegalParent');
115 115
116 // Ensure that this parent frame was not modified by its child. 116 // Ensure that this parent frame was not modified by its child.
117 expect(div, isNull); 117 expect(div, isNull);
118 }); 118 });
119 }); 119 });
120 } 120 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698