@@ -7,7 +7,6 @@ library developer_events_test;
7
7
8
8
import 'dart:developer'
9
9
show postEvent, registerExtension, ServiceExtensionResponse;
10
- import 'dart:convert' ;
11
10
12
11
import 'package:js/js.dart' ;
13
12
import 'package:expect/expect.dart' ;
@@ -50,69 +49,17 @@ class _TestDebugEvent {
50
49
}
51
50
52
51
void main () {
53
- testBackwardsCompatibility ();
54
- testWarningMessages ();
52
+ testRegisterExtensionWarningMessage ();
55
53
testPostEvent ();
56
54
testRegisterExtension ();
57
55
}
58
56
59
- /// Verify backwards compatibility for sending messages on the console.debug log
60
- /// in the chrome browser when the hooks have not been set.
61
- // TODO(nshahan) Remove testing of debug log after package:dwds removes support.
62
- // https://github.com/dart-lang/webdev/issues/1342`
63
- void testBackwardsCompatibility () {
64
- var consoleDebugLog = < List > [];
65
- var savedConsoleDebug = consoleDebug;
66
- var savedDwdsVersion = dwdsVersion;
67
-
68
- try {
69
- // Patch our own console.debug function for testing.
70
- consoleDebug = allowInterop ((arg1, [arg2, arg3]) => consoleDebugLog.add ([
71
- arg1,
72
- if (arg2 != null ) arg2,
73
- if (arg3 != null ) arg3,
74
- ]));
75
- // Provide a version to signal there is an attached debugger.
76
- dwdsVersion = '1.0.0-for-test' ;
77
-
78
- // All post and register events should go to the console debug log.
79
- var data0 = {'key0' : 'value0' };
80
- postEvent ('kind0' , data0);
81
-
82
- expect (consoleDebugLog.single[0 ], 'dart.developer.postEvent' );
83
- expect (consoleDebugLog.single[1 ], 'kind0' );
84
- Expect .contains ('"key0":"value0"' , consoleDebugLog.single[2 ]);
85
-
86
- var testHandler = (String s, Map <String , String > m) async =>
87
- ServiceExtensionResponse .result ('test result' );
88
-
89
- registerExtension ('ext.method0' , testHandler);
90
- expect (consoleDebugLog.length, 2 );
91
- expect (consoleDebugLog[1 ].first, 'dart.developer.registerExtension' );
92
- expect (consoleDebugLog[1 ].last, 'ext.method0' );
93
-
94
- var data1 = {'key1' : 'value1' };
95
- postEvent ('kind1' , data1);
96
-
97
- expect (consoleDebugLog.length, 3 );
98
- expect (consoleDebugLog[2 ][0 ], 'dart.developer.postEvent' );
99
- expect (consoleDebugLog[2 ][1 ], 'kind1' );
100
- Expect .contains ('"key1":"value1"' , consoleDebugLog[2 ][2 ]);
101
-
102
- registerExtension ('ext.method1' , testHandler);
103
- expect (consoleDebugLog.length, 4 );
104
- expect (consoleDebugLog[3 ].first, 'dart.developer.registerExtension' );
105
- expect (consoleDebugLog[3 ].last, 'ext.method1' );
106
- } finally {
107
- // Restore actual console.debug function.
108
- consoleDebug = savedConsoleDebug;
109
- dwdsVersion = savedDwdsVersion;
110
- }
111
- }
112
-
113
- /// Verify that warning messages are printed on the first call of postEvent()
114
- /// and registerExtension() when the hooks are undefined.
115
- void testWarningMessages () {
57
+ /// Verify that warning messages are printed on the first call of
58
+ /// `registerExtension()` when the hooks are undefined.
59
+ ///
60
+ /// Calls to `postEvent()` are always a no-op when no extension has been
61
+ /// registered to listen which can never happen if the hook is undefined.
62
+ void testRegisterExtensionWarningMessage () {
116
63
final consoleWarnLog = < String > [];
117
64
var savedConsoleWarn = consoleWarn;
118
65
try {
@@ -130,8 +77,9 @@ void testWarningMessages() {
130
77
var data1 = {'key1' : 'value1' };
131
78
postEvent ('kind1' , data1);
132
79
133
- // No warnings should be issued because postEvent is a no-op.
134
- expect (consoleWarnLog.length, 0 );
80
+ // No warnings should be issued because postEvent is a no-op when no
81
+ // extensions have been registered to listen.
82
+ expect (consoleWarnLog.isEmpty, true );
135
83
136
84
consoleWarnLog.clear ();
137
85
@@ -154,6 +102,15 @@ void testWarningMessages() {
154
102
155
103
// A warning is only issued on the first call of `registerExtension()`.
156
104
expect (consoleWarnLog.length, 1 );
105
+
106
+ consoleWarnLog.clear ();
107
+
108
+ // The earlier call to registerExtension() was a no-op and printed a warning
109
+ // because no debugger hooks are defined. This means more calls to
110
+ // `postEvent()` are still no ops.
111
+ postEvent ('kind0' , data0);
112
+ postEvent ('kind1' , data1);
113
+ expect (consoleWarnLog.isEmpty, true );
157
114
} finally {
158
115
// Restore actual console.warn function.
159
116
consoleWarn = savedConsoleWarn;
0 commit comments