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