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

Side by Side Diff: chrome/browser/ui/browser_close_browsertest.cc

Issue 10535026: Move creation and ownership of DownloadManager from the embedder to content. This matches all the o… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix cros compile Created 8 years, 6 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 | Annotate | Revision Log
OLDNEW
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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/stringprintf.h" 8 #include "base/stringprintf.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/download/download_service.h" 10 #include "chrome/browser/download/download_service.h"
11 #include "chrome/browser/download/download_service_factory.h" 11 #include "chrome/browser/download/download_service_factory.h"
12 #include "chrome/browser/download/download_test_observer.h" 12 #include "chrome/browser/download/download_test_observer.h"
13 #include "chrome/browser/net/url_request_mock_util.h" 13 #include "chrome/browser/net/url_request_mock_util.h"
14 #include "chrome/browser/prefs/pref_service.h" 14 #include "chrome/browser/prefs/pref_service.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/profiles/profile_manager.h" 16 #include "chrome/browser/profiles/profile_manager.h"
17 #include "chrome/browser/ui/browser.h" 17 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/browser_window.h" 18 #include "chrome/browser/ui/browser_window.h"
19 #include "chrome/common/chrome_paths.h" 19 #include "chrome/common/chrome_paths.h"
20 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
21 #include "chrome/common/url_constants.h" 21 #include "chrome/common/url_constants.h"
22 #include "chrome/test/base/in_process_browser_test.h" 22 #include "chrome/test/base/in_process_browser_test.h"
23 #include "chrome/test/base/ui_test_utils.h" 23 #include "chrome/test/base/ui_test_utils.h"
24 #include "content/public/browser/download_item.h" 24 #include "content/public/browser/download_item.h"
25 #include "content/public/common/page_transition_types.h" 25 #include "content/public/common/page_transition_types.h"
26 #include "content/test/net/url_request_slow_download_job.h" 26 #include "content/test/net/url_request_slow_download_job.h"
27 27
28 using content::BrowserContext;
28 using content::BrowserThread; 29 using content::BrowserThread;
29 using content::DownloadItem; 30 using content::DownloadItem;
30 using content::DownloadManager; 31 using content::DownloadManager;
31 32
32 class BrowserCloseTest : public InProcessBrowserTest { 33 class BrowserCloseTest : public InProcessBrowserTest {
33 public: 34 public:
34 // Structure defining test cases for DownloadsCloseCheck. 35 // Structure defining test cases for DownloadsCloseCheck.
35 struct DownloadsCloseCheckCase { 36 struct DownloadsCloseCheckCase {
36 std::string DebugString() const; 37 std::string DebugString() const;
37 38
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 // browser with active downloads. 106 // browser with active downloads.
106 void CreateStalledDownloads(Browser* browser, int num_downloads) { 107 void CreateStalledDownloads(Browser* browser, int num_downloads) {
107 GURL url(URLRequestSlowDownloadJob::kKnownSizeUrl); 108 GURL url(URLRequestSlowDownloadJob::kKnownSizeUrl);
108 109
109 if (num_downloads == 0) 110 if (num_downloads == 0)
110 return; 111 return;
111 112
112 // Setup an observer waiting for the given number of downloads 113 // Setup an observer waiting for the given number of downloads
113 // to get to IN_PROGRESS. 114 // to get to IN_PROGRESS.
114 DownloadManager* download_manager = 115 DownloadManager* download_manager =
115 browser->profile()->GetDownloadManager(); 116 BrowserContext::GetDownloadManager(browser->profile());
116 scoped_ptr<DownloadTestObserver> observer( 117 scoped_ptr<DownloadTestObserver> observer(
117 new DownloadTestObserverInProgress(download_manager, 118 new DownloadTestObserverInProgress(download_manager,
118 num_downloads, 119 num_downloads,
119 true)); // Bail on select file. 120 true)); // Bail on select file.
120 121
121 // Set of that number of downloads. 122 // Set of that number of downloads.
122 size_t count_downloads = num_downloads; 123 size_t count_downloads = num_downloads;
123 while (num_downloads--) 124 while (num_downloads--)
124 ui_test_utils::NavigateToURLWithDisposition( 125 ui_test_utils::NavigateToURLWithDisposition(
125 browser, url, NEW_BACKGROUND_TAB, 126 browser, url, NEW_BACKGROUND_TAB,
(...skipping 13 matching lines...) Expand all
139 140
140 // Go through and, for every single profile, wait until there are 141 // Go through and, for every single profile, wait until there are
141 // no active downloads on that download manager. 142 // no active downloads on that download manager.
142 std::vector<Profile*> profiles( 143 std::vector<Profile*> profiles(
143 g_browser_process->profile_manager()->GetLoadedProfiles()); 144 g_browser_process->profile_manager()->GetLoadedProfiles());
144 for (std::vector<Profile*>::const_iterator pit = profiles.begin(); 145 for (std::vector<Profile*>::const_iterator pit = profiles.begin();
145 pit != profiles.end(); ++pit) { 146 pit != profiles.end(); ++pit) {
146 DownloadService* download_service = 147 DownloadService* download_service =
147 DownloadServiceFactory::GetForProfile(*pit); 148 DownloadServiceFactory::GetForProfile(*pit);
148 if (download_service->HasCreatedDownloadManager()) { 149 if (download_service->HasCreatedDownloadManager()) {
149 DownloadManager *mgr = download_service->GetDownloadManager(); 150 DownloadManager *mgr = BrowserContext::GetDownloadManager(*pit);
150 scoped_refptr<DownloadTestFlushObserver> observer( 151 scoped_refptr<DownloadTestFlushObserver> observer(
151 new DownloadTestFlushObserver(mgr)); 152 new DownloadTestFlushObserver(mgr));
152 observer->WaitForFlush(); 153 observer->WaitForFlush();
153 } 154 }
154 if ((*pit)->HasOffTheRecordProfile()) { 155 if ((*pit)->HasOffTheRecordProfile()) {
155 DownloadService* incognito_download_service = 156 DownloadService* incognito_download_service =
156 DownloadServiceFactory::GetForProfile( 157 DownloadServiceFactory::GetForProfile(
157 (*pit)->GetOffTheRecordProfile()); 158 (*pit)->GetOffTheRecordProfile());
158 if (incognito_download_service->HasCreatedDownloadManager()) { 159 if (incognito_download_service->HasCreatedDownloadManager()) {
159 DownloadManager *mgr = 160 DownloadManager *mgr = BrowserContext::GetDownloadManager(
160 incognito_download_service->GetDownloadManager(); 161 (*pit)->GetOffTheRecordProfile());
161 scoped_refptr<DownloadTestFlushObserver> observer( 162 scoped_refptr<DownloadTestFlushObserver> observer(
162 new DownloadTestFlushObserver(mgr)); 163 new DownloadTestFlushObserver(mgr));
163 observer->WaitForFlush(); 164 observer->WaitForFlush();
164 } 165 }
165 } 166 }
166 } 167 }
167 } 168 }
168 169
169 // Create a Browser (with associated window) on the specified profile. 170 // Create a Browser (with associated window) on the specified profile.
170 Browser* CreateBrowserOnProfile(Profile* profile) { 171 Browser* CreateBrowserOnProfile(Profile* profile) {
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 } 567 }
567 } 568 }
568 569
569 IN_PROC_BROWSER_TEST_F(BrowserCloseTest, MAYBE_DownloadsCloseCheck_5) { 570 IN_PROC_BROWSER_TEST_F(BrowserCloseTest, MAYBE_DownloadsCloseCheck_5) {
570 ASSERT_TRUE(SetupForDownloadCloseCheck()); 571 ASSERT_TRUE(SetupForDownloadCloseCheck());
571 for (size_t i = 5 * arraysize(download_close_check_cases) / 6; 572 for (size_t i = 5 * arraysize(download_close_check_cases) / 6;
572 i < 6 * arraysize(download_close_check_cases) / 6; ++i) { 573 i < 6 * arraysize(download_close_check_cases) / 6; ++i) {
573 ExecuteDownloadCloseCheckCase(i); 574 ExecuteDownloadCloseCheckCase(i);
574 } 575 }
575 } 576 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698