diff --git a/runtime/dart_isolate_unittests.cc b/runtime/dart_isolate_unittests.cc index 98644a1fc7c08..a3e03b59b0604 100644 --- a/runtime/dart_isolate_unittests.cc +++ b/runtime/dart_isolate_unittests.cc @@ -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 @@ -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 @@ -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(); @@ -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."; diff --git a/runtime/runtime_test.cc b/runtime/runtime_test.cc index 264e619ffdde3..455a52c95a67a 100644 --- a/runtime/runtime_test.cc +++ b/runtime/runtime_test.cc @@ -11,7 +11,7 @@ namespace flutter { namespace testing { RuntimeTest::RuntimeTest() - : native_resolver_(std::make_shared<::testing::TestDartNativeResolver>()) {} + : native_resolver_(std::make_shared()) {} RuntimeTest::~RuntimeTest() = default; @@ -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(); } diff --git a/runtime/runtime_test.h b/runtime/runtime_test.h index 40f781cf8f97a..8c60a6e858a6c 100644 --- a/runtime/runtime_test.h +++ b/runtime/runtime_test.h @@ -15,7 +15,7 @@ namespace flutter { namespace testing { -class RuntimeTest : public ::testing::ThreadTest { +class RuntimeTest : public ThreadTest { public: RuntimeTest(); @@ -34,7 +34,7 @@ class RuntimeTest : public ::testing::ThreadTest { private: fml::UniqueFD assets_dir_; - std::shared_ptr<::testing::TestDartNativeResolver> native_resolver_; + std::shared_ptr native_resolver_; void SetSnapshotsAndAssets(Settings& settings); }; diff --git a/shell/common/shell_test.cc b/shell/common/shell_test.cc index a6c958f7bbfa8..54bbd9d18f79e 100644 --- a/shell/common/shell_test.cc +++ b/shell/common/shell_test.cc @@ -14,7 +14,7 @@ namespace flutter { namespace testing { ShellTest::ShellTest() - : native_resolver_(std::make_shared<::testing::TestDartNativeResolver>()) {} + : native_resolver_(std::make_shared()) {} ShellTest::~ShellTest() = default; @@ -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( - "io.flutter.test." + ::testing::GetCurrentTestName() + ".", + "io.flutter.test." + GetCurrentTestName() + ".", ThreadHost::Type::Platform | ThreadHost::Type::IO | ThreadHost::Type::UI | ThreadHost::Type::GPU); } @@ -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 ShellTestPlatformView::CreateRenderingSurface() { + return std::make_unique(this); +} + +// |GPUSurfaceSoftwareDelegate| +sk_sp 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 backing_store) { + return true; +} + } // namespace testing } // namespace flutter diff --git a/shell/common/shell_test.h b/shell/common/shell_test.h index c88fde85aa812..e011cb6e9d237 100644 --- a/shell/common/shell_test.h +++ b/shell/common/shell_test.h @@ -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(); @@ -38,12 +40,33 @@ class ShellTest : public ::testing::ThreadTest { private: fml::UniqueFD assets_dir_; - std::shared_ptr<::testing::TestDartNativeResolver> native_resolver_; + std::shared_ptr native_resolver_; std::unique_ptr 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 CreateRenderingSurface() override; + + // |GPUSurfaceSoftwareDelegate| + virtual sk_sp AcquireBackingStore(const SkISize& size) override; + + // |GPUSurfaceSoftwareDelegate| + virtual bool PresentBackingStore(sk_sp backing_store) override; + + FML_DISALLOW_COPY_AND_ASSIGN(ShellTestPlatformView); +}; + } // namespace testing } // namespace flutter diff --git a/shell/common/shell_unittests.cc b/shell/common/shell_unittests.cc index b18cdf2cd1dff..2ad540ee830e2 100644 --- a/shell/common/shell_unittests.cc +++ b/shell/common/shell_unittests.cc @@ -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 CreateRenderingSurface() override { - return std::make_unique(this); - } - - // |GPUSurfaceSoftwareDelegate| - virtual sk_sp 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 backing_store) override { - return true; - } - - FML_DISALLOW_COPY_AND_ASSIGN(TestPlatformView); -}; - static bool ValidateShell(Shell* shell) { if (!shell) { return false; @@ -90,8 +60,8 @@ TEST_F(ShellTest, InitializeWithInvalidThreads) { auto shell = Shell::Create( std::move(task_runners), settings, [](Shell& shell) { - return std::make_unique(shell, - shell.GetTaskRunners()); + return std::make_unique(shell, + shell.GetTaskRunners()); }, [](Shell& shell) { return std::make_unique(shell.GetTaskRunners()); @@ -103,10 +73,9 @@ 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(), @@ -114,8 +83,8 @@ TEST_F(ShellTest, InitializeWithDifferentThreads) { auto shell = Shell::Create( std::move(task_runners), settings, [](Shell& shell) { - return std::make_unique(shell, - shell.GetTaskRunners()); + return std::make_unique(shell, + shell.GetTaskRunners()); }, [](Shell& shell) { return std::make_unique(shell.GetTaskRunners()); @@ -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(shell, - shell.GetTaskRunners()); + return std::make_unique(shell, + shell.GetTaskRunners()); }, [](Shell& shell) { return std::make_unique(shell.GetTaskRunners()); @@ -160,8 +128,8 @@ TEST_F(ShellTest, InitializeWithSingleThreadWhichIsTheCallingThread) { auto shell = Shell::Create( std::move(task_runners), settings, [](Shell& shell) { - return std::make_unique(shell, - shell.GetTaskRunners()); + return std::make_unique(shell, + shell.GetTaskRunners()); }, [](Shell& shell) { return std::make_unique(shell.GetTaskRunners()); @@ -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", @@ -188,8 +156,8 @@ TEST_F(ShellTest, auto shell = Shell::Create( std::move(task_runners), settings, [](Shell& shell) { - return std::make_unique(shell, - shell.GetTaskRunners()); + return std::make_unique(shell, + shell.GetTaskRunners()); }, [](Shell& shell) { return std::make_unique(shell.GetTaskRunners()); @@ -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", @@ -216,8 +184,8 @@ TEST_F(ShellTest, InitializeWithGPUAndPlatformThreadsTheSame) { auto shell = Shell::Create( std::move(task_runners), settings, [](Shell& shell) { - return std::make_unique(shell, - shell.GetTaskRunners()); + return std::make_unique(shell, + shell.GetTaskRunners()); }, [](Shell& shell) { return std::make_unique(shell.GetTaskRunners()); @@ -234,8 +202,8 @@ TEST_F(ShellTest, FixturesAreFunctional) { auto shell = Shell::Create( GetTaskRunnersForFixture(), settings, [](Shell& shell) { - return std::make_unique(shell, - shell.GetTaskRunners()); + return std::make_unique(shell, + shell.GetTaskRunners()); }, [](Shell& shell) { return std::make_unique(shell.GetTaskRunners()); @@ -274,8 +242,8 @@ TEST_F(ShellTest, SecondaryIsolateBindingsAreSetupViaShellSettings) { auto shell = Shell::Create( GetTaskRunnersForFixture(), settings, [](Shell& shell) { - return std::make_unique(shell, - shell.GetTaskRunners()); + return std::make_unique(shell, + shell.GetTaskRunners()); }, [](Shell& shell) { return std::make_unique(shell.GetTaskRunners()); diff --git a/shell/platform/embedder/tests/embedder_a11y_unittests.cc b/shell/platform/embedder/tests/embedder_a11y_unittests.cc index 5da4938175bfb..eb83886ae0eed 100644 --- a/shell/platform/embedder/tests/embedder_a11y_unittests.cc +++ b/shell/platform/embedder/tests/embedder_a11y_unittests.cc @@ -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) { diff --git a/shell/platform/embedder/tests/embedder_context.cc b/shell/platform/embedder/tests/embedder_context.cc index eecec06fe8c9a..46b8c2e6f14bd 100644 --- a/shell/platform/embedder/tests/embedder_context.cc +++ b/shell/platform/embedder/tests/embedder_context.cc @@ -11,7 +11,7 @@ namespace testing { EmbedderContext::EmbedderContext(std::string assets_path) : assets_path_(std::move(assets_path)), - native_resolver_(std::make_shared<::testing::TestDartNativeResolver>()) { + native_resolver_(std::make_shared()) { auto assets_dir = fml::OpenDirectory(assets_path_.c_str(), false, fml::FilePermission::kRead); vm_snapshot_data_ = @@ -27,8 +27,8 @@ EmbedderContext::EmbedderContext(std::string assets_path) } isolate_create_callbacks_.push_back( - [weak_resolver = std::weak_ptr<::testing::TestDartNativeResolver>{ - native_resolver_}]() { + [weak_resolver = + std::weak_ptr{native_resolver_}]() { if (auto resolver = weak_resolver.lock()) { resolver->SetNativeResolverForIsolate(); } diff --git a/shell/platform/embedder/tests/embedder_context.h b/shell/platform/embedder/tests/embedder_context.h index 3ca774ae54c59..5c166063b4c40 100644 --- a/shell/platform/embedder/tests/embedder_context.h +++ b/shell/platform/embedder/tests/embedder_context.h @@ -58,7 +58,7 @@ class EmbedderContext { std::unique_ptr isolate_snapshot_data_; std::unique_ptr isolate_snapshot_instructions_; std::vector isolate_create_callbacks_; - std::shared_ptr<::testing::TestDartNativeResolver> native_resolver_; + std::shared_ptr native_resolver_; SemanticsNodeCallback update_semantics_node_callback_; SemanticsActionCallback update_semantics_custom_action_callback_; diff --git a/shell/platform/embedder/tests/embedder_test.cc b/shell/platform/embedder/tests/embedder_test.cc index 06ae0d21cfcfa..89ca660ba762c 100644 --- a/shell/platform/embedder/tests/embedder_test.cc +++ b/shell/platform/embedder/tests/embedder_test.cc @@ -12,7 +12,7 @@ EmbedderTest::EmbedderTest() = default; EmbedderTest::~EmbedderTest() = default; std::string EmbedderTest::GetFixturesDirectory() const { - return ::testing::GetFixturesPath(); + return GetFixturesPath(); } EmbedderContext& EmbedderTest::GetEmbedderContext() { diff --git a/testing/build/gen_fixtures_location_symbol.py b/testing/build/gen_fixtures_location_symbol.py index 3b66475d4afb8..01f41d2818759 100644 --- a/testing/build/gen_fixtures_location_symbol.py +++ b/testing/build/gen_fixtures_location_symbol.py @@ -19,7 +19,7 @@ def main(): args = parser.parse_args() with open(args.fixtures_location_file, 'w') as file: - file.write('namespace testing {const char* GetFixturesPath() {return "%s";}}' + file.write('namespace flutter {namespace testing {const char* GetFixturesPath() {return "%s";}}}' % args.fixtures_location) diff --git a/testing/run_all_unittests.cc b/testing/run_all_unittests.cc index 1fa0019be22b4..6d5d11c584fa4 100644 --- a/testing/run_all_unittests.cc +++ b/testing/run_all_unittests.cc @@ -5,6 +5,6 @@ #include "gtest/gtest.h" int main(int argc, char** argv) { - testing::InitGoogleTest(&argc, argv); + ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/testing/test_dart_native_resolver.cc b/testing/test_dart_native_resolver.cc index a6d3684ad566b..1a439943358b9 100644 --- a/testing/test_dart_native_resolver.cc +++ b/testing/test_dart_native_resolver.cc @@ -12,6 +12,7 @@ #include "third_party/tonic/logging/dart_error.h" #include "tonic/converter/dart_converter.h" +namespace flutter { namespace testing { TestDartNativeResolver::TestDartNativeResolver() = default; @@ -89,3 +90,4 @@ void TestDartNativeResolver::SetNativeResolverForIsolate() { } } // namespace testing +} // namespace flutter diff --git a/testing/test_dart_native_resolver.h b/testing/test_dart_native_resolver.h index 632824142d930..66050def9b221 100644 --- a/testing/test_dart_native_resolver.h +++ b/testing/test_dart_native_resolver.h @@ -14,7 +14,7 @@ #define CREATE_NATIVE_ENTRY(native_entry) \ ([&]() { \ - static ::testing::NativeEntry closure; \ + static ::flutter::testing::NativeEntry closure; \ static Dart_NativeFunction entrypoint = [](Dart_NativeArguments args) { \ closure(args); \ }; \ @@ -22,6 +22,7 @@ return entrypoint; \ })() +namespace flutter { namespace testing { using NativeEntry = std::function; @@ -51,5 +52,6 @@ class TestDartNativeResolver }; } // namespace testing +} // namespace flutter #endif // FLUTTER_TESTING_TEST_DART_NATIVE_RESOLVER_H_ diff --git a/testing/testing.cc b/testing/testing.cc index c738219541452..2e2225a568036 100644 --- a/testing/testing.cc +++ b/testing/testing.cc @@ -4,10 +4,12 @@ #include "testing.h" +namespace flutter { namespace testing { std::string GetCurrentTestName() { - return UnitTest::GetInstance()->current_test_info()->name(); + return ::testing::UnitTest::GetInstance()->current_test_info()->name(); } } // namespace testing +} // namespace flutter diff --git a/testing/testing.h b/testing/testing.h index 0662055fea502..00fe3806488dc 100644 --- a/testing/testing.h +++ b/testing/testing.h @@ -9,6 +9,7 @@ #include "gtest/gtest.h" +namespace flutter { namespace testing { // Returns the directory containing the test fixture for the target if this @@ -19,5 +20,6 @@ const char* GetFixturesPath(); std::string GetCurrentTestName(); } // namespace testing +} // namespace flutter #endif // TESTING_TESTING_H_ diff --git a/testing/thread_test.cc b/testing/thread_test.cc index 978d9af532bb6..986afd4e62fbb 100644 --- a/testing/thread_test.cc +++ b/testing/thread_test.cc @@ -6,6 +6,7 @@ #include "flutter/testing/thread_test.h" +namespace flutter { namespace testing { // |testing::Test| @@ -33,3 +34,4 @@ fml::RefPtr ThreadTest::GetThreadTaskRunner() { } } // namespace testing +} // namespace flutter diff --git a/testing/thread_test.h b/testing/thread_test.h index e4af5e1241b87..6d168b0d0c01a 100644 --- a/testing/thread_test.h +++ b/testing/thread_test.h @@ -13,9 +13,10 @@ #include "flutter/fml/thread.h" #include "gtest/gtest.h" +namespace flutter { namespace testing { -class ThreadTest : public Test { +class ThreadTest : public ::testing::Test { public: fml::RefPtr GetCurrentTaskRunner(); @@ -35,5 +36,6 @@ class ThreadTest : public Test { }; } // namespace testing +} // namespace flutter #endif // FLUTTER_TESTING_THREAD_TEST_H_