Home | History | Annotate | Download | only in accessibility
      1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/browser/chromeos/accessibility/magnification_manager.h"
      6 
      7 #include "ash/magnifier/magnifier_constants.h"
      8 #include "ash/test/ash_test_base.h"
      9 #include "base/prefs/pref_service.h"
     10 #include "chrome/common/pref_names.h"
     11 #include "chrome/test/base/testing_profile.h"
     12 #include "testing/gtest/include/gtest/gtest.h"
     13 
     14 namespace chromeos {
     15 namespace {
     16 
     17 void EnableMagnifier() {
     18   return MagnificationManager::Get()->SetMagnifierEnabled(true);
     19 }
     20 
     21 void DisableMagnifier() {
     22   return MagnificationManager::Get()->SetMagnifierEnabled(false);
     23 }
     24 
     25 bool IsMagnifierEnabled() {
     26   return MagnificationManager::Get()->IsMagnifierEnabled();
     27 }
     28 
     29 ash::MagnifierType GetMagnifierType() {
     30   return MagnificationManager::Get()->GetMagnifierType();
     31 }
     32 
     33 void SetMagnifierType(ash::MagnifierType type) {
     34   return MagnificationManager::Get()->SetMagnifierType(type);
     35 }
     36 
     37 }  // namespace
     38 
     39 class MagnificationManagerTest : public ash::test::AshTestBase {
     40  public:
     41   MagnificationManagerTest() {
     42   }
     43 
     44   virtual void SetUp() OVERRIDE {
     45     ash::test::AshTestBase::SetUp();
     46     MagnificationManager::Initialize();
     47     ASSERT_TRUE(MagnificationManager::Get());
     48     MagnificationManager::Get()->SetProfileForTest(&profile_);
     49   }
     50 
     51   virtual void TearDown() OVERRIDE {
     52     MagnificationManager::Shutdown();
     53     ash::test::AshTestBase::TearDown();
     54   }
     55 
     56   TestingProfile profile_;
     57 };
     58 
     59 TEST_F(MagnificationManagerTest, ChangeType) {
     60   // Set full screen magnifier, and confirm the status is set successfully.
     61   EnableMagnifier();
     62   SetMagnifierType(ash::MAGNIFIER_FULL);
     63   EXPECT_TRUE(IsMagnifierEnabled());
     64   EXPECT_EQ(GetMagnifierType(), ash::MAGNIFIER_FULL);
     65 
     66   // Set partial screen magnifier, and confirm the change is ignored.
     67   SetMagnifierType(ash::MAGNIFIER_PARTIAL);
     68   EXPECT_TRUE(IsMagnifierEnabled());
     69   EXPECT_EQ(GetMagnifierType(), ash::MAGNIFIER_FULL);
     70 
     71   // Disables magnifier, and confirm the status is set successfully.
     72   DisableMagnifier();
     73   EXPECT_FALSE(IsMagnifierEnabled());
     74   EXPECT_EQ(GetMagnifierType(), ash::MAGNIFIER_FULL);
     75 }
     76 
     77 }  // namespace chromeos
     78