-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PrivacyIndicators: Add launch settings notification button.
Add the buttons to privacy indicators notification with the functionality to launch the app settings. The button to launch the app will be implemented in the future. Also, added unit tests for PrivacyIndicatorsController. Bug: 1344681 Change-Id: Ic97fe58da719fa37b57fb8268bf3ceef2d1877b8 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3827623 Reviewed-by: Ahmed Fakhry <afakhry@chromium.org> Reviewed-by: Alex Newcomer <newcomer@chromium.org> Commit-Queue: Andre Le <leandre@chromium.org> Cr-Commit-Position: refs/heads/main@{#1035123}
- Loading branch information
Andre Le
authored and
Chromium LUCI CQ
committed
Aug 15, 2022
1 parent
e1b241c
commit dc88516
Showing
8 changed files
with
243 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
ash/ash_strings_grd/IDS_PRIVACY_NOTIFICATION_BUTTON_APP_LAUNCH.png.sha1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
b39e1039abbe8b4b283caaa49179df03e639d98b |
1 change: 1 addition & 0 deletions
1
ash/ash_strings_grd/IDS_PRIVACY_NOTIFICATION_BUTTON_APP_SETTINGS.png.sha1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0db2f5a5696cfaae437f53d87945927583da33df |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
ash/system/privacy/privacy_indicators_controller_unittest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
// Copyright 2022 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "ash/system/privacy/privacy_indicators_controller.h" | ||
|
||
#include <string> | ||
|
||
#include "ash/system/message_center/ash_message_popup_collection.h" | ||
#include "ash/system/message_center/unified_message_center_bubble.h" | ||
#include "ash/system/message_center/unified_message_center_view.h" | ||
#include "ash/system/message_center/unified_message_list_view.h" | ||
#include "ash/system/unified/unified_system_tray.h" | ||
#include "ash/test/ash_test_base.h" | ||
#include "base/bind.h" | ||
#include "ui/events/test/event_generator.h" | ||
#include "ui/message_center/message_center.h" | ||
#include "ui/message_center/views/notification_view_base.h" | ||
#include "ui/views/widget/widget_utils.h" | ||
|
||
namespace ash { | ||
|
||
namespace { | ||
|
||
const char kPrivacyIndicatorsNotificationIdPrefix[] = "privacy-indicators"; | ||
|
||
class TestDelegate : public PrivacyIndicatorsNotificationDelegate { | ||
public: | ||
TestDelegate() | ||
: PrivacyIndicatorsNotificationDelegate( | ||
base::BindRepeating(&TestDelegate::LaunchApp, | ||
base::Unretained(this)), | ||
base::BindRepeating(&TestDelegate::LaunchAppSettings, | ||
base::Unretained(this))) {} | ||
TestDelegate(const TestDelegate&) = delete; | ||
TestDelegate& operator=(const TestDelegate&) = delete; | ||
|
||
void LaunchApp() { launch_app_called_ = true; } | ||
void LaunchAppSettings() { launch_settings_called_ = true; } | ||
|
||
bool launch_app_called() { return launch_app_called_; } | ||
bool launch_settings_called() { return launch_settings_called_; } | ||
|
||
private: | ||
~TestDelegate() override = default; | ||
|
||
bool launch_app_called_ = false; | ||
bool launch_settings_called_ = false; | ||
}; | ||
|
||
} // namespace | ||
|
||
class PrivacyIndicatorsControllerTest : public AshTestBase { | ||
public: | ||
PrivacyIndicatorsControllerTest() = default; | ||
PrivacyIndicatorsControllerTest(const PrivacyIndicatorsControllerTest&) = | ||
delete; | ||
PrivacyIndicatorsControllerTest& operator=( | ||
const PrivacyIndicatorsControllerTest&) = delete; | ||
~PrivacyIndicatorsControllerTest() override = default; | ||
|
||
// Get the notification view from message center associated with `id`. | ||
views::View* GetNotificationViewFromMessageCenter(const std::string& id) { | ||
return GetPrimaryUnifiedSystemTray() | ||
->message_center_bubble() | ||
->message_center_view() | ||
->message_list_view() | ||
->GetMessageViewForNotificationId(id); | ||
} | ||
|
||
// Get the popup notification view associated with `id`. | ||
views::View* GetPopupNotificationView(const std::string& id) { | ||
return GetPrimaryUnifiedSystemTray() | ||
->GetMessagePopupCollection() | ||
->GetMessageViewForNotificationId(id); | ||
} | ||
|
||
void ClickView(message_center::NotificationViewBase* view, int button_index) { | ||
auto* action_buttons = view->GetViewByID( | ||
message_center::NotificationViewBase::kActionButtonsRow); | ||
|
||
auto* button_view = action_buttons->children()[button_index]; | ||
|
||
ui::test::EventGenerator generator(GetRootWindow(button_view->GetWidget())); | ||
gfx::Point cursor_location = button_view->GetBoundsInScreen().CenterPoint(); | ||
generator.MoveMouseTo(cursor_location); | ||
generator.ClickLeftButton(); | ||
} | ||
}; | ||
|
||
TEST_F(PrivacyIndicatorsControllerTest, NotificationMetadata) { | ||
std::string app_id = "test_app_id"; | ||
std::u16string app_name = u"test_app_name"; | ||
std::string notification_id = kPrivacyIndicatorsNotificationIdPrefix + app_id; | ||
scoped_refptr<TestDelegate> delegate = base::MakeRefCounted<TestDelegate>(); | ||
ash::ModifyPrivacyIndicatorsNotification( | ||
app_id, app_name, /*camera_is_used=*/true, /*microphone_is_used=*/true, | ||
delegate); | ||
|
||
auto* notification = | ||
message_center::MessageCenter::Get()->FindNotificationById( | ||
notification_id); | ||
|
||
// Notification message should contains app name. | ||
EXPECT_NE(std::string::npos, notification->message().find(app_name)); | ||
} | ||
|
||
TEST_F(PrivacyIndicatorsControllerTest, NotificationClickButton) { | ||
std::string app_id = "test_app_id"; | ||
std::string notification_id = kPrivacyIndicatorsNotificationIdPrefix + app_id; | ||
scoped_refptr<TestDelegate> delegate = base::MakeRefCounted<TestDelegate>(); | ||
ash::ModifyPrivacyIndicatorsNotification( | ||
app_id, u"test_app_name", /*camera_is_used=*/true, | ||
/*microphone_is_used=*/true, delegate); | ||
|
||
// Privacy indicators notification should not be a popup. It is silently added | ||
// to the tray. | ||
EXPECT_FALSE(GetPopupNotificationView(notification_id)); | ||
GetPrimaryUnifiedSystemTray()->ShowBubble(); | ||
auto* notification_view = static_cast<message_center::NotificationViewBase*>( | ||
GetNotificationViewFromMessageCenter(notification_id)); | ||
EXPECT_TRUE(notification_view); | ||
|
||
// Clicking the first button will trigger launching the app. | ||
EXPECT_FALSE(delegate->launch_app_called()); | ||
ClickView(notification_view, 0); | ||
EXPECT_TRUE(delegate->launch_app_called()); | ||
|
||
// Clicking the first button will trigger launching the app settings. | ||
EXPECT_FALSE(delegate->launch_settings_called()); | ||
ClickView(notification_view, 1); | ||
EXPECT_TRUE(delegate->launch_settings_called()); | ||
} | ||
|
||
} // namespace ash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters