[EnterprisePill] Add check for non-primary otr profile
The browser management service constructor crashes when
CanShowEnterpriseBadgingForAvatar() is true. It is caused by HATS view
created with an OTR profile, which is different from the incognito
profile that we currently bypass (see comments 16 and 17 on
crbug.com/402453333).
Bug: 402453333,402526946
Change-Id: Id7dcb3b7a838ca841655ac1d25590b7e9642b0cf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6404284
Reviewed-by: Yann Dago <ydago@chromium.org>
Commit-Queue: Salma Elmahallawy <esalma@google.com>
Cr-Commit-Position: refs/heads/main@{#1439057}
diff --git a/chrome/browser/enterprise/util/managed_browser_utils.cc b/chrome/browser/enterprise/util/managed_browser_utils.cc
index 196f80e2..4613757e 100644
--- a/chrome/browser/enterprise/util/managed_browser_utils.cc
+++ b/chrome/browser/enterprise/util/managed_browser_utils.cc
@@ -269,7 +269,7 @@
}
bool CanShowEnterpriseBadgingForMenu(Profile* profile) {
- if (profile->IsIncognitoProfile() || profile->IsGuestSession()) {
+ if (profile->IsGuestSession() || profile->IsOffTheRecord()) {
return false;
}
if (!UserAcceptedAccountManagement(profile) && !profile->IsChild()) {
@@ -293,7 +293,7 @@
}
bool CanShowEnterpriseBadgingForAvatar(Profile* profile) {
- if (profile->IsIncognitoProfile() || profile->IsGuestSession()) {
+ if (profile->IsGuestSession() || profile->IsOffTheRecord()) {
return false;
}
if (!UserAcceptedAccountManagement(profile)) {
diff --git a/chrome/browser/enterprise/util/managed_browser_utils_browsertest.cc b/chrome/browser/enterprise/util/managed_browser_utils_browsertest.cc
index ec7399e..7a2ff54 100644
--- a/chrome/browser/enterprise/util/managed_browser_utils_browsertest.cc
+++ b/chrome/browser/enterprise/util/managed_browser_utils_browsertest.cc
@@ -142,7 +142,7 @@
}
IN_PROC_BROWSER_TEST_P(EnterpriseBadgingTest,
- CanNotShowEnterpriseBadgingForOTRProfile) {
+ CanNotShowEnterpriseBadgingForPrimaryOTRProfile) {
Browser* incognito_browser = Browser::Create(Browser::CreateParams(
browser()->profile()->GetPrimaryOTRProfile(/*create_if_needed=*/true),
true));
@@ -151,6 +151,17 @@
EXPECT_FALSE(CanShowEnterpriseBadgingForMenu(incognito_browser->profile()));
}
+IN_PROC_BROWSER_TEST_P(EnterpriseBadgingTest,
+ CanNotShowEnterpriseBadgingForNonPrimaryOTRProfile) {
+ browser()->profile()->GetPrimaryOTRProfile(/*create_if_needed=*/true);
+ Profile* secondary_incognito = browser()->profile()->GetOffTheRecordProfile(
+ Profile::OTRProfileID::CreateUnique("Test:NonPrimaryOTRProfile"),
+ /*create_if_needed=*/true);
+ // Profile badging should always return false in incognito.
+ EXPECT_FALSE(CanShowEnterpriseBadgingForAvatar(secondary_incognito));
+ EXPECT_FALSE(CanShowEnterpriseBadgingForMenu(secondary_incognito));
+}
+
INSTANTIATE_TEST_SUITE_P(,
EnterpriseBadgingTest,
testing::Combine(testing::Bool(),