Index: LayoutTests/dart/Window-postMessage.html |
diff --git a/LayoutTests/dart/Window-postMessage.html b/LayoutTests/dart/Window-postMessage.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b2df36d07de96f608f10d40eff96cab799313c4b |
--- /dev/null |
+++ b/LayoutTests/dart/Window-postMessage.html |
@@ -0,0 +1,99 @@ |
+<html> |
+<body> |
+ |
+<div id='status'></div> |
+<iframe src='resources/pong.html'></iframe> |
+ |
+<script type='application/dart'> |
+import 'dart:html'; |
+ |
+class MessageQueue { |
+ final WindowBase _main; |
+ final WindowBase _target; |
+ final List _messages; |
+ int _pos = -1; |
+ |
+ MessageQueue(this._main, this._target, this._messages); |
+ |
+ void run() { |
+ scheduleNext(); |
+ } |
+ |
+ void scheduleNext() { |
+ _pos++; |
+ if (_pos == _messages.length) { |
+ _notifyDone(); |
+ return; |
+ } |
+ |
+ if (_pos % 2 == 0) { |
+ _target.postMessage(currentMessage, '*', []); |
+ } else { |
+ _target.postMessage(currentMessage, '*'); |
+ } |
+ output('message sent: $currentMessage'); |
+ } |
+ |
+ get currentMessage => _messages[_pos]; |
+ |
+ void _notifyDone() { |
+ window.postMessage('test-done', '*'); |
+ } |
+} |
+ |
+void main() { |
+ IFrameElement iframeElement = document.queryAll('iframe')[0]; |
+ iframeElement.onLoad.listen(test); |
+} |
+ |
+test(Event e) { |
+ WindowBase other = document.queryAll('iframe')[0].contentWindow; |
+ |
+ // FIXME: consider support for WebCore objects like File, FileList. |
+ MessageQueue messageQueue = new MessageQueue(window, other, [null, 'I am a string']); |
+ |
+ window.onMessage.listen( |
+ (Event event) { |
+ output('response received: ${event.data}'); |
+ output('event.source === other: ${event.source == other}'); |
+ messageQueue.scheduleNext(); |
+ }); |
+ |
+ try { |
+ other.postMessage(); |
+ } catch(_) { |
+ output('.postMessage() throws'); |
+ } |
+ |
+ try { |
+ other.postMessage(null); |
+ } catch (_) { |
+ output('.postMessage(null) throws'); |
+ } |
+ |
+ messageQueue.run(); |
+} |
+ |
+output(var object) { |
+ final status = document.query('#status'); |
+ status.innerHtml = '${status.innerHtml}$object<br>'; |
+} |
+ |
+</script> |
+ |
+<script> |
+ if (window.testRunner) { |
+ window.testRunner.dumpAsText(); |
+ window.testRunner.waitUntilDone(); |
+ } |
+ |
+ window.addEventListener('message', function (e) { |
+ if (e.data == 'test-done') { |
+ window.testRunner.notifyDone(); |
+ } |
+ }); |
+ |
+</script> |
+ |
+</body> |
+</html> |