| 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 @TestOn("browser") |
| 6 library usage.web_test; | 6 library usage.web_test; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:html'; | |
| 10 | 9 |
| 11 import 'package:test/test.dart'; | 10 import 'package:test/test.dart'; |
| 12 import 'package:usage/src/usage_impl_html.dart'; | 11 import 'package:usage/src/usage_impl_html.dart'; |
| 13 | 12 |
| 14 import 'hit_types_test.dart' as hit_types_test; | 13 import 'hit_types_test.dart' as hit_types_test; |
| 15 import 'usage_impl_test.dart' as usage_impl_test; | 14 import 'usage_impl_test.dart' as usage_impl_test; |
| 16 import 'usage_test.dart' as usage_test; | 15 import 'usage_test.dart' as usage_test; |
| 17 import 'uuid_test.dart' as uuid_test; | 16 import 'uuid_test.dart' as uuid_test; |
| 18 | 17 |
| 19 void main() { | 18 void main() { |
| 20 // Define the tests. | 19 // Define the tests. |
| 21 hit_types_test.defineTests(); | 20 hit_types_test.defineTests(); |
| 22 usage_test.defineTests(); | 21 usage_test.defineTests(); |
| 23 usage_impl_test.defineTests(); | 22 usage_impl_test.defineTests(); |
| 24 uuid_test.defineTests(); | 23 uuid_test.defineTests(); |
| 25 | 24 |
| 26 // Define some web specific tests. | 25 // Define some web specfic tests. |
| 27 defineWebTests(); | 26 defineWebTests(); |
| 28 } | 27 } |
| 29 | 28 |
| 30 void defineWebTests() { | 29 void defineWebTests() { |
| 31 group('HtmlPostHandler', () { | 30 group('HtmlPostHandler', () { |
| 32 test('sendPost', () async { | 31 test('sendPost', () { |
| 33 MockRequestor client = new MockRequestor(); | 32 MockRequestor client = new MockRequestor(); |
| 34 HtmlPostHandler postHandler = | 33 HtmlPostHandler postHandler = new HtmlPostHandler( |
| 35 new HtmlPostHandler(mockRequestor: client.request); | 34 mockRequestor: client.request); |
| 36 Map<String, dynamic> args = {'utv': 'varName', 'utt': 123}; | 35 Map<String, dynamic> args = {'utv': 'varName', 'utt': 123}; |
| 37 | 36 return postHandler.sendPost('http://www.google.com', args).then((_) { |
| 38 await postHandler.sendPost('http://www.google.com', args); | 37 expect(client.sendCount, 1); |
| 39 expect(client.sendCount, 1); | 38 }); |
| 40 }); | 39 }); |
| 41 }); | 40 }); |
| 42 | 41 |
| 43 group('HtmlPersistentProperties', () { | 42 group('HtmlPersistentProperties', () { |
| 44 test('add', () { | 43 test('add', () { |
| 45 HtmlPersistentProperties props = | 44 HtmlPersistentProperties props = new HtmlPersistentProperties('foo_props')
; |
| 46 new HtmlPersistentProperties('foo_props'); | |
| 47 props['foo'] = 'bar'; | 45 props['foo'] = 'bar'; |
| 48 expect(props['foo'], 'bar'); | 46 expect(props['foo'], 'bar'); |
| 49 }); | 47 }); |
| 50 | 48 |
| 51 test('remove', () { | 49 test('remove', () { |
| 52 HtmlPersistentProperties props = | 50 HtmlPersistentProperties props = new HtmlPersistentProperties('foo_props')
; |
| 53 new HtmlPersistentProperties('foo_props'); | |
| 54 props['foo'] = 'bar'; | 51 props['foo'] = 'bar'; |
| 55 expect(props['foo'], 'bar'); | 52 expect(props['foo'], 'bar'); |
| 56 props['foo'] = null; | 53 props['foo'] = null; |
| 57 expect(props['foo'], null); | 54 expect(props['foo'], null); |
| 58 }); | 55 }); |
| 59 }); | 56 }); |
| 60 } | 57 } |
| 61 | 58 |
| 62 class MockRequestor { | 59 class MockRequestor { |
| 63 int sendCount = 0; | 60 int sendCount = 0; |
| 64 | 61 |
| 65 Future<HttpRequest> request(String url, {String method, sendData}) { | 62 Future request(String url, {String method, String sendData}) { |
| 66 expect(url, isNotEmpty); | 63 expect(url, isNotEmpty); |
| 67 expect(method, isNotEmpty); | 64 expect(method, isNotEmpty); |
| 68 expect(sendData, isNotEmpty); | 65 expect(sendData, isNotEmpty); |
| 69 | 66 |
| 70 sendCount++; | 67 sendCount++; |
| 71 return new Future.value(); | 68 return new Future.value(); |
| 72 } | 69 } |
| 73 } | 70 } |
| OLD | NEW |