diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index e01e277e8fda0..cb5cfc803f811 100755 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -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 diff --git a/lib/ui/BUILD.gn b/lib/ui/BUILD.gn index 2751d6934b980..6df56ae91acdd 100644 --- a/lib/ui/BUILD.gn +++ b/lib/ui/BUILD.gn @@ -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", diff --git a/lib/ui/painting/image_decoder_test.cc b/lib/ui/painting/image_decoder_test.cc deleted file mode 100644 index 6075856e7f38e..0000000000000 --- a/lib/ui/painting/image_decoder_test.cc +++ /dev/null @@ -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()), - 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> kernel_mappings; - kernel_mappings.emplace_back( - fml::FileMapping::CreateReadOnly(assets_dir_, "kernel_blob.bin")); - return kernel_mappings; - }; - } -} - -} // namespace testing -} // namespace flutter diff --git a/lib/ui/painting/image_decoder_test.h b/lib/ui/painting/image_decoder_test.h deleted file mode 100644 index 5b7c58f49953e..0000000000000 --- a/lib/ui/painting/image_decoder_test.h +++ /dev/null @@ -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 - -#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 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_ diff --git a/lib/ui/painting/image_decoder_unittests.cc b/lib/ui/painting/image_decoder_unittests.cc index 6c17157373fd6..582df460d85d7 100644 --- a/lib/ui/painting/image_decoder_unittests.cc +++ b/lib/ui/painting/image_decoder_unittests.cc @@ -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 OpenFixtureAsSkData(const char* name) { return data; } +class ImageDecoderFixtureTest : public FixtureTest {}; + TEST_F(ImageDecoderFixtureTest, CanCreateImageDecoder) { auto loop = fml::ConcurrentMessageLoop::Create(); auto thread_task_runner = CreateNewThread(); diff --git a/runtime/BUILD.gn b/runtime/BUILD.gn index 35524016ad583..a25b428e180fc 100644 --- a/runtime/BUILD.gn +++ b/runtime/BUILD.gn @@ -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", ] } diff --git a/runtime/dart_isolate_unittests.cc b/runtime/dart_isolate_unittests.cc index 283f3801a9e8a..e67945a351ba6 100644 --- a/runtime/dart_isolate_unittests.cc +++ b/runtime/dart_isolate_unittests.cc @@ -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()); diff --git a/runtime/dart_lifecycle_unittests.cc b/runtime/dart_lifecycle_unittests.cc index ffafe1bf0c278..94e3598038d4d 100644 --- a/runtime/dart_lifecycle_unittests.cc +++ b/runtime/dart_lifecycle_unittests.cc @@ -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(); diff --git a/runtime/dart_vm_unittests.cc b/runtime/dart_vm_unittests.cc index 26fa4231fdfb7..4d6c065b3ae25 100644 --- a/runtime/dart_vm_unittests.cc +++ b/runtime/dart_vm_unittests.cc @@ -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()); diff --git a/runtime/runtime_test.cc b/runtime/runtime_test.cc deleted file mode 100644 index 4e92925f5d645..0000000000000 --- a/runtime/runtime_test.cc +++ /dev/null @@ -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()), - 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> 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 diff --git a/runtime/runtime_test.h b/runtime/runtime_test.h deleted file mode 100644 index 6a4a4fc2f8736..0000000000000 --- a/runtime/runtime_test.h +++ /dev/null @@ -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 - -#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 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_ diff --git a/shell/common/BUILD.gn b/shell/common/BUILD.gn index 01fd392d3c986..38c35a34e89d6 100644 --- a/shell/common/BUILD.gn +++ b/shell/common/BUILD.gn @@ -267,6 +267,7 @@ if (enable_unittests) { ":shell_unittests_gpu_configuration", "//flutter/lib/ui:ui", "//flutter/testing:dart", + "//flutter/testing:fixture_test", ] } diff --git a/shell/common/shell_test.cc b/shell/common/shell_test.cc index 8bd7d8b14b24e..c8ebf642e056f 100644 --- a/shell/common/shell_test.cc +++ b/shell/common/shell_test.cc @@ -20,14 +20,9 @@ namespace flutter { namespace testing { ShellTest::ShellTest() - : native_resolver_(std::make_shared()), - 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> 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, latch.Wait(); } -void ShellTest::AddNativeCallback(std::string name, - Dart_NativeFunction callback) { - native_resolver_->AddNativeCallback(std::move(name), callback); -} - } // namespace testing } // namespace flutter diff --git a/shell/common/shell_test.h b/shell/common/shell_test.h index caf055120f0a0..2b46881c3c68f 100644 --- a/shell/common/shell_test.h +++ b/shell/common/shell_test.h @@ -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 CreateShell(Settings settings, bool simulate_vsync = false); std::unique_ptr CreateShell( @@ -48,8 +48,6 @@ class ShellTest : public ThreadTest { void SendEnginePlatformMessage(Shell* shell, fml::RefPtr 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 native_resolver_; ThreadHost thread_host_; - fml::UniqueFD assets_dir_; - ELFAOTSymbols aot_symbols_; FML_DISALLOW_COPY_AND_ASSIGN(ShellTest); }; diff --git a/testing/BUILD.gn b/testing/BUILD.gn index 37aae0fdcb9e7..1ec19a9c20284 100644 --- a/testing/BUILD.gn +++ b/testing/BUILD.gn @@ -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", ] } diff --git a/testing/fixture_test.cc b/testing/fixture_test.cc index ac81612afd5fb..06cb2227fdfeb 100644 --- a/testing/fixture_test.cc +++ b/testing/fixture_test.cc @@ -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 diff --git a/testing/fixture_test.h b/testing/fixture_test.h index 340e29a30d5e1..f48c94319fc99 100644 --- a/testing/fixture_test.h +++ b/testing/fixture_test.h @@ -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); - private: std::shared_ptr native_resolver_; + + private: fml::UniqueFD assets_dir_; ELFAOTSymbols aot_symbols_; - void SetSnapshotsAndAssets(Settings& settings); - FML_DISALLOW_COPY_AND_ASSIGN(FixtureTest); };