Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
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
4 changes: 4 additions & 0 deletions testing/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]

Expand Down
33 changes: 33 additions & 0 deletions testing/thread_test.cc
Original file line number Diff line number Diff line change
@@ -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<fml::Thread>();
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<fml::TaskRunner> ThreadTest::GetCurrentTaskRunner() {
return current_task_runner_;
}

fxl::RefPtr<fml::TaskRunner> ThreadTest::GetThreadTaskRunner() {
return thread_task_runner_;
}

} // namespace testing
37 changes: 37 additions & 0 deletions testing/thread_test.h
Original file line number Diff line number Diff line change
@@ -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 <memory>

#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<fml::TaskRunner> GetCurrentTaskRunner();

fxl::RefPtr<fml::TaskRunner> GetThreadTaskRunner();

protected:
void SetUp() override;

void TearDown() override;

private:
std::unique_ptr<fml::Thread> thread_;
fxl::RefPtr<fml::TaskRunner> thread_task_runner_;
fxl::RefPtr<fml::TaskRunner> current_task_runner_;
};

} // namespace testing

#endif // FLUTTER_TESTING_THREAD_TEST_H_