| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/common/plugin_list.h" | 5 #include "content/common/plugin_list.h" |
| 6 | 6 |
| 7 #include "base/strings/string16.h" | 7 #include "base/strings/string16.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 using webkit::WebPluginInfo; | 11 using webkit::WebPluginInfo; |
| 12 using webkit::WebPluginMimeType; | 12 using webkit::WebPluginMimeType; |
| 13 | 13 |
| 14 namespace content { | 14 namespace content { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 base::FilePath::CharType kFooPath[] = FILE_PATH_LITERAL("/plugins/foo.plugin"); |
| 19 base::FilePath::CharType kBarPath[] = FILE_PATH_LITERAL("/plugins/bar.plugin"); |
| 20 const char* kFooName = "Foo Plugin"; |
| 21 |
| 18 bool Equals(const WebPluginInfo& a, const WebPluginInfo& b) { | 22 bool Equals(const WebPluginInfo& a, const WebPluginInfo& b) { |
| 19 return (a.name == b.name && | 23 return (a.name == b.name && |
| 20 a.path == b.path && | 24 a.path == b.path && |
| 21 a.version == b.version && | 25 a.version == b.version && |
| 22 a.desc == b.desc); | 26 a.desc == b.desc); |
| 23 } | 27 } |
| 24 | 28 |
| 25 bool Contains(const std::vector<WebPluginInfo>& list, | 29 bool Contains(const std::vector<WebPluginInfo>& list, |
| 26 const WebPluginInfo& plugin) { | 30 const WebPluginInfo& plugin) { |
| 27 for (std::vector<WebPluginInfo>::const_iterator it = list.begin(); | 31 for (std::vector<WebPluginInfo>::const_iterator it = list.begin(); |
| 28 it != list.end(); ++it) { | 32 it != list.end(); ++it) { |
| 29 if (Equals(*it, plugin)) | 33 if (Equals(*it, plugin)) |
| 30 return true; | 34 return true; |
| 31 } | 35 } |
| 32 return false; | 36 return false; |
| 33 } | 37 } |
| 34 | 38 |
| 35 } // namespace | 39 } // namespace |
| 36 | 40 |
| 37 // Linux Aura and Android don't support NPAPI. | |
| 38 #if defined(OS_WIN) || defined(OS_MACOSX) || (defined(OS_LINUX) && !defined(USE_
AURA)) | |
| 39 | |
| 40 base::FilePath::CharType kFooPath[] = FILE_PATH_LITERAL("/plugins/foo.plugin"); | |
| 41 base::FilePath::CharType kBarPath[] = FILE_PATH_LITERAL("/plugins/bar.plugin"); | |
| 42 const char* kFooName = "Foo Plugin"; | |
| 43 | |
| 44 class PluginListTest : public testing::Test { | 41 class PluginListTest : public testing::Test { |
| 45 public: | 42 public: |
| 46 PluginListTest() | 43 PluginListTest() |
| 47 : foo_plugin_(ASCIIToUTF16(kFooName), | 44 : foo_plugin_(ASCIIToUTF16(kFooName), |
| 48 base::FilePath(kFooPath), | 45 base::FilePath(kFooPath), |
| 49 ASCIIToUTF16("1.2.3"), | 46 ASCIIToUTF16("1.2.3"), |
| 50 ASCIIToUTF16("foo")), | 47 ASCIIToUTF16("foo")), |
| 51 bar_plugin_(ASCIIToUTF16("Bar Plugin"), | 48 bar_plugin_(ASCIIToUTF16("Bar Plugin"), |
| 52 base::FilePath(kBarPath), | 49 base::FilePath(kBarPath), |
| 53 ASCIIToUTF16("2.3.4"), | 50 ASCIIToUTF16("2.3.4"), |
| 54 ASCIIToUTF16("bar")) { | 51 ASCIIToUTF16("bar")) { |
| 55 } | 52 } |
| 56 | 53 |
| 57 virtual void SetUp() { | 54 virtual void SetUp() { |
| 58 plugin_list_.DisablePluginsDiscovery(); | 55 plugin_list_.DisablePluginsDiscovery(); |
| 59 plugin_list_.RegisterInternalPlugin(bar_plugin_, false); | 56 plugin_list_.RegisterInternalPlugin(bar_plugin_, false); |
| 60 plugin_list_.RegisterInternalPlugin(foo_plugin_, false); | 57 plugin_list_.RegisterInternalPlugin(foo_plugin_, false); |
| 61 } | 58 } |
| 62 | 59 |
| 63 protected: | 60 protected: |
| 64 PluginList plugin_list_; | 61 PluginList plugin_list_; |
| 65 WebPluginInfo foo_plugin_; | 62 WebPluginInfo foo_plugin_; |
| 66 WebPluginInfo bar_plugin_; | 63 WebPluginInfo bar_plugin_; |
| 67 }; | 64 }; |
| 68 | 65 |
| 69 TEST_F(PluginListTest, GetPlugins) { | 66 TEST_F(PluginListTest, GetPlugins) { |
| 70 std::vector<WebPluginInfo> plugins; | 67 std::vector<WebPluginInfo> plugins; |
| 71 plugin_list_.GetPlugins(&plugins); | 68 plugin_list_.GetPlugins(&plugins, true); |
| 72 EXPECT_EQ(2u, plugins.size()); | 69 EXPECT_EQ(2u, plugins.size()); |
| 73 EXPECT_TRUE(Contains(plugins, foo_plugin_)); | 70 EXPECT_TRUE(Contains(plugins, foo_plugin_)); |
| 74 EXPECT_TRUE(Contains(plugins, bar_plugin_)); | 71 EXPECT_TRUE(Contains(plugins, bar_plugin_)); |
| 75 } | 72 } |
| 76 | 73 |
| 77 TEST_F(PluginListTest, BadPluginDescription) { | 74 TEST_F(PluginListTest, BadPluginDescription) { |
| 78 WebPluginInfo plugin_3043( | 75 WebPluginInfo plugin_3043( |
| 79 base::string16(), base::FilePath(FILE_PATH_LITERAL("/myplugin.3.0.43")), | 76 base::string16(), base::FilePath(FILE_PATH_LITERAL("/myplugin.3.0.43")), |
| 80 base::string16(), base::string16()); | 77 base::string16(), base::string16()); |
| 81 // Simulate loading of the plugins. | 78 // Simulate loading of the plugins. |
| 82 plugin_list_.RegisterInternalPlugin(plugin_3043, false); | 79 plugin_list_.RegisterInternalPlugin(plugin_3043, false); |
| 83 // Now we should have them in the state we specified above. | 80 // Now we should have them in the state we specified above. |
| 84 plugin_list_.RefreshPlugins(); | 81 plugin_list_.RefreshPlugins(); |
| 85 std::vector<WebPluginInfo> plugins; | 82 std::vector<WebPluginInfo> plugins; |
| 86 plugin_list_.GetPlugins(&plugins); | 83 plugin_list_.GetPlugins(&plugins, true); |
| 87 ASSERT_TRUE(Contains(plugins, plugin_3043)); | 84 ASSERT_TRUE(Contains(plugins, plugin_3043)); |
| 88 } | 85 } |
| 89 | 86 |
| 90 #endif | |
| 91 | |
| 92 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 87 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 93 | 88 |
| 94 // Test parsing a simple description: Real Audio. | 89 // Test parsing a simple description: Real Audio. |
| 95 TEST(MIMEDescriptionParse, Simple) { | 90 TEST(MIMEDescriptionParse, Simple) { |
| 96 std::vector<WebPluginMimeType> types; | 91 std::vector<WebPluginMimeType> types; |
| 97 PluginList::ParseMIMEDescription( | 92 PluginList::ParseMIMEDescription( |
| 98 "audio/x-pn-realaudio-plugin:rpm:RealAudio document;", | 93 "audio/x-pn-realaudio-plugin:rpm:RealAudio document;", |
| 99 &types); | 94 &types); |
| 100 ASSERT_EQ(1U, types.size()); | 95 ASSERT_EQ(1U, types.size()); |
| 101 const WebPluginMimeType& type = types[0]; | 96 const WebPluginMimeType& type = types[0]; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 "IcedTea-Web Plugin " | 190 "IcedTea-Web Plugin " |
| 196 "(using IcedTea-Web 1.2 (1.2-2ubuntu0.10.04.2))", | 191 "(using IcedTea-Web 1.2 (1.2-2ubuntu0.10.04.2))", |
| 197 &info); | 192 &info); |
| 198 EXPECT_EQ(ASCIIToUTF16("1.2"), info.version); | 193 EXPECT_EQ(ASCIIToUTF16("1.2"), info.version); |
| 199 } | 194 } |
| 200 | 195 |
| 201 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) | 196 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) |
| 202 | 197 |
| 203 | 198 |
| 204 } // namespace content | 199 } // namespace content |
| OLD | NEW |