summaryrefslogtreecommitdiffstats
path: root/chrome/browser/net/client_hints_unittest.cc
diff options
context:
space:
mode:
authorbengr@chromium.org <bengr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-05 05:07:23 +0000
committerbengr@chromium.org <bengr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-05 05:07:23 +0000
commit3620bbccdc81bc4af00cd68747e45b18c617617c (patch)
treedf2bc1ff4924599c97561d7346fefec3ae9f3eda /chrome/browser/net/client_hints_unittest.cc
parent0a7465e3c2aec71ebdec2a9569542adc3fbe2f30 (diff)
downloadchromium_src-3620bbccdc81bc4af00cd68747e45b18c617617c.zip
chromium_src-3620bbccdc81bc4af00cd68747e45b18c617617c.tar.gz
chromium_src-3620bbccdc81bc4af00cd68747e45b18c617617c.tar.bz2
Client Hints
Client Hints can be used as input to proactive content negotiation; just as the Accept header allowed clients to indicate what formats they prefer, Client Hints allow clients to indicate a list of device and agent specific preferences. See: https://github.com/igrigorik/http-client-hints/blob/draft2/draft-grigorik-http-client-hints-01.txt Patched from https://codereview.chromium.org/23654014/, which was patched from https://codereview.chromium.org/11970002 BUG=170388 CONTRIBUTOR=yoav@yoav.ws Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=225425 Review URL: https://codereview.chromium.org/24451003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@227178 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/net/client_hints_unittest.cc')
-rw-r--r--chrome/browser/net/client_hints_unittest.cc56
1 files changed, 56 insertions, 0 deletions
diff --git a/chrome/browser/net/client_hints_unittest.cc b/chrome/browser/net/client_hints_unittest.cc
new file mode 100644
index 0000000..d64fe53
--- /dev/null
+++ b/chrome/browser/net/client_hints_unittest.cc
@@ -0,0 +1,56 @@
+// 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"
+#if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_IOS)
+#include "base/test/scoped_locale.h"
+#endif
+#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);
+}
+
+// Android and iOS do not support setLocale.
+#if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_IOS)
+// TODO(bengr): Use ScopedLocal in Windows once it is supported.
+TEST_F(ClientHintsTest, HintsWellFormattedWithNonEnLocale) {
+ base::ScopedLocale locale("fr_FR.UTF-8");
+ UpdateScreenInfo(1.567f);
+ std::string hint = client_hints_.GetDevicePixelRatioHeader();
+ EXPECT_EQ("1.57", hint);
+}
+#endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_IOS)
+
+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);
+}
+