Add a test for creating images from bytes. (#10799)

This commit is contained in:
Chinmay Garde 2019-08-08 21:46:55 -07:00 committed by GitHub
parent d47a136aa5
commit 0c42c516d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 53 additions and 0 deletions

View File

@ -75,3 +75,22 @@ void testSkiaResourceCacheSendsResponse() {
callback,
);
}
void notifyWidthHeight(int width, int height) native 'NotifyWidthHeight';
@pragma('vm:entry-point')
void canCreateImageFromDecompressedData() {
const int imageWidth = 10;
const int imageHeight = 10;
final Uint8List pixels = Uint8List.fromList(List<int>.generate(
imageWidth * imageHeight * 4,
(int i) => i % 4 < 2 ? 0x00 : 0xFF,
));
decodeImageFromPixels(
pixels, imageWidth, imageHeight, PixelFormat.rgba8888,
(Image image) {
notifyWidthHeight(image.width, image.height);
});
}

View File

@ -22,6 +22,7 @@
#include "flutter/shell/common/switches.h"
#include "flutter/shell/common/thread_host.h"
#include "flutter/testing/testing.h"
#include "third_party/tonic/converter/dart_converter.h"
namespace flutter {
namespace testing {
@ -730,5 +731,38 @@ TEST_F(ShellTest, SetResourceCacheSizeNotifiesDart) {
static_cast<size_t>(10000U));
}
TEST_F(ShellTest, CanCreateImagefromDecompressedBytes) {
Settings settings = CreateSettingsForFixture();
auto task_runner = GetThreadTaskRunner();
TaskRunners task_runners("test", task_runner, task_runner, task_runner,
task_runner);
std::unique_ptr<Shell> shell =
CreateShell(std::move(settings), std::move(task_runners));
// Create the surface needed by rasterizer
PlatformViewNotifyCreated(shell.get());
auto configuration = RunConfiguration::InferFromSettings(settings);
configuration.SetEntrypoint("canCreateImageFromDecompressedData");
fml::AutoResetWaitableEvent latch;
AddNativeCallback("NotifyWidthHeight",
CREATE_NATIVE_ENTRY([&latch](auto args) {
auto width = tonic::DartConverter<int>::FromDart(
Dart_GetNativeArgument(args, 0));
auto height = tonic::DartConverter<int>::FromDart(
Dart_GetNativeArgument(args, 1));
ASSERT_EQ(width, 10);
ASSERT_EQ(height, 10);
latch.Signal();
}));
RunEngine(shell.get(), std::move(configuration));
latch.Wait();
}
} // namespace testing
} // namespace flutter