This source file includes following definitions.
- Wait
- OnPrefChange
- LoginScreenDefaultPolicyBrowsertestBase
- LoginScreenDefaultPolicyBrowsertestBase
- SetUpInProcessBrowserTestFixture
- SetUpOnMainThread
- RefreshDevicePolicyAndWaitForPrefChange
- LoginScreenDefaultPolicyLoginScreenBrowsertest
- LoginScreenDefaultPolicyLoginScreenBrowsertest
- SetUpCommandLine
- SetUpOnMainThread
- CleanUpOnMainThread
- VerifyPrefFollowsRecommendation
- LoginScreenDefaultPolicyInSessionBrowsertest
- LoginScreenDefaultPolicyInSessionBrowsertest
- SetUpOnMainThread
- VerifyPrefFollowsDefault
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
#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/location.h"
#include "base/message_loop/message_loop.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/proto/chrome_device_policy.pb.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/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/pref_names.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;
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();
}
}
class LoginScreenDefaultPolicyBrowsertestBase
: public DevicePolicyCrosBrowserTest {
protected:
LoginScreenDefaultPolicyBrowsertestBase();
virtual ~LoginScreenDefaultPolicyBrowsertestBase();
virtual void SetUpInProcessBrowserTestFixture() OVERRIDE;
virtual void SetUpOnMainThread() OVERRIDE;
void RefreshDevicePolicyAndWaitForPrefChange(const char* pref_name);
Profile* login_profile_;
private:
DISALLOW_COPY_AND_ASSIGN(LoginScreenDefaultPolicyBrowsertestBase);
};
class LoginScreenDefaultPolicyLoginScreenBrowsertest
: public LoginScreenDefaultPolicyBrowsertestBase {
protected:
LoginScreenDefaultPolicyLoginScreenBrowsertest();
virtual ~LoginScreenDefaultPolicyLoginScreenBrowsertest();
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
virtual void SetUpOnMainThread() OVERRIDE;
virtual void CleanUpOnMainThread() OVERRIDE;
void VerifyPrefFollowsRecommendation(const char* pref_name,
const base::Value& recommended_value);
private:
DISALLOW_COPY_AND_ASSIGN(LoginScreenDefaultPolicyLoginScreenBrowsertest);
};
class LoginScreenDefaultPolicyInSessionBrowsertest
: public LoginScreenDefaultPolicyBrowsertestBase {
protected:
LoginScreenDefaultPolicyInSessionBrowsertest();
virtual ~LoginScreenDefaultPolicyInSessionBrowsertest();
virtual void SetUpOnMainThread() OVERRIDE;
void VerifyPrefFollowsDefault(const char* pref_name);
private:
DISALLOW_COPY_AND_ASSIGN(LoginScreenDefaultPolicyInSessionBrowsertest);
};
LoginScreenDefaultPolicyBrowsertestBase::
LoginScreenDefaultPolicyBrowsertestBase() : login_profile_(NULL) {
}
LoginScreenDefaultPolicyBrowsertestBase::
~LoginScreenDefaultPolicyBrowsertestBase() {
}
void LoginScreenDefaultPolicyBrowsertestBase::
SetUpInProcessBrowserTestFixture() {
InstallOwnerKey();
MarkAsEnterpriseOwned();
DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture();
}
void LoginScreenDefaultPolicyBrowsertestBase::SetUpOnMainThread() {
DevicePolicyCrosBrowserTest::SetUpOnMainThread();
login_profile_ = chromeos::ProfileHelper::GetSigninProfile();
ASSERT_TRUE(login_profile_);
}
void LoginScreenDefaultPolicyBrowsertestBase::
RefreshDevicePolicyAndWaitForPrefChange(const char* pref_name) {
PrefChangeWatcher watcher(pref_name, login_profile_->GetPrefs());
RefreshDevicePolicy();
watcher.Wait();
}
LoginScreenDefaultPolicyLoginScreenBrowsertest::
LoginScreenDefaultPolicyLoginScreenBrowsertest() {
}
LoginScreenDefaultPolicyLoginScreenBrowsertest::
~LoginScreenDefaultPolicyLoginScreenBrowsertest() {
}
void LoginScreenDefaultPolicyLoginScreenBrowsertest::SetUpCommandLine(
CommandLine* command_line) {
LoginScreenDefaultPolicyBrowsertestBase::SetUpCommandLine(command_line);
command_line->AppendSwitch(chromeos::switches::kLoginManager);
command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests);
}
void LoginScreenDefaultPolicyLoginScreenBrowsertest::SetUpOnMainThread() {
LoginScreenDefaultPolicyBrowsertestBase::SetUpOnMainThread();
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 LoginScreenDefaultPolicyLoginScreenBrowsertest::CleanUpOnMainThread() {
base::MessageLoop::current()->PostTask(FROM_HERE,
base::Bind(&chrome::AttemptExit));
base::RunLoop().RunUntilIdle();
LoginScreenDefaultPolicyBrowsertestBase::CleanUpOnMainThread();
}
void LoginScreenDefaultPolicyLoginScreenBrowsertest::
VerifyPrefFollowsRecommendation(const char* pref_name,
const base::Value& recommended_value) {
const PrefService::Preference* pref =
login_profile_->GetPrefs()->FindPreference(pref_name);
ASSERT_TRUE(pref);
EXPECT_FALSE(pref->IsManaged());
EXPECT_FALSE(pref->IsDefaultValue());
EXPECT_TRUE(base::Value::Equals(&recommended_value, pref->GetValue()));
EXPECT_TRUE(base::Value::Equals(&recommended_value,
pref->GetRecommendedValue()));
}
LoginScreenDefaultPolicyInSessionBrowsertest::
LoginScreenDefaultPolicyInSessionBrowsertest() {
}
LoginScreenDefaultPolicyInSessionBrowsertest::
~LoginScreenDefaultPolicyInSessionBrowsertest() {
}
void LoginScreenDefaultPolicyInSessionBrowsertest::SetUpOnMainThread() {
LoginScreenDefaultPolicyBrowsertestBase::SetUpOnMainThread();
chromeos::DeviceSettingsService::Get()->SetUsername(std::string());
}
void LoginScreenDefaultPolicyInSessionBrowsertest::VerifyPrefFollowsDefault(
const char* pref_name) {
Profile* profile = ProfileManager::GetActiveUserProfile();
ASSERT_TRUE(profile);
const PrefService::Preference* pref =
profile->GetPrefs()->FindPreference(pref_name);
ASSERT_TRUE(pref);
EXPECT_FALSE(pref->IsManaged());
EXPECT_TRUE(pref->IsDefaultValue());
EXPECT_FALSE(pref->GetRecommendedValue());
}
IN_PROC_BROWSER_TEST_F(LoginScreenDefaultPolicyLoginScreenBrowsertest,
DeviceLoginScreenDefaultLargeCursorEnabled) {
em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
proto.mutable_accessibility_settings()->
set_login_screen_default_large_cursor_enabled(true);
RefreshDevicePolicyAndWaitForPrefChange(prefs::kLargeCursorEnabled);
VerifyPrefFollowsRecommendation(prefs::kLargeCursorEnabled,
base::FundamentalValue(true));
chromeos::AccessibilityManager* accessibility_manager =
chromeos::AccessibilityManager::Get();
ASSERT_TRUE(accessibility_manager);
EXPECT_TRUE(accessibility_manager->IsLargeCursorEnabled());
}
IN_PROC_BROWSER_TEST_F(LoginScreenDefaultPolicyLoginScreenBrowsertest,
DeviceLoginScreenDefaultSpokenFeedbackEnabled) {
em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
proto.mutable_accessibility_settings()->
set_login_screen_default_spoken_feedback_enabled(true);
RefreshDevicePolicyAndWaitForPrefChange(prefs::kSpokenFeedbackEnabled);
VerifyPrefFollowsRecommendation(prefs::kSpokenFeedbackEnabled,
base::FundamentalValue(true));
chromeos::AccessibilityManager* accessibility_manager =
chromeos::AccessibilityManager::Get();
ASSERT_TRUE(accessibility_manager);
EXPECT_TRUE(accessibility_manager->IsSpokenFeedbackEnabled());
}
IN_PROC_BROWSER_TEST_F(LoginScreenDefaultPolicyLoginScreenBrowsertest,
DeviceLoginScreenDefaultHighContrastEnabled) {
em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
proto.mutable_accessibility_settings()->
set_login_screen_default_high_contrast_enabled(true);
RefreshDevicePolicyAndWaitForPrefChange(prefs::kHighContrastEnabled);
VerifyPrefFollowsRecommendation(prefs::kHighContrastEnabled,
base::FundamentalValue(true));
chromeos::AccessibilityManager* accessibility_manager =
chromeos::AccessibilityManager::Get();
ASSERT_TRUE(accessibility_manager);
EXPECT_TRUE(accessibility_manager->IsHighContrastEnabled());
}
IN_PROC_BROWSER_TEST_F(LoginScreenDefaultPolicyLoginScreenBrowsertest,
DeviceLoginScreenDefaultScreenMagnifierType) {
em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
proto.mutable_accessibility_settings()->
set_login_screen_default_screen_magnifier_type(kFullScreenMagnifier);
RefreshDevicePolicyAndWaitForPrefChange(prefs::kScreenMagnifierType);
VerifyPrefFollowsRecommendation(prefs::kScreenMagnifierEnabled,
base::FundamentalValue(true));
VerifyPrefFollowsRecommendation(prefs::kScreenMagnifierType,
base::FundamentalValue(ash::MAGNIFIER_FULL));
chromeos::MagnificationManager* magnification_manager =
chromeos::MagnificationManager::Get();
ASSERT_TRUE(magnification_manager);
EXPECT_TRUE(magnification_manager->IsMagnifierEnabled());
EXPECT_EQ(ash::MAGNIFIER_FULL, magnification_manager->GetMagnifierType());
}
IN_PROC_BROWSER_TEST_F(LoginScreenDefaultPolicyInSessionBrowsertest,
DeviceLoginScreenDefaultLargeCursorEnabled) {
em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
proto.mutable_accessibility_settings()->
set_login_screen_default_large_cursor_enabled(true);
RefreshDevicePolicyAndWaitForPrefChange(prefs::kLargeCursorEnabled);
VerifyPrefFollowsDefault(prefs::kLargeCursorEnabled);
chromeos::AccessibilityManager* accessibility_manager =
chromeos::AccessibilityManager::Get();
ASSERT_TRUE(accessibility_manager);
EXPECT_FALSE(accessibility_manager->IsLargeCursorEnabled());
}
IN_PROC_BROWSER_TEST_F(LoginScreenDefaultPolicyInSessionBrowsertest,
DeviceLoginScreenDefaultSpokenFeedbackEnabled) {
em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
proto.mutable_accessibility_settings()->
set_login_screen_default_spoken_feedback_enabled(true);
RefreshDevicePolicyAndWaitForPrefChange(prefs::kSpokenFeedbackEnabled);
VerifyPrefFollowsDefault(prefs::kSpokenFeedbackEnabled);
chromeos::AccessibilityManager* accessibility_manager =
chromeos::AccessibilityManager::Get();
ASSERT_TRUE(accessibility_manager);
EXPECT_FALSE(accessibility_manager->IsSpokenFeedbackEnabled());
}
IN_PROC_BROWSER_TEST_F(LoginScreenDefaultPolicyInSessionBrowsertest,
DeviceLoginScreenDefaultHighContrastEnabled) {
em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
proto.mutable_accessibility_settings()->
set_login_screen_default_high_contrast_enabled(true);
RefreshDevicePolicyAndWaitForPrefChange(prefs::kHighContrastEnabled);
VerifyPrefFollowsDefault(prefs::kHighContrastEnabled);
chromeos::AccessibilityManager* accessibility_manager =
chromeos::AccessibilityManager::Get();
ASSERT_TRUE(accessibility_manager);
EXPECT_FALSE(accessibility_manager->IsHighContrastEnabled());
}
IN_PROC_BROWSER_TEST_F(LoginScreenDefaultPolicyInSessionBrowsertest,
DeviceLoginScreenDefaultScreenMagnifierType) {
em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
proto.mutable_accessibility_settings()->
set_login_screen_default_screen_magnifier_type(kFullScreenMagnifier);
RefreshDevicePolicyAndWaitForPrefChange(prefs::kScreenMagnifierType);
VerifyPrefFollowsDefault(prefs::kScreenMagnifierEnabled);
VerifyPrefFollowsDefault(prefs::kScreenMagnifierType);
chromeos::MagnificationManager* magnification_manager =
chromeos::MagnificationManager::Get();
ASSERT_TRUE(magnification_manager);
EXPECT_FALSE(magnification_manager->IsMagnifierEnabled());
EXPECT_EQ(ash::kDefaultMagnifierType,
magnification_manager->GetMagnifierType());
}
IN_PROC_BROWSER_TEST_F(LoginScreenDefaultPolicyLoginScreenBrowsertest,
DeviceLoginScreenDefaultVirtualKeyboardEnabled) {
em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
proto.mutable_accessibility_settings()->
set_login_screen_default_virtual_keyboard_enabled(true);
RefreshDevicePolicyAndWaitForPrefChange(prefs::kVirtualKeyboardEnabled);
VerifyPrefFollowsRecommendation(prefs::kVirtualKeyboardEnabled,
base::FundamentalValue(true));
chromeos::AccessibilityManager* accessibility_manager =
chromeos::AccessibilityManager::Get();
ASSERT_TRUE(accessibility_manager);
EXPECT_TRUE(accessibility_manager->IsVirtualKeyboardEnabled());
}
}