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 #include "url/gurl.h" |
10 | 11 |
11 namespace content { | 12 namespace content { |
12 | 13 |
13 namespace { | 14 namespace { |
14 | 15 |
15 base::FilePath::CharType kFooPath[] = FILE_PATH_LITERAL("/plugins/foo.plugin"); | 16 base::FilePath::CharType kFooPath[] = FILE_PATH_LITERAL("/plugins/foo.plugin"); |
16 base::FilePath::CharType kBarPath[] = FILE_PATH_LITERAL("/plugins/bar.plugin"); | 17 base::FilePath::CharType kBarPath[] = FILE_PATH_LITERAL("/plugins/bar.plugin"); |
17 const char* kFooName = "Foo Plugin"; | 18 const char* kFooName = "Foo Plugin"; |
| 19 const char* kFooMimeType = "application/x-foo-mime-type"; |
| 20 const char* kFooFileType = "foo"; |
18 | 21 |
19 bool Equals(const WebPluginInfo& a, const WebPluginInfo& b) { | 22 bool Equals(const WebPluginInfo& a, const WebPluginInfo& b) { |
20 return (a.name == b.name && | 23 return (a.name == b.name && |
21 a.path == b.path && | 24 a.path == b.path && |
22 a.version == b.version && | 25 a.version == b.version && |
23 a.desc == b.desc); | 26 a.desc == b.desc); |
24 } | 27 } |
25 | 28 |
26 bool Contains(const std::vector<WebPluginInfo>& list, | 29 bool Contains(const std::vector<WebPluginInfo>& list, |
27 const WebPluginInfo& plugin) { | 30 const WebPluginInfo& plugin) { |
(...skipping 16 matching lines...) Expand all Loading... |
44 ASCIIToUTF16("foo")), | 47 ASCIIToUTF16("foo")), |
45 bar_plugin_(ASCIIToUTF16("Bar Plugin"), | 48 bar_plugin_(ASCIIToUTF16("Bar Plugin"), |
46 base::FilePath(kBarPath), | 49 base::FilePath(kBarPath), |
47 ASCIIToUTF16("2.3.4"), | 50 ASCIIToUTF16("2.3.4"), |
48 ASCIIToUTF16("bar")) { | 51 ASCIIToUTF16("bar")) { |
49 } | 52 } |
50 | 53 |
51 virtual void SetUp() { | 54 virtual void SetUp() { |
52 plugin_list_.DisablePluginsDiscovery(); | 55 plugin_list_.DisablePluginsDiscovery(); |
53 plugin_list_.RegisterInternalPlugin(bar_plugin_, false); | 56 plugin_list_.RegisterInternalPlugin(bar_plugin_, false); |
| 57 foo_plugin_.mime_types.push_back( |
| 58 WebPluginMimeType(kFooMimeType, kFooFileType, std::string())); |
54 plugin_list_.RegisterInternalPlugin(foo_plugin_, false); | 59 plugin_list_.RegisterInternalPlugin(foo_plugin_, false); |
55 } | 60 } |
56 | 61 |
57 protected: | 62 protected: |
58 PluginList plugin_list_; | 63 PluginList plugin_list_; |
59 WebPluginInfo foo_plugin_; | 64 WebPluginInfo foo_plugin_; |
60 WebPluginInfo bar_plugin_; | 65 WebPluginInfo bar_plugin_; |
61 }; | 66 }; |
62 | 67 |
63 TEST_F(PluginListTest, GetPlugins) { | 68 TEST_F(PluginListTest, GetPlugins) { |
(...skipping 10 matching lines...) Expand all Loading... |
74 base::string16(), base::string16()); | 79 base::string16(), base::string16()); |
75 // Simulate loading of the plugins. | 80 // Simulate loading of the plugins. |
76 plugin_list_.RegisterInternalPlugin(plugin_3043, false); | 81 plugin_list_.RegisterInternalPlugin(plugin_3043, false); |
77 // Now we should have them in the state we specified above. | 82 // Now we should have them in the state we specified above. |
78 plugin_list_.RefreshPlugins(); | 83 plugin_list_.RefreshPlugins(); |
79 std::vector<WebPluginInfo> plugins; | 84 std::vector<WebPluginInfo> plugins; |
80 plugin_list_.GetPlugins(&plugins, true); | 85 plugin_list_.GetPlugins(&plugins, true); |
81 ASSERT_TRUE(Contains(plugins, plugin_3043)); | 86 ASSERT_TRUE(Contains(plugins, plugin_3043)); |
82 } | 87 } |
83 | 88 |
| 89 TEST_F(PluginListTest, GetPluginInfoArray) { |
| 90 const char kTargetUrl[] = "http://example.com/test.foo"; |
| 91 GURL target_url(kTargetUrl); |
| 92 std::vector<WebPluginInfo> plugins; |
| 93 std::vector<std::string> actual_mime_types; |
| 94 |
| 95 // The file type of the URL is supported by foo_plugin_. However, |
| 96 // GetPluginInfoArray should not match foo_plugin_ because the MIME type is |
| 97 // application/octet-stream. |
| 98 plugin_list_.GetPluginInfoArray(target_url, |
| 99 "application/octet-stream", |
| 100 false, // allow_wildcard |
| 101 NULL, // use_stale |
| 102 false, // include_npapi |
| 103 &plugins, |
| 104 &actual_mime_types); |
| 105 EXPECT_EQ(0u, plugins.size()); |
| 106 EXPECT_EQ(0u, actual_mime_types.size()); |
| 107 |
| 108 // foo_plugin_ matches due to the MIME type. |
| 109 plugins.clear(); |
| 110 actual_mime_types.clear(); |
| 111 plugin_list_.GetPluginInfoArray(target_url, |
| 112 kFooMimeType, |
| 113 false, // allow_wildcard |
| 114 NULL, // use_stale |
| 115 false, // include_npapi |
| 116 &plugins, |
| 117 &actual_mime_types); |
| 118 EXPECT_EQ(1u, plugins.size()); |
| 119 EXPECT_TRUE(Contains(plugins, foo_plugin_)); |
| 120 ASSERT_EQ(1u, actual_mime_types.size()); |
| 121 EXPECT_EQ(kFooMimeType, actual_mime_types.front()); |
| 122 |
| 123 // foo_plugin_ matches due to the file type and empty MIME type. |
| 124 plugins.clear(); |
| 125 actual_mime_types.clear(); |
| 126 plugin_list_.GetPluginInfoArray(target_url, |
| 127 "", |
| 128 false, // allow_wildcard |
| 129 NULL, // use_stale |
| 130 false, // include_npapi |
| 131 &plugins, |
| 132 &actual_mime_types); |
| 133 EXPECT_EQ(1u, plugins.size()); |
| 134 EXPECT_TRUE(Contains(plugins, foo_plugin_)); |
| 135 ASSERT_EQ(1u, actual_mime_types.size()); |
| 136 EXPECT_EQ(kFooMimeType, actual_mime_types.front()); |
| 137 } |
| 138 |
84 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 139 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
85 | 140 |
86 // Test parsing a simple description: Real Audio. | 141 // Test parsing a simple description: Real Audio. |
87 TEST(MIMEDescriptionParse, Simple) { | 142 TEST(MIMEDescriptionParse, Simple) { |
88 std::vector<WebPluginMimeType> types; | 143 std::vector<WebPluginMimeType> types; |
89 PluginList::ParseMIMEDescription( | 144 PluginList::ParseMIMEDescription( |
90 "audio/x-pn-realaudio-plugin:rpm:RealAudio document;", | 145 "audio/x-pn-realaudio-plugin:rpm:RealAudio document;", |
91 &types); | 146 &types); |
92 ASSERT_EQ(1U, types.size()); | 147 ASSERT_EQ(1U, types.size()); |
93 const WebPluginMimeType& type = types[0]; | 148 const WebPluginMimeType& type = types[0]; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 "IcedTea-Web Plugin " | 242 "IcedTea-Web Plugin " |
188 "(using IcedTea-Web 1.2 (1.2-2ubuntu0.10.04.2))", | 243 "(using IcedTea-Web 1.2 (1.2-2ubuntu0.10.04.2))", |
189 &info); | 244 &info); |
190 EXPECT_EQ(ASCIIToUTF16("1.2"), info.version); | 245 EXPECT_EQ(ASCIIToUTF16("1.2"), info.version); |
191 } | 246 } |
192 | 247 |
193 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) | 248 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) |
194 | 249 |
195 | 250 |
196 } // namespace content | 251 } // namespace content |
OLD | NEW |