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

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

Issue 200052: linux: rewrite mime parser (Closed)
Patch Set: review comments Created 11 years, 3 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
« no previous file with comments | « webkit/glue/plugins/plugin_lib_linux.cc ('k') | no next file » | 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/glue/plugins/plugin_lib.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 #if defined(OS_LINUX) 10 #if defined(OS_LINUX)
11 11
12 // Test parsing a simple description: Real Audio. 12 // Test parsing a simple description: Real Audio.
13 TEST(MIMEDescriptionParse, Simple) { 13 TEST(MIMEDescriptionParse, Simple) {
14 std::vector<WebPluginMimeType> types; 14 std::vector<WebPluginMimeType> types;
15 ASSERT_TRUE(NPAPI::PluginLib::ParseMIMEDescription( 15 NPAPI::PluginLib::ParseMIMEDescription(
16 "audio/x-pn-realaudio-plugin:rpm:RealAudio document;", 16 "audio/x-pn-realaudio-plugin:rpm:RealAudio document;",
17 &types)); 17 &types);
18 ASSERT_EQ(1U, types.size()); 18 ASSERT_EQ(1U, types.size());
19 const WebPluginMimeType& type = types[0]; 19 const WebPluginMimeType& type = types[0];
20 EXPECT_EQ("audio/x-pn-realaudio-plugin", type.mime_type); 20 EXPECT_EQ("audio/x-pn-realaudio-plugin", type.mime_type);
21 ASSERT_EQ(1U, type.file_extensions.size()); 21 ASSERT_EQ(1U, type.file_extensions.size());
22 EXPECT_EQ("rpm", type.file_extensions[0]); 22 EXPECT_EQ("rpm", type.file_extensions[0]);
23 EXPECT_EQ(L"RealAudio document", type.description); 23 EXPECT_EQ(L"RealAudio document", type.description);
24 } 24 }
25 25
26 // Test parsing a multi-entry description: QuickTime as provided by Totem. 26 // Test parsing a multi-entry description: QuickTime as provided by Totem.
27 TEST(MIMEDescriptionParse, Multi) { 27 TEST(MIMEDescriptionParse, Multi) {
28 std::vector<WebPluginMimeType> types; 28 std::vector<WebPluginMimeType> types;
29 ASSERT_TRUE(NPAPI::PluginLib::ParseMIMEDescription( 29 NPAPI::PluginLib::ParseMIMEDescription(
30 "video/quicktime:mov:QuickTime video;video/mp4:mp4:MPEG-4 " 30 "video/quicktime:mov:QuickTime video;video/mp4:mp4:MPEG-4 "
31 "video;image/x-macpaint:pntg:MacPaint Bitmap image;image/x" 31 "video;image/x-macpaint:pntg:MacPaint Bitmap image;image/x"
32 "-quicktime:pict, pict1, pict2:QuickTime image;video/x-m4v" 32 "-quicktime:pict, pict1, pict2:QuickTime image;video/x-m4v"
33 ":m4v:MPEG-4 video;", 33 ":m4v:MPEG-4 video;",
34 &types)); 34 &types);
35 35
36 ASSERT_EQ(5U, types.size()); 36 ASSERT_EQ(5U, types.size());
37 37
38 // Check the x-quicktime one, since it looks tricky with spaces in the 38 // Check the x-quicktime one, since it looks tricky with spaces in the
39 // extension list. 39 // extension list.
40 const WebPluginMimeType& type = types[3]; 40 const WebPluginMimeType& type = types[3];
41 EXPECT_EQ("image/x-quicktime", type.mime_type); 41 EXPECT_EQ("image/x-quicktime", type.mime_type);
42 ASSERT_EQ(3U, type.file_extensions.size()); 42 ASSERT_EQ(3U, type.file_extensions.size());
43 EXPECT_EQ("pict2", type.file_extensions[2]); 43 EXPECT_EQ("pict2", type.file_extensions[2]);
44 EXPECT_EQ(L"QuickTime image", type.description); 44 EXPECT_EQ(L"QuickTime image", type.description);
45 } 45 }
46 46
47 // Test parsing a Japanese description, since we got this wrong in the past. 47 // Test parsing a Japanese description, since we got this wrong in the past.
48 // This comes from loading Totem with LANG=ja_JP.UTF-8. 48 // This comes from loading Totem with LANG=ja_JP.UTF-8.
49 TEST(MIMEDescriptionParse, JapaneseUTF8) { 49 TEST(MIMEDescriptionParse, JapaneseUTF8) {
50 std::vector<WebPluginMimeType> types; 50 std::vector<WebPluginMimeType> types;
51 ASSERT_TRUE(NPAPI::PluginLib::ParseMIMEDescription( 51 NPAPI::PluginLib::ParseMIMEDescription(
52 "audio/x-ogg:ogg:Ogg \xe3\x82\xaa\xe3\x83\xbc\xe3\x83\x87" 52 "audio/x-ogg:ogg:Ogg \xe3\x82\xaa\xe3\x83\xbc\xe3\x83\x87"
53 "\xe3\x82\xa3\xe3\x83\xaa", 53 "\xe3\x82\xa3\xe3\x83\xaa",
54 &types)); 54 &types);
55 55
56 ASSERT_EQ(1U, types.size()); 56 ASSERT_EQ(1U, types.size());
57 // Check we got the right number of Unicode characters out of the parse. 57 // Check we got the right number of Unicode characters out of the parse.
58 EXPECT_EQ(9U, types[0].description.size()); 58 EXPECT_EQ(9U, types[0].description.size());
59 } 59 }
60 60
61 /* 61 // Test that we handle corner cases gracefully.
62 TEST(MIMEDescriptionParse, CornerCases) {
63 std::vector<WebPluginMimeType> types;
64 NPAPI::PluginLib::ParseMIMEDescription("mime/type:", &types);
65 EXPECT_TRUE(types.empty());
62 66
63 TODO(evanm): write a test that covers the following, which does *not* 67 types.clear();
64 parse properly with the current code. 68 NPAPI::PluginLib::ParseMIMEDescription("mime/type:ext1:", &types);
69 ASSERT_EQ(1U, types.size());
70 EXPECT_EQ("mime/type", types[0].mime_type);
71 EXPECT_EQ(1U, types[0].file_extensions.size());
72 EXPECT_EQ("ext1", types[0].file_extensions[0]);
73 EXPECT_EQ(L"", types[0].description);
74 }
65 75
66 application/x-java-vm:class,jar:IcedTea;application/x-java-applet:class,jar:Iced Tea;application/x-java-applet;version=1.1:class,jar:IcedTea;application/x-java-a pplet;version=1.1.1:class,jar:IcedTea;application/x-java-applet;version=1.1.2:cl ass,jar:IcedTea;application/x-java-applet;version=1.1.3:class,jar:IcedTea;applic ation/x-java-applet;version=1.2:class,jar:IcedTea;application/x-java-applet;vers ion=1.2.1:class,jar:IcedTea;application/x-java-applet;version=1.2.2:class,jar:Ic edTea;application/x-java-applet;version=1.3:class,jar:IcedTea;application/x-java -applet;version=1.3.1:class,jar:IcedTea;application/x-java-applet;version=1.4:cl ass,jar:IcedTea 76 // This Java plugin has embedded semicolons in the mime type.
67 */ 77 TEST(MIMEDescriptionParse, ComplicatedJava) {
78 std::vector<WebPluginMimeType> types;
79 NPAPI::PluginLib::ParseMIMEDescription(
80 "application/x-java-vm:class,jar:IcedTea;application/x-java"
81 "-applet:class,jar:IcedTea;application/x-java-applet;versio"
82 "n=1.1:class,jar:IcedTea;application/x-java-applet;version="
83 "1.1.1:class,jar:IcedTea;application/x-java-applet;version="
84 "1.1.2:class,jar:IcedTea;application/x-java-applet;version="
85 "1.1.3:class,jar:IcedTea;application/x-java-applet;version="
86 "1.2:class,jar:IcedTea;application/x-java-applet;version=1."
87 "2.1:class,jar:IcedTea;application/x-java-applet;version=1."
88 "2.2:class,jar:IcedTea;application/x-java-applet;version=1."
89 "3:class,jar:IcedTea;application/x-java-applet;version=1.3."
90 "1:class,jar:IcedTea;application/x-java-applet;version=1.4:"
91 "class,jar:IcedTea",
92 &types);
68 93
94 ASSERT_EQ(12U, types.size());
95 for (size_t i = 0; i < types.size(); ++i)
96 EXPECT_EQ(L"IcedTea", types[i].description);
97
98 // Verify that the mime types with semis are coming through ok.
99 EXPECT_TRUE(types[4].mime_type.find(';') != std::string::npos);
100 }
69 101
70 #endif // defined(OS_LINUX) 102 #endif // defined(OS_LINUX)
71 103
104
OLDNEW
« no previous file with comments | « webkit/glue/plugins/plugin_lib_linux.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698