Skip to content

Commit

Permalink
Revert "[dpwa] Adds the DeletePlatformShortcut action and the manual …
Browse files Browse the repository at this point in the history
…browser test."

This reverts commit ff4471f.

Reason for revert: WebAppIntegrationBrowserTestMacWinLinux.CheckDeletePlatformShortcut is failing on Mac-11.

Original change's description:
> [dpwa] Adds the DeletePlatformShortcut action and the manual browser test.
>
> Change-Id: I3342f1e54559ee1fd5d4dfab5c358e8ea222a187
> Bug: 1324525
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3632952
> Commit-Queue: Clifford Cheng <cliffordcheng@chromium.org>
> Reviewed-by: Daniel Murphy <dmurph@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#1002161}

Bug: 1324525, 1324818
Change-Id: Ief4f5119b420b82bfc6517398ecf5c1968c027cc
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3641261
Auto-Submit: Minoru Chikamune <chikamune@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Owners-Override: Minoru Chikamune <chikamune@google.com>
Commit-Queue: Minoru Chikamune <chikamune@google.com>
Cr-Commit-Position: refs/heads/main@{#1002466}
  • Loading branch information
Minoru Chikamune authored and Chromium LUCI CQ committed May 12, 2022
1 parent 6027c64 commit 7554988
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,6 @@ IN_PROC_BROWSER_TEST_F(WebAppIntegrationBrowserTestMacWinLinux,
helper_.CheckPlatformShortcutNotExists(Site::kSiteA);
}

IN_PROC_BROWSER_TEST_F(WebAppIntegrationBrowserTestMacWinLinux,
CheckDeletePlatformShortcut) {
helper_.DeletePlatformShortcut(Site::kSiteA);
helper_.InstallCreateShortcutWindowed(Site::kSiteA);
helper_.CheckPlatformShortcutAndIcon(Site::kSiteA);
helper_.DeletePlatformShortcut(Site::kSiteA);
helper_.CheckPlatformShortcutNotExists(Site::kSiteA);
}

// Generated tests:

IN_PROC_BROWSER_TEST_F(
Expand Down
159 changes: 57 additions & 102 deletions chrome/browser/ui/views/web_apps/web_app_integration_test_driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,27 @@ base::FilePath GetShortcutProfile(base::FilePath shortcut_path) {
}
return shortcut_profile;
}

bool IsShortcutAndIconCorrectOnWin(Profile* profile,
const std::string& name,
base::FilePath shortcut_dir,
SkColor expected_icon_pixel_color) {
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
base::FileEnumerator enumerator(shortcut_dir, false,
base::FileEnumerator::FILES);
while (!enumerator.Next().empty()) {
std::wstring shortcut_filename = enumerator.GetInfo().GetName().value();
if (re2::RE2::FullMatch(converter.to_bytes(shortcut_filename),
name + "(.*).lnk")) {
base::FilePath shortcut_path = shortcut_dir.Append(shortcut_filename);
if (GetShortcutProfile(shortcut_path) == profile->GetBaseName()) {
SkColor icon_pixel_color = GetIconTopLeftColor(shortcut_path);
return (icon_pixel_color == expected_icon_pixel_color);
}
}
}
return false;
}
#endif

#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
Expand Down Expand Up @@ -1001,86 +1022,6 @@ void WebAppIntegrationTestDriver::OpenAppSettingsFromChromeApps(Site site) {
#endif
}

void WebAppIntegrationTestDriver::DeletePlatformShortcut(Site site) {
if (!before_state_change_action_state_ && !after_state_change_action_state_)
return;
BeforeStateChangeAction(__FUNCTION__);
base::ScopedAllowBlockingForTesting allow_blocking;
AppId app_id = GetAppIdBySiteMode(site);
std::string app_name = provider()->registrar().GetAppShortName(app_id);
if (app_name.empty()) {
ASSERT_TRUE(base::Contains(g_site_to_app_name, site));
app_name = g_site_to_app_name.find(site)->second;
}
#if BUILDFLAG(IS_WIN)
base::FilePath desktop_shortcut_path =
GetShortcutPath(shortcut_override_->desktop.GetPath(), app_name, app_id);
ASSERT_TRUE(base::PathExists(desktop_shortcut_path));
base::DeleteFile(desktop_shortcut_path);
base::FilePath app_menu_shortcut_path = GetShortcutPath(
shortcut_override_->application_menu.GetPath(), app_name, app_id);
ASSERT_TRUE(base::PathExists(app_menu_shortcut_path));
base::DeleteFile(app_menu_shortcut_path);
AfterStateChangeAction();
#elif BUILDFLAG(IS_MAC)
base::FilePath app_folder_shortcut_path = GetShortcutPath(
shortcut_override_->chrome_apps_folder.GetPath(), app_name, app_id);
ASSERT_TRUE(base::PathExists(app_folder_shortcut_path));
base::DeleteFile(app_folder_shortcut_path);
AfterStateChangeAction();
#elif BUILDFLAG(IS_LINUX)
base::FilePath desktop_shortcut_path =
GetShortcutPath(shortcut_override_->desktop.GetPath(), app_name, app_id);
ASSERT_TRUE(base::PathExists(desktop_shortcut_path));
base::DeleteFile(desktop_shortcut_path);
AfterStateChangeAction();
#else
NOTREACHED() << "Not implemented on Chrome OS.";
#endif
}

base::FilePath WebAppIntegrationTestDriver::GetShortcutPath(
base::FilePath shortcut_dir,
const std::string& app_name,
const AppId& app_id) {
base::FilePath shortcut_path;
#if BUILDFLAG(IS_WIN)
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
base::FileEnumerator enumerator(shortcut_dir, false,
base::FileEnumerator::FILES);
while (!enumerator.Next().empty()) {
std::wstring shortcut_filename = enumerator.GetInfo().GetName().value();
if (re2::RE2::FullMatch(converter.to_bytes(shortcut_filename),
app_name + "(.*).lnk")) {
shortcut_path = shortcut_dir.Append(shortcut_filename);
if (GetShortcutProfile(shortcut_path) == profile()->GetBaseName())
return shortcut_path;
}
}
#elif BUILDFLAG(IS_MAC)
std::string shortcut_filename = app_name + ".app";
shortcut_path = shortcut_dir.Append(shortcut_filename);
AppShimRegistry* registry = AppShimRegistry::Get();
// Exits early if the app id is empty because the verification won't work.
// TODO(crbug.com/1289865): Figure a way to find the profile that has the app
// installed without using app ID.
if (!app_id.empty()) {
std::set<base::FilePath> app_installed_profiles =
registry->GetInstalledProfilesForApp(app_id);
if (app_installed_profiles.find(profile()->GetPath()) !=
app_installed_profiles.end())
return shortcut_path;
}
#elif BUILDFLAG(IS_LINUX)
std::string shortcut_filename =
"chrome-" + app_id + "-" + profile()->GetBaseName().value() + ".desktop";
shortcut_path = shortcut_dir.Append(shortcut_filename);
if (base::PathExists(shortcut_path))
return shortcut_path;
#endif
return shortcut_path;
}

void WebAppIntegrationTestDriver::CheckAppSettingsAppState(
Profile* profile,
const AppState& app_state) {
Expand Down Expand Up @@ -1806,10 +1747,9 @@ void WebAppIntegrationTestDriver::CheckRunOnOsLoginEnabled(Site site) {
#elif BUILDFLAG(IS_WIN)
DCHECK(base::Contains(g_app_name_icon_color, app_state->name));
SkColor color = g_app_name_icon_color.find(app_state->name)->second;
base::FilePath startup_shortcut_path = GetShortcutPath(
shortcut_override_->startup.GetPath(), app_state->name, app_state->id);
ASSERT_TRUE(base::PathExists(startup_shortcut_path));
ASSERT_TRUE(GetIconTopLeftColor(startup_shortcut_path) == color);
ASSERT_TRUE(IsShortcutAndIconCorrectOnWin(
profile(), app_state->name, shortcut_override_->startup.GetPath(),
color));
#elif BUILDFLAG(IS_MAC)
std::string shortcut_filename = app_state->name + ".app";
base::FilePath app_shortcut_path =
Expand All @@ -1833,9 +1773,11 @@ void WebAppIntegrationTestDriver::CheckRunOnOsLoginDisabled(Site site) {
ASSERT_FALSE(base::PathExists(
shortcut_override_->startup.GetPath().Append(shortcut_filename)));
#elif BUILDFLAG(IS_WIN)
base::FilePath startup_shortcut_path = GetShortcutPath(
shortcut_override_->startup.GetPath(), app_state->name, app_state->id);
ASSERT_FALSE(base::PathExists(startup_shortcut_path));
DCHECK(base::Contains(g_app_name_icon_color, app_state->name));
SkColor color = g_app_name_icon_color.find(app_state->name)->second;
ASSERT_FALSE(IsShortcutAndIconCorrectOnWin(
profile(), app_state->name, shortcut_override_->startup.GetPath(),
color));
#elif BUILDFLAG(IS_MAC)
std::string shortcut_filename = app_state->name + ".app";
base::FilePath app_shortcut_path =
Expand Down Expand Up @@ -2399,28 +2341,41 @@ bool WebAppIntegrationTestDriver::IsShortcutAndIconCreated(
#endif

#if BUILDFLAG(IS_WIN)
base::FilePath desktop_shortcut_path =
GetShortcutPath(shortcut_override_->desktop.GetPath(), name, id);
base::FilePath application_menu_shortcut_path =
GetShortcutPath(shortcut_override_->application_menu.GetPath(), name, id);
if (base::PathExists(desktop_shortcut_path) &&
base::PathExists(application_menu_shortcut_path))
is_shortcut_and_icon_correct =
(GetIconTopLeftColor(desktop_shortcut_path) ==
expected_icon_pixel_color &&
GetIconTopLeftColor(application_menu_shortcut_path) ==
expected_icon_pixel_color);
is_shortcut_and_icon_correct =
(IsShortcutAndIconCorrectOnWin(profile, name,
shortcut_override_->desktop.GetPath(),
expected_icon_pixel_color) &&
IsShortcutAndIconCorrectOnWin(
profile, name, shortcut_override_->application_menu.GetPath(),
expected_icon_pixel_color));
#elif BUILDFLAG(IS_MAC)
base::FilePath app_shortcut_path = GetShortcutPath(
shortcut_override_->chrome_apps_folder.GetPath(), name, id);
if (base::PathExists(app_shortcut_path)) {
std::string shortcut_filename = name + ".app";
base::FilePath app_shortcut_path =
shortcut_override_->chrome_apps_folder.GetPath().Append(
shortcut_filename);
AppShimRegistry* registry = AppShimRegistry::Get();
bool is_app_profile_found = false;
// Exits early if the app id is empty because the verification won't work.
// TODO(crbug.com/1289865): Figure a way to find the profile that has the app
// installed without using app ID.
if (id.empty())
return false;
std::set<base::FilePath> app_installed_profiles =
registry->GetInstalledProfilesForApp(id);
is_app_profile_found = (app_installed_profiles.find(profile->GetPath()) !=
app_installed_profiles.end());
bool shortcut_exists =
(base::PathExists(app_shortcut_path) && is_app_profile_found);
if (shortcut_exists) {
SkColor icon_pixel_color = GetIconTopLeftColor(app_shortcut_path);
is_shortcut_and_icon_correct =
(icon_pixel_color == expected_icon_pixel_color);
}
#elif BUILDFLAG(IS_LINUX)
std::string shortcut_filename =
"chrome-" + id + "-" + profile->GetBaseName().value() + ".desktop";
base::FilePath desktop_shortcut_path =
GetShortcutPath(shortcut_override_->desktop.GetPath(), name, id);
shortcut_override_->desktop.GetPath().Append(shortcut_filename);
if (base::PathExists(desktop_shortcut_path)) {
is_shortcut_and_icon_correct = IconManagerCheckIconTopLeftColor(
provider()->icon_manager(), id, {kLauncherIconSize, kInstallIconSize},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ class WebAppIntegrationTestDriver : WebAppInstallManagerObserver {
void ApplyRunOnOsLoginPolicyAllowed(Site site);
void ApplyRunOnOsLoginPolicyBlocked(Site site);
void ApplyRunOnOsLoginPolicyRunWindowed(Site site);
void DeletePlatformShortcut(Site site);
void RemoveRunOnOsLoginPolicy(Site site);
void LaunchFromChromeApps(Site site);
void LaunchFromLaunchIcon(Site site);
Expand Down Expand Up @@ -297,9 +296,6 @@ class WebAppIntegrationTestDriver : WebAppInstallManagerObserver {
content::WebContents* GetCurrentTab(Browser* browser);
GURL GetInScopeURL(Site site);
GURL GetScopeForSiteMode(Site site);
base::FilePath GetShortcutPath(base::FilePath shortcut_dir,
const std::string& app_name,
const AppId& app_id);
GURL GetURLForSiteMode(Site site);
void InstallCreateShortcut(bool open_in_window);

Expand Down

0 comments on commit 7554988

Please sign in to comment.