| 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 @TestOn('!browser') | |
| 6 library usage.usage_impl_io_test; | 5 library usage.usage_impl_io_test; |
| 7 | 6 |
| 8 import 'dart:async'; | 7 import 'dart:async'; |
| 9 import 'dart:io'; | 8 import 'dart:io'; |
| 10 | 9 |
| 11 import 'package:test/test.dart'; | 10 import 'package:test/test.dart'; |
| 12 import 'package:usage/src/usage_impl_io.dart'; | 11 import 'package:usage/src/usage_impl_io.dart'; |
| 13 | 12 |
| 14 main() => defineTests(); | 13 main() => defineTests(); |
| 15 | 14 |
| 16 void defineTests() { | 15 void defineTests() { |
| 17 group('IOPostHandler', () { | 16 group('IOPostHandler', () { |
| 18 test('sendPost', () async { | 17 test('sendPost', () { |
| 19 var httpClient = new MockHttpClient(); | 18 var httpClient = new MockHttpClient(); |
| 20 IOPostHandler postHandler = new IOPostHandler(mockClient: httpClient); | 19 IOPostHandler postHandler = new IOPostHandler(mockClient: httpClient); |
| 21 Map<String, dynamic> args = {'utv': 'varName', 'utt': 123}; | 20 Map<String, dynamic> args = {'utv': 'varName', 'utt': 123}; |
| 22 await postHandler.sendPost('http://www.google.com', args); | 21 return postHandler.sendPost('http://www.google.com', args).then((_) { |
| 23 expect(httpClient.sendCount, 1); | 22 expect(httpClient.sendCount, 1); |
| 23 }); |
| 24 }); | 24 }); |
| 25 }); | 25 }); |
| 26 | 26 |
| 27 group('IOPersistentProperties', () { | 27 group('IOPersistentProperties', () { |
| 28 test('add', () { | 28 test('add', () { |
| 29 IOPersistentProperties props = new IOPersistentProperties('foo_props'); | 29 IOPersistentProperties props = new IOPersistentProperties('foo_props'); |
| 30 props['foo'] = 'bar'; | 30 props['foo'] = 'bar'; |
| 31 expect(props['foo'], 'bar'); | 31 expect(props['foo'], 'bar'); |
| 32 }); | 32 }); |
| 33 | 33 |
| 34 test('remove', () { | 34 test('remove', () { |
| 35 IOPersistentProperties props = new IOPersistentProperties('foo_props'); | 35 IOPersistentProperties props = new IOPersistentProperties('foo_props'); |
| 36 props['foo'] = 'bar'; | 36 props['foo'] = 'bar'; |
| 37 expect(props['foo'], 'bar'); | 37 expect(props['foo'], 'bar'); |
| 38 props['foo'] = null; | 38 props['foo'] = null; |
| 39 expect(props['foo'], null); | 39 expect(props['foo'], null); |
| 40 }); | 40 }); |
| 41 }); | 41 }); |
| 42 | |
| 43 group('usage_impl_io', () { | |
| 44 test('getDartVersion', () { | |
| 45 expect(getDartVersion(), isNotNull); | |
| 46 }); | |
| 47 | |
| 48 test('getPlatformLocale', () { | |
| 49 expect(getPlatformLocale(), isNotNull); | |
| 50 }); | |
| 51 }); | |
| 52 } | 42 } |
| 53 | 43 |
| 54 class MockHttpClient implements HttpClient { | 44 class MockHttpClient implements HttpClient { |
| 55 @override | |
| 56 String userAgent; | 45 String userAgent; |
| 57 int sendCount = 0; | 46 int sendCount = 0; |
| 58 int writeCount = 0; | 47 int writeCount = 0; |
| 59 bool closed = false; | 48 bool closed = false; |
| 60 | |
| 61 @override | |
| 62 Future<HttpClientRequest> postUrl(Uri url) { | 49 Future<HttpClientRequest> postUrl(Uri url) { |
| 63 return new Future.value(new MockHttpClientRequest(this)); | 50 return new Future.value(new MockHttpClientRequest(this)); |
| 64 } | 51 } |
| 65 | 52 noSuchMethod(Invocation invocation) { } |
| 66 @override | |
| 67 noSuchMethod(Invocation invocation) {} | |
| 68 } | 53 } |
| 69 | 54 |
| 70 class MockHttpClientRequest implements HttpClientRequest { | 55 class MockHttpClientRequest implements HttpClientRequest { |
| 71 final MockHttpClient client; | 56 final MockHttpClient client; |
| 72 | |
| 73 MockHttpClientRequest(this.client); | 57 MockHttpClientRequest(this.client); |
| 74 | |
| 75 @override | |
| 76 void write(Object obj) { | 58 void write(Object obj) { |
| 77 client.writeCount++; | 59 client.writeCount++; |
| 78 } | 60 } |
| 79 | |
| 80 @override | |
| 81 Future<HttpClientResponse> close() { | 61 Future<HttpClientResponse> close() { |
| 82 client.closed = true; | 62 client.closed = true; |
| 83 return new Future.value(new MockHttpClientResponse(client)); | 63 return new Future.value(new MockHttpClientResponse(client)); |
| 84 } | 64 } |
| 85 | 65 noSuchMethod(Invocation invocation) { } |
| 86 @override | |
| 87 noSuchMethod(Invocation invocation) {} | |
| 88 } | 66 } |
| 89 | 67 |
| 90 class MockHttpClientResponse implements HttpClientResponse { | 68 class MockHttpClientResponse implements HttpClientResponse { |
| 91 final MockHttpClient client; | 69 final MockHttpClient client; |
| 92 | |
| 93 MockHttpClientResponse(this.client); | 70 MockHttpClientResponse(this.client); |
| 94 | 71 Future drain([var futureValue]) { |
| 95 @override | |
| 96 Future/*<E>*/ drain/*<E>*/([/*=E*/ futureValue]) { | |
| 97 client.sendCount++; | 72 client.sendCount++; |
| 98 return new Future.value(); | 73 return new Future.value(); |
| 99 } | 74 } |
| 100 | 75 noSuchMethod(Invocation invocation) { } |
| 101 @override | |
| 102 noSuchMethod(Invocation invocation) {} | |
| 103 } | 76 } |
| OLD | NEW |