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