Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/safe_browsing_navigation_observer.h" | 10 #include "chrome/browser/safe_browsing/safe_browsing_navigation_observer.h" |
| 10 #include "chrome/browser/safe_browsing/safe_browsing_navigation_observer_manager .h" | 11 #include "chrome/browser/safe_browsing/safe_browsing_navigation_observer_manager .h" |
| 12 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h" | |
| 11 #include "chrome/browser/sessions/session_tab_helper.h" | 13 #include "chrome/browser/sessions/session_tab_helper.h" |
| 12 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 14 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 15 #include "chrome/test/base/in_process_browser_test.h" | 17 #include "chrome/test/base/in_process_browser_test.h" |
| 16 #include "chrome/test/base/ui_test_utils.h" | 18 #include "chrome/test/base/ui_test_utils.h" |
| 17 #include "components/prefs/pref_service.h" | 19 #include "components/prefs/pref_service.h" |
| 18 #include "content/public/browser/browser_context.h" | 20 #include "content/public/browser/browser_context.h" |
| 19 #include "content/public/browser/download_item.h" | 21 #include "content/public/browser/download_item.h" |
| 20 #include "content/public/browser/download_manager.h" | 22 #include "content/public/browser/download_manager.h" |
| 21 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
| 22 #include "content/public/test/browser_test_utils.h" | 24 #include "content/public/test/browser_test_utils.h" |
| 23 #include "content/public/test/test_navigation_observer.h" | 25 #include "content/public/test/test_navigation_observer.h" |
| 24 #include "content/public/test/test_utils.h" | 26 #include "content/public/test/test_utils.h" |
| 25 #include "net/dns/mock_host_resolver.h" | 27 #include "net/dns/mock_host_resolver.h" |
| 26 #include "net/test/embedded_test_server/embedded_test_server.h" | 28 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 27 #include "url/gurl.h" | 29 #include "url/gurl.h" |
| 28 #include "url/url_canon.h" | 30 #include "url/url_canon.h" |
| 29 | 31 |
| 32 using content::DownloadItem; | |
| 33 | |
| 30 namespace safe_browsing { | 34 namespace safe_browsing { |
| 31 | 35 |
| 32 const char kSingleFrameTestURL[] = | 36 const char kSingleFrameTestURL[] = |
| 33 "/safe_browsing/download_protection/navigation_observer/" | 37 "/safe_browsing/download_protection/navigation_observer/" |
| 34 "navigation_observer_tests.html"; | 38 "navigation_observer_tests.html"; |
| 35 const char kMultiFrameTestURL[] = | 39 const char kMultiFrameTestURL[] = |
| 36 "/safe_browsing/download_protection/navigation_observer/" | 40 "/safe_browsing/download_protection/navigation_observer/" |
| 37 "navigation_observer_multi_frame_tests.html"; | 41 "navigation_observer_multi_frame_tests.html"; |
| 38 const char kRedirectURL[] = | 42 const char kRedirectURL[] = |
| 39 "/safe_browsing/download_protection/navigation_observer/redirect.html"; | 43 "/safe_browsing/download_protection/navigation_observer/redirect.html"; |
| 40 const char kDownloadDataURL[] = | 44 const char kDownloadDataURL[] = |
| 41 "data:application/octet-stream;base64,a2poYWxrc2hkbGtoYXNka2xoYXNsa2RoYWxra" | 45 "data:application/octet-stream;base64,a2poYWxrc2hkbGtoYXNka2xoYXNsa2RoYWxra" |
| 42 "GtoYWxza2hka2xzamFoZGxramhhc2xka2hhc2xrZGgKYXNrZGpoa2FzZGpoYWtzaGRrYXNoZGt" | 46 "GtoYWxza2hka2xzamFoZGxramhhc2xka2hhc2xrZGgKYXNrZGpoa2FzZGpoYWtzaGRrYXNoZGt" |
| 43 "oYXNrZGhhc2tkaGthc2hka2Foc2RraGFrc2hka2FzaGRraGFzCmFza2pkaGFrc2hkbSxjbmtza" | 47 "oYXNrZGhhc2tkaGthc2hka2Foc2RraGFrc2hka2FzaGRraGFzCmFza2pkaGFrc2hkbSxjbmtza" |
| 44 "mFoZGtoYXNrZGhhc2tka2hrYXNkCjg3MzQ2ODEyNzQ2OGtqc2hka2FoZHNrZGhraApha3NqZGt" | 48 "mFoZGtoYXNrZGhhc2tka2hrYXNkCjg3MzQ2ODEyNzQ2OGtqc2hka2FoZHNrZGhraApha3NqZGt" |
| 45 "hc2Roa3NkaGthc2hka2FzaGtkaAohISomXkAqJl4qYWhpZGFzeWRpeWlhc1xcb1wKa2Fqc2Roa" | 49 "hc2Roa3NkaGthc2hka2FzaGtkaAohISomXkAqJl4qYWhpZGFzeWRpeWlhc1xcb1wKa2Fqc2Roa" |
| 46 "2FzaGRrYXNoZGsKYWtzamRoc2tkaAplbmQK"; | 50 "2FzaGRrYXNoZGsKYWtzamRoc2tkaAplbmQK"; |
| 47 const char kIframeDirectDownloadURL[] = | 51 const char kIframeDirectDownloadURL[] = |
| 48 "/safe_browsing/download_protection/navigation_observer/iframe.html"; | 52 "/safe_browsing/download_protection/navigation_observer/iframe.html"; |
| 49 const char kIframeRetargetingURL[] = | 53 const char kIframeRetargetingURL[] = |
| 50 "/safe_browsing/download_protection/navigation_observer/" | 54 "/safe_browsing/download_protection/navigation_observer/" |
| 51 "iframe_retargeting.html"; | 55 "iframe_retargeting.html"; |
| 52 const char kDownloadItemURL[] = "/safe_browsing/download_protection/signed.exe"; | 56 const char kDownloadItemURL[] = "/safe_browsing/download_protection/signed.exe"; |
| 57 const char kRedirectToLandingURL[] = | |
| 58 "/safe_browsing/download_protection/navigation_observer/" | |
| 59 "redirect_to_landing.html"; | |
| 60 const char kLandingURL[] = | |
| 61 "/safe_browsing/download_protection/navigation_observer/" | |
| 62 "landing.html"; | |
| 63 const char kLandingReferrerURL[] = | |
| 64 "/safe_browsing/download_protection/navigation_observer/" | |
| 65 "landing_referrer.html"; | |
| 66 const char kPageBeforeLandingReferrerURL[] = | |
| 67 "/safe_browsing/download_protection/navigation_observer/" | |
| 68 "page_before_landing_referrer.html"; | |
| 53 | 69 |
| 54 // Test class to help create SafeBrowsingNavigationObservers for each | 70 // Test class to help create SafeBrowsingNavigationObservers for each |
| 55 // WebContents before they are actually installed through AttachTabHelper. | 71 // WebContents before they are actually installed through AttachTabHelper. |
| 56 class TestNavigationObserverManager | 72 class TestNavigationObserverManager |
| 57 : public SafeBrowsingNavigationObserverManager { | 73 : public SafeBrowsingNavigationObserverManager { |
| 58 public: | 74 public: |
| 59 TestNavigationObserverManager() : SafeBrowsingNavigationObserverManager() { | 75 TestNavigationObserverManager() : SafeBrowsingNavigationObserverManager() { |
| 60 registrar_.Add(this, chrome::NOTIFICATION_TAB_ADDED, | 76 registrar_.Add(this, chrome::NOTIFICATION_TAB_ADDED, |
| 61 content::NotificationService::AllSources()); | 77 content::NotificationService::AllSources()); |
| 62 } | 78 } |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 86 class SBNavigationObserverBrowserTest : public InProcessBrowserTest { | 102 class SBNavigationObserverBrowserTest : public InProcessBrowserTest { |
| 87 public: | 103 public: |
| 88 SBNavigationObserverBrowserTest() {} | 104 SBNavigationObserverBrowserTest() {} |
| 89 | 105 |
| 90 void SetUpOnMainThread() override { | 106 void SetUpOnMainThread() override { |
| 91 // Disable Safe Browsing service since it is irrelevant to this test. | 107 // Disable Safe Browsing service since it is irrelevant to this test. |
| 92 browser()->profile()->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled, | 108 browser()->profile()->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled, |
| 93 false); | 109 false); |
| 94 ASSERT_TRUE(embedded_test_server()->Start()); | 110 ASSERT_TRUE(embedded_test_server()->Start()); |
| 95 host_resolver()->AddRule("*", "127.0.0.1"); | 111 host_resolver()->AddRule("*", "127.0.0.1"); |
| 96 // Navigate to test page. | |
| 97 ui_test_utils::NavigateToURL( | |
| 98 browser(), embedded_test_server()->GetURL(kSingleFrameTestURL)); | |
| 99 observer_manager_ = new TestNavigationObserverManager(); | 112 observer_manager_ = new TestNavigationObserverManager(); |
| 100 observer_ = new SafeBrowsingNavigationObserver( | 113 observer_ = new SafeBrowsingNavigationObserver( |
| 101 browser()->tab_strip_model()->GetActiveWebContents(), | 114 browser()->tab_strip_model()->GetActiveWebContents(), |
| 102 observer_manager_); | 115 observer_manager_); |
| 103 ASSERT_TRUE(observer_); | 116 ASSERT_TRUE(observer_); |
| 104 ASSERT_TRUE(InitialSetup()); | 117 ASSERT_TRUE(InitialSetup()); |
| 118 // Navigate to test page. | |
| 119 ui_test_utils::NavigateToURL( | |
| 120 browser(), embedded_test_server()->GetURL(kSingleFrameTestURL)); | |
| 105 } | 121 } |
| 106 | 122 |
| 107 bool InitialSetup() { | 123 bool InitialSetup() { |
| 108 if (!browser()) | 124 if (!browser()) |
| 109 return false; | 125 return false; |
| 110 | 126 |
| 111 if (!downloads_directory_.CreateUniqueTempDir()) | 127 if (!downloads_directory_.CreateUniqueTempDir()) |
| 112 return false; | 128 return false; |
| 113 | 129 |
| 114 // Set up default download path. | 130 // Set up default download path. |
| 115 browser()->profile()->GetPrefs()->SetFilePath( | 131 browser()->profile()->GetPrefs()->SetFilePath( |
| 116 prefs::kDownloadDefaultDirectory, downloads_directory_.GetPath()); | 132 prefs::kDownloadDefaultDirectory, downloads_directory_.GetPath()); |
| 117 browser()->profile()->GetPrefs()->SetFilePath( | 133 browser()->profile()->GetPrefs()->SetFilePath( |
| 118 prefs::kSaveFileDefaultDirectory, downloads_directory_.GetPath()); | 134 prefs::kSaveFileDefaultDirectory, downloads_directory_.GetPath()); |
| 119 browser()->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, | 135 browser()->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, |
| 120 false); | 136 false); |
| 121 content::DownloadManager* manager = | 137 content::DownloadManager* manager = |
| 122 content::BrowserContext::GetDownloadManager(browser()->profile()); | 138 content::BrowserContext::GetDownloadManager(browser()->profile()); |
| 123 DownloadPrefs::FromDownloadManager(manager)->ResetAutoOpen(); | 139 DownloadPrefs::FromDownloadManager(manager)->ResetAutoOpen(); |
| 124 manager->RemoveAllDownloads(); | 140 manager->RemoveAllDownloads(); |
| 125 | 141 |
| 126 return true; | 142 return true; |
| 127 } | 143 } |
| 128 | 144 |
| 129 void TearDownOnMainThread() override { delete observer_; } | 145 void TearDownOnMainThread() override { |
| 146 // Cancel unfinished download if any. | |
| 147 CancelDownloads(); | |
| 148 delete observer_; | |
| 149 } | |
| 130 | 150 |
| 131 // Most test cases will trigger downloads, though we don't really care if | 151 // Most test cases will trigger downloads, though we don't really care if |
| 132 // download completed or not. So we cancel downloads as soon as we record | 152 // download completed or not. So we cancel downloads as soon as we record |
| 133 // all the navigation events we need. | 153 // all the navigation events we need. |
| 134 void CancelDownloads() { | 154 void CancelDownloads() { |
| 135 std::vector<content::DownloadItem*> download_items; | 155 std::vector<DownloadItem*> download_items; |
| 136 content::DownloadManager* manager = | 156 content::DownloadManager* manager = |
| 137 content::BrowserContext::GetDownloadManager(browser()->profile()); | 157 content::BrowserContext::GetDownloadManager(browser()->profile()); |
| 138 manager->GetAllDownloads(&download_items); | 158 manager->GetAllDownloads(&download_items); |
| 139 for (auto item : download_items) { | 159 for (auto item : download_items) { |
| 140 if (!item->IsDone()) | 160 if (!item->IsDone()) |
| 141 item->Cancel(true); | 161 item->Cancel(true); |
| 142 } | 162 } |
| 143 } | 163 } |
| 144 | 164 |
| 145 // This function needs javascript support, only works on | 165 DownloadItem* GetDownload() { |
| 146 // navigation_observer_tests.html and | 166 std::vector<DownloadItem*> download_items; |
| 147 // navigation_observer_multi_frame_tests.html. | 167 content::DownloadManager* manager = |
| 168 content::BrowserContext::GetDownloadManager(browser()->profile()); | |
| 169 manager->GetAllDownloads(&download_items); | |
| 170 EXPECT_EQ(1ULL, download_items.size()); | |
| 171 return download_items[0]; | |
| 172 } | |
| 173 | |
| 174 // This function needs javascript support from test pages. | |
|
Charlie Reis
2016/12/09 22:00:25
Let's elaborate a bit on what it needs, so that ot
Jialiu Lin
2016/12/12 23:43:37
Done.
| |
| 148 void ClickTestLink(const char* test_name, | 175 void ClickTestLink(const char* test_name, |
| 149 int number_of_navigations) { | 176 int number_of_navigations, |
| 177 const GURL& page_clicked) { | |
| 150 TabStripModel* tab_strip = browser()->tab_strip_model(); | 178 TabStripModel* tab_strip = browser()->tab_strip_model(); |
| 151 content::WebContents* current_web_contents = | 179 content::WebContents* current_web_contents = |
| 152 tab_strip->GetActiveWebContents(); | 180 tab_strip->GetActiveWebContents(); |
| 153 ASSERT_TRUE(content::WaitForLoadStop(current_web_contents)); | 181 ASSERT_TRUE(content::WaitForLoadStop(current_web_contents)); |
| 154 content::TestNavigationObserver navigation_observer( | 182 content::TestNavigationObserver navigation_observer( |
| 155 current_web_contents, | 183 current_web_contents, |
| 156 number_of_navigations); | 184 number_of_navigations); |
| 157 navigation_observer.StartWatchingNewWebContents(); | 185 navigation_observer.StartWatchingNewWebContents(); |
| 158 // Execute test. | 186 // Execute test. |
| 159 std::string script = base::StringPrintf("clickLink('%s');", test_name); | 187 std::string script = base::StringPrintf("clickLink('%s');", test_name); |
| 160 ASSERT_TRUE(content::ExecuteScript(current_web_contents, script)); | 188 ASSERT_TRUE(content::ExecuteScript(current_web_contents, script)); |
| 161 // Wait for navigations on current tab and new tab (if any) to finish. | 189 // Wait for navigations on current tab and new tab (if any) to finish. |
| 162 navigation_observer.Wait(); | 190 navigation_observer.Wait(); |
| 163 navigation_observer.StopWatchingNewWebContents(); | 191 navigation_observer.StopWatchingNewWebContents(); |
| 164 // Cancel unfinished download if any. | 192 |
| 165 CancelDownloads(); | 193 // Since this test uses javascript to mimic clicking on a link (no actual |
| 194 // user gesture), and DidGetUserInteraction() does not respond to | |
| 195 // ExecuteScript(), is_user_initiated field in resulting NavigationEvents | |
| 196 // will always be false. Therefore, we need to make some adjustment to | |
| 197 // relevant NavigationEvent. | |
| 198 for (auto it = navigation_map()->begin(); it != navigation_map()->end(); | |
| 199 it++) { | |
| 200 for (NavigationEvent& nav_event : it->second) { | |
| 201 if (nav_event.source_url == page_clicked) { | |
| 202 nav_event.is_user_initiated = true; | |
| 203 return; | |
| 204 } | |
| 205 } | |
| 206 } | |
| 166 } | 207 } |
| 167 | 208 |
| 168 void VerifyNavigationEvent(const GURL& expected_source_url, | 209 void VerifyNavigationEvent(const GURL& expected_source_url, |
| 169 const GURL& expected_source_main_frame_url, | 210 const GURL& expected_source_main_frame_url, |
| 170 const GURL& expected_original_request_url, | 211 const GURL& expected_original_request_url, |
| 171 const GURL& expected_destination_url, | 212 const GURL& expected_destination_url, |
| 172 bool expected_is_user_initiated, | 213 bool expected_is_user_initiated, |
| 173 bool expected_has_committed, | 214 bool expected_has_committed, |
| 174 bool expected_has_server_redirect, | 215 bool expected_has_server_redirect, |
| 175 const NavigationEvent& actual_nav_event) { | 216 const NavigationEvent& actual_nav_event) { |
| 176 EXPECT_EQ(expected_source_url, actual_nav_event.source_url); | 217 EXPECT_EQ(expected_source_url, actual_nav_event.source_url); |
| 177 EXPECT_EQ(expected_source_main_frame_url, | 218 EXPECT_EQ(expected_source_main_frame_url, |
| 178 actual_nav_event.source_main_frame_url); | 219 actual_nav_event.source_main_frame_url); |
| 179 EXPECT_EQ(expected_original_request_url, | 220 EXPECT_EQ(expected_original_request_url, |
| 180 actual_nav_event.original_request_url); | 221 actual_nav_event.original_request_url); |
| 181 EXPECT_EQ(expected_destination_url, actual_nav_event.destination_url); | 222 EXPECT_EQ(expected_destination_url, actual_nav_event.destination_url); |
| 182 EXPECT_EQ(expected_is_user_initiated, actual_nav_event.is_user_initiated); | 223 EXPECT_EQ(expected_is_user_initiated, actual_nav_event.is_user_initiated); |
| 183 EXPECT_EQ(expected_has_committed, actual_nav_event.has_committed); | 224 EXPECT_EQ(expected_has_committed, actual_nav_event.has_committed); |
| 184 EXPECT_EQ(expected_has_server_redirect, | 225 EXPECT_EQ(expected_has_server_redirect, |
| 185 actual_nav_event.has_server_redirect); | 226 actual_nav_event.has_server_redirect); |
| 186 } | 227 } |
| 187 | 228 |
| 229 void VerifyReferrerChainEntry( | |
| 230 const GURL& expected_url, | |
| 231 ReferrerChainEntry::URLType expected_type, | |
| 232 const std::string& expected_ip_address, | |
| 233 const GURL& expected_referrer_url, | |
| 234 const GURL& expected_referrer_main_frame_url, | |
| 235 bool expected_is_retargeting, | |
| 236 ReferrerChainEntry actual_entry) { | |
| 237 EXPECT_EQ(expected_url.spec(), actual_entry.url()); | |
| 238 EXPECT_EQ(expected_type, actual_entry.type()); | |
| 239 if (expected_ip_address.empty()) { | |
| 240 ASSERT_EQ(0, actual_entry.ip_address_size()); | |
| 241 } else { | |
| 242 ASSERT_EQ(1, actual_entry.ip_address_size()); | |
| 243 EXPECT_EQ(expected_ip_address, actual_entry.ip_address(0)); | |
| 244 } | |
| 245 EXPECT_EQ(expected_referrer_url.spec(), actual_entry.referrer_url()); | |
| 246 EXPECT_EQ(expected_referrer_main_frame_url.spec(), | |
| 247 actual_entry.referrer_main_frame_url()); | |
| 248 EXPECT_EQ(expected_is_retargeting, actual_entry.is_retargeting()); | |
| 249 } | |
| 250 | |
| 251 std::vector<ReferrerChainEntry> IdentifyReferrerChain( | |
| 252 DownloadItem* download) { | |
| 253 std::vector<ReferrerChainEntry> referrer_chain; | |
| 254 int download_tab_id = | |
| 255 SessionTabHelper::IdForTab(download->GetWebContents()); | |
| 256 observer_manager_->IdentifyReferrerChain( | |
|
Charlie Reis
2016/12/09 22:00:25
Please include an EXPECT_EQ for the return value.
Jialiu Lin
2016/12/12 23:43:37
Done.
| |
| 257 download->GetURL(), download_tab_id, 2, &referrer_chain); | |
|
Charlie Reis
2016/12/09 22:00:24
Let's document that 2 is the user gesture limit.
Jialiu Lin
2016/12/12 23:43:37
Done.
| |
| 258 return referrer_chain; | |
| 259 } | |
| 260 | |
| 188 void VerifyHostToIpMap() { | 261 void VerifyHostToIpMap() { |
| 189 // Since all testing pages have the same host, there is only one entry in | 262 // Since all testing pages have the same host, there is only one entry in |
| 190 // host_to_ip_map_. | 263 // host_to_ip_map_. |
| 191 SafeBrowsingNavigationObserverManager::HostToIpMap* actual_host_ip_map = | 264 SafeBrowsingNavigationObserverManager::HostToIpMap* actual_host_ip_map = |
| 192 host_to_ip_map(); | 265 host_to_ip_map(); |
| 193 ASSERT_EQ(std::size_t(1), actual_host_ip_map->size()); | 266 ASSERT_EQ(1ULL, actual_host_ip_map->size()); |
|
Charlie Reis
2016/12/09 22:00:25
I'm curious, is there a reason to use ULL here? I
Jialiu Lin
2016/12/12 23:43:37
You're right. U is more commonly used in size lite
| |
| 194 auto ip_list = | 267 auto ip_list = |
| 195 actual_host_ip_map->at(embedded_test_server()->base_url().host()); | 268 actual_host_ip_map->at(embedded_test_server()->base_url().host()); |
| 196 ASSERT_EQ(std::size_t(1), ip_list.size()); | 269 ASSERT_EQ(1ULL, ip_list.size()); |
| 197 EXPECT_EQ(embedded_test_server()->host_port_pair().host(), | 270 EXPECT_EQ(embedded_test_server()->host_port_pair().host(), |
| 198 ip_list.back().ip); | 271 ip_list.back().ip); |
| 199 } | 272 } |
| 200 | 273 |
| 201 SafeBrowsingNavigationObserverManager::NavigationMap* navigation_map() { | 274 SafeBrowsingNavigationObserverManager::NavigationMap* navigation_map() { |
| 202 return observer_manager_->navigation_map(); | 275 return observer_manager_->navigation_map(); |
| 203 } | 276 } |
| 204 | 277 |
| 205 SafeBrowsingNavigationObserverManager::HostToIpMap* host_to_ip_map() { | 278 SafeBrowsingNavigationObserverManager::HostToIpMap* host_to_ip_map() { |
| 206 return observer_manager_->host_to_ip_map(); | 279 return observer_manager_->host_to_ip_map(); |
| 207 } | 280 } |
| 208 | 281 |
| 209 protected: | 282 protected: |
| 210 SafeBrowsingNavigationObserverManager* observer_manager_; | 283 SafeBrowsingNavigationObserverManager* observer_manager_; |
| 211 SafeBrowsingNavigationObserver* observer_; | 284 SafeBrowsingNavigationObserver* observer_; |
| 212 | 285 |
| 213 private: | 286 private: |
| 214 base::ScopedTempDir downloads_directory_; | 287 base::ScopedTempDir downloads_directory_; |
| 215 }; | 288 }; |
| 216 | 289 |
| 290 // Type download URL into address bar and start download on the same page. | |
| 291 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, TypeInURLDownload) { | |
| 292 ui_test_utils::NavigateToURL( | |
| 293 browser(), embedded_test_server()->GetURL(kDownloadItemURL)); | |
| 294 GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL); | |
| 295 GURL download_url = embedded_test_server()->GetURL(kDownloadItemURL); | |
| 296 std::string test_server_ip(embedded_test_server()->host_port_pair().host()); | |
| 297 auto nav_map = navigation_map(); | |
| 298 ASSERT_TRUE(nav_map); | |
| 299 ASSERT_EQ(2ULL, nav_map->size()); | |
| 300 ASSERT_EQ(1ULL, nav_map->at(download_url).size()); | |
| 301 ASSERT_EQ(1ULL, nav_map->at(initial_url).size()); | |
| 302 VerifyNavigationEvent(GURL(), // source_url | |
| 303 GURL(), // source_main_frame_url | |
| 304 initial_url, // original_request_url | |
| 305 initial_url, // destination_url | |
| 306 true, // is_user_initiated, | |
| 307 true, // has_committed | |
| 308 false, // has_server_redirect | |
| 309 nav_map->at(initial_url).at(0)); | |
| 310 VerifyNavigationEvent(GURL(), // source_url | |
| 311 GURL(), // source_main_frame_url | |
| 312 download_url, // original_request_url | |
| 313 download_url, // destination_url | |
| 314 true, // is_user_initiated, | |
| 315 false, // has_committed | |
| 316 false, // has_server_redirect | |
| 317 nav_map->at(download_url).at(0)); | |
| 318 VerifyHostToIpMap(); | |
| 319 auto referrer_chain = IdentifyReferrerChain(GetDownload()); | |
|
Charlie Reis
2016/12/09 22:00:25
nit: Blank line before (same in all tests). This
Jialiu Lin
2016/12/12 23:43:37
Done.
| |
| 320 ASSERT_EQ(1ULL, referrer_chain.size()); | |
| 321 VerifyReferrerChainEntry( | |
| 322 download_url, // url | |
| 323 ReferrerChainEntry::DOWNLOAD_URL, // type | |
| 324 test_server_ip, // ip_address | |
| 325 GURL(), // referrer_url | |
| 326 GURL(), // referrer_main_frame_url | |
| 327 false, // is_retargeting | |
| 328 referrer_chain[0]); | |
| 329 } | |
| 217 // Click on a link and start download on the same page. | 330 // Click on a link and start download on the same page. |
| 218 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, DirectDownload) { | 331 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, DirectDownload) { |
| 219 ClickTestLink("direct_download", 1); | |
| 220 GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL); | 332 GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL); |
| 333 ClickTestLink("direct_download", 1, initial_url); | |
| 221 GURL download_url = embedded_test_server()->GetURL(kDownloadItemURL); | 334 GURL download_url = embedded_test_server()->GetURL(kDownloadItemURL); |
| 335 std::string test_server_ip(embedded_test_server()->host_port_pair().host()); | |
| 222 auto nav_map = navigation_map(); | 336 auto nav_map = navigation_map(); |
| 223 ASSERT_TRUE(nav_map); | 337 ASSERT_TRUE(nav_map); |
| 224 ASSERT_EQ(std::size_t(1), nav_map->size()); | 338 ASSERT_EQ(2ULL, nav_map->size()); |
| 225 ASSERT_EQ(std::size_t(1), nav_map->at(download_url).size()); | 339 ASSERT_EQ(1ULL, nav_map->at(download_url).size()); |
| 226 // Since this test uses javascript to mimic clicking on a link (no actual user | 340 ASSERT_EQ(1ULL, nav_map->at(initial_url).size()); |
| 227 // gesture), and DidGetUserInteraction() does not respond to ExecuteScript(), | 341 VerifyNavigationEvent(GURL(), // source_url |
| 228 // therefore is_user_initiated is false. | 342 GURL(), // source_main_frame_url |
| 343 initial_url, // original_request_url | |
| 344 initial_url, // destination_url | |
| 345 true, // is_user_initiated, | |
| 346 true, // has_committed | |
| 347 false, // has_server_redirect | |
| 348 nav_map->at(initial_url).at(0)); | |
| 229 VerifyNavigationEvent(initial_url, // source_url | 349 VerifyNavigationEvent(initial_url, // source_url |
| 230 initial_url, // source_main_frame_url | 350 initial_url, // source_main_frame_url |
| 231 download_url, // original_request_url | 351 download_url, // original_request_url |
| 232 download_url, // destination_url | 352 download_url, // destination_url |
| 233 false, // is_user_initiated, | 353 true, // is_user_initiated, |
| 234 false, // has_committed | 354 false, // has_committed |
| 235 false, // has_server_redirect | 355 false, // has_server_redirect |
| 236 nav_map->at(download_url).at(0)); | 356 nav_map->at(download_url).at(0)); |
| 237 VerifyHostToIpMap(); | 357 VerifyHostToIpMap(); |
| 358 auto referrer_chain = IdentifyReferrerChain(GetDownload()); | |
| 359 ASSERT_EQ(2ULL, referrer_chain.size()); | |
| 360 VerifyReferrerChainEntry( | |
| 361 download_url, // url | |
| 362 ReferrerChainEntry::DOWNLOAD_URL, // type | |
| 363 test_server_ip, // ip_address | |
| 364 initial_url, // referrer_url | |
| 365 initial_url, // referrer_main_frame_url | |
| 366 false, // is_retargeting | |
| 367 referrer_chain[0]); | |
| 368 VerifyReferrerChainEntry( | |
| 369 initial_url, // url | |
| 370 ReferrerChainEntry::LANDING_PAGE, // type | |
| 371 test_server_ip, // ip_address | |
| 372 GURL(), // referrer_url | |
| 373 GURL(), // referrer_main_frame_url | |
| 374 false, // is_retargeting | |
| 375 referrer_chain[1]); | |
| 238 } | 376 } |
| 239 | 377 |
| 240 // Click on a link with rel="noreferrer" attribute, and start download on the | 378 // Click on a link with rel="noreferrer" attribute, and start download on the |
| 241 // same page. | 379 // same page. |
| 242 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, | 380 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, |
| 243 DirectDownloadNoReferrer) { | 381 DirectDownloadNoReferrer) { |
| 244 ClickTestLink("direct_download_noreferrer", 1); | |
| 245 GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL); | 382 GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL); |
| 383 ClickTestLink("direct_download_noreferrer", 1, initial_url); | |
| 246 GURL download_url = embedded_test_server()->GetURL(kDownloadItemURL); | 384 GURL download_url = embedded_test_server()->GetURL(kDownloadItemURL); |
| 385 std::string test_server_ip(embedded_test_server()->host_port_pair().host()); | |
| 247 auto nav_map = navigation_map(); | 386 auto nav_map = navigation_map(); |
| 248 ASSERT_TRUE(nav_map); | 387 ASSERT_TRUE(nav_map); |
| 249 ASSERT_EQ(std::size_t(1), nav_map->size()); | 388 ASSERT_EQ(2ULL, nav_map->size()); |
| 250 ASSERT_EQ(std::size_t(1), nav_map->at(download_url).size()); | 389 ASSERT_EQ(1ULL, nav_map->at(download_url).size()); |
| 390 ASSERT_EQ(1ULL, nav_map->at(initial_url).size()); | |
| 391 VerifyNavigationEvent(GURL(), // source_url | |
| 392 GURL(), // source_main_frame_url | |
| 393 initial_url, // original_request_url | |
| 394 initial_url, // destination_url | |
| 395 true, // is_user_initiated, | |
| 396 true, // has_committed | |
| 397 false, // has_server_redirect | |
| 398 nav_map->at(initial_url).at(0)); | |
| 251 VerifyNavigationEvent(initial_url, // source_url | 399 VerifyNavigationEvent(initial_url, // source_url |
| 252 initial_url, // source_main_frame_url | 400 initial_url, // source_main_frame_url |
| 253 download_url, // original_request_url | 401 download_url, // original_request_url |
| 254 download_url, // destination_url | 402 download_url, // destination_url |
| 255 false, // is_user_initiated, | 403 true, // is_user_initiated, |
| 256 false, // has_committed | 404 false, // has_committed |
| 257 false, // has_server_redirect | 405 false, // has_server_redirect |
| 258 nav_map->at(download_url).at(0)); | 406 nav_map->at(download_url).at(0)); |
| 259 VerifyHostToIpMap(); | 407 VerifyHostToIpMap(); |
| 408 auto referrer_chain = IdentifyReferrerChain(GetDownload()); | |
| 409 ASSERT_EQ(2ULL, referrer_chain.size()); | |
| 410 VerifyReferrerChainEntry( | |
| 411 download_url, // url | |
| 412 ReferrerChainEntry::DOWNLOAD_URL, // type | |
| 413 test_server_ip, // ip_address | |
| 414 initial_url, // referrer_url | |
| 415 initial_url, // referrer_main_frame_url | |
| 416 false, // is_retargeting | |
| 417 referrer_chain[0]); | |
| 418 VerifyReferrerChainEntry( | |
| 419 initial_url, // url | |
| 420 ReferrerChainEntry::LANDING_PAGE, // type | |
| 421 test_server_ip, // ip_address | |
| 422 GURL(), // referrer_url | |
| 423 GURL(), // referrer_main_frame_url | |
| 424 false, // is_retargeting | |
| 425 referrer_chain[1]); | |
| 260 } | 426 } |
| 261 | 427 |
| 262 // Click on a link with rel="noreferrer" attribute, and start download in a | 428 // Click on a link with rel="noreferrer" attribute, and start download in a |
| 263 // new tab using target=_blank. | 429 // new tab using target=_blank. |
| 264 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, | 430 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, |
| 265 DirectDownloadNoReferrerTargetBlank) { | 431 DirectDownloadNoReferrerTargetBlank) { |
| 266 ClickTestLink("direct_download_noreferrer_target_blank", 1); | |
| 267 GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL); | 432 GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL); |
| 433 ClickTestLink("direct_download_noreferrer_target_blank", 1, initial_url); | |
| 268 GURL download_url = embedded_test_server()->GetURL(kDownloadItemURL); | 434 GURL download_url = embedded_test_server()->GetURL(kDownloadItemURL); |
| 435 std::string test_server_ip(embedded_test_server()->host_port_pair().host()); | |
| 269 auto nav_map = navigation_map(); | 436 auto nav_map = navigation_map(); |
| 270 ASSERT_TRUE(nav_map); | 437 ASSERT_TRUE(nav_map); |
| 271 ASSERT_EQ(std::size_t(1), nav_map->size()); | 438 ASSERT_EQ(2ULL, nav_map->size()); |
| 272 ASSERT_EQ(std::size_t(2), nav_map->at(download_url).size()); | 439 ASSERT_EQ(2ULL, nav_map->at(download_url).size()); |
| 273 // The first NavigationEvent was obtained from NOIFICATION_RETARGETING. | 440 ASSERT_EQ(1ULL, nav_map->at(initial_url).size()); |
| 441 VerifyNavigationEvent(GURL(), // source_url | |
| 442 GURL(), // source_main_frame_url | |
| 443 initial_url, // original_request_url | |
| 444 initial_url, // destination_url | |
| 445 true, // is_user_initiated, | |
| 446 true, // has_committed | |
| 447 false, // has_server_redirect | |
| 448 nav_map->at(initial_url).at(0)); | |
| 449 // The next NavigationEvent was obtained from NOIFICATION_RETARGETING. | |
| 274 // TODO(jialiul): After https://crbug.com/651895 is fixed, we'll no longer | 450 // TODO(jialiul): After https://crbug.com/651895 is fixed, we'll no longer |
| 275 // listen to NOTIFICATION_RETARGETING, hence only one NavigationEvent will | 451 // listen to NOTIFICATION_RETARGETING, hence only one NavigationEvent will |
| 276 // be observed with the true initator URL. This applies to other new tab | 452 // be observed with the true initator URL. This applies to other new tab |
| 277 // download, and target blank download test cases too. | 453 // download, and target blank download test cases too. |
| 278 VerifyNavigationEvent(initial_url, // source_url | 454 VerifyNavigationEvent(initial_url, // source_url |
| 279 initial_url, // source_main_frame_url | 455 initial_url, // source_main_frame_url |
| 280 download_url, // original_request_url | 456 download_url, // original_request_url |
| 281 download_url, // destination_url | 457 download_url, // destination_url |
| 282 false, // is_user_initiated, | 458 true, // is_user_initiated, |
| 283 false, // has_committed | 459 false, // has_committed |
| 284 false, // has_server_redirect | 460 false, // has_server_redirect |
| 285 nav_map->at(download_url).at(0)); | 461 nav_map->at(download_url).at(0)); |
| 286 // The second one is the actual navigation which triggers download. | 462 // This one is the actual navigation which triggers download. |
| 287 VerifyNavigationEvent(GURL(), // source_url | 463 VerifyNavigationEvent(GURL(), // source_url |
| 288 GURL(), // source_main_frame_url | 464 GURL(), // source_main_frame_url |
| 289 download_url, // original_request_url | 465 download_url, // original_request_url |
| 290 download_url, // destination_url | 466 download_url, // destination_url |
| 291 false, // is_user_initiated, | 467 false, // is_user_initiated, |
| 292 false, // has_committed | 468 false, // has_committed |
| 293 false, // has_server_redirect | 469 false, // has_server_redirect |
| 294 nav_map->at(download_url).at(1)); | 470 nav_map->at(download_url).at(1)); |
| 295 VerifyHostToIpMap(); | 471 VerifyHostToIpMap(); |
| 472 auto referrer_chain = IdentifyReferrerChain(GetDownload()); | |
| 473 ASSERT_EQ(2ULL, referrer_chain.size()); | |
| 474 VerifyReferrerChainEntry( | |
| 475 download_url, // url | |
| 476 ReferrerChainEntry::DOWNLOAD_URL, // type | |
| 477 test_server_ip, // ip_address | |
| 478 initial_url, // referrer_url | |
| 479 initial_url, // referrer_main_frame_url | |
| 480 true, // is_retargeting | |
| 481 referrer_chain[0]); | |
| 482 VerifyReferrerChainEntry( | |
| 483 initial_url, // url | |
| 484 ReferrerChainEntry::LANDING_PAGE, // type | |
| 485 test_server_ip, // ip_address | |
| 486 GURL(), // referrer_url | |
| 487 GURL(), // referrer_main_frame_url | |
| 488 false, // is_retargeting | |
| 489 referrer_chain[1]); | |
| 296 } | 490 } |
| 297 | 491 |
| 298 // Click on a link which navigates to a page then redirects to a download using | 492 // Click on a link which navigates to a page then redirects to a download using |
| 299 // META HTTP-EQUIV="refresh". All transitions happen in the same tab. | 493 // META HTTP-EQUIV="refresh". All transitions happen in the same tab. |
| 300 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, | 494 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, |
| 301 SingleMetaRefreshRedirect) { | 495 SingleMetaRefreshRedirect) { |
| 302 ClickTestLink("single_meta_refresh_redirect", 2); | |
| 303 GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL); | 496 GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL); |
| 497 ClickTestLink("single_meta_refresh_redirect", 2, initial_url); | |
| 304 GURL redirect_url = embedded_test_server()->GetURL(kRedirectURL); | 498 GURL redirect_url = embedded_test_server()->GetURL(kRedirectURL); |
| 305 GURL download_url = embedded_test_server()->GetURL(kDownloadItemURL); | 499 GURL download_url = embedded_test_server()->GetURL(kDownloadItemURL); |
| 500 std::string test_server_ip(embedded_test_server()->host_port_pair().host()); | |
| 306 auto nav_map = navigation_map(); | 501 auto nav_map = navigation_map(); |
| 307 ASSERT_TRUE(nav_map); | 502 ASSERT_TRUE(nav_map); |
| 308 // Since unlike server redirects client redirects commit and then generate a | 503 // Since unlike server redirects client redirects commit and then generate a |
| 309 // second navigation, our observer records two NavigationEvents for this test. | 504 // second navigation, our observer records two NavigationEvents for this test. |
| 310 ASSERT_EQ(std::size_t(2), nav_map->size()); | 505 ASSERT_EQ(std::size_t(3), nav_map->size()); |
| 311 ASSERT_EQ(std::size_t(1), nav_map->at(redirect_url).size()); | 506 ASSERT_EQ(1ULL, nav_map->at(redirect_url).size()); |
| 312 ASSERT_EQ(std::size_t(1), nav_map->at(download_url).size()); | 507 ASSERT_EQ(1ULL, nav_map->at(download_url).size()); |
| 508 ASSERT_EQ(1ULL, nav_map->at(initial_url).size()); | |
| 509 VerifyNavigationEvent(GURL(), // source_url | |
| 510 GURL(), // source_main_frame_url | |
| 511 initial_url, // original_request_url | |
| 512 initial_url, // destination_url | |
| 513 true, // is_user_initiated, | |
| 514 true, // has_committed | |
| 515 false, // has_server_redirect | |
| 516 nav_map->at(initial_url).at(0)); | |
| 313 VerifyNavigationEvent(initial_url, // source_url | 517 VerifyNavigationEvent(initial_url, // source_url |
| 314 initial_url, // source_main_frame_url | 518 initial_url, // source_main_frame_url |
| 315 redirect_url, // original_request_url | 519 redirect_url, // original_request_url |
| 316 redirect_url, // destination_url | 520 redirect_url, // destination_url |
| 317 false, // is_user_initiated, | 521 true, // is_user_initiated, |
| 318 true, // has_committed | 522 true, // has_committed |
| 319 false, // has_server_redirect | 523 false, // has_server_redirect |
| 320 nav_map->at(redirect_url).at(0)); | 524 nav_map->at(redirect_url).at(0)); |
| 321 VerifyNavigationEvent(redirect_url, // source_url | 525 VerifyNavigationEvent(redirect_url, // source_url |
| 322 redirect_url, // source_main_frame_url | 526 redirect_url, // source_main_frame_url |
| 323 download_url, // original_request_url | 527 download_url, // original_request_url |
| 324 download_url, // destination_url | 528 download_url, // destination_url |
| 325 false, // is_user_initiated, | 529 false, // is_user_initiated, |
| 326 false, // has_committed | 530 false, // has_committed |
| 327 false, // has_server_redirect | 531 false, // has_server_redirect |
| 328 nav_map->at(download_url).at(0)); | 532 nav_map->at(download_url).at(0)); |
| 329 VerifyHostToIpMap(); | 533 VerifyHostToIpMap(); |
| 534 auto referrer_chain = IdentifyReferrerChain(GetDownload()); | |
| 535 ASSERT_EQ(std::size_t(3), referrer_chain.size()); | |
| 536 VerifyReferrerChainEntry( | |
| 537 download_url, // url | |
| 538 ReferrerChainEntry::DOWNLOAD_URL, // type | |
| 539 test_server_ip, // ip_address | |
| 540 redirect_url, // referrer_url | |
| 541 redirect_url, // referrer_main_frame_url | |
| 542 false, // is_retargeting | |
| 543 referrer_chain[0]); | |
| 544 VerifyReferrerChainEntry( | |
| 545 redirect_url, // url | |
| 546 ReferrerChainEntry::CLIENT_REDIRECT, // type | |
| 547 test_server_ip, // ip_address | |
| 548 initial_url, // referrer_url | |
| 549 initial_url, // referrer_main_frame_url | |
| 550 false, // is_retargeting | |
| 551 referrer_chain[1]); | |
| 552 VerifyReferrerChainEntry( | |
| 553 initial_url, // url | |
| 554 ReferrerChainEntry::LANDING_PAGE, // type | |
| 555 test_server_ip, // ip_address | |
| 556 GURL(), // referrer_url | |
| 557 GURL(), // referrer_main_frame_url | |
| 558 false, // is_retargeting | |
| 559 referrer_chain[2]); | |
| 330 } | 560 } |
| 331 | 561 |
| 332 // https://crbug.com/667784: The test is flaky on Linux. | 562 // https://crbug.com/667784: The test is flaky on Linux. |
| 333 #if defined(OS_LINUX) | 563 #if defined(OS_LINUX) |
| 334 #define MAYBE_SingleMetaRefreshRedirectTargetBlank DISABLED_SingleMetaRefreshRed irectTargetBlank | 564 #define MAYBE_SingleMetaRefreshRedirectTargetBlank DISABLED_SingleMetaRefreshRed irectTargetBlank |
| 335 #else | 565 #else |
| 336 #define MAYBE_SingleMetaRefreshRedirectTargetBlank SingleMetaRefreshRedirectTarg etBlank | 566 #define MAYBE_SingleMetaRefreshRedirectTargetBlank SingleMetaRefreshRedirectTarg etBlank |
| 337 #endif | 567 #endif |
| 338 // Click on a link which navigates to a page then redirects to a download using | 568 // Click on a link which navigates to a page then redirects to a download using |
| 339 // META HTTP-EQUIV="refresh". First navigation happens in target blank. | 569 // META HTTP-EQUIV="refresh". First navigation happens in target blank. |
| 340 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, | 570 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, |
| 341 MAYBE_SingleMetaRefreshRedirectTargetBlank) { | 571 MAYBE_SingleMetaRefreshRedirectTargetBlank) { |
| 342 ClickTestLink("single_meta_refresh_redirect_target_blank", 2); | |
| 343 GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL); | 572 GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL); |
| 573 ClickTestLink("single_meta_refresh_redirect_target_blank", 2, initial_url); | |
| 344 GURL redirect_url = embedded_test_server()->GetURL(kRedirectURL); | 574 GURL redirect_url = embedded_test_server()->GetURL(kRedirectURL); |
| 345 GURL download_url = embedded_test_server()->GetURL(kDownloadItemURL); | 575 GURL download_url = embedded_test_server()->GetURL(kDownloadItemURL); |
| 576 std::string test_server_ip(embedded_test_server()->host_port_pair().host()); | |
| 346 auto nav_map = navigation_map(); | 577 auto nav_map = navigation_map(); |
| 347 ASSERT_TRUE(nav_map); | 578 ASSERT_TRUE(nav_map); |
| 348 ASSERT_EQ(std::size_t(2), nav_map->size()); | 579 ASSERT_EQ(std::size_t(3), nav_map->size()); |
| 349 ASSERT_EQ(std::size_t(2), nav_map->at(redirect_url).size()); | 580 ASSERT_EQ(2ULL, nav_map->at(redirect_url).size()); |
| 350 ASSERT_EQ(std::size_t(1), nav_map->at(download_url).size()); | 581 ASSERT_EQ(1ULL, nav_map->at(download_url).size()); |
| 582 ASSERT_EQ(1ULL, nav_map->at(initial_url).size()); | |
| 583 VerifyNavigationEvent(GURL(), // source_url | |
| 584 GURL(), // source_main_frame_url | |
| 585 initial_url, // original_request_url | |
| 586 initial_url, // destination_url | |
| 587 true, // is_user_initiated, | |
| 588 true, // has_committed | |
| 589 false, // has_server_redirect | |
| 590 nav_map->at(initial_url).at(0)); | |
| 351 // TODO(jialiul): After https://crbug.com/651895 is fixed, we'll no longer | 591 // TODO(jialiul): After https://crbug.com/651895 is fixed, we'll no longer |
| 352 // listen to NOTIFICATION_RETARGETING, hence only two NavigationEvents will | 592 // listen to NOTIFICATION_RETARGETING, hence only two NavigationEvents will |
| 353 // be observed with the true initator URL. | 593 // be observed with the true initator URL. |
| 354 VerifyNavigationEvent(initial_url, // source_url | 594 VerifyNavigationEvent(initial_url, // source_url |
| 355 initial_url, // source_main_frame_url | 595 initial_url, // source_main_frame_url |
| 356 redirect_url, // original_request_url | 596 redirect_url, // original_request_url |
| 357 redirect_url, // destination_url | 597 redirect_url, // destination_url |
| 358 false, // is_user_initiated, | 598 true, // is_user_initiated, |
| 359 false, // has_committed | 599 false, // has_committed |
| 360 false, // has_server_redirect | 600 false, // has_server_redirect |
| 361 nav_map->at(redirect_url).at(0)); | 601 nav_map->at(redirect_url).at(0)); |
| 362 VerifyNavigationEvent(GURL(), // source_url | 602 VerifyNavigationEvent(GURL(), // source_url |
| 363 GURL(), // source_main_frame_url | 603 GURL(), // source_main_frame_url |
| 364 redirect_url, // original_request_url | 604 redirect_url, // original_request_url |
| 365 redirect_url, // destination_url | 605 redirect_url, // destination_url |
| 366 false, // is_user_initiated, | 606 false, // is_user_initiated, |
| 367 true, // has_committed | 607 true, // has_committed |
| 368 false, // has_server_redirect | 608 false, // has_server_redirect |
| 369 nav_map->at(redirect_url).at(1)); | 609 nav_map->at(redirect_url).at(1)); |
| 370 VerifyNavigationEvent(redirect_url, // source_url | 610 VerifyNavigationEvent(redirect_url, // source_url |
| 371 redirect_url, // source_main_frame_url | 611 redirect_url, // source_main_frame_url |
| 372 download_url, // original_request_url | 612 download_url, // original_request_url |
| 373 download_url, // destination_url | 613 download_url, // destination_url |
| 374 false, // is_user_initiated, | 614 false, // is_user_initiated, |
| 375 false, // has_committed | 615 false, // has_committed |
| 376 false, // has_server_redirect | 616 false, // has_server_redirect |
| 377 nav_map->at(download_url).at(0)); | 617 nav_map->at(download_url).at(0)); |
| 378 VerifyHostToIpMap(); | 618 VerifyHostToIpMap(); |
| 619 auto referrer_chain = IdentifyReferrerChain(GetDownload()); | |
| 620 ASSERT_EQ(std::size_t(3), referrer_chain.size()); | |
| 621 VerifyReferrerChainEntry( | |
| 622 download_url, // url | |
| 623 ReferrerChainEntry::DOWNLOAD_URL, // type | |
| 624 test_server_ip, // ip_address | |
| 625 redirect_url, // referrer_url | |
| 626 redirect_url, // referrer_main_frame_url | |
| 627 false, // is_retargeting | |
| 628 referrer_chain[0]); | |
| 629 VerifyReferrerChainEntry( | |
| 630 redirect_url, // url | |
| 631 ReferrerChainEntry::CLIENT_REDIRECT, // type | |
| 632 test_server_ip, // ip_address | |
| 633 initial_url, // referrer_url | |
| 634 initial_url, // referrer_main_frame_url | |
| 635 true, // is_retargeting | |
| 636 referrer_chain[1]); | |
| 637 VerifyReferrerChainEntry( | |
| 638 initial_url, // url | |
| 639 ReferrerChainEntry::LANDING_PAGE, // type | |
| 640 test_server_ip, // ip_address | |
| 641 GURL(), // referrer_url | |
| 642 GURL(), // referrer_main_frame_url | |
| 643 false, // is_retargeting | |
| 644 referrer_chain[2]); | |
| 379 } | 645 } |
| 380 | 646 |
| 381 // Click on a link which redirects twice before reaching download using | 647 // Click on a link which redirects twice before reaching download using |
| 382 // META HTTP-EQUIV="refresh". All transitions happen in the same tab. | 648 // META HTTP-EQUIV="refresh". All transitions happen in the same tab. |
| 383 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, | 649 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, |
| 384 MultiMetaRefreshRedirects) { | 650 MultiMetaRefreshRedirects) { |
| 385 ClickTestLink("multiple_meta_refresh_redirects", 3); | |
| 386 GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL); | 651 GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL); |
| 652 ClickTestLink("multiple_meta_refresh_redirects", 3, initial_url); | |
| 387 GURL first_redirect_url = embedded_test_server()->GetURL( | 653 GURL first_redirect_url = embedded_test_server()->GetURL( |
| 388 "/safe_browsing/download_protection/navigation_observer/" | 654 "/safe_browsing/download_protection/navigation_observer/" |
| 389 "double_redirect.html"); | 655 "double_redirect.html"); |
| 390 GURL second_redirect_url = embedded_test_server()->GetURL(kRedirectURL); | 656 GURL second_redirect_url = embedded_test_server()->GetURL(kRedirectURL); |
| 391 GURL download_url = embedded_test_server()->GetURL(kDownloadItemURL); | 657 GURL download_url = embedded_test_server()->GetURL(kDownloadItemURL); |
| 658 std::string test_server_ip(embedded_test_server()->host_port_pair().host()); | |
| 392 auto nav_map = navigation_map(); | 659 auto nav_map = navigation_map(); |
| 393 ASSERT_TRUE(nav_map); | 660 ASSERT_TRUE(nav_map); |
| 394 ASSERT_EQ(std::size_t(3), nav_map->size()); | 661 ASSERT_EQ(std::size_t(4), nav_map->size()); |
| 395 ASSERT_EQ(std::size_t(1), nav_map->at(first_redirect_url).size()); | 662 ASSERT_EQ(1ULL, nav_map->at(first_redirect_url).size()); |
| 396 ASSERT_EQ(std::size_t(1), nav_map->at(second_redirect_url).size()); | 663 ASSERT_EQ(1ULL, nav_map->at(second_redirect_url).size()); |
| 397 ASSERT_EQ(std::size_t(1), nav_map->at(download_url).size()); | 664 ASSERT_EQ(1ULL, nav_map->at(download_url).size()); |
| 665 ASSERT_EQ(1ULL, nav_map->at(initial_url).size()); | |
| 666 VerifyNavigationEvent(GURL(), // source_url | |
| 667 GURL(), // source_main_frame_url | |
| 668 initial_url, // original_request_url | |
| 669 initial_url, // destination_url | |
| 670 true, // is_user_initiated, | |
| 671 true, // has_committed | |
| 672 false, // has_server_redirect | |
| 673 nav_map->at(initial_url).at(0)); | |
| 398 VerifyNavigationEvent(initial_url, // source_url | 674 VerifyNavigationEvent(initial_url, // source_url |
| 399 initial_url, // source_main_frame_url | 675 initial_url, // source_main_frame_url |
| 400 first_redirect_url, // original_request_url | 676 first_redirect_url, // original_request_url |
| 401 first_redirect_url, // destination_url | 677 first_redirect_url, // destination_url |
| 402 false, // is_user_initiated, | 678 true, // is_user_initiated, |
| 403 true, // has_committed | 679 true, // has_committed |
| 404 false, // has_server_redirect | 680 false, // has_server_redirect |
| 405 nav_map->at(first_redirect_url).at(0)); | 681 nav_map->at(first_redirect_url).at(0)); |
| 406 VerifyNavigationEvent(first_redirect_url, // source_url | 682 VerifyNavigationEvent(first_redirect_url, // source_url |
| 407 first_redirect_url, // source_main_frame_url | 683 first_redirect_url, // source_main_frame_url |
| 408 second_redirect_url, // original_request_url | 684 second_redirect_url, // original_request_url |
| 409 second_redirect_url, // destination_url | 685 second_redirect_url, // destination_url |
| 410 false, // is_user_initiated, | 686 false, // is_user_initiated, |
| 411 true, // has_committed | 687 true, // has_committed |
| 412 false, // has_server_redirect | 688 false, // has_server_redirect |
| 413 nav_map->at(second_redirect_url).at(0)); | 689 nav_map->at(second_redirect_url).at(0)); |
| 414 VerifyNavigationEvent(second_redirect_url, // source_url | 690 VerifyNavigationEvent(second_redirect_url, // source_url |
| 415 second_redirect_url, // source_main_frame_url | 691 second_redirect_url, // source_main_frame_url |
| 416 download_url, // original_request_url | 692 download_url, // original_request_url |
| 417 download_url, // destination_url | 693 download_url, // destination_url |
| 418 false, // is_user_initiated, | 694 false, // is_user_initiated, |
| 419 false, // has_committed | 695 false, // has_committed |
| 420 false, // has_server_redirect | 696 false, // has_server_redirect |
| 421 nav_map->at(download_url).at(0)); | 697 nav_map->at(download_url).at(0)); |
| 422 VerifyHostToIpMap(); | 698 VerifyHostToIpMap(); |
| 699 auto referrer_chain = IdentifyReferrerChain(GetDownload()); | |
| 700 ASSERT_EQ(std::size_t(4), referrer_chain.size()); | |
| 701 VerifyReferrerChainEntry( | |
| 702 download_url, // url | |
| 703 ReferrerChainEntry::DOWNLOAD_URL, // type | |
| 704 test_server_ip, // ip_address | |
| 705 second_redirect_url, // referrer_url | |
| 706 second_redirect_url, // referrer_main_frame_url | |
| 707 false, // is_retargeting | |
| 708 referrer_chain[0]); | |
| 709 VerifyReferrerChainEntry( | |
| 710 second_redirect_url, // url | |
| 711 ReferrerChainEntry::CLIENT_REDIRECT, // type | |
| 712 test_server_ip, // ip_address | |
| 713 first_redirect_url, // referrer_url | |
| 714 first_redirect_url, // referrer_main_frame_url | |
| 715 false, // is_retargeting | |
| 716 referrer_chain[1]); | |
| 717 VerifyReferrerChainEntry( | |
| 718 first_redirect_url, // url | |
| 719 ReferrerChainEntry::CLIENT_REDIRECT, // type | |
| 720 test_server_ip, // ip_address | |
| 721 initial_url, // referrer_url | |
| 722 initial_url, // referrer_main_frame_url | |
| 723 false, // is_retargeting | |
| 724 referrer_chain[2]); | |
| 725 VerifyReferrerChainEntry( | |
| 726 initial_url, // url | |
| 727 ReferrerChainEntry::LANDING_PAGE, // type | |
| 728 test_server_ip, // ip_address | |
| 729 GURL(), // referrer_url | |
| 730 GURL(), // referrer_main_frame_url | |
| 731 false, // is_retargeting | |
| 732 referrer_chain[3]); | |
| 423 } | 733 } |
| 424 | 734 |
| 425 // Click on a link which redirects to download using window.location. | 735 // Click on a link which redirects to download using window.location. |
| 426 // All transitions happen in the same tab. | 736 // All transitions happen in the same tab. |
| 427 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, | 737 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, |
| 428 WindowLocationRedirect) { | 738 WindowLocationRedirect) { |
| 429 ClickTestLink("window_location_redirection", 1); | |
| 430 GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL); | 739 GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL); |
| 740 ClickTestLink("window_location_redirection", 1, initial_url); | |
| 431 GURL download_url = embedded_test_server()->GetURL(kDownloadItemURL); | 741 GURL download_url = embedded_test_server()->GetURL(kDownloadItemURL); |
| 742 std::string test_server_ip(embedded_test_server()->host_port_pair().host()); | |
| 432 auto nav_map = navigation_map(); | 743 auto nav_map = navigation_map(); |
| 433 ASSERT_TRUE(nav_map); | 744 ASSERT_TRUE(nav_map); |
| 434 ASSERT_EQ(std::size_t(1), nav_map->size()); | 745 ASSERT_EQ(2ULL, nav_map->size()); |
| 435 ASSERT_EQ(std::size_t(1), nav_map->at(download_url).size()); | 746 ASSERT_EQ(1ULL, nav_map->at(download_url).size()); |
| 747 ASSERT_EQ(1ULL, nav_map->at(initial_url).size()); | |
| 748 VerifyNavigationEvent(GURL(), // source_url | |
| 749 GURL(), // source_main_frame_url | |
| 750 initial_url, // original_request_url | |
| 751 initial_url, // destination_url | |
| 752 true, // is_user_initiated, | |
| 753 true, // has_committed | |
| 754 false, // has_server_redirect | |
| 755 nav_map->at(initial_url).at(0)); | |
| 436 VerifyNavigationEvent(initial_url, // source_url | 756 VerifyNavigationEvent(initial_url, // source_url |
| 437 initial_url, // source_main_frame_url | 757 initial_url, // source_main_frame_url |
| 438 download_url, // original_request_url | 758 download_url, // original_request_url |
| 439 download_url, // destination_url | 759 download_url, // destination_url |
| 440 false, // is_user_initiated, | 760 true, // is_user_initiated, |
| 441 false, // has_committed | 761 false, // has_committed |
| 442 false, // has_server_redirect | 762 false, // has_server_redirect |
| 443 nav_map->at(download_url).at(0)); | 763 nav_map->at(download_url).at(0)); |
| 764 auto referrer_chain = IdentifyReferrerChain(GetDownload()); | |
| 765 ASSERT_EQ(2ULL, referrer_chain.size()); | |
| 766 VerifyReferrerChainEntry( | |
| 767 download_url, // url | |
| 768 ReferrerChainEntry::DOWNLOAD_URL, // type | |
| 769 test_server_ip, // ip_address | |
| 770 initial_url, // referrer_url | |
| 771 initial_url, // referrer_main_frame_url | |
| 772 false, // is_retargeting | |
| 773 referrer_chain[0]); | |
| 774 VerifyReferrerChainEntry( | |
| 775 initial_url, // url | |
| 776 ReferrerChainEntry::LANDING_PAGE, // type | |
| 777 test_server_ip, // ip_address | |
| 778 GURL(), // referrer_url | |
| 779 GURL(), // referrer_main_frame_url | |
| 780 false, // is_retargeting | |
| 781 referrer_chain[1]); | |
| 444 } | 782 } |
| 445 | 783 |
| 446 // Click on a link which redirects twice until it reaches download using a | 784 // Click on a link which redirects twice until it reaches download using a |
| 447 // mixture of meta refresh and window.location. All transitions happen in the | 785 // mixture of meta refresh and window.location. All transitions happen in the |
| 448 // same tab. | 786 // same tab. |
| 449 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, MixRedirects) { | 787 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, MixRedirects) { |
| 450 ClickTestLink("mix_redirects", 2); | 788 GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL); |
| 789 ClickTestLink("mix_redirects", 2, initial_url); | |
| 451 GURL redirect_url = embedded_test_server()->GetURL(kRedirectURL); | 790 GURL redirect_url = embedded_test_server()->GetURL(kRedirectURL); |
| 452 GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL); | |
| 453 GURL download_url = embedded_test_server()->GetURL(kDownloadItemURL); | 791 GURL download_url = embedded_test_server()->GetURL(kDownloadItemURL); |
| 792 std::string test_server_ip(embedded_test_server()->host_port_pair().host()); | |
| 454 auto nav_map = navigation_map(); | 793 auto nav_map = navigation_map(); |
| 455 ASSERT_TRUE(nav_map); | 794 ASSERT_TRUE(nav_map); |
| 456 ASSERT_EQ(std::size_t(2), nav_map->size()); | 795 ASSERT_EQ(std::size_t(3), nav_map->size()); |
| 457 ASSERT_EQ(std::size_t(1), nav_map->at(redirect_url).size()); | 796 ASSERT_EQ(1ULL, nav_map->at(redirect_url).size()); |
| 458 ASSERT_EQ(std::size_t(1), nav_map->at(download_url).size()); | 797 ASSERT_EQ(1ULL, nav_map->at(download_url).size()); |
| 798 ASSERT_EQ(1ULL, nav_map->at(initial_url).size()); | |
| 799 VerifyNavigationEvent(GURL(), // source_url | |
| 800 GURL(), // source_main_frame_url | |
| 801 initial_url, // original_request_url | |
| 802 initial_url, // destination_url | |
| 803 true, // is_user_initiated, | |
| 804 true, // has_committed | |
| 805 false, // has_server_redirect | |
| 806 nav_map->at(initial_url).at(0)); | |
| 459 VerifyNavigationEvent(initial_url, // source_url | 807 VerifyNavigationEvent(initial_url, // source_url |
| 460 initial_url, // source_main_frame_url | 808 initial_url, // source_main_frame_url |
| 461 redirect_url, // original_request_url | 809 redirect_url, // original_request_url |
| 462 redirect_url, // destination_url | 810 redirect_url, // destination_url |
| 463 false, // is_user_initiated, | 811 true, // is_user_initiated, |
| 464 true, // has_committed | 812 true, // has_committed |
| 465 false, // has_server_redirect | 813 false, // has_server_redirect |
| 466 nav_map->at(redirect_url).at(0)); | 814 nav_map->at(redirect_url).at(0)); |
| 467 VerifyNavigationEvent(redirect_url, // source_url | 815 VerifyNavigationEvent(redirect_url, // source_url |
| 468 redirect_url, // source_main_frame_url | 816 redirect_url, // source_main_frame_url |
| 469 download_url, // original_request_url | 817 download_url, // original_request_url |
| 470 download_url, // destination_url | 818 download_url, // destination_url |
| 471 false, // is_user_initiated, | 819 false, // is_user_initiated, |
| 472 false, // has_committed | 820 false, // has_committed |
| 473 false, // has_server_redirect | 821 false, // has_server_redirect |
| 474 nav_map->at(download_url).at(0)); | 822 nav_map->at(download_url).at(0)); |
| 475 VerifyHostToIpMap(); | 823 VerifyHostToIpMap(); |
| 824 auto referrer_chain = IdentifyReferrerChain(GetDownload()); | |
| 825 ASSERT_EQ(std::size_t(3), referrer_chain.size()); | |
| 826 VerifyReferrerChainEntry( | |
| 827 download_url, // url | |
| 828 ReferrerChainEntry::DOWNLOAD_URL, // type | |
| 829 test_server_ip, // ip_address | |
| 830 redirect_url, // referrer_url | |
| 831 redirect_url, // referrer_main_frame_url | |
| 832 false, // is_retargeting | |
| 833 referrer_chain[0]); | |
| 834 VerifyReferrerChainEntry( | |
| 835 redirect_url, // url | |
| 836 ReferrerChainEntry::CLIENT_REDIRECT, // type | |
| 837 test_server_ip, // ip_address | |
| 838 initial_url, // referrer_url | |
| 839 initial_url, // referrer_main_frame_url | |
| 840 false, // is_retargeting | |
| 841 referrer_chain[1]); | |
| 842 VerifyReferrerChainEntry( | |
| 843 initial_url, // url | |
| 844 ReferrerChainEntry::LANDING_PAGE, // type | |
| 845 test_server_ip, // ip_address | |
| 846 GURL(), // referrer_url | |
| 847 GURL(), // referrer_main_frame_url | |
| 848 false, // is_retargeting | |
| 849 referrer_chain[2]); | |
| 476 } | 850 } |
| 477 | 851 |
| 478 // Use javascript to open download in a new tab. | 852 // Use javascript to open download in a new tab. |
| 479 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, NewTabDownload) { | 853 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, NewTabDownload) { |
| 480 ClickTestLink("new_tab_download", 2); | |
| 481 GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL); | 854 GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL); |
| 855 ClickTestLink("new_tab_download", 2, initial_url); | |
| 482 GURL download_url = embedded_test_server()->GetURL(kDownloadItemURL); | 856 GURL download_url = embedded_test_server()->GetURL(kDownloadItemURL); |
| 483 GURL blank_url = GURL(url::kAboutBlankURL); | 857 GURL blank_url = GURL(url::kAboutBlankURL); |
| 858 std::string test_server_ip(embedded_test_server()->host_port_pair().host()); | |
| 484 auto nav_map = navigation_map(); | 859 auto nav_map = navigation_map(); |
| 485 ASSERT_TRUE(nav_map); | 860 ASSERT_TRUE(nav_map); |
| 486 ASSERT_EQ(std::size_t(2), nav_map->size()); | 861 ASSERT_EQ(std::size_t(3), nav_map->size()); |
| 487 ASSERT_EQ(std::size_t(2), nav_map->at(blank_url).size()); | 862 ASSERT_EQ(2ULL, nav_map->at(blank_url).size()); |
| 488 ASSERT_EQ(std::size_t(1), nav_map->at(download_url).size()); | 863 ASSERT_EQ(1ULL, nav_map->at(download_url).size()); |
| 864 ASSERT_EQ(1ULL, nav_map->at(initial_url).size()); | |
| 865 VerifyNavigationEvent(GURL(), // source_url | |
| 866 GURL(), // source_main_frame_url | |
| 867 initial_url, // original_request_url | |
| 868 initial_url, // destination_url | |
| 869 true, // is_user_initiated, | |
| 870 true, // has_committed | |
| 871 false, // has_server_redirect | |
| 872 nav_map->at(initial_url).at(0)); | |
| 489 VerifyNavigationEvent(initial_url, // source_url | 873 VerifyNavigationEvent(initial_url, // source_url |
| 490 initial_url, // source_main_frame_url | 874 initial_url, // source_main_frame_url |
| 491 blank_url, // original_request_url | 875 blank_url, // original_request_url |
| 492 blank_url, // destination_url | 876 blank_url, // destination_url |
| 493 false, // is_user_initiated, | 877 true, // is_user_initiated, |
| 494 false, // has_committed | 878 false, // has_committed |
| 495 false, // has_server_redirect | 879 false, // has_server_redirect |
| 496 nav_map->at(blank_url).at(0)); | 880 nav_map->at(blank_url).at(0)); |
| 497 // Source and target are at different tabs. | 881 // Source and target are at different tabs. |
| 498 EXPECT_NE(nav_map->at(blank_url).at(0).source_tab_id, | 882 EXPECT_NE(nav_map->at(blank_url).at(0).source_tab_id, |
| 499 nav_map->at(blank_url).at(0).target_tab_id); | 883 nav_map->at(blank_url).at(0).target_tab_id); |
| 500 VerifyNavigationEvent(GURL(), // source_url | 884 VerifyNavigationEvent(GURL(), // source_url |
| 501 GURL(), // source_main_frame_url | 885 GURL(), // source_main_frame_url |
| 502 blank_url, // original_request_url | 886 blank_url, // original_request_url |
| 503 blank_url, // destination_url | 887 blank_url, // destination_url |
| 504 false, // is_user_initiated, | 888 false, // is_user_initiated, |
| 505 false, // has_committed | 889 false, // has_committed |
| 506 false, // has_server_redirect | 890 false, // has_server_redirect |
| 507 nav_map->at(blank_url).at(1)); | 891 nav_map->at(blank_url).at(1)); |
| 508 EXPECT_EQ(nav_map->at(blank_url).at(1).source_tab_id, | 892 EXPECT_EQ(nav_map->at(blank_url).at(1).source_tab_id, |
| 509 nav_map->at(blank_url).at(1).target_tab_id); | 893 nav_map->at(blank_url).at(1).target_tab_id); |
| 510 VerifyNavigationEvent(blank_url, // source_url | 894 VerifyNavigationEvent(blank_url, // source_url |
| 511 blank_url, // source_main_frame_url | 895 blank_url, // source_main_frame_url |
| 512 download_url, // original_request_url | 896 download_url, // original_request_url |
| 513 download_url, // destination_url | 897 download_url, // destination_url |
| 514 false, // is_user_initiated, | 898 false, // is_user_initiated, |
| 515 false, // has_committed | 899 false, // has_committed |
| 516 false, // has_server_redirect | 900 false, // has_server_redirect |
| 517 nav_map->at(download_url).at(0)); | 901 nav_map->at(download_url).at(0)); |
| 518 EXPECT_EQ(nav_map->at(download_url).at(0).source_tab_id, | 902 EXPECT_EQ(nav_map->at(download_url).at(0).source_tab_id, |
| 519 nav_map->at(download_url).at(0).target_tab_id); | 903 nav_map->at(download_url).at(0).target_tab_id); |
| 520 VerifyHostToIpMap(); | 904 VerifyHostToIpMap(); |
| 905 auto referrer_chain = IdentifyReferrerChain(GetDownload()); | |
| 906 ASSERT_EQ(std::size_t(3), referrer_chain.size()); | |
| 907 VerifyReferrerChainEntry( | |
| 908 download_url, // url | |
| 909 ReferrerChainEntry::DOWNLOAD_URL, // type | |
| 910 test_server_ip, // ip_address | |
| 911 blank_url, // referrer_url | |
| 912 blank_url, // referrer_main_frame_url | |
| 913 false, // is_retargeting | |
| 914 referrer_chain[0]); | |
| 915 VerifyReferrerChainEntry( | |
| 916 blank_url, // url | |
| 917 ReferrerChainEntry::CLIENT_REDIRECT, // type | |
| 918 "", // ip_address | |
| 919 initial_url, // referrer_url | |
| 920 initial_url, // referrer_main_frame_url | |
| 921 true, // is_retargeting | |
| 922 referrer_chain[1]); | |
| 923 VerifyReferrerChainEntry( | |
| 924 initial_url, // url | |
| 925 ReferrerChainEntry::LANDING_PAGE, // type | |
| 926 test_server_ip, // ip_address | |
| 927 GURL(), // referrer_url | |
| 928 GURL(), // referrer_main_frame_url | |
| 929 false, // is_retargeting | |
| 930 referrer_chain[2]); | |
| 521 } | 931 } |
| 522 | 932 |
| 523 // Use javascript to open download in a new tab and download has a data url. | 933 // Use javascript to open download in a new tab and download has a data url. |
| 524 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, | 934 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, |
| 525 NewTabDownloadWithDataURL) { | 935 NewTabDownloadWithDataURL) { |
| 526 ClickTestLink("new_tab_download_with_data_url", 2); | |
| 527 GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL); | 936 GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL); |
| 937 ClickTestLink("new_tab_download_with_data_url", 2, initial_url); | |
| 528 GURL download_url = GURL(kDownloadDataURL); | 938 GURL download_url = GURL(kDownloadDataURL); |
| 529 GURL blank_url = GURL("about:blank"); | 939 GURL blank_url = GURL(url::kAboutBlankURL); |
| 940 std::string test_server_ip(embedded_test_server()->host_port_pair().host()); | |
| 530 auto nav_map = navigation_map(); | 941 auto nav_map = navigation_map(); |
| 531 ASSERT_TRUE(nav_map); | 942 ASSERT_TRUE(nav_map); |
| 532 ASSERT_EQ(std::size_t(2), nav_map->size()); | 943 ASSERT_EQ(std::size_t(3), nav_map->size()); |
| 533 ASSERT_EQ(std::size_t(2), nav_map->at(blank_url).size()); | 944 ASSERT_EQ(2ULL, nav_map->at(blank_url).size()); |
| 534 ASSERT_EQ(std::size_t(1), nav_map->at(download_url).size()); | 945 ASSERT_EQ(1ULL, nav_map->at(download_url).size()); |
| 946 ASSERT_EQ(1ULL, nav_map->at(initial_url).size()); | |
| 947 VerifyNavigationEvent(GURL(), // source_url | |
| 948 GURL(), // source_main_frame_url | |
| 949 initial_url, // original_request_url | |
| 950 initial_url, // destination_url | |
| 951 true, // is_user_initiated, | |
| 952 true, // has_committed | |
| 953 false, // has_server_redirect | |
| 954 nav_map->at(initial_url).at(0)); | |
| 535 // The first one comes from NOTIFICATION_RETARGETING. | 955 // The first one comes from NOTIFICATION_RETARGETING. |
| 536 VerifyNavigationEvent(initial_url, // source_url | 956 VerifyNavigationEvent(initial_url, // source_url |
| 537 initial_url, // source_main_frame_url | 957 initial_url, // source_main_frame_url |
| 538 blank_url, // original_request_url | 958 blank_url, // original_request_url |
| 539 blank_url, // destination_url | 959 blank_url, // destination_url |
| 540 false, // is_user_initiated, | 960 true, // is_user_initiated, |
| 541 false, // has_committed | 961 false, // has_committed |
| 542 false, // has_server_redirect | 962 false, // has_server_redirect |
| 543 nav_map->at(blank_url).at(0)); | 963 nav_map->at(blank_url).at(0)); |
| 544 // Source and target are at different tabs. | 964 // Source and target are at different tabs. |
| 545 EXPECT_FALSE(nav_map->at(blank_url).at(0).source_tab_id == | 965 EXPECT_FALSE(nav_map->at(blank_url).at(0).source_tab_id == |
| 546 nav_map->at(blank_url).at(0).target_tab_id); | 966 nav_map->at(blank_url).at(0).target_tab_id); |
| 547 VerifyNavigationEvent(GURL(), // source_url | 967 VerifyNavigationEvent(GURL(), // source_url |
| 548 GURL(), // source_main_frame_url | 968 GURL(), // source_main_frame_url |
| 549 blank_url, // original_request_url | 969 blank_url, // original_request_url |
| 550 blank_url, // destination_url | 970 blank_url, // destination_url |
| 551 false, // is_user_initiated, | 971 false, // is_user_initiated, |
| 552 false, // has_committed | 972 false, // has_committed |
| 553 false, // has_server_redirect | 973 false, // has_server_redirect |
| 554 nav_map->at(blank_url).at(1)); | 974 nav_map->at(blank_url).at(1)); |
| 555 EXPECT_EQ(nav_map->at(blank_url).at(1).source_tab_id, | 975 EXPECT_EQ(nav_map->at(blank_url).at(1).source_tab_id, |
| 556 nav_map->at(blank_url).at(1).target_tab_id); | 976 nav_map->at(blank_url).at(1).target_tab_id); |
| 557 VerifyNavigationEvent(blank_url, // source_url | 977 VerifyNavigationEvent(blank_url, // source_url |
| 558 blank_url, // source_main_frame_url | 978 blank_url, // source_main_frame_url |
| 559 download_url, // original_request_url | 979 download_url, // original_request_url |
| 560 download_url, // destination_url | 980 download_url, // destination_url |
| 561 false, // is_user_initiated, | 981 false, // is_user_initiated, |
| 562 false, // has_committed | 982 false, // has_committed |
| 563 false, // has_server_redirect | 983 false, // has_server_redirect |
| 564 nav_map->at(download_url).at(0)); | 984 nav_map->at(download_url).at(0)); |
| 565 EXPECT_TRUE(nav_map->at(download_url).at(0).source_tab_id == | 985 EXPECT_TRUE(nav_map->at(download_url).at(0).source_tab_id == |
| 566 nav_map->at(download_url).at(0).target_tab_id); | 986 nav_map->at(download_url).at(0).target_tab_id); |
| 567 // Since data url does does not have IP, host_to_ip_map_ should be empty. | 987 VerifyHostToIpMap(); |
| 568 EXPECT_EQ(std::size_t(0), host_to_ip_map()->size()); | 988 auto referrer_chain = IdentifyReferrerChain(GetDownload()); |
| 989 ASSERT_EQ(std::size_t(3), referrer_chain.size()); | |
| 990 VerifyReferrerChainEntry( | |
| 991 download_url, // url | |
| 992 ReferrerChainEntry::DOWNLOAD_URL, // type | |
| 993 "", // ip_address | |
| 994 blank_url, // referrer_url | |
| 995 blank_url, // referrer_main_frame_url | |
| 996 false, // is_retargeting | |
| 997 referrer_chain[0]); | |
| 998 VerifyReferrerChainEntry( | |
| 999 blank_url, // url | |
| 1000 ReferrerChainEntry::CLIENT_REDIRECT, // type | |
| 1001 "", // ip_address | |
| 1002 initial_url, // referrer_url | |
| 1003 initial_url, // referrer_main_frame_url | |
| 1004 true, // is_retargeting | |
| 1005 referrer_chain[1]); | |
| 1006 VerifyReferrerChainEntry( | |
| 1007 initial_url, // url | |
| 1008 ReferrerChainEntry::LANDING_PAGE, // type | |
| 1009 test_server_ip, // ip_address | |
| 1010 GURL(), // referrer_url | |
| 1011 GURL(), // referrer_main_frame_url | |
| 1012 false, // is_retargeting | |
| 1013 referrer_chain[2]); | |
| 569 } | 1014 } |
| 570 | 1015 |
| 571 // TODO(jialiul): Need to figure out why this test is failing on Windows and | 1016 // TODO(jialiul): Need to figure out why this test is failing on Windows and |
| 572 // flaky on other platforms. | 1017 // flaky on other platforms. |
| 573 #define MAYBE_DownloadViaHTML5FileApi DISABLED_DownloadViaHTML5FileApi | 1018 #define MAYBE_DownloadViaHTML5FileApi DISABLED_DownloadViaHTML5FileApi |
| 574 // Download via html5 file API. | 1019 // Download via html5 file API. |
| 575 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, | 1020 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, |
| 576 MAYBE_DownloadViaHTML5FileApi) { | 1021 MAYBE_DownloadViaHTML5FileApi) { |
| 577 ClickTestLink("html5_file_api", 1); | |
| 578 GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL); | 1022 GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL); |
| 1023 ClickTestLink("html5_file_api", 1, initial_url); | |
| 579 std::string download_url_str = | 1024 std::string download_url_str = |
| 580 base::StringPrintf("filesystem:%stemporary/test.exe", | 1025 base::StringPrintf("filesystem:%stemporary/test.exe", |
| 581 embedded_test_server()->base_url().spec().c_str()); | 1026 embedded_test_server()->base_url().spec().c_str()); |
| 582 GURL download_url = GURL(download_url_str); | 1027 GURL download_url = GURL(download_url_str); |
| 1028 std::string test_server_ip(embedded_test_server()->host_port_pair().host()); | |
| 583 auto nav_map = navigation_map(); | 1029 auto nav_map = navigation_map(); |
| 584 ASSERT_TRUE(nav_map); | 1030 ASSERT_TRUE(nav_map); |
| 585 ASSERT_EQ(std::size_t(1), nav_map->size()); | 1031 ASSERT_EQ(2ULL, nav_map->size()); |
| 586 ASSERT_EQ(std::size_t(1), nav_map->at(download_url).size()); | 1032 ASSERT_EQ(1ULL, nav_map->at(download_url).size()); |
| 1033 ASSERT_EQ(1ULL, nav_map->at(initial_url).size()); | |
| 1034 VerifyNavigationEvent(GURL(), // source_url | |
| 1035 GURL(), // source_main_frame_url | |
| 1036 initial_url, // original_request_url | |
| 1037 initial_url, // destination_url | |
| 1038 true, // is_user_initiated, | |
| 1039 true, // has_committed | |
| 1040 false, // has_server_redirect | |
| 1041 nav_map->at(initial_url).at(0)); | |
| 587 VerifyNavigationEvent(initial_url, // source_url | 1042 VerifyNavigationEvent(initial_url, // source_url |
| 588 initial_url, // source_main_frame_url | 1043 initial_url, // source_main_frame_url |
| 589 download_url, // original_request_url | 1044 download_url, // original_request_url |
| 590 download_url, // destination_url | 1045 download_url, // destination_url |
| 591 false, // is_user_initiated, | 1046 true, // is_user_initiated, |
| 592 false, // has_committed | 1047 false, // has_committed |
| 593 false, // has_server_redirect | 1048 false, // has_server_redirect |
| 594 nav_map->at(download_url).at(0)); | 1049 nav_map->at(download_url).at(0)); |
| 595 VerifyHostToIpMap(); | 1050 VerifyHostToIpMap(); |
| 1051 auto referrer_chain = IdentifyReferrerChain(GetDownload()); | |
| 1052 ASSERT_EQ(2ULL, referrer_chain.size()); | |
| 1053 VerifyReferrerChainEntry( | |
| 1054 download_url, // url | |
| 1055 ReferrerChainEntry::DOWNLOAD_URL, // type | |
| 1056 "", // ip_address | |
| 1057 initial_url, // referrer_url | |
| 1058 initial_url, // referrer_main_frame_url | |
| 1059 false, // is_retargeting | |
| 1060 referrer_chain[0]); | |
| 1061 VerifyReferrerChainEntry( | |
| 1062 initial_url, // url | |
| 1063 ReferrerChainEntry::LANDING_PAGE, // type | |
| 1064 test_server_ip, // ip_address | |
| 1065 GURL(), // referrer_url | |
| 1066 GURL(), // referrer_main_frame_url | |
| 1067 false, // is_retargeting | |
| 1068 referrer_chain[1]); | |
| 596 } | 1069 } |
| 597 | 1070 |
| 598 // Click a link in a subframe and start download. | 1071 // Click a link in a subframe and start download. |
| 599 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, | 1072 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, |
| 600 SubFrameDirectDownload) { | 1073 SubFrameDirectDownload) { |
| 601 ui_test_utils::NavigateToURL( | 1074 ui_test_utils::NavigateToURL( |
| 602 browser(), embedded_test_server()->GetURL(kMultiFrameTestURL)); | 1075 browser(), embedded_test_server()->GetURL(kMultiFrameTestURL)); |
| 603 std::string test_name = | 1076 std::string test_name = |
| 604 base::StringPrintf("%s', '%s", "iframe1", "iframe_direct_download"); | 1077 base::StringPrintf("%s', '%s", "iframe1", "iframe_direct_download"); |
| 605 ClickTestLink(test_name.c_str(), 1); | |
| 606 GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL); | 1078 GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL); |
| 607 GURL multi_frame_test_url = | 1079 GURL multi_frame_test_url = |
| 608 embedded_test_server()->GetURL(kMultiFrameTestURL); | 1080 embedded_test_server()->GetURL(kMultiFrameTestURL); |
| 609 GURL iframe_url = embedded_test_server()->GetURL(kIframeDirectDownloadURL); | 1081 GURL iframe_url = embedded_test_server()->GetURL(kIframeDirectDownloadURL); |
| 1082 ClickTestLink(test_name.c_str(), 1, iframe_url); | |
| 610 GURL iframe_retargeting_url = | 1083 GURL iframe_retargeting_url = |
| 611 embedded_test_server()->GetURL(kIframeRetargetingURL); | 1084 embedded_test_server()->GetURL(kIframeRetargetingURL); |
| 612 GURL download_url = embedded_test_server()->GetURL(kDownloadItemURL); | 1085 GURL download_url = embedded_test_server()->GetURL(kDownloadItemURL); |
| 1086 std::string test_server_ip(embedded_test_server()->host_port_pair().host()); | |
| 613 auto nav_map = navigation_map(); | 1087 auto nav_map = navigation_map(); |
| 614 ASSERT_TRUE(nav_map); | 1088 ASSERT_TRUE(nav_map); |
| 615 ASSERT_EQ(std::size_t(4), nav_map->size()); | 1089 ASSERT_EQ(std::size_t(5), nav_map->size()); |
| 616 ASSERT_EQ(std::size_t(1), nav_map->at(multi_frame_test_url).size()); | 1090 ASSERT_EQ(1ULL, nav_map->at(multi_frame_test_url).size()); |
| 617 ASSERT_EQ(std::size_t(1), nav_map->at(iframe_url).size()); | 1091 ASSERT_EQ(1ULL, nav_map->at(iframe_url).size()); |
| 618 ASSERT_EQ(std::size_t(1), nav_map->at(iframe_retargeting_url).size()); | 1092 ASSERT_EQ(1ULL, nav_map->at(iframe_retargeting_url).size()); |
| 619 ASSERT_EQ(std::size_t(1), nav_map->at(download_url).size()); | 1093 ASSERT_EQ(1ULL, nav_map->at(download_url).size()); |
| 620 VerifyNavigationEvent(initial_url, // source_url | 1094 ASSERT_EQ(1ULL, nav_map->at(initial_url).size()); |
| 621 initial_url, // source_main_frame_url | 1095 VerifyNavigationEvent(GURL(), // source_url |
| 1096 GURL(), // source_main_frame_url | |
| 1097 initial_url, // original_request_url | |
| 1098 initial_url, // destination_url | |
| 1099 true, // is_user_initiated, | |
| 1100 true, // has_committed | |
| 1101 false, // has_server_redirect | |
| 1102 nav_map->at(initial_url).at(0)); | |
| 1103 VerifyNavigationEvent(GURL(), // source_url | |
| 1104 GURL(), // source_main_frame_url | |
| 622 multi_frame_test_url, // original_request_url | 1105 multi_frame_test_url, // original_request_url |
| 623 multi_frame_test_url, // destination_url | 1106 multi_frame_test_url, // destination_url |
| 624 true, // is_user_initiated, | 1107 true, // is_user_initiated, |
| 625 true, // has_committed | 1108 true, // has_committed |
| 626 false, // has_server_redirect | 1109 false, // has_server_redirect |
| 627 nav_map->at(multi_frame_test_url).at(0)); | 1110 nav_map->at(multi_frame_test_url).at(0)); |
| 628 VerifyNavigationEvent(GURL(), // source_url | 1111 VerifyNavigationEvent(GURL(), // source_url |
| 629 multi_frame_test_url, // source_main_frame_url | 1112 multi_frame_test_url, // source_main_frame_url |
| 630 iframe_url, // original_request_url | 1113 iframe_url, // original_request_url |
| 631 iframe_url, // destination_url | 1114 iframe_url, // destination_url |
| 632 false, // is_user_initiated, | 1115 false, // is_user_initiated, |
| 633 true, // has_committed | 1116 true, // has_committed |
| 634 false, // has_server_redirect | 1117 false, // has_server_redirect |
| 635 nav_map->at(iframe_url).at(0)); | 1118 nav_map->at(iframe_url).at(0)); |
| 636 VerifyNavigationEvent(GURL(), // source_url | 1119 VerifyNavigationEvent(GURL(), // source_url |
| 637 multi_frame_test_url, // source_main_frame_url | 1120 multi_frame_test_url, // source_main_frame_url |
| 638 iframe_retargeting_url, // original_request_url | 1121 iframe_retargeting_url, // original_request_url |
| 639 iframe_retargeting_url, // destination_url | 1122 iframe_retargeting_url, // destination_url |
| 640 false, // is_user_initiated, | 1123 false, // is_user_initiated, |
| 641 true, // has_committed | 1124 true, // has_committed |
| 642 false, // has_server_redirect | 1125 false, // has_server_redirect |
| 643 nav_map->at(iframe_retargeting_url).at(0)); | 1126 nav_map->at(iframe_retargeting_url).at(0)); |
| 644 VerifyNavigationEvent(iframe_url, // source_url | 1127 VerifyNavigationEvent(iframe_url, // source_url |
| 645 multi_frame_test_url, // source_main_frame_url | 1128 multi_frame_test_url, // source_main_frame_url |
| 646 download_url, // original_request_url | 1129 download_url, // original_request_url |
| 647 download_url, // destination_url | 1130 download_url, // destination_url |
| 648 false, // is_user_initiated, | 1131 true, // is_user_initiated, |
| 649 false, // has_committed | 1132 false, // has_committed |
| 650 false, // has_server_redirect | 1133 false, // has_server_redirect |
| 651 nav_map->at(download_url).at(0)); | 1134 nav_map->at(download_url).at(0)); |
| 652 VerifyHostToIpMap(); | 1135 VerifyHostToIpMap(); |
| 1136 auto referrer_chain = IdentifyReferrerChain(GetDownload()); | |
| 1137 ASSERT_EQ(2ULL, referrer_chain.size()); | |
| 1138 VerifyReferrerChainEntry( | |
| 1139 download_url, // url | |
| 1140 ReferrerChainEntry::DOWNLOAD_URL, // type | |
| 1141 test_server_ip, // ip_address | |
| 1142 iframe_url, // referrer_url | |
| 1143 multi_frame_test_url, // referrer_main_frame_url | |
| 1144 false, // is_retargeting | |
| 1145 referrer_chain[0]); | |
| 1146 VerifyReferrerChainEntry( | |
| 1147 iframe_url, // url | |
| 1148 ReferrerChainEntry::LANDING_PAGE, // type | |
| 1149 test_server_ip, // ip_address | |
| 1150 GURL(), // referrer_url | |
| 1151 multi_frame_test_url, // referrer_main_frame_url | |
| 1152 false, // is_retargeting | |
| 1153 referrer_chain[1]); | |
| 653 } | 1154 } |
| 654 | 1155 |
| 655 // Click a link in a subframe and open download in a new tab. | 1156 // Click a link in a subframe and open download in a new tab. |
| 656 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, | 1157 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, |
| 657 SubFrameNewTabDownload) { | 1158 SubFrameNewTabDownload) { |
| 658 ui_test_utils::NavigateToURL( | 1159 ui_test_utils::NavigateToURL( |
| 659 browser(), embedded_test_server()->GetURL(kMultiFrameTestURL)); | 1160 browser(), embedded_test_server()->GetURL(kMultiFrameTestURL)); |
| 660 std::string test_name = | 1161 std::string test_name = |
| 661 base::StringPrintf("%s', '%s", "iframe2", "iframe_new_tab_download"); | 1162 base::StringPrintf("%s', '%s", "iframe2", "iframe_new_tab_download"); |
| 662 ClickTestLink(test_name.c_str(), 2); | |
| 663 GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL); | 1163 GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL); |
| 664 GURL multi_frame_test_url = | 1164 GURL multi_frame_test_url = |
| 665 embedded_test_server()->GetURL(kMultiFrameTestURL); | 1165 embedded_test_server()->GetURL(kMultiFrameTestURL); |
| 666 GURL iframe_url = embedded_test_server()->GetURL(kIframeDirectDownloadURL); | 1166 GURL iframe_url = embedded_test_server()->GetURL(kIframeDirectDownloadURL); |
| 667 GURL iframe_retargeting_url = | 1167 GURL iframe_retargeting_url = |
| 668 embedded_test_server()->GetURL(kIframeRetargetingURL); | 1168 embedded_test_server()->GetURL(kIframeRetargetingURL); |
| 1169 ClickTestLink(test_name.c_str(), 2, iframe_retargeting_url); | |
| 669 GURL blank_url = GURL(url::kAboutBlankURL); | 1170 GURL blank_url = GURL(url::kAboutBlankURL); |
| 670 GURL download_url = embedded_test_server()->GetURL(kDownloadItemURL); | 1171 GURL download_url = embedded_test_server()->GetURL(kDownloadItemURL); |
| 1172 std::string test_server_ip(embedded_test_server()->host_port_pair().host()); | |
| 671 auto nav_map = navigation_map(); | 1173 auto nav_map = navigation_map(); |
| 672 ASSERT_TRUE(nav_map); | 1174 ASSERT_TRUE(nav_map); |
| 673 ASSERT_EQ(std::size_t(5), nav_map->size()); | 1175 ASSERT_EQ(std::size_t(6), nav_map->size()); |
| 674 ASSERT_EQ(std::size_t(1), nav_map->at(multi_frame_test_url).size()); | 1176 ASSERT_EQ(1ULL, nav_map->at(multi_frame_test_url).size()); |
| 675 ASSERT_EQ(std::size_t(1), nav_map->at(iframe_url).size()); | 1177 ASSERT_EQ(1ULL, nav_map->at(iframe_url).size()); |
| 676 ASSERT_EQ(std::size_t(1), nav_map->at(iframe_retargeting_url).size()); | 1178 ASSERT_EQ(1ULL, nav_map->at(iframe_retargeting_url).size()); |
| 677 ASSERT_EQ(std::size_t(2), nav_map->at(blank_url).size()); | 1179 ASSERT_EQ(2ULL, nav_map->at(blank_url).size()); |
| 678 ASSERT_EQ(std::size_t(1), nav_map->at(download_url).size()); | 1180 ASSERT_EQ(1ULL, nav_map->at(download_url).size()); |
| 679 VerifyNavigationEvent(initial_url, // source_url | 1181 ASSERT_EQ(1ULL, nav_map->at(initial_url).size()); |
| 680 initial_url, // source_main_frame_url | 1182 VerifyNavigationEvent(GURL(), // source_url |
| 1183 GURL(), // source_main_frame_url | |
| 1184 initial_url, // original_request_url | |
| 1185 initial_url, // destination_url | |
| 1186 true, // is_user_initiated, | |
| 1187 true, // has_committed | |
| 1188 false, // has_server_redirect | |
| 1189 nav_map->at(initial_url).at(0)); | |
| 1190 VerifyNavigationEvent(GURL(), // source_url | |
| 1191 GURL(), // source_main_frame_url | |
| 681 multi_frame_test_url, // original_request_url | 1192 multi_frame_test_url, // original_request_url |
| 682 multi_frame_test_url, // destination_url | 1193 multi_frame_test_url, // destination_url |
| 683 true, // is_user_initiated, | 1194 true, // is_user_initiated, |
| 684 true, // has_committed | 1195 true, // has_committed |
| 685 false, // has_server_redirect | 1196 false, // has_server_redirect |
| 686 nav_map->at(multi_frame_test_url).at(0)); | 1197 nav_map->at(multi_frame_test_url).at(0)); |
| 687 VerifyNavigationEvent(GURL(), // source_url | 1198 VerifyNavigationEvent(GURL(), // source_url |
| 688 multi_frame_test_url, // source_main_frame_url | 1199 multi_frame_test_url, // source_main_frame_url |
| 689 iframe_url, // original_request_url | 1200 iframe_url, // original_request_url |
| 690 iframe_url, // destination_url | 1201 iframe_url, // destination_url |
| 691 false, // is_user_initiated, | 1202 false, // is_user_initiated, |
| 692 true, // has_committed | 1203 true, // has_committed |
| 693 false, // has_server_redirect | 1204 false, // has_server_redirect |
| 694 nav_map->at(iframe_url).at(0)); | 1205 nav_map->at(iframe_url).at(0)); |
| 695 VerifyNavigationEvent(GURL(), // source_url | 1206 VerifyNavigationEvent(GURL(), // source_url |
| 696 multi_frame_test_url, // source_main_frame_url | 1207 multi_frame_test_url, // source_main_frame_url |
| 697 iframe_retargeting_url, // original_request_url | 1208 iframe_retargeting_url, // original_request_url |
| 698 iframe_retargeting_url, // destination_url | 1209 iframe_retargeting_url, // destination_url |
| 699 false, // is_user_initiated, | 1210 false, // is_user_initiated, |
| 700 true, // has_committed | 1211 true, // has_committed |
| 701 false, // has_server_redirect | 1212 false, // has_server_redirect |
| 702 nav_map->at(iframe_retargeting_url).at(0)); | 1213 nav_map->at(iframe_retargeting_url).at(0)); |
| 703 VerifyNavigationEvent(iframe_retargeting_url, // source_url | 1214 VerifyNavigationEvent(iframe_retargeting_url, // source_url |
| 704 multi_frame_test_url, // source_main_frame_url | 1215 multi_frame_test_url, // source_main_frame_url |
| 705 blank_url, // original_request_url | 1216 blank_url, // original_request_url |
| 706 blank_url, // destination_url | 1217 blank_url, // destination_url |
| 707 false, // is_user_initiated, | 1218 true, // is_user_initiated, |
| 708 false, // has_committed | 1219 false, // has_committed |
| 709 false, // has_server_redirect | 1220 false, // has_server_redirect |
| 710 nav_map->at(blank_url).at(0)); | 1221 nav_map->at(blank_url).at(0)); |
| 711 VerifyNavigationEvent(GURL(), // source_url | 1222 VerifyNavigationEvent(GURL(), // source_url |
| 712 GURL(), // source_main_frame_url | 1223 GURL(), // source_main_frame_url |
| 713 blank_url, // original_request_url | 1224 blank_url, // original_request_url |
| 714 blank_url, // destination_url | 1225 blank_url, // destination_url |
| 715 false, // is_user_initiated, | 1226 false, // is_user_initiated, |
| 716 false, // has_committed | 1227 false, // has_committed |
| 717 false, // has_server_redirect | 1228 false, // has_server_redirect |
| 718 nav_map->at(blank_url).at(1)); | 1229 nav_map->at(blank_url).at(1)); |
| 719 VerifyNavigationEvent(blank_url, // source_url | 1230 VerifyNavigationEvent(blank_url, // source_url |
| 720 blank_url, // source_main_frame_url | 1231 blank_url, // source_main_frame_url |
| 721 download_url, // original_request_url | 1232 download_url, // original_request_url |
| 722 download_url, // destination_url | 1233 download_url, // destination_url |
| 723 false, // is_user_initiated, | 1234 false, // is_user_initiated, |
| 724 false, // has_committed | 1235 false, // has_committed |
| 725 false, // has_server_redirect | 1236 false, // has_server_redirect |
| 726 nav_map->at(download_url).at(0)); | 1237 nav_map->at(download_url).at(0)); |
| 727 VerifyHostToIpMap(); | 1238 VerifyHostToIpMap(); |
| 1239 auto referrer_chain = IdentifyReferrerChain(GetDownload()); | |
| 1240 EXPECT_EQ(std::size_t(3), referrer_chain.size()); | |
| 1241 VerifyReferrerChainEntry( | |
| 1242 download_url, // url | |
| 1243 ReferrerChainEntry::DOWNLOAD_URL, // type | |
| 1244 test_server_ip, // ip_address | |
| 1245 blank_url, // referrer_url | |
| 1246 blank_url, // referrer_main_frame_url | |
| 1247 false, // is_retargeting | |
| 1248 referrer_chain[0]); | |
| 1249 VerifyReferrerChainEntry( | |
| 1250 blank_url, // url | |
| 1251 ReferrerChainEntry::CLIENT_REDIRECT, // type | |
| 1252 "", // ip_address | |
| 1253 iframe_retargeting_url, // referrer_url | |
| 1254 multi_frame_test_url, // referrer_main_frame_url | |
| 1255 true, // is_retargeting | |
| 1256 referrer_chain[1]); | |
| 1257 VerifyReferrerChainEntry( | |
| 1258 iframe_retargeting_url, // url | |
| 1259 ReferrerChainEntry::LANDING_PAGE, // type | |
| 1260 test_server_ip, // ip_address | |
| 1261 GURL(), // referrer_url | |
| 1262 multi_frame_test_url, // referrer_main_frame_url | |
| 1263 false, // is_retargeting | |
| 1264 referrer_chain[2]); | |
| 1265 } | |
| 1266 | |
| 1267 // Click a link which redirects to the landing page, and then click on the | |
| 1268 // landing page to trigger download. | |
| 1269 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, CompleteReferrerChain) { | |
| 1270 GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL); | |
| 1271 ClickTestLink("complete_referrer_chain", 2, initial_url); | |
| 1272 GURL redirect_url = embedded_test_server()->GetURL(kRedirectToLandingURL); | |
| 1273 GURL landing_url = embedded_test_server()->GetURL(kLandingURL); | |
| 1274 ClickTestLink("download_on_landing_page", 1, landing_url); | |
| 1275 GURL download_url = embedded_test_server()->GetURL(kDownloadItemURL); | |
| 1276 std::string test_server_ip(embedded_test_server()->host_port_pair().host()); | |
| 1277 auto nav_map = navigation_map(); | |
| 1278 ASSERT_TRUE(nav_map); | |
| 1279 ASSERT_EQ(std::size_t(4), nav_map->size()); | |
| 1280 ASSERT_EQ(1ULL, nav_map->at(redirect_url).size()); | |
| 1281 ASSERT_EQ(1ULL, nav_map->at(landing_url).size()); | |
| 1282 ASSERT_EQ(1ULL, nav_map->at(download_url).size()); | |
| 1283 ASSERT_EQ(1ULL, nav_map->at(initial_url).size()); | |
| 1284 VerifyNavigationEvent(GURL(), // source_url | |
| 1285 GURL(), // source_main_frame_url | |
| 1286 initial_url, // original_request_url | |
| 1287 initial_url, // destination_url | |
| 1288 true, // is_user_initiated, | |
| 1289 true, // has_committed | |
| 1290 false, // has_server_redirect | |
| 1291 nav_map->at(initial_url).at(0)); | |
| 1292 VerifyNavigationEvent(initial_url, // source_url | |
| 1293 initial_url, // source_main_frame_url | |
| 1294 redirect_url, // original_request_url | |
| 1295 redirect_url, // destination_url | |
| 1296 true, // is_user_initiated, | |
| 1297 true, // has_committed | |
| 1298 false, // has_server_redirect | |
| 1299 nav_map->at(redirect_url).at(0)); | |
| 1300 VerifyNavigationEvent(redirect_url, // source_url | |
| 1301 redirect_url, // source_main_frame_url | |
| 1302 landing_url, // original_request_url | |
| 1303 landing_url, // destination_url | |
| 1304 false, // is_user_initiated, | |
| 1305 true, // has_committed | |
| 1306 false, // has_server_redirect | |
| 1307 nav_map->at(landing_url).at(0)); | |
| 1308 VerifyNavigationEvent(landing_url, // source_url | |
| 1309 landing_url, // source_main_frame_url | |
| 1310 download_url, // original_request_url | |
| 1311 download_url, // destination_url | |
| 1312 true, // is_user_initiated, | |
| 1313 false, // has_committed | |
| 1314 false, // has_server_redirect | |
| 1315 nav_map->at(download_url).at(0)); | |
| 1316 VerifyHostToIpMap(); | |
| 1317 auto referrer_chain = IdentifyReferrerChain(GetDownload()); | |
| 1318 EXPECT_EQ(std::size_t(4), referrer_chain.size()); | |
| 1319 VerifyReferrerChainEntry( | |
| 1320 download_url, // url | |
| 1321 ReferrerChainEntry::DOWNLOAD_URL, // type | |
| 1322 test_server_ip, // ip_address | |
| 1323 landing_url, // referrer_url | |
| 1324 landing_url, // referrer_main_frame_url | |
| 1325 false, // is_retargeting | |
| 1326 referrer_chain[0]); | |
| 1327 VerifyReferrerChainEntry( | |
| 1328 landing_url, // url | |
| 1329 ReferrerChainEntry::LANDING_PAGE, // type | |
| 1330 test_server_ip, // ip_address | |
| 1331 redirect_url, // referrer_url | |
| 1332 redirect_url, // referrer_main_frame_url | |
| 1333 false, // is_retargeting | |
| 1334 referrer_chain[1]); | |
| 1335 VerifyReferrerChainEntry( | |
| 1336 redirect_url, // url | |
| 1337 ReferrerChainEntry::CLIENT_REDIRECT, // type | |
| 1338 test_server_ip, // ip_address | |
| 1339 initial_url, // referrer_url | |
| 1340 initial_url, // referrer_main_frame_url | |
| 1341 false, // is_retargeting | |
| 1342 referrer_chain[2]); | |
| 1343 VerifyReferrerChainEntry( | |
| 1344 initial_url, // url | |
| 1345 ReferrerChainEntry::LANDING_REFERRER, // type | |
| 1346 test_server_ip, // ip_address | |
| 1347 GURL(), // referrer_url is empty since this beyonds 2 clicks. | |
| 1348 GURL(), // referrer_main_frame_url is empty for the same reason. | |
| 1349 false, // is_retargeting | |
| 1350 referrer_chain[3]); | |
| 1351 } | |
| 1352 | |
| 1353 // Click three links before reach download. | |
|
Charlie Reis
2016/12/09 22:00:24
nit: reaching
Jialiu Lin
2016/12/12 23:43:37
Done.
| |
| 1354 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, | |
| 1355 ReferrerAttributionWithinTwoUserGestures) { | |
| 1356 GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL); | |
| 1357 ClickTestLink("attribution_within_two_user_gestures", 1, initial_url); | |
| 1358 GURL page_before_landing_referrer_url = | |
| 1359 embedded_test_server()->GetURL(kPageBeforeLandingReferrerURL); | |
| 1360 ClickTestLink("link_to_landing_referrer", 1, | |
| 1361 page_before_landing_referrer_url); | |
| 1362 GURL landing_referrer_url = | |
| 1363 embedded_test_server()->GetURL(kLandingReferrerURL); | |
| 1364 ClickTestLink("link_to_landing", 1, landing_referrer_url); | |
| 1365 GURL landing_url = embedded_test_server()->GetURL(kLandingURL); | |
| 1366 ClickTestLink("download_on_landing_page", 1, landing_url); | |
| 1367 GURL download_url = embedded_test_server()->GetURL(kDownloadItemURL); | |
| 1368 std::string test_server_ip(embedded_test_server()->host_port_pair().host()); | |
| 1369 auto nav_map = navigation_map(); | |
| 1370 ASSERT_TRUE(nav_map); | |
| 1371 ASSERT_EQ(std::size_t(5), nav_map->size()); | |
| 1372 ASSERT_EQ(1ULL, nav_map->at(initial_url).size()); | |
| 1373 ASSERT_EQ(1ULL, | |
| 1374 nav_map->at(page_before_landing_referrer_url).size()); | |
| 1375 ASSERT_EQ(1ULL, nav_map->at(landing_referrer_url).size()); | |
| 1376 ASSERT_EQ(1ULL, nav_map->at(landing_url).size()); | |
| 1377 ASSERT_EQ(1ULL, nav_map->at(download_url).size()); | |
| 1378 VerifyNavigationEvent(GURL(), // source_url | |
| 1379 GURL(), // source_main_frame_url | |
| 1380 initial_url, // original_request_url | |
| 1381 initial_url, // destination_url | |
| 1382 true, // is_user_initiated, | |
| 1383 true, // has_committed | |
| 1384 false, // has_server_redirect | |
| 1385 nav_map->at(initial_url).at(0)); | |
| 1386 VerifyNavigationEvent(initial_url, // source_url | |
| 1387 initial_url, // source_main_frame_url | |
| 1388 page_before_landing_referrer_url, // original_request | |
| 1389 page_before_landing_referrer_url, // destination_url | |
| 1390 true, // is_user_initiated, | |
| 1391 true, // has_committed | |
| 1392 false, // has_server_redirect | |
| 1393 nav_map->at(page_before_landing_referrer_url).at(0)); | |
| 1394 VerifyNavigationEvent(page_before_landing_referrer_url, // source_url | |
| 1395 page_before_landing_referrer_url, // source_main_frame | |
| 1396 landing_referrer_url, // original_request_url | |
| 1397 landing_referrer_url, // destination_url | |
| 1398 true, // is_user_initiated, | |
| 1399 true, // has_committed | |
| 1400 false, // has_server_redirect | |
| 1401 nav_map->at(landing_referrer_url).at(0)); | |
| 1402 VerifyNavigationEvent(landing_referrer_url, // source_url | |
| 1403 landing_referrer_url, // source_main_frame | |
| 1404 landing_url, // original_request_url | |
| 1405 landing_url, // destination_url | |
| 1406 true, // is_user_initiated, | |
| 1407 true, // has_committed | |
| 1408 false, // has_server_redirect | |
| 1409 nav_map->at(landing_url).at(0)); | |
| 1410 VerifyNavigationEvent(landing_url, // source_url | |
| 1411 landing_url, // source_main_frame_url | |
| 1412 download_url, // original_request_url | |
| 1413 download_url, // destination_url | |
| 1414 true, // is_user_initiated, | |
| 1415 false, // has_committed | |
| 1416 false, // has_server_redirect | |
| 1417 nav_map->at(download_url).at(0)); | |
| 1418 VerifyHostToIpMap(); | |
| 1419 auto referrer_chain = IdentifyReferrerChain(GetDownload()); | |
| 1420 EXPECT_EQ(std::size_t(3), referrer_chain.size()); | |
| 1421 VerifyReferrerChainEntry( | |
| 1422 download_url, // url | |
| 1423 ReferrerChainEntry::DOWNLOAD_URL, // type | |
| 1424 test_server_ip, // ip_address | |
| 1425 landing_url, // referrer_url | |
| 1426 landing_url, // referrer_main_frame_url | |
| 1427 false, // is_retargeting | |
| 1428 referrer_chain[0]); | |
| 1429 VerifyReferrerChainEntry( | |
| 1430 landing_url, // url | |
| 1431 ReferrerChainEntry::LANDING_PAGE, // type | |
| 1432 test_server_ip, // ip_address | |
| 1433 landing_referrer_url, // referrer_url | |
| 1434 landing_referrer_url, // referrer_main_frame_url | |
| 1435 false, // is_retargeting | |
| 1436 referrer_chain[1]); | |
| 1437 VerifyReferrerChainEntry( | |
| 1438 landing_referrer_url, // url | |
| 1439 ReferrerChainEntry::LANDING_REFERRER, // type | |
| 1440 test_server_ip, // ip_address | |
| 1441 GURL(), // referrer_url is empty since this beyonds 2 clicks. | |
| 1442 GURL(), // referrer_main_frame_url is empty for the same reason. | |
| 1443 false, // is_retargeting | |
| 1444 referrer_chain[2]); | |
| 1445 // page_before_landing_referrer_url is not in referrer chain. | |
| 728 } | 1446 } |
| 729 | 1447 |
| 730 // Server-side redirect. | 1448 // Server-side redirect. |
| 731 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, ServerRedirect) { | 1449 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, ServerRedirect) { |
| 732 GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL); | 1450 GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL); |
| 733 GURL download_url = embedded_test_server()->GetURL(kDownloadItemURL); | 1451 GURL download_url = embedded_test_server()->GetURL(kDownloadItemURL); |
| 734 GURL request_url = | 1452 GURL request_url = |
| 735 embedded_test_server()->GetURL("/server-redirect?" + download_url.spec()); | 1453 embedded_test_server()->GetURL("/server-redirect?" + download_url.spec()); |
| 736 ui_test_utils::NavigateToURL(browser(), request_url); | 1454 ui_test_utils::NavigateToURL(browser(), request_url); |
| 737 CancelDownloads(); | 1455 std::string test_server_ip(embedded_test_server()->host_port_pair().host()); |
| 738 auto nav_map = navigation_map(); | 1456 auto nav_map = navigation_map(); |
| 739 ASSERT_TRUE(nav_map); | 1457 ASSERT_TRUE(nav_map); |
| 740 ASSERT_EQ(std::size_t(1), nav_map->size()); | 1458 ASSERT_EQ(2ULL, nav_map->size()); |
| 741 ASSERT_EQ(std::size_t(1), nav_map->at(download_url).size()); | 1459 ASSERT_EQ(1ULL, nav_map->at(download_url).size()); |
| 742 VerifyNavigationEvent(initial_url, // source_url | 1460 ASSERT_EQ(1ULL, nav_map->at(initial_url).size()); |
| 743 initial_url, // source_main_frame_url | 1461 VerifyNavigationEvent(GURL(), // source_url |
| 1462 GURL(), // source_main_frame_url | |
| 1463 initial_url, // original_request_url | |
| 1464 initial_url, // destination_url | |
| 1465 true, // is_user_initiated, | |
| 1466 true, // has_committed | |
| 1467 false, // has_server_redirect | |
| 1468 nav_map->at(initial_url).at(0)); | |
| 1469 VerifyNavigationEvent(GURL(), // source_url | |
| 1470 GURL(), // source_main_frame_url | |
| 744 request_url, // original_request_url | 1471 request_url, // original_request_url |
| 745 download_url, // destination_url | 1472 download_url, // destination_url |
| 746 true, // is_user_initiated, | 1473 true, // is_user_initiated, |
| 747 false, // has_committed | 1474 false, // has_committed |
| 748 true, // has_server_redirect | 1475 true, // has_server_redirect |
| 749 nav_map->at(download_url).at(0)); | 1476 nav_map->at(download_url).at(0)); |
| 1477 auto referrer_chain = IdentifyReferrerChain(GetDownload()); | |
| 1478 ASSERT_EQ(1ULL, referrer_chain.size()); | |
| 1479 VerifyReferrerChainEntry( | |
| 1480 download_url, // url | |
| 1481 ReferrerChainEntry::DOWNLOAD_URL, // type | |
| 1482 test_server_ip, // ip_address | |
| 1483 GURL(), // referrer_url | |
| 1484 GURL(), // referrer_main_frame_url | |
| 1485 false, // is_retargeting | |
| 1486 referrer_chain[0]); | |
| 750 } | 1487 } |
| 751 | 1488 |
| 752 // host_to_ip_map_ size should increase by one after a new navigation. | 1489 // host_to_ip_map_ size should increase by one after a new navigation. |
| 753 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, AddIPMapping) { | 1490 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, AddIPMapping) { |
| 1491 GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL); | |
| 754 auto ip_map = host_to_ip_map(); | 1492 auto ip_map = host_to_ip_map(); |
| 755 std::string test_server_host(embedded_test_server()->base_url().host()); | 1493 std::string test_server_host(embedded_test_server()->base_url().host()); |
| 1494 ip_map->clear(); | |
| 756 ip_map->insert( | 1495 ip_map->insert( |
| 757 std::make_pair(test_server_host, std::vector<ResolvedIPAddress>())); | 1496 std::make_pair(test_server_host, std::vector<ResolvedIPAddress>())); |
| 758 ASSERT_EQ(std::size_t(0), ip_map->at(test_server_host).size()); | 1497 ASSERT_EQ(std::size_t(0), ip_map->at(test_server_host).size()); |
| 759 ClickTestLink("direct_download", 1); | 1498 ClickTestLink("direct_download", 1, initial_url); |
| 760 EXPECT_EQ(std::size_t(1), ip_map->at(test_server_host).size()); | 1499 EXPECT_EQ(1ULL, ip_map->at(test_server_host).size()); |
| 761 EXPECT_EQ(embedded_test_server()->host_port_pair().host(), | 1500 EXPECT_EQ(embedded_test_server()->host_port_pair().host(), |
| 762 ip_map->at(test_server_host).back().ip); | 1501 ip_map->at(test_server_host).back().ip); |
| 763 } | 1502 } |
| 764 | 1503 |
| 765 // If we have already seen an IP associated with a host, update its timestamp. | 1504 // If we have already seen an IP associated with a host, update its timestamp. |
| 766 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, IPListDedup) { | 1505 IN_PROC_BROWSER_TEST_F(SBNavigationObserverBrowserTest, IPListDedup) { |
| 1506 GURL initial_url = embedded_test_server()->GetURL(kSingleFrameTestURL); | |
| 767 auto ip_map = host_to_ip_map(); | 1507 auto ip_map = host_to_ip_map(); |
| 1508 ip_map->clear(); | |
| 768 std::string test_server_host(embedded_test_server()->base_url().host()); | 1509 std::string test_server_host(embedded_test_server()->base_url().host()); |
| 769 ip_map->insert( | 1510 ip_map->insert( |
| 770 std::make_pair(test_server_host, std::vector<ResolvedIPAddress>())); | 1511 std::make_pair(test_server_host, std::vector<ResolvedIPAddress>())); |
| 771 base::Time yesterday(base::Time::Now() - base::TimeDelta::FromDays(1)); | 1512 base::Time yesterday(base::Time::Now() - base::TimeDelta::FromDays(1)); |
| 772 ip_map->at(test_server_host) | 1513 ip_map->at(test_server_host) |
| 773 .push_back(ResolvedIPAddress( | 1514 .push_back(ResolvedIPAddress( |
| 774 yesterday, embedded_test_server()->host_port_pair().host())); | 1515 yesterday, embedded_test_server()->host_port_pair().host())); |
| 775 ASSERT_EQ(std::size_t(1), ip_map->at(test_server_host).size()); | 1516 ASSERT_EQ(1ULL, ip_map->at(test_server_host).size()); |
| 776 ClickTestLink("direct_download", 1); | 1517 ClickTestLink("direct_download", 1, initial_url); |
| 777 EXPECT_EQ(std::size_t(1), ip_map->at(test_server_host).size()); | 1518 EXPECT_EQ(1ULL, ip_map->at(test_server_host).size()); |
| 778 EXPECT_EQ(embedded_test_server()->host_port_pair().host(), | 1519 EXPECT_EQ(embedded_test_server()->host_port_pair().host(), |
| 779 ip_map->at(test_server_host).back().ip); | 1520 ip_map->at(test_server_host).back().ip); |
| 780 EXPECT_NE(yesterday, ip_map->at(test_server_host).front().timestamp); | 1521 EXPECT_NE(yesterday, ip_map->at(test_server_host).front().timestamp); |
| 781 } | 1522 } |
| 782 | 1523 |
| 783 } // namespace safe_browsing | 1524 } // namespace safe_browsing |
| OLD | NEW |