diff --git a/testing/BUILD.gn b/testing/BUILD.gn index 3927e71cfc0e4..a65311bfaeb7c 100644 --- a/testing/BUILD.gn +++ b/testing/BUILD.gn @@ -9,9 +9,13 @@ source_set("testing") { "$flutter_root/testing/run_all_unittests.cc", "$flutter_root/testing/testing.cc", "$flutter_root/testing/testing.h", + "$flutter_root/testing/thread_test.cc", + "$flutter_root/testing/thread_test.h", ] public_deps = [ + "$flutter_root/fml", + "//garnet/public/lib/fxl", "//third_party/googletest:gtest", ] diff --git a/testing/thread_test.cc b/testing/thread_test.cc new file mode 100644 index 0000000000000..1306f37678fbe --- /dev/null +++ b/testing/thread_test.cc @@ -0,0 +1,33 @@ +// Copyright 2017 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. + +#define FML_USED_ON_EMBEDDER + +#include "flutter/testing/thread_test.h" + +namespace testing { + +void ThreadTest::SetUp() { + thread_ = std::make_unique(); + thread_task_runner_ = thread_->GetTaskRunner(); + + fml::MessageLoop::EnsureInitializedForCurrentThread(); + current_task_runner_ = fml::MessageLoop::GetCurrent().GetTaskRunner(); +} + +void ThreadTest::TearDown() { + thread_task_runner_ = nullptr; + thread_ = nullptr; + current_task_runner_ = nullptr; +} + +fxl::RefPtr ThreadTest::GetCurrentTaskRunner() { + return current_task_runner_; +} + +fxl::RefPtr ThreadTest::GetThreadTaskRunner() { + return thread_task_runner_; +} + +} // namespace testing diff --git a/testing/thread_test.h b/testing/thread_test.h new file mode 100644 index 0000000000000..511d09c978858 --- /dev/null +++ b/testing/thread_test.h @@ -0,0 +1,37 @@ +// Copyright 2017 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_TESTING_THREAD_TEST_H_ +#define FLUTTER_TESTING_THREAD_TEST_H_ + +#include + +#include "flutter/fml/message_loop.h" +#include "flutter/fml/task_runner.h" +#include "flutter/fml/thread.h" +#include "gtest/gtest.h" +#include "lib/fxl/macros.h" + +namespace testing { + +class ThreadTest : public Test { + public: + fxl::RefPtr GetCurrentTaskRunner(); + + fxl::RefPtr GetThreadTaskRunner(); + + protected: + void SetUp() override; + + void TearDown() override; + + private: + std::unique_ptr thread_; + fxl::RefPtr thread_task_runner_; + fxl::RefPtr current_task_runner_; +}; + +} // namespace testing + +#endif // FLUTTER_TESTING_THREAD_TEST_H_