This source file includes following definitions.
- SetMagnifierEnabled
 
- SetMagnifierType
 
- SetFullScreenMagnifierScale
 
- GetFullScreenMagnifierScale
 
- SetSavedFullScreenMagnifierScale
 
- GetSavedFullScreenMagnifierScale
 
- GetMagnifierType
 
- IsMagnifierEnabled
 
- profile
 
- prefs
 
- SetScreenMagnifierEnabledPref
 
- SetScreenMagnifierTypePref
 
- SetFullScreenMagnifierScalePref
 
- GetScreenMagnifierEnabledFromPref
 
- PrepareNonNewProfile
 
- magnifier_type_
 
- observed
 
- observed_enabled
 
- magnifier_type
 
- reset
 
- OnAccessibilityStatusChanged
 
- SetUpCommandLine
 
- SetUpOnMainThread
 
- 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
 
- 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/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/chrome_notification_types.h"
#include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
#include "chrome/browser/chromeos/accessibility/magnification_manager.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_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/testing_profile.h"
#include "chromeos/chromeos_switches.h"
#include "components/user_prefs/user_prefs.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_service.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chromeos {
namespace {
const char kTestUserName[] = "owner@invalid.domain";
void SetMagnifierEnabled(bool enabled) {
  MagnificationManager::Get()->SetMagnifierEnabled(enabled);
}
void SetMagnifierType(ash::MagnifierType type) {
  MagnificationManager::Get()->SetMagnifierType(type);
}
void SetFullScreenMagnifierScale(double scale) {
  ash::Shell::GetInstance()->
      magnification_controller()->SetScale(scale, false);
}
double GetFullScreenMagnifierScale() {
  return ash::Shell::GetInstance()->magnification_controller()->GetScale();
}
void SetSavedFullScreenMagnifierScale(double scale) {
  MagnificationManager::Get()->SaveScreenMagnifierScale(scale);
}
double GetSavedFullScreenMagnifierScale() {
  return MagnificationManager::Get()->GetSavedScreenMagnifierScale();
}
ash::MagnifierType GetMagnifierType() {
  return MagnificationManager::Get()->GetMagnifierType();
}
bool IsMagnifierEnabled() {
  return MagnificationManager::Get()->IsMagnifierEnabled();
}
Profile* profile() {
  Profile* profile = ProfileManager::GetActiveUserProfile();
  DCHECK(profile);
  return profile;
}
PrefService* prefs() {
  return user_prefs::UserPrefs::Get(profile());
}
void SetScreenMagnifierEnabledPref(bool enabled) {
  prefs()->SetBoolean(prefs::kScreenMagnifierEnabled, enabled);
}
void SetScreenMagnifierTypePref(ash::MagnifierType type) {
  prefs()->SetInteger(prefs::kScreenMagnifierType, type);
}
void SetFullScreenMagnifierScalePref(double scale) {
  prefs()->SetDouble(prefs::kScreenMagnifierScale, scale);
}
bool GetScreenMagnifierEnabledFromPref() {
  return prefs()->GetBoolean(prefs::kScreenMagnifierEnabled);
}
void PrepareNonNewProfile(const std::string& name) {
  UserManager::Get()->UserLoggedIn(name, name, true);
  
  
  
  
  ProfileManager::GetActiveUserProfile();
}
}  
class MockMagnificationObserver {
 public:
  MockMagnificationObserver() : observed_(false),
                                observed_enabled_(false),
                                magnifier_type_(-1)
  {
    AccessibilityManager* accessibility_manager = AccessibilityManager::Get();
    CHECK(accessibility_manager);
    accessibility_subscription_ = accessibility_manager->RegisterCallback(
        base::Bind(&MockMagnificationObserver::OnAccessibilityStatusChanged,
                   base::Unretained(this)));
  }
  virtual ~MockMagnificationObserver() {}
  bool observed() const { return observed_; }
  bool observed_enabled() const { return observed_enabled_; }
  int magnifier_type() const { return magnifier_type_; }
  void reset() { observed_ = false; }
 private:
  void OnAccessibilityStatusChanged(
      const AccessibilityStatusEventDetails& details) {
    if (details.notification_type == ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFIER) {
      magnifier_type_ = details.magnifier_type;
      observed_enabled_ = details.enabled;
      observed_ = true;
    }
  }
  bool observed_;
  bool observed_enabled_;
  int magnifier_type_;
  scoped_ptr<AccessibilityStatusSubscription> accessibility_subscription_;
  DISALLOW_COPY_AND_ASSIGN(MockMagnificationObserver);
};
class MagnificationManagerTest : public InProcessBrowserTest {
 protected:
  MagnificationManagerTest() {}
  virtual ~MagnificationManagerTest() {}
  virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
    command_line->AppendSwitch(switches::kLoginManager);
    command_line->AppendSwitchASCII(switches::kLoginProfile,
                                    TestingProfile::kTestUserProfileDir);
  }
  virtual void SetUpOnMainThread() OVERRIDE {
    
    MagnificationManager::Get()->SetProfileForTest(
        ProfileManager::GetActiveUserProfile());
  }
  DISALLOW_COPY_AND_ASSIGN(MagnificationManagerTest);
};
IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, PRE_LoginOffToOff) {
  
  PrepareNonNewProfile(kTestUserName);
  
  SetScreenMagnifierEnabledPref(false);
}
IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, LoginOffToOff) {
  
  EXPECT_FALSE(IsMagnifierEnabled());
  
  SetMagnifierEnabled(false);
  EXPECT_FALSE(IsMagnifierEnabled());
  
  UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true);
  
  EXPECT_FALSE(IsMagnifierEnabled());
  UserManager::Get()->SessionStarted();
  
  EXPECT_FALSE(IsMagnifierEnabled());
  
  SetMagnifierEnabled(true);
  
  EXPECT_TRUE(IsMagnifierEnabled());
  EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType());
  EXPECT_TRUE(GetScreenMagnifierEnabledFromPref());
}
IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, PRE_LoginFullToOff) {
  
  PrepareNonNewProfile(kTestUserName);
  
  SetScreenMagnifierEnabledPref(false);
}
IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, LoginFullToOff) {
  
  EXPECT_FALSE(IsMagnifierEnabled());
  
  SetMagnifierEnabled(true);
  SetMagnifierType(ash::MAGNIFIER_FULL);
  SetFullScreenMagnifierScale(2.5);
  EXPECT_TRUE(IsMagnifierEnabled());
  EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType());
  EXPECT_EQ(2.5, GetFullScreenMagnifierScale());
  
  UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true);
  
  EXPECT_TRUE(IsMagnifierEnabled());
  EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType());
  UserManager::Get()->SessionStarted();
  
  EXPECT_FALSE(IsMagnifierEnabled());
  EXPECT_FALSE(GetScreenMagnifierEnabledFromPref());
}
IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, PRE_LoginOffToFull) {
  
  PrepareNonNewProfile(kTestUserName);
  
  SetScreenMagnifierEnabledPref(true);
  SetScreenMagnifierTypePref(ash::MAGNIFIER_FULL);
  SetFullScreenMagnifierScalePref(2.5);
}
IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, LoginOffToFull) {
  
  SetMagnifierEnabled(false);
  EXPECT_FALSE(IsMagnifierEnabled());
  
  UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true);
  
  EXPECT_FALSE(IsMagnifierEnabled());
  UserManager::Get()->SessionStarted();
  
  
  EXPECT_TRUE(IsMagnifierEnabled());
  EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType());
  EXPECT_EQ(2.5, GetFullScreenMagnifierScale());
  EXPECT_TRUE(GetScreenMagnifierEnabledFromPref());
}
IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, PRE_LoginFullToFull) {
  
  PrepareNonNewProfile(kTestUserName);
  
  SetScreenMagnifierEnabledPref(true);
  SetScreenMagnifierTypePref(ash::MAGNIFIER_FULL);
  SetFullScreenMagnifierScalePref(2.5);
}
IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, LoginFullToFull) {
  
  SetMagnifierType(ash::MAGNIFIER_FULL);
  SetMagnifierEnabled(true);
  SetFullScreenMagnifierScale(3.0);
  EXPECT_TRUE(IsMagnifierEnabled());
  EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType());
  EXPECT_EQ(3.0, GetFullScreenMagnifierScale());
  
  UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true);
  
  EXPECT_TRUE(IsMagnifierEnabled());
  EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType());
  UserManager::Get()->SessionStarted();
  
  
  EXPECT_TRUE(IsMagnifierEnabled());
  EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType());
  EXPECT_EQ(2.5, GetFullScreenMagnifierScale());
  EXPECT_TRUE(GetScreenMagnifierEnabledFromPref());
}
IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, PRE_LoginFullToUnset) {
  
  PrepareNonNewProfile(kTestUserName);
}
IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, LoginFullToUnset) {
  
  SetMagnifierType(ash::MAGNIFIER_FULL);
  SetMagnifierEnabled(true);
  EXPECT_TRUE(IsMagnifierEnabled());
  EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType());
  
  UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true);
  
  EXPECT_TRUE(IsMagnifierEnabled());
  EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType());
  UserManager::Get()->SessionStarted();
  
  EXPECT_FALSE(IsMagnifierEnabled());
  EXPECT_FALSE(GetScreenMagnifierEnabledFromPref());
}
IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, LoginAsNewUserOff) {
  
  EXPECT_FALSE(IsMagnifierEnabled());
  
  SetMagnifierEnabled(false);
  
  UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true);
  
  EXPECT_FALSE(IsMagnifierEnabled());
  UserManager::Get()->SessionStarted();
  
  EXPECT_FALSE(IsMagnifierEnabled());
  EXPECT_FALSE(GetScreenMagnifierEnabledFromPref());
}
IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, LoginAsNewUserFull) {
  
  SetMagnifierType(ash::MAGNIFIER_FULL);
  SetMagnifierEnabled(true);
  SetFullScreenMagnifierScale(2.5);
  EXPECT_TRUE(IsMagnifierEnabled());
  EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType());
  EXPECT_EQ(2.5, GetFullScreenMagnifierScale());
  
  UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true);
  
  EXPECT_TRUE(IsMagnifierEnabled());
  EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType());
  UserManager::Get()->SessionStarted();
  
  EXPECT_TRUE(IsMagnifierEnabled());
  EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType());
  EXPECT_EQ(2.5, GetFullScreenMagnifierScale());
  EXPECT_TRUE(GetScreenMagnifierEnabledFromPref());
}
IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, LoginAsNewUserUnset) {
  
  EXPECT_FALSE(IsMagnifierEnabled());
  
  UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true);
  
  EXPECT_FALSE(IsMagnifierEnabled());
  UserManager::Get()->SessionStarted();
  
  EXPECT_FALSE(IsMagnifierEnabled());
  EXPECT_FALSE(GetScreenMagnifierEnabledFromPref());
}
IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, ChangeMagnifierType) {
  
  SetMagnifierEnabled(false);
  SetMagnifierType(ash::MAGNIFIER_FULL);
  EXPECT_FALSE(IsMagnifierEnabled());
  EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType());
  SetMagnifierEnabled(true);
  EXPECT_TRUE(IsMagnifierEnabled());
  EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType());
  SetMagnifierEnabled(false);
  EXPECT_FALSE(IsMagnifierEnabled());
  EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType());
  
  SetMagnifierType(ash::MAGNIFIER_PARTIAL);
  EXPECT_FALSE(IsMagnifierEnabled());
  EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType());
  SetMagnifierEnabled(true);
  EXPECT_TRUE(IsMagnifierEnabled());
  EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType());
  SetMagnifierEnabled(false);
  EXPECT_FALSE(IsMagnifierEnabled());
  EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType());
  
  SetMagnifierType(ash::MAGNIFIER_FULL);
  SetMagnifierEnabled(true);
  EXPECT_TRUE(IsMagnifierEnabled());
  EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType());
  SetMagnifierType(ash::MAGNIFIER_PARTIAL);
  EXPECT_TRUE(IsMagnifierEnabled());
  EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType());
  SetMagnifierType(ash::MAGNIFIER_FULL);
  EXPECT_TRUE(IsMagnifierEnabled());
  EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType());
  
  SetMagnifierEnabled(false);
  SetMagnifierType(ash::MAGNIFIER_FULL);
  EXPECT_FALSE(IsMagnifierEnabled());
  EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType());
  SetMagnifierType(ash::MAGNIFIER_PARTIAL);
  EXPECT_FALSE(IsMagnifierEnabled());
  EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType());
  SetMagnifierType(ash::MAGNIFIER_FULL);
  EXPECT_FALSE(IsMagnifierEnabled());
  EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType());
}
IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, TypePref) {
  
  UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true);
  UserManager::Get()->SessionStarted();
  
  EXPECT_FALSE(IsMagnifierEnabled());
  
  SetScreenMagnifierTypePref(ash::MAGNIFIER_FULL);
  SetScreenMagnifierEnabledPref(true);
  
  EXPECT_TRUE(IsMagnifierEnabled());
  EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType());
}
IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, ScalePref) {
  SetMagnifierEnabled(false);
  EXPECT_FALSE(IsMagnifierEnabled());
  
  SetSavedFullScreenMagnifierScale(2.5);
  
  SetMagnifierType(ash::MAGNIFIER_FULL);
  SetMagnifierEnabled(true);
  EXPECT_TRUE(IsMagnifierEnabled());
  EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType());
  
  EXPECT_EQ(2.5, GetFullScreenMagnifierScale());
  
  SetFullScreenMagnifierScale(3.0);
  EXPECT_EQ(3.0, GetSavedFullScreenMagnifierScale());
}
IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, InvalidScalePref) {
  
  SetMagnifierEnabled(false);
  EXPECT_FALSE(IsMagnifierEnabled());
  
  SetSavedFullScreenMagnifierScale(0.5);
  
  SetMagnifierType(ash::MAGNIFIER_FULL);
  SetMagnifierEnabled(true);
  EXPECT_TRUE(IsMagnifierEnabled());
  EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType());
  
  EXPECT_EQ(1.0, GetFullScreenMagnifierScale());
  
  SetMagnifierEnabled(false);
  EXPECT_FALSE(IsMagnifierEnabled());
  
  SetSavedFullScreenMagnifierScale(50.0);
  
  SetMagnifierEnabled(true);
  EXPECT_TRUE(IsMagnifierEnabled());
  EXPECT_EQ(ash::MAGNIFIER_FULL, GetMagnifierType());
  
  EXPECT_EQ(4.0, GetFullScreenMagnifierScale());
}
IN_PROC_BROWSER_TEST_F(MagnificationManagerTest,
                       ChangingTypeInvokesNotification) {
  MockMagnificationObserver observer;
  EXPECT_FALSE(observer.observed());
  
  SetMagnifierEnabled(true);
  SetMagnifierType(ash::MAGNIFIER_FULL);
  EXPECT_TRUE(observer.observed());
  EXPECT_TRUE(observer.observed_enabled());
  EXPECT_EQ(observer.magnifier_type(), ash::MAGNIFIER_FULL);
  EXPECT_EQ(GetMagnifierType(), ash::MAGNIFIER_FULL);
  observer.reset();
  
  SetMagnifierType(ash::MAGNIFIER_FULL);
  EXPECT_FALSE(observer.observed());
  EXPECT_EQ(GetMagnifierType(), ash::MAGNIFIER_FULL);
  observer.reset();
}
}