OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "base/test/histogram_tester.h" | 6 #include "base/test/histogram_tester.h" |
7 #include "chrome/browser/page_load_metrics/observers/from_gws_page_load_metrics_
observer.h" | 7 #include "chrome/browser/page_load_metrics/observers/from_gws_page_load_metrics_
observer.h" |
| 8 #include "chrome/browser/page_load_metrics/observers/google_captcha_observer.h" |
8 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 9 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
9 #include "components/page_load_metrics/browser/metrics_web_contents_observer.h" | 10 #include "components/page_load_metrics/browser/metrics_web_contents_observer.h" |
10 #include "components/page_load_metrics/common/page_load_metrics_messages.h" | 11 #include "components/page_load_metrics/common/page_load_metrics_messages.h" |
11 #include "content/public/test/web_contents_tester.h" | 12 #include "content/public/test/web_contents_tester.h" |
12 #include "url/gurl.h" | 13 #include "url/gurl.h" |
13 | 14 |
14 namespace { | 15 namespace { |
15 | 16 |
16 const char kHistogramNameFromGWSFirstTextPaint[] = | 17 const char kHistogramNameFromGWSFirstTextPaint[] = |
17 "PageLoad.Clients.FromGWS.Timing2.NavigationToFirstTextPaint"; | 18 "PageLoad.Clients.FromGWS.Timing2.NavigationToFirstTextPaint"; |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 GURL("https://www.anothersite.com"), blink::WebReferrerPolicyDefault)); | 224 GURL("https://www.anothersite.com"), blink::WebReferrerPolicyDefault)); |
224 | 225 |
225 observer_->OnMessageReceived( | 226 observer_->OnMessageReceived( |
226 PageLoadMetricsMsg_TimingUpdated(observer_->routing_id(), timing), | 227 PageLoadMetricsMsg_TimingUpdated(observer_->routing_id(), timing), |
227 web_contents()->GetMainFrame()); | 228 web_contents()->GetMainFrame()); |
228 | 229 |
229 // Navigate again to force logging. | 230 // Navigate again to force logging. |
230 NavigateAndCommit(GURL("https://www.google.com")); | 231 NavigateAndCommit(GURL("https://www.google.com")); |
231 histogram_tester_.ExpectTotalCount(kHistogramNameFromGWSFirstTextPaint, 0); | 232 histogram_tester_.ExpectTotalCount(kHistogramNameFromGWSFirstTextPaint, 0); |
232 } | 233 } |
| 234 |
| 235 TEST_F(PageLoadMetricsObserverTest, IsGoogleCaptcha) { |
| 236 struct { |
| 237 std::string url; |
| 238 bool expected; |
| 239 } test_cases[] = { |
| 240 {"", false}, |
| 241 {"http://www.google.com/", false}, |
| 242 {"http://www.cnn.com/", false}, |
| 243 {"http://ipv4.google.com/", false}, |
| 244 {"https://ipv4.google.com/sorry/IndexRedirect?continue=http://a", true}, |
| 245 {"https://ipv6.google.com/sorry/IndexRedirect?continue=http://a", true}, |
| 246 {"https://ipv7.google.com/sorry/IndexRedirect?continue=http://a", false}, |
| 247 }; |
| 248 for (const auto& test : test_cases) { |
| 249 EXPECT_EQ(test.expected, |
| 250 google_captcha_observer::IsGoogleCaptcha(GURL(test.url))) |
| 251 << "for URL: " << test.url; |
| 252 } |
| 253 } |
OLD | NEW |