More preparation for HttpClientResponse implements Uint8List (#35245)
https://github.com/dart-lang/sdk/issues/36900
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
@@ -14,8 +15,8 @@ import '../flutter_test_alternative.dart';
|
||||
|
||||
void main() {
|
||||
group(consolidateHttpClientResponseBytes, () {
|
||||
final List<int> chunkOne = <int>[0, 1, 2, 3, 4, 5];
|
||||
final List<int> chunkTwo = <int>[6, 7, 8, 9, 10];
|
||||
final Uint8List chunkOne = Uint8List.fromList(<int>[0, 1, 2, 3, 4, 5]);
|
||||
final Uint8List chunkTwo = Uint8List.fromList(<int>[6, 7, 8, 9, 10]);
|
||||
MockHttpClientResponse response;
|
||||
|
||||
setUp(() {
|
||||
@@ -32,8 +33,8 @@ void main() {
|
||||
final void Function() onDone = invocation.namedArguments[#onDone];
|
||||
final bool cancelOnError = invocation.namedArguments[#cancelOnError];
|
||||
|
||||
return Stream<List<int>>.fromIterable(
|
||||
<List<int>>[chunkOne, chunkTwo]).listen(
|
||||
return Stream<Uint8List>.fromIterable(
|
||||
<Uint8List>[chunkOne, chunkTwo]).listen(
|
||||
onData,
|
||||
onDone: onDone,
|
||||
onError: onError,
|
||||
@@ -98,8 +99,8 @@ void main() {
|
||||
final void Function() onDone = invocation.namedArguments[#onDone];
|
||||
final bool cancelOnError = invocation.namedArguments[#cancelOnError];
|
||||
|
||||
return Stream<List<int>>.fromFuture(
|
||||
Future<List<int>>.error(Exception('Test Error')))
|
||||
return Stream<Uint8List>.fromFuture(
|
||||
Future<Uint8List>.error(Exception('Test Error')))
|
||||
.listen(
|
||||
onData,
|
||||
onDone: onDone,
|
||||
@@ -126,9 +127,9 @@ void main() {
|
||||
});
|
||||
|
||||
group('when gzipped', () {
|
||||
final List<int> gzipped = gzip.encode(chunkOne.followedBy(chunkTwo).toList());
|
||||
final List<int> gzippedChunkOne = gzipped.sublist(0, gzipped.length ~/ 2);
|
||||
final List<int> gzippedChunkTwo = gzipped.sublist(gzipped.length ~/ 2);
|
||||
final Uint8List gzipped = gzip.encode(chunkOne.followedBy(chunkTwo).toList());
|
||||
final Uint8List gzippedChunkOne = gzipped.sublist(0, gzipped.length ~/ 2);
|
||||
final Uint8List gzippedChunkTwo = gzipped.sublist(gzipped.length ~/ 2);
|
||||
|
||||
setUp(() {
|
||||
when(response.compressionState).thenReturn(HttpClientResponseCompressionState.compressed);
|
||||
@@ -143,8 +144,8 @@ void main() {
|
||||
final void Function() onDone = invocation.namedArguments[#onDone];
|
||||
final bool cancelOnError = invocation.namedArguments[#cancelOnError];
|
||||
|
||||
return Stream<List<int>>.fromIterable(
|
||||
<List<int>>[gzippedChunkOne, gzippedChunkTwo]).listen(
|
||||
return Stream<Uint8List>.fromIterable(
|
||||
<Uint8List>[gzippedChunkOne, gzippedChunkTwo]).listen(
|
||||
onData,
|
||||
onDone: onDone,
|
||||
onError: onError,
|
||||
|
||||
@@ -202,10 +202,10 @@ void main() {
|
||||
});
|
||||
|
||||
test('Notifies listeners of chunk events', () async {
|
||||
final List<List<int>> chunks = <List<int>>[];
|
||||
final List<Uint8List> chunks = <Uint8List>[];
|
||||
const int chunkSize = 8;
|
||||
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 MockHttpClientRequest request = MockHttpClientRequest();
|
||||
@@ -225,7 +225,7 @@ void main() {
|
||||
final void Function() onDone = invocation.namedArguments[#onDone];
|
||||
final bool cancelOnError = invocation.namedArguments[#cancelOnError];
|
||||
|
||||
return Stream<List<int>>.fromIterable(chunks).listen(
|
||||
return Stream<Uint8List>.fromIterable(chunks).listen(
|
||||
onData,
|
||||
onDone: onDone,
|
||||
onError: onError,
|
||||
|
||||
Reference in New Issue
Block a user