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

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

Issue 24451003: Client Hints (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed nit and use ScopedLocale with posix only 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
OLDNEW
(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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698