Chromium Code Reviews| 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 // SharedOptions=--package-root=sdk/lib/_internal/ | 5 // SharedOptions=--package-root=sdk/lib/_internal/ |
| 6 | 6 |
| 7 library trydart.paste_test; | 7 library trydart.paste_test; |
| 8 | 8 |
| 9 import 'dart:html'; | 9 import 'dart:html'; |
| 10 import 'dart:async'; | 10 import 'dart:async'; |
| 11 | 11 |
| 12 import '../../site/try/src/interaction_manager.dart' show | 12 import '../../site/try/src/interaction_manager.dart' show |
| 13 InteractionManager; | 13 InteractionManager; |
| 14 | 14 |
| 15 import '../../site/try/src/ui.dart' show | 15 import '../../site/try/src/ui.dart' show |
| 16 mainEditorPane, | 16 mainEditorPane, |
| 17 observer; | 17 observer; |
| 18 | 18 |
| 19 import '../../site/try/src/user_option.dart' show | 19 import '../../site/try/src/user_option.dart' show |
| 20 UserOption; | 20 UserOption; |
| 21 | 21 |
| 22 import '../../pkg/expect/lib/expect.dart'; | 22 import '../../pkg/expect/lib/expect.dart'; |
| 23 import '../../pkg/async_helper/lib/async_helper.dart'; | 23 import '../../pkg/async_helper/lib/async_helper.dart'; |
| 24 | 24 |
| 25 main() { | 25 const Map<String, String> tests = const <String, String> { |
| 26 '<span><p>//...</p>}</span>': '//...\n}\n', | |
| 27 'someText': 'someText\n', | |
| 28 '"\$"': '"\$"<DIAGNOSTIC>\n', | |
| 29 '"\$\$"': '"\$\$<DIAGNOSTIC>"<DIAGNOSTIC>\n', | |
| 30 '"\$\$4"': '"\$\$<DIAGNOSTIC>4<DIAGNOSTIC>"\n', | |
| 31 '"\$\$4 "': '"\$\$<DIAGNOSTIC>4<DIAGNOSTIC> "\n', | |
| 32 }; | |
| 33 | |
| 34 List<Node> queryDiagnosticNodes() { | |
| 35 return mainEditorPane.querySelectorAll('a.diagnostic>span'); | |
| 36 } | |
| 37 | |
| 38 Future runTests() { | |
| 39 Iterator<String> keys = tests.keys.iterator; | |
| 40 keys.moveNext(); | |
| 41 mainEditorPane.innerHtml = keys.current; | |
| 42 | |
| 43 Future makeFuture() => new Future(() { | |
| 44 String key = keys.current; | |
| 45 print('Checking $key'); | |
| 46 queryDiagnosticNodes().forEach((Node node) { | |
| 47 node.replaceWith(new Text('<DIAGNOSTIC>')); | |
| 48 observer.takeRecords(); // Discard mutations. | |
| 49 }); | |
| 50 Expect.stringEquals(tests[key], mainEditorPane.text); | |
| 51 if (keys.moveNext()) { | |
| 52 key = keys.current; | |
| 53 print('Setting $key'); | |
| 54 mainEditorPane.innerHtml = key; | |
| 55 return makeFuture(); | |
| 56 } else { | |
| 57 // Clear the DOM to work around a bug in test.dart. | |
| 58 document.body.nodes.clear(); | |
| 59 return null; | |
| 60 } | |
| 61 }); | |
| 62 | |
| 63 return makeFuture(); | |
| 64 } | |
| 65 | |
| 66 void main() { | |
| 26 UserOption.storage = {}; | 67 UserOption.storage = {}; |
| 27 | 68 |
| 28 var interaction = new InteractionManager(); | 69 var interaction = new InteractionManager(); |
| 29 mainEditorPane = new DivElement(); | 70 mainEditorPane = new DivElement(); |
| 30 document.body.append(mainEditorPane); | 71 document.body.append(mainEditorPane); |
| 31 observer = new MutationObserver(interaction.onMutation) | 72 observer = new MutationObserver(interaction.onMutation) |
| 32 ..observe(mainEditorPane, childList: true, characterData: true, subtree: t rue); | 73 ..observe( |
| 74 mainEditorPane, childList: true, characterData: true, subtree: true); | |
|
ahe
2014/03/26 12:45:05
You missed this long line :-)
| |
| 33 | 75 |
| 34 mainEditorPane.innerHtml = "<span><p>//...</p>}</span>"; | 76 mainEditorPane.innerHtml = "<span><p>//...</p>}</span>"; |
| 35 | 77 |
| 36 asyncTest(() => new Future(() { | 78 asyncTest(runTests); |
| 37 print('Welcome to the future'); | |
| 38 Expect.stringEquals('//...\n}\n', mainEditorPane.text); | |
| 39 }).then((_) { | |
| 40 mainEditorPane.innerHtml = 'someText'; | |
| 41 return new Future(() { | |
| 42 Expect.stringEquals('someText\n', mainEditorPane.text); | |
| 43 | |
| 44 // Clear the DOM to work around a bug in test.dart. | |
| 45 document.body.nodes.clear(); | |
| 46 }); | |
| 47 })); | |
| 48 } | 79 } |
| OLD | NEW |