mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Use FixtureTest to remove duplicate code (flutter/engine#19219)
Fixes https://github.com/flutter/flutter/issues/59109
This commit is contained in:
parent
ee22d12eba
commit
02f828632c
@ -331,8 +331,6 @@ FILE: ../../../flutter/lib/ui/painting/image.cc
|
||||
FILE: ../../../flutter/lib/ui/painting/image.h
|
||||
FILE: ../../../flutter/lib/ui/painting/image_decoder.cc
|
||||
FILE: ../../../flutter/lib/ui/painting/image_decoder.h
|
||||
FILE: ../../../flutter/lib/ui/painting/image_decoder_test.cc
|
||||
FILE: ../../../flutter/lib/ui/painting/image_decoder_test.h
|
||||
FILE: ../../../flutter/lib/ui/painting/image_decoder_unittests.cc
|
||||
FILE: ../../../flutter/lib/ui/painting/image_encoding.cc
|
||||
FILE: ../../../flutter/lib/ui/painting/image_encoding.h
|
||||
@ -567,8 +565,6 @@ FILE: ../../../flutter/runtime/runtime_controller.cc
|
||||
FILE: ../../../flutter/runtime/runtime_controller.h
|
||||
FILE: ../../../flutter/runtime/runtime_delegate.cc
|
||||
FILE: ../../../flutter/runtime/runtime_delegate.h
|
||||
FILE: ../../../flutter/runtime/runtime_test.cc
|
||||
FILE: ../../../flutter/runtime/runtime_test.h
|
||||
FILE: ../../../flutter/runtime/service_protocol.cc
|
||||
FILE: ../../../flutter/runtime/service_protocol.h
|
||||
FILE: ../../../flutter/runtime/skia_concurrent_executor.cc
|
||||
|
||||
@ -160,8 +160,6 @@ if (current_toolchain == host_toolchain) {
|
||||
configs += [ "//flutter:export_dynamic_symbols" ]
|
||||
|
||||
sources = [
|
||||
"painting/image_decoder_test.cc",
|
||||
"painting/image_decoder_test.h",
|
||||
"painting/image_decoder_unittests.cc",
|
||||
"painting/vertices_unittests.cc",
|
||||
"window/pointer_data_packet_converter_unittests.cc",
|
||||
@ -174,6 +172,7 @@ if (current_toolchain == host_toolchain) {
|
||||
"//flutter/shell/common:shell_test_fixture_sources",
|
||||
"//flutter/testing",
|
||||
"//flutter/testing:dart",
|
||||
"//flutter/testing:fixture_test",
|
||||
"//flutter/testing:opengl",
|
||||
"//flutter/third_party/tonic",
|
||||
"//third_party/dart/runtime/bin:elf_loader",
|
||||
|
||||
@ -1,53 +0,0 @@
|
||||
// Copyright 2013 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.
|
||||
|
||||
#include "flutter/lib/ui/painting/image_decoder_test.h"
|
||||
|
||||
namespace flutter {
|
||||
namespace testing {
|
||||
|
||||
ImageDecoderFixtureTest::ImageDecoderFixtureTest()
|
||||
: native_resolver_(std::make_shared<TestDartNativeResolver>()),
|
||||
assets_dir_(fml::OpenDirectory(GetFixturesPath(),
|
||||
false,
|
||||
fml::FilePermission::kRead)),
|
||||
aot_symbols_(LoadELFSymbolFromFixturesIfNeccessary()) {}
|
||||
|
||||
Settings ImageDecoderFixtureTest::CreateSettingsForFixture() {
|
||||
Settings settings;
|
||||
settings.leak_vm = false;
|
||||
settings.task_observer_add = [](intptr_t, fml::closure) {};
|
||||
settings.task_observer_remove = [](intptr_t) {};
|
||||
settings.isolate_create_callback = [this]() {
|
||||
native_resolver_->SetNativeResolverForIsolate();
|
||||
};
|
||||
settings.enable_observatory = false;
|
||||
SetSnapshotsAndAssets(settings);
|
||||
return settings;
|
||||
}
|
||||
|
||||
void ImageDecoderFixtureTest::SetSnapshotsAndAssets(Settings& settings) {
|
||||
if (!assets_dir_.is_valid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
settings.assets_dir = assets_dir_.get();
|
||||
|
||||
// In JIT execution, all snapshots are present within the binary itself and
|
||||
// don't need to be explicitly supplied by the embedder. In AOT, these
|
||||
// snapshots will be present in the application AOT dylib.
|
||||
if (DartVM::IsRunningPrecompiledCode()) {
|
||||
FML_CHECK(PrepareSettingsForAOTWithSymbols(settings, aot_symbols_));
|
||||
} else {
|
||||
settings.application_kernels = [this]() {
|
||||
std::vector<std::unique_ptr<const fml::Mapping>> kernel_mappings;
|
||||
kernel_mappings.emplace_back(
|
||||
fml::FileMapping::CreateReadOnly(assets_dir_, "kernel_blob.bin"));
|
||||
return kernel_mappings;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace flutter
|
||||
@ -1,39 +0,0 @@
|
||||
// Copyright 2013 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.
|
||||
|
||||
#ifndef FLUTTER_LIB_UI_PAINTING_IMAGE_DECODER_TEST_H_
|
||||
#define FLUTTER_LIB_UI_PAINTING_IMAGE_DECODER_TEST_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "flutter/common/settings.h"
|
||||
#include "flutter/runtime/dart_vm.h"
|
||||
#include "flutter/testing/elf_loader.h"
|
||||
#include "flutter/testing/test_dart_native_resolver.h"
|
||||
#include "flutter/testing/testing.h"
|
||||
#include "flutter/testing/thread_test.h"
|
||||
|
||||
namespace flutter {
|
||||
namespace testing {
|
||||
|
||||
class ImageDecoderFixtureTest : public ThreadTest {
|
||||
public:
|
||||
ImageDecoderFixtureTest();
|
||||
|
||||
Settings CreateSettingsForFixture();
|
||||
|
||||
private:
|
||||
std::shared_ptr<TestDartNativeResolver> native_resolver_;
|
||||
fml::UniqueFD assets_dir_;
|
||||
ELFAOTSymbols aot_symbols_;
|
||||
|
||||
void SetSnapshotsAndAssets(Settings& settings);
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(ImageDecoderFixtureTest);
|
||||
};
|
||||
|
||||
} // namespace testing
|
||||
} // namespace flutter
|
||||
|
||||
#endif // FLUTTER_LIB_UI_PAINTING_IMAGE_DECODER_TEST_H_
|
||||
@ -6,16 +6,15 @@
|
||||
#include "flutter/fml/mapping.h"
|
||||
#include "flutter/fml/synchronization/waitable_event.h"
|
||||
#include "flutter/lib/ui/painting/image_decoder.h"
|
||||
#include "flutter/lib/ui/painting/image_decoder_test.h"
|
||||
#include "flutter/lib/ui/painting/multi_frame_codec.h"
|
||||
#include "flutter/runtime/dart_vm.h"
|
||||
#include "flutter/runtime/dart_vm_lifecycle.h"
|
||||
#include "flutter/testing/dart_isolate_runner.h"
|
||||
#include "flutter/testing/elf_loader.h"
|
||||
#include "flutter/testing/fixture_test.h"
|
||||
#include "flutter/testing/test_dart_native_resolver.h"
|
||||
#include "flutter/testing/test_gl_surface.h"
|
||||
#include "flutter/testing/testing.h"
|
||||
#include "flutter/testing/thread_test.h"
|
||||
#include "third_party/skia/include/codec/SkCodec.h"
|
||||
|
||||
namespace flutter {
|
||||
@ -120,6 +119,8 @@ static sk_sp<SkData> OpenFixtureAsSkData(const char* name) {
|
||||
return data;
|
||||
}
|
||||
|
||||
class ImageDecoderFixtureTest : public FixtureTest {};
|
||||
|
||||
TEST_F(ImageDecoderFixtureTest, CanCreateImageDecoder) {
|
||||
auto loop = fml::ConcurrentMessageLoop::Create();
|
||||
auto thread_task_runner = CreateNewThread();
|
||||
|
||||
@ -117,8 +117,6 @@ source_set_maybe_fuchsia_legacy("runtime_unittests_common") {
|
||||
"dart_lifecycle_unittests.cc",
|
||||
"dart_service_isolate_unittests.cc",
|
||||
"dart_vm_unittests.cc",
|
||||
"runtime_test.cc",
|
||||
"runtime_test.h",
|
||||
]
|
||||
|
||||
public_deps = [
|
||||
@ -136,6 +134,7 @@ source_set_maybe_fuchsia_legacy("runtime_unittests_common") {
|
||||
deps_legacy_and_next = [
|
||||
":runtime",
|
||||
"//flutter/testing:dart",
|
||||
"//flutter/testing:fixture_test",
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@ -9,17 +9,16 @@
|
||||
#include "flutter/runtime/dart_isolate.h"
|
||||
#include "flutter/runtime/dart_vm.h"
|
||||
#include "flutter/runtime/dart_vm_lifecycle.h"
|
||||
#include "flutter/runtime/runtime_test.h"
|
||||
#include "flutter/testing/dart_isolate_runner.h"
|
||||
#include "flutter/testing/fixture_test.h"
|
||||
#include "flutter/testing/testing.h"
|
||||
#include "flutter/testing/thread_test.h"
|
||||
#include "third_party/tonic/converter/dart_converter.h"
|
||||
#include "third_party/tonic/scopes/dart_isolate_scope.h"
|
||||
|
||||
namespace flutter {
|
||||
namespace testing {
|
||||
|
||||
using DartIsolateTest = RuntimeTest;
|
||||
using DartIsolateTest = FixtureTest;
|
||||
|
||||
TEST_F(DartIsolateTest, RootIsolateCreationAndShutdown) {
|
||||
ASSERT_FALSE(DartVMRef::IsInstanceRunning());
|
||||
|
||||
@ -8,12 +8,12 @@
|
||||
#include "flutter/fml/synchronization/waitable_event.h"
|
||||
#include "flutter/runtime/dart_vm.h"
|
||||
#include "flutter/runtime/dart_vm_lifecycle.h"
|
||||
#include "flutter/runtime/runtime_test.h"
|
||||
#include "flutter/testing/fixture_test.h"
|
||||
|
||||
namespace flutter {
|
||||
namespace testing {
|
||||
|
||||
using DartLifecycleTest = RuntimeTest;
|
||||
using DartLifecycleTest = FixtureTest;
|
||||
|
||||
TEST_F(DartLifecycleTest, CanStartAndShutdownVM) {
|
||||
auto settings = CreateSettingsForFixture();
|
||||
|
||||
@ -4,13 +4,13 @@
|
||||
|
||||
#include "flutter/runtime/dart_vm.h"
|
||||
#include "flutter/runtime/dart_vm_lifecycle.h"
|
||||
#include "flutter/runtime/runtime_test.h"
|
||||
#include "flutter/testing/fixture_test.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace flutter {
|
||||
namespace testing {
|
||||
|
||||
using DartVMTest = RuntimeTest;
|
||||
using DartVMTest = FixtureTest;
|
||||
|
||||
TEST_F(DartVMTest, SimpleInitialization) {
|
||||
ASSERT_FALSE(DartVMRef::IsInstanceRunning());
|
||||
|
||||
@ -1,60 +0,0 @@
|
||||
// Copyright 2013 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.
|
||||
|
||||
#include "flutter/runtime/runtime_test.h"
|
||||
|
||||
#include "flutter/runtime/dart_vm.h"
|
||||
#include "flutter/testing/testing.h"
|
||||
|
||||
namespace flutter {
|
||||
namespace testing {
|
||||
|
||||
RuntimeTest::RuntimeTest()
|
||||
: native_resolver_(std::make_shared<TestDartNativeResolver>()),
|
||||
assets_dir_(fml::OpenDirectory(GetFixturesPath(),
|
||||
false,
|
||||
fml::FilePermission::kRead)),
|
||||
aot_symbols_(LoadELFSymbolFromFixturesIfNeccessary()) {}
|
||||
|
||||
void RuntimeTest::SetSnapshotsAndAssets(Settings& settings) {
|
||||
if (!assets_dir_.is_valid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
settings.assets_dir = assets_dir_.get();
|
||||
|
||||
// In JIT execution, all snapshots are present within the binary itself and
|
||||
// don't need to be explicitly supplied by the embedder. In AOT, these
|
||||
// snapshots will be present in the application AOT dylib.
|
||||
if (DartVM::IsRunningPrecompiledCode()) {
|
||||
PrepareSettingsForAOTWithSymbols(settings, aot_symbols_);
|
||||
} else {
|
||||
settings.application_kernels = [this]() {
|
||||
std::vector<std::unique_ptr<const fml::Mapping>> kernel_mappings;
|
||||
kernel_mappings.emplace_back(
|
||||
fml::FileMapping::CreateReadOnly(assets_dir_, "kernel_blob.bin"));
|
||||
return kernel_mappings;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Settings RuntimeTest::CreateSettingsForFixture() {
|
||||
Settings settings;
|
||||
settings.leak_vm = false;
|
||||
settings.task_observer_add = [](intptr_t, fml::closure) {};
|
||||
settings.task_observer_remove = [](intptr_t) {};
|
||||
settings.isolate_create_callback = [this]() {
|
||||
native_resolver_->SetNativeResolverForIsolate();
|
||||
};
|
||||
SetSnapshotsAndAssets(settings);
|
||||
return settings;
|
||||
}
|
||||
|
||||
void RuntimeTest::AddNativeCallback(std::string name,
|
||||
Dart_NativeFunction callback) {
|
||||
native_resolver_->AddNativeCallback(std::move(name), callback);
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace flutter
|
||||
@ -1,40 +0,0 @@
|
||||
// Copyright 2013 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.
|
||||
|
||||
#ifndef FLUTTER_RUNTIME_RUNTIME_TEST_H_
|
||||
#define FLUTTER_RUNTIME_RUNTIME_TEST_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "flutter/common/settings.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/testing/elf_loader.h"
|
||||
#include "flutter/testing/test_dart_native_resolver.h"
|
||||
#include "flutter/testing/thread_test.h"
|
||||
|
||||
namespace flutter {
|
||||
namespace testing {
|
||||
|
||||
class RuntimeTest : public ThreadTest {
|
||||
public:
|
||||
RuntimeTest();
|
||||
|
||||
Settings CreateSettingsForFixture();
|
||||
|
||||
void AddNativeCallback(std::string name, Dart_NativeFunction callback);
|
||||
|
||||
private:
|
||||
std::shared_ptr<TestDartNativeResolver> native_resolver_;
|
||||
fml::UniqueFD assets_dir_;
|
||||
ELFAOTSymbols aot_symbols_;
|
||||
|
||||
void SetSnapshotsAndAssets(Settings& settings);
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(RuntimeTest);
|
||||
};
|
||||
|
||||
} // namespace testing
|
||||
} // namespace flutter
|
||||
|
||||
#endif // FLUTTER_RUNTIME_RUNTIME_TEST_H_
|
||||
@ -267,6 +267,7 @@ if (enable_unittests) {
|
||||
":shell_unittests_gpu_configuration",
|
||||
"//flutter/lib/ui:ui",
|
||||
"//flutter/testing:dart",
|
||||
"//flutter/testing:fixture_test",
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@ -20,14 +20,9 @@ namespace flutter {
|
||||
namespace testing {
|
||||
|
||||
ShellTest::ShellTest()
|
||||
: native_resolver_(std::make_shared<TestDartNativeResolver>()),
|
||||
thread_host_("io.flutter.test." + GetCurrentTestName() + ".",
|
||||
: thread_host_("io.flutter.test." + GetCurrentTestName() + ".",
|
||||
ThreadHost::Type::Platform | ThreadHost::Type::IO |
|
||||
ThreadHost::Type::UI | ThreadHost::Type::GPU),
|
||||
assets_dir_(fml::OpenDirectory(GetFixturesPath(),
|
||||
false,
|
||||
fml::FilePermission::kRead)),
|
||||
aot_symbols_(LoadELFSymbolFromFixturesIfNeccessary()) {}
|
||||
ThreadHost::Type::UI | ThreadHost::Type::GPU) {}
|
||||
|
||||
void ShellTest::SendEnginePlatformMessage(
|
||||
Shell* shell,
|
||||
@ -44,27 +39,6 @@ void ShellTest::SendEnginePlatformMessage(
|
||||
latch.Wait();
|
||||
}
|
||||
|
||||
void ShellTest::SetSnapshotsAndAssets(Settings& settings) {
|
||||
if (!assets_dir_.is_valid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
settings.assets_dir = assets_dir_.get();
|
||||
|
||||
// In JIT execution, all snapshots are present within the binary itself and
|
||||
// don't need to be explicitly suppiled by the embedder.
|
||||
if (DartVM::IsRunningPrecompiledCode()) {
|
||||
PrepareSettingsForAOTWithSymbols(settings, aot_symbols_);
|
||||
} else {
|
||||
settings.application_kernels = [this]() {
|
||||
std::vector<std::unique_ptr<const fml::Mapping>> kernel_mappings;
|
||||
kernel_mappings.emplace_back(
|
||||
fml::FileMapping::CreateReadOnly(assets_dir_, "kernel_blob.bin"));
|
||||
return kernel_mappings;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
void ShellTest::PlatformViewNotifyCreated(Shell* shell) {
|
||||
fml::AutoResetWaitableEvent latch;
|
||||
fml::TaskRunner::RunNowOrPostTask(
|
||||
@ -317,10 +291,5 @@ void ShellTest::DestroyShell(std::unique_ptr<Shell> shell,
|
||||
latch.Wait();
|
||||
}
|
||||
|
||||
void ShellTest::AddNativeCallback(std::string name,
|
||||
Dart_NativeFunction callback) {
|
||||
native_resolver_->AddNativeCallback(std::move(name), callback);
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace flutter
|
||||
|
||||
@ -20,17 +20,17 @@
|
||||
#include "flutter/shell/common/thread_host.h"
|
||||
#include "flutter/shell/common/vsync_waiters_test.h"
|
||||
#include "flutter/testing/elf_loader.h"
|
||||
#include "flutter/testing/fixture_test.h"
|
||||
#include "flutter/testing/test_dart_native_resolver.h"
|
||||
#include "flutter/testing/thread_test.h"
|
||||
|
||||
namespace flutter {
|
||||
namespace testing {
|
||||
|
||||
class ShellTest : public ThreadTest {
|
||||
class ShellTest : public FixtureTest {
|
||||
public:
|
||||
ShellTest();
|
||||
|
||||
Settings CreateSettingsForFixture();
|
||||
Settings CreateSettingsForFixture() override;
|
||||
std::unique_ptr<Shell> CreateShell(Settings settings,
|
||||
bool simulate_vsync = false);
|
||||
std::unique_ptr<Shell> CreateShell(
|
||||
@ -48,8 +48,6 @@ class ShellTest : public ThreadTest {
|
||||
void SendEnginePlatformMessage(Shell* shell,
|
||||
fml::RefPtr<PlatformMessage> message);
|
||||
|
||||
void AddNativeCallback(std::string name, Dart_NativeFunction callback);
|
||||
|
||||
static void PlatformViewNotifyCreated(
|
||||
Shell* shell); // This creates the surface
|
||||
static void RunEngine(Shell* shell, RunConfiguration configuration);
|
||||
@ -104,12 +102,7 @@ class ShellTest : public ThreadTest {
|
||||
static int UnreportedTimingsCount(Shell* shell);
|
||||
|
||||
private:
|
||||
void SetSnapshotsAndAssets(Settings& settings);
|
||||
|
||||
std::shared_ptr<TestDartNativeResolver> native_resolver_;
|
||||
ThreadHost thread_host_;
|
||||
fml::UniqueFD assets_dir_;
|
||||
ELFAOTSymbols aot_symbols_;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(ShellTest);
|
||||
};
|
||||
|
||||
@ -82,7 +82,7 @@ source_set("skia") {
|
||||
]
|
||||
}
|
||||
|
||||
source_set("fixture_test") {
|
||||
source_set_maybe_fuchsia_legacy("fixture_test") {
|
||||
testonly = true
|
||||
|
||||
sources = [
|
||||
@ -91,8 +91,11 @@ source_set("fixture_test") {
|
||||
]
|
||||
|
||||
public_deps = [
|
||||
":dart",
|
||||
"//flutter/common",
|
||||
]
|
||||
|
||||
public_deps_legacy_and_next = [
|
||||
":dart",
|
||||
"//flutter/runtime:runtime",
|
||||
]
|
||||
}
|
||||
|
||||
@ -49,5 +49,10 @@ void FixtureTest::SetSnapshotsAndAssets(Settings& settings) {
|
||||
}
|
||||
}
|
||||
|
||||
void FixtureTest::AddNativeCallback(std::string name,
|
||||
Dart_NativeFunction callback) {
|
||||
native_resolver_->AddNativeCallback(std::move(name), callback);
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace flutter
|
||||
|
||||
@ -21,15 +21,19 @@ class FixtureTest : public ThreadTest {
|
||||
public:
|
||||
FixtureTest();
|
||||
|
||||
Settings CreateSettingsForFixture();
|
||||
virtual Settings CreateSettingsForFixture();
|
||||
|
||||
void AddNativeCallback(std::string name, Dart_NativeFunction callback);
|
||||
|
||||
protected:
|
||||
void SetSnapshotsAndAssets(Settings& settings);
|
||||
|
||||
std::shared_ptr<TestDartNativeResolver> native_resolver_;
|
||||
|
||||
private:
|
||||
std::shared_ptr<TestDartNativeResolver> native_resolver_;
|
||||
fml::UniqueFD assets_dir_;
|
||||
ELFAOTSymbols aot_symbols_;
|
||||
|
||||
void SetSnapshotsAndAssets(Settings& settings);
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(FixtureTest);
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user