Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(472)

Side by Side Diff: chrome/browser/safe_browsing/incident_reporting/off_domain_inclusion_detector_unittest.cc

Issue 1870003002: Convert //chrome/browser/safe_browsing from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and address comments Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/incident_reporting/off_domain_inclusion_d etector.h" 5 #include "chrome/browser/safe_browsing/incident_reporting/off_domain_inclusion_d etector.h"
6 6
7 #include <memory>
7 #include <utility> 8 #include <utility>
8 9
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ptr_util.h"
13 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/run_loop.h" 16 #include "base/run_loop.h"
16 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
18 #include "base/time/time.h" 19 #include "base/time/time.h"
19 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 20 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
20 #include "chrome/browser/history/chrome_history_client.h" 21 #include "chrome/browser/history/chrome_history_client.h"
21 #include "chrome/browser/history/history_service_factory.h" 22 #include "chrome/browser/history/history_service_factory.h"
22 #include "chrome/browser/history/web_history_service_factory.h" 23 #include "chrome/browser/history/web_history_service_factory.h"
23 #include "chrome/browser/prefs/browser_prefs.h" 24 #include "chrome/browser/prefs/browser_prefs.h"
24 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
(...skipping 28 matching lines...) Expand all
53 using testing::NiceMock; 54 using testing::NiceMock;
54 using testing::Return; 55 using testing::Return;
55 using testing::Values; 56 using testing::Values;
56 57
57 namespace { 58 namespace {
58 59
59 const int kFakeRenderProcessId = 123; 60 const int kFakeRenderProcessId = 123;
60 61
61 // A BrowserContextKeyedServiceFactory::TestingFactoryFunction that creates a 62 // A BrowserContextKeyedServiceFactory::TestingFactoryFunction that creates a
62 // HistoryService for a TestingProfile. 63 // HistoryService for a TestingProfile.
63 scoped_ptr<KeyedService> BuildHistoryService(content::BrowserContext* context) { 64 std::unique_ptr<KeyedService> BuildHistoryService(
65 content::BrowserContext* context) {
64 TestingProfile* profile = static_cast<TestingProfile*>(context); 66 TestingProfile* profile = static_cast<TestingProfile*>(context);
65 67
66 // Delete the file before creating the service. 68 // Delete the file before creating the service.
67 base::FilePath history_path( 69 base::FilePath history_path(
68 profile->GetPath().Append(history::kHistoryFilename)); 70 profile->GetPath().Append(history::kHistoryFilename));
69 if (!base::DeleteFile(history_path, false) || 71 if (!base::DeleteFile(history_path, false) ||
70 base::PathExists(history_path)) { 72 base::PathExists(history_path)) {
71 ADD_FAILURE() << "failed to delete history db file " 73 ADD_FAILURE() << "failed to delete history db file "
72 << history_path.value(); 74 << history_path.value();
73 return nullptr; 75 return nullptr;
74 } 76 }
75 77
76 scoped_ptr<history::HistoryService> history_service( 78 std::unique_ptr<history::HistoryService> history_service(
77 new history::HistoryService( 79 new history::HistoryService(
78 make_scoped_ptr(new ChromeHistoryClient( 80 base::WrapUnique(new ChromeHistoryClient(
79 BookmarkModelFactory::GetForProfile(profile))), 81 BookmarkModelFactory::GetForProfile(profile))),
80 scoped_ptr<history::VisitDelegate>())); 82 std::unique_ptr<history::VisitDelegate>()));
81 if (history_service->Init( 83 if (history_service->Init(
82 history::HistoryDatabaseParamsForPath(profile->GetPath()))) { 84 history::HistoryDatabaseParamsForPath(profile->GetPath()))) {
83 return std::move(history_service); 85 return std::move(history_service);
84 } 86 }
85 87
86 ADD_FAILURE() << "failed to initialize history service"; 88 ADD_FAILURE() << "failed to initialize history service";
87 return nullptr; 89 return nullptr;
88 } 90 }
89 91
90 } // namespace 92 } // namespace
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 void SimulateTestURLRequest(const std::string& url_str, 228 void SimulateTestURLRequest(const std::string& url_str,
227 const std::string& referrer, 229 const std::string& referrer,
228 content::ResourceType resource_type, 230 content::ResourceType resource_type,
229 bool is_main_frame, 231 bool is_main_frame,
230 bool parent_is_main_frame) const { 232 bool parent_is_main_frame) const {
231 const GURL url(url_str); 233 const GURL url(url_str);
232 234
233 history::HistoryService* history_service = 235 history::HistoryService* history_service =
234 HistoryServiceFactory::GetForProfile( 236 HistoryServiceFactory::GetForProfile(
235 testing_profile_, ServiceAccessType::EXPLICIT_ACCESS); 237 testing_profile_, ServiceAccessType::EXPLICIT_ACCESS);
236 scoped_ptr<ScopedHistoryEntry> scoped_history_entry; 238 std::unique_ptr<ScopedHistoryEntry> scoped_history_entry;
237 if (ShouldAddSimulatedURLsToHistory()) 239 if (ShouldAddSimulatedURLsToHistory())
238 scoped_history_entry.reset(new ScopedHistoryEntry(history_service, url)); 240 scoped_history_entry.reset(new ScopedHistoryEntry(history_service, url));
239 241
240 scoped_ptr<net::URLRequest> url_request( 242 std::unique_ptr<net::URLRequest> url_request(
241 context_.CreateRequest(url, net::DEFAULT_PRIORITY, NULL)); 243 context_.CreateRequest(url, net::DEFAULT_PRIORITY, NULL));
242 244
243 if (!referrer.empty()) 245 if (!referrer.empty())
244 url_request->SetReferrer(referrer); 246 url_request->SetReferrer(referrer);
245 247
246 content::ResourceRequestInfo::AllocateForTesting( 248 content::ResourceRequestInfo::AllocateForTesting(
247 url_request.get(), 249 url_request.get(),
248 resource_type, 250 resource_type,
249 NULL, // resource_context 251 NULL, // resource_context
250 kFakeRenderProcessId, // render_process_id 252 kFakeRenderProcessId, // render_process_id
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 TestingProfile::TestingFactories factories; 326 TestingProfile::TestingFactories factories;
325 factories.push_back(std::make_pair(HistoryServiceFactory::GetInstance(), 327 factories.push_back(std::make_pair(HistoryServiceFactory::GetInstance(),
326 &BuildHistoryService)); 328 &BuildHistoryService));
327 // Suppress WebHistoryService since it makes network requests. 329 // Suppress WebHistoryService since it makes network requests.
328 factories.push_back(std::make_pair( 330 factories.push_back(std::make_pair(
329 WebHistoryServiceFactory::GetInstance(), 331 WebHistoryServiceFactory::GetInstance(),
330 static_cast<BrowserContextKeyedServiceFactory::TestingFactoryFunction>( 332 static_cast<BrowserContextKeyedServiceFactory::TestingFactoryFunction>(
331 NULL))); 333 NULL)));
332 334
333 // Create default prefs for the test profile. 335 // Create default prefs for the test profile.
334 scoped_ptr<syncable_prefs::TestingPrefServiceSyncable> prefs( 336 std::unique_ptr<syncable_prefs::TestingPrefServiceSyncable> prefs(
335 new syncable_prefs::TestingPrefServiceSyncable); 337 new syncable_prefs::TestingPrefServiceSyncable);
336 chrome::RegisterUserProfilePrefs(prefs->registry()); 338 chrome::RegisterUserProfilePrefs(prefs->registry());
337 339
338 // |testing_profile_| is owned by |profile_manager_|. 340 // |testing_profile_| is owned by |profile_manager_|.
339 testing_profile_ = profile_manager_->CreateTestingProfile( 341 testing_profile_ = profile_manager_->CreateTestingProfile(
340 "profile", // profile_name 342 "profile", // profile_name
341 std::move(prefs), 343 std::move(prefs),
342 base::UTF8ToUTF16("user"), // user_name 344 base::UTF8ToUTF16("user"), // user_name
343 0, // avatar_id 345 0, // avatar_id
344 std::string(), // supervised_user_id 346 std::string(), // supervised_user_id
(...skipping 18 matching lines...) Expand all
363 base::Unretained(this)))); 365 base::Unretained(this))));
364 // ProfileFromRenderProcessId doesn't *have* to be called, but if it is, it 366 // ProfileFromRenderProcessId doesn't *have* to be called, but if it is, it
365 // should always request the profile for |kFakeRenderProcessId| and this 367 // should always request the profile for |kFakeRenderProcessId| and this
366 // test will always return it |testing_profile_|. 368 // test will always return it |testing_profile_|.
367 ON_CALL(*off_domain_inclusion_detector_, 369 ON_CALL(*off_domain_inclusion_detector_,
368 ProfileFromRenderProcessId(Eq(kFakeRenderProcessId))) 370 ProfileFromRenderProcessId(Eq(kFakeRenderProcessId)))
369 .WillByDefault(Return(testing_profile_)); 371 .WillByDefault(Return(testing_profile_));
370 } 372 }
371 373
372 Profile* testing_profile_; 374 Profile* testing_profile_;
373 scoped_ptr<TestingProfileManager> profile_manager_; 375 std::unique_ptr<TestingProfileManager> profile_manager_;
374 376
375 content::TestBrowserThreadBundle thread_bundle_; 377 content::TestBrowserThreadBundle thread_bundle_;
376 net::TestURLRequestContext context_; 378 net::TestURLRequestContext context_;
377 379
378 AnalysisEvent observed_analysis_event_; 380 AnalysisEvent observed_analysis_event_;
379 381
380 scoped_ptr<MockOffDomainInclusionDetector> off_domain_inclusion_detector_; 382 std::unique_ptr<MockOffDomainInclusionDetector>
383 off_domain_inclusion_detector_;
381 384
382 DISALLOW_COPY_AND_ASSIGN(OffDomainInclusionDetectorTest); 385 DISALLOW_COPY_AND_ASSIGN(OffDomainInclusionDetectorTest);
383 }; 386 };
384 387
385 TEST_P(OffDomainInclusionDetectorTest, NoEventForIgnoredResourceTypes) { 388 TEST_P(OffDomainInclusionDetectorTest, NoEventForIgnoredResourceTypes) {
386 for (content::ResourceType tested_type : kResourceTypesIgnored) { 389 for (content::ResourceType tested_type : kResourceTypesIgnored) {
387 SCOPED_TRACE(tested_type); 390 SCOPED_TRACE(tested_type);
388 391
389 SimulateTestURLRequest("http://offdomain.com/foo", 392 SimulateTestURLRequest("http://offdomain.com/foo",
390 "http://mydomain.com/bar", 393 "http://mydomain.com/bar",
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 } 601 }
599 602
600 INSTANTIATE_TEST_CASE_P(OffDomainInclusionDetectorTestInstance, 603 INSTANTIATE_TEST_CASE_P(OffDomainInclusionDetectorTestInstance,
601 OffDomainInclusionDetectorTest, 604 OffDomainInclusionDetectorTest,
602 Values(TestCase::WHITELISTED, 605 Values(TestCase::WHITELISTED,
603 TestCase::IN_HISTORY, 606 TestCase::IN_HISTORY,
604 TestCase::IN_HISTORY_AND_WHITELISTED, 607 TestCase::IN_HISTORY_AND_WHITELISTED,
605 TestCase::UNKNOWN)); 608 TestCase::UNKNOWN));
606 609
607 } // namespace safe_browsing 610 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698