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 "testing/gtest/include/gtest/gtest.h" | |
11 | |
12 class ClientHintsTest : public testing::Test { | |
13 public: | |
14 void UpdateScreenInfo(float pixel_ratio) { | |
15 client_hints_.UpdateScreenInfo(pixel_ratio); | |
16 }; | |
17 | |
18 protected: | |
19 ClientHints client_hints_; | |
20 }; | |
21 | |
22 TEST_F(ClientHintsTest, HintsWellFormatted) { | |
23 UpdateScreenInfo(1.567f); | |
24 std::string hint = client_hints_.GetDevicePixelRatioHeader(); | |
25 EXPECT_EQ("1.57", hint); | |
26 } | |
27 | |
28 TEST_F(ClientHintsTest, HintsWellFormattedWithNonEnLocale) { | |
29 setlocale(LC_ALL, "fr_FR.UTF-8"); | |
Avi (use Gerrit)
2013/09/26 19:21:26
Nooooo. Please don't set a locale and fail to rese
| |
30 UpdateScreenInfo(1.567f); | |
31 std::string hint = client_hints_.GetDevicePixelRatioHeader(); | |
32 EXPECT_EQ("1.57", hint); | |
33 } | |
34 | |
35 TEST_F(ClientHintsTest, HintsHaveNonbogusValues) { | |
36 UpdateScreenInfo(-1.567f); | |
37 std::string hint = client_hints_.GetDevicePixelRatioHeader(); | |
38 EXPECT_EQ("", hint); | |
39 | |
40 UpdateScreenInfo(1.567f); | |
41 hint = client_hints_.GetDevicePixelRatioHeader(); | |
42 EXPECT_EQ("1.57", hint); | |
43 | |
44 UpdateScreenInfo(0.0f); | |
45 hint = client_hints_.GetDevicePixelRatioHeader(); | |
46 // Hints should be last known good values. | |
47 EXPECT_EQ("1.57", hint); | |
48 } | |
49 | |
OLD | NEW |