Skip to content

Commit

Permalink
Use FixtureTest to remove duplicate code (flutter#19219)
Browse files Browse the repository at this point in the history
  • Loading branch information
liyuqian authored Jun 30, 2020
1 parent 36a7060 commit e9e59f4
Show file tree
Hide file tree
Showing 17 changed files with 35 additions and 258 deletions.
4 changes: 0 additions & 4 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions lib/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
53 changes: 0 additions & 53 deletions lib/ui/painting/image_decoder_test.cc

This file was deleted.

39 changes: 0 additions & 39 deletions lib/ui/painting/image_decoder_test.h

This file was deleted.

5 changes: 3 additions & 2 deletions lib/ui/painting/image_decoder_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions runtime/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -136,6 +134,7 @@ source_set_maybe_fuchsia_legacy("runtime_unittests_common") {
deps_legacy_and_next = [
":runtime",
"//flutter/testing:dart",
"//flutter/testing:fixture_test",
]
}

Expand Down
5 changes: 2 additions & 3 deletions runtime/dart_isolate_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions runtime/dart_lifecycle_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions runtime/dart_vm_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
60 changes: 0 additions & 60 deletions runtime/runtime_test.cc

This file was deleted.

40 changes: 0 additions & 40 deletions runtime/runtime_test.h

This file was deleted.

1 change: 1 addition & 0 deletions shell/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ if (enable_unittests) {
":shell_unittests_gpu_configuration",
"//flutter/lib/ui:ui",
"//flutter/testing:dart",
"//flutter/testing:fixture_test",
]
}

Expand Down
35 changes: 2 additions & 33 deletions shell/common/shell_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -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
Loading

0 comments on commit e9e59f4

Please sign in to comment.