Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Put the testing lib in the flutter namespace. #8661

Merged
merged 1 commit into from
Apr 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions runtime/dart_isolate_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ TEST_F(DartIsolateTest, RootIsolateCreationAndShutdown) {
ASSERT_TRUE(vm_ref);
auto vm_data = vm_ref.GetVMData();
ASSERT_TRUE(vm_data);
TaskRunners task_runners(::testing::GetCurrentTestName(), //
GetCurrentTaskRunner(), //
GetCurrentTaskRunner(), //
GetCurrentTaskRunner(), //
GetCurrentTaskRunner() //
TaskRunners task_runners(GetCurrentTestName(), //
GetCurrentTaskRunner(), //
GetCurrentTaskRunner(), //
GetCurrentTaskRunner(), //
GetCurrentTaskRunner() //
);
auto weak_isolate = DartIsolate::CreateRootIsolate(
vm_data->GetSettings(), // settings
Expand Down Expand Up @@ -62,11 +62,11 @@ TEST_F(DartIsolateTest, IsolateShutdownCallbackIsInIsolateScope) {
ASSERT_TRUE(vm_ref);
auto vm_data = vm_ref.GetVMData();
ASSERT_TRUE(vm_data);
TaskRunners task_runners(::testing::GetCurrentTestName(), //
GetCurrentTaskRunner(), //
GetCurrentTaskRunner(), //
GetCurrentTaskRunner(), //
GetCurrentTaskRunner() //
TaskRunners task_runners(GetCurrentTestName(), //
GetCurrentTaskRunner(), //
GetCurrentTaskRunner(), //
GetCurrentTaskRunner(), //
GetCurrentTaskRunner() //
);
auto weak_isolate = DartIsolate::CreateRootIsolate(
vm_data->GetSettings(), // settings
Expand Down Expand Up @@ -164,11 +164,11 @@ static void RunDartCodeInIsolate(DartVMRef& vm_ref,
return;
}

TaskRunners task_runners(::testing::GetCurrentTestName(), //
task_runner, //
task_runner, //
task_runner, //
task_runner //
TaskRunners task_runners(GetCurrentTestName(), //
task_runner, //
task_runner, //
task_runner, //
task_runner //
);

auto vm_data = vm_ref.GetVMData();
Expand Down Expand Up @@ -206,8 +206,8 @@ static void RunDartCodeInIsolate(DartVMRef& vm_ref,
}

if (!DartVM::IsRunningPrecompiledCode()) {
auto kernel_file_path = fml::paths::JoinPaths(
{::testing::GetFixturesPath(), "kernel_blob.bin"});
auto kernel_file_path =
fml::paths::JoinPaths({GetFixturesPath(), "kernel_blob.bin"});

if (!fml::IsFile(kernel_file_path)) {
FML_LOG(ERROR) << "Could not locate kernel file.";
Expand Down
6 changes: 3 additions & 3 deletions runtime/runtime_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace flutter {
namespace testing {

RuntimeTest::RuntimeTest()
: native_resolver_(std::make_shared<::testing::TestDartNativeResolver>()) {}
: native_resolver_(std::make_shared<TestDartNativeResolver>()) {}

RuntimeTest::~RuntimeTest() = default;

Expand Down Expand Up @@ -69,8 +69,8 @@ Settings RuntimeTest::CreateSettingsForFixture() {

// |testing::ThreadTest|
void RuntimeTest::SetUp() {
assets_dir_ = fml::OpenDirectory(::testing::GetFixturesPath(), false,
fml::FilePermission::kRead);
assets_dir_ =
fml::OpenDirectory(GetFixturesPath(), false, fml::FilePermission::kRead);
ThreadTest::SetUp();
}

Expand Down
4 changes: 2 additions & 2 deletions runtime/runtime_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
namespace flutter {
namespace testing {

class RuntimeTest : public ::testing::ThreadTest {
class RuntimeTest : public ThreadTest {
public:
RuntimeTest();

Expand All @@ -34,7 +34,7 @@ class RuntimeTest : public ::testing::ThreadTest {

private:
fml::UniqueFD assets_dir_;
std::shared_ptr<::testing::TestDartNativeResolver> native_resolver_;
std::shared_ptr<TestDartNativeResolver> native_resolver_;

void SetSnapshotsAndAssets(Settings& settings);
};
Expand Down
33 changes: 29 additions & 4 deletions shell/common/shell_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace flutter {
namespace testing {

ShellTest::ShellTest()
: native_resolver_(std::make_shared<::testing::TestDartNativeResolver>()) {}
: native_resolver_(std::make_shared<TestDartNativeResolver>()) {}

ShellTest::~ShellTest() = default;

Expand Down Expand Up @@ -87,10 +87,10 @@ TaskRunners ShellTest::GetTaskRunnersForFixture() {
// |testing::ThreadTest|
void ShellTest::SetUp() {
ThreadTest::SetUp();
assets_dir_ = fml::OpenDirectory(::testing::GetFixturesPath(), false,
fml::FilePermission::kRead);
assets_dir_ =
fml::OpenDirectory(GetFixturesPath(), false, fml::FilePermission::kRead);
thread_host_ = std::make_unique<ThreadHost>(
"io.flutter.test." + ::testing::GetCurrentTestName() + ".",
"io.flutter.test." + GetCurrentTestName() + ".",
ThreadHost::Type::Platform | ThreadHost::Type::IO | ThreadHost::Type::UI |
ThreadHost::Type::GPU);
}
Expand All @@ -107,5 +107,30 @@ void ShellTest::AddNativeCallback(std::string name,
native_resolver_->AddNativeCallback(std::move(name), callback);
}

ShellTestPlatformView::ShellTestPlatformView(PlatformView::Delegate& delegate,
TaskRunners task_runners)
: PlatformView(delegate, std::move(task_runners)) {}

ShellTestPlatformView::~ShellTestPlatformView() = default;

// |PlatformView|
std::unique_ptr<Surface> ShellTestPlatformView::CreateRenderingSurface() {
return std::make_unique<GPUSurfaceSoftware>(this);
}

// |GPUSurfaceSoftwareDelegate|
sk_sp<SkSurface> ShellTestPlatformView::AcquireBackingStore(
const SkISize& size) {
SkImageInfo image_info = SkImageInfo::MakeN32Premul(
size.width(), size.height(), SkColorSpace::MakeSRGB());
return SkSurface::MakeRaster(image_info);
}

// |GPUSurfaceSoftwareDelegate|
bool ShellTestPlatformView::PresentBackingStore(
sk_sp<SkSurface> backing_store) {
return true;
}

} // namespace testing
} // namespace flutter
27 changes: 25 additions & 2 deletions shell/common/shell_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
#include "flutter/common/settings.h"
#include "flutter/fml/macros.h"
#include "flutter/shell/common/run_configuration.h"
#include "flutter/shell/common/shell.h"
#include "flutter/shell/common/thread_host.h"
#include "flutter/shell/gpu/gpu_surface_software.h"
#include "flutter/testing/test_dart_native_resolver.h"
#include "flutter/testing/thread_test.h"

namespace flutter {
namespace testing {

class ShellTest : public ::testing::ThreadTest {
class ShellTest : public ThreadTest {
public:
ShellTest();

Expand All @@ -38,12 +40,33 @@ class ShellTest : public ::testing::ThreadTest {

private:
fml::UniqueFD assets_dir_;
std::shared_ptr<::testing::TestDartNativeResolver> native_resolver_;
std::shared_ptr<TestDartNativeResolver> native_resolver_;
std::unique_ptr<ThreadHost> thread_host_;

void SetSnapshotsAndAssets(Settings& settings);
};

class ShellTestPlatformView : public PlatformView,
public GPUSurfaceSoftwareDelegate {
public:
ShellTestPlatformView(PlatformView::Delegate& delegate,
TaskRunners task_runners);

~ShellTestPlatformView() override;

private:
// |PlatformView|
std::unique_ptr<Surface> CreateRenderingSurface() override;

// |GPUSurfaceSoftwareDelegate|
virtual sk_sp<SkSurface> AcquireBackingStore(const SkISize& size) override;

// |GPUSurfaceSoftwareDelegate|
virtual bool PresentBackingStore(sk_sp<SkSurface> backing_store) override;

FML_DISALLOW_COPY_AND_ASSIGN(ShellTestPlatformView);
};

} // namespace testing
} // namespace flutter

Expand Down
78 changes: 23 additions & 55 deletions shell/common/shell_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,13 @@
#include "flutter/fml/synchronization/waitable_event.h"
#include "flutter/shell/common/platform_view.h"
#include "flutter/shell/common/rasterizer.h"
#include "flutter/shell/common/shell.h"
#include "flutter/shell/common/shell_test.h"
#include "flutter/shell/common/thread_host.h"
#include "flutter/shell/gpu/gpu_surface_software.h"
#include "flutter/testing/testing.h"
#include "gtest/gtest.h"

namespace flutter {
namespace testing {

class TestPlatformView : public PlatformView,
public GPUSurfaceSoftwareDelegate {
public:
TestPlatformView(PlatformView::Delegate& delegate, TaskRunners task_runners)
: PlatformView(delegate, std::move(task_runners)) {}

private:
// |PlatformView|
std::unique_ptr<Surface> CreateRenderingSurface() override {
return std::make_unique<GPUSurfaceSoftware>(this);
}

// |GPUSurfaceSoftwareDelegate|
virtual sk_sp<SkSurface> AcquireBackingStore(const SkISize& size) override {
SkImageInfo image_info = SkImageInfo::MakeN32Premul(
size.width(), size.height(), SkColorSpace::MakeSRGB());
return SkSurface::MakeRaster(image_info);
}

// |GPUSurfaceSoftwareDelegate|
virtual bool PresentBackingStore(sk_sp<SkSurface> backing_store) override {
return true;
}

FML_DISALLOW_COPY_AND_ASSIGN(TestPlatformView);
};

static bool ValidateShell(Shell* shell) {
if (!shell) {
return false;
Expand Down Expand Up @@ -90,8 +60,8 @@ TEST_F(ShellTest, InitializeWithInvalidThreads) {
auto shell = Shell::Create(
std::move(task_runners), settings,
[](Shell& shell) {
return std::make_unique<TestPlatformView>(shell,
shell.GetTaskRunners());
return std::make_unique<ShellTestPlatformView>(shell,
shell.GetTaskRunners());
},
[](Shell& shell) {
return std::make_unique<Rasterizer>(shell.GetTaskRunners());
Expand All @@ -103,19 +73,18 @@ TEST_F(ShellTest, InitializeWithInvalidThreads) {
TEST_F(ShellTest, InitializeWithDifferentThreads) {
ASSERT_FALSE(DartVMRef::IsInstanceRunning());
Settings settings = CreateSettingsForFixture();
ThreadHost thread_host(
"io.flutter.test." + ::testing::GetCurrentTestName() + ".",
ThreadHost::Type::Platform | ThreadHost::Type::GPU |
ThreadHost::Type::IO | ThreadHost::Type::UI);
ThreadHost thread_host("io.flutter.test." + GetCurrentTestName() + ".",
ThreadHost::Type::Platform | ThreadHost::Type::GPU |
ThreadHost::Type::IO | ThreadHost::Type::UI);
TaskRunners task_runners("test", thread_host.platform_thread->GetTaskRunner(),
thread_host.gpu_thread->GetTaskRunner(),
thread_host.ui_thread->GetTaskRunner(),
thread_host.io_thread->GetTaskRunner());
auto shell = Shell::Create(
std::move(task_runners), settings,
[](Shell& shell) {
return std::make_unique<TestPlatformView>(shell,
shell.GetTaskRunners());
return std::make_unique<ShellTestPlatformView>(shell,
shell.GetTaskRunners());
},
[](Shell& shell) {
return std::make_unique<Rasterizer>(shell.GetTaskRunners());
Expand All @@ -129,17 +98,16 @@ TEST_F(ShellTest, InitializeWithDifferentThreads) {
TEST_F(ShellTest, InitializeWithSingleThread) {
ASSERT_FALSE(DartVMRef::IsInstanceRunning());
Settings settings = CreateSettingsForFixture();
ThreadHost thread_host(
"io.flutter.test." + ::testing::GetCurrentTestName() + ".",
ThreadHost::Type::Platform);
ThreadHost thread_host("io.flutter.test." + GetCurrentTestName() + ".",
ThreadHost::Type::Platform);
auto task_runner = thread_host.platform_thread->GetTaskRunner();
TaskRunners task_runners("test", task_runner, task_runner, task_runner,
task_runner);
auto shell = Shell::Create(
std::move(task_runners), settings,
[](Shell& shell) {
return std::make_unique<TestPlatformView>(shell,
shell.GetTaskRunners());
return std::make_unique<ShellTestPlatformView>(shell,
shell.GetTaskRunners());
},
[](Shell& shell) {
return std::make_unique<Rasterizer>(shell.GetTaskRunners());
Expand All @@ -160,8 +128,8 @@ TEST_F(ShellTest, InitializeWithSingleThreadWhichIsTheCallingThread) {
auto shell = Shell::Create(
std::move(task_runners), settings,
[](Shell& shell) {
return std::make_unique<TestPlatformView>(shell,
shell.GetTaskRunners());
return std::make_unique<ShellTestPlatformView>(shell,
shell.GetTaskRunners());
},
[](Shell& shell) {
return std::make_unique<Rasterizer>(shell.GetTaskRunners());
Expand All @@ -177,7 +145,7 @@ TEST_F(ShellTest,
ASSERT_FALSE(DartVMRef::IsInstanceRunning());
Settings settings = CreateSettingsForFixture();
ThreadHost thread_host(
"io.flutter.test." + ::testing::GetCurrentTestName() + ".",
"io.flutter.test." + GetCurrentTestName() + ".",
ThreadHost::Type::GPU | ThreadHost::Type::IO | ThreadHost::Type::UI);
fml::MessageLoop::EnsureInitializedForCurrentThread();
TaskRunners task_runners("test",
Expand All @@ -188,8 +156,8 @@ TEST_F(ShellTest,
auto shell = Shell::Create(
std::move(task_runners), settings,
[](Shell& shell) {
return std::make_unique<TestPlatformView>(shell,
shell.GetTaskRunners());
return std::make_unique<ShellTestPlatformView>(shell,
shell.GetTaskRunners());
},
[](Shell& shell) {
return std::make_unique<Rasterizer>(shell.GetTaskRunners());
Expand All @@ -204,7 +172,7 @@ TEST_F(ShellTest, InitializeWithGPUAndPlatformThreadsTheSame) {
ASSERT_FALSE(DartVMRef::IsInstanceRunning());
Settings settings = CreateSettingsForFixture();
ThreadHost thread_host(
"io.flutter.test." + ::testing::GetCurrentTestName() + ".",
"io.flutter.test." + GetCurrentTestName() + ".",
ThreadHost::Type::Platform | ThreadHost::Type::IO | ThreadHost::Type::UI);
TaskRunners task_runners(
"test",
Expand All @@ -216,8 +184,8 @@ TEST_F(ShellTest, InitializeWithGPUAndPlatformThreadsTheSame) {
auto shell = Shell::Create(
std::move(task_runners), settings,
[](Shell& shell) {
return std::make_unique<TestPlatformView>(shell,
shell.GetTaskRunners());
return std::make_unique<ShellTestPlatformView>(shell,
shell.GetTaskRunners());
},
[](Shell& shell) {
return std::make_unique<Rasterizer>(shell.GetTaskRunners());
Expand All @@ -234,8 +202,8 @@ TEST_F(ShellTest, FixturesAreFunctional) {
auto shell = Shell::Create(
GetTaskRunnersForFixture(), settings,
[](Shell& shell) {
return std::make_unique<TestPlatformView>(shell,
shell.GetTaskRunners());
return std::make_unique<ShellTestPlatformView>(shell,
shell.GetTaskRunners());
},
[](Shell& shell) {
return std::make_unique<Rasterizer>(shell.GetTaskRunners());
Expand Down Expand Up @@ -274,8 +242,8 @@ TEST_F(ShellTest, SecondaryIsolateBindingsAreSetupViaShellSettings) {
auto shell = Shell::Create(
GetTaskRunnersForFixture(), settings,
[](Shell& shell) {
return std::make_unique<TestPlatformView>(shell,
shell.GetTaskRunners());
return std::make_unique<ShellTestPlatformView>(shell,
shell.GetTaskRunners());
},
[](Shell& shell) {
return std::make_unique<Rasterizer>(shell.GetTaskRunners());
Expand Down
2 changes: 1 addition & 1 deletion shell/platform/embedder/tests/embedder_a11y_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ TEST_F(Embedder11yTest, A11yTreeIsConsistent) {
})));

// Called by test fixture on UI thread to pass data back to this test.
::testing::NativeEntry callback;
NativeEntry callback;
context.AddNativeCallback(
"NotifyTestData",
CREATE_NATIVE_ENTRY(([&callback](Dart_NativeArguments args) {
Expand Down
Loading