| Index: chrome/browser/chromeos/accessibility/accessibility_manager_browsertest.cc
|
| diff --git a/chrome/browser/chromeos/accessibility/accessibility_manager_browsertest.cc b/chrome/browser/chromeos/accessibility/accessibility_manager_browsertest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..230f22caa898a2242c7568975a35913f6ac898a7
|
| --- /dev/null
|
| +++ b/chrome/browser/chromeos/accessibility/accessibility_manager_browsertest.cc
|
| @@ -0,0 +1,301 @@
|
| +// 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 "chrome/browser/chromeos/accessibility/accessibility_manager.h"
|
| +
|
| +#include "ash/magnifier/magnification_controller.h"
|
| +#include "ash/shell.h"
|
| +#include "base/command_line.h"
|
| +#include "base/prefs/pref_service.h"
|
| +#include "chrome/browser/browser_process.h"
|
| +#include "chrome/browser/chromeos/accessibility/magnification_manager.h"
|
| +#include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h"
|
| +#include "chrome/browser/chromeos/login/helper.h"
|
| +#include "chrome/browser/chromeos/login/login_utils.h"
|
| +#include "chrome/browser/chromeos/login/user_manager.h"
|
| +#include "chrome/browser/chromeos/login/user_manager_impl.h"
|
| +#include "chrome/browser/profiles/profile.h"
|
| +#include "chrome/browser/profiles/profile_manager.h"
|
| +#include "chrome/common/chrome_notification_types.h"
|
| +#include "chrome/common/pref_names.h"
|
| +#include "chrome/test/base/testing_profile.h"
|
| +#include "chromeos/chromeos_switches.h"
|
| +#include "content/public/browser/notification_service.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace chromeos {
|
| +
|
| +namespace {
|
| +
|
| +const char kTestUserName[] = "owner@invalid.domain";
|
| +
|
| +class MockAccessibilityObserver : public content::NotificationObserver {
|
| + public:
|
| + MockAccessibilityObserver() : observed_(false),
|
| + observed_enabled_(false),
|
| + observed_type_(-1) {
|
| + registrar_.Add(
|
| + this,
|
| + chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK,
|
| + content::NotificationService::AllSources());
|
| + registrar_.Add(
|
| + this,
|
| + chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE,
|
| + content::NotificationService::AllSources());
|
| + }
|
| +
|
| + bool observed() const { return observed_; }
|
| + bool observed_enabled() const { return observed_enabled_; }
|
| + int observed_type() const { return observed_type_; }
|
| +
|
| + void reset() { observed_ = false; }
|
| +
|
| + private:
|
| + // content::NotificationObserver implimentation:
|
| + virtual void Observe(int type,
|
| + const content::NotificationSource& source,
|
| + const content::NotificationDetails& details) OVERRIDE {
|
| + AccessibilityStatusEventDetails* accessibility_status =
|
| + content::Details<AccessibilityStatusEventDetails>(
|
| + details).ptr();
|
| + ASSERT_FALSE(observed_);
|
| +
|
| + switch (type) {
|
| + case chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK:
|
| + observed_ = true;
|
| + observed_enabled_ = accessibility_status->enabled;
|
| + observed_type_ = type;
|
| + break;
|
| + case chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE:
|
| + observed_ = true;
|
| + observed_enabled_ = accessibility_status->enabled;
|
| + observed_type_ = type;
|
| + break;
|
| + }
|
| + }
|
| +
|
| + bool observed_;
|
| + bool observed_enabled_;
|
| + int observed_type_;
|
| +
|
| + content::NotificationRegistrar registrar_;
|
| +};
|
| +
|
| +void SetHighContrastEnabled(bool enabled) {
|
| + return AccessibilityManager::Get()->EnableHighContrast(enabled);
|
| +}
|
| +
|
| +bool IsHighContrastEnabled() {
|
| + return AccessibilityManager::Get()->IsHighContrastEnabled();
|
| +}
|
| +
|
| +void SetSpokenFeedbackEnabled(bool enabled) {
|
| + return AccessibilityManager::Get()->EnableSpokenFeedback(
|
| + enabled, NULL, ash::A11Y_NOTIFICATION_NONE);
|
| +}
|
| +
|
| +bool IsSpokenFeedbackEnabled() {
|
| + return AccessibilityManager::Get()->IsSpokenFeedbackEnabled();
|
| +}
|
| +
|
| +Profile* profile() {
|
| + Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord();
|
| + DCHECK(profile);
|
| + return profile;
|
| +}
|
| +
|
| +PrefService* prefs() {
|
| + return profile()->GetPrefs();
|
| +}
|
| +
|
| +void SetHighContrastEnabledToPref(bool enabled) {
|
| + prefs()->SetBoolean(prefs::kHighContrastEnabled, enabled);
|
| +}
|
| +
|
| +void SetSpokenFeedbackEnabledToPref(bool enabled) {
|
| + prefs()->SetBoolean(prefs::kSpokenFeedbackEnabled, enabled);
|
| +}
|
| +
|
| +} // anonymouse namespace
|
| +
|
| +class AccessibilityManagerTest : public CrosInProcessBrowserTest {
|
| + protected:
|
| + AccessibilityManagerTest() {}
|
| + virtual ~AccessibilityManagerTest() {}
|
| +
|
| + virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
|
| + command_line->AppendSwitch(chromeos::switches::kLoginManager);
|
| + command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile,
|
| + TestingProfile::kTestUserProfileDir);
|
| + }
|
| +
|
| + virtual void SetUpOnMainThread() OVERRIDE {
|
| + }
|
| +
|
| + content::NotificationRegistrar registrar_;
|
| + DISALLOW_COPY_AND_ASSIGN(AccessibilityManagerTest);
|
| +};
|
| +
|
| +IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, Login) {
|
| + // Confirms that magnifier is disabled on the login screen.
|
| + EXPECT_FALSE(IsSpokenFeedbackEnabled());
|
| + EXPECT_FALSE(IsHighContrastEnabled());
|
| +
|
| + // Logs in.
|
| + UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true);
|
| +
|
| + // Confirms that magnifier is still disabled just after login.
|
| + EXPECT_FALSE(IsSpokenFeedbackEnabled());
|
| + EXPECT_FALSE(IsHighContrastEnabled());
|
| +
|
| + UserManager::Get()->SessionStarted();
|
| +
|
| + // Confirms that magnifier is still disabled just after login.
|
| + EXPECT_FALSE(IsSpokenFeedbackEnabled());
|
| + EXPECT_FALSE(IsHighContrastEnabled());
|
| +
|
| + // Enables magnifier.
|
| + SetSpokenFeedbackEnabled(true);
|
| + // Confirms that magnifier is enabled.
|
| + EXPECT_TRUE(IsSpokenFeedbackEnabled());
|
| +
|
| + // Enables magnifier.
|
| + SetHighContrastEnabled(true);
|
| + // Confirms that magnifier is enabled.
|
| + EXPECT_TRUE(IsHighContrastEnabled());
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, TypePref) {
|
| + // Logs in
|
| + UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true);
|
| + UserManager::Get()->SessionStarted();
|
| +
|
| + // Confirms that magnifier is disabled just after login.
|
| + EXPECT_FALSE(IsSpokenFeedbackEnabled());
|
| + EXPECT_FALSE(IsHighContrastEnabled());
|
| +
|
| + // Sets the pref as true to enable magnifier.
|
| + SetSpokenFeedbackEnabledToPref(true);
|
| + // Confirms that magnifier is enabled.
|
| + EXPECT_TRUE(IsSpokenFeedbackEnabled());
|
| +
|
| + // Enables magnifier.
|
| + SetHighContrastEnabled(true);
|
| + // Confirms that magnifier is enabled.
|
| + EXPECT_TRUE(IsHighContrastEnabled());
|
| +
|
| + SetSpokenFeedbackEnabledToPref(false);
|
| + EXPECT_FALSE(IsSpokenFeedbackEnabled());
|
| +
|
| + SetHighContrastEnabledToPref(false);
|
| + EXPECT_FALSE(IsHighContrastEnabled());
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, ResumeSavedPref) {
|
| + // Loads the profile of the user.
|
| + UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true);
|
| +
|
| + // Sets the pref as true to enable magnifier before login.
|
| + SetSpokenFeedbackEnabledToPref(true);
|
| + EXPECT_TRUE(IsSpokenFeedbackEnabled());
|
| +
|
| + // Sets the pref as true to enable magnifier before login.
|
| + SetHighContrastEnabledToPref(true);
|
| + EXPECT_TRUE(IsHighContrastEnabled());
|
| +
|
| + // Logs in.
|
| + UserManager::Get()->SessionStarted();
|
| +
|
| + // Confirms that magnifier is enabled just after login.
|
| + EXPECT_TRUE(IsSpokenFeedbackEnabled());
|
| + EXPECT_TRUE(IsHighContrastEnabled());
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest,
|
| + ChangingTypeInvokesNotification) {
|
| + MockAccessibilityObserver observer;
|
| +
|
| + // Logs in
|
| + UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true);
|
| + UserManager::Get()->SessionStarted();
|
| +
|
| + EXPECT_FALSE(observer.observed());
|
| + observer.reset();
|
| +
|
| + SetSpokenFeedbackEnabled(true);
|
| + EXPECT_TRUE(observer.observed());
|
| + EXPECT_TRUE(observer.observed_enabled());
|
| + EXPECT_EQ(observer.observed_type(),
|
| + chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK);
|
| + EXPECT_TRUE(IsSpokenFeedbackEnabled());
|
| +
|
| + observer.reset();
|
| + SetSpokenFeedbackEnabled(false);
|
| + EXPECT_TRUE(observer.observed());
|
| + EXPECT_FALSE(observer.observed_enabled());
|
| + EXPECT_EQ(observer.observed_type(),
|
| + chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK);
|
| + EXPECT_FALSE(IsSpokenFeedbackEnabled());
|
| +
|
| + observer.reset();
|
| + SetHighContrastEnabled(true);
|
| + EXPECT_TRUE(observer.observed());
|
| + EXPECT_TRUE(observer.observed_enabled());
|
| + EXPECT_EQ(observer.observed_type(),
|
| + chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE);
|
| + EXPECT_TRUE(IsHighContrastEnabled());
|
| +
|
| + observer.reset();
|
| + SetHighContrastEnabled(false);
|
| + EXPECT_TRUE(observer.observed());
|
| + EXPECT_FALSE(observer.observed_enabled());
|
| + EXPECT_EQ(observer.observed_type(),
|
| + chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE);
|
| + EXPECT_FALSE(IsHighContrastEnabled());
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest,
|
| + ChangingTypePrefInvokesNotification) {
|
| + MockAccessibilityObserver observer;
|
| +
|
| + // Logs in
|
| + UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true);
|
| + UserManager::Get()->SessionStarted();
|
| +
|
| + EXPECT_FALSE(observer.observed());
|
| + observer.reset();
|
| +
|
| + SetSpokenFeedbackEnabledToPref(true);
|
| + EXPECT_TRUE(observer.observed());
|
| + EXPECT_TRUE(observer.observed_enabled());
|
| + EXPECT_EQ(observer.observed_type(),
|
| + chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK);
|
| + EXPECT_TRUE(IsSpokenFeedbackEnabled());
|
| +
|
| + observer.reset();
|
| + SetSpokenFeedbackEnabledToPref(false);
|
| + EXPECT_TRUE(observer.observed());
|
| + EXPECT_FALSE(observer.observed_enabled());
|
| + EXPECT_EQ(observer.observed_type(),
|
| + chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK);
|
| + EXPECT_FALSE(IsSpokenFeedbackEnabled());
|
| +
|
| + observer.reset();
|
| + SetHighContrastEnabledToPref(true);
|
| + EXPECT_TRUE(observer.observed());
|
| + EXPECT_TRUE(observer.observed_enabled());
|
| + EXPECT_EQ(observer.observed_type(),
|
| + chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE);
|
| + EXPECT_TRUE(IsHighContrastEnabled());
|
| +
|
| + observer.reset();
|
| + SetHighContrastEnabledToPref(false);
|
| + EXPECT_TRUE(observer.observed());
|
| + EXPECT_FALSE(observer.observed_enabled());
|
| + EXPECT_EQ(observer.observed_type(),
|
| + chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE);
|
| + EXPECT_FALSE(IsHighContrastEnabled());
|
| +}
|
| +
|
| +} // namespace chromeos
|
|
|