Chromium Code Reviews| 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 crypto_test; | |
| 6 import '../../pkg/unittest/lib/unittest.dart'; | |
| 7 import '../../pkg/unittest/lib/html_config.dart'; | |
| 8 import 'dart:html'; | |
| 9 | |
| 10 main() { | |
| 11 useHtmlConfiguration(); | |
|
Anton Muhin
2013/02/21 12:40:43
please, use useHtmlIndividualConfiguration
Mads Ager (google)
2013/02/21 13:38:57
But then I have to use 'group', right. And since I
| |
| 12 | |
| 13 test('exists', () { | |
| 14 var crypto = window.crypto; | |
| 15 expect(crypto is Crypto, isTrue); | |
| 16 }); | |
| 17 | |
| 18 test('successful call', () { | |
| 19 var crypto = window.crypto; | |
| 20 var data = new Uint8Array(100); | |
| 21 expect(data.every((e) => e == 0), isTrue); | |
| 22 crypto.getRandomValues(data); | |
| 23 // In theory this is flaky. However, in practice you will get 100 zeroes | |
| 24 // in a row from a cryptographically secure random number generator so | |
| 25 // rarely that we don't have to worry about it. | |
| 26 expect(data.any((e) => e != 0), isTrue); | |
| 27 }); | |
| 28 | |
| 29 test('type mismatch', () { | |
| 30 var crypto = window.crypto; | |
| 31 var data = new Float32Array(100); | |
| 32 expect(() { | |
| 33 crypto.getRandomValues(data); | |
| 34 }, throws, reason: "Only typed array views with integer types allowed"); | |
|
Anton Muhin
2013/02/21 12:40:43
nit: ' instead of ", please
Mads Ager (google)
2013/02/21 13:38:57
Done.
| |
| 35 }); | |
| 36 } | |
| OLD | NEW |