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..47ad805dcafa974c34e5dc3cd0792bc219dcd503 |
| --- /dev/null |
| +++ b/chrome/browser/net/client_hints_unittest.cc |
| @@ -0,0 +1,45 @@ |
| +// Copyright (c) 2012 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 "base/logging.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +class ClientHintsTest : public testing::Test { |
| + public: |
| + void UpdateScreenInfo(int width, int height, float pixel_ratio) { |
| + ClientHints::ScreenInfo info; |
| + info.width = width; |
| + info.height = height; |
| + info.pixel_ratio = pixel_ratio; |
| + client_hints_.UpdateScreenInfo(&info); |
| + }; |
|
mmenke
2013/02/27 21:06:05
nit: Add line break.
bengr
2013/03/06 00:34:19
Done.
|
| + protected: |
| + ClientHints client_hints_; |
| +}; |
| + |
| +TEST_F(ClientHintsTest, HintsWellFormatted) { |
| + UpdateScreenInfo(100, 200, 1.567); |
| + std::string hint = client_hints_.GetScreenInfoHints(); |
| + EXPECT_EQ("dh=200, dw=100, dpr=1.57", hint); |
| +} |
| + |
| +TEST_F(ClientHintsTest, HintsHaveNonbogusValues) { |
| + UpdateScreenInfo(-100, -200, -1.567); |
| + std::string hint = client_hints_.GetScreenInfoHints(); |
| + EXPECT_EQ("", hint); |
| + |
| + UpdateScreenInfo(100, 200, 1.567); |
| + hint = client_hints_.GetScreenInfoHints(); |
| + EXPECT_EQ("dh=200, dw=100, dpr=1.57", hint); |
| + |
| + UpdateScreenInfo(100, 200, 0.0); |
| + hint = client_hints_.GetScreenInfoHints(); |
| + // Hints should be last known good values. |
| + EXPECT_EQ("dh=200, dw=100, dpr=1.57", hint); |
| + |
|
mmenke
2013/02/27 21:06:05
nit: Remove blank line.
bengr
2013/03/06 00:34:19
Done.
|
| +} |
| + |