Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4907)

Unified Diff: chrome/browser/chromeos/policy/device_policy_browsertest.cc

Issue 16658015: Add device policies to control accessibility settings on the login screen (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix copy&paste mistake found by clang. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/policy/device_policy_browsertest.cc
diff --git a/chrome/browser/chromeos/policy/device_policy_browsertest.cc b/chrome/browser/chromeos/policy/device_policy_browsertest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f57543cf60ba0b7e669bd7bc83a82b44a3a96fa8
--- /dev/null
+++ b/chrome/browser/chromeos/policy/device_policy_browsertest.cc
@@ -0,0 +1,387 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <string>
+
+#include "ash/magnifier/magnifier_constants.h"
+#include "base/basictypes.h"
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/command_line.h"
+#include "base/compiler_specific.h"
+#include "base/file_util.h"
+#include "base/files/file_path.h"
+#include "base/location.h"
+#include "base/message_loop.h"
+#include "base/path_service.h"
+#include "base/prefs/pref_change_registrar.h"
+#include "base/prefs/pref_service.h"
+#include "base/run_loop.h"
+#include "base/values.h"
+#include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
+#include "chrome/browser/chromeos/accessibility/magnification_manager.h"
+#include "chrome/browser/chromeos/policy/device_policy_builder.h"
+#include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h"
+#include "chrome/browser/chromeos/policy/enterprise_install_attributes.h"
+#include "chrome/browser/chromeos/profiles/profile_helper.h"
+#include "chrome/browser/chromeos/settings/device_settings_service.h"
+#include "chrome/browser/lifetime/application_lifetime.h"
+#include "chrome/browser/policy/proto/chromeos/chrome_device_policy.pb.h"
+#include "chrome/browser/policy/proto/chromeos/install_attributes.pb.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/common/pref_names.h"
+#include "chromeos/chromeos_paths.h"
+#include "chromeos/chromeos_switches.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace em = enterprise_management;
+
+namespace policy {
+
+namespace {
+
+const em::AccessibilitySettingsProto_ScreenMagnifierType kFullScreenMagnifier =
+ em::AccessibilitySettingsProto_ScreenMagnifierType_SCREEN_MAGNIFIER_TYPE_FULL;
+
+// Spins the loop until a notification is received from |prefs| that the value
+// of |pref_name| has changed. If the notification is received before Wait()
+// has been called, Wait() returns immediately and no loop is spun.
+class PrefChangeWatcher {
+ public:
+ PrefChangeWatcher(const char* pref_name, PrefService* prefs);
+
+ void Wait();
+
+ void OnPrefChange();
+
+ private:
+ bool pref_changed_;
+
+ base::RunLoop run_loop_;
+ PrefChangeRegistrar registrar_;
+
+ DISALLOW_COPY_AND_ASSIGN(PrefChangeWatcher);
+};
+
+PrefChangeWatcher::PrefChangeWatcher(const char* pref_name,
+ PrefService* prefs)
+ : pref_changed_(false) {
+ registrar_.Init(prefs);
+ registrar_.Add(pref_name, base::Bind(&PrefChangeWatcher::OnPrefChange,
+ base::Unretained(this)));
+}
+
+void PrefChangeWatcher::Wait() {
+ if (!pref_changed_)
+ run_loop_.Run();
+}
+
+void PrefChangeWatcher::OnPrefChange() {
+ pref_changed_ = true;
+ run_loop_.Quit();
+}
+
+} // namespace
+
+class DevicePolicyBrowsertest : public DevicePolicyCrosBrowserTest,
Mattias Nissler (ping if slow) 2013/06/12 13:55:16 The name of this class and file is a bit misleadin
bartfab (slow) 2013/06/12 18:57:49 My idea was that we do not have the complete boile
+ public testing::WithParamInterface<bool> {
+ protected:
+ DevicePolicyBrowsertest();
+ virtual ~DevicePolicyBrowsertest();
+
+ // DevicePolicyCrosBrowserTest:
+ virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
+ virtual void SetUpInProcessBrowserTestFixture() OVERRIDE;
+ virtual void SetUpOnMainThread() OVERRIDE;
+ virtual void CleanUpOnMainThread() OVERRIDE;
+
+ const bool logged_in_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DevicePolicyBrowsertest);
+};
+
+DevicePolicyBrowsertest::DevicePolicyBrowsertest() : logged_in_(GetParam()) {
+}
+
+DevicePolicyBrowsertest::~DevicePolicyBrowsertest() {
+}
+
+void DevicePolicyBrowsertest::SetUpCommandLine(CommandLine* command_line) {
+ DevicePolicyCrosBrowserTest::SetUpCommandLine(command_line);
+ if (logged_in_)
Mattias Nissler (ping if slow) 2013/06/12 13:55:16 It seems like logged_in_ behavior and test verific
bartfab (slow) 2013/06/12 18:57:49 Done.
+ return;
+
+ command_line->AppendSwitch(chromeos::switches::kLoginManager);
+ command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests);
+}
+
+void DevicePolicyBrowsertest::SetUpInProcessBrowserTestFixture() {
+ InstallOwnerKey();
+
+ // Mark the device as enterprise-owned.
+ cryptohome::SerializedInstallAttributes install_attrs_proto;
+ cryptohome::SerializedInstallAttributes::Attribute* attribute = NULL;
+
+ attribute = install_attrs_proto.add_attributes();
+ attribute->set_name(EnterpriseInstallAttributes::kAttrEnterpriseOwned);
+ attribute->set_value("true");
+
+ attribute = install_attrs_proto.add_attributes();
+ attribute->set_name(EnterpriseInstallAttributes::kAttrEnterpriseUser);
+ attribute->set_value(DevicePolicyBuilder::kFakeUsername);
+
+ base::FilePath install_attrs_file =
+ temp_dir_.path().AppendASCII("install_attributes.pb");
+ const std::string install_attrs_blob(
+ install_attrs_proto.SerializeAsString());
+ ASSERT_EQ(static_cast<int>(install_attrs_blob.size()),
+ file_util::WriteFile(install_attrs_file,
+ install_attrs_blob.c_str(),
+ install_attrs_blob.size()));
+ ASSERT_TRUE(PathService::Override(chromeos::FILE_INSTALL_ATTRIBUTES,
+ install_attrs_file));
Mattias Nissler (ping if slow) 2013/06/12 13:55:16 Given this is a copy of existing code, we should p
bartfab (slow) 2013/06/12 18:57:49 Done. But I had to make the method static because
+
+ DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture();
+}
+
+void DevicePolicyBrowsertest::SetUpOnMainThread() {
+ DevicePolicyCrosBrowserTest::SetUpOnMainThread();
+
+ // Tell the DeviceSettingsService that there is no local owner.
+ chromeos::DeviceSettingsService::Get()->SetUsername(std::string());
+
+ if (logged_in_)
+ return;
+
+ // Set the login screen profile.
+ chromeos::AccessibilityManager* accessibility_manager =
+ chromeos::AccessibilityManager::Get();
+ ASSERT_TRUE(accessibility_manager);
+ accessibility_manager->SetProfileForTest(
+ chromeos::ProfileHelper::GetSigninProfile());
+
+ chromeos::MagnificationManager* magnification_manager =
+ chromeos::MagnificationManager::Get();
+ ASSERT_TRUE(magnification_manager);
+ magnification_manager->SetProfileForTest(
+ chromeos::ProfileHelper::GetSigninProfile());
+}
+
+void DevicePolicyBrowsertest::CleanUpOnMainThread() {
+ base::MessageLoop::current()->PostTask(FROM_HERE,
+ base::Bind(&chrome::AttemptExit));
+ base::RunLoop().RunUntilIdle();
+ DevicePolicyCrosBrowserTest::CleanUpOnMainThread();
+}
+
+IN_PROC_BROWSER_TEST_P(DevicePolicyBrowsertest,
+ LoginScreenDefaultLargeCursorEnabled) {
+ // Verifies that the default state of the large cursor accessibility feature
+ // on the login screen can be controlled through device policy.
+ Profile* login_profile = chromeos::ProfileHelper::GetSigninProfile();
+ ASSERT_TRUE(login_profile);
+
+ // Enable the large cursor through device policy and wait for the change to
+ // take effect.
+ em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
+ proto.mutable_accessibility_settings()->
+ set_login_screen_default_large_cursor_enabled(true);
+ PrefChangeWatcher watcher(prefs::kLargeCursorEnabled,
+ login_profile->GetPrefs());
+ RefreshDevicePolicy();
+ watcher.Wait();
+
+ Profile* current_profile = logged_in_ ? ProfileManager::GetDefaultProfile() :
Mattias Nissler (ping if slow) 2013/06/12 13:55:16 style nit: not sure, but I think the colon commonl
bartfab (slow) 2013/06/12 18:57:49 Done.
+ login_profile;
+ ASSERT_TRUE(current_profile);
+ const PrefService::Preference* pref =
+ current_profile->GetPrefs()->FindPreference(prefs::kLargeCursorEnabled);
+ ASSERT_TRUE(pref);
+
+ // When logged in, verify that the pref which controls the large cursor in
+ // the current profile is unchanged.
+ // When not logged in, verify that the pref which controls the large cursor
+ // in the login profile has changed to the policy-supplied default.
+ const base::FundamentalValue expected_value(!logged_in_);
+ EXPECT_FALSE(pref->IsManaged());
+ EXPECT_EQ(logged_in_, pref->IsDefaultValue());
+ EXPECT_TRUE(base::Value::Equals(&expected_value, pref->GetValue()));
+ const base::Value* recommended_value = pref->GetRecommendedValue();
+ if (logged_in_)
+ EXPECT_FALSE(recommended_value);
+ else
+ EXPECT_TRUE(base::Value::Equals(&expected_value, recommended_value));
+
+ // When logged in, verify that the large cursor is disabled.
+ // When not logged in, verify that the large cursor is enabled.
+ chromeos::AccessibilityManager* accessibility_manager =
+ chromeos::AccessibilityManager::Get();
+ ASSERT_TRUE(accessibility_manager);
+ EXPECT_EQ(!logged_in_, accessibility_manager->IsLargeCursorEnabled());
+}
+
+IN_PROC_BROWSER_TEST_P(DevicePolicyBrowsertest,
+ LoginScreenDefaultSpokenFeedbackEnabled) {
+ // Verifies that the default state of the spoken feedback accessibility
+ // feature on the login screen can be controlled through device policy.
+ Profile* login_profile = chromeos::ProfileHelper::GetSigninProfile();
+ ASSERT_TRUE(login_profile);
+
+ // Enable spoken feedback through device policy and wait for the change to
+ // take effect.
+ em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
+ proto.mutable_accessibility_settings()->
+ set_login_screen_default_spoken_feedback_enabled(true);
+ PrefChangeWatcher watcher(prefs::kSpokenFeedbackEnabled,
+ login_profile->GetPrefs());
+ RefreshDevicePolicy();
+ watcher.Wait();
+
+ Profile* current_profile = logged_in_ ? ProfileManager::GetDefaultProfile() :
+ login_profile;
+ ASSERT_TRUE(current_profile);
+ const PrefService::Preference* pref =
+ current_profile->GetPrefs()->FindPreference(
+ prefs::kSpokenFeedbackEnabled);
+ ASSERT_TRUE(pref);
+
+ // When logged in, verify that the pref which controls spoken feedback in the
+ // current profile is unchanged.
+ // When not logged in, verify that the pref which controls spoken feedback in
+ // the login profile has changed to the policy-supplied default.
+ const base::FundamentalValue expected_value(!logged_in_);
+ EXPECT_FALSE(pref->IsManaged());
+ EXPECT_EQ(logged_in_, pref->IsDefaultValue());
+ EXPECT_TRUE(base::Value::Equals(&expected_value, pref->GetValue()));
+ const base::Value* recommended_value = pref->GetRecommendedValue();
+ if (logged_in_)
+ EXPECT_FALSE(recommended_value);
+ else
+ EXPECT_TRUE(base::Value::Equals(&expected_value, recommended_value));
+
+ // When logged in, verify that spoken feedback is disabled.
+ // When not logged in, verify that spoken feedback is enabled.
+ chromeos::AccessibilityManager* accessibility_manager =
+ chromeos::AccessibilityManager::Get();
+ ASSERT_TRUE(accessibility_manager);
+ EXPECT_EQ(!logged_in_, accessibility_manager->IsSpokenFeedbackEnabled());
+}
+
+IN_PROC_BROWSER_TEST_P(DevicePolicyBrowsertest,
+ LoginScreenDefaultHighContrastEnabled) {
+ // Verifies that the default state of the high contrast mode accessibility
+ // feature on the login screen can be controlled through device policy.
+ Profile* login_profile = chromeos::ProfileHelper::GetSigninProfile();
+ ASSERT_TRUE(login_profile);
+
+ // Enable high contrast mode through device policy and wait for the change to
+ // take effect.
+ em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
+ proto.mutable_accessibility_settings()->
+ set_login_screen_default_high_contrast_enabled(true);
+ PrefChangeWatcher watcher(prefs::kHighContrastEnabled,
+ login_profile->GetPrefs());
+ RefreshDevicePolicy();
+ watcher.Wait();
+
+ Profile* current_profile = logged_in_ ? ProfileManager::GetDefaultProfile() :
+ login_profile;
+ ASSERT_TRUE(current_profile);
+ const PrefService::Preference* pref =
+ current_profile->GetPrefs()->FindPreference(prefs::kHighContrastEnabled);
+ ASSERT_TRUE(pref);
+
+ // When logged in, verify that the pref which controls high contrast mode in
+ // the current profile is unchanged.
+ // When not logged in, verify that the pref which controls high contrast mode
+ // in the login profile has changed to the policy-supplied default.
+ const base::FundamentalValue expected_value(!logged_in_);
+ EXPECT_FALSE(pref->IsManaged());
+ EXPECT_EQ(logged_in_, pref->IsDefaultValue());
+ EXPECT_TRUE(base::Value::Equals(&expected_value, pref->GetValue()));
+ const base::Value* recommended_value = pref->GetRecommendedValue();
+ if (logged_in_)
+ EXPECT_FALSE(recommended_value);
+ else
+ EXPECT_TRUE(base::Value::Equals(&expected_value, recommended_value));
+
+ // When logged in, verify that high contrast mode is disabled.
+ // When not logged in, verify that high contrast mode is enabled.
+ chromeos::AccessibilityManager* accessibility_manager =
+ chromeos::AccessibilityManager::Get();
+ ASSERT_TRUE(accessibility_manager);
+ EXPECT_EQ(!logged_in_, accessibility_manager->IsHighContrastEnabled());
+}
Mattias Nissler (ping if slow) 2013/06/12 13:55:16 The previous 3 test cases are identical in terms o
bartfab (slow) 2013/06/12 18:57:49 Done.
+
+IN_PROC_BROWSER_TEST_P(DevicePolicyBrowsertest,
+ LoginScreenDefaultScreenMagnifierType) {
+ // Verifies that the default screen magnifier type enabled on the login screen
+ // can be controlled through device policy.
+ Profile* login_profile = chromeos::ProfileHelper::GetSigninProfile();
+ ASSERT_TRUE(login_profile);
+
+ // Set the screen magnifier type through device policy and wait for the change
+ // to take effect.
+ em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
+ proto.mutable_accessibility_settings()->
+ set_login_screen_default_screen_magnifier_type(kFullScreenMagnifier);
+ PrefChangeWatcher watcher(prefs::kScreenMagnifierType,
+ login_profile->GetPrefs());
+ RefreshDevicePolicy();
+ watcher.Wait();
+
+ Profile* current_profile = logged_in_ ? ProfileManager::GetDefaultProfile() :
+ login_profile;
+ ASSERT_TRUE(current_profile);
+ const PrefService::Preference* enabled_pref =
+ current_profile->GetPrefs()->FindPreference(
+ prefs::kScreenMagnifierEnabled);
+ const PrefService::Preference* type_pref =
+ current_profile->GetPrefs()->FindPreference(prefs::kScreenMagnifierType);
+ ASSERT_TRUE(enabled_pref);
+ ASSERT_TRUE(type_pref);
+
+ // When logged in, verify that the prefs which control the screen magnifier
+ // are unchanged.
+ // When not logged in, verify that the prefs which control the screen
+ // magnifier type have changed to the policy-supplied default.
+ const base::FundamentalValue expected_enabled(!logged_in_);
+ EXPECT_FALSE(enabled_pref->IsManaged());
+ EXPECT_EQ(logged_in_, enabled_pref->IsDefaultValue());
+ EXPECT_TRUE(base::Value::Equals(&expected_enabled, enabled_pref->GetValue()));
+ const base::Value* recommended_value = enabled_pref->GetRecommendedValue();
+ if (logged_in_) {
+ EXPECT_FALSE(recommended_value);
+ } else {
+ EXPECT_TRUE(base::Value::Equals(&expected_enabled, recommended_value));
+ }
+
+ ash::MagnifierType expected_magnifier_type =
+ logged_in_ ? ash::kDefaultMagnifierType : ash::MAGNIFIER_FULL;
+ const base::FundamentalValue expected_type(expected_magnifier_type);
+ EXPECT_FALSE(type_pref->IsManaged());
+ EXPECT_EQ(logged_in_, type_pref->IsDefaultValue());
+ EXPECT_TRUE(base::Value::Equals(&expected_type, type_pref->GetValue()));
+ recommended_value = type_pref->GetRecommendedValue();
+ if (logged_in_)
+ EXPECT_FALSE(recommended_value);
+ else
+ EXPECT_TRUE(base::Value::Equals(&expected_type, recommended_value));
+
+ // When logged in, verify that the screen magnifier is disabled.
+ // When not logged in, verify that the full-screen magnifier is enabled.
+ chromeos::MagnificationManager* magnification_manager =
+ chromeos::MagnificationManager::Get();
+ ASSERT_TRUE(magnification_manager);
+ EXPECT_EQ(!logged_in_, magnification_manager->IsMagnifierEnabled());
+ EXPECT_EQ(expected_magnifier_type, magnification_manager->GetMagnifierType());
+}
+
+INSTANTIATE_TEST_CASE_P(DevicePolicyBrowsertestInstantiation,
+ DevicePolicyBrowsertest,
+ testing::Bool());
+
+} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698