Chromium Code Reviews| Index: pkg/unittest/lib/interactive_html_config.dart |
| diff --git a/pkg/unittest/lib/interactive_html_config.dart b/pkg/unittest/lib/interactive_html_config.dart |
| index 3971a9f36cc9e352c8d843b030e8d5ab7fcae4ae..d0fc74f2f29bc82bffe1ae83f63b13caf32399be 100644 |
| --- a/pkg/unittest/lib/interactive_html_config.dart |
| +++ b/pkg/unittest/lib/interactive_html_config.dart |
| @@ -15,6 +15,7 @@ library unittest_interactive_html_config; |
| // IFrame for failed tests/keep IFrame for all tests. |
| import 'dart:html'; |
| +import 'dart:async'; |
| import 'dart:math'; |
| import 'unittest.dart'; |
| @@ -53,22 +54,23 @@ class _Message { |
| class HtmlConfiguration extends Configuration { |
| - // TODO(rnystrom): Get rid of this if we get canonical closures for methods. |
| - EventListener _onErrorClosure; |
| + StreamSubscription _errorSubscription; |
| void _installErrorHandler() { |
| - if (_onErrorClosure == null) { |
| - _onErrorClosure = |
| - (e) => handleExternalError(e, '(DOM callback has errors)'); |
| + if (_errorSubscription == null) { |
| + assert(_errorSubscription == null); |
|
gram
2013/03/12 22:44:46
This assert seems superfluous, given the if guard.
|
| + |
| // Listen for uncaught errors. |
| - window.on.error.add(_onErrorClosure); |
| + _errorSubscription = window.onError.listen((e) { |
| + handleExternalError(e, '(DOM callback has errors)'); |
| + }); |
| } |
| } |
| void _uninstallErrorHandler() { |
| - if (_onErrorClosure != null) { |
| - window.on.error.remove(_onErrorClosure); |
| - _onErrorClosure = null; |
| + if (_errorSubscription != null) { |
| + _errorSubscription.cancel(); |
| + _errorSubscription = null; |
| } |
| } |
| } |
| @@ -82,7 +84,7 @@ class HtmlConfiguration extends Configuration { |
| class ChildInteractiveHtmlConfiguration extends HtmlConfiguration { |
| /** The window to which results must be posted. */ |
| - Window parentWindow; |
| + WindowBase parentWindow; |
| /** The time at which tests start. */ |
| Map<int,DateTime> _testStarts; |
| @@ -102,7 +104,7 @@ class ChildInteractiveHtmlConfiguration extends HtmlConfiguration { |
| * window, gets the test ID from the query parameter in the |
| * IFrame URL, sets that as a solo test and starts test execution. |
| */ |
| - window.on.message.add((MessageEvent e) { |
| + window.onMessage.listen((MessageEvent e) { |
| // Get the result, do any logging, then do a pass/fail. |
| var m = new _Message.fromString(e.data); |
| if (m.messageType == _Message.START) { |
| @@ -188,11 +190,7 @@ class ParentInteractiveHtmlConfiguration extends HtmlConfiguration { |
| */ |
| bool _doneWrap = false; |
| - /** |
| - * We use this to make a single closure from _handleMessage so we |
| - * can remove the handler later. |
| - */ |
| - Function _messageHandler; |
| + StreamSubscription _messageSubscription; |
| ParentInteractiveHtmlConfiguration() : |
| _testStarts = new Map<int,DateTime>(); |
| @@ -214,7 +212,7 @@ class ParentInteractiveHtmlConfiguration extends HtmlConfiguration { |
| childDiv.nodes.add(child); |
| completeTest = expectAsync0((){ }); |
| // Kick off the test when the IFrame is loaded. |
| - child.on.load.add((e) { |
| + child.onLoad.listen((e) { |
| child.contentWindow.postMessage(_Message.text(_Message.START), '*'); |
| }); |
| }; |
| @@ -243,7 +241,6 @@ class ParentInteractiveHtmlConfiguration extends HtmlConfiguration { |
| void onInit() { |
| _installErrorHandler(); |
| - _messageHandler = _handleMessage; // We need to make just one closure. |
| document.query('#group-divs').innerHtml = ""; |
| } |
| @@ -257,7 +254,8 @@ class ParentInteractiveHtmlConfiguration extends HtmlConfiguration { |
| testCases[i].tearDown = null; |
| } |
| } |
| - window.on.message.add(_messageHandler); |
| + assert(_messageSubscription == null); |
| + _messageSubscription = window.onMessage.listen(_handleMessage); |
| } |
| static final _notAlphaNumeric = new RegExp('[^a-z0-9A-Z]'); |
| @@ -297,12 +295,12 @@ class ParentInteractiveHtmlConfiguration extends HtmlConfiguration { |
| </ul> |
| </div>"""); |
| document.query('#group-divs').nodes.add(groupDiv); |
| - groupDiv.query('.groupselect').on.click.add((e) { |
| + groupDiv.query('.groupselect').onClick.listen((e) { |
| var parent = document.query('#$groupId'); |
| InputElement cb = parent.query('.groupselect'); |
| var state = cb.checked; |
| var tests = parent.query('.tests'); |
| - for (Element t in tests.elements) { |
| + for (Element t in tests.children) { |
| cb = t.query('.testselect') as InputElement; |
| cb.checked = state; |
| var testId = int.parse(t.id.substring(_testIdPrefix.length)); |
| @@ -335,11 +333,11 @@ class ParentInteractiveHtmlConfiguration extends HtmlConfiguration { |
| </div> |
| </li>"""); |
| list.nodes.add(testItem); |
| - testItem.query('#$_selectedIdPrefix$id').on.change.add((e) { |
| + testItem.query('#$_selectedIdPrefix$id').onChange.listen((e) { |
| InputElement cb = testItem.query('#$_selectedIdPrefix$id'); |
| testCase.enabled = cb.checked; |
| }); |
| - testItem.query('.test-label').on.click.add((e) { |
| + testItem.query('.test-label').onClick.listen((e) { |
| var _testItem = document.query('#$_testIdPrefix$id'); |
| var _actions = _testItem.query('#$_actionIdPrefix$id'); |
| var _label = _testItem.query('.test-name'); |
| @@ -414,7 +412,9 @@ class ParentInteractiveHtmlConfiguration extends HtmlConfiguration { |
| } |
| void onDone(bool success) { |
| - window.on.message.remove(_messageHandler); |
| + assert(_messageSubscription != null); |
| + _messageSubscription.cancel(); |
| + _messageSubscription = null; |
| _uninstallErrorHandler(); |
| document.query('#busy').style.display = 'none'; |
| InputElement startButton = document.query('#start'); |
| @@ -440,7 +440,7 @@ void _prepareDom() { |
| "<div id='control'>" |
| "<input id='start' disabled='true' type='button' value='Run'>" |
| "</div>")); |
| - document.query('#start').on.click.add((e) { |
| + document.query('#start').onClick.listen((e) { |
| InputElement startButton = document.query('#start'); |
| startButton.disabled = true; |
| rerunTests(); |