Skip to content

Commit

Permalink
[DTC] Pull managing organization name in device signals consent dialog
Browse files Browse the repository at this point in the history
Replace "example.com" in device signals consent dialog with managing organization of the current profile

Bug: b:283490063

Change-Id: I556feb6d0dd32e6b47bf0cf54e6c89bcb21e038e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4567832
Reviewed-by: Sébastien Lalancette <seblalancette@chromium.org>
Commit-Queue: Zonghan Xu <xzonghan@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1150282}
  • Loading branch information
Zonghan Xu authored and Chromium LUCI CQ committed May 29, 2023
1 parent 5e6abd7 commit e30b0e0
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 2 deletions.
7 changes: 7 additions & 0 deletions chrome/app/generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -10924,6 +10924,13 @@ Check your passwords anytime in <ph name="GOOGLE_PASSWORD_MANAGER">$1<ex>Google

Device signals can include information about your browser, OS, device, installed software, and files.

If you choose not to share signals, this profile will be closed.
</message>
<message name="IDS_DEVICE_SIGNALS_CONSENT_DIALOG_DEFAULT_BODY_TEXT" desc="Default message for device signals consent dialog when we are unable to retrieve the name of the managing organization.">
This profile is managed by your organization. To continue using this managed profile, your organization requires you to share your device signals.

Device signals can include information about your browser, OS, device, installed software, and files.

If you choose not to share signals, this profile will be closed.
</message>
</if>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7b2ba0ea6b778d5a5f8f808443306bdb2ad48d7a
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/views/device_signals_consent/consent_dialog_coordinator.h"

#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "base/values.h"
#include "chrome/browser/enterprise/browser_management/management_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_attributes_entry.h"
#include "chrome/browser/profiles/profile_attributes_storage.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "components/policy/core/browser/browser_policy_connector.h"
#include "components/policy/core/common/management/management_service.h"
#include "components/policy/core/common/management/scoped_management_service_override_for_testing.h"
#include "components/policy/core/common/mock_configuration_policy_provider.h"
#include "content/public/test/browser_test.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "ui/base/l10n/l10n_util.h"

class ConsentDialogUiTest : public InProcessBrowserTest {
public:
ConsentDialogUiTest() {}

ConsentDialogUiTest(const ConsentDialogUiTest&) = delete;
ConsentDialogUiTest& operator=(const ConsentDialogUiTest&) = delete;

~ConsentDialogUiTest() override = default;

void SetUpInProcessBrowserTestFixture() override {
provider_.SetDefaultReturns(
/*is_initialization_complete_return=*/true,
/*is_first_policy_load_complete_return=*/true);
policy::BrowserPolicyConnectorBase::SetPolicyProviderForTesting(&provider_);
}

policy::MockConfigurationPolicyProvider* provider() { return &provider_; }

void AddEnterpriseManagedPolicies() {
policy::PolicyMap policy_map;
policy_map.Set("test-policy", policy::POLICY_LEVEL_MANDATORY,
policy::POLICY_SCOPE_MACHINE, policy::POLICY_SOURCE_PLATFORM,
base::Value("hello world"), nullptr);
provider()->UpdateChromePolicy(policy_map);
}

std::u16string GetDialogBodyTextFromProfile(Profile* profile) {
return std::make_unique<ConsentDialogCoordinator>(browser(), profile)
->GetDialogBodyText();
}

std::u16string GetExpectedBodyText(
absl::optional<std::string> manager = absl::nullopt) {
return (!manager) ? l10n_util::GetStringUTF16(
IDS_DEVICE_SIGNALS_CONSENT_DIALOG_DEFAULT_BODY_TEXT)
: l10n_util::GetStringFUTF16(
IDS_DEVICE_SIGNALS_CONSENT_DIALOG_BODY_TEXT,
base::UTF8ToUTF16(manager.value()));
}

private:
testing::NiceMock<policy::MockConfigurationPolicyProvider> provider_;
};

IN_PROC_BROWSER_TEST_F(ConsentDialogUiTest, GetConsentDialogBodyTest) {
// Simulate a managed profile.
AddEnterpriseManagedPolicies();
policy::ScopedManagementServiceOverrideForTesting browser_management(
policy::ManagementServiceFactory::GetForProfile(browser()->profile()),
policy::EnterpriseManagementAuthority::CLOUD);

TestingProfile::Builder builder;
auto profile = builder.Build();

TestingProfile::Builder builder_with_domain;
builder_with_domain.SetProfileName("foobar@example.com");
builder_with_domain.OverridePolicyConnectorIsManagedForTesting(true);
auto profile_with_domain = builder_with_domain.Build();

auto* profile_with_hosted_domain = browser()->profile();
ProfileAttributesEntry* entry =
g_browser_process->profile_manager()
->GetProfileAttributesStorage()
.GetProfileAttributesWithPath(profile_with_hosted_domain->GetPath());
ASSERT_TRUE(entry);
entry->SetHostedDomain("hosteddomain.com");

// Simulate a supervised profile.
TestingProfile::Builder builder_supervised;
builder_supervised.SetIsSupervisedProfile();
std::unique_ptr<TestingProfile> profile_supervised =
builder_supervised.Build();

EXPECT_EQ(GetExpectedBodyText(), GetDialogBodyTextFromProfile(profile.get()));
EXPECT_EQ(GetExpectedBodyText("example.com"),
GetDialogBodyTextFromProfile(profile_with_domain.get()));
EXPECT_EQ(GetExpectedBodyText("hosteddomain.com"),
GetDialogBodyTextFromProfile(profile_with_hosted_domain));
// Enterprise management takes precedence over supervision in the management
// UI.
EXPECT_EQ(GetExpectedBodyText(),
GetDialogBodyTextFromProfile(profile_supervised.get()));
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
#include "chrome/browser/ui/views/device_signals_consent/consent_dialog_coordinator.h"

#include "base/no_destructor.h"
#include "chrome/browser/browser_features.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_window.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/managed_ui.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "chrome/grit/generated_resources.h"
#include "components/device_signals/core/browser/pref_names.h"
Expand Down Expand Up @@ -55,8 +57,7 @@ ConsentDialogCoordinator::CreateDeviceSignalsConsentDialogModel() {
ui::DialogModelButton::Params().SetLabel(l10n_util::GetStringUTF16(
IDS_DEVICE_SIGNALS_CONSENT_DIALOG_CANCEL_BUTTON)))
.OverrideDefaultButton(ui::DialogButton::DIALOG_BUTTON_NONE)
.AddParagraph(ui::DialogModelLabel(l10n_util::GetStringFUTF16(
IDS_DEVICE_SIGNALS_CONSENT_DIALOG_BODY_TEXT, u"example.com")))
.AddParagraph(ui::DialogModelLabel(GetDialogBodyText()))
.Build();
}

Expand Down Expand Up @@ -99,6 +100,21 @@ void ConsentDialogCoordinator::RequestConsent(RequestConsentCallback callback) {
Show();
}

std::u16string ConsentDialogCoordinator::GetDialogBodyText() {
absl::optional<std::string> manager =
chrome::GetAccountManagerIdentity(profile_);
if (!manager &&
base::FeatureList::IsEnabled(features::kFlexOrgManagementDisclosure)) {
manager = chrome::GetDeviceManagerIdentity();
}
return (manager && manager.value().length())
? l10n_util::GetStringFUTF16(
IDS_DEVICE_SIGNALS_CONSENT_DIALOG_BODY_TEXT,
base::UTF8ToUTF16(manager.value()))
: l10n_util::GetStringUTF16(
IDS_DEVICE_SIGNALS_CONSENT_DIALOG_DEFAULT_BODY_TEXT);
}

void ConsentDialogCoordinator::Show() {
if (dialog_widget_) {
dialog_widget_->Hide();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class ConsentDialogCoordinator : public ConsentRequester {

void RequestConsent(RequestConsentCallback callback) override;

// Retrieves the domain managing current profile, and formats the body text of
// the consent dialog accordingly. If no domain is pulled, default body text
// will be used.
std::u16string GetDialogBodyText();

private:
std::unique_ptr<ui::DialogModel> CreateDeviceSignalsConsentDialogModel();

Expand Down
4 changes: 4 additions & 0 deletions chrome/test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2542,6 +2542,10 @@ if (!is_android) {
"v8/wasm_trap_handler_browsertest.cc",
]

if (is_win || is_mac || is_linux || is_chromeos_ash) {
sources += [ "../browser/ui/views/device_signals_consent/consent_dialog_browsertest.cc" ]
}

if (build_with_tflite_lib) {
sources += [
"../browser/optimization_guide/prediction/prediction_manager_browsertest.cc",
Expand Down

0 comments on commit e30b0e0

Please sign in to comment.