| 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 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 contentWindowProxy['onerror'] = onError; | 64 contentWindowProxy['onerror'] = onError; |
| 65 } | 65 } |
| 66 | 66 |
| 67 void onIframeLoaded(Event event) { | 67 void onIframeLoaded(Event event) { |
| 68 installErrorHandlerOn(event.target); | 68 installErrorHandlerOn(event.target); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void main() { | 71 void main() { |
| 72 asyncStart(); | 72 asyncStart(); |
| 73 window.onMessage.listen((MessageEvent e) { | 73 window.onMessage.listen((MessageEvent e) { |
| 74 if (e.data == 'Hello, World!\n') { | 74 switch (e.data) { |
| 75 // Clear the DOM to work around a bug in test.dart. | 75 case 'Hello, World!\n': |
| 76 document.body.nodes.clear(); | 76 // Clear the DOM to work around a bug in test.dart. |
| 77 document.body.nodes.clear(); |
| 77 | 78 |
| 78 // Clean up after ourselves. | 79 // Clean up after ourselves. |
| 79 window.localStorage.clear(); | 80 window.localStorage.clear(); |
| 80 | 81 |
| 81 asyncEnd(); | 82 asyncEnd(); |
| 83 break; |
| 84 |
| 85 case 'dart-calling-main': |
| 86 case 'dart-main-done': |
| 87 case 'unittest-suite-done': |
| 88 case 'unittest-suite-fail': |
| 89 case 'unittest-suite-success': |
| 90 case 'unittest-suite-wait-for-done': |
| 91 break; |
| 92 |
| 93 default: |
| 94 throw 'Unexpected message: ${e.data}'; |
| 82 } | 95 } |
| 83 }); | 96 }); |
| 84 | 97 |
| 85 // Clearing localStorage makes Try Dart! think it is opening for the first | 98 // Clearing localStorage makes Try Dart! think it is opening for the first |
| 86 // time. | 99 // time. |
| 87 window.localStorage.clear(); | 100 window.localStorage.clear(); |
| 88 | 101 |
| 89 IFrameElement iframe = new IFrameElement() | 102 IFrameElement iframe = new IFrameElement() |
| 90 ..src = '/root_build/try_dartlang_org/index.html' | 103 ..src = '/root_build/try_dartlang_org/index.html' |
| 91 ..style.width = '90vw' | 104 ..style.width = '90vw' |
| 92 ..style.height = '90vh' | 105 ..style.height = '90vh' |
| 93 ..onLoad.listen(onIframeLoaded); | 106 ..onLoad.listen(onIframeLoaded); |
| 94 document.body.append(iframe); | 107 document.body.append(iframe); |
| 95 // Install an error handler both on the new iframe element, and when it has | 108 // Install an error handler both on the new iframe element, and when it has |
| 96 // fired the load event. That seems to matter according to some sources on | 109 // fired the load event. That seems to matter according to some sources on |
| 97 // stackoverflow. | 110 // stackoverflow. |
| 98 installErrorHandlerOn(iframe); | 111 installErrorHandlerOn(iframe); |
| 99 } | 112 } |
| OLD | NEW |