Commit 05d61186 authored by dewittj@chromium.org's avatar dewittj@chromium.org

Allow extension crash notifications to replace each other.

Previously they did not set an origin or replace_id, causing updates
to be turned into adds in the notification UI manager, where it would
DCHECK because the id matched that of an existing notification.

This patch adds a replace_id and origin so that updates can happen
smoothly.

BUG=360591

Review URL: https://codereview.chromium.org/294473002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272006 0039d316-1c4b-4281-b951-d872f2087c98
parent 737c0831
......@@ -177,11 +177,11 @@ void NotificationImageReady(
// TODO(mukai, dewittj): remove this and switch to message center
// notifications.
DesktopNotificationService::AddIconNotification(
GURL() /* empty origin */,
base::string16(),
GURL("chrome://extension-crash"), // Origin URL.
base::string16(), // Title of notification.
message,
notification_icon,
base::string16(),
base::UTF8ToUTF16(delegate->id()), // Replace ID.
delegate.get(),
profile);
}
......
......@@ -131,8 +131,6 @@ class NotificationWaiter : public message_center::MessageCenterObserver {
DCHECK(!run_loop_.running());
message_center::MessageCenter* message_center =
message_center::MessageCenter::Get();
if (message_center->HasNotification(target_id_))
return;
message_center->AddObserver(this);
run_loop_.Run();
......@@ -147,6 +145,12 @@ class NotificationWaiter : public message_center::MessageCenterObserver {
run_loop_.Quit();
}
virtual void OnNotificationUpdated(
const std::string& notification_id) OVERRIDE {
if (notification_id == target_id_)
run_loop_.Quit();
}
std::string target_id_;
base::RunLoop run_loop_;
......@@ -366,4 +370,19 @@ TEST_F(BackgroundContentsServiceNotificationTest, TestShowBalloonNoIcon) {
const Notification* notification = CreateCrashNotification(extension);
EXPECT_FALSE(notification->icon().IsEmpty());
}
TEST_F(BackgroundContentsServiceNotificationTest, TestShowTwoBalloons) {
TestingProfile profile;
scoped_refptr<extensions::Extension> extension =
extension_test_util::LoadManifest("app", "manifest.json");
ASSERT_TRUE(extension.get());
CreateCrashNotification(extension);
CreateCrashNotification(extension);
message_center::MessageCenter* message_center =
message_center::MessageCenter::Get();
message_center::NotificationList::Notifications notifications =
message_center->GetVisibleNotifications();
ASSERT_EQ(1u, notifications.size());
}
#endif
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