| Index: chrome/browser/page_load_metrics/page_load_metrics_util_unittest.cc
|
| diff --git a/chrome/browser/page_load_metrics/page_load_metrics_util_unittest.cc b/chrome/browser/page_load_metrics/page_load_metrics_util_unittest.cc
|
| index 6704311a1b6327a92fd8f6ebc418a75a8c8e2143..5bf67d39740084b34385170717b994d7625b151e 100644
|
| --- a/chrome/browser/page_load_metrics/page_load_metrics_util_unittest.cc
|
| +++ b/chrome/browser/page_load_metrics/page_load_metrics_util_unittest.cc
|
| @@ -78,3 +78,154 @@ TEST_F(PageLoadMetricsUtilTest, GetGoogleHostnamePrefix) {
|
| }
|
| }
|
| }
|
| +
|
| +TEST_F(PageLoadMetricsUtilTest, IsGoogleSearchHostname) {
|
| + struct {
|
| + bool expected_result;
|
| + const char* url;
|
| + } test_cases[] = {
|
| + {true, "https://www.google.com/"},
|
| + {true, "https://www.google.co.uk/"},
|
| + {true, "https://www.google.co.in/"},
|
| + {false, "https://other.google.com/"},
|
| + {false, "https://other.www.google.com/"},
|
| + {false, "https://www.other.google.com/"},
|
| + {false, "https://www.www.google.com/"},
|
| + {false, "https://www.google.appspot.com/"},
|
| + {false, "https://www.google.example.com/"},
|
| + // Search results are not served from the bare google.com domain.
|
| + {false, "https://google.com/"},
|
| + };
|
| + for (const auto& test : test_cases) {
|
| + EXPECT_EQ(test.expected_result,
|
| + page_load_metrics::IsGoogleSearchHostname(GURL(test.url)))
|
| + << "for URL: " << test.url;
|
| + }
|
| +}
|
| +
|
| +TEST_F(PageLoadMetricsUtilTest, IsGoogleSearchResultUrl) {
|
| + struct {
|
| + bool expected_result;
|
| + const char* url;
|
| + } test_cases[] = {
|
| + {true, "https://www.google.com/#q=test"},
|
| + {true, "https://www.google.com/search#q=test"},
|
| + {true, "https://www.google.com/search?q=test"},
|
| + {true, "https://www.google.com/webhp#q=test"},
|
| + {true, "https://www.google.com/webhp?q=test"},
|
| + {true, "https://www.google.com/webhp?a=b&q=test"},
|
| + {true, "https://www.google.com/webhp?a=b&q=test&c=d"},
|
| + {true, "https://www.google.com/webhp#a=b&q=test&c=d"},
|
| + {true, "https://www.google.com/webhp?#a=b&q=test&c=d"},
|
| + {false, "https://www.google.com/"},
|
| + {false, "https://www.google.com/about/"},
|
| + {false, "https://other.google.com/"},
|
| + {false, "https://other.google.com/webhp?q=test"},
|
| + {false, "http://www.example.com/"},
|
| + {false, "https://www.example.com/webhp?q=test"},
|
| + {false, "https://google.com/#q=test"},
|
| + };
|
| + for (const auto& test : test_cases) {
|
| + EXPECT_EQ(test.expected_result,
|
| + page_load_metrics::IsGoogleSearchResultUrl(GURL(test.url)))
|
| + << "for URL: " << test.url;
|
| + }
|
| +}
|
| +
|
| +TEST_F(PageLoadMetricsUtilTest, IsGoogleSearchRedirectorUrl) {
|
| + struct {
|
| + bool expected_result;
|
| + const char* url;
|
| + } test_cases[] = {
|
| + {true, "https://www.google.com/url?source=web"},
|
| + {true, "https://www.google.com/url?source=web#foo"},
|
| + {true, "https://www.google.com/searchurl/r.html#foo"},
|
| + {true, "https://www.google.com/url?a=b&source=web&c=d"},
|
| + {false, "https://www.google.com/?"},
|
| + {false, "https://www.google.com/?url"},
|
| + {false, "https://www.example.com/url?source=web"},
|
| + {false, "https://google.com/url?"},
|
| + {false, "https://www.google.com/?source=web"},
|
| + {false, "https://www.google.com/source=web"},
|
| + {false, "https://www.example.com/url?source=web"},
|
| + {false, "https://www.google.com/url?"},
|
| + {false, "https://www.google.com/url?a=b"},
|
| + };
|
| + for (const auto& test : test_cases) {
|
| + EXPECT_EQ(test.expected_result,
|
| + page_load_metrics::IsGoogleSearchRedirectorUrl(GURL(test.url)))
|
| + << "for URL: " << test.url;
|
| + }
|
| +}
|
| +
|
| +TEST_F(PageLoadMetricsUtilTest, QueryContainsComponent) {
|
| + struct {
|
| + bool expected_result;
|
| + const char* query;
|
| + const char* component;
|
| + } test_cases[] = {
|
| + {true, "a=b", "a=b"},
|
| + {true, "a=b&c=d", "a=b"},
|
| + {true, "a=b&c=d", "c=d"},
|
| + {true, "a=b&c=d&e=f", "c=d"},
|
| + {true, "za=b&a=b", "a=b"},
|
| + {true, "a=bz&a=b", "a=b"},
|
| + {true, "a=ba=b&a=b", "a=b"},
|
| + {true, "a=a=a&a=a", "a=a"},
|
| + {true, "source=web", "source=web"},
|
| + {true, "a=b&source=web", "source=web"},
|
| + {true, "a=b&source=web&c=d", "source=web"},
|
| + {false, "a=a=a", "a=a"},
|
| + {false, "", ""},
|
| + {false, "a=b", ""},
|
| + {false, "", "a=b"},
|
| + {false, "za=b", "a=b"},
|
| + {false, "za=bz", "a=b"},
|
| + {false, "a=bz", "a=b"},
|
| + {false, "za=b&c=d", "a=b"},
|
| + {false, "a=b&c=dz", "c=d"},
|
| + {false, "a=b&zc=d&e=f", "c=d"},
|
| + {false, "a=b&c=dz&e=f", "c=d"},
|
| + {false, "a=b&zc=dz&e=f", "c=d"},
|
| + {false, "a=b&foosource=web&c=d", "source=web"},
|
| + {false, "a=b&source=webbar&c=d", "source=web"},
|
| + {false, "a=b&foosource=webbar&c=d", "source=web"},
|
| + };
|
| + for (const auto& test : test_cases) {
|
| + EXPECT_EQ(test.expected_result, page_load_metrics::QueryContainsComponent(
|
| + test.query, test.component))
|
| + << "For query: " << test.query << " with component: " << test.component;
|
| + }
|
| +}
|
| +
|
| +TEST_F(PageLoadMetricsUtilTest, QueryContainsComponentPrefix) {
|
| + struct {
|
| + bool expected_result;
|
| + const char* query;
|
| + const char* component;
|
| + } test_cases[] = {
|
| + {true, "a=b", "a="},
|
| + {true, "a=b&c=d", "a="},
|
| + {true, "a=b&c=d", "c="},
|
| + {true, "a=b&c=d&e=f", "c="},
|
| + {true, "za=b&a=b", "a="},
|
| + {true, "ba=a=b&a=b", "a="},
|
| + {true, "q=test", "q="},
|
| + {true, "a=b&q=test", "q="},
|
| + {true, "q=test&c=d", "q="},
|
| + {true, "a=b&q=test&c=d", "q="},
|
| + {false, "", ""},
|
| + {false, "za=b", "a="},
|
| + {false, "za=b&c=d", "a="},
|
| + {false, "a=b&zc=d", "c="},
|
| + {false, "a=b&zc=d&e=f", "c="},
|
| + {false, "a=b&zq=test&c=d", "q="},
|
| + {false, "ba=a=b", "a="},
|
| + };
|
| + for (const auto& test : test_cases) {
|
| + EXPECT_EQ(test.expected_result,
|
| + page_load_metrics::QueryContainsComponentPrefix(test.query,
|
| + test.component))
|
| + << "For query: " << test.query << " with component: " << test.component;
|
| + }
|
| +}
|
|
|