Chromium Code Reviews| 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 "webkit/plugins/npapi/plugin_list.h" | 5 #include "webkit/plugins/npapi/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 #include "url/gurl.h" | |
| 10 | 11 |
| 11 namespace webkit { | 12 namespace webkit { |
| 12 namespace npapi { | 13 namespace npapi { |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 bool Equals(const WebPluginInfo& a, const WebPluginInfo& b) { | 17 bool Equals(const WebPluginInfo& a, const WebPluginInfo& b) { |
| 17 return (a.name == b.name && | 18 return (a.name == b.name && |
| 18 a.path == b.path && | 19 a.path == b.path && |
| 19 a.version == b.version && | 20 a.version == b.version && |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 31 } | 32 } |
| 32 | 33 |
| 33 } // namespace | 34 } // namespace |
| 34 | 35 |
| 35 // Linux Aura and Android don't support NPAPI. | 36 // Linux Aura and Android don't support NPAPI. |
| 36 #if defined(OS_WIN) || defined(OS_MACOSX) || (defined(OS_LINUX) && !defined(USE_ AURA)) | 37 #if defined(OS_WIN) || defined(OS_MACOSX) || (defined(OS_LINUX) && !defined(USE_ AURA)) |
| 37 | 38 |
| 38 base::FilePath::CharType kFooPath[] = FILE_PATH_LITERAL("/plugins/foo.plugin"); | 39 base::FilePath::CharType kFooPath[] = FILE_PATH_LITERAL("/plugins/foo.plugin"); |
| 39 base::FilePath::CharType kBarPath[] = FILE_PATH_LITERAL("/plugins/bar.plugin"); | 40 base::FilePath::CharType kBarPath[] = FILE_PATH_LITERAL("/plugins/bar.plugin"); |
| 40 const char* kFooName = "Foo Plugin"; | 41 const char* kFooName = "Foo Plugin"; |
| 42 const char* kFooMimeType = "application/x-foo-mime-type"; | |
| 43 const char* kFooFileType = "foo"; | |
| 41 | 44 |
| 42 class PluginListTest : public testing::Test { | 45 class PluginListTest : public testing::Test { |
| 43 public: | 46 public: |
| 44 PluginListTest() | 47 PluginListTest() |
| 45 : foo_plugin_(ASCIIToUTF16(kFooName), | 48 : foo_plugin_(ASCIIToUTF16(kFooName), |
| 46 base::FilePath(kFooPath), | 49 base::FilePath(kFooPath), |
| 47 ASCIIToUTF16("1.2.3"), | 50 ASCIIToUTF16("1.2.3"), |
| 48 ASCIIToUTF16("foo")), | 51 ASCIIToUTF16("foo")), |
| 49 bar_plugin_(ASCIIToUTF16("Bar Plugin"), | 52 bar_plugin_(ASCIIToUTF16("Bar Plugin"), |
| 50 base::FilePath(kBarPath), | 53 base::FilePath(kBarPath), |
| 51 ASCIIToUTF16("2.3.4"), | 54 ASCIIToUTF16("2.3.4"), |
| 52 ASCIIToUTF16("bar")) { | 55 ASCIIToUTF16("bar")) { |
| 53 } | 56 } |
| 54 | 57 |
| 55 virtual void SetUp() { | 58 virtual void SetUp() { |
| 56 plugin_list_.DisablePluginsDiscovery(); | 59 plugin_list_.DisablePluginsDiscovery(); |
| 57 plugin_list_.RegisterInternalPlugin(bar_plugin_, false); | 60 plugin_list_.RegisterInternalPlugin(bar_plugin_, false); |
| 61 foo_plugin_.mime_types.push_back( | |
| 62 WebPluginMimeType(kFooMimeType, kFooFileType, "")); | |
|
Bernhard Bauer
2013/07/18 21:17:10
Nit: Using an empty constructor is slightly more e
asanka
2013/07/18 21:23:52
Done.
| |
| 58 plugin_list_.RegisterInternalPlugin(foo_plugin_, false); | 63 plugin_list_.RegisterInternalPlugin(foo_plugin_, false); |
| 59 } | 64 } |
| 60 | 65 |
| 61 protected: | 66 protected: |
| 62 PluginList plugin_list_; | 67 PluginList plugin_list_; |
| 63 WebPluginInfo foo_plugin_; | 68 WebPluginInfo foo_plugin_; |
| 64 WebPluginInfo bar_plugin_; | 69 WebPluginInfo bar_plugin_; |
| 65 }; | 70 }; |
| 66 | 71 |
| 67 TEST_F(PluginListTest, GetPlugins) { | 72 TEST_F(PluginListTest, GetPlugins) { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 78 base::string16(), base::string16()); | 83 base::string16(), base::string16()); |
| 79 // Simulate loading of the plugins. | 84 // Simulate loading of the plugins. |
| 80 plugin_list_.RegisterInternalPlugin(plugin_3043, false); | 85 plugin_list_.RegisterInternalPlugin(plugin_3043, false); |
| 81 // Now we should have them in the state we specified above. | 86 // Now we should have them in the state we specified above. |
| 82 plugin_list_.RefreshPlugins(); | 87 plugin_list_.RefreshPlugins(); |
| 83 std::vector<WebPluginInfo> plugins; | 88 std::vector<WebPluginInfo> plugins; |
| 84 plugin_list_.GetPlugins(&plugins); | 89 plugin_list_.GetPlugins(&plugins); |
| 85 ASSERT_TRUE(Contains(plugins, plugin_3043)); | 90 ASSERT_TRUE(Contains(plugins, plugin_3043)); |
| 86 } | 91 } |
| 87 | 92 |
| 93 TEST_F(PluginListTest, GetPluginInfoArray) { | |
| 94 const char kTargetUrl[] = "http://example.com/test.foo"; | |
| 95 GURL target_url(kTargetUrl); | |
| 96 std::vector<WebPluginInfo> plugins; | |
| 97 std::vector<std::string> actual_mime_types; | |
| 98 | |
| 99 // The file type of the URL is supported by foo_plugin_. However, | |
| 100 // GetPluginInfoArray should not match foo_plugin_ because the MIME type is | |
| 101 // application/octet-stream. | |
| 102 plugin_list_.GetPluginInfoArray(target_url, | |
| 103 "application/octet-stream", | |
| 104 false, // allow_wildcard | |
| 105 NULL, // use_stale | |
| 106 &plugins, | |
| 107 &actual_mime_types); | |
| 108 EXPECT_EQ(0u, plugins.size()); | |
| 109 EXPECT_EQ(0u, actual_mime_types.size()); | |
| 110 | |
| 111 // foo_plugin_ matches due to the MIME type. | |
| 112 plugins.clear(); | |
| 113 actual_mime_types.clear(); | |
| 114 plugin_list_.GetPluginInfoArray(target_url, | |
| 115 kFooMimeType, | |
| 116 false, // allow_wildcard | |
| 117 NULL, // use_stale | |
| 118 &plugins, | |
| 119 &actual_mime_types); | |
| 120 EXPECT_EQ(1u, plugins.size()); | |
| 121 EXPECT_TRUE(Contains(plugins, foo_plugin_)); | |
| 122 ASSERT_EQ(1u, actual_mime_types.size()); | |
| 123 EXPECT_EQ(kFooMimeType, actual_mime_types.front()); | |
| 124 | |
| 125 // foo_plugin_ matches due to the file type and empty MIME type. | |
| 126 plugins.clear(); | |
| 127 actual_mime_types.clear(); | |
| 128 plugin_list_.GetPluginInfoArray(target_url, | |
| 129 "", | |
| 130 false, // allow_wildcard | |
| 131 NULL, // use_stale | |
| 132 &plugins, | |
| 133 &actual_mime_types); | |
| 134 EXPECT_EQ(1u, plugins.size()); | |
| 135 EXPECT_TRUE(Contains(plugins, foo_plugin_)); | |
| 136 ASSERT_EQ(1u, actual_mime_types.size()); | |
| 137 EXPECT_EQ(kFooMimeType, actual_mime_types.front()); | |
| 138 } | |
| 139 | |
| 88 #endif | 140 #endif |
| 89 | 141 |
| 90 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 142 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 91 | 143 |
| 92 // Test parsing a simple description: Real Audio. | 144 // Test parsing a simple description: Real Audio. |
| 93 TEST(MIMEDescriptionParse, Simple) { | 145 TEST(MIMEDescriptionParse, Simple) { |
| 94 std::vector<WebPluginMimeType> types; | 146 std::vector<WebPluginMimeType> types; |
| 95 PluginList::ParseMIMEDescription( | 147 PluginList::ParseMIMEDescription( |
| 96 "audio/x-pn-realaudio-plugin:rpm:RealAudio document;", | 148 "audio/x-pn-realaudio-plugin:rpm:RealAudio document;", |
| 97 &types); | 149 &types); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 "(using IcedTea-Web 1.2 (1.2-2ubuntu0.10.04.2))", | 246 "(using IcedTea-Web 1.2 (1.2-2ubuntu0.10.04.2))", |
| 195 &info); | 247 &info); |
| 196 EXPECT_EQ(ASCIIToUTF16("1.2"), info.version); | 248 EXPECT_EQ(ASCIIToUTF16("1.2"), info.version); |
| 197 } | 249 } |
| 198 | 250 |
| 199 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) | 251 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) |
| 200 | 252 |
| 201 | 253 |
| 202 } // namespace npapi | 254 } // namespace npapi |
| 203 } // namespace webkit | 255 } // namespace webkit |
| OLD | NEW |