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

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

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