Commit be1a1049 authored by Roman Aleksandrov's avatar Roman Aleksandrov Committed by Commit Bot

Management WebUI: Refactoring follow-up

Add tests to the ChromeOS only part of the code.
Fix subtitle for the non-managed devices and
managed/non-managed accounts.

Bug: 879146
Change-Id: I7f24f7b527fcaa8d8ce0b165b3b276bf80ee8936
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1569705
Commit-Queue: Roman Aleksandrov <raleksandrov@google.com>
Reviewed-by: default avatarHector Carmona <hcarmona@chromium.org>
Cr-Commit-Position: refs/heads/master@{#652179}
parent f80153f5
...@@ -200,7 +200,15 @@ ...@@ -200,7 +200,15 @@
</if> </if>
<div>[[accountManagedInfo_.overview]]</div> <div>[[accountManagedInfo_.overview]]</div>
<ul class="overview-messages" hidden="[[!accountManagedInfo_]]"> <ul class="overview-messages" hidden="[[!accountManagedInfo_]]">
<if expr="chromeos">
<li>[[accountManagedInfo_.setup]]
<a href="$i18nRaw{managementAccountLearnMoreUrl}"
target="_blank">$i18n{learnMore}</a>
</li>
</if>
<if expr="not chromeos">
<li>[[accountManagedInfo_.setup]]</li> <li>[[accountManagedInfo_.setup]]</li>
</if>
<li>[[accountManagedInfo_.data]]</li> <li>[[accountManagedInfo_.data]]</li>
</ul> </ul>
</section> </section>
......
...@@ -97,6 +97,8 @@ content::WebUIDataSource* CreateManagementUIHtmlSource(Profile* profile) { ...@@ -97,6 +97,8 @@ content::WebUIDataSource* CreateManagementUIHtmlSource(Profile* profile) {
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
source->AddString("managementDeviceLearnMoreUrl", source->AddString("managementDeviceLearnMoreUrl",
chrome::kLearnMoreEnterpriseURL); chrome::kLearnMoreEnterpriseURL);
source->AddString("managementAccountLearnMoreUrl",
chrome::kManagedUiLearnMoreUrl);
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
source->SetJsonPath("strings.js"); source->SetJsonPath("strings.js");
...@@ -128,20 +130,22 @@ base::string16 ManagementUI::GetManagementPageSubtitle(Profile* profile) { ...@@ -128,20 +130,22 @@ base::string16 ManagementUI::GetManagementPageSubtitle(Profile* profile) {
policy::BrowserPolicyConnectorChromeOS* connector = policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos(); g_browser_process->platform_part()->browser_policy_connector_chromeos();
const auto device_type = ui::GetChromeOSDeviceTypeResourceId(); const auto device_type = ui::GetChromeOSDeviceTypeResourceId();
if (!connector->IsEnterpriseManaged()) { if (!connector->IsEnterpriseManaged() &&
!policy::ProfilePolicyConnectorFactory::IsProfileManaged(profile)) {
return l10n_util::GetStringFUTF16(IDS_MANAGEMENT_NOT_MANAGED_SUBTITLE, return l10n_util::GetStringFUTF16(IDS_MANAGEMENT_NOT_MANAGED_SUBTITLE,
l10n_util::GetStringUTF16(device_type)); l10n_util::GetStringUTF16(device_type));
} }
std::string display_domain = connector->GetEnterpriseDisplayDomain(); std::string display_domain = connector->GetEnterpriseDisplayDomain();
if (display_domain.empty())
display_domain = connector->GetRealm();
if (display_domain.empty())
display_domain = ManagementUIHandler::GetAccountDomain(profile);
if (display_domain.empty()) { if (display_domain.empty()) {
if (!connector->IsActiveDirectoryManaged()) {
return l10n_util::GetStringFUTF16(IDS_MANAGEMENT_SUBTITLE_MANAGED, return l10n_util::GetStringFUTF16(IDS_MANAGEMENT_SUBTITLE_MANAGED,
l10n_util::GetStringUTF16(device_type)); l10n_util::GetStringUTF16(device_type));
} }
display_domain = connector->GetRealm();
}
return l10n_util::GetStringFUTF16(IDS_MANAGEMENT_SUBTITLE_MANAGED_BY, return l10n_util::GetStringFUTF16(IDS_MANAGEMENT_SUBTITLE_MANAGED_BY,
l10n_util::GetStringUTF16(device_type), l10n_util::GetStringUTF16(device_type),
base::UTF8ToUTF16(display_domain)); base::UTF8ToUTF16(display_domain));
......
...@@ -131,6 +131,14 @@ bool IsProfileManaged(Profile* profile) { ...@@ -131,6 +131,14 @@ bool IsProfileManaged(Profile* profile) {
return policy::ProfilePolicyConnectorFactory::IsProfileManaged(profile); return policy::ProfilePolicyConnectorFactory::IsProfileManaged(profile);
} }
#if defined(OS_CHROMEOS)
bool IsDeviceManaged() {
policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
return connector->IsEnterpriseManaged();
}
#endif // defined(OS_CHROMEOS)
#if !defined(OS_CHROMEOS) #if !defined(OS_CHROMEOS)
bool IsBrowserManaged() { bool IsBrowserManaged() {
return g_browser_process->browser_policy_connector() return g_browser_process->browser_policy_connector()
...@@ -336,7 +344,7 @@ void ManagementUIHandler::InitializeInternal(content::WebUI* web_ui, ...@@ -336,7 +344,7 @@ void ManagementUIHandler::InitializeInternal(content::WebUI* web_ui,
auto handler = std::make_unique<ManagementUIHandler>(); auto handler = std::make_unique<ManagementUIHandler>();
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
handler->managed_ = IsProfileManaged(profile); handler->managed_ = IsProfileManaged(profile) || IsDeviceManaged();
#else #else
handler->managed_ = IsProfileManaged(profile) || IsBrowserManaged(); handler->managed_ = IsProfileManaged(profile) || IsBrowserManaged();
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
...@@ -478,7 +486,18 @@ void ManagementUIHandler::AddExtensionReportingInfo( ...@@ -478,7 +486,18 @@ void ManagementUIHandler::AddExtensionReportingInfo(
base::DictionaryValue ManagementUIHandler::GetContextualManagedData( base::DictionaryValue ManagementUIHandler::GetContextualManagedData(
Profile* profile) const { Profile* profile) const {
base::DictionaryValue response; base::DictionaryValue response;
auto management_domain = GetAccountDomain(profile);
#if defined(OS_CHROMEOS)
policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
std::string management_domain = connector->GetEnterpriseDisplayDomain();
if (management_domain.empty())
management_domain = connector->GetRealm();
if (management_domain.empty())
management_domain = GetAccountDomain(profile);
#else
std::string management_domain = GetAccountDomain(profile);
#endif
if (management_domain.empty()) { if (management_domain.empty()) {
response.SetString( response.SetString(
...@@ -497,12 +516,13 @@ base::DictionaryValue ManagementUIHandler::GetContextualManagedData( ...@@ -497,12 +516,13 @@ base::DictionaryValue ManagementUIHandler::GetContextualManagedData(
: IDS_MANAGEMENT_NOT_MANAGED_SUBTITLE)); : IDS_MANAGEMENT_NOT_MANAGED_SUBTITLE));
#else #else
const auto device_type = ui::GetChromeOSDeviceTypeResourceId(); const auto device_type = ui::GetChromeOSDeviceTypeResourceId();
response.SetString( response.SetString("pageSubtitle",
"pageSubtitle", managed_ ? l10n_util::GetStringFUTF16(
managed_ IDS_MANAGEMENT_SUBTITLE_MANAGED,
? l10n_util::GetStringFUTF16(IDS_MANAGEMENT_SUBTITLE_MANAGED,
l10n_util::GetStringUTF16(device_type)) l10n_util::GetStringUTF16(device_type))
: l10n_util::GetStringUTF16(IDS_MANAGEMENT_NOT_MANAGED_SUBTITLE)); : l10n_util::GetStringFUTF16(
IDS_MANAGEMENT_NOT_MANAGED_SUBTITLE,
l10n_util::GetStringUTF16(device_type)));
#endif // !defined(OS_CHROMEOS) #endif // !defined(OS_CHROMEOS)
} else { } else {
...@@ -529,13 +549,14 @@ base::DictionaryValue ManagementUIHandler::GetContextualManagedData( ...@@ -529,13 +549,14 @@ base::DictionaryValue ManagementUIHandler::GetContextualManagedData(
: l10n_util::GetStringUTF16(IDS_MANAGEMENT_NOT_MANAGED_SUBTITLE)); : l10n_util::GetStringUTF16(IDS_MANAGEMENT_NOT_MANAGED_SUBTITLE));
#else #else
const auto device_type = ui::GetChromeOSDeviceTypeResourceId(); const auto device_type = ui::GetChromeOSDeviceTypeResourceId();
response.SetString( response.SetString("pageSubtitle",
"pageSubtitle", managed_ ? l10n_util::GetStringFUTF16(
managed_ IDS_MANAGEMENT_SUBTITLE_MANAGED_BY,
? l10n_util::GetStringFUTF16(IDS_MANAGEMENT_SUBTITLE_MANAGED_BY,
l10n_util::GetStringUTF16(device_type), l10n_util::GetStringUTF16(device_type),
base::UTF8ToUTF16(management_domain)) base::UTF8ToUTF16(management_domain))
: l10n_util::GetStringUTF16(IDS_MANAGEMENT_NOT_MANAGED_SUBTITLE)); : l10n_util::GetStringFUTF16(
IDS_MANAGEMENT_NOT_MANAGED_SUBTITLE,
l10n_util::GetStringUTF16(device_type)));
#endif // !defined(OS_CHROMEOS) #endif // !defined(OS_CHROMEOS)
} }
GetManagementStatus(profile, &response); GetManagementStatus(profile, &response);
...@@ -617,7 +638,7 @@ void AddStatusOverviewManagedDeviceAndAccount( ...@@ -617,7 +638,7 @@ void AddStatusOverviewManagedDeviceAndAccount(
base::UTF8ToUTF16(device_domain), base::UTF8ToUTF16(device_domain),
base::UTF8ToUTF16(account_domain)))); base::UTF8ToUTF16(account_domain))));
AddStatusDeviceManagedInfo(status, device_domain); AddStatusDeviceManagedInfo(status, device_domain);
status->SetKey(kAccountManagedInfo, base::Value()); AddStatusAccountManagedInfo(status, account_domain);
} }
void AddStatusOverviewManagedDeviceAndAccount( void AddStatusOverviewManagedDeviceAndAccount(
...@@ -818,7 +839,7 @@ void ManagementUIHandler::OnExtensionUnloaded( ...@@ -818,7 +839,7 @@ void ManagementUIHandler::OnExtensionUnloaded(
void ManagementUIHandler::OnManagedStateChanged() { void ManagementUIHandler::OnManagedStateChanged() {
auto* profile = Profile::FromWebUI(web_ui()); auto* profile = Profile::FromWebUI(web_ui());
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
bool managed = IsProfileManaged(profile); bool managed = IsProfileManaged(profile) || IsDeviceManaged();
#else #else
bool managed = IsProfileManaged(profile) || IsBrowserManaged(); bool managed = IsProfileManaged(profile) || IsBrowserManaged();
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
......
...@@ -24,6 +24,10 @@ ...@@ -24,6 +24,10 @@
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#if defined(OS_CHROMEOS)
#include "ui/chromeos/devicetype_utils.h"
#endif // defined(OS_CHROMEOS)
using testing::_; using testing::_;
using testing::Return; using testing::Return;
using testing::ReturnRef; using testing::ReturnRef;
...@@ -349,6 +353,63 @@ TEST_F(ManagementUIHandlerTests, ...@@ -349,6 +353,63 @@ TEST_F(ManagementUIHandlerTests,
#endif // !defined(OS_CHROMEOS) #endif // !defined(OS_CHROMEOS)
#if defined(OS_CHROMEOS)
TEST_F(ManagementUIHandlerTests,
ManagementContextualSourceUpdateManagedAccountKnownDomain) {
TestingProfile::Builder builder;
builder.SetProfileName("managed@manager.com");
auto profile = builder.Build();
const auto device_type = ui::GetChromeOSDeviceTypeResourceId();
base::string16 extensions_installed;
base::string16 browser_management_notice;
base::string16 subtitle;
base::string16 management_overview;
base::string16 management_overview_data_notice;
base::string16 management_overview_setup_notice;
ContextualManagementSourceUpdate extracted{&extensions_installed,
&browser_management_notice,
&subtitle,
&management_overview,
&management_overview_data_notice,
&management_overview_setup_notice};
handler_.SetManagedForTesting(true);
auto data = handler_.GetContextualManagedDataForTesting(profile.get());
ExtractContextualSourceUpdate(data, extracted);
EXPECT_EQ(subtitle,
l10n_util::GetStringFUTF16(IDS_MANAGEMENT_SUBTITLE_MANAGED_BY,
l10n_util::GetStringUTF16(device_type),
base::UTF8ToUTF16("manager.com")));
}
TEST_F(ManagementUIHandlerTests, ManagementContextualSourceUpdateUnmanaged) {
auto profile = TestingProfile::Builder().Build();
const auto device_type = ui::GetChromeOSDeviceTypeResourceId();
base::string16 extension_reporting_title;
base::string16 browser_management_notice;
base::string16 subtitle;
base::string16 management_overview;
base::string16 management_overview_data_notice;
base::string16 management_overview_setup_notice;
ContextualManagementSourceUpdate extracted{&extension_reporting_title,
&browser_management_notice,
&subtitle,
&management_overview,
&management_overview_data_notice,
&management_overview_setup_notice};
handler_.SetManagedForTesting(false);
auto data = handler_.GetContextualManagedDataForTesting(profile.get());
ExtractContextualSourceUpdate(data, extracted);
EXPECT_EQ(subtitle,
l10n_util::GetStringFUTF16(IDS_MANAGEMENT_NOT_MANAGED_SUBTITLE,
l10n_util::GetStringUTF16(device_type)));
}
#endif
TEST_F(ManagementUIHandlerTests, ExtensionReportingInfoNoPolicySetNoMessage) { TEST_F(ManagementUIHandlerTests, ExtensionReportingInfoNoPolicySetNoMessage) {
handler_.EnableCloudReportingExtension(false); handler_.EnableCloudReportingExtension(false);
auto reporting_info = handler_.GetExtensionReportingInfo(); auto reporting_info = handler_.GetExtensionReportingInfo();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment