Allow chrome://policy/test to treat a profile as managed
chrome://policy/test is not available on managed profiles, making it
impossible to test policies that only work in managed profiles.
By adding a new browser management status provider for the local test
policy provider, we can "fake" the profile being managed if any cloud
user level policy is set, allowing cloud user only policies to be
testable using chrome://policy.
NO_IFTTT= Change only affects desktop
Change-Id: Ia545cd61f86dd8db3ca733dd64a1099c08a104d4
Bug: 357581387
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5757343
Commit-Queue: Yann Dago <[email protected]>
Reviewed-by: Maksim Ivanov <[email protected]>
Reviewed-by: Elly FJ <[email protected]>
Reviewed-by: Igor Ruvinov <[email protected]>
Code-Coverage: [email protected] <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1338096}
diff --git a/chrome/browser/ui/webui/policy/policy_ui.cc b/chrome/browser/ui/webui/policy/policy_ui.cc
index 5da322af0..fd62965 100644
--- a/chrome/browser/ui/webui/policy/policy_ui.cc
+++ b/chrome/browser/ui/webui/policy/policy_ui.cc
@@ -21,6 +21,7 @@
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/enterprise/browser_management/management_service_factory.h"
+#include "chrome/browser/policy/profile_policy_connector.h"
#include "chrome/browser/policy/schema_registry_service.h"
#include "chrome/browser/policy/value_provider/chrome_policies_value_provider.h"
#include "chrome/browser/profiles/profile.h"
@@ -260,13 +261,20 @@
// static
bool PolicyUI::ShouldLoadTestPage(Profile* profile) {
- // Test page should only load if testing is enabled and the profile is not
- // managed by cloud.
- return policy::utils::IsPolicyTestingEnabled(profile->GetPrefs(),
- chrome::GetChannel()) &&
- !policy::ManagementServiceFactory::GetForProfile(profile)
- ->HasManagementAuthority(
- policy::EnterpriseManagementAuthority::CLOUD);
+ // Test page should only load if testing is enabled.
+ if (!policy::utils::IsPolicyTestingEnabled(profile->GetPrefs(),
+ chrome::GetChannel())) {
+ return false;
+ }
+ // The test page is not allowed if the profile is cloud managed unless
+ // we are already using the test policies.
+ if (policy::ManagementServiceFactory::GetForProfile(profile)
+ ->HasManagementAuthority(
+ policy::EnterpriseManagementAuthority::CLOUD) &&
+ !profile->GetProfilePolicyConnector()->IsUsingLocalTestPolicyProvider()) {
+ return false;
+ }
+ return true;
}
// static