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.impl_test; | 5 library usage.impl_test; |
6 | 6 |
7 import 'package:test/test.dart'; | 7 import 'package:test/test.dart'; |
8 import 'package:usage/src/usage_impl.dart'; | 8 import 'package:usage/src/usage_impl.dart'; |
9 | 9 |
10 import 'src/common.dart'; | 10 import 'src/common.dart'; |
(...skipping 10 matching lines...) Expand all Loading... |
21 test('doesn\'t send too many', () { | 21 test('doesn\'t send too many', () { |
22 ThrottlingBucket bucket = new ThrottlingBucket(20); | 22 ThrottlingBucket bucket = new ThrottlingBucket(20); |
23 for (int i = 0; i < 20; i++) { | 23 for (int i = 0; i < 20; i++) { |
24 expect(bucket.removeDrop(), true); | 24 expect(bucket.removeDrop(), true); |
25 } | 25 } |
26 expect(bucket.removeDrop(), false); | 26 expect(bucket.removeDrop(), false); |
27 }); | 27 }); |
28 }); | 28 }); |
29 | 29 |
30 group('AnalyticsImpl', () { | 30 group('AnalyticsImpl', () { |
| 31 test('trackingId', () { |
| 32 AnalyticsImplMock mock = createMock(); |
| 33 expect(mock.trackingId, isNotNull); |
| 34 }); |
| 35 |
| 36 test('applicationName', () { |
| 37 AnalyticsImplMock mock = createMock(); |
| 38 expect(mock.applicationName, isNotNull); |
| 39 }); |
| 40 |
| 41 test('applicationVersion', () { |
| 42 AnalyticsImplMock mock = createMock(); |
| 43 expect(mock.applicationVersion, isNotNull); |
| 44 }); |
| 45 |
31 test('respects disabled', () { | 46 test('respects disabled', () { |
32 AnalyticsImplMock mock = createMock(); | 47 AnalyticsImplMock mock = createMock(); |
33 mock.optIn = false; | 48 mock.enabled = false; |
34 mock.sendException('FooBar exception'); | 49 mock.sendException('FooBar exception'); |
35 expect(mock.optIn, false); | 50 expect(mock.enabled, false); |
36 expect(mock.mockPostHandler.sentValues, isEmpty); | 51 expect(mock.mockPostHandler.sentValues, isEmpty); |
37 }); | 52 }); |
38 | 53 |
39 test('hasSetOptIn', () { | 54 test('firstRun', () { |
40 AnalyticsImplMock mock = createMock(setOptIn: false); | 55 AnalyticsImplMock mock = createMock(); |
41 expect(mock.hasSetOptIn, false); | 56 expect(mock.firstRun, true); |
42 mock.optIn = false; | 57 mock = createMock(props: {'firstRun': false}); |
43 expect(mock.hasSetOptIn, true); | 58 expect(mock.firstRun, false); |
44 }); | 59 }); |
45 | 60 |
46 test('setSessionValue', () { | 61 test('setSessionValue', () { |
47 AnalyticsImplMock mock = createMock(); | 62 AnalyticsImplMock mock = createMock(); |
48 mock.sendScreenView('foo'); | 63 mock.sendScreenView('foo'); |
49 hasnt(mock.last, 'val'); | 64 hasnt(mock.last, 'val'); |
50 mock.setSessionValue('val', 'ue'); | 65 mock.setSessionValue('val', 'ue'); |
51 mock.sendScreenView('bar'); | 66 mock.sendScreenView('bar'); |
52 has(mock.last, 'val'); | 67 has(mock.last, 'val'); |
53 mock.setSessionValue('val', null); | 68 mock.setSessionValue('val', null); |
54 mock.sendScreenView('baz'); | 69 mock.sendScreenView('baz'); |
55 hasnt(mock.last, 'val'); | 70 hasnt(mock.last, 'val'); |
56 }); | 71 }); |
57 | 72 |
58 test('waitForLastPing', () { | 73 test('waitForLastPing', () { |
59 AnalyticsImplMock mock = createMock(); | 74 AnalyticsImplMock mock = createMock(); |
60 mock.sendScreenView('foo'); | 75 mock.sendScreenView('foo'); |
61 mock.sendScreenView('bar'); | 76 mock.sendScreenView('bar'); |
62 mock.sendScreenView('baz'); | 77 mock.sendScreenView('baz'); |
63 return mock.waitForLastPing(timeout: new Duration(milliseconds: 100)); | 78 return mock.waitForLastPing(timeout: new Duration(milliseconds: 100)); |
64 }); | 79 }); |
| 80 |
| 81 group('clientId', () { |
| 82 test('is available immediately', () { |
| 83 AnalyticsImplMock mock = createMock(); |
| 84 expect(mock.clientId, isNotEmpty); |
| 85 }); |
| 86 |
| 87 test('is memoized', () { |
| 88 AnalyticsImplMock mock = createMock(); |
| 89 final value1 = mock.clientId; |
| 90 final value2 = mock.clientId; |
| 91 expect(value1, isNotEmpty); |
| 92 expect(value1, value2); |
| 93 }); |
| 94 |
| 95 test('is stored in properties', () { |
| 96 AnalyticsImplMock mock = createMock(); |
| 97 expect(mock.properties['clientId'], isNull); |
| 98 final value = mock.clientId; |
| 99 expect(mock.properties['clientId'], value); |
| 100 }); |
| 101 }); |
65 }); | 102 }); |
66 | 103 |
67 group('postEncode', () { | 104 group('postEncode', () { |
68 test('simple', () { | 105 test('simple', () { |
69 Map<String, dynamic> map = {'foo': 'bar', 'baz': 'qux norf'}; | 106 Map<String, dynamic> map = {'foo': 'bar', 'baz': 'qux norf'}; |
70 expect(postEncode(map), 'foo=bar&baz=qux%20norf'); | 107 expect(postEncode(map), 'foo=bar&baz=qux%20norf'); |
71 }); | 108 }); |
72 }); | 109 }); |
73 } | 110 } |
OLD | NEW |