This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cacheWidth cacheHeight support for canvaskit on web (#117423)
* cacheWidth cacheHeight support for web canvaskit * comments * clarifying comment for loadTestImageProvider class Co-authored-by: alanwutang11 <alpwu@google.com>
- Loading branch information
1 parent
2a50236
commit 1970bc9
Showing
6 changed files
with
108 additions
and
13 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
80 changes: 80 additions & 0 deletions
80
dev/integration_tests/web_e2e_tests/test_driver/cache_width_cache_height_integration.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,80 @@ | ||
// Copyright 2014 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'dart:async'; | ||
import 'dart:ui' as ui; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:integration_test/integration_test.dart'; | ||
|
||
// This class allows loadBuffer, a protected method, to be called with a custom | ||
// DecoderBufferCallback function. | ||
class LoadTestImageProvider extends ImageProvider<Object> { | ||
LoadTestImageProvider(this.provider); | ||
|
||
final ImageProvider provider; | ||
|
||
ImageStreamCompleter testLoad(Object key, DecoderBufferCallback decode) { | ||
return provider.loadBuffer(key, decode); | ||
} | ||
|
||
@override | ||
Future<Object> obtainKey(ImageConfiguration configuration) { | ||
throw UnimplementedError(); | ||
} | ||
|
||
@override | ||
ImageStreamCompleter loadBuffer(Object key, DecoderBufferCallback decode) { | ||
throw UnimplementedError(); | ||
} | ||
} | ||
|
||
void main() { | ||
IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | ||
|
||
testWidgets('Image.network uses cacheWidth and cacheHeight', (WidgetTester tester) async { | ||
const int expectedCacheHeight = 9; | ||
const int expectedCacheWidth = 11; | ||
await tester.pumpAndSettle(); | ||
|
||
final Image image = Image.network( | ||
'assets/packages/flutter_gallery_assets/assets/icons/material/material.png', | ||
cacheHeight: 9, | ||
cacheWidth: 11, | ||
); | ||
|
||
bool called = false; | ||
|
||
Future<ui.Codec> decode(ui.ImmutableBuffer buffer, {int? cacheWidth, int? cacheHeight, bool allowUpscaling = false}) { | ||
expect(cacheHeight, expectedCacheHeight); | ||
expect(cacheWidth, expectedCacheWidth); | ||
expect(allowUpscaling, false); | ||
called = true; | ||
return PaintingBinding.instance.instantiateImageCodecFromBuffer(buffer, cacheWidth: cacheWidth, cacheHeight: cacheHeight, allowUpscaling: allowUpscaling); | ||
} | ||
|
||
final ImageProvider resizeImage = image.image; | ||
expect(image.image, isA<ResizeImage>()); | ||
|
||
final LoadTestImageProvider testProvider = LoadTestImageProvider(image.image); | ||
final ImageStreamCompleter streamCompleter = testProvider.testLoad(await resizeImage.obtainKey(ImageConfiguration.empty), decode); | ||
|
||
final Completer<void> completer = Completer<void>(); | ||
int? imageInfoCachedWidth; | ||
int? imageInfoCachedHeight; | ||
streamCompleter.addListener(ImageStreamListener((ImageInfo imageInfo, bool syncCall) { | ||
imageInfoCachedWidth = imageInfo.image.width; | ||
imageInfoCachedHeight = imageInfo.image.height; | ||
completer.complete(); | ||
})); | ||
await completer.future; | ||
|
||
expect(imageInfoCachedHeight, isNotNull); | ||
expect(imageInfoCachedHeight, expectedCacheHeight); | ||
expect(imageInfoCachedWidth, isNotNull); | ||
expect(imageInfoCachedWidth, expectedCacheWidth); | ||
expect(called, true); | ||
}); | ||
} |
7 changes: 7 additions & 0 deletions
7
...ntegration_tests/web_e2e_tests/test_driver/cache_width_cache_height_integration_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,7 @@ | ||
// Copyright 2014 The Flutter Authors. 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:integration_test/integration_test_driver.dart' as test; | ||
|
||
Future<void> main() async => test.integrationDriver(); |
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