Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors |
Tom Sepez | 8db30ad | 2018-03-01 21:38:54 | [diff] [blame] | 2 | // 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 Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 8 | #include <optional> |
Tom Sepez | 19fecb3d | 2018-03-02 18:40:21 | [diff] [blame] | 9 | #include <string> |
Tom Sepez | 8db30ad | 2018-03-01 21:38:54 | [diff] [blame] | 10 | #include <utility> |
| 11 | |
Avi Drissman | adac2199 | 2023-01-11 23:46:39 | [diff] [blame] | 12 | #include "base/functional/bind.h" |
Keishi Hattori | c1b0023 | 2022-11-22 09:04:26 | [diff] [blame] | 13 | #include "base/memory/raw_ptr.h" |
Takuto Ikuta | a47d785 | 2024-02-19 03:46:58 | [diff] [blame] | 14 | #include "base/run_loop.h" |
Tom Sepez | 19fecb3d | 2018-03-02 18:40:21 | [diff] [blame] | 15 | #include "base/strings/stringprintf.h" |
Tom Sepez | 8db30ad | 2018-03-01 21:38:54 | [diff] [blame] | 16 | #include "base/strings/utf_string_conversions.h" |
| 17 | #include "build/build_config.h" |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 18 | #include "content/public/browser/browser_task_traits.h" |
Tom Sepez | 8db30ad | 2018-03-01 21:38:54 | [diff] [blame] | 19 | #include "content/public/browser/browser_thread.h" |
K. Moon | 9ae6ef2c | 2022-08-18 01:30:06 | [diff] [blame] | 20 | #include "content/public/common/webplugininfo.h" |
Peter Kasting | 919ce65 | 2020-05-07 10:22:36 | [diff] [blame] | 21 | #include "content/public/test/browser_test.h" |
Tom Sepez | 8db30ad | 2018-03-01 21:38:54 | [diff] [blame] | 22 | #include "content/public/test/content_browser_test.h" |
Tom Sepez | 8db30ad | 2018-03-01 21:38:54 | [diff] [blame] | 23 | #include "testing/gtest/include/gtest/gtest.h" |
Tom Sepez | 8db30ad | 2018-03-01 21:38:54 | [diff] [blame] | 24 | |
Tom Sepez | 8db30ad | 2018-03-01 21:38:54 | [diff] [blame] | 25 | namespace content { |
| 26 | |
Tom Sepez | 8db30ad | 2018-03-01 21:38:54 | [diff] [blame] | 27 | class 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örrie | 8aeb574 | 2021-03-23 19:27:02 | [diff] [blame] | 37 | fake_info.name = u"fake_plugin"; |
Tom Sepez | 8db30ad | 2018-03-01 21:38:54 | [diff] [blame] | 38 | fake_info.path = plugin_path_; |
Tom Sepez | 8db30ad | 2018-03-01 21:38:54 | [diff] [blame] | 39 | |
| 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 Sepez | 8db30ad | 2018-03-01 21:38:54 | [diff] [blame] | 55 | base::FilePath plugin_path_; |
| 56 | base::FilePath profile_dir_; |
| 57 | }; |
| 58 | |
K. Moon | c5aece5 | 2022-08-18 23:24:43 | [diff] [blame] | 59 | IN_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 Sepez | 8db30ad | 2018-03-01 21:38:54 | [diff] [blame] | 70 | } // namespace content |