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

Side by Side Diff: chrome/browser/page_load_metrics/page_load_metrics_util_unittest.cc

Issue 2936543002: Move Google search related util methods to page_load_metrics_util (Closed)
Patch Set: incorporated falken's comment Created 3 years, 6 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/page_load_metrics/page_load_metrics_util.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" 5 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h"
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "url/gurl.h" 8 #include "url/gurl.h"
9 9
10 class PageLoadMetricsUtilTest : public testing::Test {}; 10 class PageLoadMetricsUtilTest : public testing::Test {};
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 base::Optional<std::string> result = 71 base::Optional<std::string> result =
72 page_load_metrics::GetGoogleHostnamePrefix(GURL(test.url)); 72 page_load_metrics::GetGoogleHostnamePrefix(GURL(test.url));
73 EXPECT_EQ(test.expected_result, result.has_value()) 73 EXPECT_EQ(test.expected_result, result.has_value())
74 << "For URL: " << test.url; 74 << "For URL: " << test.url;
75 if (result) { 75 if (result) {
76 EXPECT_EQ(test.expected_prefix, result.value()) 76 EXPECT_EQ(test.expected_prefix, result.value())
77 << "Prefix for URL: " << test.url; 77 << "Prefix for URL: " << test.url;
78 } 78 }
79 } 79 }
80 } 80 }
81
82 TEST_F(PageLoadMetricsUtilTest, IsGoogleSearchHostname) {
83 struct {
84 bool expected_result;
85 const char* url;
86 } test_cases[] = {
87 {true, "https://www.google.com/"},
88 {true, "https://www.google.co.uk/"},
89 {true, "https://www.google.co.in/"},
90 {false, "https://other.google.com/"},
91 {false, "https://other.www.google.com/"},
92 {false, "https://www.other.google.com/"},
93 {false, "https://www.www.google.com/"},
94 {false, "https://www.google.appspot.com/"},
95 {false, "https://www.google.example.com/"},
96 // Search results are not served from the bare google.com domain.
97 {false, "https://google.com/"},
98 };
99 for (const auto& test : test_cases) {
100 EXPECT_EQ(test.expected_result,
101 page_load_metrics::IsGoogleSearchHostname(GURL(test.url)))
102 << "for URL: " << test.url;
103 }
104 }
105
106 TEST_F(PageLoadMetricsUtilTest, IsGoogleSearchResultUrl) {
107 struct {
108 bool expected_result;
109 const char* url;
110 } test_cases[] = {
111 {true, "https://www.google.com/#q=test"},
112 {true, "https://www.google.com/search#q=test"},
113 {true, "https://www.google.com/search?q=test"},
114 {true, "https://www.google.com/webhp#q=test"},
115 {true, "https://www.google.com/webhp?q=test"},
116 {true, "https://www.google.com/webhp?a=b&q=test"},
117 {true, "https://www.google.com/webhp?a=b&q=test&c=d"},
118 {true, "https://www.google.com/webhp#a=b&q=test&c=d"},
119 {true, "https://www.google.com/webhp?#a=b&q=test&c=d"},
120 {false, "https://www.google.com/"},
121 {false, "https://www.google.com/about/"},
122 {false, "https://other.google.com/"},
123 {false, "https://other.google.com/webhp?q=test"},
124 {false, "http://www.example.com/"},
125 {false, "https://www.example.com/webhp?q=test"},
126 {false, "https://google.com/#q=test"},
127 };
128 for (const auto& test : test_cases) {
129 EXPECT_EQ(test.expected_result,
130 page_load_metrics::IsGoogleSearchResultUrl(GURL(test.url)))
131 << "for URL: " << test.url;
132 }
133 }
134
135 TEST_F(PageLoadMetricsUtilTest, IsGoogleSearchRedirectorUrl) {
136 struct {
137 bool expected_result;
138 const char* url;
139 } test_cases[] = {
140 {true, "https://www.google.com/url?source=web"},
141 {true, "https://www.google.com/url?source=web#foo"},
142 {true, "https://www.google.com/searchurl/r.html#foo"},
143 {true, "https://www.google.com/url?a=b&source=web&c=d"},
144 {false, "https://www.google.com/?"},
145 {false, "https://www.google.com/?url"},
146 {false, "https://www.example.com/url?source=web"},
147 {false, "https://google.com/url?"},
148 {false, "https://www.google.com/?source=web"},
149 {false, "https://www.google.com/source=web"},
150 {false, "https://www.example.com/url?source=web"},
151 {false, "https://www.google.com/url?"},
152 {false, "https://www.google.com/url?a=b"},
153 };
154 for (const auto& test : test_cases) {
155 EXPECT_EQ(test.expected_result,
156 page_load_metrics::IsGoogleSearchRedirectorUrl(GURL(test.url)))
157 << "for URL: " << test.url;
158 }
159 }
160
161 TEST_F(PageLoadMetricsUtilTest, QueryContainsComponent) {
162 struct {
163 bool expected_result;
164 const char* query;
165 const char* component;
166 } test_cases[] = {
167 {true, "a=b", "a=b"},
168 {true, "a=b&c=d", "a=b"},
169 {true, "a=b&c=d", "c=d"},
170 {true, "a=b&c=d&e=f", "c=d"},
171 {true, "za=b&a=b", "a=b"},
172 {true, "a=bz&a=b", "a=b"},
173 {true, "a=ba=b&a=b", "a=b"},
174 {true, "a=a=a&a=a", "a=a"},
175 {true, "source=web", "source=web"},
176 {true, "a=b&source=web", "source=web"},
177 {true, "a=b&source=web&c=d", "source=web"},
178 {false, "a=a=a", "a=a"},
179 {false, "", ""},
180 {false, "a=b", ""},
181 {false, "", "a=b"},
182 {false, "za=b", "a=b"},
183 {false, "za=bz", "a=b"},
184 {false, "a=bz", "a=b"},
185 {false, "za=b&c=d", "a=b"},
186 {false, "a=b&c=dz", "c=d"},
187 {false, "a=b&zc=d&e=f", "c=d"},
188 {false, "a=b&c=dz&e=f", "c=d"},
189 {false, "a=b&zc=dz&e=f", "c=d"},
190 {false, "a=b&foosource=web&c=d", "source=web"},
191 {false, "a=b&source=webbar&c=d", "source=web"},
192 {false, "a=b&foosource=webbar&c=d", "source=web"},
193 };
194 for (const auto& test : test_cases) {
195 EXPECT_EQ(test.expected_result, page_load_metrics::QueryContainsComponent(
196 test.query, test.component))
197 << "For query: " << test.query << " with component: " << test.component;
198 }
199 }
200
201 TEST_F(PageLoadMetricsUtilTest, QueryContainsComponentPrefix) {
202 struct {
203 bool expected_result;
204 const char* query;
205 const char* component;
206 } test_cases[] = {
207 {true, "a=b", "a="},
208 {true, "a=b&c=d", "a="},
209 {true, "a=b&c=d", "c="},
210 {true, "a=b&c=d&e=f", "c="},
211 {true, "za=b&a=b", "a="},
212 {true, "ba=a=b&a=b", "a="},
213 {true, "q=test", "q="},
214 {true, "a=b&q=test", "q="},
215 {true, "q=test&c=d", "q="},
216 {true, "a=b&q=test&c=d", "q="},
217 {false, "", ""},
218 {false, "za=b", "a="},
219 {false, "za=b&c=d", "a="},
220 {false, "a=b&zc=d", "c="},
221 {false, "a=b&zc=d&e=f", "c="},
222 {false, "a=b&zq=test&c=d", "q="},
223 {false, "ba=a=b", "a="},
224 };
225 for (const auto& test : test_cases) {
226 EXPECT_EQ(test.expected_result,
227 page_load_metrics::QueryContainsComponentPrefix(test.query,
228 test.component))
229 << "For query: " << test.query << " with component: " << test.component;
230 }
231 }
OLDNEW
« no previous file with comments | « chrome/browser/page_load_metrics/page_load_metrics_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698