1 // Copyright 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.
5 #include "chrome/browser/net/client_hints.h"
9 #include "base/logging.h"
10 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_IOS)
11 #include "base/test/scoped_locale.h"
13 #include "testing/gtest/include/gtest/gtest.h"
15 class ClientHintsTest
: public testing::Test
{
17 void UpdateScreenInfo(float pixel_ratio
) {
18 client_hints_
.UpdateScreenInfo(pixel_ratio
);
22 ClientHints client_hints_
;
25 TEST_F(ClientHintsTest
, HintsWellFormatted
) {
26 UpdateScreenInfo(1.567f
);
27 std::string hint
= client_hints_
.GetDevicePixelRatioHeader();
28 EXPECT_EQ("1.57", hint
);
31 // Android and iOS do not support setLocale.
32 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_IOS)
33 // TODO(bengr): Use ScopedLocal in Windows once it is supported.
34 TEST_F(ClientHintsTest
, HintsWellFormattedWithNonEnLocale
) {
35 base::ScopedLocale
locale("fr_FR.UTF-8");
36 UpdateScreenInfo(1.567f
);
37 std::string hint
= client_hints_
.GetDevicePixelRatioHeader();
38 EXPECT_EQ("1.57", hint
);
40 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_IOS)
42 TEST_F(ClientHintsTest
, HintsHaveNonbogusValues
) {
43 UpdateScreenInfo(-1.567f
);
44 std::string hint
= client_hints_
.GetDevicePixelRatioHeader();
47 UpdateScreenInfo(1.567f
);
48 hint
= client_hints_
.GetDevicePixelRatioHeader();
49 EXPECT_EQ("1.57", hint
);
51 UpdateScreenInfo(0.0f
);
52 hint
= client_hints_
.GetDevicePixelRatioHeader();
53 // Hints should be last known good values.
54 EXPECT_EQ("1.57", hint
);