Skip to content

Commit

Permalink
Close screen layout notification after clicked.
Browse files Browse the repository at this point in the history
Previously, when the screen layout notification was clicked, settings
was opened, but the notification is still seen.

However, the notification should be closed just after clicked.

BUG=816414
TEST=ash_unittests

Change-Id: I853515e6131d7377f94d5d4cbf120f0fd95d0c3c
Reviewed-on: https://chromium-review.googlesource.com/938804
Reviewed-by: Sadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: Tetsui Ohkubo <tetsui@chromium.org>
Commit-Queue: Megumi Hattori <megumihattori@google.com>
Cr-Commit-Position: refs/heads/master@{#540452}
  • Loading branch information
Megumi Hattori authored and Commit Bot committed Mar 2, 2018
1 parent 099eef9 commit 1d62281
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ash/system/screen_layout_observer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ base::string16 GetDisplaySize(int64_t display_id) {
}

// Callback to handle a user selecting the notification view.
void OpenSettingsFromNotification(base::Optional<int> button_index) {
void OnNotificationClicked(base::Optional<int> button_index) {
DCHECK(!button_index);

Shell::Get()->metrics()->RecordUserMetricsAction(
Expand All @@ -80,6 +80,8 @@ void OpenSettingsFromNotification(base::Optional<int> button_index) {
Shell::Get()->metrics()->RecordUserMetricsAction(
UMA_STATUS_AREA_DISPLAY_NOTIFICATION_SHOW_SETTINGS);
}
message_center::MessageCenter::Get()->RemoveNotification(
ScreenLayoutObserver::kNotificationId, true /* by_user */);
}

// Returns the name of the currently connected external display whose ID is
Expand Down Expand Up @@ -371,7 +373,7 @@ void ScreenLayoutObserver::CreateOrUpdateNotification(
message_center::NotifierId::SYSTEM_COMPONENT, kNotifierDisplay),
message_center::RichNotificationData(),
new message_center::HandleNotificationClickDelegate(
base::Bind(&OpenSettingsFromNotification)),
base::Bind(&OnNotificationClicked)),
kNotificationScreenIcon,
message_center::SystemNotificationWarningLevel::NORMAL);
notification->set_clickable(true);
Expand Down
19 changes: 19 additions & 0 deletions ash/system/screen_layout_observer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class ScreenLayoutObserverTest : public AshTestBase {
void CheckUpdate();

void CloseNotification();
void ClickNotification();
base::string16 GetDisplayNotificationText() const;
base::string16 GetDisplayNotificationAdditionalText() const;

Expand Down Expand Up @@ -82,6 +83,11 @@ void ScreenLayoutObserverTest::CloseNotification() {
RunAllPendingInMessageLoop();
}

void ScreenLayoutObserverTest::ClickNotification() {
const message_center::Notification* notification = GetDisplayNotification();
notification->Click();
}

base::string16 ScreenLayoutObserverTest::GetDisplayNotificationText() const {
const message_center::Notification* notification = GetDisplayNotification();
return notification ? notification->title() : base::string16();
Expand Down Expand Up @@ -706,4 +712,17 @@ TEST_F(ScreenLayoutObserverTest, MirrorModeAddOrRemoveDisplayMessage) {
EXPECT_TRUE(display_manager()->IsInMirrorMode());
}

TEST_F(ScreenLayoutObserverTest, ClickNotification) {
Shell::Get()->screen_layout_observer()->set_show_notifications_for_testing(
true);

// Create notification.
UpdateDisplay("400x400/r");
EXPECT_FALSE(GetDisplayNotificationAdditionalText().empty());

// Click notification.
ClickNotification();
EXPECT_TRUE(GetDisplayNotificationAdditionalText().empty());
}

} // namespace ash

0 comments on commit 1d62281

Please sign in to comment.