-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make it possible to use a custom CronetEngine with runWithClient (#843)
- Loading branch information
1 parent
38d5dd9
commit d434d42
Showing
7 changed files
with
146 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 0 additions & 25 deletions
25
pkgs/cronet_http/example/integration_test/client_conformance_test.dart
This file was deleted.
Oops, something went wrong.
68 changes: 68 additions & 0 deletions
68
pkgs/cronet_http/example/integration_test/client_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:cronet_http/cronet_client.dart'; | ||
import 'package:http/http.dart'; | ||
import 'package:http_client_conformance_tests/http_client_conformance_tests.dart'; | ||
import 'package:integration_test/integration_test.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void testClientConformance(CronetClient Function() clientFactory) { | ||
// TODO: Use `testAll` when `testServerErrors` passes i.e. | ||
// testAll(CronetClient(), canStreamRequestBody: false); | ||
|
||
final client = clientFactory(); | ||
testRequestBody(client); | ||
testRequestBodyStreamed(client, canStreamRequestBody: false); | ||
testResponseBody(client); | ||
testResponseBodyStreamed(client); | ||
testRequestHeaders(client); | ||
testResponseHeaders(client); | ||
testRedirect(client); | ||
testCompressedResponseBody(client); | ||
testMultipleClients(clientFactory); | ||
} | ||
|
||
Future<void> testConformance() async { | ||
group('default cronet engine', | ||
() => testClientConformance(CronetClient.defaultCronetEngine)); | ||
|
||
final engine = await CronetEngine.build( | ||
cacheMode: CacheMode.disabled, userAgent: 'Test Agent (Engine)'); | ||
|
||
group('from cronet engine', () { | ||
testClientConformance(() => CronetClient.fromCronetEngine(engine)); | ||
}); | ||
|
||
group('from cronet engine future', () { | ||
final engineFuture = CronetEngine.build( | ||
cacheMode: CacheMode.disabled, userAgent: 'Test Agent (Future)'); | ||
testClientConformance( | ||
() => CronetClient.fromCronetEngineFuture(engineFuture)); | ||
}); | ||
} | ||
|
||
Future<void> testClientFromFutureFails() async { | ||
test('cronet engine future fails', () async { | ||
final engineFuture = CronetEngine.build( | ||
cacheMode: CacheMode.disk, | ||
storagePath: '/non-existant-path/', // Will cause `build` to throw. | ||
userAgent: 'Test Agent (Future)'); | ||
|
||
final client = CronetClient.fromCronetEngineFuture(engineFuture); | ||
await expectLater( | ||
client.get(Uri.http('example.com', '/')), | ||
throwsA((Exception e) => | ||
e is ClientException && | ||
e.message.contains('Exception building CronetEngine: ' | ||
'Invalid argument(s): Storage path must'))); | ||
}); | ||
} | ||
|
||
void main() async { | ||
IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | ||
|
||
await testConformance(); | ||
await testClientFromFutureFails(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters