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

Side by Side Diff: content/common/plugin_list_unittest.cc

Issue 26541011: Return matching plug-ins in the sorted order (by version number). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use multiset Created 7 years, 1 month 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 | « content/common/plugin_list.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) 2012 The Chromium Authors. All rights reserved. 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 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 "content/common/plugin_list.h" 5 #include "content/common/plugin_list.h"
6 6
7 #include <string>
8
7 #include "base/strings/string16.h" 9 #include "base/strings/string16.h"
8 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
9 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
10 #include "url/gurl.h" 12 #include "url/gurl.h"
11 13
12 namespace content { 14 namespace content {
13 15
14 namespace { 16 namespace {
15 17
16 base::FilePath::CharType kFooPath[] = FILE_PATH_LITERAL("/plugins/foo.plugin"); 18 base::FilePath::CharType kFooPath[] = FILE_PATH_LITERAL("/plugins/foo.plugin");
(...skipping 12 matching lines...) Expand all
29 bool Contains(const std::vector<WebPluginInfo>& list, 31 bool Contains(const std::vector<WebPluginInfo>& list,
30 const WebPluginInfo& plugin) { 32 const WebPluginInfo& plugin) {
31 for (std::vector<WebPluginInfo>::const_iterator it = list.begin(); 33 for (std::vector<WebPluginInfo>::const_iterator it = list.begin();
32 it != list.end(); ++it) { 34 it != list.end(); ++it) {
33 if (Equals(*it, plugin)) 35 if (Equals(*it, plugin))
34 return true; 36 return true;
35 } 37 }
36 return false; 38 return false;
37 } 39 }
38 40
41 WebPluginInfo CreateFooPluginWithVersion(const std::string& version) {
42 base::FilePath plugin_path = base::FilePath::FromUTF8Unsafe(
43 std::string("/plugins/foo") + version + std::string(".plugin"));
44 WebPluginInfo plugin(ASCIIToUTF16(kFooName),
45 plugin_path,
46 ASCIIToUTF16(version.c_str()),
47 base::string16());
48 plugin.mime_types.push_back(
49 WebPluginMimeType(kFooMimeType, kFooFileType, std::string()));
50 return plugin;
51 }
52
39 } // namespace 53 } // namespace
40 54
41 class PluginListTest : public testing::Test { 55 class PluginListTest : public testing::Test {
42 public: 56 public:
43 PluginListTest() 57 PluginListTest()
44 : foo_plugin_(ASCIIToUTF16(kFooName), 58 : foo_plugin_(ASCIIToUTF16(kFooName),
45 base::FilePath(kFooPath), 59 base::FilePath(kFooPath),
46 ASCIIToUTF16("1.2.3"), 60 ASCIIToUTF16("1.2.3"),
47 ASCIIToUTF16("foo")), 61 ASCIIToUTF16("foo")),
48 bar_plugin_(ASCIIToUTF16("Bar Plugin"), 62 bar_plugin_(ASCIIToUTF16("Bar Plugin"),
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 NULL, // use_stale 143 NULL, // use_stale
130 false, // include_npapi 144 false, // include_npapi
131 &plugins, 145 &plugins,
132 &actual_mime_types); 146 &actual_mime_types);
133 EXPECT_EQ(1u, plugins.size()); 147 EXPECT_EQ(1u, plugins.size());
134 EXPECT_TRUE(Contains(plugins, foo_plugin_)); 148 EXPECT_TRUE(Contains(plugins, foo_plugin_));
135 ASSERT_EQ(1u, actual_mime_types.size()); 149 ASSERT_EQ(1u, actual_mime_types.size());
136 EXPECT_EQ(kFooMimeType, actual_mime_types.front()); 150 EXPECT_EQ(kFooMimeType, actual_mime_types.front());
137 } 151 }
138 152
153 TEST_F(PluginListTest, GetPluginInfoArrayVersionOrder) {
154 GURL target_url("http://example.com/test.foo");
155
156 // Set up 3 plug-ins that differ in version, randomly ordered.
157 std::vector<WebPluginInfo> test_plugins;
158 WebPluginInfo plugin_v1 = CreateFooPluginWithVersion("1.2.3");
159 WebPluginInfo plugin_v2 = CreateFooPluginWithVersion("2.3.4");
160 WebPluginInfo plugin_v3 = CreateFooPluginWithVersion("3.4.5");
161 test_plugins.push_back(plugin_v3);
162 test_plugins.push_back(plugin_v1);
163 test_plugins.push_back(plugin_v2);
164 plugin_list_.SetPlugins(test_plugins);
165
166 std::vector<WebPluginInfo> matched_plugins;
167 std::vector<std::string> actual_mime_types;
168 plugin_list_.GetPluginInfoArray(target_url,
169 kFooMimeType,
170 false, // allow_wildcard
171 NULL, // use_stale
172 false, // include_npapi
173 &matched_plugins,
174 &actual_mime_types);
175
176 EXPECT_EQ(3u, matched_plugins.size());
177 // Must be ordered from the highest to lowest version.
178 EXPECT_TRUE(Equals(matched_plugins[0], plugin_v3));
179 EXPECT_TRUE(Equals(matched_plugins[1], plugin_v2));
180 EXPECT_TRUE(Equals(matched_plugins[2], plugin_v1));
181 }
182
139 #if defined(OS_POSIX) && !defined(OS_MACOSX) 183 #if defined(OS_POSIX) && !defined(OS_MACOSX)
140 184
141 // Test parsing a simple description: Real Audio. 185 // Test parsing a simple description: Real Audio.
142 TEST(MIMEDescriptionParse, Simple) { 186 TEST(MIMEDescriptionParse, Simple) {
143 std::vector<WebPluginMimeType> types; 187 std::vector<WebPluginMimeType> types;
144 PluginList::ParseMIMEDescription( 188 PluginList::ParseMIMEDescription(
145 "audio/x-pn-realaudio-plugin:rpm:RealAudio document;", 189 "audio/x-pn-realaudio-plugin:rpm:RealAudio document;",
146 &types); 190 &types);
147 ASSERT_EQ(1U, types.size()); 191 ASSERT_EQ(1U, types.size());
148 const WebPluginMimeType& type = types[0]; 192 const WebPluginMimeType& type = types[0];
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 "IcedTea-Web Plugin " 286 "IcedTea-Web Plugin "
243 "(using IcedTea-Web 1.2 (1.2-2ubuntu0.10.04.2))", 287 "(using IcedTea-Web 1.2 (1.2-2ubuntu0.10.04.2))",
244 &info); 288 &info);
245 EXPECT_EQ(ASCIIToUTF16("1.2"), info.version); 289 EXPECT_EQ(ASCIIToUTF16("1.2"), info.version);
246 } 290 }
247 291
248 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) 292 #endif // defined(OS_POSIX) && !defined(OS_MACOSX)
249 293
250 294
251 } // namespace content 295 } // namespace content
OLDNEW
« no previous file with comments | « content/common/plugin_list.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698