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

Side by Side Diff: dart/tests/try/web/incremental_compilation_update_test.dart

Issue 654523003: Handle top-level tear offs. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 library trydart.incremental_compilation_update_test; 5 library trydart.incremental_compilation_update_test;
6 6
7 import 'dart:html'; 7 import 'dart:html';
8 8
9 import 'dart:async' show 9 import 'dart:async' show
10 Future; 10 Future;
11 11
12 import 'package:async_helper/async_helper.dart' show 12 import 'package:async_helper/async_helper.dart' show
13 asyncTest; 13 asyncTest;
14 14
15 import 'sandbox.dart' show 15 import 'sandbox.dart' show
16 appendIFrame, 16 appendIFrame,
17 listener; 17 listener;
18 18
19 import 'web_compiler_test_case.dart' show 19 import 'web_compiler_test_case.dart' show
20 WebCompilerTestCase, 20 WebCompilerTestCase,
21 WebInputProvider; 21 WebInputProvider;
22 22
23 void main() => asyncTest(() { 23 import 'program_result.dart';
24
25 const List<List<ProgramResult>> tests = const <List<ProgramResult>>[
26 // Basic hello-world test.
27 const <ProgramResult>[
28 const ProgramResult(
29 "main() { print('Hello, World!'); }",
30 const <String> ['Hello, World!']),
31 const ProgramResult(
32 "main() { print('Hello, Brave New World!'); }",
33 const <String> ['Hello, Brave New World!']),
34 ],
35
36 // Test that the test framework handles more than one update.
37 const <ProgramResult>[
38 const ProgramResult(
39 "main() { print('Hello darkness, my old friend'); }",
40 const <String> ['Hello darkness, my old friend']),
41 const ProgramResult(
42 "main() { print('I\\'ve come to talk with you again'); }",
43 const <String> ['I\'ve come to talk with you again']),
44 const ProgramResult(
45 "main() { print('Because a vision softly creeping'); }",
46 const <String> ['Because a vision softly creeping']),
47 ],
48
49 // Test that that isolate support works.
50 const <ProgramResult>[
51 const ProgramResult(
52 "main(arguments) { print('Hello, Isolated World!'); }",
53 const <String> ['Hello, Isolated World!']),
54 const ProgramResult(
55 "main(arguments) { print(arguments); }",
56 const <String> ['[]']),
57 ],
58
59 // Test that a store closure changes behavior when updated.
Johnni Winther 2014/10/14 07:40:26 store -> stored
ahe 2014/10/15 09:11:12 Done.
60 const <ProgramResult>[
61 const ProgramResult(
62 r"""
63 var closure;
64
65 foo(a, [b = 'b']) {
66 print('$a $b');
67 }
68
69 main() {
70 if (closure == null) {
71 print('[closure] is null.');
72 closure = foo;
73 }
74 closure('a');
75 closure('a', 'c');
76 }
77 """,
78 const <String> ['[closure] is null.', 'a b', 'a c']),
79 const ProgramResult(
80 r"""
81 var closure;
82
83 foo(a, [b = 'b']) {
84 print('$b $a');
85 }
86
87 main() {
88 if (closure == null) {
89 print('[closure] is null.');
90 closure = foo;
91 }
92 closure('a');
93 closure('a', 'c');
94 }
95 """,
96 const <String> ['b a', 'c a']),
97 ],
98 ];
99
100
101 void main() {
24 listener.start(); 102 listener.start();
25 103
104 return asyncTest(() => Future.forEach(tests, compileAndRun));
105 }
106
107 Future compileAndRun(List<ProgramResult> programs) {
108 var status = new DivElement();
109 document.body.append(status);
110
26 IFrameElement iframe = 111 IFrameElement iframe =
27 appendIFrame( 112 appendIFrame(
28 '/root_dart/tests/try/web/incremental_compilation_update.html', 113 '/root_dart/tests/try/web/incremental_compilation_update.html',
29 document.body) 114 document.body)
30 ..style.width = '90vw' 115 ..style.width = '100%'
31 ..style.height = '90vh'; 116 ..style.height = '600px';
32 117
33 return listener.expect('iframe-ready').then((_) { 118 return listener.expect('iframe-ready').then((_) {
34 WebCompilerTestCase test = 119 ProgramResult program = programs.first;
35 new WebCompilerTestCase("main() { print('Hello, World!'); }"); 120 status.append(new PreElement()..appendText(program.code));
121 status.style.color = 'orange';
122 WebCompilerTestCase test = new WebCompilerTestCase(program.code);
36 return test.run().then((String jsCode) { 123 return test.run().then((String jsCode) {
37 var objectUrl = 124 status.style.color = 'red';
38 Url.createObjectUrl(new Blob([jsCode], 'application/javascript')); 125 var objectUrl =
126 Url.createObjectUrl(new Blob([jsCode], 'application/javascript'));
39 127
40 iframe.contentWindow.postMessage(['add-script', objectUrl], '*'); 128 iframe.contentWindow.postMessage(['add-script', objectUrl], '*');
41 return listener.expect(['Hello, World!', 'iframe-dart-main-done']).then( 129 Future future =
42 (_) { 130 listener.expect(program.messagesWith('iframe-dart-main-done'));
43 WebInputProvider inputProvider = 131 return future.then((_) {
44 test.incrementalCompiler.inputProvider; 132 int version = 2;
45 Uri uri = test.scriptUri.resolve('?v2'); 133 return Future.forEach(programs.skip(1), (ProgramResult program) {
46 inputProvider.cachedSources[uri] = new Future.value(
47 "main() { print('Hello, Brave New World!'); }");
48 Future future = test.incrementalCompiler.compileUpdates(
49 {test.scriptUri: uri});
50 return future.then((String update) {
51 iframe.contentWindow.postMessage(['apply-update', update], '*');
52 134
53 return listener.expect( 135 status.append(new PreElement()..appendText(program.code));
54 ['Hello, Brave New World!', 136
55 'iframe-dart-updated-main-done']); 137 WebInputProvider inputProvider =
56 }); 138 test.incrementalCompiler.inputProvider;
57 }); 139 Uri uri = test.scriptUri.resolve('?v${version++}');
140 inputProvider.cachedSources[uri] = new Future.value(program.code);
141 Future future = test.incrementalCompiler.compileUpdates(
142 {test.scriptUri: uri});
143 return future.then((String update) {
144 iframe.contentWindow.postMessage(['apply-update', update], '*');
145
146 return listener.expect(
147 program.messagesWith('iframe-dart-updated-main-done'));
148 });
149 });
150 });
58 }); 151 });
59 }).then((_) { 152 }).then((_) {
153 status.style.color = 'limegreen';
154
60 // Remove the iframe to work around a bug in test.dart. 155 // Remove the iframe to work around a bug in test.dart.
61 iframe.remove(); 156 iframe.remove();
62 }); 157 });
63 }); 158 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698