Chromium Code Reviews| Index: dart/tests/try/web/incremental_compilation_update_test.dart |
| diff --git a/dart/tests/try/web/incremental_compilation_update_test.dart b/dart/tests/try/web/incremental_compilation_update_test.dart |
| index 4c043edf50932007aaaaaf678e527121b178325d..b004c7c1ecf51b1f45564f0362b2624f40e9d1d4 100644 |
| --- a/dart/tests/try/web/incremental_compilation_update_test.dart |
| +++ b/dart/tests/try/web/incremental_compilation_update_test.dart |
| @@ -20,44 +20,139 @@ import 'web_compiler_test_case.dart' show |
| WebCompilerTestCase, |
| WebInputProvider; |
| -void main() => asyncTest(() { |
| +import 'program_result.dart'; |
| + |
| +const List<List<ProgramResult>> tests = const <List<ProgramResult>>[ |
| + // Basic hello-world test. |
| + const <ProgramResult>[ |
| + const ProgramResult( |
| + "main() { print('Hello, World!'); }", |
| + const <String> ['Hello, World!']), |
| + const ProgramResult( |
| + "main() { print('Hello, Brave New World!'); }", |
| + const <String> ['Hello, Brave New World!']), |
| + ], |
| + |
| + // Test that the test framework handles more than one update. |
| + const <ProgramResult>[ |
| + const ProgramResult( |
| + "main() { print('Hello darkness, my old friend'); }", |
| + const <String> ['Hello darkness, my old friend']), |
| + const ProgramResult( |
| + "main() { print('I\\'ve come to talk with you again'); }", |
| + const <String> ['I\'ve come to talk with you again']), |
| + const ProgramResult( |
| + "main() { print('Because a vision softly creeping'); }", |
| + const <String> ['Because a vision softly creeping']), |
| + ], |
| + |
| + // Test that that isolate support works. |
| + const <ProgramResult>[ |
| + const ProgramResult( |
| + "main(arguments) { print('Hello, Isolated World!'); }", |
| + const <String> ['Hello, Isolated World!']), |
| + const ProgramResult( |
| + "main(arguments) { print(arguments); }", |
| + const <String> ['[]']), |
| + ], |
| + |
| + // 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.
|
| + const <ProgramResult>[ |
| + const ProgramResult( |
| + r""" |
| +var closure; |
| + |
| +foo(a, [b = 'b']) { |
| + print('$a $b'); |
| +} |
| + |
| +main() { |
| + if (closure == null) { |
| + print('[closure] is null.'); |
| + closure = foo; |
| + } |
| + closure('a'); |
| + closure('a', 'c'); |
| +} |
| +""", |
| + const <String> ['[closure] is null.', 'a b', 'a c']), |
| + const ProgramResult( |
| + r""" |
| +var closure; |
| + |
| +foo(a, [b = 'b']) { |
| + print('$b $a'); |
| +} |
| + |
| +main() { |
| + if (closure == null) { |
| + print('[closure] is null.'); |
| + closure = foo; |
| + } |
| + closure('a'); |
| + closure('a', 'c'); |
| +} |
| +""", |
| + const <String> ['b a', 'c a']), |
| + ], |
| +]; |
| + |
| + |
| +void main() { |
| listener.start(); |
| + return asyncTest(() => Future.forEach(tests, compileAndRun)); |
| +} |
| + |
| +Future compileAndRun(List<ProgramResult> programs) { |
| + var status = new DivElement(); |
| + document.body.append(status); |
| + |
| IFrameElement iframe = |
| appendIFrame( |
| '/root_dart/tests/try/web/incremental_compilation_update.html', |
| document.body) |
| - ..style.width = '90vw' |
| - ..style.height = '90vh'; |
| + ..style.width = '100%' |
| + ..style.height = '600px'; |
| return listener.expect('iframe-ready').then((_) { |
| - WebCompilerTestCase test = |
| - new WebCompilerTestCase("main() { print('Hello, World!'); }"); |
| + ProgramResult program = programs.first; |
| + status.append(new PreElement()..appendText(program.code)); |
| + status.style.color = 'orange'; |
| + WebCompilerTestCase test = new WebCompilerTestCase(program.code); |
| return test.run().then((String jsCode) { |
| - var objectUrl = |
| - Url.createObjectUrl(new Blob([jsCode], 'application/javascript')); |
| - |
| - iframe.contentWindow.postMessage(['add-script', objectUrl], '*'); |
| - return listener.expect(['Hello, World!', 'iframe-dart-main-done']).then( |
| - (_) { |
| - WebInputProvider inputProvider = |
| - test.incrementalCompiler.inputProvider; |
| - Uri uri = test.scriptUri.resolve('?v2'); |
| - inputProvider.cachedSources[uri] = new Future.value( |
| - "main() { print('Hello, Brave New World!'); }"); |
| - Future future = test.incrementalCompiler.compileUpdates( |
| - {test.scriptUri: uri}); |
| - return future.then((String update) { |
| - iframe.contentWindow.postMessage(['apply-update', update], '*'); |
| - |
| - return listener.expect( |
| - ['Hello, Brave New World!', |
| - 'iframe-dart-updated-main-done']); |
| - }); |
| - }); |
| + status.style.color = 'red'; |
| + var objectUrl = |
| + Url.createObjectUrl(new Blob([jsCode], 'application/javascript')); |
| + |
| + iframe.contentWindow.postMessage(['add-script', objectUrl], '*'); |
| + Future future = |
| + listener.expect(program.messagesWith('iframe-dart-main-done')); |
| + return future.then((_) { |
| + int version = 2; |
| + return Future.forEach(programs.skip(1), (ProgramResult program) { |
| + |
| + status.append(new PreElement()..appendText(program.code)); |
| + |
| + WebInputProvider inputProvider = |
| + test.incrementalCompiler.inputProvider; |
| + Uri uri = test.scriptUri.resolve('?v${version++}'); |
| + inputProvider.cachedSources[uri] = new Future.value(program.code); |
| + Future future = test.incrementalCompiler.compileUpdates( |
| + {test.scriptUri: uri}); |
| + return future.then((String update) { |
| + iframe.contentWindow.postMessage(['apply-update', update], '*'); |
| + |
| + return listener.expect( |
| + program.messagesWith('iframe-dart-updated-main-done')); |
| + }); |
| + }); |
| + }); |
| }); |
| }).then((_) { |
| + status.style.color = 'limegreen'; |
| + |
| // Remove the iframe to work around a bug in test.dart. |
| iframe.remove(); |
| }); |
| -}); |
| +} |