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 library usage.hit_types_test; | 5 library usage.hit_types_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:test/test.dart'; | 9 import 'package:test/test.dart'; |
10 import 'package:usage/usage.dart'; | 10 import 'package:usage/usage.dart'; |
11 | 11 |
12 import 'src/common.dart'; | 12 import 'src/common.dart'; |
13 | 13 |
14 main() => defineTests(); | 14 main() => defineTests(); |
15 | 15 |
16 void defineTests() { | 16 void defineTests() { |
17 group('screenView', () { | 17 group('screenView', () { |
18 test('simple', () { | 18 test('simple', () { |
19 AnalyticsImplMock mock = createMock(); | 19 AnalyticsImplMock mock = createMock(); |
20 mock.sendScreenView('main'); | 20 mock.sendScreenView('main'); |
21 expect(mock.mockProperties['clientId'], isNotNull); | 21 expect(mock.mockProperties['clientId'], isNotNull); |
22 expect(mock.mockPostHandler.sentValues, isNot(isEmpty)); | 22 expect(mock.mockPostHandler.sentValues, isNot(isEmpty)); |
23 }); | 23 }); |
| 24 test('with parameters', () { |
| 25 AnalyticsImplMock mock = createMock(); |
| 26 mock.sendScreenView('withParams', parameters: {'cd1': 'foo'}); |
| 27 expect(mock.mockProperties['clientId'], isNotNull); |
| 28 expect(mock.mockPostHandler.sentValues, isNot(isEmpty)); |
| 29 has(mock.last, 'cd1'); |
| 30 }); |
24 }); | 31 }); |
25 | 32 |
26 group('event', () { | 33 group('event', () { |
27 test('simple', () { | 34 test('simple', () { |
28 AnalyticsImplMock mock = createMock(); | 35 AnalyticsImplMock mock = createMock(); |
29 mock.sendEvent('files', 'save'); | 36 mock.sendEvent('files', 'save'); |
30 expect(mock.mockPostHandler.sentValues, isNot(isEmpty)); | 37 expect(mock.mockPostHandler.sentValues, isNot(isEmpty)); |
31 was(mock.last, 'event'); | 38 was(mock.last, 'event'); |
32 has(mock.last, 'ec'); | 39 has(mock.last, 'ec'); |
33 has(mock.last, 'ea'); | 40 has(mock.last, 'ea'); |
34 }); | 41 }); |
35 | 42 |
| 43 test('with parameters', () { |
| 44 AnalyticsImplMock mock = createMock(); |
| 45 mock.sendEvent('withParams', 'save', parameters: {'cd1': 'foo'}); |
| 46 expect(mock.mockPostHandler.sentValues, isNot(isEmpty)); |
| 47 was(mock.last, 'event'); |
| 48 has(mock.last, 'ec'); |
| 49 has(mock.last, 'ea'); |
| 50 has(mock.last, 'cd1'); |
| 51 }); |
| 52 |
36 test('optional args', () { | 53 test('optional args', () { |
37 AnalyticsImplMock mock = createMock(); | 54 AnalyticsImplMock mock = createMock(); |
38 mock.sendEvent('files', 'save', label: 'File Save', value: 23); | 55 mock.sendEvent('files', 'save', label: 'File Save', value: 23); |
39 expect(mock.mockPostHandler.sentValues, isNot(isEmpty)); | 56 expect(mock.mockPostHandler.sentValues, isNot(isEmpty)); |
40 was(mock.last, 'event'); | 57 was(mock.last, 'event'); |
41 has(mock.last, 'ec'); | 58 has(mock.last, 'ec'); |
42 has(mock.last, 'ea'); | 59 has(mock.last, 'ea'); |
43 has(mock.last, 'el'); | 60 has(mock.last, 'el'); |
44 has(mock.last, 'ev'); | 61 has(mock.last, 'ev'); |
45 }); | 62 }); |
(...skipping 25 matching lines...) Expand all Loading... |
71 AnalyticsImplMock mock = createMock(); | 88 AnalyticsImplMock mock = createMock(); |
72 mock.sendTiming('compile', 123, category: 'Build', label: 'Compile'); | 89 mock.sendTiming('compile', 123, category: 'Build', label: 'Compile'); |
73 expect(mock.mockPostHandler.sentValues, isNot(isEmpty)); | 90 expect(mock.mockPostHandler.sentValues, isNot(isEmpty)); |
74 was(mock.last, 'timing'); | 91 was(mock.last, 'timing'); |
75 has(mock.last, 'utv'); | 92 has(mock.last, 'utv'); |
76 has(mock.last, 'utt'); | 93 has(mock.last, 'utt'); |
77 has(mock.last, 'utc'); | 94 has(mock.last, 'utc'); |
78 has(mock.last, 'utl'); | 95 has(mock.last, 'utl'); |
79 }); | 96 }); |
80 | 97 |
81 test('timer', () { | 98 test('timer', () async { |
82 AnalyticsImplMock mock = createMock(); | 99 AnalyticsImplMock mock = createMock(); |
83 AnalyticsTimer timer = | 100 AnalyticsTimer timer = |
84 mock.startTimer('compile', category: 'Build', label: 'Compile'); | 101 mock.startTimer('compile', category: 'Build', label: 'Compile'); |
85 | 102 |
86 return new Future.delayed(new Duration(milliseconds: 20), () { | 103 await new Future.delayed(new Duration(milliseconds: 20)); |
87 return timer.finish().then((_) { | 104 |
88 expect(mock.mockPostHandler.sentValues, isNot(isEmpty)); | 105 await timer.finish(); |
89 was(mock.last, 'timing'); | 106 expect(mock.mockPostHandler.sentValues, isNot(isEmpty)); |
90 has(mock.last, 'utv'); | 107 was(mock.last, 'timing'); |
91 has(mock.last, 'utt'); | 108 has(mock.last, 'utv'); |
92 has(mock.last, 'utc'); | 109 has(mock.last, 'utt'); |
93 has(mock.last, 'utl'); | 110 has(mock.last, 'utc'); |
94 int time = timer.currentElapsedMillis; | 111 has(mock.last, 'utl'); |
95 expect(time, greaterThan(10)); | 112 int time = timer.currentElapsedMillis; |
96 return new Future.delayed(new Duration(milliseconds: 10), () { | 113 expect(time, greaterThan(10)); |
97 expect(timer.currentElapsedMillis, time); | 114 |
98 }); | 115 await new Future.delayed(new Duration(milliseconds: 10)); |
99 }); | 116 expect(timer.currentElapsedMillis, time); |
100 }); | |
101 }); | 117 }); |
102 }); | 118 }); |
103 | 119 |
104 group('exception', () { | 120 group('exception', () { |
105 test('simple', () { | 121 test('simple', () { |
106 AnalyticsImplMock mock = createMock(); | 122 AnalyticsImplMock mock = createMock(); |
107 mock.sendException('FooException'); | 123 mock.sendException('FooException'); |
108 expect(mock.mockPostHandler.sentValues, isNot(isEmpty)); | 124 expect(mock.mockPostHandler.sentValues, isNot(isEmpty)); |
109 was(mock.last, 'exception'); | 125 was(mock.last, 'exception'); |
110 has(mock.last, 'exd'); | 126 has(mock.last, 'exd'); |
111 }); | 127 }); |
112 | 128 |
113 test('optional args', () { | 129 test('optional args', () { |
114 AnalyticsImplMock mock = createMock(); | 130 AnalyticsImplMock mock = createMock(); |
115 mock.sendException('FooException', fatal: true); | 131 mock.sendException('FooException', fatal: true); |
116 expect(mock.mockPostHandler.sentValues, isNot(isEmpty)); | 132 expect(mock.mockPostHandler.sentValues, isNot(isEmpty)); |
117 was(mock.last, 'exception'); | 133 was(mock.last, 'exception'); |
118 has(mock.last, 'exd'); | 134 has(mock.last, 'exd'); |
119 has(mock.last, 'exf'); | 135 has(mock.last, 'exf'); |
120 }); | 136 }); |
121 | 137 |
122 test('exception file paths', () { | 138 test('exception file paths', () { |
123 AnalyticsImplMock mock = createMock(); | 139 AnalyticsImplMock mock = createMock(); |
124 mock.sendException('foo bar (file:///Users/foobar/tmp/error.dart:3:13)'); | 140 mock.sendException('foo bar (file:///Users/foobar/tmp/error.dart:3:13)'); |
125 expect(mock.last['exd'], 'foo bar ('); | 141 expect(mock.last['exd'], 'foo bar ('); |
126 }); | 142 }); |
127 | |
128 test('long description trimmed', () { | |
129 String str = '0123456789abcdefghijklmnopqrstuvwxyz'; | |
130 AnalyticsImplMock mock = createMock(); | |
131 mock.sendException(str + str + str + str + str); | |
132 expect(mock.last['exd'].length, 100); | |
133 }); | |
134 }); | 143 }); |
135 } | 144 } |
OLD | NEW |