Unverified Commit 66273157 authored by Todd Volkert's avatar Todd Volkert Committed by GitHub

More preparation for HttpClientResponse implements Uint8List (#35245)

https://github.com/dart-lang/sdk/issues/36900
parent 17c18da0
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
import 'dart:async'; import 'dart:async';
import 'dart:io'; import 'dart:io';
import 'dart:typed_data';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
...@@ -14,8 +15,8 @@ import '../flutter_test_alternative.dart'; ...@@ -14,8 +15,8 @@ import '../flutter_test_alternative.dart';
void main() { void main() {
group(consolidateHttpClientResponseBytes, () { group(consolidateHttpClientResponseBytes, () {
final List<int> chunkOne = <int>[0, 1, 2, 3, 4, 5]; final Uint8List chunkOne = Uint8List.fromList(<int>[0, 1, 2, 3, 4, 5]);
final List<int> chunkTwo = <int>[6, 7, 8, 9, 10]; final Uint8List chunkTwo = Uint8List.fromList(<int>[6, 7, 8, 9, 10]);
MockHttpClientResponse response; MockHttpClientResponse response;
setUp(() { setUp(() {
...@@ -32,8 +33,8 @@ void main() { ...@@ -32,8 +33,8 @@ void main() {
final void Function() onDone = invocation.namedArguments[#onDone]; final void Function() onDone = invocation.namedArguments[#onDone];
final bool cancelOnError = invocation.namedArguments[#cancelOnError]; final bool cancelOnError = invocation.namedArguments[#cancelOnError];
return Stream<List<int>>.fromIterable( return Stream<Uint8List>.fromIterable(
<List<int>>[chunkOne, chunkTwo]).listen( <Uint8List>[chunkOne, chunkTwo]).listen(
onData, onData,
onDone: onDone, onDone: onDone,
onError: onError, onError: onError,
...@@ -98,8 +99,8 @@ void main() { ...@@ -98,8 +99,8 @@ void main() {
final void Function() onDone = invocation.namedArguments[#onDone]; final void Function() onDone = invocation.namedArguments[#onDone];
final bool cancelOnError = invocation.namedArguments[#cancelOnError]; final bool cancelOnError = invocation.namedArguments[#cancelOnError];
return Stream<List<int>>.fromFuture( return Stream<Uint8List>.fromFuture(
Future<List<int>>.error(Exception('Test Error'))) Future<Uint8List>.error(Exception('Test Error')))
.listen( .listen(
onData, onData,
onDone: onDone, onDone: onDone,
...@@ -126,9 +127,9 @@ void main() { ...@@ -126,9 +127,9 @@ void main() {
}); });
group('when gzipped', () { group('when gzipped', () {
final List<int> gzipped = gzip.encode(chunkOne.followedBy(chunkTwo).toList()); final Uint8List gzipped = gzip.encode(chunkOne.followedBy(chunkTwo).toList());
final List<int> gzippedChunkOne = gzipped.sublist(0, gzipped.length ~/ 2); final Uint8List gzippedChunkOne = gzipped.sublist(0, gzipped.length ~/ 2);
final List<int> gzippedChunkTwo = gzipped.sublist(gzipped.length ~/ 2); final Uint8List gzippedChunkTwo = gzipped.sublist(gzipped.length ~/ 2);
setUp(() { setUp(() {
when(response.compressionState).thenReturn(HttpClientResponseCompressionState.compressed); when(response.compressionState).thenReturn(HttpClientResponseCompressionState.compressed);
...@@ -143,8 +144,8 @@ void main() { ...@@ -143,8 +144,8 @@ void main() {
final void Function() onDone = invocation.namedArguments[#onDone]; final void Function() onDone = invocation.namedArguments[#onDone];
final bool cancelOnError = invocation.namedArguments[#cancelOnError]; final bool cancelOnError = invocation.namedArguments[#cancelOnError];
return Stream<List<int>>.fromIterable( return Stream<Uint8List>.fromIterable(
<List<int>>[gzippedChunkOne, gzippedChunkTwo]).listen( <Uint8List>[gzippedChunkOne, gzippedChunkTwo]).listen(
onData, onData,
onDone: onDone, onDone: onDone,
onError: onError, onError: onError,
......
...@@ -202,10 +202,10 @@ void main() { ...@@ -202,10 +202,10 @@ void main() {
}); });
test('Notifies listeners of chunk events', () async { test('Notifies listeners of chunk events', () async {
final List<List<int>> chunks = <List<int>>[]; final List<Uint8List> chunks = <Uint8List>[];
const int chunkSize = 8; const int chunkSize = 8;
for (int offset = 0; offset < kTransparentImage.length; offset += chunkSize) { for (int offset = 0; offset < kTransparentImage.length; offset += chunkSize) {
chunks.add(kTransparentImage.skip(offset).take(chunkSize).toList()); chunks.add(Uint8List.fromList(kTransparentImage.skip(offset).take(chunkSize).toList()));
} }
final Completer<void> imageAvailable = Completer<void>(); final Completer<void> imageAvailable = Completer<void>();
final MockHttpClientRequest request = MockHttpClientRequest(); final MockHttpClientRequest request = MockHttpClientRequest();
...@@ -225,7 +225,7 @@ void main() { ...@@ -225,7 +225,7 @@ void main() {
final void Function() onDone = invocation.namedArguments[#onDone]; final void Function() onDone = invocation.namedArguments[#onDone];
final bool cancelOnError = invocation.namedArguments[#cancelOnError]; final bool cancelOnError = invocation.namedArguments[#cancelOnError];
return Stream<List<int>>.fromIterable(chunks).listen( return Stream<Uint8List>.fromIterable(chunks).listen(
onData, onData,
onDone: onDone, onDone: onDone,
onError: onError, onError: onError,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment