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 #include "base/memory/scoped_ptr.h" | |
Lei Zhang
2013/09/25 20:36:32
nit: not used
bengr
2013/09/25 21:39:45
Done.
| |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 | |
13 class ClientHintsTest : public testing::Test { | |
14 public: | |
15 void UpdateScreenInfo(float pixel_ratio) { | |
16 client_hints_.UpdateScreenInfo(pixel_ratio); | |
17 }; | |
18 | |
19 protected: | |
20 ClientHints client_hints_; | |
21 }; | |
22 | |
23 TEST_F(ClientHintsTest, HintsWellFormatted) { | |
24 UpdateScreenInfo(1.567f); | |
25 std::string hint = client_hints_.GetDevicePixelRatioHeader(); | |
26 EXPECT_EQ("1.57", hint); | |
27 } | |
28 | |
29 TEST_F(ClientHintsTest, HintsWellFormattedWithNonEnLocale) { | |
30 setlocale(LC_ALL, "fr_FR.UTF-8"); | |
31 UpdateScreenInfo(1.567f); | |
32 std::string hint = client_hints_.GetDevicePixelRatioHeader(); | |
33 EXPECT_EQ("1.57", hint); | |
34 } | |
35 | |
36 TEST_F(ClientHintsTest, HintsHaveNonbogusValues) { | |
37 UpdateScreenInfo(-1.567f); | |
38 std::string hint = client_hints_.GetDevicePixelRatioHeader(); | |
39 EXPECT_EQ("", hint); | |
40 | |
41 UpdateScreenInfo(1.567f); | |
42 hint = client_hints_.GetDevicePixelRatioHeader(); | |
43 EXPECT_EQ("1.57", hint); | |
44 | |
45 UpdateScreenInfo(0.0f); | |
46 hint = client_hints_.GetDevicePixelRatioHeader(); | |
47 // Hints should be last known good values. | |
48 EXPECT_EQ("1.57", hint); | |
49 } | |
50 | |
OLD | NEW |