| 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/download_protection_service.h" |
| 10 #include "chrome/browser/safe_browsing/safe_browsing_navigation_observer.h" | 10 #include "chrome/browser/safe_browsing/safe_browsing_navigation_observer.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 base::Closure quit_waiting_callback_; | 121 base::Closure quit_waiting_callback_; |
| 122 DownloadManager* manager_; | 122 DownloadManager* manager_; |
| 123 std::vector<DownloadItem*> items_seen_; | 123 std::vector<DownloadItem*> items_seen_; |
| 124 | 124 |
| 125 DISALLOW_COPY_AND_ASSIGN(DownloadItemCreatedObserver); | 125 DISALLOW_COPY_AND_ASSIGN(DownloadItemCreatedObserver); |
| 126 }; | 126 }; |
| 127 | 127 |
| 128 // Test class to help create SafeBrowsingNavigationObservers for each | 128 // Test class to help create SafeBrowsingNavigationObservers for each |
| 129 // WebContents before they are actually installed through AttachTabHelper. | 129 // WebContents before they are actually installed through AttachTabHelper. |
| 130 class TestNavigationObserverManager | 130 class TestNavigationObserverManager |
| 131 : public SafeBrowsingNavigationObserverManager { | 131 : public SafeBrowsingNavigationObserverManager, |
| 132 public content::NotificationObserver { |
| 132 public: | 133 public: |
| 133 TestNavigationObserverManager() : SafeBrowsingNavigationObserverManager() { | 134 TestNavigationObserverManager() : SafeBrowsingNavigationObserverManager() { |
| 134 registrar_.Add(this, chrome::NOTIFICATION_TAB_ADDED, | 135 registrar_.Add(this, chrome::NOTIFICATION_TAB_ADDED, |
| 135 content::NotificationService::AllSources()); | 136 content::NotificationService::AllSources()); |
| 136 } | 137 } |
| 137 | 138 |
| 138 void Observe(int type, | 139 void Observe(int type, |
| 139 const content::NotificationSource& source, | 140 const content::NotificationSource& source, |
| 140 const content::NotificationDetails& details) override { | 141 const content::NotificationDetails& details) override { |
| 141 if (type == chrome::NOTIFICATION_TAB_ADDED) { | 142 if (type == chrome::NOTIFICATION_TAB_ADDED) { |
| 142 content::WebContents* dest_content = | 143 content::WebContents* dest_content = |
| 143 content::Details<content::WebContents>(details).ptr(); | 144 content::Details<content::WebContents>(details).ptr(); |
| 144 DCHECK(dest_content); | 145 DCHECK(dest_content); |
| 145 observer_list_.push_back( | 146 observer_list_.push_back( |
| 146 new SafeBrowsingNavigationObserver(dest_content, this)); | 147 new SafeBrowsingNavigationObserver(dest_content, this)); |
| 147 DCHECK(observer_list_.back()); | 148 DCHECK(observer_list_.back()); |
| 148 } else if (type == chrome::NOTIFICATION_RETARGETING) { | |
| 149 RecordRetargeting(details); | |
| 150 } | 149 } |
| 151 } | 150 } |
| 152 | 151 |
| 153 protected: | 152 protected: |
| 154 ~TestNavigationObserverManager() override { observer_list_.clear(); } | 153 ~TestNavigationObserverManager() override { observer_list_.clear(); } |
| 155 | 154 |
| 156 private: | 155 private: |
| 157 std::vector<SafeBrowsingNavigationObserver*> observer_list_; | 156 std::vector<SafeBrowsingNavigationObserver*> observer_list_; |
| 157 |
| 158 content::NotificationRegistrar registrar_; |
| 158 }; | 159 }; |
| 159 | 160 |
| 160 class SBNavigationObserverBrowserTest : public InProcessBrowserTest { | 161 class SBNavigationObserverBrowserTest : public InProcessBrowserTest { |
| 161 public: | 162 public: |
| 162 SBNavigationObserverBrowserTest() {} | 163 SBNavigationObserverBrowserTest() {} |
| 163 | 164 |
| 164 void SetUpOnMainThread() override { | 165 void SetUpOnMainThread() override { |
| 165 // Disable Safe Browsing service since it is irrelevant to this test. | 166 // Disable Safe Browsing service since it is irrelevant to this test. |
| 166 browser()->profile()->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled, | 167 browser()->profile()->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled, |
| 167 false); | 168 false); |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 ASSERT_TRUE(nav_list); | 576 ASSERT_TRUE(nav_list); |
| 576 ASSERT_EQ(3U, nav_list->Size()); | 577 ASSERT_EQ(3U, nav_list->Size()); |
| 577 VerifyNavigationEvent(GURL(), // source_url | 578 VerifyNavigationEvent(GURL(), // source_url |
| 578 GURL(), // source_main_frame_url | 579 GURL(), // source_main_frame_url |
| 579 initial_url, // original_request_url | 580 initial_url, // original_request_url |
| 580 initial_url, // destination_url | 581 initial_url, // destination_url |
| 581 true, // is_user_initiated, | 582 true, // is_user_initiated, |
| 582 true, // has_committed | 583 true, // has_committed |
| 583 false, // has_server_redirect | 584 false, // has_server_redirect |
| 584 nav_list->Get(0)); | 585 nav_list->Get(0)); |
| 585 // The next NavigationEvent was obtained from NOIFICATION_RETARGETING. | 586 // The next NavigationEvent opens a new tab. |
| 586 // TODO(jialiul): After https://crbug.com/651895 is fixed, we'll no longer | |
| 587 // listen to NOTIFICATION_RETARGETING, hence only one NavigationEvent will | |
| 588 // be observed with the true initator URL. This applies to other new tab | |
| 589 // download, and target blank download test cases too. | |
| 590 VerifyNavigationEvent(initial_url, // source_url | 587 VerifyNavigationEvent(initial_url, // source_url |
| 591 initial_url, // source_main_frame_url | 588 initial_url, // source_main_frame_url |
| 592 download_url, // original_request_url | 589 download_url, // original_request_url |
| 593 download_url, // destination_url | 590 download_url, // destination_url |
| 594 true, // is_user_initiated, | 591 true, // is_user_initiated, |
| 595 false, // has_committed | 592 false, // has_committed |
| 596 false, // has_server_redirect | 593 false, // has_server_redirect |
| 597 nav_list->Get(1)); | 594 nav_list->Get(1)); |
| 598 // This one is the actual navigation which triggers download. | 595 // This one is the actual navigation which triggers download. |
| 599 VerifyNavigationEvent(GURL(), // source_url | 596 VerifyNavigationEvent(GURL(), // source_url |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 ASSERT_TRUE(nav_list); | 711 ASSERT_TRUE(nav_list); |
| 715 ASSERT_EQ(4U, nav_list->Size()); | 712 ASSERT_EQ(4U, nav_list->Size()); |
| 716 VerifyNavigationEvent(GURL(), // source_url | 713 VerifyNavigationEvent(GURL(), // source_url |
| 717 GURL(), // source_main_frame_url | 714 GURL(), // source_main_frame_url |
| 718 initial_url, // original_request_url | 715 initial_url, // original_request_url |
| 719 initial_url, // destination_url | 716 initial_url, // destination_url |
| 720 true, // is_user_initiated, | 717 true, // is_user_initiated, |
| 721 true, // has_committed | 718 true, // has_committed |
| 722 false, // has_server_redirect | 719 false, // has_server_redirect |
| 723 nav_list->Get(0)); | 720 nav_list->Get(0)); |
| 724 // TODO(jialiul): After https://crbug.com/651895 is fixed, we'll no longer | |
| 725 // listen to NOTIFICATION_RETARGETING, hence only two NavigationEvents will | |
| 726 // be observed with the true initator URL. | |
| 727 VerifyNavigationEvent(initial_url, // source_url | 721 VerifyNavigationEvent(initial_url, // source_url |
| 728 initial_url, // source_main_frame_url | 722 initial_url, // source_main_frame_url |
| 729 redirect_url, // original_request_url | 723 redirect_url, // original_request_url |
| 730 redirect_url, // destination_url | 724 redirect_url, // destination_url |
| 731 true, // is_user_initiated, | 725 true, // is_user_initiated, |
| 732 false, // has_committed | 726 false, // has_committed |
| 733 false, // has_server_redirect | 727 false, // has_server_redirect |
| 734 nav_list->Get(1)); | 728 nav_list->Get(1)); |
| 735 VerifyNavigationEvent(GURL(), // source_url | 729 VerifyNavigationEvent(GURL(), // source_url |
| 736 GURL(), // source_main_frame_url | 730 GURL(), // source_main_frame_url |
| (...skipping 1228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1965 GURL(), // main_frame_url | 1959 GURL(), // main_frame_url |
| 1966 ReferrerChainEntry::CLIENT_REDIRECT, // type | 1960 ReferrerChainEntry::CLIENT_REDIRECT, // type |
| 1967 test_server_ip, // ip_address | 1961 test_server_ip, // ip_address |
| 1968 GURL(), // referrer_url | 1962 GURL(), // referrer_url |
| 1969 GURL(), // referrer_main_frame_url | 1963 GURL(), // referrer_main_frame_url |
| 1970 false, // is_retargeting | 1964 false, // is_retargeting |
| 1971 std::vector<GURL>(), // server redirects | 1965 std::vector<GURL>(), // server redirects |
| 1972 referrer_chain.Get(0)); | 1966 referrer_chain.Get(0)); |
| 1973 } | 1967 } |
| 1974 } // namespace safe_browsing | 1968 } // namespace safe_browsing |
| OLD | NEW |