- add sources.
[platform/framework/web/crosswalk.git] / src / ui / base / l10n / l10n_util_win_unittest.cc
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 "ui/base/l10n/l10n_util_win.h"
6
7 #include <windows.h>
8
9 #include "base/win/win_util.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "testing/platform_test.h"
12 #include "ui/gfx/win/dpi.h"
13
14 typedef PlatformTest L10nUtilWinTest;
15
16 TEST_F(L10nUtilWinTest, TestDPIScaling) {
17   // Baseline font for comparison.
18   NONCLIENTMETRICS metrics;
19   base::win::GetNonClientMetrics(&metrics);
20   LOGFONT lf = metrics.lfMessageFont;
21   l10n_util::AdjustUIFont(&lf);
22   int size = lf.lfHeight;
23   float rounding = size < 0 ? -0.5f : 0.5f;
24
25   // Test that font size is properly normalized for DIP. In high-DPI mode, the
26   // font metrics are scaled based on the DPI scale factor. For Windows 8, 140%
27   // and 180% font scaling are supported. Simulate size normalization for a DPI-
28   // aware process by manually scaling up the font and checking that it returns
29   // to the expected size.
30   lf.lfHeight = static_cast<int>(1.4 * size + rounding);
31   l10n_util::AdjustUIFontForDIP(1.4f, &lf);
32   EXPECT_NEAR(size, lf.lfHeight, 1);
33
34   lf.lfHeight = static_cast<int>(1.8 * size + rounding);
35   l10n_util::AdjustUIFontForDIP(1.8f, &lf);
36   EXPECT_NEAR(size, lf.lfHeight, 1);
37 }