Devon Carew | 26ceabe | 2014-12-11 11:44:53 -0800 | [diff] [blame] | 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 |
| 3 | // BSD-style license that can be found in the LICENSE file. |
| 4 | |
| 5 | library usage.impl_test; |
| 6 | |
| 7 | import 'package:unittest/unittest.dart'; |
| 8 | import 'package:usage/src/usage_impl.dart'; |
Devon Carew | e328cc2 | 2014-12-18 13:10:45 -0800 | [diff] [blame] | 9 | |
| 10 | import 'src/common.dart'; |
Devon Carew | 26ceabe | 2014-12-11 11:44:53 -0800 | [diff] [blame] | 11 | |
| 12 | void defineTests() { |
| 13 | group('ThrottlingBucket', () { |
| 14 | test('can send', () { |
| 15 | ThrottlingBucket bucket = new ThrottlingBucket(20); |
| 16 | expect(bucket.removeDrop(), true); |
| 17 | }); |
| 18 | |
| 19 | test('doesn\'t send too many', () { |
| 20 | ThrottlingBucket bucket = new ThrottlingBucket(20); |
| 21 | for (int i = 0; i < 20; i++) { |
| 22 | expect(bucket.removeDrop(), true); |
| 23 | } |
| 24 | expect(bucket.removeDrop(), false); |
| 25 | }); |
| 26 | }); |
| 27 | |
Devon Carew | e328cc2 | 2014-12-18 13:10:45 -0800 | [diff] [blame] | 28 | group('AnalyticsImpl', () { |
| 29 | test('respects disabled', () { |
| 30 | AnalyticsImplMock mock = createMock(); |
| 31 | mock.optIn = false; |
| 32 | mock.sendException('FooBar exception'); |
| 33 | expect(mock.optIn, false); |
| 34 | expect(mock.mockPostHandler.sentValues, isEmpty); |
| 35 | }); |
| 36 | |
| 37 | test('hasSetOptIn', () { |
| 38 | AnalyticsImplMock mock = createMock(setOptIn: false); |
| 39 | expect(mock.hasSetOptIn, false); |
| 40 | mock.optIn = false; |
| 41 | expect(mock.hasSetOptIn, true); |
| 42 | }); |
| 43 | |
| 44 | test('setSessionValue', () { |
| 45 | AnalyticsImplMock mock = createMock(); |
| 46 | mock.sendScreenView('foo'); |
| 47 | hasnt(mock.last, 'val'); |
| 48 | mock.setSessionValue('val', 'ue'); |
| 49 | mock.sendScreenView('bar'); |
| 50 | has(mock.last, 'val'); |
Devon Carew | 9243d31 | 2014-12-18 13:20:20 -0800 | [diff] [blame^] | 51 | mock.setSessionValue('val', null); |
| 52 | mock.sendScreenView('baz'); |
| 53 | hasnt(mock.last, 'val'); |
Devon Carew | e328cc2 | 2014-12-18 13:10:45 -0800 | [diff] [blame] | 54 | }); |
| 55 | }); |
| 56 | |
Devon Carew | 26ceabe | 2014-12-11 11:44:53 -0800 | [diff] [blame] | 57 | group('sanitizeFilePaths', () { |
| 58 | test('replace file', () { |
| 59 | expect(sanitizeFilePaths( |
| 60 | '(file:///Users/foo/tmp/error.dart:3:13)'), |
| 61 | '(error.dart:3:13)'); |
| 62 | }); |
| 63 | |
| 64 | test('replace files', () { |
| 65 | expect(sanitizeFilePaths( |
| 66 | 'foo (file:///Users/foo/tmp/error.dart:3:13)\n' |
| 67 | 'bar (file:///Users/foo/tmp/error.dart:3:13)'), |
| 68 | 'foo (error.dart:3:13)\nbar (error.dart:3:13)'); |
| 69 | }); |
| 70 | }); |
| 71 | |
Devon Carew | e328cc2 | 2014-12-18 13:10:45 -0800 | [diff] [blame] | 72 | group('postEncode', () { |
| 73 | test('simple', () { |
| 74 | Map map = {'foo': 'bar', 'baz': 'qux norf'}; |
| 75 | expect(postEncode(map), 'foo=bar&baz=qux%20norf'); |
Devon Carew | 26ceabe | 2014-12-11 11:44:53 -0800 | [diff] [blame] | 76 | }); |
| 77 | }); |
| 78 | } |