Commit 5b8a06be authored by Jay Civelli's avatar Jay Civelli Committed by Commit Bot

Add a test to validate CPU info init in media gallery util

Adds a test that validates that the third-party libraries used by the
chrome media gallery util service are using the right CPU info.
This is going to be usefull for an upcoming CL that changes how that
information is set (it'll be passed through IPC).

Bug: 823931
Change-Id: I9e9586af8615739db0baf36ed547ef017546adb5
Reviewed-on: https://chromium-review.googlesource.com/996392Reviewed-by: default avatarKen Rockot <rockot@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Commit-Queue: Jay Civelli <jcivelli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548235}
parent fae27f31
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
import("//media/media_options.gni")
import("//services/service_manager/public/cpp/service.gni") import("//services/service_manager/public/cpp/service.gni")
import("//services/service_manager/public/service_manifest.gni") import("//services/service_manager/public/service_manifest.gni")
...@@ -27,6 +28,13 @@ source_set("lib") { ...@@ -27,6 +28,13 @@ source_set("lib") {
"//chrome/services/media_gallery_util/public/mojom", "//chrome/services/media_gallery_util/public/mojom",
"//services/service_manager/public/cpp", "//services/service_manager/public/cpp",
] ]
if (media_use_ffmpeg) {
deps += [
"//third_party/ffmpeg",
"//third_party/ffmpeg:ffmpeg_features",
]
}
} }
service_manifest("manifest") { service_manifest("manifest") {
......
include_rules = [ include_rules = [
"+content/public", "+content/public",
"+media", "+media",
"+third_party/libyuv",
] ]
...@@ -7,9 +7,13 @@ ...@@ -7,9 +7,13 @@
#include "chrome/services/media_gallery_util/ipc_data_source.h" #include "chrome/services/media_gallery_util/ipc_data_source.h"
#include "chrome/services/media_gallery_util/media_metadata_parser.h" #include "chrome/services/media_gallery_util/media_metadata_parser.h"
#include "media/media_buildflags.h" #include "media/media_buildflags.h"
#include "third_party/libyuv/include/libyuv.h"
#if BUILDFLAG(ENABLE_FFMPEG) #if BUILDFLAG(ENABLE_FFMPEG)
#include "media/filters/media_file_checker.h" #include "media/filters/media_file_checker.h"
extern "C" {
#include <libavutil/cpu.h>
}
#endif #endif
namespace { namespace {
...@@ -54,3 +58,11 @@ void MediaParser::CheckMediaFile(base::TimeDelta decode_time, ...@@ -54,3 +58,11 @@ void MediaParser::CheckMediaFile(base::TimeDelta decode_time,
std::move(callback).Run(false); std::move(callback).Run(false);
#endif #endif
} }
void MediaParser::GetCpuInfo(GetCpuInfoCallback callback) {
int64_t ffmpeg_cpu_flags = 0;
#if BUILDFLAG(ENABLE_FFMPEG)
ffmpeg_cpu_flags = av_get_cpu_flags();
#endif
std::move(callback).Run(libyuv::InitCpuFlags(), ffmpeg_cpu_flags);
}
\ No newline at end of file
...@@ -29,6 +29,7 @@ class MediaParser : public chrome::mojom::MediaParser { ...@@ -29,6 +29,7 @@ class MediaParser : public chrome::mojom::MediaParser {
void CheckMediaFile(base::TimeDelta decode_time, void CheckMediaFile(base::TimeDelta decode_time,
base::File file, base::File file,
CheckMediaFileCallback callback) override; CheckMediaFileCallback callback) override;
void GetCpuInfo(GetCpuInfoCallback callback) override;
const std::unique_ptr<service_manager::ServiceContextRef> service_ref_; const std::unique_ptr<service_manager::ServiceContextRef> service_ref_;
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
import("//media/media_options.gni")
source_set("cpp") { source_set("cpp") {
sources = [ sources = [
"safe_audio_video_checker.cc", "safe_audio_video_checker.cc",
...@@ -19,3 +21,25 @@ source_set("cpp") { ...@@ -19,3 +21,25 @@ source_set("cpp") {
"//chrome/services/media_gallery_util/public/mojom", "//chrome/services/media_gallery_util/public/mojom",
] ]
} }
source_set("browser_tests") {
testonly = true
sources = [
"media_gallery_util_browsertest.cc",
]
defines = [ "HAS_OUT_OF_PROC_TEST_RUNNER" ]
deps = [
"//base",
"//chrome/test:test_support",
"//testing/gtest",
]
if (media_use_ffmpeg) {
deps += [
"//third_party/ffmpeg",
"//third_party/ffmpeg:ffmpeg_features",
]
}
}
// Copyright 2018 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 "chrome/services/media_gallery_util/public/mojom/media_parser.mojom.h"
#include "base/bind.h"
#include "base/run_loop.h"
#include "chrome/services/media_gallery_util/public/mojom/constants.mojom.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "content/public/common/service_manager_connection.h"
#include "media/media_buildflags.h"
#include "services/service_manager/public/cpp/connector.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/libyuv/include/libyuv.h"
#if BUILDFLAG(ENABLE_FFMPEG)
extern "C" {
#include <libavutil/cpu.h>
}
#endif
namespace {
using MediaGalleryUtilBrowserTest = InProcessBrowserTest;
} // namespace
IN_PROC_BROWSER_TEST_F(MediaGalleryUtilBrowserTest, TestThirdPartyCpuInfo) {
service_manager::Connector* connector =
content::ServiceManagerConnection::GetForProcess()->GetConnector();
chrome::mojom::MediaParserPtr media_parser_ptr;
connector->BindInterface(chrome::mojom::kMediaGalleryUtilServiceName,
mojo::MakeRequest(&media_parser_ptr));
base::RunLoop run_loop;
media_parser_ptr->GetCpuInfo(base::BindOnce(
[](base::Closure quit_closure, int64_t libyuv_cpu_flags,
int64_t ffmpeg_cpu_flags) {
int64_t expected_ffmpeg_cpu_flags = 0;
#if BUILDFLAG(ENABLE_FFMPEG)
expected_ffmpeg_cpu_flags = av_get_cpu_flags();
#endif
EXPECT_EQ(expected_ffmpeg_cpu_flags, ffmpeg_cpu_flags);
EXPECT_EQ(libyuv::InitCpuFlags(), libyuv_cpu_flags);
std::move(quit_closure).Run();
},
run_loop.QuitClosure()));
run_loop.Run();
}
...@@ -29,6 +29,10 @@ interface MediaParser { ...@@ -29,6 +29,10 @@ interface MediaParser {
CheckMediaFile(mojo_base.mojom.TimeDelta decode_time, CheckMediaFile(mojo_base.mojom.TimeDelta decode_time,
mojo_base.mojom.File file) mojo_base.mojom.File file)
=> (bool success); => (bool success);
// Used by tests to validate the right CPU information is set on third-party
// libraries.
GetCpuInfo() => (int64 libyuv_cpu_flags, int64 ffmpeg_cpu_flags);
}; };
interface MediaDataSource { interface MediaDataSource {
......
...@@ -1345,6 +1345,7 @@ test("browser_tests") { ...@@ -1345,6 +1345,7 @@ test("browser_tests") {
deps += [ deps += [
"//chrome/common/extensions/api", "//chrome/common/extensions/api",
"//chrome/services/media_gallery_util/public/cpp:browser_tests",
"//chrome/test/media_router:browser_tests", "//chrome/test/media_router:browser_tests",
"//components/guest_view/browser:test_support", "//components/guest_view/browser:test_support",
"//components/keep_alive_registry", "//components/keep_alive_registry",
......
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