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 "chrome/browser/safe_browsing/safe_browsing_navigation_observer.h" | 5 #include "chrome/browser/safe_browsing/safe_browsing_navigation_observer.h" |
| 6 | 6 |
| 7 #include "base/test/histogram_tester.h" | 7 #include "base/test/histogram_tester.h" |
| 8 #include "chrome/browser/safe_browsing/safe_browsing_navigation_observer_manager .h" | 8 #include "chrome/browser/safe_browsing/safe_browsing_navigation_observer_manager .h" |
| 9 #include "chrome/browser/sessions/session_tab_helper.h" | 9 #include "chrome/browser/sessions/session_tab_helper.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 EXPECT_EQ(nullptr, | 242 EXPECT_EQ(nullptr, |
| 243 navigation_event_list()->FindNavigationEvent(url_1, GURL(), -1)); | 243 navigation_event_list()->FindNavigationEvent(url_1, GURL(), -1)); |
| 244 EXPECT_THAT(histograms.GetAllSamples(kNavigationEventCleanUpHistogramName), | 244 EXPECT_THAT(histograms.GetAllSamples(kNavigationEventCleanUpHistogramName), |
| 245 testing::ElementsAre(base::Bucket(4, 1))); | 245 testing::ElementsAre(base::Bucket(4, 1))); |
| 246 } | 246 } |
| 247 | 247 |
| 248 TEST_F(SBNavigationObserverTest, TestCleanUpStaleUserGestures) { | 248 TEST_F(SBNavigationObserverTest, TestCleanUpStaleUserGestures) { |
| 249 // Sets up user_gesture_map() such that it includes fresh, stale and invalid | 249 // Sets up user_gesture_map() such that it includes fresh, stale and invalid |
| 250 // user gestures. | 250 // user gestures. |
| 251 base::Time now = base::Time::Now(); // Fresh | 251 base::Time now = base::Time::Now(); // Fresh |
| 252 base::Time one_minute_ago = | 252 base::Time three_minute_ago = |
|
lpz
2017/05/17 20:22:04
nit: three_minuteS_ago
Jialiu Lin
2017/05/17 20:58:24
Good catch. Done.
| |
| 253 base::Time::FromDoubleT(now.ToDoubleT() - 60.0); // Stale | 253 base::Time::FromDoubleT(now.ToDoubleT() - 60.0 * 3); // Stale |
| 254 base::Time in_an_hour = | 254 base::Time in_an_hour = |
| 255 base::Time::FromDoubleT(now.ToDoubleT() + 60.0 * 60.0); // Invalid | 255 base::Time::FromDoubleT(now.ToDoubleT() + 60.0 * 60.0); // Invalid |
| 256 AddTab(browser(), GURL("http://foo/1")); | 256 AddTab(browser(), GURL("http://foo/1")); |
| 257 AddTab(browser(), GURL("http://foo/2")); | 257 AddTab(browser(), GURL("http://foo/2")); |
| 258 content::WebContents* content0 = | 258 content::WebContents* content0 = |
| 259 browser()->tab_strip_model()->GetWebContentsAt(0); | 259 browser()->tab_strip_model()->GetWebContentsAt(0); |
| 260 content::WebContents* content1 = | 260 content::WebContents* content1 = |
| 261 browser()->tab_strip_model()->GetWebContentsAt(1); | 261 browser()->tab_strip_model()->GetWebContentsAt(1); |
| 262 content::WebContents* content2 = | 262 content::WebContents* content2 = |
| 263 browser()->tab_strip_model()->GetWebContentsAt(2); | 263 browser()->tab_strip_model()->GetWebContentsAt(2); |
| 264 user_gesture_map()->insert(std::make_pair(content0, now)); | 264 user_gesture_map()->insert(std::make_pair(content0, now)); |
| 265 user_gesture_map()->insert(std::make_pair(content1, one_minute_ago)); | 265 user_gesture_map()->insert(std::make_pair(content1, three_minute_ago)); |
| 266 user_gesture_map()->insert(std::make_pair(content2, in_an_hour)); | 266 user_gesture_map()->insert(std::make_pair(content2, in_an_hour)); |
| 267 ASSERT_EQ(3U, user_gesture_map()->size()); | 267 ASSERT_EQ(3U, user_gesture_map()->size()); |
| 268 | 268 |
| 269 // Cleans up user_gesture_map() | 269 // Cleans up user_gesture_map() |
| 270 CleanUpUserGestures(); | 270 CleanUpUserGestures(); |
| 271 | 271 |
| 272 // Verifies all stale and invalid user gestures are removed. | 272 // Verifies all stale and invalid user gestures are removed. |
| 273 ASSERT_EQ(1U, user_gesture_map()->size()); | 273 ASSERT_EQ(1U, user_gesture_map()->size()); |
| 274 EXPECT_NE(user_gesture_map()->end(), user_gesture_map()->find(content0)); | 274 EXPECT_NE(user_gesture_map()->end(), user_gesture_map()->find(content0)); |
| 275 EXPECT_EQ(now, user_gesture_map()->at(content0)); | 275 EXPECT_EQ(now, user_gesture_map()->at(content0)); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 341 // 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. |
| 342 std::string host_1 = GURL("http://bar/1").host(); | 342 std::string host_1 = GURL("http://bar/1").host(); |
| 343 RecordHostToIpMapping(host_1, "9.9.9.9"); | 343 RecordHostToIpMapping(host_1, "9.9.9.9"); |
| 344 ASSERT_EQ(2U, host_to_ip_map()->size()); | 344 ASSERT_EQ(2U, host_to_ip_map()->size()); |
| 345 EXPECT_EQ(3U, host_to_ip_map()->at(host_0).size()); | 345 EXPECT_EQ(3U, host_to_ip_map()->at(host_0).size()); |
| 346 EXPECT_EQ(1U, host_to_ip_map()->at(host_1).size()); | 346 EXPECT_EQ(1U, host_to_ip_map()->at(host_1).size()); |
| 347 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); |
| 348 } | 348 } |
| 349 | 349 |
| 350 } // namespace safe_browsing | 350 } // namespace safe_browsing |
| OLD | NEW |