1 // Copyright (c) 2012 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 "ui/base/layout.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 #if defined(OS_CHROMEOS)
10 #include "base/command_line.h"
11 #include "ui/base/ui_base_switches.h"
12 #endif
13
14 namespace ui {
15
TEST(LayoutTest,GetScaleFactorScale)16 TEST(LayoutTest, GetScaleFactorScale) {
17 EXPECT_FLOAT_EQ(1.0f, GetScaleForScaleFactor(SCALE_FACTOR_100P));
18 EXPECT_FLOAT_EQ(1.25f, GetScaleForScaleFactor(SCALE_FACTOR_125P));
19 EXPECT_FLOAT_EQ(1.33f, GetScaleForScaleFactor(SCALE_FACTOR_133P));
20 EXPECT_FLOAT_EQ(1.4f, GetScaleForScaleFactor(SCALE_FACTOR_140P));
21 EXPECT_FLOAT_EQ(1.5f, GetScaleForScaleFactor(SCALE_FACTOR_150P));
22 EXPECT_FLOAT_EQ(1.8f, GetScaleForScaleFactor(SCALE_FACTOR_180P));
23 EXPECT_FLOAT_EQ(2.0f, GetScaleForScaleFactor(SCALE_FACTOR_200P));
24 EXPECT_FLOAT_EQ(2.5f, GetScaleForScaleFactor(SCALE_FACTOR_250P));
25 EXPECT_FLOAT_EQ(3.0f, GetScaleForScaleFactor(SCALE_FACTOR_300P));
26 }
27
TEST(LayoutTest,GetScaleFactorFromScalePartlySupported)28 TEST(LayoutTest, GetScaleFactorFromScalePartlySupported) {
29 std::vector<ScaleFactor> supported_factors;
30 supported_factors.push_back(SCALE_FACTOR_100P);
31 supported_factors.push_back(SCALE_FACTOR_180P);
32 test::ScopedSetSupportedScaleFactors scoped_supported(supported_factors);
33 EXPECT_EQ(SCALE_FACTOR_100P, GetSupportedScaleFactor(0.1f));
34 EXPECT_EQ(SCALE_FACTOR_100P, GetSupportedScaleFactor(0.9f));
35 EXPECT_EQ(SCALE_FACTOR_100P, GetSupportedScaleFactor(1.0f));
36 EXPECT_EQ(SCALE_FACTOR_100P, GetSupportedScaleFactor(1.39f));
37 EXPECT_EQ(SCALE_FACTOR_180P, GetSupportedScaleFactor(1.41f));
38 EXPECT_EQ(SCALE_FACTOR_180P, GetSupportedScaleFactor(1.8f));
39 EXPECT_EQ(SCALE_FACTOR_180P, GetSupportedScaleFactor(2.0f));
40 EXPECT_EQ(SCALE_FACTOR_180P, GetSupportedScaleFactor(999.0f));
41 }
42
TEST(LayoutTest,GetScaleFactorFromScaleAllSupported)43 TEST(LayoutTest, GetScaleFactorFromScaleAllSupported) {
44 std::vector<ScaleFactor> supported_factors;
45 for (int factor = SCALE_FACTOR_100P; factor < NUM_SCALE_FACTORS; ++factor) {
46 supported_factors.push_back(static_cast<ScaleFactor>(factor));
47 }
48 test::ScopedSetSupportedScaleFactors scoped_supported(supported_factors);
49
50 EXPECT_EQ(SCALE_FACTOR_100P, GetSupportedScaleFactor(0.1f));
51 EXPECT_EQ(SCALE_FACTOR_100P, GetSupportedScaleFactor(0.9f));
52 EXPECT_EQ(SCALE_FACTOR_100P, GetSupportedScaleFactor(1.0f));
53 EXPECT_EQ(SCALE_FACTOR_125P, GetSupportedScaleFactor(1.19f));
54 EXPECT_EQ(SCALE_FACTOR_125P, GetSupportedScaleFactor(1.21f));
55 EXPECT_EQ(SCALE_FACTOR_133P, GetSupportedScaleFactor(1.291f));
56 EXPECT_EQ(SCALE_FACTOR_133P, GetSupportedScaleFactor(1.3f));
57 EXPECT_EQ(SCALE_FACTOR_140P, GetSupportedScaleFactor(1.4f));
58 EXPECT_EQ(SCALE_FACTOR_150P, GetSupportedScaleFactor(1.59f));
59 EXPECT_EQ(SCALE_FACTOR_150P, GetSupportedScaleFactor(1.61f));
60 EXPECT_EQ(SCALE_FACTOR_180P, GetSupportedScaleFactor(1.7f));
61 EXPECT_EQ(SCALE_FACTOR_180P, GetSupportedScaleFactor(1.89f));
62 EXPECT_EQ(SCALE_FACTOR_200P, GetSupportedScaleFactor(1.91f));
63 EXPECT_EQ(SCALE_FACTOR_200P, GetSupportedScaleFactor(2.0f));
64 EXPECT_EQ(SCALE_FACTOR_200P, GetSupportedScaleFactor(2.1f));
65 EXPECT_EQ(SCALE_FACTOR_250P, GetSupportedScaleFactor(2.3f));
66 EXPECT_EQ(SCALE_FACTOR_250P, GetSupportedScaleFactor(2.5f));
67 EXPECT_EQ(SCALE_FACTOR_250P, GetSupportedScaleFactor(2.6f));
68 EXPECT_EQ(SCALE_FACTOR_300P, GetSupportedScaleFactor(2.9f));
69 EXPECT_EQ(SCALE_FACTOR_300P, GetSupportedScaleFactor(3.0f));
70 EXPECT_EQ(SCALE_FACTOR_300P, GetSupportedScaleFactor(3.1f));
71 EXPECT_EQ(SCALE_FACTOR_300P, GetSupportedScaleFactor(999.0f));
72 }
73
74 } // namespace ui
75