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

Side by Side Diff: dart/tests/try/end_to_end_test.dart

Issue 386563002: Add "point of interest" app for command-line testing of dart2js type information. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « dart/tests/try/cursor_position_test.dart ('k') | dart/tests/try/internal_error_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 /// Whitebox integration/end-to-end test of Try Dart! site.
6 ///
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
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
11 /// test just waits for a "Hello, World!" message.
12 library trydart.end_to_end_test;
13
14 import 'dart:html';
15 import 'dart:async';
16
17 // TODO(ahe): Remove this import if issue 17936 is fixed.
18 import 'dart:js' as hack;
19
20 import 'package:async_helper/async_helper.dart';
21
22 void onError(String message, String filename, int lineno, [int colno, error]) {
23 if (filename != null && filename != "" && lineno != 0) {
24 if (colno != null && colno != 0) {
25 message = '$filename:$lineno:$colno $message';
26 } else {
27 message = '$filename:$lineno: $message';
28 }
29 }
30 if (error != null) {
31 // See:
32 // https://mikewest.org/2013/08/debugging-runtime-errors-with-window-onerror
33 var stack = error['stack'];
34 if (stack != null) {
35 message += '\n$stack';
36 }
37 }
38 message = "Error occurred in Try Dart iframe: $message";
39
40 // Synchronous, easier to read when running the browser manually.
41 window.console.log(message);
42
43 new Future(() {
44 // Browsers ignore errors throw in event listeners (or from
45 // window.onerror).
46 throw message;
47 });
48 }
49
50 void installErrorHandlerOn(IFrameElement iframe) {
51 // This method uses dart:js to install an error event handler on the content
52 // window of [iframe]. This is a workaround for http://dartbug.com/17936.
53 var iframeProxy = new hack.JsObject.fromBrowserObject(iframe);
54 var contentWindowProxy = iframeProxy['contentWindow'];
55 if (contentWindowProxy == null) {
56 print('No contentWindow in iframe');
57 throw 'No contentWindow in iframe';
58 }
59
60 // Note: we have two options, use "iframe.contentWindow.onerror = ..." or
61 // "iframe.contentWindow.addEventListener('error', ...)". The former seems
62 // to provide more details on both Chrome and Firefox (which provides no
63 // information at all in error events).
64 contentWindowProxy['onerror'] = onError;
65 }
66
67 void onIframeLoaded(Event event) {
68 installErrorHandlerOn(event.target);
69 }
70
71 void main() {
72 asyncStart();
73 window.onMessage.listen((MessageEvent e) {
74 switch (e.data) {
75 case 'Hello, World!\n':
76 // Clear the DOM to work around a bug in test.dart.
77 document.body.nodes.clear();
78
79 // Clean up after ourselves.
80 window.localStorage.clear();
81
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}';
95 }
96 });
97
98 // Clearing localStorage makes Try Dart! think it is opening for the first
99 // time.
100 window.localStorage.clear();
101
102 IFrameElement iframe = new IFrameElement()
103 ..src = '/root_build/try_dartlang_org/index.html'
104 ..style.width = '90vw'
105 ..style.height = '90vh'
106 ..onLoad.listen(onIframeLoaded);
107 document.body.append(iframe);
108 // Install an error handler both on the new iframe element, and when it has
109 // fired the load event. That seems to matter according to some sources on
110 // stackoverflow.
111 installErrorHandlerOn(iframe);
112 }
OLDNEW
« no previous file with comments | « dart/tests/try/cursor_position_test.dart ('k') | dart/tests/try/internal_error_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698