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

Unified Diff: net/base/url_util_unittest.cc

Issue 992733002: Remove //net (except for Android test stuff) and sdch (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 months 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
« no previous file with comments | « net/base/url_util.cc ('k') | net/base/winsock_init.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/url_util_unittest.cc
diff --git a/net/base/url_util_unittest.cc b/net/base/url_util_unittest.cc
deleted file mode 100644
index 158e2740306e29bcdcfd1ab53b6d5cfcbd39af43..0000000000000000000000000000000000000000
--- a/net/base/url_util_unittest.cc
+++ /dev/null
@@ -1,163 +0,0 @@
-// 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 "net/base/url_util.h"
-
-#include "testing/gtest/include/gtest/gtest.h"
-#include "url/gurl.h"
-
-namespace net {
-namespace {
-
-TEST(UrlUtilTest, AppendQueryParameter) {
- // Appending a name-value pair to a URL without a query component.
- EXPECT_EQ("http://example.com/path?name=value",
- AppendQueryParameter(GURL("http://example.com/path"),
- "name", "value").spec());
-
- // Appending a name-value pair to a URL with a query component.
- // The original component should be preserved, and the new pair should be
- // appended with '&'.
- EXPECT_EQ("http://example.com/path?existing=one&name=value",
- AppendQueryParameter(GURL("http://example.com/path?existing=one"),
- "name", "value").spec());
-
- // Appending a name-value pair with unsafe characters included. The
- // unsafe characters should be escaped.
- EXPECT_EQ("http://example.com/path?existing=one&na+me=v.alue%3D",
- AppendQueryParameter(GURL("http://example.com/path?existing=one"),
- "na me", "v.alue=").spec());
-
-}
-
-TEST(UrlUtilTest, AppendOrReplaceQueryParameter) {
- // Appending a name-value pair to a URL without a query component.
- EXPECT_EQ("http://example.com/path?name=value",
- AppendOrReplaceQueryParameter(GURL("http://example.com/path"),
- "name", "value").spec());
-
- // Appending a name-value pair to a URL with a query component.
- // The original component should be preserved, and the new pair should be
- // appended with '&'.
- EXPECT_EQ("http://example.com/path?existing=one&name=value",
- AppendOrReplaceQueryParameter(
- GURL("http://example.com/path?existing=one"),
- "name", "value").spec());
-
- // Appending a name-value pair with unsafe characters included. The
- // unsafe characters should be escaped.
- EXPECT_EQ("http://example.com/path?existing=one&na+me=v.alue%3D",
- AppendOrReplaceQueryParameter(
- GURL("http://example.com/path?existing=one"),
- "na me", "v.alue=").spec());
-
- // Replace value of an existing paramater.
- EXPECT_EQ("http://example.com/path?existing=one&name=new",
- AppendOrReplaceQueryParameter(
- GURL("http://example.com/path?existing=one&name=old"),
- "name", "new").spec());
-
- // Replace a name-value pair with unsafe characters included. The
- // unsafe characters should be escaped.
- EXPECT_EQ("http://example.com/path?na+me=n.ew%3D&existing=one",
- AppendOrReplaceQueryParameter(
- GURL("http://example.com/path?na+me=old&existing=one"),
- "na me", "n.ew=").spec());
-
- // Replace the value of first parameter with this name only.
- EXPECT_EQ("http://example.com/path?name=new&existing=one&name=old",
- AppendOrReplaceQueryParameter(
- GURL("http://example.com/path?name=old&existing=one&name=old"),
- "name", "new").spec());
-
- // Preserve the content of the original params regarless of our failure to
- // interpret them correctly.
- EXPECT_EQ("http://example.com/path?bar&name=new&left=&"
- "=right&=&&name=again",
- AppendOrReplaceQueryParameter(
- GURL("http://example.com/path?bar&name=old&left=&"
- "=right&=&&name=again"),
- "name", "new").spec());
-}
-
-TEST(UrlUtilTest, GetValueForKeyInQuery) {
- GURL url("http://example.com/path?name=value&boolParam&"
- "url=http://test.com/q?n1%3Dv1%26n2");
- std::string value;
-
- // False when getting a non-existent query param.
- EXPECT_FALSE(GetValueForKeyInQuery(url, "non-exist", &value));
-
- // True when query param exist.
- EXPECT_TRUE(GetValueForKeyInQuery(url, "name", &value));
- EXPECT_EQ("value", value);
-
- EXPECT_TRUE(GetValueForKeyInQuery(url, "boolParam", &value));
- EXPECT_EQ("", value);
-
- EXPECT_TRUE(GetValueForKeyInQuery(url, "url", &value));
- EXPECT_EQ("http://test.com/q?n1=v1&n2", value);
-}
-
-TEST(UrlUtilTest, GetValueForKeyInQueryInvalidURL) {
- GURL url("http://%01/?test");
- std::string value;
-
- // Always false when parsing an invalid URL.
- EXPECT_FALSE(GetValueForKeyInQuery(url, "test", &value));
-}
-
-TEST(UrlUtilTest, ParseQuery) {
- const GURL url("http://example.com/path?name=value&boolParam&"
- "url=http://test.com/q?n1%3Dv1%26n2&"
- "multikey=value1&multikey=value2&multikey");
- QueryIterator it(url);
-
- ASSERT_FALSE(it.IsAtEnd());
- EXPECT_EQ("name", it.GetKey());
- EXPECT_EQ("value", it.GetValue());
- EXPECT_EQ("value", it.GetUnescapedValue());
- it.Advance();
-
- ASSERT_FALSE(it.IsAtEnd());
- EXPECT_EQ("boolParam", it.GetKey());
- EXPECT_EQ("", it.GetValue());
- EXPECT_EQ("", it.GetUnescapedValue());
- it.Advance();
-
- ASSERT_FALSE(it.IsAtEnd());
- EXPECT_EQ("url", it.GetKey());
- EXPECT_EQ("http://test.com/q?n1%3Dv1%26n2", it.GetValue());
- EXPECT_EQ("http://test.com/q?n1=v1&n2", it.GetUnescapedValue());
- it.Advance();
-
- ASSERT_FALSE(it.IsAtEnd());
- EXPECT_EQ("multikey", it.GetKey());
- EXPECT_EQ("value1", it.GetValue());
- EXPECT_EQ("value1", it.GetUnescapedValue());
- it.Advance();
-
- ASSERT_FALSE(it.IsAtEnd());
- EXPECT_EQ("multikey", it.GetKey());
- EXPECT_EQ("value2", it.GetValue());
- EXPECT_EQ("value2", it.GetUnescapedValue());
- it.Advance();
-
- ASSERT_FALSE(it.IsAtEnd());
- EXPECT_EQ("multikey", it.GetKey());
- EXPECT_EQ("", it.GetValue());
- EXPECT_EQ("", it.GetUnescapedValue());
- it.Advance();
-
- EXPECT_TRUE(it.IsAtEnd());
-}
-
-TEST(UrlUtilTest, ParseQueryInvalidURL) {
- const GURL url("http://%01/?test");
- QueryIterator it(url);
- EXPECT_TRUE(it.IsAtEnd());
-}
-
-} // namespace
-} // namespace net
« no previous file with comments | « net/base/url_util.cc ('k') | net/base/winsock_init.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698