OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/pickle.h" | 11 #include "base/pickle.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "base/test/histogram_tester.h" | 13 #include "base/test/histogram_tester.h" |
14 #include "base/test/scoped_feature_list.h" | |
15 #include "base/time/time.h" | 14 #include "base/time/time.h" |
16 #include "chrome/browser/history/history_service_factory.h" | 15 #include "chrome/browser/history/history_service_factory.h" |
17 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 17 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
19 #include "chrome/browser/safe_browsing/threat_details.h" | 18 #include "chrome/browser/safe_browsing/threat_details.h" |
20 #include "chrome/browser/safe_browsing/threat_details_history.h" | 19 #include "chrome/browser/safe_browsing/threat_details_history.h" |
21 #include "chrome/browser/safe_browsing/ui_manager.h" | 20 #include "chrome/browser/safe_browsing/ui_manager.h" |
22 #include "chrome/common/safe_browsing/csd.pb.h" | 21 #include "chrome/common/safe_browsing/csd.pb.h" |
23 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 22 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
24 #include "chrome/test/base/testing_profile.h" | 23 #include "chrome/test/base/testing_profile.h" |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 class ThreatDetailsTest : public ChromeRenderViewHostTestHarness { | 205 class ThreatDetailsTest : public ChromeRenderViewHostTestHarness { |
207 public: | 206 public: |
208 typedef SafeBrowsingUIManager::UnsafeResource UnsafeResource; | 207 typedef SafeBrowsingUIManager::UnsafeResource UnsafeResource; |
209 | 208 |
210 ThreatDetailsTest() : ui_manager_(new MockSafeBrowsingUIManager()) {} | 209 ThreatDetailsTest() : ui_manager_(new MockSafeBrowsingUIManager()) {} |
211 | 210 |
212 void SetUp() override { | 211 void SetUp() override { |
213 ChromeRenderViewHostTestHarness::SetUp(); | 212 ChromeRenderViewHostTestHarness::SetUp(); |
214 ASSERT_TRUE(profile()->CreateHistoryService(true /* delete_file */, | 213 ASSERT_TRUE(profile()->CreateHistoryService(true /* delete_file */, |
215 false /* no_db */)); | 214 false /* no_db */)); |
216 | |
217 feature_list_.reset(new base::test::ScopedFeatureList); | |
218 feature_list_->InitAndEnableFeature(kFillDOMInThreatDetails); | |
219 } | 215 } |
220 | 216 |
221 std::string WaitForSerializedReport(ThreatDetails* report, | 217 std::string WaitForSerializedReport(ThreatDetails* report, |
222 bool did_proceed, | 218 bool did_proceed, |
223 int num_visit) { | 219 int num_visit) { |
224 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 220 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
225 base::Bind(&ThreatDetails::FinishCollection, report, | 221 base::Bind(&ThreatDetails::FinishCollection, report, |
226 did_proceed, num_visit)); | 222 did_proceed, num_visit)); |
227 // Wait for the callback (SendSerializedThreatDetails). | 223 // Wait for the callback (SendSerializedThreatDetails). |
228 DVLOG(1) << "Waiting for SendSerializedThreatDetails"; | 224 DVLOG(1) << "Waiting for SendSerializedThreatDetails"; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 // The last item of the redirect chain has to be the final url when adding | 360 // The last item of the redirect chain has to be the final url when adding |
365 // to history backend. | 361 // to history backend. |
366 redirects->push_back(url); | 362 redirects->push_back(url); |
367 history_service()->AddPage(url, base::Time::Now(), | 363 history_service()->AddPage(url, base::Time::Now(), |
368 reinterpret_cast<history::ContextID>(1), 0, | 364 reinterpret_cast<history::ContextID>(1), 0, |
369 GURL(), *redirects, ui::PAGE_TRANSITION_TYPED, | 365 GURL(), *redirects, ui::PAGE_TRANSITION_TYPED, |
370 history::SOURCE_BROWSED, false); | 366 history::SOURCE_BROWSED, false); |
371 } | 367 } |
372 | 368 |
373 scoped_refptr<MockSafeBrowsingUIManager> ui_manager_; | 369 scoped_refptr<MockSafeBrowsingUIManager> ui_manager_; |
374 std::unique_ptr<base::test::ScopedFeatureList> feature_list_; | |
375 }; | 370 }; |
376 | 371 |
377 // Tests creating a simple threat report of a malware URL. | 372 // Tests creating a simple threat report of a malware URL. |
378 TEST_F(ThreatDetailsTest, ThreatSubResource) { | 373 TEST_F(ThreatDetailsTest, ThreatSubResource) { |
379 // Commit a load. | 374 // Commit a load. |
380 content::WebContentsTester::For(web_contents()) | 375 content::WebContentsTester::For(web_contents()) |
381 ->TestDidNavigateWithReferrer( | 376 ->TestDidNavigateWithReferrer( |
382 web_contents()->GetMainFrame(), 0 /* nav_entry_id */, | 377 web_contents()->GetMainFrame(), 0 /* nav_entry_id */, |
383 true /* did_create_new_entry */, GURL(kLandingURL), | 378 true /* did_create_new_entry */, GURL(kLandingURL), |
384 content::Referrer(GURL(kReferrerURL), | 379 content::Referrer(GURL(kReferrerURL), |
(...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1329 pb_resource->set_parent_id(3); | 1324 pb_resource->set_parent_id(3); |
1330 pb_resource->set_url(kSecondRedirectURL); | 1325 pb_resource->set_url(kSecondRedirectURL); |
1331 pb_resource = expected.add_resources(); | 1326 pb_resource = expected.add_resources(); |
1332 pb_resource->set_id(3); | 1327 pb_resource->set_id(3); |
1333 pb_resource->set_url(kFirstRedirectURL); | 1328 pb_resource->set_url(kFirstRedirectURL); |
1334 | 1329 |
1335 VerifyResults(actual, expected); | 1330 VerifyResults(actual, expected); |
1336 } | 1331 } |
1337 | 1332 |
1338 } // namespace safe_browsing | 1333 } // namespace safe_browsing |
OLD | NEW |