OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "chrome/browser/net/client_hints.h" | |
6 | |
7 #include <locale.h> | |
8 | |
9 #include "base/logging.h" | |
10 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_IOS) | |
11 #include "base/test/scoped_locale.h" | |
12 #endif | |
13 #include "testing/gtest/include/gtest/gtest.h" | |
14 | |
15 class ClientHintsTest : public testing::Test { | |
16 public: | |
17 void UpdateScreenInfo(float pixel_ratio) { | |
18 client_hints_.UpdateScreenInfo(pixel_ratio); | |
19 }; | |
20 | |
21 protected: | |
22 ClientHints client_hints_; | |
23 }; | |
24 | |
25 TEST_F(ClientHintsTest, HintsWellFormatted) { | |
26 UpdateScreenInfo(1.567f); | |
27 std::string hint = client_hints_.GetDevicePixelRatioHeader(); | |
28 EXPECT_EQ("1.57", hint); | |
29 } | |
30 | |
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); | |
39 } | |
40 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_IOS) | |
41 | |
42 TEST_F(ClientHintsTest, HintsHaveNonbogusValues) { | |
43 UpdateScreenInfo(-1.567f); | |
44 std::string hint = client_hints_.GetDevicePixelRatioHeader(); | |
45 EXPECT_EQ("", hint); | |
46 | |
47 UpdateScreenInfo(1.567f); | |
48 hint = client_hints_.GetDevicePixelRatioHeader(); | |
49 EXPECT_EQ("1.57", hint); | |
50 | |
51 UpdateScreenInfo(0.0f); | |
52 hint = client_hints_.GetDevicePixelRatioHeader(); | |
53 // Hints should be last known good values. | |
54 EXPECT_EQ("1.57", hint); | |
55 } | |
56 | |
OLD | NEW |