#include "chrome/browser/plugins/plugin_info_host_impl.h"
#include <stddef.h>
#include <memory>
#include <string>
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/i18n/base_i18n_switches.h"
#include "base/i18n/rtl.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/gmock_move_support.h"
#include "base/test/mock_callback.h"
#include "build/branding_buildflags.h"
#include "chrome/browser/chrome_browser_main_extra_parts_nacl_deprecation.h"
#include "chrome/browser/plugins/plugin_prefs.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_content_client.h"
#include "chrome/common/plugin.mojom.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "components/nacl/common/buildflags.h"
#include "content/public/browser/plugin_service.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/webplugininfo.h"
#include "content/public/test/browser_test.h"
#include "pdf/buildflags.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkColor.h"
#include "url/gurl.h"
#include "url/origin.h"
#if BUILDFLAG(ENABLE_NACL)
#include "components/nacl/common/nacl_constants.h"
#include "ppapi/shared_impl/ppapi_permissions.h"
#endif
#if BUILDFLAG(ENABLE_PDF)
#include "components/pdf/common/constants.h"
#endif
namespace {
PluginInfo;
PluginInfoHost;
PluginInfoPtr;
PluginStatus;
WebPluginInfo;
WebPluginMimeType;
Contains;
ElementsAre;
Field;
IsEmpty;
SizeIs;
}
class PluginInfoHostImplTest : public InProcessBrowserTest { … };
#if BUILDFLAG(ENABLE_PDF)
class PluginInfoHostImplBidiTest : public PluginInfoHostImplTest,
public testing::WithParamInterface<bool> { … };
#endif
IN_PROC_BROWSER_TEST_F(PluginInfoHostImplTest, CoverAllPlugins) { … }
IN_PROC_BROWSER_TEST_F(PluginInfoHostImplTest, GetPluginInfoForFlash) { … }
IN_PROC_BROWSER_TEST_F(PluginInfoHostImplTest, GetPluginInfoForFutureSplash) { … }
#if BUILDFLAG(ENABLE_NACL)
IN_PROC_BROWSER_TEST_F(PluginInfoHostImplTest, GetPluginInfoForNaCl) {
const std::u16string kPluginName = base::UTF8ToUTF16(nacl::kNaClPluginName);
const base::FilePath kPluginPath =
base::FilePath(nacl::kInternalNaClPluginFileName);
PluginInfoPtr plugin_info = GetPluginInfo(
GURL("fake-resource"), url::Origin(), nacl::kNaClPluginMimeType);
ASSERT_TRUE(plugin_info);
EXPECT_EQ(PluginStatus::kPlayImportantContent, plugin_info->status);
EXPECT_EQ(nacl::kNaClPluginMimeType, plugin_info->actual_mime_type);
EXPECT_EQ(kPluginPath.BaseName().AsUTF8Unsafe(),
plugin_info->group_identifier);
EXPECT_EQ(kPluginName, plugin_info->group_name);
EXPECT_EQ(kPluginName, plugin_info->plugin.name);
EXPECT_EQ(kPluginPath, plugin_info->plugin.path);
EXPECT_EQ(u"", plugin_info->plugin.version);
EXPECT_EQ(u"", plugin_info->plugin.desc);
EXPECT_EQ(WebPluginInfo::PLUGIN_TYPE_PEPPER_IN_PROCESS,
plugin_info->plugin.type);
EXPECT_EQ(ppapi::PERMISSION_PRIVATE | ppapi::PERMISSION_DEV,
plugin_info->plugin.pepper_permissions);
EXPECT_EQ(WebPluginInfo::kDefaultBackgroundColor,
plugin_info->plugin.background_color);
ASSERT_THAT(plugin_info->plugin.mime_types, SizeIs(2));
WebPluginMimeType nacl_mime_type = plugin_info->plugin.mime_types[0];
EXPECT_EQ(nacl::kNaClPluginMimeType, nacl_mime_type.mime_type);
EXPECT_THAT(nacl_mime_type.file_extensions,
ElementsAre(nacl::kNaClPluginExtension));
EXPECT_EQ(base::UTF8ToUTF16(nacl::kNaClPluginDescription),
nacl_mime_type.description);
EXPECT_THAT(nacl_mime_type.additional_params, IsEmpty());
WebPluginMimeType pnacl_mime_type = plugin_info->plugin.mime_types[1];
EXPECT_EQ(nacl::kPnaclPluginMimeType, pnacl_mime_type.mime_type);
EXPECT_THAT(pnacl_mime_type.file_extensions,
ElementsAre(nacl::kPnaclPluginExtension));
EXPECT_EQ(base::UTF8ToUTF16(nacl::kPnaclPluginDescription),
pnacl_mime_type.description);
EXPECT_THAT(pnacl_mime_type.additional_params, IsEmpty());
}
IN_PROC_BROWSER_TEST_F(PluginInfoHostImplTest, GetPluginInfoForPnacl) {
const std::u16string kPluginName = base::UTF8ToUTF16(nacl::kNaClPluginName);
const base::FilePath kPluginPath =
base::FilePath(nacl::kInternalNaClPluginFileName);
PluginInfoPtr plugin_info = GetPluginInfo(
GURL("fake-resource"), url::Origin(), nacl::kPnaclPluginMimeType);
ASSERT_TRUE(plugin_info);
EXPECT_EQ(PluginStatus::kPlayImportantContent, plugin_info->status);
EXPECT_EQ(nacl::kPnaclPluginMimeType, plugin_info->actual_mime_type);
EXPECT_EQ(kPluginPath.BaseName().AsUTF8Unsafe(),
plugin_info->group_identifier);
EXPECT_EQ(kPluginName, plugin_info->group_name);
EXPECT_EQ(kPluginName, plugin_info->plugin.name);
EXPECT_EQ(kPluginPath, plugin_info->plugin.path);
EXPECT_EQ(u"", plugin_info->plugin.version);
EXPECT_EQ(u"", plugin_info->plugin.desc);
EXPECT_EQ(WebPluginInfo::PLUGIN_TYPE_PEPPER_IN_PROCESS,
plugin_info->plugin.type);
EXPECT_EQ(ppapi::PERMISSION_PRIVATE | ppapi::PERMISSION_DEV,
plugin_info->plugin.pepper_permissions);
EXPECT_EQ(WebPluginInfo::kDefaultBackgroundColor,
plugin_info->plugin.background_color);
ASSERT_THAT(plugin_info->plugin.mime_types, SizeIs(2));
WebPluginMimeType nacl_mime_type = plugin_info->plugin.mime_types[0];
EXPECT_EQ(nacl::kNaClPluginMimeType, nacl_mime_type.mime_type);
EXPECT_THAT(nacl_mime_type.file_extensions,
ElementsAre(nacl::kNaClPluginExtension));
EXPECT_EQ(base::UTF8ToUTF16(nacl::kNaClPluginDescription),
nacl_mime_type.description);
EXPECT_THAT(nacl_mime_type.additional_params, IsEmpty());
WebPluginMimeType pnacl_mime_type = plugin_info->plugin.mime_types[1];
EXPECT_EQ(nacl::kPnaclPluginMimeType, pnacl_mime_type.mime_type);
EXPECT_THAT(pnacl_mime_type.file_extensions,
ElementsAre(nacl::kPnaclPluginExtension));
EXPECT_EQ(base::UTF8ToUTF16(nacl::kPnaclPluginDescription),
pnacl_mime_type.description);
EXPECT_THAT(pnacl_mime_type.additional_params, IsEmpty());
}
#endif
#if BUILDFLAG(ENABLE_PDF)
IN_PROC_BROWSER_TEST_P(PluginInfoHostImplBidiTest,
GetPluginInfoForPdfViewerExtension) { … }
IN_PROC_BROWSER_TEST_P(PluginInfoHostImplBidiTest,
GetPluginInfoForPdfViewerExtensionWhenDisabled) { … }
IN_PROC_BROWSER_TEST_F(PluginInfoHostImplTest,
GetPluginInfoForPdfInternalPlugin) { … }
IN_PROC_BROWSER_TEST_F(PluginInfoHostImplTest,
GetPluginInfoForPdfInternalPluginWhenDisabled) { … }
INSTANTIATE_TEST_SUITE_P(…);
#endif