@@ -48,6 +48,14 @@ web_app::LaunchXdgUtilityForTesting& GetInstalledLaunchXdgUtilityForTesting() {
48
48
return *instance;
49
49
}
50
50
51
+ base::FilePath GetDesktopPath () {
52
+ base::FilePath desktop_path;
53
+ if (web_app::GetShortcutOverrideForTesting ())
54
+ return web_app::GetShortcutOverrideForTesting ()->desktop ;
55
+ base::PathService::Get (base::DIR_USER_DESKTOP, &desktop_path);
56
+ return desktop_path;
57
+ }
58
+
51
59
// Result of creating app shortcut icon.
52
60
// Success is recorded for each icon image, but the first two errors
53
61
// are per app, so the success/error ratio might not be very meaningful.
@@ -201,8 +209,8 @@ bool CreateShortcutAtLocation(const base::FilePath location_path,
201
209
202
210
bool CreateShortcutOnDesktop (const base::FilePath& shortcut_filename,
203
211
const std::string& contents) {
204
- base::FilePath desktop_path;
205
- if (! base::PathService::Get (base::DIR_USER_DESKTOP, & desktop_path)) {
212
+ base::FilePath desktop_path = GetDesktopPath () ;
213
+ if (desktop_path. empty ( )) {
206
214
RecordCreateShortcut (CreateShortcutResult::kFailToGetDesktopPath );
207
215
return false ;
208
216
}
@@ -213,6 +221,7 @@ bool CreateShortcutOnDesktop(const base::FilePath& shortcut_filename,
213
221
bool CreateShortcutInAutoStart (base::Environment* env,
214
222
const base::FilePath& shortcut_filename,
215
223
const std::string& contents) {
224
+ DCHECK (!web_app::GetShortcutOverrideForTesting ());
216
225
base::FilePath autostart_path = AutoStart::GetAutostartDirectory (env);
217
226
if (!base::DirectoryExists (autostart_path) &&
218
227
!base::CreateDirectory (autostart_path)) {
@@ -231,6 +240,7 @@ bool CreateShortcutInApplicationsMenu(base::Environment* env,
231
240
const std::string& contents,
232
241
const base::FilePath& directory_filename,
233
242
const std::string& directory_contents) {
243
+ DCHECK (!web_app::GetShortcutOverrideForTesting ());
234
244
base::ScopedTempDir temp_dir;
235
245
if (!temp_dir.CreateUniqueTempDir ()) {
236
246
RecordCreateShortcut (CreateShortcutResult::kFailToCreateTempDir );
@@ -321,9 +331,9 @@ base::FilePath GetAppShortcutFilename(const base::FilePath& profile_path,
321
331
}
322
332
323
333
bool DeleteShortcutOnDesktop (const base::FilePath& shortcut_filename) {
324
- base::FilePath desktop_path;
334
+ base::FilePath desktop_path = GetDesktopPath () ;
325
335
bool result = false ;
326
- if (base::PathService::Get (base::DIR_USER_DESKTOP, & desktop_path))
336
+ if (! desktop_path. empty ( ))
327
337
result = base::DeleteFile (desktop_path.Append (shortcut_filename));
328
338
return result;
329
339
}
@@ -362,6 +372,21 @@ bool CreateDesktopShortcut(base::Environment* env,
362
372
base::ScopedBlockingCall scoped_blocking_call (FROM_HERE,
363
373
base::BlockingType::MAY_BLOCK);
364
374
375
+ bool create_shortcut_in_startup = creation_locations.in_startup ;
376
+ // Do not create the shortcuts in startup directory when testing because
377
+ // xdg-utility (which creates this shortcut) doesn't work well with temp
378
+ // directories.
379
+ if (web_app::GetShortcutOverrideForTesting ())
380
+ create_shortcut_in_startup = false ;
381
+
382
+ ApplicationsMenuLocation applications_menu_location =
383
+ creation_locations.applications_menu_location ;
384
+ // Do not create the shortcuts in startup directory when testing because
385
+ // xdg-utility (which creates this shortcut) doesn't work well with temp
386
+ // directories.
387
+ if (web_app::GetShortcutOverrideForTesting ())
388
+ applications_menu_location = APP_MENU_LOCATION_NONE;
389
+
365
390
base::FilePath shortcut_filename;
366
391
if (!shortcut_info.extension_id .empty ()) {
367
392
shortcut_filename = GetAppShortcutFilename (shortcut_info.profile_path ,
@@ -371,11 +396,11 @@ bool CreateDesktopShortcut(base::Environment* env,
371
396
if (creation_locations.on_desktop )
372
397
DeleteShortcutOnDesktop (shortcut_filename);
373
398
374
- if (creation_locations.in_startup )
399
+ if (create_shortcut_in_startup)
400
+ // if (creation_locations.in_startup)
375
401
DeleteShortcutInAutoStart (env, shortcut_filename);
376
402
377
- if (creation_locations.applications_menu_location !=
378
- APP_MENU_LOCATION_NONE) {
403
+ if (applications_menu_location != APP_MENU_LOCATION_NONE) {
379
404
DeleteShortcutInApplicationsMenu (shortcut_filename, base::FilePath ());
380
405
}
381
406
} else {
@@ -410,7 +435,8 @@ bool CreateDesktopShortcut(base::Environment* env,
410
435
success = CreateShortcutOnDesktop (shortcut_filename, contents);
411
436
}
412
437
413
- if (creation_locations.in_startup ) {
438
+ if (create_shortcut_in_startup) {
439
+ // if (creation_locations.in_startup) {
414
440
std::string contents = shell_integration_linux::GetDesktopFileContents (
415
441
chrome_exe_path, app_name, shortcut_info.url ,
416
442
shortcut_info.extension_id , shortcut_info.title , icon_name,
@@ -419,7 +445,7 @@ bool CreateDesktopShortcut(base::Environment* env,
419
445
CreateShortcutInAutoStart (env, shortcut_filename, contents) && success;
420
446
}
421
447
422
- if (creation_locations. applications_menu_location == APP_MENU_LOCATION_NONE) {
448
+ if (applications_menu_location == APP_MENU_LOCATION_NONE) {
423
449
return success;
424
450
}
425
451
@@ -479,9 +505,8 @@ ShortcutLocations GetExistingShortcutLocations(
479
505
ShortcutLocations locations;
480
506
481
507
// Determine whether there is a shortcut on desktop.
482
- base::FilePath desktop_path;
483
- // If Get returns false, just leave desktop_path empty.
484
- base::PathService::Get (base::DIR_USER_DESKTOP, &desktop_path);
508
+ base::FilePath desktop_path = GetDesktopPath ();
509
+
485
510
if (!desktop_path.empty ()) {
486
511
locations.on_desktop =
487
512
base::PathExists (desktop_path.Append (shortcut_filename));
@@ -542,8 +567,8 @@ bool DeleteAllDesktopShortcuts(base::Environment* env,
542
567
543
568
bool result = true ;
544
569
// Delete shortcuts from Desktop.
545
- base::FilePath desktop_path;
546
- if (base::PathService::Get (base::DIR_USER_DESKTOP, & desktop_path)) {
570
+ base::FilePath desktop_path = GetDesktopPath () ;
571
+ if (! desktop_path. empty ( )) {
547
572
std::vector<base::FilePath> shortcut_filenames_desktop =
548
573
shell_integration_linux::GetExistingProfileShortcutFilenames (
549
574
profile_path, desktop_path);
@@ -610,9 +635,7 @@ std::vector<base::FilePath> GetShortcutLocations(
610
635
DCHECK (!shortcut_filename.empty ());
611
636
612
637
if (locations.on_desktop ) {
613
- base::FilePath desktop_path;
614
- // If Get returns false, just leave |desktop_path| empty.
615
- base::PathService::Get (base::DIR_USER_DESKTOP, &desktop_path);
638
+ base::FilePath desktop_path = GetDesktopPath ();
616
639
if (!desktop_path.empty ()) {
617
640
base::FilePath desktop_shortcut_path =
618
641
desktop_path.Append (shortcut_filename);
0 commit comments