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

Side by Side Diff: webkit/glue/plugins/plugin_lib_unittest.cc

Issue 6012002: Move the NPAPI files from webkit/glue/plugins to webkit/plugins/npapi and put... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years 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
« no previous file with comments | « webkit/glue/plugins/plugin_lib_posix.cc ('k') | webkit/glue/plugins/plugin_lib_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2009 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/glue/plugins/plugin_lib.h"
6
7 #include "base/string_util.h"
8 #include "base/utf_string_conversions.h"
9 #include "build/build_config.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 // Test the unloading of plugin libs. Bug http://crbug.com/46526 showed that
13 // if UnloadAllPlugins() simply iterates through the g_loaded_libs global
14 // variable, we can get a crash if no plugin libs were marked as always loaded.
15 class PluginLibTest : public NPAPI::PluginLib {
16 public:
17 PluginLibTest() : NPAPI::PluginLib(WebPluginInfo(), NULL) {
18 }
19 using NPAPI::PluginLib::Unload;
20 };
21
22 TEST(PluginLibLoading, UnloadAllPlugins) {
23 // For the creation of the g_loaded_libs global variable.
24 ASSERT_EQ(static_cast<PluginLibTest*>(NULL),
25 PluginLibTest::CreatePluginLib(FilePath()));
26
27 // Try with a single plugin lib.
28 scoped_refptr<PluginLibTest> plugin_lib1(new PluginLibTest());
29 NPAPI::PluginLib::UnloadAllPlugins();
30
31 // Need to create it again, it should have been destroyed above.
32 ASSERT_EQ(static_cast<PluginLibTest*>(NULL),
33 PluginLibTest::CreatePluginLib(FilePath()));
34
35 // Try with two plugin libs.
36 plugin_lib1 = new PluginLibTest();
37 scoped_refptr<PluginLibTest> plugin_lib2(new PluginLibTest());
38 NPAPI::PluginLib::UnloadAllPlugins();
39
40 // Need to create it again, it should have been destroyed above.
41 ASSERT_EQ(static_cast<PluginLibTest*>(NULL),
42 PluginLibTest::CreatePluginLib(FilePath()));
43
44 // Now try to manually Unload one and then UnloadAll.
45 plugin_lib1 = new PluginLibTest();
46 plugin_lib2 = new PluginLibTest();
47 plugin_lib1->Unload();
48 NPAPI::PluginLib::UnloadAllPlugins();
49
50 // Need to create it again, it should have been destroyed above.
51 ASSERT_EQ(static_cast<PluginLibTest*>(NULL),
52 PluginLibTest::CreatePluginLib(FilePath()));
53
54 // Now try to manually Unload the only one and then UnloadAll.
55 plugin_lib1 = new PluginLibTest();
56 plugin_lib1->Unload();
57 NPAPI::PluginLib::UnloadAllPlugins();
58 }
59
60 #if defined(OS_LINUX)
61
62 // Test parsing a simple description: Real Audio.
63 TEST(MIMEDescriptionParse, Simple) {
64 std::vector<WebPluginMimeType> types;
65 NPAPI::PluginLib::ParseMIMEDescription(
66 "audio/x-pn-realaudio-plugin:rpm:RealAudio document;",
67 &types);
68 ASSERT_EQ(1U, types.size());
69 const WebPluginMimeType& type = types[0];
70 EXPECT_EQ("audio/x-pn-realaudio-plugin", type.mime_type);
71 ASSERT_EQ(1U, type.file_extensions.size());
72 EXPECT_EQ("rpm", type.file_extensions[0]);
73 EXPECT_EQ(ASCIIToUTF16("RealAudio document"), type.description);
74 }
75
76 // Test parsing a multi-entry description: QuickTime as provided by Totem.
77 TEST(MIMEDescriptionParse, Multi) {
78 std::vector<WebPluginMimeType> types;
79 NPAPI::PluginLib::ParseMIMEDescription(
80 "video/quicktime:mov:QuickTime video;video/mp4:mp4:MPEG-4 "
81 "video;image/x-macpaint:pntg:MacPaint Bitmap image;image/x"
82 "-quicktime:pict, pict1, pict2:QuickTime image;video/x-m4v"
83 ":m4v:MPEG-4 video;",
84 &types);
85
86 ASSERT_EQ(5U, types.size());
87
88 // Check the x-quicktime one, since it looks tricky with spaces in the
89 // extension list.
90 const WebPluginMimeType& type = types[3];
91 EXPECT_EQ("image/x-quicktime", type.mime_type);
92 ASSERT_EQ(3U, type.file_extensions.size());
93 EXPECT_EQ("pict2", type.file_extensions[2]);
94 EXPECT_EQ(ASCIIToUTF16("QuickTime image"), type.description);
95 }
96
97 // Test parsing a Japanese description, since we got this wrong in the past.
98 // This comes from loading Totem with LANG=ja_JP.UTF-8.
99 TEST(MIMEDescriptionParse, JapaneseUTF8) {
100 std::vector<WebPluginMimeType> types;
101 NPAPI::PluginLib::ParseMIMEDescription(
102 "audio/x-ogg:ogg:Ogg \xe3\x82\xaa\xe3\x83\xbc\xe3\x83\x87"
103 "\xe3\x82\xa3\xe3\x83\xaa",
104 &types);
105
106 ASSERT_EQ(1U, types.size());
107 // Check we got the right number of Unicode characters out of the parse.
108 EXPECT_EQ(9U, types[0].description.size());
109 }
110
111 // Test that we handle corner cases gracefully.
112 TEST(MIMEDescriptionParse, CornerCases) {
113 std::vector<WebPluginMimeType> types;
114 NPAPI::PluginLib::ParseMIMEDescription("mime/type:", &types);
115 EXPECT_TRUE(types.empty());
116
117 types.clear();
118 NPAPI::PluginLib::ParseMIMEDescription("mime/type:ext1:", &types);
119 ASSERT_EQ(1U, types.size());
120 EXPECT_EQ("mime/type", types[0].mime_type);
121 EXPECT_EQ(1U, types[0].file_extensions.size());
122 EXPECT_EQ("ext1", types[0].file_extensions[0]);
123 EXPECT_EQ(string16(), types[0].description);
124 }
125
126 // This Java plugin has embedded semicolons in the mime type.
127 TEST(MIMEDescriptionParse, ComplicatedJava) {
128 std::vector<WebPluginMimeType> types;
129 NPAPI::PluginLib::ParseMIMEDescription(
130 "application/x-java-vm:class,jar:IcedTea;application/x-java"
131 "-applet:class,jar:IcedTea;application/x-java-applet;versio"
132 "n=1.1:class,jar:IcedTea;application/x-java-applet;version="
133 "1.1.1:class,jar:IcedTea;application/x-java-applet;version="
134 "1.1.2:class,jar:IcedTea;application/x-java-applet;version="
135 "1.1.3:class,jar:IcedTea;application/x-java-applet;version="
136 "1.2:class,jar:IcedTea;application/x-java-applet;version=1."
137 "2.1:class,jar:IcedTea;application/x-java-applet;version=1."
138 "2.2:class,jar:IcedTea;application/x-java-applet;version=1."
139 "3:class,jar:IcedTea;application/x-java-applet;version=1.3."
140 "1:class,jar:IcedTea;application/x-java-applet;version=1.4:"
141 "class,jar:IcedTea",
142 &types);
143
144 ASSERT_EQ(12U, types.size());
145 for (size_t i = 0; i < types.size(); ++i)
146 EXPECT_EQ(ASCIIToUTF16("IcedTea"), types[i].description);
147
148 // Verify that the mime types with semis are coming through ok.
149 EXPECT_TRUE(types[4].mime_type.find(';') != std::string::npos);
150 }
151
152 #endif // defined(OS_LINUX)
OLDNEW
« no previous file with comments | « webkit/glue/plugins/plugin_lib_posix.cc ('k') | webkit/glue/plugins/plugin_lib_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698