Commit 27bdec41 authored by Nicolas Ouellet-payeur's avatar Nicolas Ouellet-payeur Committed by Commit Bot

Disable managed UI for Unicorn accounts

Bug: 924836
Change-Id: Ib03b926e770adcfe8678ee64ec2094c117724314
Reviewed-on: https://chromium-review.googlesource.com/c/1436141
Commit-Queue: Nicolas Ouellet-Payeur <nicolaso@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#628790}
parent d95e3b28
......@@ -30,6 +30,10 @@ bool ShouldDisplayManagedUi(Profile* profile) {
// Don't show the UI in demo mode.
if (chromeos::DemoSession::IsDeviceInDemoMode())
return false;
// Don't show the UI for Unicorn accounts.
if (profile->IsSupervised())
return false;
#endif
// This profile may have policies configured.
......
......@@ -13,6 +13,7 @@
#include "chrome/browser/policy/profile_policy_connector_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/managed_ui.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/generated_resources.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h"
......@@ -45,7 +46,9 @@ void ManagedUIHandler::InitializeInternal(content::WebUI* web_ui,
}
ManagedUIHandler::ManagedUIHandler(Profile* profile)
: profile_(profile), managed_(chrome::ShouldDisplayManagedUi(profile_)) {}
: profile_(profile), managed_(chrome::ShouldDisplayManagedUi(profile_)) {
pref_registrar_.Init(profile_->GetPrefs());
}
ManagedUIHandler::~ManagedUIHandler() {
RemoveObservers();
......@@ -86,6 +89,10 @@ void ManagedUIHandler::AddObservers() {
auto domain = static_cast<policy::PolicyDomain>(i);
policy_service->AddObserver(domain, this);
}
pref_registrar_.Add(prefs::kSupervisedUserId,
base::BindRepeating(&ManagedUIHandler::NotifyIfChanged,
base::Unretained(this)));
}
void ManagedUIHandler::RemoveObservers() {
......@@ -99,6 +106,8 @@ void ManagedUIHandler::RemoveObservers() {
auto domain = static_cast<policy::PolicyDomain>(i);
policy_service->RemoveObserver(domain, this);
}
pref_registrar_.RemoveAll();
}
std::unique_ptr<base::DictionaryValue> ManagedUIHandler::GetDataSourceUpdate()
......
......@@ -10,6 +10,7 @@
#include "base/macros.h"
#include "components/policy/core/common/policy_service.h"
#include "components/prefs/pref_change_registrar.h"
#include "content/public/browser/web_ui_message_handler.h"
namespace content {
......@@ -67,6 +68,8 @@ class ManagedUIHandler : public content::WebUIMessageHandler,
// failure.
bool has_observers_ = false;
PrefChangeRegistrar pref_registrar_;
// Profile to update data sources on. Injected for testing.
Profile* const profile_;
......
......@@ -11,6 +11,9 @@
#include "chrome/browser/policy/profile_policy_connector.h"
#include "chrome/browser/policy/profile_policy_connector_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/account_tracker_service_factory.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/identity_test_environment_profile_adaptor.h"
#include "chrome/common/chrome_features.h"
#include "chrome/test/base/testing_profile.h"
#include "components/policy/core/common/mock_configuration_policy_provider.h"
......@@ -20,6 +23,8 @@
#include "content/public/test/test_browser_thread_bundle.h"
#include "content/public/test/test_web_ui.h"
#include "content/public/test/test_web_ui_data_source.h"
#include "services/identity/public/cpp/identity_manager.h"
#include "services/identity/public/cpp/identity_test_environment.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -42,11 +47,17 @@ class ManagedUIHandlerTest : public testing::Test {
// Create a TestingProfile that uses our MockConfigurationPolicyProvider.
policy_provider()->Init();
policy::PolicyServiceImpl::Providers providers = {policy_provider()};
TestingProfile::Builder builder;
builder.SetPolicyService(
std::make_unique<policy::PolicyServiceImpl>(std::move(providers)));
profile_ = builder.Build();
identity_adaptor_ =
std::make_unique<IdentityTestEnvironmentProfileAdaptor>(profile());
identity_adaptor_->identity_test_env()->MakePrimaryAccountAvailable(
"foobarbaz@gmail.com");
// We use a random source_name here as calling Add() can replace existing
// sources with the same name (which might destroy the memory addressed by
// |source_->GetWebUIDataSource()|.
......@@ -55,7 +66,7 @@ class ManagedUIHandlerTest : public testing::Test {
void TearDown() override { policy_provider()->Shutdown(); }
Profile* profile() { return profile_.get(); }
TestingProfile* profile() { return profile_.get(); }
policy::MockConfigurationPolicyProvider* policy_provider() {
return &policy_provider_;
}
......@@ -88,6 +99,8 @@ class ManagedUIHandlerTest : public testing::Test {
testing::NiceMock<policy::MockConfigurationPolicyProvider> policy_provider_;
std::unique_ptr<TestingProfile> profile_;
std::unique_ptr<IdentityTestEnvironmentProfileAdaptor> identity_adaptor_;
content::TestWebUI web_ui_;
std::unique_ptr<content::TestWebUIDataSource> source_;
};
......@@ -118,3 +131,14 @@ TEST_F(ManagedUIHandlerTest, ManagedUIBecomesEnabledByProfile) {
// Source should auto-update.
EXPECT_TRUE(IsSourceManaged());
}
#if defined(OS_CHROMEOS)
TEST_F(ManagedUIHandlerTest, ManagedUIDisabledForChildAccount) {
profile_policy_connector()->OverrideIsManagedForTesting(true);
profile()->SetSupervisedUserId("supervised");
InitializeHandler();
EXPECT_FALSE(IsSourceManaged());
}
#endif
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