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

Unified Diff: dart/tests/try/web/sandbox.dart

Issue 645513002: Scaffolding for testing incremental compilation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix bad refactoring. Created 6 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
« no previous file with comments | « dart/tests/try/web/print.js ('k') | dart/tests/try/web/web_compiler_test_case.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/tests/try/web/sandbox.dart
diff --git a/dart/tests/try/web/end_to_end_test.dart b/dart/tests/try/web/sandbox.dart
similarity index 59%
copy from dart/tests/try/web/end_to_end_test.dart
copy to dart/tests/try/web/sandbox.dart
index bffbd8e5d840cb1dd5c29273dab311ff9c0498e6..e11567c945d00b696f27cfda274e7b2483503f25 100644
--- a/dart/tests/try/web/end_to_end_test.dart
+++ b/dart/tests/try/web/sandbox.dart
@@ -2,14 +2,9 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-/// Whitebox integration/end-to-end test of Try Dart! site.
-///
-/// This test opens Try Dart! in an iframe. When opened the first time, Try
-/// Dart! will display a simple hello-world example, color tokens, compile the
-/// example, and run the result. We've instrumented Try Dart! to use
-/// window.parent.postMessage when the running program prints anything. So this
-/// test just waits for a "Hello, World!" message.
-library trydart.end_to_end_test;
+/// Helper library that creates an iframe sandbox that can be used to load
+/// code.
+library trydart.test.sandbox;
import 'dart:html';
import 'dart:async';
@@ -17,7 +12,10 @@ import 'dart:async';
// TODO(ahe): Remove this import if issue 17936 is fixed.
import 'dart:js' as hack;
-import 'package:async_helper/async_helper.dart';
+import 'package:expect/expect.dart' show
+ Expect;
+
+final Listener listener = new Listener();
void onError(String message, String filename, int lineno, [int colno, error]) {
if (filename != null && filename != "" && lineno != 0) {
@@ -35,7 +33,7 @@ void onError(String message, String filename, int lineno, [int colno, error]) {
message += '\n$stack';
}
}
- message = "Error occurred in Try Dart iframe: $message";
+ message = "Error occurred in iframe: $message";
// Synchronous, easier to read when running the browser manually.
window.console.log(message);
@@ -68,46 +66,57 @@ void onIframeLoaded(Event event) {
installErrorHandlerOn(event.target);
}
-void main() {
- document.cookie = 'org-trydart-AutomatedTest=true;path=/';
- asyncStart();
- window.onMessage.listen((MessageEvent e) {
- switch (e.data) {
- case 'Hello, World!\n':
- // Clear the DOM to work around a bug in test.dart.
- document.body.nodes.clear();
-
- // Clean up after ourselves.
- window.localStorage.clear();
-
- asyncEnd();
- break;
-
- case 'dart-calling-main':
- case 'dart-main-done':
- case 'unittest-suite-done':
- case 'unittest-suite-fail':
- case 'unittest-suite-success':
- case 'unittest-suite-wait-for-done':
- break;
-
- default:
- throw 'Unexpected message: ${e.data}';
- }
- });
-
- // Clearing localStorage makes Try Dart! think it is opening for the first
- // time.
- window.localStorage.clear();
-
+IFrameElement appendIFrame(String src, Element element) {
IFrameElement iframe = new IFrameElement()
- ..src = '/root_build/try_dartlang_org/index.html'
- ..style.width = '90vw'
- ..style.height = '90vh'
+ ..src = src
..onLoad.listen(onIframeLoaded);
- document.body.append(iframe);
+ element.append(iframe);
// Install an error handler both on the new iframe element, and when it has
// fired the load event. That seems to matter according to some sources on
// stackoverflow.
installErrorHandlerOn(iframe);
+ return iframe;
+}
+
+class Listener {
+ Completer completer;
+
+ String expectedMessage;
+
+ void onMessage(MessageEvent e) {
+ String message = e.data;
+ if (expectedMessage == message) {
+ completer.complete();
+ } else {
+ switch (message) {
+ case 'dart-calling-main':
+ case 'dart-main-done':
+ case 'unittest-suite-done':
+ case 'unittest-suite-fail':
+ case 'unittest-suite-success':
+ case 'unittest-suite-wait-for-done':
+ break;
+
+ default:
+ completer.completeError('Unexpected message: "$message".');
+ }
+ }
+ }
+
+ Future expect(data) {
+ if (data is String) {
+ Expect.isTrue(completer == null || completer.isCompleted);
+ expectedMessage = data;
+ completer = new Completer();
+ return completer.future;
+ } else if (data is Iterable) {
+ return Future.forEach(data, expect);
+ } else {
+ throw 'Unexpected data type: ${data.runtimeType}.';
+ }
+ }
+
+ void start() {
+ window.onMessage.listen(onMessage);
+ }
}
« no previous file with comments | « dart/tests/try/web/print.js ('k') | dart/tests/try/web/web_compiler_test_case.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698