Commit 7605150f authored by liberato@chromium.org's avatar liberato@chromium.org Committed by Commit Bot

Switch media/blink unittests to use a mock time source.

Also provides BlinkPlatformWithTaskEnvironment::GetTaskEnvironment()
so that unittests can get access to it.  Previously, it was hidden
in //media/blink/run_all_unittests.cc .

Change-Id: Ib2a13045fd377d603f8b08cba9e78da76dc67099
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1868838Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Commit-Queue: Frank Liberato <liberato@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707511}
parent 2cf46cc0
......@@ -131,6 +131,8 @@ test("media_blink_unittests") {
]
sources = [
"blink_platform_with_task_environment.cc",
"blink_platform_with_task_environment.h",
"buffered_data_source_host_impl_unittest.cc",
"cache_util_unittest.cc",
"interval_map_unittest.cc",
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "media/blink/blink_platform_with_task_environment.h"
namespace media {
BlinkPlatformWithTaskEnvironment::BlinkPlatformWithTaskEnvironment()
: task_environment_(base::test::TaskEnvironment::TimeSource::MOCK_TIME),
main_thread_scheduler_(
blink::scheduler::WebThreadScheduler::CreateMainThreadScheduler()) {}
BlinkPlatformWithTaskEnvironment::~BlinkPlatformWithTaskEnvironment() {
main_thread_scheduler_->Shutdown();
}
blink::scheduler::WebThreadScheduler*
BlinkPlatformWithTaskEnvironment::GetMainThreadScheduler() {
return main_thread_scheduler_.get();
}
// static
base::test::TaskEnvironment*
BlinkPlatformWithTaskEnvironment::GetTaskEnvironment() {
return &static_cast<BlinkPlatformWithTaskEnvironment*>(
blink::Platform::Current())
->task_environment_;
}
} // namespace media
// Copyright 2019 The Chromium 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 MEDIA_BLINK_BLINK_PLATFORM_WITH_TASK_ENVIRONMENT_H_
#define MEDIA_BLINK_BLINK_PLATFORM_WITH_TASK_ENVIRONMENT_H_
#include "base/macros.h"
#include "base/test/task_environment.h"
#include "third_party/blink/public/platform/scheduler/web_thread_scheduler.h"
#include "third_party/blink/public/web/blink.h"
namespace media {
// We must use a custom blink::Platform that ensures the main thread scheduler
// knows about the TaskEnvironment.
class BlinkPlatformWithTaskEnvironment : public blink::Platform {
public:
BlinkPlatformWithTaskEnvironment();
~BlinkPlatformWithTaskEnvironment() override;
blink::scheduler::WebThreadScheduler* GetMainThreadScheduler();
// Returns |task_environment_| from the current blink::Platform.
static base::test::TaskEnvironment* GetTaskEnvironment();
private:
base::test::TaskEnvironment task_environment_;
std::unique_ptr<blink::scheduler::WebThreadScheduler> main_thread_scheduler_;
DISALLOW_COPY_AND_ASSIGN(BlinkPlatformWithTaskEnvironment);
};
} // namespace media
#endif // MEDIA_BLINK_BLINK_PLATFORM_WITH_TASK_ENVIRONMENT_H_
......@@ -5,13 +5,12 @@
#include "base/bind.h"
#include "base/macros.h"
#include "base/test/launcher/unit_test_launcher.h"
#include "base/test/task_environment.h"
#include "base/test/test_suite.h"
#include "build/build_config.h"
#include "media/base/media.h"
#include "media/blink/blink_platform_with_task_environment.h"
#include "services/service_manager/public/cpp/binder_registry.h"
#include "third_party/blink/public/platform/scheduler/test/renderer_scheduler_test_support.h"
#include "third_party/blink/public/platform/scheduler/web_thread_scheduler.h"
#include "third_party/blink/public/web/blink.h"
#if defined(OS_ANDROID)
......@@ -25,6 +24,8 @@
#if defined(V8_USE_EXTERNAL_STARTUP_DATA)
#include "gin/v8_initializer.h"
using media::BlinkPlatformWithTaskEnvironment;
constexpr gin::V8Initializer::V8SnapshotFileType kSnapshotType =
#if defined(USE_V8_CONTEXT_SNAPSHOT)
gin::V8Initializer::V8SnapshotFileType::kWithAdditionalContext;
......@@ -33,30 +34,6 @@ constexpr gin::V8Initializer::V8SnapshotFileType kSnapshotType =
#endif // defined(USE_V8_CONTEXT_SNAPSHOT)
#endif // defined(V8_USE_EXTERNAL_STARTUP_DATA)
// We must use a custom blink::Platform that ensures the main thread scheduler
// knows about the TaskEnvironment.
class BlinkPlatformWithTaskEnvironment : public blink::Platform {
public:
BlinkPlatformWithTaskEnvironment()
: main_thread_scheduler_(
blink::scheduler::WebThreadScheduler::CreateMainThreadScheduler()) {
}
~BlinkPlatformWithTaskEnvironment() override {
main_thread_scheduler_->Shutdown();
}
blink::scheduler::WebThreadScheduler* GetMainThreadScheduler() {
return main_thread_scheduler_.get();
}
private:
base::test::TaskEnvironment task_environment_;
std::unique_ptr<blink::scheduler::WebThreadScheduler> main_thread_scheduler_;
DISALLOW_COPY_AND_ASSIGN(BlinkPlatformWithTaskEnvironment);
};
class MediaBlinkTestSuite : public base::TestSuite {
public:
MediaBlinkTestSuite(int argc, char** argv) : base::TestSuite(argc, argv) {}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment