Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(406)

Side by Side Diff: webkit/plugins/npapi/plugin_list_unittest.cc

Issue 19761007: Move NPAPI implementation out of webkit/plugins/npapi and into content. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix mac Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "webkit/plugins/npapi/plugin_list.h"
6
7 #include "base/strings/string16.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace webkit {
12 namespace npapi {
13
14 namespace {
15
16 bool Equals(const WebPluginInfo& a, const WebPluginInfo& b) {
17 return (a.name == b.name &&
18 a.path == b.path &&
19 a.version == b.version &&
20 a.desc == b.desc);
21 }
22
23 bool Contains(const std::vector<WebPluginInfo>& list,
24 const WebPluginInfo& plugin) {
25 for (std::vector<WebPluginInfo>::const_iterator it = list.begin();
26 it != list.end(); ++it) {
27 if (Equals(*it, plugin))
28 return true;
29 }
30 return false;
31 }
32
33 } // namespace
34
35 // Linux Aura and Android don't support NPAPI.
36 #if defined(OS_WIN) || defined(OS_MACOSX) || (defined(OS_LINUX) && !defined(USE_ AURA))
37
38 base::FilePath::CharType kFooPath[] = FILE_PATH_LITERAL("/plugins/foo.plugin");
39 base::FilePath::CharType kBarPath[] = FILE_PATH_LITERAL("/plugins/bar.plugin");
40 const char* kFooName = "Foo Plugin";
41
42 class PluginListTest : public testing::Test {
43 public:
44 PluginListTest()
45 : foo_plugin_(ASCIIToUTF16(kFooName),
46 base::FilePath(kFooPath),
47 ASCIIToUTF16("1.2.3"),
48 ASCIIToUTF16("foo")),
49 bar_plugin_(ASCIIToUTF16("Bar Plugin"),
50 base::FilePath(kBarPath),
51 ASCIIToUTF16("2.3.4"),
52 ASCIIToUTF16("bar")) {
53 }
54
55 virtual void SetUp() {
56 plugin_list_.DisablePluginsDiscovery();
57 plugin_list_.RegisterInternalPlugin(bar_plugin_, false);
58 plugin_list_.RegisterInternalPlugin(foo_plugin_, false);
59 }
60
61 protected:
62 PluginList plugin_list_;
63 WebPluginInfo foo_plugin_;
64 WebPluginInfo bar_plugin_;
65 };
66
67 TEST_F(PluginListTest, GetPlugins) {
68 std::vector<WebPluginInfo> plugins;
69 plugin_list_.GetPlugins(&plugins);
70 EXPECT_EQ(2u, plugins.size());
71 EXPECT_TRUE(Contains(plugins, foo_plugin_));
72 EXPECT_TRUE(Contains(plugins, bar_plugin_));
73 }
74
75 TEST_F(PluginListTest, BadPluginDescription) {
76 WebPluginInfo plugin_3043(
77 base::string16(), base::FilePath(FILE_PATH_LITERAL("/myplugin.3.0.43")),
78 base::string16(), base::string16());
79 // Simulate loading of the plugins.
80 plugin_list_.RegisterInternalPlugin(plugin_3043, false);
81 // Now we should have them in the state we specified above.
82 plugin_list_.RefreshPlugins();
83 std::vector<WebPluginInfo> plugins;
84 plugin_list_.GetPlugins(&plugins);
85 ASSERT_TRUE(Contains(plugins, plugin_3043));
86 }
87
88 #endif
89
90 #if defined(OS_POSIX) && !defined(OS_MACOSX)
91
92 // Test parsing a simple description: Real Audio.
93 TEST(MIMEDescriptionParse, Simple) {
94 std::vector<WebPluginMimeType> types;
95 PluginList::ParseMIMEDescription(
96 "audio/x-pn-realaudio-plugin:rpm:RealAudio document;",
97 &types);
98 ASSERT_EQ(1U, types.size());
99 const WebPluginMimeType& type = types[0];
100 EXPECT_EQ("audio/x-pn-realaudio-plugin", type.mime_type);
101 ASSERT_EQ(1U, type.file_extensions.size());
102 EXPECT_EQ("rpm", type.file_extensions[0]);
103 EXPECT_EQ(ASCIIToUTF16("RealAudio document"), type.description);
104 }
105
106 // Test parsing a multi-entry description: QuickTime as provided by Totem.
107 TEST(MIMEDescriptionParse, Multi) {
108 std::vector<WebPluginMimeType> types;
109 PluginList::ParseMIMEDescription(
110 "video/quicktime:mov:QuickTime video;video/mp4:mp4:MPEG-4 "
111 "video;image/x-macpaint:pntg:MacPaint Bitmap image;image/x"
112 "-quicktime:pict, pict1, pict2:QuickTime image;video/x-m4v"
113 ":m4v:MPEG-4 video;",
114 &types);
115
116 ASSERT_EQ(5U, types.size());
117
118 // Check the x-quicktime one, since it looks tricky with spaces in the
119 // extension list.
120 const WebPluginMimeType& type = types[3];
121 EXPECT_EQ("image/x-quicktime", type.mime_type);
122 ASSERT_EQ(3U, type.file_extensions.size());
123 EXPECT_EQ("pict2", type.file_extensions[2]);
124 EXPECT_EQ(ASCIIToUTF16("QuickTime image"), type.description);
125 }
126
127 // Test parsing a Japanese description, since we got this wrong in the past.
128 // This comes from loading Totem with LANG=ja_JP.UTF-8.
129 TEST(MIMEDescriptionParse, JapaneseUTF8) {
130 std::vector<WebPluginMimeType> types;
131 PluginList::ParseMIMEDescription(
132 "audio/x-ogg:ogg:Ogg \xe3\x82\xaa\xe3\x83\xbc\xe3\x83\x87"
133 "\xe3\x82\xa3\xe3\x83\xaa",
134 &types);
135
136 ASSERT_EQ(1U, types.size());
137 // Check we got the right number of Unicode characters out of the parse.
138 EXPECT_EQ(9U, types[0].description.size());
139 }
140
141 // Test that we handle corner cases gracefully.
142 TEST(MIMEDescriptionParse, CornerCases) {
143 std::vector<WebPluginMimeType> types;
144 PluginList::ParseMIMEDescription("mime/type:", &types);
145 EXPECT_TRUE(types.empty());
146
147 types.clear();
148 PluginList::ParseMIMEDescription("mime/type:ext1:", &types);
149 ASSERT_EQ(1U, types.size());
150 EXPECT_EQ("mime/type", types[0].mime_type);
151 EXPECT_EQ(1U, types[0].file_extensions.size());
152 EXPECT_EQ("ext1", types[0].file_extensions[0]);
153 EXPECT_EQ(base::string16(), types[0].description);
154 }
155
156 // This Java plugin has embedded semicolons in the mime type.
157 TEST(MIMEDescriptionParse, ComplicatedJava) {
158 std::vector<WebPluginMimeType> types;
159 PluginList::ParseMIMEDescription(
160 "application/x-java-vm:class,jar:IcedTea;application/x-java"
161 "-applet:class,jar:IcedTea;application/x-java-applet;versio"
162 "n=1.1:class,jar:IcedTea;application/x-java-applet;version="
163 "1.1.1:class,jar:IcedTea;application/x-java-applet;version="
164 "1.1.2:class,jar:IcedTea;application/x-java-applet;version="
165 "1.1.3:class,jar:IcedTea;application/x-java-applet;version="
166 "1.2:class,jar:IcedTea;application/x-java-applet;version=1."
167 "2.1:class,jar:IcedTea;application/x-java-applet;version=1."
168 "2.2:class,jar:IcedTea;application/x-java-applet;version=1."
169 "3:class,jar:IcedTea;application/x-java-applet;version=1.3."
170 "1:class,jar:IcedTea;application/x-java-applet;version=1.4:"
171 "class,jar:IcedTea",
172 &types);
173
174 ASSERT_EQ(12U, types.size());
175 for (size_t i = 0; i < types.size(); ++i)
176 EXPECT_EQ(ASCIIToUTF16("IcedTea"), types[i].description);
177
178 // Verify that the mime types with semis are coming through ok.
179 EXPECT_TRUE(types[4].mime_type.find(';') != std::string::npos);
180 }
181
182 // Make sure we understand how to get the version numbers for common Linux
183 // plug-ins.
184 TEST(PluginDescriptionParse, ExtractVersion) {
185 WebPluginInfo info;
186 PluginList::ExtractVersionString("Shockwave Flash 10.1 r102", &info);
187 EXPECT_EQ(ASCIIToUTF16("10.1 r102"), info.version);
188 PluginList::ExtractVersionString("Java(TM) Plug-in 1.6.0_22", &info);
189 EXPECT_EQ(ASCIIToUTF16("1.6.0_22"), info.version);
190 // It's actually much more likely for a modern Linux distribution to have
191 // IcedTea.
192 PluginList::ExtractVersionString(
193 "IcedTea-Web Plugin "
194 "(using IcedTea-Web 1.2 (1.2-2ubuntu0.10.04.2))",
195 &info);
196 EXPECT_EQ(ASCIIToUTF16("1.2"), info.version);
197 }
198
199 #endif // defined(OS_POSIX) && !defined(OS_MACOSX)
200
201
202 } // namespace npapi
203 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698