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

Unified Diff: net/http/http_util_icu_unittest.cc

Issue 2559243003: Extend with a language code in http accept languages
Patch Set: Rebased separate Generate AcceptLanguage Header from http_util Created 4 years 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 side-by-side diff with in-line comments
Download patch
Index: net/http/http_util_icu_unittest.cc
diff --git a/net/http/http_util_icu_unittest.cc b/net/http/http_util_icu_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a08737bf79539bc267b20a071dd627193723d076
--- /dev/null
+++ b/net/http/http_util_icu_unittest.cc
@@ -0,0 +1,44 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
Seigo Nonaka 2016/12/12 01:48:54 2016
Yirui Huang 2016/12/12 06:50:41 Done.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <algorithm>
Seigo Nonaka 2016/12/12 01:48:54 remove?
Yirui Huang 2016/12/12 06:50:41 Done.
+#include <limits>
Seigo Nonaka 2016/12/12 01:48:54 remove?
Yirui Huang 2016/12/12 06:50:41 Done.
+
+#include "base/strings/string_util.h"
Seigo Nonaka 2016/12/12 01:48:54 remove?
Yirui Huang 2016/12/12 06:50:41 Done.
+#include "net/http/http_util_icu.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace net {
+
+namespace {
+class HttpUtilIcuTest : public testing::Test {};
Seigo Nonaka 2016/12/12 01:48:54 Not necessary. Please remove this class declaratio
Yirui Huang 2016/12/12 06:50:41 Done.
+}
+
+TEST(HttpUtilIcuTest, GenerateAcceptLanguageHeader) {
+ EXPECT_EQ(std::string("en-US,en;q=0.8,fr;q=0.6,de;q=0.4"),
+ HttpUtilIcu::GenerateAcceptLanguageHeader("en-US,fr,de"));
+
+ // Test whitespace between language tags.
+ EXPECT_EQ(std::string("en-US,en;q=0.8,fr;q=0.6,de;q=0.4"),
+ HttpUtilIcu::GenerateAcceptLanguageHeader("en-US, fr, de"));
+
+ // Test a language code is inserted after languageTag only if it is not
+ // already in the request language list
+ EXPECT_EQ(std::string("en-US,en;q=0.8,fr-FR;q=0.6,fr;q=0.4,zh-CN;q=0.2,"
+ "zh;q=0.2"),
+ HttpUtilIcu::GenerateAcceptLanguageHeader("en-US,fr-FR,zh-CN"));
+
+ // Test a language code will not be inserted after languageTag if it is
+ // already in the request language list
+ EXPECT_EQ(std::string("en-US,en;q=0.8,fr-FR;q=0.6,fr;q=0.4,zh-CN;q=0.2,"
+ "zh;q=0.2"),
+ HttpUtilIcu::GenerateAcceptLanguageHeader("en-US,fr-FR,fr,zh-CN"));
+
+ // Make sure a language code is only inserted after the last languageTag that
+ // contains that language.
+ EXPECT_EQ(std::string("en-US,en-GB;q=0.8,en;q=0.6,fr;q=0.4,zh-CN;q=0.2,"
+ "zh;q=0.2"),
+ HttpUtilIcu::GenerateAcceptLanguageHeader("en-US,en-GB,fr,zh-CN"));
+}
+}

Powered by Google App Engine
This is Rietveld 408576698