Commit f08397f2 authored by nancylingwang@google.com's avatar nancylingwang@google.com Committed by Commit Bot

Add notification badging test cases for install and uninstall apps.

BUG=1068884

Change-Id: I7fd646bc3a714c6d06554d886c7a802771497559
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2203041
Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771775}
parent adbbc60a
......@@ -22,8 +22,7 @@ void AppNotifications::RemoveNotification(const std::string& notification_id) {
auto it = notification_id_to_app_ids_.find(notification_id);
DCHECK(it != notification_id_to_app_ids_.end());
const auto& app_ids = it->second;
for (const auto& app_id : app_ids) {
for (const auto& app_id : it->second) {
auto app_id_it = app_id_to_notification_ids_.find(app_id);
app_id_it->second.erase(notification_id);
if (app_id_it->second.empty()) {
......@@ -33,6 +32,22 @@ void AppNotifications::RemoveNotification(const std::string& notification_id) {
notification_id_to_app_ids_.erase(it);
}
void AppNotifications::RemoveNotificationsForApp(const std::string& app_id) {
auto it = app_id_to_notification_ids_.find(app_id);
if (it == app_id_to_notification_ids_.end()) {
return;
}
for (const auto& notification_id : it->second) {
auto notification_id_it = notification_id_to_app_ids_.find(notification_id);
notification_id_it->second.erase(app_id);
if (notification_id_it->second.empty()) {
notification_id_to_app_ids_.erase(notification_id_it);
}
}
app_id_to_notification_ids_.erase(it);
}
bool AppNotifications::HasNotification(const std::string& app_id) {
return base::Contains(app_id_to_notification_ids_, app_id);
}
......
......@@ -30,6 +30,9 @@ class AppNotifications {
// Removes the notification for the given |notification_id|.
void RemoveNotification(const std::string& notification_id);
// Removes notifications for the given |app_id|.
void RemoveNotificationsForApp(const std::string& app_id);
// Returns true, if the app has notifications. Otherwise, returns false.
bool HasNotification(const std::string& app_id);
......
......@@ -323,6 +323,13 @@ void AppServiceProxy::Uninstall(const std::string& app_id,
#endif
}
void AppServiceProxy::UninstallSilently(const std::string& app_id) {
if (app_service_.is_connected()) {
app_service_->Uninstall(cache_.GetAppType(app_id), app_id,
/*clear_site_data=*/false, /*report_abuse=*/false);
}
}
#if defined(OS_CHROMEOS)
void AppServiceProxy::PauseApps(
const std::map<std::string, PauseData>& pause_data) {
......@@ -441,6 +448,7 @@ void AppServiceProxy::UninstallForTesting(const std::string& app_id,
base::OnceClosure callback) {
UninstallImpl(app_id, parent_window, std::move(callback));
}
#endif
std::vector<std::string> AppServiceProxy::GetAppIdsForUrl(const GURL& url) {
......
......@@ -157,6 +157,10 @@ class AppServiceProxy : public KeyedService,
// |parent_window|. Otherwise, the browser window will be used as the anchor.
void Uninstall(const std::string& app_id, gfx::NativeWindow parent_window);
// Uninstalls an app for the given |app_id| without prompting the user to
// confirm.
void UninstallSilently(const std::string& app_id);
#if defined(OS_CHROMEOS)
// Pauses apps. |pause_data|'s key is the app_id. |pause_data|'s PauseData
// is the time limit setting for the app, which is shown in the pause app
......
......@@ -733,6 +733,7 @@ void ArcApps::OnAppStatesChanged(const std::string& app_id,
}
void ArcApps::OnAppRemoved(const std::string& app_id) {
app_notifications_.RemoveNotificationsForApp(app_id);
paused_apps_.MaybeRemoveApp(app_id);
if (base::Contains(app_id_to_task_ids_, app_id)) {
......
......@@ -469,6 +469,7 @@ void ExtensionAppsChromeOs::OnExtensionUninstalled(
return;
}
app_notifications_.RemoveNotificationsForApp(extension->id());
paused_apps_.MaybeRemoveApp(extension->id());
ExtensionAppsBase::OnExtensionUninstalled(browser_context, extension, reason);
......
......@@ -235,6 +235,7 @@ void WebAppsChromeOs::OnWebAppUninstalled(const web_app::AppId& app_id) {
return;
}
app_notifications_.RemoveNotificationsForApp(app_id);
paused_apps_.MaybeRemoveApp(app_id);
WebAppsBase::OnWebAppUninstalled(app_id);
......
......@@ -20,6 +20,7 @@
#include "chrome/browser/ui/web_applications/app_browser_controller.h"
#include "chrome/browser/web_applications/components/app_registrar.h"
#include "chrome/browser/web_applications/components/external_install_options.h"
#include "chrome/browser/web_applications/components/install_finalizer.h"
#include "chrome/browser/web_applications/components/pending_app_manager.h"
#include "chrome/browser/web_applications/components/web_app_constants.h"
#include "chrome/browser/web_applications/components/web_app_helpers.h"
......@@ -204,4 +205,12 @@ bool IsBrowserOpen(const Browser* test_browser) {
return false;
}
void UninstallWebApp(Profile* profile, const AppId& app_id) {
auto* provider = WebAppProviderBase::GetProviderBase(profile);
DCHECK(provider);
DCHECK(provider->install_finalizer().CanUserUninstallExternalApp(app_id));
provider->install_finalizer().UninstallExternalAppByUser(app_id,
base::DoNothing());
}
} // namespace web_app
......@@ -61,6 +61,9 @@ AppMenuCommandState GetAppMenuCommandState(int command_id, Browser* browser);
bool IsBrowserOpen(const Browser* test_browser);
// Launches the app for |app| in |profile|.
void UninstallWebApp(Profile* profile, const AppId& app_id);
} // namespace web_app
#endif // CHROME_BROWSER_UI_WEB_APPLICATIONS_TEST_WEB_APP_BROWSERTEST_UTIL_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment