Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: chrome/browser/net/client_hints_unittest.cc

Issue 24809002: Leaking locale changes is a Very Bad Idea. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/net/client_hints.h" 5 #include "chrome/browser/net/client_hints.h"
6 6
7 #include <locale.h>
8
9 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/test/scoped_locale.h"
10 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
11 10
12 class ClientHintsTest : public testing::Test { 11 class ClientHintsTest : public testing::Test {
13 public: 12 public:
14 void UpdateScreenInfo(float pixel_ratio) { 13 void UpdateScreenInfo(float pixel_ratio) {
15 client_hints_.UpdateScreenInfo(pixel_ratio); 14 client_hints_.UpdateScreenInfo(pixel_ratio);
16 }; 15 };
17 16
18 protected: 17 protected:
19 ClientHints client_hints_; 18 ClientHints client_hints_;
20 }; 19 };
21 20
22 TEST_F(ClientHintsTest, HintsWellFormatted) { 21 TEST_F(ClientHintsTest, HintsWellFormatted) {
23 UpdateScreenInfo(1.567f); 22 UpdateScreenInfo(1.567f);
24 std::string hint = client_hints_.GetDevicePixelRatioHeader(); 23 std::string hint = client_hints_.GetDevicePixelRatioHeader();
25 EXPECT_EQ("1.57", hint); 24 EXPECT_EQ("1.57", hint);
26 } 25 }
27 26
28 TEST_F(ClientHintsTest, HintsWellFormattedWithNonEnLocale) { 27 TEST_F(ClientHintsTest, HintsWellFormattedWithNonEnLocale) {
29 setlocale(LC_ALL, "fr_FR.UTF-8"); 28 base::ScopedLocale locale("fr_FR.UTF-8");
30 UpdateScreenInfo(1.567f); 29 UpdateScreenInfo(1.567f);
31 std::string hint = client_hints_.GetDevicePixelRatioHeader(); 30 std::string hint = client_hints_.GetDevicePixelRatioHeader();
32 EXPECT_EQ("1.57", hint); 31 EXPECT_EQ("1.57", hint);
33 } 32 }
34 33
35 TEST_F(ClientHintsTest, HintsHaveNonbogusValues) { 34 TEST_F(ClientHintsTest, HintsHaveNonbogusValues) {
36 UpdateScreenInfo(-1.567f); 35 UpdateScreenInfo(-1.567f);
37 std::string hint = client_hints_.GetDevicePixelRatioHeader(); 36 std::string hint = client_hints_.GetDevicePixelRatioHeader();
38 EXPECT_EQ("", hint); 37 EXPECT_EQ("", hint);
39 38
40 UpdateScreenInfo(1.567f); 39 UpdateScreenInfo(1.567f);
41 hint = client_hints_.GetDevicePixelRatioHeader(); 40 hint = client_hints_.GetDevicePixelRatioHeader();
42 EXPECT_EQ("1.57", hint); 41 EXPECT_EQ("1.57", hint);
43 42
44 UpdateScreenInfo(0.0f); 43 UpdateScreenInfo(0.0f);
45 hint = client_hints_.GetDevicePixelRatioHeader(); 44 hint = client_hints_.GetDevicePixelRatioHeader();
46 // Hints should be last known good values. 45 // Hints should be last known good values.
47 EXPECT_EQ("1.57", hint); 46 EXPECT_EQ("1.57", hint);
48 } 47 }
49 48
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698