OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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/accessibility/font_size_prefs.h" |
| 6 |
| 7 #include "chrome/test/base/testing_profile.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 |
| 10 class FontSizePrefsTest : public testing::Test { |
| 11 protected: |
| 12 virtual void SetUp() OVERRIDE { |
| 13 profile_.reset(new TestingProfile()); |
| 14 font_size_prefs_.reset(new FontSizePrefs(profile_.get())); |
| 15 } |
| 16 scoped_ptr<TestingProfile> profile_; |
| 17 scoped_ptr<FontSizePrefs> font_size_prefs_; |
| 18 }; |
| 19 |
| 20 class TestingObserver : public FontSizePrefs::Observer { |
| 21 public: |
| 22 TestingObserver() : font_scale_factor_(1), force_enable_zoom_(false) {} |
| 23 |
| 24 virtual void OnChangeFontSize(float font) OVERRIDE { |
| 25 font_scale_factor_ = font; |
| 26 } |
| 27 |
| 28 virtual void OnChangeForceEnableZoom(bool enabled) OVERRIDE { |
| 29 force_enable_zoom_ = enabled; |
| 30 } |
| 31 |
| 32 float GetFontScaleFactor() { return font_scale_factor_; } |
| 33 bool GetForceEnableZoom() { return force_enable_zoom_; } |
| 34 |
| 35 private: |
| 36 float font_scale_factor_; |
| 37 bool force_enable_zoom_; |
| 38 }; |
| 39 |
| 40 TEST_F(FontSizePrefsTest, TestingSetFontSizeSingleObserver) { |
| 41 TestingObserver obs; |
| 42 font_size_prefs_->AddObserver(&obs); |
| 43 EXPECT_EQ(1, obs.GetFontScaleFactor()); |
| 44 |
| 45 font_size_prefs_->SetFontScaleFactor(1.2f); |
| 46 EXPECT_EQ(1.2f, obs.GetFontScaleFactor()); |
| 47 EXPECT_EQ(1.2f, font_size_prefs_->GetFontScaleFactor()); |
| 48 |
| 49 font_size_prefs_->RemoveObserver(&obs); |
| 50 } |
| 51 |
| 52 TEST_F(FontSizePrefsTest, TestingSetForceEnableZoomSingleObserver) { |
| 53 TestingObserver obs; |
| 54 font_size_prefs_->AddObserver(&obs); |
| 55 EXPECT_EQ(false, obs.GetForceEnableZoom()); |
| 56 |
| 57 font_size_prefs_->SetForceEnableZoom(true); |
| 58 EXPECT_EQ(true, font_size_prefs_->GetForceEnableZoom()); |
| 59 EXPECT_EQ(true, obs.GetForceEnableZoom()); |
| 60 |
| 61 font_size_prefs_->RemoveObserver(&obs); |
| 62 } |
| 63 |
| 64 TEST_F(FontSizePrefsTest, TestingMultipleObserversFontSize) { |
| 65 TestingObserver obs1; |
| 66 font_size_prefs_->AddObserver(&obs1); |
| 67 TestingObserver obs2; |
| 68 font_size_prefs_->AddObserver(&obs2); |
| 69 |
| 70 font_size_prefs_->SetFontScaleFactor(1.2f); |
| 71 EXPECT_EQ(1.2f, obs1.GetFontScaleFactor()); |
| 72 EXPECT_EQ(1.2f, obs2.GetFontScaleFactor()); |
| 73 |
| 74 font_size_prefs_->RemoveObserver(&obs1); |
| 75 font_size_prefs_->SetFontScaleFactor(1.4f); |
| 76 EXPECT_EQ(1.2f, obs1.GetFontScaleFactor()); |
| 77 EXPECT_EQ(1.4f, obs2.GetFontScaleFactor()); |
| 78 |
| 79 font_size_prefs_->RemoveObserver(&obs2); |
| 80 } |
| 81 |
| 82 TEST_F(FontSizePrefsTest, TestingMultipleObserversForceEnableZoom) { |
| 83 TestingObserver obs1; |
| 84 font_size_prefs_->AddObserver(&obs1); |
| 85 TestingObserver obs2; |
| 86 font_size_prefs_->AddObserver(&obs2); |
| 87 |
| 88 font_size_prefs_->SetForceEnableZoom(true); |
| 89 EXPECT_EQ(true, obs1.GetForceEnableZoom()); |
| 90 EXPECT_EQ(true, obs2.GetForceEnableZoom()); |
| 91 |
| 92 font_size_prefs_->RemoveObserver(&obs1); |
| 93 font_size_prefs_->SetForceEnableZoom(false); |
| 94 EXPECT_EQ(true, obs1.GetForceEnableZoom()); |
| 95 EXPECT_EQ(false, obs2.GetForceEnableZoom()); |
| 96 |
| 97 font_size_prefs_->RemoveObserver(&obs2); |
| 98 } |
OLD | NEW |