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

Unified Diff: tests/html/inner_frame_test.dart

Issue 11074005: Wrap Window in case it's a window from a different page / frame. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Cleanup Created 8 years, 2 months 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 side-by-side diff with in-line comments
Download patch
Index: tests/html/inner_frame_test.dart
diff --git a/tests/html/inner_frame_test.dart b/tests/html/inner_frame_test.dart
index 799cb63e833d522c259cda82db0351f00b68bba6..c14fa7956ba5ff19d2155e70fe7955f82d417add 100644
--- a/tests/html/inner_frame_test.dart
+++ b/tests/html/inner_frame_test.dart
@@ -10,30 +10,60 @@ main() {
// The child's frame should not be able to access its parent's
// document.
- // Check window.frameElement.
- try {
- var parentDocument = window.frameElement.document;
- var div = parentDocument.$dom_createElement("div");
- div.id = "illegalFrameElement";
- parentDocument.body.nodes.add(div);
- Expect.fail('Should not reach here.');
- } on NoSuchMethodError catch (e) {
- // Expected.
- }
-
- // Check window.top.
- try {
- final top = window.top;
- var parentDocument = top.document;
- var div = parentDocument.$dom_createElement("div");
- div.id = "illegalTop";
- parentDocument.body.nodes.add(div);
- Expect.fail('Should not reach here.');
- } catch (e) {
- // Expected.
- // TODO(vsm): Enforce this is a NoSuchMethodError.
- }
- return;
+ window.on.message.add((Event e) {
+ switch (e.data) {
+ case 'frameElement': {
+ // Check window.frameElement.
+ try {
+ var parentDocument = window.frameElement.document;
+ var div = parentDocument.$dom_createElement("div");
+ div.id = "illegalFrameElement";
+ parentDocument.body.nodes.add(div);
+ Expect.fail('Should not reach here.');
+ } on NoSuchMethodError catch (e) {
+ // Expected.
+ window.top.postMessage('pass_frameElement', '*');
+ } catch (e) {
+ window.top.postMessage('fail_frameElement', '*');
+ }
+ return;
+ }
+ case 'top': {
+ // Check window.top.
+ try {
+ final top = window.top;
+ var parentDocument = top.document;
+ var div = parentDocument.$dom_createElement("div");
+ div.id = "illegalTop";
+ parentDocument.body.nodes.add(div);
+ Expect.fail('Should not reach here.');
+ } on NoSuchMethodError catch (e) {
+ // Expected.
+ window.top.postMessage('pass_top', '*');
+ } catch (e) {
+ window.top.postMessage('fail_top', '*');
+ }
+ return;
+ }
+ case 'parent': {
+ // Check window.parent.
+ try {
+ final parent = window.parent;
+ var parentDocument = parent.document;
+ var div = parentDocument.$dom_createElement("div");
+ div.id = "illegalParent";
+ parentDocument.body.nodes.add(div);
+ Expect.fail('Should not reach here.');
+ } on NoSuchMethodError catch (e) {
+ // Expected.
+ window.top.postMessage('pass_parent', '*');
+ } catch (e) {
+ window.top.postMessage('fail_parent', '*');
+ }
+ return;
+ }
+ }
+ });
}
// Parent / test frame
@@ -41,23 +71,50 @@ main() {
final iframe = new Element.tag('iframe');
iframe.src = window.location.href;
+ var child;
test('prepare', () {
- iframe.on.load.add(expectAsync1((e) {}));
+ iframe.on.load.add(expectAsync1((e) { child = iframe.contentWindow;}));
document.body.nodes.add(iframe);
});
+ final validate = (testName, verify) {
+ final expectedVerify = expectAsync0(verify);
+ window.on.message.add((e) {
+ guardAsync(() {
+ if (e.data == 'pass_$testName') {
+ expectedVerify();
+ }
+ expect(e.data != 'fail_$testName');
+ });
+ });
+ child.postMessage(testName, '*');
+ };
+
test('frameElement', () {
- var div = document.query('#illegalFrameElement');
+ validate('frameElement', () {
+ var div = document.query('#illegalFrameElement');
- // Ensure that this parent frame was not modified by its child.
- Expect.isNull(div);
+ // Ensure that this parent frame was not modified by its child.
+ expect(div, isNull);
+ });
});
test('top', () {
- var div = document.query('#illegalTop');
+ validate('top', () {
+ var div = document.query('#illegalTop');
+
+ // Ensure that this parent frame was not modified by its child.
+ expect(div, isNull);
+ });
+ });
+
+ test('parent', () {
+ validate('parent', () {
+ var div = document.query('#illegalParent');
- // Ensure that this parent frame was not modified by its child.
- Expect.isNull(div);
+ // Ensure that this parent frame was not modified by its child.
+ expect(div, isNull);
+ });
});
}

Powered by Google App Engine
This is Rietveld 408576698