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_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 TEST_F(ClientHintsTest, HintsWellFormattedWithNonEnLocale) { | |
32 #if !defined(OS_ANDROID) && !defined(OS_IOS) | |
33 // Android and iOS do not support setLocal. | |
Avi (use Gerrit)
2013/09/30 17:35:55
Without ScopedLocale, this test is meaningless (an
bengr
2013/09/30 17:42:23
Done.
| |
34 base::ScopedLocale locale("fr_FR.UTF-8"); | |
35 #endif | |
36 UpdateScreenInfo(1.567f); | |
37 std::string hint = client_hints_.GetDevicePixelRatioHeader(); | |
38 EXPECT_EQ("1.57", hint); | |
39 } | |
40 | |
41 TEST_F(ClientHintsTest, HintsHaveNonbogusValues) { | |
42 UpdateScreenInfo(-1.567f); | |
43 std::string hint = client_hints_.GetDevicePixelRatioHeader(); | |
44 EXPECT_EQ("", hint); | |
45 | |
46 UpdateScreenInfo(1.567f); | |
47 hint = client_hints_.GetDevicePixelRatioHeader(); | |
48 EXPECT_EQ("1.57", hint); | |
49 | |
50 UpdateScreenInfo(0.0f); | |
51 hint = client_hints_.GetDevicePixelRatioHeader(); | |
52 // Hints should be last known good values. | |
53 EXPECT_EQ("1.57", hint); | |
54 } | |
55 | |
OLD | NEW |