chromium/third_party/blink/renderer/platform/scheduler/worker/non_main_thread_impl_unittest.cc

// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/platform/scheduler/worker/non_main_thread_impl.h"

#include "base/functional/bind.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/synchronization/waitable_event.h"
#include "build/build_config.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/scheduler/worker/worker_thread_scheduler.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h"

_;
AnyOf;
ElementsAre;
Invoke;

namespace blink {
namespace scheduler {
namespace worker_thread_unittest {

class MockTask {};

class MockIdleTask {};

class TestObserver : public Thread::TaskObserver {};

void RunTestTask(StringBuilder* calls) {}

void AddTaskObserver(Thread* thread, TestObserver* observer) {}

void RemoveTaskObserver(Thread* thread, TestObserver* observer) {}

void ShutdownOnThread(Thread* thread) {}

class NonMainThreadImplTest : public testing::Test {};

TEST_F(NonMainThreadImplTest, TestDefaultTask) {}

TEST_F(NonMainThreadImplTest, TestTaskObserver) {}

TEST_F(NonMainThreadImplTest, TestShutdown) {}

}  // namespace worker_thread_unittest

// Needs to be in scheduler namespace for FRIEND_TEST_ALL_PREFIXES to work
#if BUILDFLAG(IS_APPLE)
TEST(NonMainThreadImplRealtimePeriodTest, RealtimePeriodConfiguration) {
  ThreadCreationParams params(ThreadType::kTestThread);
  params.realtime_period = base::Milliseconds(10);

  auto non_main_thread = std::make_unique<NonMainThreadImpl>(params);
  non_main_thread->Init();
  // No period configuration for a non-real-time thread.
  EXPECT_EQ(static_cast<base::PlatformThread::Delegate*>(
                non_main_thread->thread_.get())
                ->GetRealtimePeriod(),
            base::TimeDelta());

  params.base_thread_type = base::ThreadType::kRealtimeAudio;

  non_main_thread = std::make_unique<NonMainThreadImpl>(params);
  non_main_thread->Init();
  // Delegate correctly reports period for a real-time thread.
  EXPECT_EQ(static_cast<base::PlatformThread::Delegate*>(
                non_main_thread->thread_.get())
                ->GetRealtimePeriod(),
            params.realtime_period);
}
#endif

}  // namespace scheduler
}  // namespace blink