Chromium Code Reviews| Index: chrome/browser/net/client_hints_unittest.cc |
| diff --git a/chrome/browser/net/client_hints_unittest.cc b/chrome/browser/net/client_hints_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7aff24589ecd6a081e2865655e732aa497638bf2 |
| --- /dev/null |
| +++ b/chrome/browser/net/client_hints_unittest.cc |
| @@ -0,0 +1,50 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/net/client_hints.h" |
| + |
| +#include <locale.h> |
| + |
| +#include "base/logging.h" |
| +#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.
|
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +class ClientHintsTest : public testing::Test { |
| + public: |
| + void UpdateScreenInfo(float pixel_ratio) { |
| + client_hints_.UpdateScreenInfo(pixel_ratio); |
| + }; |
| + |
| + protected: |
| + ClientHints client_hints_; |
| +}; |
| + |
| +TEST_F(ClientHintsTest, HintsWellFormatted) { |
| + UpdateScreenInfo(1.567f); |
| + std::string hint = client_hints_.GetDevicePixelRatioHeader(); |
| + EXPECT_EQ("1.57", hint); |
| +} |
| + |
| +TEST_F(ClientHintsTest, HintsWellFormattedWithNonEnLocale) { |
| + setlocale(LC_ALL, "fr_FR.UTF-8"); |
| + UpdateScreenInfo(1.567f); |
| + std::string hint = client_hints_.GetDevicePixelRatioHeader(); |
| + EXPECT_EQ("1.57", hint); |
| +} |
| + |
| +TEST_F(ClientHintsTest, HintsHaveNonbogusValues) { |
| + UpdateScreenInfo(-1.567f); |
| + std::string hint = client_hints_.GetDevicePixelRatioHeader(); |
| + EXPECT_EQ("", hint); |
| + |
| + UpdateScreenInfo(1.567f); |
| + hint = client_hints_.GetDevicePixelRatioHeader(); |
| + EXPECT_EQ("1.57", hint); |
| + |
| + UpdateScreenInfo(0.0f); |
| + hint = client_hints_.GetDevicePixelRatioHeader(); |
| + // Hints should be last known good values. |
| + EXPECT_EQ("1.57", hint); |
| +} |
| + |