Commit 98ad5095 authored by David Benjamin's avatar David Benjamin Committed by Commit Bot

clang-format google_util_unittest.cc

This is in preparation for
https://chromium-review.googlesource.com/c/chromium/src/+/1687348 which
renames it, triggering a clang-format.

Bug: 973591
Change-Id: Iadcb37013281583c462d9bacf559cd5c622ccbfe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1695746
Auto-Submit: David Benjamin <davidben@chromium.org>
Commit-Queue: Ilya Sherman <isherman@chromium.org>
Reviewed-by: default avatarIlya Sherman <isherman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#676095}
parent 77922eb9
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "components/google/core/common/google_util.h" #include "components/google/core/common/google_util.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
...@@ -12,19 +13,15 @@ ...@@ -12,19 +13,15 @@
using google_util::IsGoogleDomainUrl; using google_util::IsGoogleDomainUrl;
// Helpers -------------------------------------------------------------------- // Helpers --------------------------------------------------------------------
namespace { namespace {
const std::string kValidSearchSchemes[] = { const std::string kValidSearchSchemes[] = {"http", "https"};
"http",
"https"
};
const std::string kValidSearchQueryParams[] = { const std::string kValidSearchQueryParams[] = {
"q", "q",
"as_q" // Advanced search uses "as_q" instead of "q" as the query param. "as_q" // Advanced search uses "as_q" instead of "q" as the query param.
}; };
// These functions merely provide brevity in the callers. // These functions merely provide brevity in the callers.
...@@ -43,7 +40,6 @@ bool StartsWithBaseURL(const std::string& url) { ...@@ -43,7 +40,6 @@ bool StartsWithBaseURL(const std::string& url) {
} // namespace } // namespace
// Actual tests --------------------------------------------------------------- // Actual tests ---------------------------------------------------------------
TEST(GoogleUtilTest, GoodHomePagesNonSecure) { TEST(GoogleUtilTest, GoodHomePagesNonSecure) {
...@@ -174,7 +170,8 @@ TEST(GoogleUtilTest, GoodSearches) { ...@@ -174,7 +170,8 @@ TEST(GoogleUtilTest, GoodSearches) {
"%s://ipv6.google.com?name=bob#age=24&%s=something", "%s://ipv6.google.com?name=bob#age=24&%s=something",
// Trailing dots in the hosts. // Trailing dots in the hosts.
"%s://www.google.com./#%s=something", "%s://www.google.de./#%s=something", "%s://www.google.com./#%s=something",
"%s://www.google.de./#%s=something",
"%s://ipv4.google.com./#%s=something", "%s://ipv4.google.com./#%s=something",
"%s://ipv6.google.com./#%s=something", "%s://ipv6.google.com./#%s=something",
}; };
...@@ -182,8 +179,7 @@ TEST(GoogleUtilTest, GoodSearches) { ...@@ -182,8 +179,7 @@ TEST(GoogleUtilTest, GoodSearches) {
for (const std::string& pattern : patterns) { for (const std::string& pattern : patterns) {
for (const std::string& scheme : kValidSearchSchemes) { for (const std::string& scheme : kValidSearchSchemes) {
for (const std::string& query_param : kValidSearchQueryParams) { for (const std::string& query_param : kValidSearchQueryParams) {
EXPECT_TRUE(IsSearch(base::StringPrintf(pattern.c_str(), EXPECT_TRUE(IsSearch(base::StringPrintf(pattern.c_str(), scheme.c_str(),
scheme.c_str(),
query_param.c_str()))); query_param.c_str())));
} }
} }
...@@ -203,45 +199,39 @@ TEST(GoogleUtilTest, BadSearches) { ...@@ -203,45 +199,39 @@ TEST(GoogleUtilTest, BadSearches) {
// Empty URL is invalid. // Empty URL is invalid.
EXPECT_FALSE(IsSearch(std::string())); EXPECT_FALSE(IsSearch(std::string()));
const std::string patterns[] = { const std::string patterns[] = {"%s://google.com", "%s://www.google.com",
"%s://google.com", "%s://www.google.com/search",
"%s://www.google.com", "%s://www.google.com/search?"};
"%s://www.google.com/search",
"%s://www.google.com/search?"
};
for (const std::string& pattern : patterns) { for (const std::string& pattern : patterns) {
for (const std::string& scheme : kValidSearchSchemes) { for (const std::string& scheme : kValidSearchSchemes) {
EXPECT_FALSE(IsSearch(base::StringPrintf(pattern.c_str(), EXPECT_FALSE(
scheme.c_str()))); IsSearch(base::StringPrintf(pattern.c_str(), scheme.c_str())));
} }
} }
const std::string patterns_q[] = { const std::string patterns_q[] = {
// Home page searches without a hash fragment query parameter are invalid. // Home page searches without a hash fragment query parameter are invalid.
"%s://www.google.com/webhp?%s=something", "%s://www.google.com/webhp?%s=something",
"%s://www.google.com/webhp?%s=something#no=good", "%s://www.google.com/webhp?%s=something#no=good",
"%s://www.google.com/webhp?name=bob&%s=something", "%s://www.google.com/webhp?name=bob&%s=something",
"%s://www.google.com/?%s=something", "%s://www.google.com/?%s=something", "%s://www.google.com?%s=something",
"%s://www.google.com?%s=something",
// Some paths are outright invalid as searches.
// Some paths are outright invalid as searches. "%s://www.google.com/notreal?%s=something",
"%s://www.google.com/notreal?%s=something", "%s://www.google.com/chrome?%s=something",
"%s://www.google.com/chrome?%s=something", "%s://www.google.com/search/nogood?%s=something",
"%s://www.google.com/search/nogood?%s=something", "%s://www.google.com/webhp/nogood#%s=something",
"%s://www.google.com/webhp/nogood#%s=something",
// Case sensitive paths.
// Case sensitive paths. "%s://www.google.com/SEARCH?%s=something",
"%s://www.google.com/SEARCH?%s=something", "%s://www.google.com/WEBHP#%s=something"};
"%s://www.google.com/WEBHP#%s=something"
};
for (const std::string& pattern : patterns_q) { for (const std::string& pattern : patterns_q) {
for (const std::string& scheme : kValidSearchSchemes) { for (const std::string& scheme : kValidSearchSchemes) {
for (const std::string& query_param : kValidSearchQueryParams) { for (const std::string& query_param : kValidSearchQueryParams) {
EXPECT_FALSE(IsSearch(base::StringPrintf(pattern.c_str(), EXPECT_FALSE(IsSearch(base::StringPrintf(
scheme.c_str(), pattern.c_str(), scheme.c_str(), query_param.c_str())));
query_param.c_str())));
} }
} }
} }
...@@ -341,8 +331,8 @@ TEST(GoogleUtilTest, GoogleBaseURLNotSpecified) { ...@@ -341,8 +331,8 @@ TEST(GoogleUtilTest, GoogleBaseURLNotSpecified) {
// By default, none of the IsGoogleXXX functions should return true for a // By default, none of the IsGoogleXXX functions should return true for a
// "foo.com" URL. // "foo.com" URL.
EXPECT_FALSE(IsGoogleHostname("www.foo.com", EXPECT_FALSE(
google_util::DISALLOW_SUBDOMAIN)); IsGoogleHostname("www.foo.com", google_util::DISALLOW_SUBDOMAIN));
EXPECT_FALSE(IsGoogleDomainUrl(GURL("http://www.foo.com/xyz"), EXPECT_FALSE(IsGoogleDomainUrl(GURL("http://www.foo.com/xyz"),
google_util::DISALLOW_SUBDOMAIN, google_util::DISALLOW_SUBDOMAIN,
google_util::DISALLOW_NON_STANDARD_PORTS)); google_util::DISALLOW_NON_STANDARD_PORTS));
...@@ -409,8 +399,8 @@ TEST(GoogleUtilTest, YoutubeDomains) { ...@@ -409,8 +399,8 @@ TEST(GoogleUtilTest, YoutubeDomains) {
google_util::ALLOW_SUBDOMAIN, google_util::ALLOW_SUBDOMAIN,
google_util::DISALLOW_NON_STANDARD_PORTS)); google_util::DISALLOW_NON_STANDARD_PORTS));
EXPECT_FALSE(IsYoutubeDomainUrl(GURL("http://notyoutube.com"), EXPECT_FALSE(IsYoutubeDomainUrl(GURL("http://notyoutube.com"),
google_util::ALLOW_SUBDOMAIN, google_util::ALLOW_SUBDOMAIN,
google_util::DISALLOW_NON_STANDARD_PORTS)); google_util::DISALLOW_NON_STANDARD_PORTS));
// TLD checks. // TLD checks.
EXPECT_TRUE(IsYoutubeDomainUrl(GURL("http://www.youtube.ca"), EXPECT_TRUE(IsYoutubeDomainUrl(GURL("http://www.youtube.ca"),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment