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

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

Issue 2321453002: c/browser, c/common, components S-W: Change ScopedTempDir::path() to GetPath() (Closed)
Patch Set: Just rebased Created 4 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_linux.h" 5 #include "chrome/browser/shell_integration_linux.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <cstdlib> 10 #include <cstdlib>
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 EXPECT_EQ(web_app::APP_MENU_LOCATION_NONE, 206 EXPECT_EQ(web_app::APP_MENU_LOCATION_NONE,
207 result.applications_menu_location); 207 result.applications_menu_location);
208 208
209 EXPECT_FALSE(result.in_quick_launch_bar); 209 EXPECT_FALSE(result.in_quick_launch_bar);
210 } 210 }
211 211
212 // Shortcut on desktop. 212 // Shortcut on desktop.
213 { 213 {
214 base::ScopedTempDir temp_dir; 214 base::ScopedTempDir temp_dir;
215 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 215 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
216 base::FilePath desktop_path = temp_dir.path(); 216 base::FilePath desktop_path = temp_dir.GetPath();
217 217
218 MockEnvironment env; 218 MockEnvironment env;
219 ASSERT_TRUE(base::CreateDirectory(desktop_path)); 219 ASSERT_TRUE(base::CreateDirectory(desktop_path));
220 ASSERT_TRUE(WriteEmptyFile(desktop_path.Append(kTemplateFilename))); 220 ASSERT_TRUE(WriteEmptyFile(desktop_path.Append(kTemplateFilename)));
221 web_app::ShortcutLocations result = GetExistingShortcutLocations( 221 web_app::ShortcutLocations result = GetExistingShortcutLocations(
222 &env, kProfilePath, kExtensionId, desktop_path); 222 &env, kProfilePath, kExtensionId, desktop_path);
223 EXPECT_TRUE(result.on_desktop); 223 EXPECT_TRUE(result.on_desktop);
224 EXPECT_EQ(web_app::APP_MENU_LOCATION_NONE, 224 EXPECT_EQ(web_app::APP_MENU_LOCATION_NONE,
225 result.applications_menu_location); 225 result.applications_menu_location);
226 226
227 EXPECT_FALSE(result.in_quick_launch_bar); 227 EXPECT_FALSE(result.in_quick_launch_bar);
228 } 228 }
229 229
230 // Shortcut in applications directory. 230 // Shortcut in applications directory.
231 { 231 {
232 base::ScopedTempDir temp_dir; 232 base::ScopedTempDir temp_dir;
233 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 233 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
234 base::FilePath apps_path = temp_dir.path().Append("applications"); 234 base::FilePath apps_path = temp_dir.GetPath().Append("applications");
235 235
236 MockEnvironment env; 236 MockEnvironment env;
237 env.Set("XDG_DATA_HOME", temp_dir.path().value()); 237 env.Set("XDG_DATA_HOME", temp_dir.GetPath().value());
238 ASSERT_TRUE(base::CreateDirectory(apps_path)); 238 ASSERT_TRUE(base::CreateDirectory(apps_path));
239 ASSERT_TRUE(WriteEmptyFile(apps_path.Append(kTemplateFilename))); 239 ASSERT_TRUE(WriteEmptyFile(apps_path.Append(kTemplateFilename)));
240 web_app::ShortcutLocations result = 240 web_app::ShortcutLocations result =
241 GetExistingShortcutLocations(&env, kProfilePath, kExtensionId); 241 GetExistingShortcutLocations(&env, kProfilePath, kExtensionId);
242 EXPECT_FALSE(result.on_desktop); 242 EXPECT_FALSE(result.on_desktop);
243 EXPECT_EQ(web_app::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS, 243 EXPECT_EQ(web_app::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS,
244 result.applications_menu_location); 244 result.applications_menu_location);
245 245
246 EXPECT_FALSE(result.in_quick_launch_bar); 246 EXPECT_FALSE(result.in_quick_launch_bar);
247 } 247 }
248 248
249 // Shortcut in applications directory with NoDisplay=true. 249 // Shortcut in applications directory with NoDisplay=true.
250 { 250 {
251 base::ScopedTempDir temp_dir; 251 base::ScopedTempDir temp_dir;
252 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 252 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
253 base::FilePath apps_path = temp_dir.path().Append("applications"); 253 base::FilePath apps_path = temp_dir.GetPath().Append("applications");
254 254
255 MockEnvironment env; 255 MockEnvironment env;
256 env.Set("XDG_DATA_HOME", temp_dir.path().value()); 256 env.Set("XDG_DATA_HOME", temp_dir.GetPath().value());
257 ASSERT_TRUE(base::CreateDirectory(apps_path)); 257 ASSERT_TRUE(base::CreateDirectory(apps_path));
258 ASSERT_TRUE(WriteString(apps_path.Append(kTemplateFilename), 258 ASSERT_TRUE(WriteString(apps_path.Append(kTemplateFilename),
259 kNoDisplayDesktopFile)); 259 kNoDisplayDesktopFile));
260 web_app::ShortcutLocations result = 260 web_app::ShortcutLocations result =
261 GetExistingShortcutLocations(&env, kProfilePath, kExtensionId); 261 GetExistingShortcutLocations(&env, kProfilePath, kExtensionId);
262 // Doesn't count as being in applications menu. 262 // Doesn't count as being in applications menu.
263 EXPECT_FALSE(result.on_desktop); 263 EXPECT_FALSE(result.on_desktop);
264 EXPECT_EQ(web_app::APP_MENU_LOCATION_HIDDEN, 264 EXPECT_EQ(web_app::APP_MENU_LOCATION_HIDDEN,
265 result.applications_menu_location); 265 result.applications_menu_location);
266 EXPECT_FALSE(result.in_quick_launch_bar); 266 EXPECT_FALSE(result.in_quick_launch_bar);
267 } 267 }
268 268
269 // Shortcut on desktop and in applications directory. 269 // Shortcut on desktop and in applications directory.
270 { 270 {
271 base::ScopedTempDir temp_dir1; 271 base::ScopedTempDir temp_dir1;
272 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir()); 272 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir());
273 base::FilePath desktop_path = temp_dir1.path(); 273 base::FilePath desktop_path = temp_dir1.GetPath();
274 274
275 base::ScopedTempDir temp_dir2; 275 base::ScopedTempDir temp_dir2;
276 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); 276 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir());
277 base::FilePath apps_path = temp_dir2.path().Append("applications"); 277 base::FilePath apps_path = temp_dir2.GetPath().Append("applications");
278 278
279 MockEnvironment env; 279 MockEnvironment env;
280 ASSERT_TRUE(base::CreateDirectory(desktop_path)); 280 ASSERT_TRUE(base::CreateDirectory(desktop_path));
281 ASSERT_TRUE(WriteEmptyFile(desktop_path.Append(kTemplateFilename))); 281 ASSERT_TRUE(WriteEmptyFile(desktop_path.Append(kTemplateFilename)));
282 env.Set("XDG_DATA_HOME", temp_dir2.path().value()); 282 env.Set("XDG_DATA_HOME", temp_dir2.GetPath().value());
283 ASSERT_TRUE(base::CreateDirectory(apps_path)); 283 ASSERT_TRUE(base::CreateDirectory(apps_path));
284 ASSERT_TRUE(WriteEmptyFile(apps_path.Append(kTemplateFilename))); 284 ASSERT_TRUE(WriteEmptyFile(apps_path.Append(kTemplateFilename)));
285 web_app::ShortcutLocations result = GetExistingShortcutLocations( 285 web_app::ShortcutLocations result = GetExistingShortcutLocations(
286 &env, kProfilePath, kExtensionId, desktop_path); 286 &env, kProfilePath, kExtensionId, desktop_path);
287 EXPECT_TRUE(result.on_desktop); 287 EXPECT_TRUE(result.on_desktop);
288 EXPECT_EQ(web_app::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS, 288 EXPECT_EQ(web_app::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS,
289 result.applications_menu_location); 289 result.applications_menu_location);
290 EXPECT_FALSE(result.in_quick_launch_bar); 290 EXPECT_FALSE(result.in_quick_launch_bar);
291 } 291 }
292 } 292 }
293 293
294 TEST(ShellIntegrationTest, GetExistingShortcutContents) { 294 TEST(ShellIntegrationTest, GetExistingShortcutContents) {
295 const char kTemplateFilename[] = "shortcut-test.desktop"; 295 const char kTemplateFilename[] = "shortcut-test.desktop";
296 base::FilePath kTemplateFilepath(kTemplateFilename); 296 base::FilePath kTemplateFilepath(kTemplateFilename);
297 const char kTestData1[] = "a magical testing string"; 297 const char kTestData1[] = "a magical testing string";
298 const char kTestData2[] = "a different testing string"; 298 const char kTestData2[] = "a different testing string";
299 299
300 base::MessageLoop message_loop; 300 base::MessageLoop message_loop;
301 content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop); 301 content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop);
302 302
303 // Test that it searches $XDG_DATA_HOME/applications. 303 // Test that it searches $XDG_DATA_HOME/applications.
304 { 304 {
305 base::ScopedTempDir temp_dir; 305 base::ScopedTempDir temp_dir;
306 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 306 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
307 307
308 MockEnvironment env; 308 MockEnvironment env;
309 env.Set("XDG_DATA_HOME", temp_dir.path().value()); 309 env.Set("XDG_DATA_HOME", temp_dir.GetPath().value());
310 // Create a file in a non-applications directory. This should be ignored. 310 // Create a file in a non-applications directory. This should be ignored.
311 ASSERT_TRUE(WriteString(temp_dir.path().Append(kTemplateFilename), 311 ASSERT_TRUE(
312 kTestData2)); 312 WriteString(temp_dir.GetPath().Append(kTemplateFilename), kTestData2));
313 ASSERT_TRUE(base::CreateDirectory( 313 ASSERT_TRUE(
314 temp_dir.path().Append("applications"))); 314 base::CreateDirectory(temp_dir.GetPath().Append("applications")));
315 ASSERT_TRUE(WriteString( 315 ASSERT_TRUE(WriteString(
316 temp_dir.path().Append("applications").Append(kTemplateFilename), 316 temp_dir.GetPath().Append("applications").Append(kTemplateFilename),
317 kTestData1)); 317 kTestData1));
318 std::string contents; 318 std::string contents;
319 ASSERT_TRUE( 319 ASSERT_TRUE(
320 GetExistingShortcutContents(&env, kTemplateFilepath, &contents)); 320 GetExistingShortcutContents(&env, kTemplateFilepath, &contents));
321 EXPECT_EQ(kTestData1, contents); 321 EXPECT_EQ(kTestData1, contents);
322 } 322 }
323 323
324 // Test that it falls back to $HOME/.local/share/applications. 324 // Test that it falls back to $HOME/.local/share/applications.
325 { 325 {
326 base::ScopedTempDir temp_dir; 326 base::ScopedTempDir temp_dir;
327 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 327 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
328 328
329 MockEnvironment env; 329 MockEnvironment env;
330 base::ScopedPathOverride home_override(base::DIR_HOME, 330 base::ScopedPathOverride home_override(base::DIR_HOME, temp_dir.GetPath(),
331 temp_dir.path(),
332 true /* absolute? */, 331 true /* absolute? */,
333 false /* create? */); 332 false /* create? */);
334 ASSERT_TRUE(base::CreateDirectory( 333 ASSERT_TRUE(base::CreateDirectory(
335 temp_dir.path().Append(".local/share/applications"))); 334 temp_dir.GetPath().Append(".local/share/applications")));
336 ASSERT_TRUE(WriteString( 335 ASSERT_TRUE(WriteString(temp_dir.GetPath()
337 temp_dir.path().Append(".local/share/applications") 336 .Append(".local/share/applications")
338 .Append(kTemplateFilename), 337 .Append(kTemplateFilename),
339 kTestData1)); 338 kTestData1));
340 std::string contents; 339 std::string contents;
341 ASSERT_TRUE( 340 ASSERT_TRUE(
342 GetExistingShortcutContents(&env, kTemplateFilepath, &contents)); 341 GetExistingShortcutContents(&env, kTemplateFilepath, &contents));
343 EXPECT_EQ(kTestData1, contents); 342 EXPECT_EQ(kTestData1, contents);
344 } 343 }
345 344
346 // Test that it searches $XDG_DATA_DIRS/applications. 345 // Test that it searches $XDG_DATA_DIRS/applications.
347 { 346 {
348 base::ScopedTempDir temp_dir; 347 base::ScopedTempDir temp_dir;
349 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 348 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
350 349
351 MockEnvironment env; 350 MockEnvironment env;
352 env.Set("XDG_DATA_DIRS", temp_dir.path().value()); 351 env.Set("XDG_DATA_DIRS", temp_dir.GetPath().value());
353 ASSERT_TRUE(base::CreateDirectory( 352 ASSERT_TRUE(
354 temp_dir.path().Append("applications"))); 353 base::CreateDirectory(temp_dir.GetPath().Append("applications")));
355 ASSERT_TRUE(WriteString( 354 ASSERT_TRUE(WriteString(
356 temp_dir.path().Append("applications").Append(kTemplateFilename), 355 temp_dir.GetPath().Append("applications").Append(kTemplateFilename),
357 kTestData2)); 356 kTestData2));
358 std::string contents; 357 std::string contents;
359 ASSERT_TRUE( 358 ASSERT_TRUE(
360 GetExistingShortcutContents(&env, kTemplateFilepath, &contents)); 359 GetExistingShortcutContents(&env, kTemplateFilepath, &contents));
361 EXPECT_EQ(kTestData2, contents); 360 EXPECT_EQ(kTestData2, contents);
362 } 361 }
363 362
364 // Test that it searches $X/applications for each X in $XDG_DATA_DIRS. 363 // Test that it searches $X/applications for each X in $XDG_DATA_DIRS.
365 { 364 {
366 base::ScopedTempDir temp_dir1; 365 base::ScopedTempDir temp_dir1;
367 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir()); 366 ASSERT_TRUE(temp_dir1.CreateUniqueTempDir());
368 base::ScopedTempDir temp_dir2; 367 base::ScopedTempDir temp_dir2;
369 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir()); 368 ASSERT_TRUE(temp_dir2.CreateUniqueTempDir());
370 369
371 MockEnvironment env; 370 MockEnvironment env;
372 env.Set("XDG_DATA_DIRS", temp_dir1.path().value() + ":" + 371 env.Set("XDG_DATA_DIRS",
373 temp_dir2.path().value()); 372 temp_dir1.GetPath().value() + ":" + temp_dir2.GetPath().value());
374 // Create a file in a non-applications directory. This should be ignored. 373 // Create a file in a non-applications directory. This should be ignored.
375 ASSERT_TRUE(WriteString(temp_dir1.path().Append(kTemplateFilename), 374 ASSERT_TRUE(
376 kTestData1)); 375 WriteString(temp_dir1.GetPath().Append(kTemplateFilename), kTestData1));
377 // Only create a findable desktop file in the second path. 376 // Only create a findable desktop file in the second path.
378 ASSERT_TRUE(base::CreateDirectory( 377 ASSERT_TRUE(
379 temp_dir2.path().Append("applications"))); 378 base::CreateDirectory(temp_dir2.GetPath().Append("applications")));
380 ASSERT_TRUE(WriteString( 379 ASSERT_TRUE(WriteString(
381 temp_dir2.path().Append("applications").Append(kTemplateFilename), 380 temp_dir2.GetPath().Append("applications").Append(kTemplateFilename),
382 kTestData2)); 381 kTestData2));
383 std::string contents; 382 std::string contents;
384 ASSERT_TRUE( 383 ASSERT_TRUE(
385 GetExistingShortcutContents(&env, kTemplateFilepath, &contents)); 384 GetExistingShortcutContents(&env, kTemplateFilepath, &contents));
386 EXPECT_EQ(kTestData2, contents); 385 EXPECT_EQ(kTestData2, contents);
387 } 386 }
388 } 387 }
389 388
390 TEST(ShellIntegrationTest, GetExtensionShortcutFilename) { 389 TEST(ShellIntegrationTest, GetExtensionShortcutFilename) {
391 base::FilePath kProfilePath("a/b/c/Profile Name?"); 390 base::FilePath kProfilePath("a/b/c/Profile Name?");
392 const char kExtensionId[] = "extensionid"; 391 const char kExtensionId[] = "extensionid";
393 EXPECT_EQ(base::FilePath("chrome-extensionid-Profile_Name_.desktop"), 392 EXPECT_EQ(base::FilePath("chrome-extensionid-Profile_Name_.desktop"),
394 GetExtensionShortcutFilename(kProfilePath, kExtensionId)); 393 GetExtensionShortcutFilename(kProfilePath, kExtensionId));
395 } 394 }
396 395
397 TEST(ShellIntegrationTest, GetExistingProfileShortcutFilenames) { 396 TEST(ShellIntegrationTest, GetExistingProfileShortcutFilenames) {
398 base::FilePath kProfilePath("a/b/c/Profile Name?"); 397 base::FilePath kProfilePath("a/b/c/Profile Name?");
399 const char kApp1Filename[] = "chrome-extension1-Profile_Name_.desktop"; 398 const char kApp1Filename[] = "chrome-extension1-Profile_Name_.desktop";
400 const char kApp2Filename[] = "chrome-extension2-Profile_Name_.desktop"; 399 const char kApp2Filename[] = "chrome-extension2-Profile_Name_.desktop";
401 const char kUnrelatedAppFilename[] = "chrome-extension-Other_Profile.desktop"; 400 const char kUnrelatedAppFilename[] = "chrome-extension-Other_Profile.desktop";
402 401
403 base::MessageLoop message_loop; 402 base::MessageLoop message_loop;
404 content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop); 403 content::TestBrowserThread file_thread(BrowserThread::FILE, &message_loop);
405 404
406 base::ScopedTempDir temp_dir; 405 base::ScopedTempDir temp_dir;
407 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 406 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
408 ASSERT_TRUE(WriteEmptyFile(temp_dir.path().Append(kApp1Filename))); 407 ASSERT_TRUE(WriteEmptyFile(temp_dir.GetPath().Append(kApp1Filename)));
409 ASSERT_TRUE(WriteEmptyFile(temp_dir.path().Append(kApp2Filename))); 408 ASSERT_TRUE(WriteEmptyFile(temp_dir.GetPath().Append(kApp2Filename)));
410 // This file should not be returned in the results. 409 // This file should not be returned in the results.
411 ASSERT_TRUE(WriteEmptyFile(temp_dir.path().Append(kUnrelatedAppFilename))); 410 ASSERT_TRUE(WriteEmptyFile(temp_dir.GetPath().Append(kUnrelatedAppFilename)));
412 std::vector<base::FilePath> paths = 411 std::vector<base::FilePath> paths =
413 GetExistingProfileShortcutFilenames(kProfilePath, temp_dir.path()); 412 GetExistingProfileShortcutFilenames(kProfilePath, temp_dir.GetPath());
414 // Path order is arbitrary. Sort the output for consistency. 413 // Path order is arbitrary. Sort the output for consistency.
415 std::sort(paths.begin(), paths.end()); 414 std::sort(paths.begin(), paths.end());
416 EXPECT_THAT(paths, 415 EXPECT_THAT(paths,
417 ElementsAre(base::FilePath(kApp1Filename), 416 ElementsAre(base::FilePath(kApp1Filename),
418 base::FilePath(kApp2Filename))); 417 base::FilePath(kApp2Filename)));
419 } 418 }
420 419
421 TEST(ShellIntegrationTest, GetWebShortcutFilename) { 420 TEST(ShellIntegrationTest, GetWebShortcutFilename) {
422 const struct { 421 const struct {
423 const char* const path; 422 const char* const path;
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 EXPECT_EQ("baR", internal::GetProgramClassClass(command_line, "foo.desktop")); 663 EXPECT_EQ("baR", internal::GetProgramClassClass(command_line, "foo.desktop"));
665 664
666 command_line = base::CommandLine(base::FilePath()); 665 command_line = base::CommandLine(base::FilePath());
667 command_line.AppendSwitchASCII("user-data-dir", "/tmp/baz"); 666 command_line.AppendSwitchASCII("user-data-dir", "/tmp/baz");
668 EXPECT_EQ("foo (/tmp/baz)", 667 EXPECT_EQ("foo (/tmp/baz)",
669 internal::GetProgramClassName(command_line, "foo.desktop")); 668 internal::GetProgramClassName(command_line, "foo.desktop"));
670 EXPECT_EQ("Foo", internal::GetProgramClassClass(command_line, "foo.desktop")); 669 EXPECT_EQ("Foo", internal::GetProgramClassClass(command_line, "foo.desktop"));
671 } 670 }
672 671
673 } // namespace shell_integration_linux 672 } // namespace shell_integration_linux
OLDNEW
« no previous file with comments | « chrome/browser/shell_integration_linux.cc ('k') | chrome/browser/shell_integration_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698