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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_navigation_observer_browsertest.cc

Issue 2644133005: Include all server redirects in referrer chain (Closed)
Patch Set: nit Created 3 years, 11 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/strings/stringprintf.h" 5 #include "base/strings/stringprintf.h"
6 #include "chrome/browser/chrome_notification_types.h" 6 #include "chrome/browser/chrome_notification_types.h"
7 #include "chrome/browser/download/download_prefs.h" 7 #include "chrome/browser/download/download_prefs.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/safe_browsing/download_protection_service.h" 9 #include "chrome/browser/safe_browsing/download_protection_service.h"
10 #include "chrome/browser/safe_browsing/safe_browsing_navigation_observer.h" 10 #include "chrome/browser/safe_browsing/safe_browsing_navigation_observer.h"
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 const GURL& expected_destination_url, 216 const GURL& expected_destination_url,
217 bool expected_is_user_initiated, 217 bool expected_is_user_initiated,
218 bool expected_has_committed, 218 bool expected_has_committed,
219 bool expected_has_server_redirect, 219 bool expected_has_server_redirect,
220 const NavigationEvent& actual_nav_event) { 220 const NavigationEvent& actual_nav_event) {
221 EXPECT_EQ(expected_source_url, actual_nav_event.source_url); 221 EXPECT_EQ(expected_source_url, actual_nav_event.source_url);
222 EXPECT_EQ(expected_source_main_frame_url, 222 EXPECT_EQ(expected_source_main_frame_url,
223 actual_nav_event.source_main_frame_url); 223 actual_nav_event.source_main_frame_url);
224 EXPECT_EQ(expected_original_request_url, 224 EXPECT_EQ(expected_original_request_url,
225 actual_nav_event.original_request_url); 225 actual_nav_event.original_request_url);
226 EXPECT_EQ(expected_destination_url, actual_nav_event.destination_url); 226 EXPECT_EQ(expected_destination_url, actual_nav_event.GetDestinationUrl());
227 EXPECT_EQ(expected_is_user_initiated, actual_nav_event.is_user_initiated); 227 EXPECT_EQ(expected_is_user_initiated, actual_nav_event.is_user_initiated);
228 EXPECT_EQ(expected_has_committed, actual_nav_event.has_committed); 228 EXPECT_EQ(expected_has_committed, actual_nav_event.has_committed);
229 EXPECT_EQ(expected_has_server_redirect, 229 EXPECT_EQ(expected_has_server_redirect,
230 actual_nav_event.has_server_redirect); 230 actual_nav_event.has_server_redirect);
231 } 231 }
232 232
233 void VerifyReferrerChainEntry(const GURL& expected_url, 233 void VerifyReferrerChainEntry(const GURL& expected_url,
234 ReferrerChainEntry::URLType expected_type, 234 ReferrerChainEntry::URLType expected_type,
235 const std::string& expected_ip_address, 235 const std::string& expected_ip_address,
236 const GURL& expected_referrer_url, 236 const GURL& expected_referrer_url,
(...skipping 1427 matching lines...) Expand 10 before | Expand all | Expand 10 after
1664 ReferrerChain referrer_chain; 1664 ReferrerChain referrer_chain;
1665 IdentifyReferrerChainForDownload(GetDownload(), &referrer_chain); 1665 IdentifyReferrerChainForDownload(GetDownload(), &referrer_chain);
1666 ASSERT_EQ(1U, referrer_chain.size()); 1666 ASSERT_EQ(1U, referrer_chain.size());
1667 VerifyReferrerChainEntry(download_url, // url 1667 VerifyReferrerChainEntry(download_url, // url
1668 ReferrerChainEntry::DOWNLOAD_URL, // type 1668 ReferrerChainEntry::DOWNLOAD_URL, // type
1669 test_server_ip, // ip_address 1669 test_server_ip, // ip_address
1670 GURL(), // referrer_url 1670 GURL(), // referrer_url
1671 GURL(), // referrer_main_frame_url 1671 GURL(), // referrer_main_frame_url
1672 false, // is_retargeting 1672 false, // is_retargeting
1673 referrer_chain[0].get()); 1673 referrer_chain[0].get());
1674 const auto server_redirects =
1675 referrer_chain[0].get()->server_redirect_chain();
1676 ASSERT_EQ(2, server_redirects.size());
1677 EXPECT_EQ(request_url, server_redirects.Get(0));
1678 EXPECT_EQ(download_url, server_redirects.Get(1));
1679 }
1680
1681 // 2 consecutive server-side redirects.
1682 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, TwoServerRedirects) {
1683 GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL);
1684 GURL destination_url = embedded_test_server()->GetURL(kDownloadItemURL);
1685 GURL redirect_url =
1686 embedded_test_server()->GetURL("/server-redirect?" +
1687 destination_url.spec());
1688 GURL request_url =
1689 embedded_test_server()->GetURL("/server-redirect?" +
1690 redirect_url.spec());
1691 ui_test_utils::NavigateToURL(browser(), request_url);
1692 std::string test_server_ip(embedded_test_server()->host_port_pair().host());
1693 auto nav_map = navigation_map();
1694 ASSERT_TRUE(nav_map);
1695 ASSERT_EQ(2U, nav_map->size());
1696 ASSERT_EQ(1U, nav_map->at(destination_url).size());
1697 ASSERT_EQ(1U, nav_map->at(initial_url).size());
1698 VerifyNavigationEvent(GURL(), // source_url
1699 GURL(), // source_main_frame_url
1700 initial_url, // original_request_url
1701 initial_url, // destination_url
1702 true, // is_user_initiated,
1703 true, // has_committed
1704 false, // has_server_redirect
1705 nav_map->at(initial_url).at(0));
1706 VerifyNavigationEvent(GURL(), // source_url
1707 GURL(), // source_main_frame_url
1708 request_url, // original_request_url
1709 destination_url, // destination_url
1710 true, // is_user_initiated,
1711 false, // has_committed
1712 true, // has_server_redirect
1713 nav_map->at(destination_url).at(0));
1714 const auto redirect_vector =
1715 nav_map->at(destination_url).at(0).server_redirect_urls;
1716 ASSERT_EQ(2U, redirect_vector.size());
1717 EXPECT_EQ(redirect_url, redirect_vector.at(0));
1718 EXPECT_EQ(destination_url, redirect_vector.at(1));
1719
1720 ReferrerChain referrer_chain;
1721 IdentifyReferrerChainForDownload(GetDownload(), &referrer_chain);
1722 ASSERT_EQ(1U, referrer_chain.size());
1723 VerifyReferrerChainEntry(destination_url, // url
1724 ReferrerChainEntry::DOWNLOAD_URL, // type
1725 test_server_ip, // ip_address
1726 GURL(), // referrer_url
1727 GURL(), // referrer_main_frame_url
1728 false, // is_retargeting
1729 referrer_chain[0].get());
1730 const auto server_redirects =
1731 referrer_chain[0].get()->server_redirect_chain();
1732 ASSERT_EQ(3, server_redirects.size());
1733 EXPECT_EQ(request_url, server_redirects.Get(0));
1734 EXPECT_EQ(redirect_url, server_redirects.Get(1));
1735 EXPECT_EQ(destination_url, server_redirects.Get(2));
1674 } 1736 }
1675 1737
1676 // Retargeting immediately followed by server-side redirect. 1738 // Retargeting immediately followed by server-side redirect.
1677 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, 1739 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest,
1678 RetargetingAndServerRedirect) { 1740 RetargetingAndServerRedirect) {
1679 GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL); 1741 GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL);
1680 GURL download_url = embedded_test_server()->GetURL(kDownloadItemURL); 1742 GURL download_url = embedded_test_server()->GetURL(kDownloadItemURL);
1681 GURL request_url = 1743 GURL request_url =
1682 embedded_test_server()->GetURL("/server-redirect?" + download_url.spec()); 1744 embedded_test_server()->GetURL("/server-redirect?" + download_url.spec());
1683 ClickTestLink("new_tab_download_with_server_redirect", 1, initial_url); 1745 ClickTestLink("new_tab_download_with_server_redirect", 1, initial_url);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1761 yesterday, embedded_test_server()->host_port_pair().host())); 1823 yesterday, embedded_test_server()->host_port_pair().host()));
1762 ASSERT_EQ(1U, ip_map->at(test_server_host).size()); 1824 ASSERT_EQ(1U, ip_map->at(test_server_host).size());
1763 ClickTestLink("direct_download", 1, initial_url); 1825 ClickTestLink("direct_download", 1, initial_url);
1764 EXPECT_EQ(1U, ip_map->at(test_server_host).size()); 1826 EXPECT_EQ(1U, ip_map->at(test_server_host).size());
1765 EXPECT_EQ(embedded_test_server()->host_port_pair().host(), 1827 EXPECT_EQ(embedded_test_server()->host_port_pair().host(),
1766 ip_map->at(test_server_host).back().ip); 1828 ip_map->at(test_server_host).back().ip);
1767 EXPECT_NE(yesterday, ip_map->at(test_server_host).front().timestamp); 1829 EXPECT_NE(yesterday, ip_map->at(test_server_host).front().timestamp);
1768 } 1830 }
1769 1831
1770 } // namespace safe_browsing 1832 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698