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

Side by Side Diff: chrome/browser/shell_integration_unittest.cc

Issue 6759076: Add the calculated WMClass to generated .desktop files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unit tests on linux Created 9 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/shell_integration.h" 5 #include "chrome/browser/shell_integration.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/memory/scoped_temp_dir.h" 11 #include "base/memory/scoped_temp_dir.h"
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "base/stl_util-inl.h" 13 #include "base/stl_util-inl.h"
14 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "chrome/browser/web_applications/web_app.h"
16 #include "chrome/common/chrome_constants.h" 17 #include "chrome/common/chrome_constants.h"
17 #include "chrome/common/chrome_paths_internal.h" 18 #include "chrome/common/chrome_paths_internal.h"
18 #include "content/browser/browser_thread.h" 19 #include "content/browser/browser_thread.h"
19 #include "googleurl/src/gurl.h" 20 #include "googleurl/src/gurl.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 22
22 #if defined(OS_WIN) 23 #if defined(OS_WIN)
23 #include "chrome/installer/util/browser_distribution.h" 24 #include "chrome/installer/util/browser_distribution.h"
24 #elif defined(OS_LINUX) 25 #elif defined(OS_LINUX)
25 #include "base/environment.h" 26 #include "base/environment.h"
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 "#!/usr/bin/env xdg-open\n" 190 "#!/usr/bin/env xdg-open\n"
190 "[Desktop Entry]\n" 191 "[Desktop Entry]\n"
191 "Version=1.0\n" 192 "Version=1.0\n"
192 "Encoding=UTF-8\n" 193 "Encoding=UTF-8\n"
193 "Name=GMail\n" 194 "Name=GMail\n"
194 "Exec=/opt/google/chrome/google-chrome --app=http://gmail.com/\n" 195 "Exec=/opt/google/chrome/google-chrome --app=http://gmail.com/\n"
195 "Terminal=false\n" 196 "Terminal=false\n"
196 "Icon=chrome-http__gmail.com\n" 197 "Icon=chrome-http__gmail.com\n"
197 "Type=Application\n" 198 "Type=Application\n"
198 "Categories=Application;Network;WebBrowser;\n" 199 "Categories=Application;Network;WebBrowser;\n"
200 "StartupWMClass=gmail.com\n"
199 }, 201 },
200 202
201 // Make sure we don't insert duplicate shebangs. 203 // Make sure we don't insert duplicate shebangs.
202 { "http://gmail.com", 204 { "http://gmail.com",
203 "GMail", 205 "GMail",
204 "chrome-http__gmail.com", 206 "chrome-http__gmail.com",
205 207
206 "#!/some/shebang\n" 208 "#!/some/shebang\n"
207 "Name=Google Chrome\n" 209 "Name=Google Chrome\n"
208 "Exec=/opt/google/chrome/google-chrome %U\n", 210 "Exec=/opt/google/chrome/google-chrome %U\n",
209 211
210 "#!/usr/bin/env xdg-open\n" 212 "#!/usr/bin/env xdg-open\n"
211 "Name=GMail\n" 213 "Name=GMail\n"
212 "Exec=/opt/google/chrome/google-chrome --app=http://gmail.com/\n" 214 "Exec=/opt/google/chrome/google-chrome --app=http://gmail.com/\n"
215 "StartupWMClass=gmail.com\n"
213 }, 216 },
214 217
215 // Make sure i18n-ed comments are removed. 218 // Make sure i18n-ed comments are removed.
216 { "http://gmail.com", 219 { "http://gmail.com",
217 "GMail", 220 "GMail",
218 "chrome-http__gmail.com", 221 "chrome-http__gmail.com",
219 222
220 "Name=Google Chrome\n" 223 "Name=Google Chrome\n"
221 "Exec=/opt/google/chrome/google-chrome %U\n" 224 "Exec=/opt/google/chrome/google-chrome %U\n"
222 "Comment[pl]=Jakis komentarz.\n", 225 "Comment[pl]=Jakis komentarz.\n",
223 226
224 "#!/usr/bin/env xdg-open\n" 227 "#!/usr/bin/env xdg-open\n"
225 "Name=GMail\n" 228 "Name=GMail\n"
226 "Exec=/opt/google/chrome/google-chrome --app=http://gmail.com/\n" 229 "Exec=/opt/google/chrome/google-chrome --app=http://gmail.com/\n"
230 "StartupWMClass=gmail.com\n"
227 }, 231 },
228 232
229 // Make sure that empty icons are replaced by the chrome icon. 233 // Make sure that empty icons are replaced by the chrome icon.
230 { "http://gmail.com", 234 { "http://gmail.com",
231 "GMail", 235 "GMail",
232 "", 236 "",
233 237
234 "Name=Google Chrome\n" 238 "Name=Google Chrome\n"
235 "Exec=/opt/google/chrome/google-chrome %U\n" 239 "Exec=/opt/google/chrome/google-chrome %U\n"
236 "Comment[pl]=Jakis komentarz.\n" 240 "Comment[pl]=Jakis komentarz.\n"
237 "Icon=/opt/google/chrome/product_logo_48.png\n", 241 "Icon=/opt/google/chrome/product_logo_48.png\n",
238 242
239 "#!/usr/bin/env xdg-open\n" 243 "#!/usr/bin/env xdg-open\n"
240 "Name=GMail\n" 244 "Name=GMail\n"
241 "Exec=/opt/google/chrome/google-chrome --app=http://gmail.com/\n" 245 "Exec=/opt/google/chrome/google-chrome --app=http://gmail.com/\n"
242 "Icon=/opt/google/chrome/product_logo_48.png\n" 246 "Icon=/opt/google/chrome/product_logo_48.png\n"
247 "StartupWMClass=gmail.com\n"
243 }, 248 },
244 249
245 // Now we're starting to be more evil... 250 // Now we're starting to be more evil...
246 { "http://evil.com/evil --join-the-b0tnet", 251 { "http://evil.com/evil --join-the-b0tnet",
247 "Ownz0red\nExec=rm -rf /", 252 "Ownz0red\nExec=rm -rf /",
248 "chrome-http__evil.com_evil", 253 "chrome-http__evil.com_evil",
249 254
250 "Name=Google Chrome\n" 255 "Name=Google Chrome\n"
251 "Exec=/opt/google/chrome/google-chrome %U\n", 256 "Exec=/opt/google/chrome/google-chrome %U\n",
252 257
253 "#!/usr/bin/env xdg-open\n" 258 "#!/usr/bin/env xdg-open\n"
254 "Name=http://evil.com/evil%20--join-the-b0tnet\n" 259 "Name=http://evil.com/evil%20--join-the-b0tnet\n"
255 "Exec=/opt/google/chrome/google-chrome " 260 "Exec=/opt/google/chrome/google-chrome "
256 "--app=http://evil.com/evil%20--join-the-b0tnet\n" 261 "--app=http://evil.com/evil%20--join-the-b0tnet\n"
262 "StartupWMClass=evil.com__evil%20--join-the-b0tnet\n"
257 }, 263 },
258 { "http://evil.com/evil; rm -rf /; \"; rm -rf $HOME >ownz0red", 264 { "http://evil.com/evil; rm -rf /; \"; rm -rf $HOME >ownz0red",
259 "Innocent Title", 265 "Innocent Title",
260 "chrome-http__evil.com_evil", 266 "chrome-http__evil.com_evil",
261 267
262 "Name=Google Chrome\n" 268 "Name=Google Chrome\n"
263 "Exec=/opt/google/chrome/google-chrome %U\n", 269 "Exec=/opt/google/chrome/google-chrome %U\n",
264 270
265 "#!/usr/bin/env xdg-open\n" 271 "#!/usr/bin/env xdg-open\n"
266 "Name=Innocent Title\n" 272 "Name=Innocent Title\n"
267 "Exec=/opt/google/chrome/google-chrome " 273 "Exec=/opt/google/chrome/google-chrome "
268 "\"--app=http://evil.com/evil;%20rm%20-rf%20/;%20%22;%20rm%20" 274 "\"--app=http://evil.com/evil;%20rm%20-rf%20/;%20%22;%20rm%20"
269 // Note: $ is escaped as \$ within an arg to Exec, and then 275 // Note: $ is escaped as \$ within an arg to Exec, and then
270 // the \ is escaped as \\ as all strings in a Desktop file should 276 // the \ is escaped as \\ as all strings in a Desktop file should
271 // be; finally, \\ becomes \\\\ when represented in a C++ string! 277 // be; finally, \\ becomes \\\\ when represented in a C++ string!
272 "-rf%20\\\\$HOME%20%3Eownz0red\"\n" 278 "-rf%20\\\\$HOME%20%3Eownz0red\"\n"
279 "StartupWMClass=evil.com__evil;%20rm%20-rf%20_;%20%22;%20"
280 "rm%20-rf%20$HOME%20%3Eownz0red\n"
273 }, 281 },
274 { "http://evil.com/evil | cat `echo ownz0red` >/dev/null", 282 { "http://evil.com/evil | cat `echo ownz0red` >/dev/null",
275 "Innocent Title", 283 "Innocent Title",
276 "chrome-http__evil.com_evil", 284 "chrome-http__evil.com_evil",
277 285
278 "Name=Google Chrome\n" 286 "Name=Google Chrome\n"
279 "Exec=/opt/google/chrome/google-chrome %U\n", 287 "Exec=/opt/google/chrome/google-chrome %U\n",
280 288
281 "#!/usr/bin/env xdg-open\n" 289 "#!/usr/bin/env xdg-open\n"
282 "Name=Innocent Title\n" 290 "Name=Innocent Title\n"
283 "Exec=/opt/google/chrome/google-chrome " 291 "Exec=/opt/google/chrome/google-chrome "
284 "--app=http://evil.com/evil%20%7C%20cat%20%60echo%20ownz0red" 292 "--app=http://evil.com/evil%20%7C%20cat%20%60echo%20ownz0red"
285 "%60%20%3E/dev/null\n" 293 "%60%20%3E/dev/null\n"
294 "StartupWMClass=evil.com__evil%20%7C%20cat%20%60echo%20ownz0red"
295 "%60%20%3E_dev_null\n"
286 }, 296 },
287 }; 297 };
288 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) { 298 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) {
289 SCOPED_TRACE(i); 299 SCOPED_TRACE(i);
290 EXPECT_EQ(test_cases[i].expected_output, 300 EXPECT_EQ(
291 ShellIntegration::GetDesktopFileContents( 301 test_cases[i].expected_output,
292 test_cases[i].template_contents, 302 ShellIntegration::GetDesktopFileContents(
293 GURL(test_cases[i].url), 303 test_cases[i].template_contents,
294 "", 304 web_app::GenerateApplicationNameFromURL(GURL(test_cases[i].url)),
295 ASCIIToUTF16(test_cases[i].title), 305 GURL(test_cases[i].url),
296 test_cases[i].icon_name)); 306 "",
307 ASCIIToUTF16(test_cases[i].title),
308 test_cases[i].icon_name));
297 } 309 }
298 } 310 }
299 #elif defined(OS_WIN) 311 #elif defined(OS_WIN)
300 TEST(ShellIntegrationTest, GetChromiumAppIdTest) { 312 TEST(ShellIntegrationTest, GetChromiumAppIdTest) {
301 // Empty profile path should get chrome::kBrowserAppID 313 // Empty profile path should get chrome::kBrowserAppID
302 FilePath empty_path; 314 FilePath empty_path;
303 EXPECT_EQ(BrowserDistribution::GetDistribution()->GetBrowserAppId(), 315 EXPECT_EQ(BrowserDistribution::GetDistribution()->GetBrowserAppId(),
304 ShellIntegration::GetChromiumAppId(empty_path)); 316 ShellIntegration::GetChromiumAppId(empty_path));
305 317
306 // Default profile path should get chrome::kBrowserAppID 318 // Default profile path should get chrome::kBrowserAppID
307 FilePath default_user_data_dir; 319 FilePath default_user_data_dir;
308 chrome::GetDefaultUserDataDirectory(&default_user_data_dir); 320 chrome::GetDefaultUserDataDirectory(&default_user_data_dir);
309 FilePath default_profile_path = 321 FilePath default_profile_path =
310 default_user_data_dir.AppendASCII(chrome::kNotSignedInProfile); 322 default_user_data_dir.AppendASCII(chrome::kNotSignedInProfile);
311 EXPECT_EQ(BrowserDistribution::GetDistribution()->GetBrowserAppId(), 323 EXPECT_EQ(BrowserDistribution::GetDistribution()->GetBrowserAppId(),
312 ShellIntegration::GetChromiumAppId(default_profile_path)); 324 ShellIntegration::GetChromiumAppId(default_profile_path));
313 325
314 // Non-default profile path should get chrome::kBrowserAppID joined with 326 // Non-default profile path should get chrome::kBrowserAppID joined with
315 // profile info. 327 // profile info.
316 FilePath profile_path(FILE_PATH_LITERAL("root")); 328 FilePath profile_path(FILE_PATH_LITERAL("root"));
317 profile_path = profile_path.Append(FILE_PATH_LITERAL("udd")); 329 profile_path = profile_path.Append(FILE_PATH_LITERAL("udd"));
318 profile_path = profile_path.Append(FILE_PATH_LITERAL("User Data - Test")); 330 profile_path = profile_path.Append(FILE_PATH_LITERAL("User Data - Test"));
319 EXPECT_EQ(BrowserDistribution::GetDistribution()->GetBrowserAppId() + 331 EXPECT_EQ(BrowserDistribution::GetDistribution()->GetBrowserAppId() +
320 L".udd.UserDataTest", 332 L".udd.UserDataTest",
321 ShellIntegration::GetChromiumAppId(profile_path)); 333 ShellIntegration::GetChromiumAppId(profile_path));
322 } 334 }
323 #endif 335 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698