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