blob: 0a2b26a312c5c984fcdaba9fdb66a1a0a077c883 [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2018 The Chromium Authors
Tom Sepez8db30ad2018-03-01 21:38:542// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "content/browser/plugin_service_impl.h"
6
7#include <memory>
Arthur Sonzognic686e8f2024-01-11 08:36:378#include <optional>
Tom Sepez19fecb3d2018-03-02 18:40:219#include <string>
Tom Sepez8db30ad2018-03-01 21:38:5410#include <utility>
11
Avi Drissmanadac21992023-01-11 23:46:3912#include "base/functional/bind.h"
Keishi Hattoric1b00232022-11-22 09:04:2613#include "base/memory/raw_ptr.h"
Takuto Ikutaa47d7852024-02-19 03:46:5814#include "base/run_loop.h"
Tom Sepez19fecb3d2018-03-02 18:40:2115#include "base/strings/stringprintf.h"
Tom Sepez8db30ad2018-03-01 21:38:5416#include "base/strings/utf_string_conversions.h"
17#include "build/build_config.h"
Eric Seckler8652dcd52018-09-20 10:42:2818#include "content/public/browser/browser_task_traits.h"
Tom Sepez8db30ad2018-03-01 21:38:5419#include "content/public/browser/browser_thread.h"
K. Moon9ae6ef2c2022-08-18 01:30:0620#include "content/public/common/webplugininfo.h"
Peter Kasting919ce652020-05-07 10:22:3621#include "content/public/test/browser_test.h"
Tom Sepez8db30ad2018-03-01 21:38:5422#include "content/public/test/content_browser_test.h"
Tom Sepez8db30ad2018-03-01 21:38:5423#include "testing/gtest/include/gtest/gtest.h"
Tom Sepez8db30ad2018-03-01 21:38:5424
Tom Sepez8db30ad2018-03-01 21:38:5425namespace content {
26
Tom Sepez8db30ad2018-03-01 21:38:5427class PluginServiceImplBrowserTest : public ContentBrowserTest {
28 public:
29 PluginServiceImplBrowserTest()
30 : plugin_path_(FILE_PATH_LITERAL("internal-nonesuch")),
31 profile_dir_(FILE_PATH_LITERAL("/fake/user/foo/dir")) {}
32
33 ~PluginServiceImplBrowserTest() override = default;
34
35 void RegisterFakePlugin() {
36 WebPluginInfo fake_info;
Jan Wilken Dörrie8aeb5742021-03-23 19:27:0237 fake_info.name = u"fake_plugin";
Tom Sepez8db30ad2018-03-01 21:38:5438 fake_info.path = plugin_path_;
Tom Sepez8db30ad2018-03-01 21:38:5439
40 PluginServiceImpl* service = PluginServiceImpl::GetInstance();
41 service->RegisterInternalPlugin(fake_info, true);
42 service->Init();
43
44 // Force plugins to load and wait for completion.
45 base::RunLoop run_loop;
46 service->GetPlugins(base::BindOnce(
47 [](base::OnceClosure callback,
48 const std::vector<WebPluginInfo>& ignore) {
49 std::move(callback).Run();
50 },
51 run_loop.QuitClosure()));
52 run_loop.Run();
53 }
54
Tom Sepez8db30ad2018-03-01 21:38:5455 base::FilePath plugin_path_;
56 base::FilePath profile_dir_;
57};
58
K. Moonc5aece52022-08-18 23:24:4359IN_PROC_BROWSER_TEST_F(PluginServiceImplBrowserTest, GetPluginInfoByPath) {
60 RegisterFakePlugin();
61
62 PluginServiceImpl* service = PluginServiceImpl::GetInstance();
63
64 WebPluginInfo plugin_info;
65 ASSERT_TRUE(service->GetPluginInfoByPath(plugin_path_, &plugin_info));
66
67 EXPECT_EQ(plugin_path_, plugin_info.path);
68}
69
Tom Sepez8db30ad2018-03-01 21:38:5470} // namespace content