Update microphone sw switch notification text
This CL updates the text in the microphone mute notification for the software switch. Please visit go/privacy-hub-strings for detailed specs. Bug: b/257202314 Change-Id: Ib2d7ce70b0a755686e0be574522225bc53838980 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4028660 Reviewed-by: Xiyuan Xia <xiyuan@chromium.org> Commit-Queue: Md Shahadat Hossain Shahin <shahinmd@google.com> Cr-Commit-Position: refs/heads/main@{#1075250}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
b7cc93350b
commit
fc739eabad
ash
ash_strings.grd
ash_strings_grd
IDS_MICROPHONE_MUTED_NOTIFICATION_MESSAGE.png.sha1IDS_MICROPHONE_MUTED_NOTIFICATION_MESSAGE_WITH_APP_NAME.png.sha1IDS_MICROPHONE_MUTED_NOTIFICATION_MESSAGE_WITH_ONE_APP_NAME.png.sha1IDS_MICROPHONE_MUTED_NOTIFICATION_MESSAGE_WITH_TWO_APP_NAMES.png.sha1
public
system
chrome/browser/ui/ash
@ -4515,13 +4515,16 @@ Here are some things you can try to get started.
|
||||
|
||||
<!-- Strings for microphone mute switch notification -->
|
||||
<message name="IDS_MICROPHONE_MUTED_NOTIFICATION_TITLE" desc="Title for a notification shown to the users when an app tries to use the microphone while the microphone is muted.i Similar to IDS_MICROPHONE_MUTED_NOTIFICATION_TITLE_WITH_APP_NAME, except this message contains a generic app name string. Used when the name of the app that's using the microphone cannot be determined.">
|
||||
Turn on microphone access?
|
||||
Turn on microphone access?
|
||||
</message>
|
||||
<message name="IDS_MICROPHONE_MUTED_NOTIFICATION_MESSAGE" desc="Message for a notification shown to the users when an app tries to use the microphone while the microphone is muted.">
|
||||
Allows microphone access for all apps and websites with the microphone permission
|
||||
This allows microphone access for all apps and websites with the microphone permission
|
||||
</message>
|
||||
<message name="IDS_MICROPHONE_MUTED_NOTIFICATION_MESSAGE_WITH_APP_NAME" desc="Message for a notification shown to the users when an app tries to use the microphone while the microphone is muted.">
|
||||
Allows microphone access for <ph name="APP_NAME">$1<ex>Zoom</ex></ph> and all apps and websites with the microphone permission
|
||||
<message name="IDS_MICROPHONE_MUTED_NOTIFICATION_MESSAGE_WITH_ONE_APP_NAME" desc="Message for the notification shown to the users when an app tries to use the microphone while the microphone is muted.">
|
||||
This allows microphone access for <ph name="APP_NAME">$1<ex>Zoom</ex></ph> and all apps and websites with the microphone permission
|
||||
</message>
|
||||
<message name="IDS_MICROPHONE_MUTED_NOTIFICATION_MESSAGE_WITH_TWO_APP_NAMES" desc="Message for the notification shown to the users when multiple apps try to use the microphone while the microphone is muted.">
|
||||
This allows microphone access for <ph name="APP1_NAME">$1<ex>Zoom</ex></ph>, <ph name="APP2_NAME">$2<ex>Snapchat</ex></ph>, and all apps and websites with the microphone permission
|
||||
</message>
|
||||
<message name="IDS_MICROPHONE_MUTED_NOTIFICATION_ACTION_BUTTON" desc="Label for an action button in a notification shown to the users when an app tries to use the microphone while the microphone is muted. The button, when tapped unmutes the microphone.">
|
||||
Turn on microphone access
|
||||
|
@ -1 +1 @@
|
||||
37d686b7a7166fe7d6563b34d37e93343f870236
|
||||
09afee5f32b001236ade8298d171dff0575792f0
|
@ -1 +0,0 @@
|
||||
a3f5dd22925b6f620dd7d349dcc8fea011dd9faa
|
1
ash/ash_strings_grd/IDS_MICROPHONE_MUTED_NOTIFICATION_MESSAGE_WITH_ONE_APP_NAME.png.sha1
Normal file
1
ash/ash_strings_grd/IDS_MICROPHONE_MUTED_NOTIFICATION_MESSAGE_WITH_ONE_APP_NAME.png.sha1
Normal file
@ -0,0 +1 @@
|
||||
abdd18b19fa5906ba9bef3fb9491e830ea160dc5
|
1
ash/ash_strings_grd/IDS_MICROPHONE_MUTED_NOTIFICATION_MESSAGE_WITH_TWO_APP_NAMES.png.sha1
Normal file
1
ash/ash_strings_grd/IDS_MICROPHONE_MUTED_NOTIFICATION_MESSAGE_WITH_TWO_APP_NAMES.png.sha1
Normal file
@ -0,0 +1 @@
|
||||
bb9cbefc0cbd8068e9f507e5c21a975810bcddef
|
@ -6,6 +6,7 @@
|
||||
#define ASH_PUBLIC_CPP_MICROPHONE_MUTE_NOTIFICATION_DELEGATE_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "ash/public/cpp/ash_public_export.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
@ -19,13 +20,11 @@ class ASH_PUBLIC_EXPORT MicrophoneMuteNotificationDelegate {
|
||||
public:
|
||||
static MicrophoneMuteNotificationDelegate* Get();
|
||||
|
||||
// Returns an optional string with:
|
||||
//
|
||||
// No value, if no app is accessing the mic
|
||||
// Empty value, if an app is accessing the mic but no name could be determined
|
||||
// Non-empty value, if an app is accessing the mic and a name could be
|
||||
// determined
|
||||
virtual absl::optional<std::u16string> GetAppAccessingMicrophone() = 0;
|
||||
// Returns a list of names of the applications that have attempted to use the
|
||||
// microphone, in order of most-recently-launched. If an application is
|
||||
// accessing the microphone but no name could be determined, the name of that
|
||||
// application will not be in the returned list.
|
||||
virtual std::vector<std::u16string> GetAppsAccessingMicrophone() = 0;
|
||||
|
||||
protected:
|
||||
MicrophoneMuteNotificationDelegate();
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "ash/constants/notifier_catalogs.h"
|
||||
#include "ash/public/cpp/microphone_mute_notification_delegate.h"
|
||||
@ -92,14 +93,14 @@ void MicrophoneMuteNotificationController::MaybeShowNotification(
|
||||
// `MicrophoneMuteNotificationDelegate` is not created in guest mode.
|
||||
if (!microphone_mute_notification_delegate)
|
||||
return;
|
||||
absl::optional<std::u16string> app_name =
|
||||
microphone_mute_notification_delegate->GetAppAccessingMicrophone();
|
||||
if (app_name.has_value() || input_stream_count_) {
|
||||
std::vector<std::u16string> app_names =
|
||||
microphone_mute_notification_delegate->GetAppsAccessingMicrophone();
|
||||
if (!app_names.empty() || input_stream_count_) {
|
||||
if (recreate)
|
||||
RemoveMicrophoneMuteNotification();
|
||||
|
||||
std::unique_ptr<message_center::Notification> notification =
|
||||
GenerateMicrophoneMuteNotification(app_name, priority);
|
||||
GenerateMicrophoneMuteNotification(app_names, priority);
|
||||
message_center::MessageCenter::Get()->AddNotification(
|
||||
std::move(notification));
|
||||
return;
|
||||
@ -119,7 +120,7 @@ void MicrophoneMuteNotificationController::SetAndLogMicrophoneMute(
|
||||
|
||||
std::unique_ptr<message_center::Notification>
|
||||
MicrophoneMuteNotificationController::GenerateMicrophoneMuteNotification(
|
||||
const absl::optional<std::u16string>& app_name,
|
||||
const std::vector<std::u16string>& app_names,
|
||||
message_center::NotificationPriority priority) {
|
||||
message_center::RichNotificationData notification_data;
|
||||
notification_data.priority = priority;
|
||||
@ -148,7 +149,7 @@ MicrophoneMuteNotificationController::GenerateMicrophoneMuteNotification(
|
||||
std::unique_ptr<message_center::Notification> notification =
|
||||
CreateSystemNotification(
|
||||
message_center::NOTIFICATION_TYPE_SIMPLE, kNotificationId,
|
||||
GetNotificationTitle(), GetNotificationMessage(app_name),
|
||||
GetNotificationTitle(), GetNotificationMessage(app_names),
|
||||
/*display_source=*/std::u16string(), GURL(),
|
||||
message_center::NotifierId(
|
||||
message_center::NotifierType::SYSTEM_COMPONENT, kNotificationId,
|
||||
@ -159,17 +160,26 @@ MicrophoneMuteNotificationController::GenerateMicrophoneMuteNotification(
|
||||
}
|
||||
|
||||
std::u16string MicrophoneMuteNotificationController::GetNotificationMessage(
|
||||
const absl::optional<std::u16string>& app_name) const {
|
||||
const std::vector<std::u16string>& app_names) const {
|
||||
if (mic_muted_by_mute_switch_) {
|
||||
return l10n_util::GetStringUTF16(
|
||||
IDS_MICROPHONE_MUTE_SWITCH_ON_NOTIFICATION_MESSAGE);
|
||||
}
|
||||
if (app_name.value_or(u"").empty()) {
|
||||
return l10n_util::GetStringUTF16(IDS_MICROPHONE_MUTED_NOTIFICATION_MESSAGE);
|
||||
|
||||
if (app_names.size() == 1) {
|
||||
return l10n_util::GetStringFUTF16(
|
||||
IDS_MICROPHONE_MUTED_NOTIFICATION_MESSAGE_WITH_ONE_APP_NAME,
|
||||
app_names[0]);
|
||||
} else if (app_names.size() == 2) {
|
||||
return l10n_util::GetStringFUTF16(
|
||||
IDS_MICROPHONE_MUTED_NOTIFICATION_MESSAGE_WITH_TWO_APP_NAMES,
|
||||
app_names[0], app_names[1]);
|
||||
}
|
||||
return l10n_util::GetStringFUTF16(
|
||||
IDS_MICROPHONE_MUTED_NOTIFICATION_MESSAGE_WITH_APP_NAME,
|
||||
app_name.value());
|
||||
|
||||
// If no application name can be determined or more than 2 applications are
|
||||
// attempting to use the microphone, we display this message in the
|
||||
// notification.
|
||||
return l10n_util::GetStringUTF16(IDS_MICROPHONE_MUTED_NOTIFICATION_MESSAGE);
|
||||
}
|
||||
|
||||
std::u16string MicrophoneMuteNotificationController::GetNotificationTitle()
|
||||
|
@ -58,18 +58,20 @@ class ASH_EXPORT MicrophoneMuteNotificationController
|
||||
// mic while the mic is muted.
|
||||
std::unique_ptr<message_center::Notification>
|
||||
GenerateMicrophoneMuteNotification(
|
||||
const absl::optional<std::u16string>& app_name,
|
||||
const std::vector<std::u16string>& app_names,
|
||||
message_center::NotificationPriority priority);
|
||||
|
||||
// Mic mute notification title.
|
||||
std::u16string GetNotificationTitle() const;
|
||||
|
||||
// Mic mute notification body.
|
||||
// If the name of the app is provided via \p app_name, it may be used in the
|
||||
// notification body. If the name is empty, a generic text that avoids
|
||||
// refering to the app by name will be used.
|
||||
// If the list of names of the applications attempting to use the microphone
|
||||
// provided via \p app_names is empty or has more that two elements, a generic
|
||||
// text without referrring to any application name will be displayed.
|
||||
// Otherwise, the displayed text will contain 1-2 application names depending
|
||||
// on the availability.
|
||||
std::u16string GetNotificationMessage(
|
||||
const absl::optional<std::u16string>& app_name) const;
|
||||
const std::vector<std::u16string>& app_names) const;
|
||||
|
||||
// Takes down the mic mute notification.
|
||||
void RemoveMicrophoneMuteNotification();
|
||||
|
@ -4,10 +4,12 @@
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "ash/constants/ash_features.h"
|
||||
#include "ash/public/cpp/microphone_mute_notification_delegate.h"
|
||||
#include "ash/public/cpp/test/test_system_tray_client.h"
|
||||
#include "ash/strings/grit/ash_strings.h"
|
||||
#include "ash/system/microphone_mute/microphone_mute_notification_controller.h"
|
||||
#include "ash/system/privacy_hub/privacy_hub_metrics.h"
|
||||
#include "ash/test/ash_test_base.h"
|
||||
@ -17,6 +19,7 @@
|
||||
#include "base/test/scoped_feature_list.h"
|
||||
#include "chromeos/ash/components/dbus/audio/fake_cras_audio_client.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
#include "ui/message_center/message_center.h"
|
||||
#include "ui/message_center/public/cpp/notification.h"
|
||||
#include "ui/message_center/public/cpp/notification_types.h"
|
||||
@ -26,16 +29,17 @@ namespace ash {
|
||||
class FakeMicrophoneMuteNotificationDelegate
|
||||
: public MicrophoneMuteNotificationDelegate {
|
||||
public:
|
||||
absl::optional<std::u16string> GetAppAccessingMicrophone() override {
|
||||
return app_name_;
|
||||
std::vector<std::u16string> GetAppsAccessingMicrophone() override {
|
||||
return app_names_;
|
||||
}
|
||||
|
||||
void SetAppAccessingMicrophone(
|
||||
void AddAppAccessingMicrophone(
|
||||
const absl::optional<std::u16string> app_name) {
|
||||
app_name_ = app_name;
|
||||
if (app_name.has_value())
|
||||
app_names_.insert(app_names_.begin(), app_name.value());
|
||||
}
|
||||
|
||||
absl::optional<std::u16string> app_name_;
|
||||
std::vector<std::u16string> app_names_;
|
||||
};
|
||||
|
||||
class MicrophoneMuteNotificationControllerTest : public AshTestBase {
|
||||
@ -120,7 +124,7 @@ class MicrophoneMuteNotificationControllerTest : public AshTestBase {
|
||||
}
|
||||
|
||||
void LaunchApp(absl::optional<std::u16string> app_name) {
|
||||
delegate_->SetAppAccessingMicrophone(app_name);
|
||||
delegate_->AddAppAccessingMicrophone(app_name);
|
||||
}
|
||||
|
||||
const base::HistogramTester& histogram_tester() const {
|
||||
@ -427,6 +431,68 @@ TEST_F(MicrophoneMuteNotificationControllerTest,
|
||||
EXPECT_TRUE(GetPopupNotification());
|
||||
}
|
||||
|
||||
TEST_F(MicrophoneMuteNotificationControllerTest, NotificationContents) {
|
||||
// No notification initially.
|
||||
EXPECT_FALSE(GetNotification());
|
||||
|
||||
// Mute the mic, still no notification.
|
||||
MuteMicrophone();
|
||||
EXPECT_FALSE(GetNotification());
|
||||
|
||||
// Launch an app that's not using the mic, should be no notification.
|
||||
LaunchApp(absl::nullopt);
|
||||
EXPECT_FALSE(GetNotification());
|
||||
|
||||
// Launch an app that's using the mic, but the name of the app can not be
|
||||
// determined.
|
||||
LaunchApp(absl::nullopt);
|
||||
SetNumberOfActiveInputStreams(1);
|
||||
EXPECT_TRUE(GetNotification());
|
||||
EXPECT_TRUE(GetPopupNotification());
|
||||
EXPECT_EQ(l10n_util::GetStringUTF16(IDS_MICROPHONE_MUTED_NOTIFICATION_TITLE),
|
||||
GetNotification()->title());
|
||||
// The notification body should not contain any app name.
|
||||
EXPECT_EQ(
|
||||
l10n_util::GetStringUTF16(IDS_MICROPHONE_MUTED_NOTIFICATION_MESSAGE),
|
||||
GetNotification()->message());
|
||||
|
||||
// Launch an app that's using the mic, the name of the app can be determined.
|
||||
LaunchApp(u"app1");
|
||||
SetNumberOfActiveInputStreams(2);
|
||||
EXPECT_TRUE(GetNotification());
|
||||
EXPECT_TRUE(GetPopupNotification());
|
||||
// The notification body should contain name of the app.
|
||||
EXPECT_EQ(
|
||||
l10n_util::GetStringFUTF16(
|
||||
IDS_MICROPHONE_MUTED_NOTIFICATION_MESSAGE_WITH_ONE_APP_NAME, u"app1"),
|
||||
GetNotification()->message());
|
||||
|
||||
// Launch another app that's using the mic, the name of the app can be
|
||||
// determined.
|
||||
LaunchApp(u"app2");
|
||||
SetNumberOfActiveInputStreams(3);
|
||||
EXPECT_TRUE(GetNotification());
|
||||
EXPECT_TRUE(GetPopupNotification());
|
||||
// The notification body should contain the two available app names in the
|
||||
// order of most recently launched.
|
||||
EXPECT_EQ(l10n_util::GetStringFUTF16(
|
||||
IDS_MICROPHONE_MUTED_NOTIFICATION_MESSAGE_WITH_TWO_APP_NAMES,
|
||||
u"app2", u"app1"),
|
||||
GetNotification()->message());
|
||||
|
||||
// Launch yet another app that's using the mic, the name of the app can be
|
||||
// determined.
|
||||
LaunchApp(u"app3");
|
||||
SetNumberOfActiveInputStreams(4);
|
||||
EXPECT_TRUE(GetNotification());
|
||||
EXPECT_TRUE(GetPopupNotification());
|
||||
// As more that two apps are attempting to use the microphone, we fall back to
|
||||
// displaying the generic message in the notification.
|
||||
EXPECT_EQ(
|
||||
l10n_util::GetStringUTF16(IDS_MICROPHONE_MUTED_NOTIFICATION_MESSAGE),
|
||||
GetNotification()->message());
|
||||
}
|
||||
|
||||
TEST_F(MicrophoneMuteNotificationControllerTest, MetricCollection) {
|
||||
EXPECT_EQ(histogram_tester().GetBucketCount(
|
||||
privacy_hub_metrics::
|
||||
|
@ -4,6 +4,9 @@
|
||||
|
||||
#include "ash/system/privacy_hub/microphone_privacy_switch_controller.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "ash/constants/ash_pref_names.h"
|
||||
#include "ash/public/cpp/microphone_mute_notification_delegate.h"
|
||||
#include "ash/public/cpp/privacy_hub_delegate.h"
|
||||
@ -26,8 +29,8 @@ namespace {
|
||||
class FakeMicrophoneMuteNotificationDelegate
|
||||
: public MicrophoneMuteNotificationDelegate {
|
||||
public:
|
||||
absl::optional<std::u16string> GetAppAccessingMicrophone() override {
|
||||
return absl::nullopt;
|
||||
std::vector<std::u16string> GetAppsAccessingMicrophone() override {
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -4,6 +4,9 @@
|
||||
|
||||
#include "ash/system/privacy_hub/privacy_hub_notification_controller.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "ash/constants/ash_features.h"
|
||||
#include "ash/public/cpp/microphone_mute_notification_delegate.h"
|
||||
#include "ash/public/cpp/test/test_system_tray_client.h"
|
||||
@ -28,8 +31,8 @@ namespace {
|
||||
class FakeMicrophoneMuteNotificationDelegate
|
||||
: public MicrophoneMuteNotificationDelegate {
|
||||
public:
|
||||
absl::optional<std::u16string> GetAppAccessingMicrophone() override {
|
||||
return absl::nullopt;
|
||||
std::vector<std::u16string> GetAppsAccessingMicrophone() override {
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "chrome/browser/ui/ash/app_access_notifier.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "ash/constants/ash_features.h"
|
||||
#include "ash/system/privacy/privacy_indicators_controller.h"
|
||||
@ -78,20 +79,26 @@ AppAccessNotifier::AppAccessNotifier() {
|
||||
|
||||
AppAccessNotifier::~AppAccessNotifier() = default;
|
||||
|
||||
absl::optional<std::u16string> AppAccessNotifier::GetAppAccessingMicrophone() {
|
||||
std::vector<std::u16string> AppAccessNotifier::GetAppsAccessingMicrophone() {
|
||||
apps::AppRegistryCache* reg_cache = GetActiveUserAppRegistryCache();
|
||||
apps::AppCapabilityAccessCache* cap_cache =
|
||||
GetActiveUserAppCapabilityAccessCache();
|
||||
// A reg_cache and/or cap_cache of value nullptr is possible if we have
|
||||
// no active user, e.g. the login screen, so we test and return nullopt
|
||||
// in that case instead of using DCHECK().
|
||||
// A reg_cache and/or cap_cache of value nullptr is possible if we have no
|
||||
// active user, e.g. the login screen, so we test and return empty list in
|
||||
// that case instead of using DCHECK().
|
||||
if (!reg_cache || !cap_cache ||
|
||||
mic_using_app_ids[active_user_account_id_].empty()) {
|
||||
return absl::nullopt;
|
||||
return {};
|
||||
}
|
||||
|
||||
return MapAppIdToShortName(mic_using_app_ids[active_user_account_id_].front(),
|
||||
cap_cache, reg_cache);
|
||||
std::vector<std::u16string> app_names;
|
||||
for (const auto& app_id : mic_using_app_ids[active_user_account_id_]) {
|
||||
absl::optional<std::u16string> app_name =
|
||||
MapAppIdToShortName(app_id, cap_cache, reg_cache);
|
||||
if (app_name.has_value())
|
||||
app_names.push_back(app_name.value());
|
||||
}
|
||||
return app_names;
|
||||
}
|
||||
|
||||
void AppAccessNotifier::OnCapabilityAccessUpdate(
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "ash/public/cpp/microphone_mute_notification_delegate.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
@ -45,7 +46,7 @@ class AppAccessNotifier
|
||||
~AppAccessNotifier() override;
|
||||
|
||||
// ash::MicrophoneMuteNotificationDelegate
|
||||
absl::optional<std::u16string> GetAppAccessingMicrophone() override;
|
||||
std::vector<std::u16string> GetAppsAccessingMicrophone() override;
|
||||
|
||||
// apps::AppCapabilityAccessCache::Observer
|
||||
void OnCapabilityAccessUpdate(
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "chrome/browser/ui/ash/app_access_notifier.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "ash/constants/ash_features.h"
|
||||
#include "ash/public/cpp/ash_prefs.h"
|
||||
@ -146,8 +147,8 @@ class AppAccessNotifierBaseTest : public testing::Test {
|
||||
SetActiveUserAccountId(/*is_primary=*/false);
|
||||
}
|
||||
|
||||
absl::optional<std::u16string> GetAppAccessingMicrophone() {
|
||||
return app_access_notifier_->GetAppAccessingMicrophone();
|
||||
std::vector<std::u16string> GetAppsAccessingMicrophone() {
|
||||
return app_access_notifier_->GetAppsAccessingMicrophone();
|
||||
}
|
||||
|
||||
static apps::AppPtr MakeApp(const std::string app_id,
|
||||
@ -289,28 +290,28 @@ INSTANTIATE_TEST_SUITE_P(
|
||||
/*IsPrivacyIndicatorsFeatureEnabled()=*/::testing::Bool());
|
||||
|
||||
TEST_P(AppAccessNotifierParameterizedTest, NoAppsLaunched) {
|
||||
// Should return a completely value-free app_name.
|
||||
absl::optional<std::u16string> app_name = GetAppAccessingMicrophone();
|
||||
EXPECT_FALSE(app_name.has_value());
|
||||
// Should return a empty list of application names.
|
||||
std::vector<std::u16string> app_names = GetAppsAccessingMicrophone();
|
||||
EXPECT_TRUE(app_names.empty());
|
||||
}
|
||||
|
||||
TEST_P(AppAccessNotifierParameterizedTest, AppLaunchedNotUsingMicrophone) {
|
||||
LaunchAppUsingCameraOrMicrophone("id_rose", "name_rose", /*use_camera=*/false,
|
||||
/*use_microphone=*/false);
|
||||
|
||||
// Should return a completely value-free app_name.
|
||||
absl::optional<std::u16string> app_name = GetAppAccessingMicrophone();
|
||||
EXPECT_FALSE(app_name.has_value());
|
||||
// Should return a empty list of application names.
|
||||
std::vector<std::u16string> app_names = GetAppsAccessingMicrophone();
|
||||
EXPECT_TRUE(app_names.empty());
|
||||
}
|
||||
|
||||
TEST_P(AppAccessNotifierParameterizedTest, AppLaunchedUsingMicrophone) {
|
||||
LaunchAppUsingCameraOrMicrophone("id_rose", "name_rose", /*use_camera=*/false,
|
||||
/*use_microphone=*/true);
|
||||
|
||||
// Should return the name of our app.
|
||||
absl::optional<std::u16string> app_name = GetAppAccessingMicrophone();
|
||||
EXPECT_TRUE(app_name.has_value());
|
||||
EXPECT_EQ(app_name, u"name_rose");
|
||||
// Returned list of application names should only contain "name_rose".
|
||||
std::vector<std::u16string> app_names = GetAppsAccessingMicrophone();
|
||||
EXPECT_EQ((int)app_names.size(), 1);
|
||||
EXPECT_EQ(app_names[0], u"name_rose");
|
||||
}
|
||||
|
||||
TEST_P(AppAccessNotifierParameterizedTest,
|
||||
@ -324,26 +325,29 @@ TEST_P(AppAccessNotifierParameterizedTest,
|
||||
LaunchAppUsingCameraOrMicrophone(
|
||||
"id_oscar", "name_oscar", /*use_camera=*/false, /*use_microphone=*/false);
|
||||
|
||||
// Most recently launched mic-using app should be the one we use for the
|
||||
// notification.
|
||||
absl::optional<std::u16string> app_name = GetAppAccessingMicrophone();
|
||||
EXPECT_TRUE(app_name.has_value());
|
||||
EXPECT_EQ(app_name, u"name_zara");
|
||||
// Most recently launched mic-using app should be in front of the returned
|
||||
// list.
|
||||
std::vector<std::u16string> app_names = GetAppsAccessingMicrophone();
|
||||
EXPECT_EQ((int)app_names.size(), 3);
|
||||
EXPECT_EQ(app_names[0], u"name_zara");
|
||||
|
||||
// Oscar starts using the mic, Oscar shows up in the notification.
|
||||
// Oscar starts using the mic, Oscar should be the front element of the
|
||||
// returned list now.
|
||||
LaunchAppUsingCameraOrMicrophone(
|
||||
"id_oscar", "name_oscar", /*use_camera=*/false, /*use_microphone=*/true);
|
||||
app_name = GetAppAccessingMicrophone();
|
||||
EXPECT_TRUE(app_name.has_value());
|
||||
EXPECT_EQ(app_name, u"name_oscar");
|
||||
app_names = GetAppsAccessingMicrophone();
|
||||
EXPECT_EQ((int)app_names.size(), 4);
|
||||
EXPECT_EQ(app_names[0], u"name_oscar");
|
||||
|
||||
// If we "kill" Oscar (set to no longer be using the mic or camera),
|
||||
// the notification shows Zara again.
|
||||
// If we "kill" Oscar (set to no longer be using the mic or camera), Oscar
|
||||
// should not be in the returned list anymore. Zara should be at the front.
|
||||
LaunchAppUsingCameraOrMicrophone(
|
||||
"id_oscar", "name_oscar", /*use_camera=*/false, /*use_microphone=*/false);
|
||||
app_name = GetAppAccessingMicrophone();
|
||||
EXPECT_TRUE(app_name.has_value());
|
||||
EXPECT_EQ(app_name, u"name_zara");
|
||||
app_names = GetAppsAccessingMicrophone();
|
||||
EXPECT_EQ((int)app_names.size(), 3);
|
||||
EXPECT_TRUE(std::find(app_names.begin(), app_names.end(), u"name_oscar") ==
|
||||
app_names.end());
|
||||
EXPECT_EQ(app_names[0], u"name_zara");
|
||||
}
|
||||
|
||||
TEST_P(AppAccessNotifierParameterizedTest, MultipleUsers) {
|
||||
@ -358,10 +362,11 @@ TEST_P(AppAccessNotifierParameterizedTest, MultipleUsers) {
|
||||
/*use_camera=*/false,
|
||||
/*use_microphone=*/true);
|
||||
|
||||
// App we just launched should show up in the notification.
|
||||
absl::optional<std::u16string> app_name = GetAppAccessingMicrophone();
|
||||
EXPECT_TRUE(app_name.has_value());
|
||||
EXPECT_EQ(app_name, u"name_primary_user");
|
||||
// App we just launched should be the front and only element of the returned
|
||||
// list.
|
||||
std::vector<std::u16string> app_names = GetAppsAccessingMicrophone();
|
||||
EXPECT_EQ((int)app_names.size(), 1);
|
||||
EXPECT_EQ(app_names[0], u"name_primary_user");
|
||||
|
||||
// Secondary user is now the primary user.
|
||||
SetActiveUserAccountId(/*is_primary=*/false);
|
||||
@ -371,10 +376,11 @@ TEST_P(AppAccessNotifierParameterizedTest, MultipleUsers) {
|
||||
/*use_camera=*/false,
|
||||
/*use_microphone=*/true);
|
||||
|
||||
// App we just launched should show up in the notification.
|
||||
app_name = GetAppAccessingMicrophone();
|
||||
EXPECT_TRUE(app_name.has_value());
|
||||
EXPECT_EQ(app_name, u"name_secondary_user");
|
||||
// App we just launched should be the front and only element of the returned
|
||||
// list.
|
||||
app_names = GetAppsAccessingMicrophone();
|
||||
EXPECT_EQ((int)app_names.size(), 1);
|
||||
EXPECT_EQ(app_names[0], u"name_secondary_user");
|
||||
|
||||
// Switch back to the primary user and "kill" the app it was running, no app
|
||||
// name to show.
|
||||
@ -382,23 +388,23 @@ TEST_P(AppAccessNotifierParameterizedTest, MultipleUsers) {
|
||||
LaunchAppUsingCameraOrMicrophone("id_primary_user", "name_primary_user",
|
||||
/*use_camera=*/false,
|
||||
/*use_microphone=*/false);
|
||||
app_name = GetAppAccessingMicrophone();
|
||||
EXPECT_FALSE(app_name.has_value());
|
||||
app_names = GetAppsAccessingMicrophone();
|
||||
EXPECT_TRUE(app_names.empty());
|
||||
|
||||
// Now switch back to the secondary user, verify that the same app as before
|
||||
// shows up in the notification.
|
||||
// shows up at the front of the returned list.
|
||||
SetActiveUserAccountId(/*is_primary=*/false);
|
||||
app_name = GetAppAccessingMicrophone();
|
||||
EXPECT_TRUE(app_name.has_value());
|
||||
EXPECT_EQ(app_name, u"name_secondary_user");
|
||||
app_names = GetAppsAccessingMicrophone();
|
||||
EXPECT_EQ((int)app_names.size(), 1);
|
||||
EXPECT_EQ(app_names[0], u"name_secondary_user");
|
||||
|
||||
// Now "kill" our secondary user's app and verify that there's no name to
|
||||
// show.
|
||||
LaunchAppUsingCameraOrMicrophone("id_secondary_user", "name_secondary_user",
|
||||
/*use_camera=*/false,
|
||||
/*use_microphone=*/false);
|
||||
app_name = GetAppAccessingMicrophone();
|
||||
EXPECT_FALSE(app_name.has_value());
|
||||
app_names = GetAppsAccessingMicrophone();
|
||||
EXPECT_TRUE(app_names.empty());
|
||||
}
|
||||
|
||||
TEST_P(AppAccessNotifierParameterizedTest, MultipleUsersMultipleApps) {
|
||||
@ -413,20 +419,24 @@ TEST_P(AppAccessNotifierParameterizedTest, MultipleUsersMultipleApps) {
|
||||
/*use_camera=*/false,
|
||||
/*use_microphone=*/true);
|
||||
|
||||
// App we just launched should show up in the notification.
|
||||
absl::optional<std::u16string> app_name = GetAppAccessingMicrophone();
|
||||
EXPECT_TRUE(app_name.has_value());
|
||||
EXPECT_EQ(app_name, u"name_primary_user");
|
||||
// App we just launched should be the front and only element of the returned
|
||||
// list.
|
||||
std::vector<std::u16string> app_names = GetAppsAccessingMicrophone();
|
||||
EXPECT_EQ((int)app_names.size(), 1);
|
||||
EXPECT_EQ(app_names[0], u"name_primary_user");
|
||||
|
||||
// Primary user launches a second mic-using app.
|
||||
LaunchAppUsingCameraOrMicrophone(
|
||||
"id_primary_user", "name_primary_user_another_app", /*use_camera=*/false,
|
||||
/*use_microphone=*/true);
|
||||
LaunchAppUsingCameraOrMicrophone("id_primary_user_another_app",
|
||||
"name_primary_user_another_app",
|
||||
/*use_camera=*/false,
|
||||
/*use_microphone=*/true);
|
||||
|
||||
// App we just launched should show up in the notification.
|
||||
app_name = GetAppAccessingMicrophone();
|
||||
EXPECT_TRUE(app_name.has_value());
|
||||
EXPECT_EQ(app_name, u"name_primary_user_another_app");
|
||||
// The returned list should contain two application names ordered by most
|
||||
// recently launched.
|
||||
app_names = GetAppsAccessingMicrophone();
|
||||
EXPECT_EQ((int)app_names.size(), 2);
|
||||
EXPECT_EQ(app_names[0], u"name_primary_user_another_app");
|
||||
EXPECT_EQ(app_names[1], u"name_primary_user");
|
||||
|
||||
// Secondary user is now the primary user.
|
||||
SetActiveUserAccountId(/*is_primary=*/false);
|
||||
@ -436,28 +446,33 @@ TEST_P(AppAccessNotifierParameterizedTest, MultipleUsersMultipleApps) {
|
||||
/*use_camera=*/false,
|
||||
/*use_microphone=*/true);
|
||||
|
||||
// App we just launched should show up in the notification.
|
||||
app_name = GetAppAccessingMicrophone();
|
||||
EXPECT_TRUE(app_name.has_value());
|
||||
EXPECT_EQ(app_name, u"name_secondary_user");
|
||||
// App we just launched should be the front and only element of the returned
|
||||
// list.
|
||||
app_names = GetAppsAccessingMicrophone();
|
||||
EXPECT_EQ((int)app_names.size(), 1);
|
||||
EXPECT_EQ(app_names[0], u"name_secondary_user");
|
||||
|
||||
// Secondary user launches a second mic-using app.
|
||||
LaunchAppUsingCameraOrMicrophone(
|
||||
"id_secondary_user", "name_secondary_user_another_app",
|
||||
"id_secondary_user_another_app", "name_secondary_user_another_app",
|
||||
/*use_camera=*/false, /*use_microphone=*/true);
|
||||
|
||||
// App we just launched should show up in the notification.
|
||||
app_name = GetAppAccessingMicrophone();
|
||||
EXPECT_TRUE(app_name.has_value());
|
||||
EXPECT_EQ(app_name, u"name_secondary_user_another_app");
|
||||
// The returned list should contain two application names ordered by most
|
||||
// recently launched.
|
||||
app_names = GetAppsAccessingMicrophone();
|
||||
EXPECT_EQ((int)app_names.size(), 2);
|
||||
EXPECT_EQ(app_names[0], u"name_secondary_user_another_app");
|
||||
EXPECT_EQ(app_names[1], u"name_secondary_user");
|
||||
|
||||
// Switch back to the primary user.
|
||||
SetActiveUserAccountId(/*is_primary=*/true);
|
||||
|
||||
// App we just launched should show up in the notification.
|
||||
app_name = GetAppAccessingMicrophone();
|
||||
EXPECT_TRUE(app_name.has_value());
|
||||
EXPECT_EQ(app_name, u"name_primary_user_another_app");
|
||||
// Both of the apps we launced for the primary user should be in the list
|
||||
// ordered by most recently launched.
|
||||
app_names = GetAppsAccessingMicrophone();
|
||||
EXPECT_EQ((int)app_names.size(), 2);
|
||||
EXPECT_EQ(app_names[0], u"name_primary_user_another_app");
|
||||
EXPECT_EQ(app_names[1], u"name_primary_user");
|
||||
}
|
||||
|
||||
TEST_P(AppAccessNotifierParameterizedTest, GetShortNameFromAppId) {
|
||||
|
Reference in New Issue
Block a user