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

Side by Side Diff: chrome/browser/google_url_tracker_unittest.cc

Issue 3198001: Fix leaks in GoogleURLTrackerTest::CreateRequestContext() (Closed)
Patch Set: Created 10 years, 4 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
« no previous file with comments | « no previous file | chrome/common/net/test_url_fetcher_factory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/google_url_tracker.h" 5 #include "chrome/browser/google_url_tracker.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "chrome/browser/browser_process.h" 7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/profile.h" 8 #include "chrome/browser/profile.h"
9 #include "chrome/browser/tab_contents/infobar_delegate.h" 9 #include "chrome/browser/tab_contents/infobar_delegate.h"
10 #include "chrome/common/net/url_fetcher.h" 10 #include "chrome/common/net/url_fetcher.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 const GURL& new_google_url) { 63 const GURL& new_google_url) {
64 return new TestInfoBar(google_url_tracker, new_google_url); 64 return new TestInfoBar(google_url_tracker, new_google_url);
65 } 65 }
66 }; 66 };
67 67
68 } // anonymous namespace 68 } // anonymous namespace
69 69
70 class GoogleURLTrackerTest : public testing::Test { 70 class GoogleURLTrackerTest : public testing::Test {
71 protected: 71 protected:
72 GoogleURLTrackerTest() 72 GoogleURLTrackerTest()
73 : original_default_request_context_(NULL) { 73 : message_loop_(MessageLoop::TYPE_IO),
74 io_thread_(ChromeThread::IO, &message_loop_),
75 original_default_request_context_(NULL) {
74 } 76 }
75 77
76 void SetUp() { 78 void SetUp() {
77 original_default_request_context_ = Profile::GetDefaultRequestContext(); 79 original_default_request_context_ = Profile::GetDefaultRequestContext();
78 Profile::set_default_request_context(NULL); 80 Profile::set_default_request_context(NULL);
79 message_loop_ = new MessageLoop(MessageLoop::TYPE_IO);
80 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); 81 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock());
81 testing_profile_.reset(new TestingProfile); 82 testing_profile_.reset(new TestingProfile);
82 TestingBrowserProcess* testing_browser_process = 83 TestingBrowserProcess* testing_browser_process =
83 static_cast<TestingBrowserProcess*>(g_browser_process); 84 static_cast<TestingBrowserProcess*>(g_browser_process);
84 PrefService* pref_service = testing_profile_->GetPrefs(); 85 PrefService* pref_service = testing_profile_->GetPrefs();
85 testing_browser_process->SetPrefService(pref_service); 86 testing_browser_process->SetPrefService(pref_service);
86 testing_browser_process->SetGoogleURLTracker(new GoogleURLTracker); 87 testing_browser_process->SetGoogleURLTracker(new GoogleURLTracker);
87 88
88 URLFetcher::set_factory(&fetcher_factory_); 89 URLFetcher::set_factory(&fetcher_factory_);
89 observer_.reset(new TestNotificationObserver); 90 observer_.reset(new TestNotificationObserver);
90 g_browser_process->google_url_tracker()->infobar_factory_.reset( 91 g_browser_process->google_url_tracker()->infobar_factory_.reset(
91 new TestInfoBarDelegateFactory); 92 new TestInfoBarDelegateFactory);
92 } 93 }
93 94
94 void TearDown() { 95 void TearDown() {
95 URLFetcher::set_factory(NULL); 96 URLFetcher::set_factory(NULL);
96 TestingBrowserProcess* testing_browser_process = 97 TestingBrowserProcess* testing_browser_process =
97 static_cast<TestingBrowserProcess*>(g_browser_process); 98 static_cast<TestingBrowserProcess*>(g_browser_process);
98 testing_browser_process->SetGoogleURLTracker(NULL); 99 testing_browser_process->SetGoogleURLTracker(NULL);
99 testing_browser_process->SetPrefService(NULL); 100 testing_browser_process->SetPrefService(NULL);
100 testing_profile_.reset(); 101 testing_profile_.reset();
101 network_change_notifier_.reset(); 102 network_change_notifier_.reset();
102 delete message_loop_;
103 Profile::set_default_request_context(original_default_request_context_); 103 Profile::set_default_request_context(original_default_request_context_);
104 } 104 }
105 105
106 void CreateRequestContext() { 106 void CreateRequestContext() {
107 testing_profile_->CreateRequestContext(); 107 testing_profile_->CreateRequestContext();
108 Profile::set_default_request_context(testing_profile_->GetRequestContext()); 108 Profile::set_default_request_context(testing_profile_->GetRequestContext());
109 NotificationService::current()->Notify( 109 NotificationService::current()->Notify(
110 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE, 110 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE,
111 NotificationService::AllSources(), NotificationService::NoDetails()); 111 NotificationService::AllSources(), NotificationService::NoDetails());
112 } 112 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 delete infobar; 207 delete infobar;
208 } 208 }
209 209
210 void ExpectDefaultURLs() { 210 void ExpectDefaultURLs() {
211 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), 211 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage),
212 GoogleURLTracker::GoogleURL()); 212 GoogleURLTracker::GoogleURL());
213 EXPECT_EQ(GURL(), GetFetchedGoogleURL()); 213 EXPECT_EQ(GURL(), GetFetchedGoogleURL());
214 } 214 }
215 215
216 private: 216 private:
217 MessageLoop* message_loop_; 217 MessageLoop message_loop_;
218 ChromeThread io_thread_;
218 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; 219 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
219 scoped_ptr<TestingProfile> testing_profile_; 220 scoped_ptr<TestingProfile> testing_profile_;
220 221
221 TestURLFetcherFactory fetcher_factory_; 222 TestURLFetcherFactory fetcher_factory_;
222 NotificationRegistrar registrar_; 223 NotificationRegistrar registrar_;
223 scoped_ptr<NotificationObserver> observer_; 224 scoped_ptr<NotificationObserver> observer_;
224 225
225 URLRequestContextGetter* original_default_request_context_; 226 URLRequestContextGetter* original_default_request_context_;
226 }; 227 };
227 228
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); 444 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
444 445
445 SearchCommitted(GURL("http://www.google.co.uk/search?q=test")); 446 SearchCommitted(GURL("http://www.google.co.uk/search?q=test"));
446 NavEntryCommitted(); 447 NavEntryCommitted();
447 448
448 EXPECT_FALSE(InfoBarIsShown()); 449 EXPECT_FALSE(InfoBarIsShown());
449 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetFetchedGoogleURL()); 450 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetFetchedGoogleURL());
450 EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL()); 451 EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL());
451 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); 452 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
452 } 453 }
OLDNEW
« no previous file with comments | « no previous file | chrome/common/net/test_url_fetcher_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698