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