Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /// Whitebox integration/end-to-end test of Try Dart! site. | 5 /// Whitebox integration/end-to-end test of Try Dart! site. |
| 6 /// | 6 /// |
| 7 /// This test opens Try Dart! in an iframe. When opened the first time, Try | 7 /// This test opens Try Dart! in an iframe. When opened the first time, Try |
| 8 /// Dart! will display a simple hello-world example, color tokens, compile the | 8 /// Dart! will display a simple hello-world example, color tokens, compile the |
| 9 /// example, and run the result. We've instrumented Try Dart! to use | 9 /// example, and run the result. We've instrumented Try Dart! to use |
| 10 /// window.parent.postMessage when the running program prints anything. So this | 10 /// window.parent.postMessage when the running program prints anything. So this |
| 11 /// test just waits for a "Hello, World!" message. | 11 /// test just waits for a "Hello, World!" message. |
| 12 library trydart.end_to_end_test; | 12 library trydart.end_to_end_test; |
| 13 | 13 |
| 14 import 'dart:html'; | 14 import 'dart:html'; |
| 15 import 'dart:async'; | 15 import 'dart:async'; |
| 16 | 16 |
| 17 // TODO(ahe): Remove this import if issue 17936 is fixed. | |
| 18 import 'dart:js' as hack; | |
| 19 | |
| 17 import 'package:async_helper/async_helper.dart'; | 20 import 'package:async_helper/async_helper.dart'; |
| 18 | 21 |
| 22 void installErrorHandlerOn(IFrameElement iframe) { | |
| 23 // This method uses dart:js to install an error event handler on the content | |
| 24 // window of [iframe]. This is a workaround for http://dartbug.com/17936. | |
| 25 var iframeProxy = new hack.JsObject.fromBrowserObject(iframe); | |
| 26 var contentWindowProxy = iframeProxy['contentWindow']; | |
| 27 if (contentWindowProxy == null) return; | |
|
kustermann
2014/04/01 20:27:30
If contentWindowProxy is null, we should fail, oth
ahe
2014/04/01 21:21:17
I can't tell when contentWindowProxy is null. As f
ahe
2014/04/03 11:05:35
Changed it to throw an exception.
| |
| 28 contentWindowProxy.callMethod('addEventListener', ['error', (eventProxy) { | |
| 29 String filename = eventProxy['filename']; | |
| 30 int lineno = eventProxy['lineno']; | |
| 31 String message = eventProxy['message']; | |
| 32 print("Error occurred in iframe: $message"); | |
| 33 new Future(() { | |
| 34 // Chrome seems to not call window.onerror when you throw in response to | |
| 35 // an error event. So we throw the error in a future. | |
| 36 throw 'Error from iframe: $filename:$lineno: $message'; | |
| 37 }); | |
| 38 }]); | |
| 39 } | |
| 40 | |
| 41 void onIframeLoaded(ErrorEvent event) { | |
| 42 installErrorHandlerOn(event.target); | |
| 43 } | |
| 44 | |
| 19 void main() { | 45 void main() { |
| 20 asyncStart(); | 46 asyncStart(); |
| 21 window.onMessage.listen((MessageEvent e) { | 47 window.onMessage.listen((MessageEvent e) { |
| 22 if (e.data == 'Hello, World!\n') { | 48 if (e.data == 'Hello, World!\n') { |
| 23 // Clear the DOM to work around a bug in test.dart. | 49 // Clear the DOM to work around a bug in test.dart. |
| 24 document.body.nodes.clear(); | 50 document.body.nodes.clear(); |
| 25 | 51 |
| 26 // Clean up after ourselves. | 52 // Clean up after ourselves. |
| 27 window.localStorage.clear(); | 53 window.localStorage.clear(); |
| 28 | 54 |
| 29 asyncSuccess(null); | 55 asyncSuccess(null); |
| 30 } else { | 56 } else { |
| 31 window.console.dir(e.data); | 57 window.console.dir(e.data); |
| 32 } | 58 } |
| 33 }); | 59 }); |
| 34 | 60 |
| 35 // Clearing localStorage makes Try Dart! think it is opening for the first | 61 // Clearing localStorage makes Try Dart! think it is opening for the first |
| 36 // time. | 62 // time. |
| 37 window.localStorage.clear(); | 63 window.localStorage.clear(); |
| 38 | 64 |
| 39 document.body.append(new IFrameElement() | 65 IFrameElement iframe = new IFrameElement() |
| 40 ..src = '/root_build/try_dartlang_org/index.html' | 66 ..src = '/root_build/try_dartlang_org/index.html' |
| 41 ..style.width = '90vw' | 67 ..style.width = '90vw' |
| 42 ..style.height = '90vh'); | 68 ..style.height = '90vh' |
| 69 ..onLoad.listen(onIframeLoaded); | |
| 70 document.body.append(iframe); | |
| 71 installErrorHandlerOn(iframe); | |
|
kustermann
2014/04/01 20:27:30
Why are you doing this here and in the onIframeLoa
ahe
2014/04/01 21:21:17
As far as I can gather, it matters. I think there
| |
| 43 } | 72 } |
| OLD | NEW |