| 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 "chrome/browser/safe_browsing/safe_browsing_navigation_observer.h" |
| 6 |
| 5 #include "base/test/histogram_tester.h" | 7 #include "base/test/histogram_tester.h" |
| 6 #include "chrome/browser/safe_browsing/safe_browsing_navigation_observer.h" | |
| 7 #include "chrome/browser/safe_browsing/safe_browsing_navigation_observer_manager
.h" | 8 #include "chrome/browser/safe_browsing/safe_browsing_navigation_observer_manager
.h" |
| 8 #include "chrome/browser/sessions/session_tab_helper.h" | 9 #include "chrome/browser/sessions/session_tab_helper.h" |
| 9 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 10 #include "chrome/test/base/browser_with_test_window_test.h" | 11 #include "chrome/test/base/browser_with_test_window_test.h" |
| 12 #include "content/public/common/browser_side_navigation_policy.h" |
| 11 #include "content/public/test/test_renderer_host.h" | 13 #include "content/public/test/test_renderer_host.h" |
| 14 #include "content/public/test/test_utils.h" |
| 12 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "ui/base/window_open_disposition.h" | 17 #include "ui/base/window_open_disposition.h" |
| 15 | 18 |
| 16 namespace { | 19 namespace { |
| 17 | 20 |
| 18 const char kNavigationEventCleanUpHistogramName[] = | 21 const char kNavigationEventCleanUpHistogramName[] = |
| 19 "SafeBrowsing.NavigationObserver.NavigationEventCleanUpCount"; | 22 "SafeBrowsing.NavigationObserver.NavigationEventCleanUpCount"; |
| 20 const char kIPAddressCleanUpHistogramName[] = | 23 const char kIPAddressCleanUpHistogramName[] = |
| 21 "SafeBrowsing.NavigationObserver.IPAddressCleanUpCount"; | 24 "SafeBrowsing.NavigationObserver.IPAddressCleanUpCount"; |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 GURL("http://foo/1"), // destination_url | 169 GURL("http://foo/1"), // destination_url |
| 167 tab_id, // source_tab_id | 170 tab_id, // source_tab_id |
| 168 tab_id, // target_tab_id | 171 tab_id, // target_tab_id |
| 169 true, // is_user_initiated | 172 true, // is_user_initiated |
| 170 true, // has_committed | 173 true, // has_committed |
| 171 false, // has_server_redirect | 174 false, // has_server_redirect |
| 172 nav_list->Get(0U)); | 175 nav_list->Get(0U)); |
| 173 } | 176 } |
| 174 | 177 |
| 175 TEST_F(SBNavigationObserverTest, ServerRedirect) { | 178 TEST_F(SBNavigationObserverTest, ServerRedirect) { |
| 179 if (content::IsBrowserSideNavigationEnabled() && |
| 180 content::AreAllSitesIsolatedForTesting()) { |
| 181 // http://crbug.com/674734 Fix this test with PlzNavigate and Site Isolation |
| 182 return; |
| 183 } |
| 176 content::RenderFrameHostTester* rfh_tester = | 184 content::RenderFrameHostTester* rfh_tester = |
| 177 content::RenderFrameHostTester::For( | 185 content::RenderFrameHostTester::For( |
| 178 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame()); | 186 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame()); |
| 179 rfh_tester->SimulateNavigationStart(GURL("http://foo/3")); | 187 rfh_tester->SimulateNavigationStart(GURL("http://foo/3")); |
| 180 GURL redirect("http://redirect/1"); | 188 GURL redirect("http://redirect/1"); |
| 181 rfh_tester->SimulateRedirect(redirect); | 189 rfh_tester->SimulateRedirect(redirect); |
| 182 rfh_tester->SimulateNavigationCommit(redirect); | 190 rfh_tester->SimulateNavigationCommit(redirect); |
| 183 int tab_id = SessionTabHelper::IdForTab( | 191 int tab_id = SessionTabHelper::IdForTab( |
| 184 browser()->tab_strip_model()->GetWebContentsAt(0)); | 192 browser()->tab_strip_model()->GetWebContentsAt(0)); |
| 185 auto* nav_list = navigation_event_list(); | 193 auto* nav_list = navigation_event_list(); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 // Record a host-ip pair, neither of which has been seen before. | 341 // Record a host-ip pair, neither of which has been seen before. |
| 334 std::string host_1 = GURL("http://bar/1").host(); | 342 std::string host_1 = GURL("http://bar/1").host(); |
| 335 RecordHostToIpMapping(host_1, "9.9.9.9"); | 343 RecordHostToIpMapping(host_1, "9.9.9.9"); |
| 336 ASSERT_EQ(2U, host_to_ip_map()->size()); | 344 ASSERT_EQ(2U, host_to_ip_map()->size()); |
| 337 EXPECT_EQ(3U, host_to_ip_map()->at(host_0).size()); | 345 EXPECT_EQ(3U, host_to_ip_map()->at(host_0).size()); |
| 338 EXPECT_EQ(1U, host_to_ip_map()->at(host_1).size()); | 346 EXPECT_EQ(1U, host_to_ip_map()->at(host_1).size()); |
| 339 EXPECT_EQ("9.9.9.9", host_to_ip_map()->at(host_1).at(0).ip); | 347 EXPECT_EQ("9.9.9.9", host_to_ip_map()->at(host_1).at(0).ip); |
| 340 } | 348 } |
| 341 | 349 |
| 342 } // namespace safe_browsing | 350 } // namespace safe_browsing |
| OLD | NEW |