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.
5 #include "ui/base/layout.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 #if defined(OS_CHROMEOS)
10 #include "base/command_line.h"
11 #include "ui/base/ui_base_switches.h"
16 TEST(LayoutTest
, GetScaleFactorScale
) {
17 EXPECT_FLOAT_EQ(1.0f
, GetImageScale(SCALE_FACTOR_100P
));
18 EXPECT_FLOAT_EQ(1.25f
, GetImageScale(SCALE_FACTOR_125P
));
19 EXPECT_FLOAT_EQ(1.33f
, GetImageScale(SCALE_FACTOR_133P
));
20 EXPECT_FLOAT_EQ(1.4f
, GetImageScale(SCALE_FACTOR_140P
));
21 EXPECT_FLOAT_EQ(1.5f
, GetImageScale(SCALE_FACTOR_150P
));
22 EXPECT_FLOAT_EQ(1.8f
, GetImageScale(SCALE_FACTOR_180P
));
23 EXPECT_FLOAT_EQ(2.0f
, GetImageScale(SCALE_FACTOR_200P
));
26 TEST(LayoutTest
, GetScaleFactorFromScalePartlySupported
) {
27 std::vector
<ScaleFactor
> supported_factors
;
28 supported_factors
.push_back(SCALE_FACTOR_100P
);
29 supported_factors
.push_back(SCALE_FACTOR_180P
);
30 test::ScopedSetSupportedScaleFactors
scoped_supported(supported_factors
);
31 EXPECT_EQ(SCALE_FACTOR_100P
, GetSupportedScaleFactor(0.1f
));
32 EXPECT_EQ(SCALE_FACTOR_100P
, GetSupportedScaleFactor(0.9f
));
33 EXPECT_EQ(SCALE_FACTOR_100P
, GetSupportedScaleFactor(1.0f
));
34 EXPECT_EQ(SCALE_FACTOR_100P
, GetSupportedScaleFactor(1.39f
));
35 EXPECT_EQ(SCALE_FACTOR_180P
, GetSupportedScaleFactor(1.41f
));
36 EXPECT_EQ(SCALE_FACTOR_180P
, GetSupportedScaleFactor(1.8f
));
37 EXPECT_EQ(SCALE_FACTOR_180P
, GetSupportedScaleFactor(2.0f
));
38 EXPECT_EQ(SCALE_FACTOR_180P
, GetSupportedScaleFactor(999.0f
));
41 TEST(LayoutTest
, GetScaleFactorFromScaleAllSupported
) {
42 std::vector
<ScaleFactor
> supported_factors
;
43 for (int factor
= SCALE_FACTOR_100P
; factor
< NUM_SCALE_FACTORS
; ++factor
) {
44 supported_factors
.push_back(static_cast<ScaleFactor
>(factor
));
46 test::ScopedSetSupportedScaleFactors
scoped_supported(supported_factors
);
48 EXPECT_EQ(SCALE_FACTOR_100P
, GetSupportedScaleFactor(0.1f
));
49 EXPECT_EQ(SCALE_FACTOR_100P
, GetSupportedScaleFactor(0.9f
));
50 EXPECT_EQ(SCALE_FACTOR_100P
, GetSupportedScaleFactor(1.0f
));
51 EXPECT_EQ(SCALE_FACTOR_125P
, GetSupportedScaleFactor(1.19f
));
52 EXPECT_EQ(SCALE_FACTOR_125P
, GetSupportedScaleFactor(1.21f
));
53 EXPECT_EQ(SCALE_FACTOR_133P
, GetSupportedScaleFactor(1.291f
));
54 EXPECT_EQ(SCALE_FACTOR_133P
, GetSupportedScaleFactor(1.3f
));
55 EXPECT_EQ(SCALE_FACTOR_140P
, GetSupportedScaleFactor(1.4f
));
56 EXPECT_EQ(SCALE_FACTOR_150P
, GetSupportedScaleFactor(1.59f
));
57 EXPECT_EQ(SCALE_FACTOR_150P
, GetSupportedScaleFactor(1.61f
));
58 EXPECT_EQ(SCALE_FACTOR_180P
, GetSupportedScaleFactor(1.7f
));
59 EXPECT_EQ(SCALE_FACTOR_180P
, GetSupportedScaleFactor(1.89f
));
60 EXPECT_EQ(SCALE_FACTOR_200P
, GetSupportedScaleFactor(1.91f
));
61 EXPECT_EQ(SCALE_FACTOR_200P
, GetSupportedScaleFactor(2.0f
));
62 EXPECT_EQ(SCALE_FACTOR_200P
, GetSupportedScaleFactor(2.1f
));
63 EXPECT_EQ(SCALE_FACTOR_200P
, GetSupportedScaleFactor(999.0f
));