OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library interactive_test; | 5 library interactive_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:html'; | 8 import 'dart:html'; |
9 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
10 import 'package:unittest/html_individual_config.dart'; | 10 import 'package:unittest/html_individual_config.dart'; |
11 import 'utils.dart'; | 11 import 'utils.dart'; |
12 | 12 |
13 | |
14 main() { | 13 main() { |
15 useHtmlIndividualConfiguration(); | 14 useHtmlIndividualConfiguration(); |
16 | 15 |
17 group('Geolocation', () { | 16 group('Geolocation', () { |
18 test('getCurrentPosition', () { | 17 test('getCurrentPosition', () { |
19 return window.navigator.geolocation.getCurrentPosition().then( | 18 return window.navigator.geolocation.getCurrentPosition().then((position) { |
20 (position) { | 19 expect(position.coords.latitude, isNotNull); |
21 expect(position.coords.latitude, isNotNull); | 20 expect(position.coords.longitude, isNotNull); |
22 expect(position.coords.longitude, isNotNull); | 21 expect(position.coords.accuracy, isNotNull); |
23 expect(position.coords.accuracy, isNotNull); | 22 }); |
24 }); | |
25 }); | 23 }); |
26 | 24 |
27 test('watchPosition', () { | 25 test('watchPosition', () { |
28 return window.navigator.geolocation.watchPosition().first.then( | 26 return window.navigator.geolocation |
29 (position) { | 27 .watchPosition() |
30 expect(position.coords.latitude, isNotNull); | 28 .first |
31 expect(position.coords.longitude, isNotNull); | 29 .then((position) { |
32 expect(position.coords.accuracy, isNotNull); | 30 expect(position.coords.latitude, isNotNull); |
33 }); | 31 expect(position.coords.longitude, isNotNull); |
| 32 expect(position.coords.accuracy, isNotNull); |
| 33 }); |
34 }); | 34 }); |
35 }); | 35 }); |
36 | 36 |
37 group('MediaStream', () { | 37 group('MediaStream', () { |
38 if (MediaStream.supported) { | 38 if (MediaStream.supported) { |
39 test('getUserMedia', () { | 39 test('getUserMedia', () { |
40 return window.navigator.getUserMedia(video: true).then((stream) { | 40 return window.navigator.getUserMedia(video: true).then((stream) { |
41 expect(stream, isNotNull); | 41 expect(stream, isNotNull); |
42 | 42 |
43 var url = Url.createObjectUrlFromStream(stream); | 43 var url = Url.createObjectUrlFromStream(stream); |
44 expect(url, isNotNull); | 44 expect(url, isNotNull); |
45 | 45 |
46 var video = new VideoElement() | 46 var video = new VideoElement()..autoplay = true; |
47 ..autoplay = true; | |
48 | 47 |
49 var completer = new Completer(); | 48 var completer = new Completer(); |
50 video.onError.listen((e) { | 49 video.onError.listen((e) { |
51 completer.completeError(e); | 50 completer.completeError(e); |
52 }); | 51 }); |
53 video.onPlaying.first.then((e) { | 52 video.onPlaying.first.then((e) { |
54 completer.complete(video); | 53 completer.complete(video); |
55 }); | 54 }); |
56 | 55 |
57 document.body.append(video); | 56 document.body.append(video); |
58 video.src = url; | 57 video.src = url; |
59 | 58 |
60 return completer.future; | 59 return completer.future; |
61 }); | 60 }); |
62 }); | 61 }); |
63 | 62 |
64 test('getUserMediaComplexConstructor', () { | 63 test('getUserMediaComplexConstructor', () { |
65 return window.navigator.getUserMedia( | 64 return window.navigator.getUserMedia(video: { |
66 video: {'mandatory': | 65 'mandatory': {'minAspectRatio': 1.333, 'maxAspectRatio': 1.334}, |
67 { 'minAspectRatio': 1.333, 'maxAspectRatio': 1.334 }, | 66 'optional': [ |
68 'optional': | 67 {'minFrameRate': 60}, |
69 [{ 'minFrameRate': 60 }, | 68 {'maxWidth': 640} |
70 { 'maxWidth': 640 }] | 69 ] |
71 }).then((stream) { | 70 }).then((stream) { |
72 expect(stream, isNotNull); | 71 expect(stream, isNotNull); |
73 | 72 |
74 var url = Url.createObjectUrlFromStream(stream); | 73 var url = Url.createObjectUrlFromStream(stream); |
75 expect(url, isNotNull); | 74 expect(url, isNotNull); |
76 | 75 |
77 var video = new VideoElement() | 76 var video = new VideoElement()..autoplay = true; |
78 ..autoplay = true; | |
79 | 77 |
80 var completer = new Completer(); | 78 var completer = new Completer(); |
81 video.onError.listen((e) { | 79 video.onError.listen((e) { |
82 completer.completeError(e); | 80 completer.completeError(e); |
83 }); | 81 }); |
84 video.onPlaying.first.then((e) { | 82 video.onPlaying.first.then((e) { |
85 completer.complete(video); | 83 completer.complete(video); |
86 }); | 84 }); |
87 | 85 |
88 document.body.append(video); | 86 document.body.append(video); |
89 video.src = url; | 87 video.src = url; |
90 | 88 |
91 return completer.future; | 89 return completer.future; |
92 }); | 90 }); |
93 }); | 91 }); |
94 } | 92 } |
95 }); | 93 }); |
96 | 94 |
97 group('KeyEvent', () { | 95 group('KeyEvent', () { |
98 keydownHandlerTest(KeyEvent e) { | 96 keydownHandlerTest(KeyEvent e) { |
99 document.body.innerHtml = | 97 document.body.innerHtml = |
100 '${document.body.innerHtml}KeyDOWN: CharCode: ${e.charCode}, KeyCode:' | 98 '${document.body.innerHtml}KeyDOWN: CharCode: ${e.charCode}, KeyCode:' |
101 ' ${e.keyCode}<br />'; | 99 ' ${e.keyCode}<br />'; |
102 expect(e.charCode, 0); | 100 expect(e.charCode, 0); |
103 } | 101 } |
| 102 |
104 keypressHandlerTest(KeyEvent e) { | 103 keypressHandlerTest(KeyEvent e) { |
105 document.body.innerHtml = | 104 document.body.innerHtml = |
106 '${document.body.innerHtml}KeyPRESS: CharCode: ${e.charCode}, ' | 105 '${document.body.innerHtml}KeyPRESS: CharCode: ${e.charCode}, ' |
107 'KeyCode: ${e.keyCode}<br />'; | 106 'KeyCode: ${e.keyCode}<br />'; |
108 } | 107 } |
| 108 |
109 keyupHandlerTest(KeyEvent e) { | 109 keyupHandlerTest(KeyEvent e) { |
110 document.body.innerHtml = | 110 document.body.innerHtml = |
111 '${document.body.innerHtml}KeyUP: CharCode: ${e.charCode}, KeyCode:' | 111 '${document.body.innerHtml}KeyUP: CharCode: ${e.charCode}, KeyCode:' |
112 ' ${e.keyCode}<br />'; | 112 ' ${e.keyCode}<br />'; |
113 expect(e.charCode, 0); | 113 expect(e.charCode, 0); |
114 } | 114 } |
| 115 |
115 keyupHandlerTest2(KeyEvent e) { | 116 keyupHandlerTest2(KeyEvent e) { |
116 document.body.innerHtml = | 117 document.body.innerHtml = |
117 '${document.body.innerHtml}A second KeyUP handler: CharCode: ' | 118 '${document.body.innerHtml}A second KeyUP handler: CharCode: ' |
118 '${e.charCode}, KeyCode: ${e.keyCode}<br />'; | 119 '${e.charCode}, KeyCode: ${e.keyCode}<br />'; |
119 expect(e.charCode, 0); | 120 expect(e.charCode, 0); |
120 } | 121 } |
| 122 |
121 test('keys', () { | 123 test('keys', () { |
122 document.body.innerHtml = | 124 document.body.innerHtml = |
123 '${document.body.innerHtml}To test keyboard event values, press some ' | 125 '${document.body.innerHtml}To test keyboard event values, press some ' |
124 'keys on your keyboard.<br /><br />The charcode for keydown and keyup' | 126 'keys on your keyboard.<br /><br />The charcode for keydown and keyup' |
125 ' should be 0, and the keycode should (generally) be populated with a' | 127 ' should be 0, and the keycode should (generally) be populated with a' |
126 ' value. Keycode and charcode should both have values for the ' | 128 ' value. Keycode and charcode should both have values for the ' |
127 'keypress event.'; | 129 'keypress event.'; |
128 KeyboardEventStream.onKeyDown(document.body).listen( | 130 KeyboardEventStream.onKeyDown(document.body).listen(keydownHandlerTest); |
129 keydownHandlerTest); | 131 KeyboardEventStream.onKeyPress(document.body).listen(keypressHandlerTest); |
130 KeyboardEventStream.onKeyPress(document.body).listen( | 132 KeyboardEventStream.onKeyUp(document.body).listen(keyupHandlerTest); |
131 keypressHandlerTest); | 133 KeyboardEventStream.onKeyUp(document.body).listen(keyupHandlerTest2); |
132 KeyboardEventStream.onKeyUp(document.body).listen( | |
133 keyupHandlerTest); | |
134 KeyboardEventStream.onKeyUp(document.body).listen( | |
135 keyupHandlerTest2); | |
136 }); | 134 }); |
137 }); | 135 }); |
138 } | 136 } |
OLD | NEW |