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

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

Powered by Google App Engine
This is Rietveld 408576698