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 "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_file_chooser_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_list.h" | 18 #include "chrome/browser/ui/browser_list.h" |
19 #include "chrome/browser/ui/browser_tabstrip.h" | 19 #include "chrome/browser/ui/browser_tabstrip.h" |
20 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
21 #include "chrome/common/chrome_paths.h" | 21 #include "chrome/common/chrome_paths.h" |
22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
23 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
24 #include "chrome/test/base/in_process_browser_test.h" | 24 #include "chrome/test/base/in_process_browser_test.h" |
25 #include "chrome/test/base/ui_test_utils.h" | 25 #include "chrome/test/base/ui_test_utils.h" |
26 #include "content/public/browser/download_item.h" | 26 #include "content/public/browser/download_item.h" |
27 #include "content/public/common/page_transition_types.h" | 27 #include "content/public/common/page_transition_types.h" |
28 #include "content/public/test/browser_test_utils.h" | 28 #include "content/public/test/browser_test_utils.h" |
| 29 #include "content/public/test/download_test_observer.h" |
29 #include "content/test/net/url_request_slow_download_job.h" | 30 #include "content/test/net/url_request_slow_download_job.h" |
30 | 31 |
31 using content::BrowserContext; | 32 using content::BrowserContext; |
32 using content::BrowserThread; | 33 using content::BrowserThread; |
33 using content::DownloadItem; | 34 using content::DownloadItem; |
34 using content::DownloadManager; | 35 using content::DownloadManager; |
35 | 36 |
36 class BrowserCloseTest : public InProcessBrowserTest { | 37 class BrowserCloseTest : public InProcessBrowserTest { |
37 public: | 38 public: |
38 // Structure defining test cases for DownloadsCloseCheck. | 39 // Structure defining test cases for DownloadsCloseCheck. |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 void CreateStalledDownloads(Browser* browser, int num_downloads) { | 111 void CreateStalledDownloads(Browser* browser, int num_downloads) { |
111 GURL url(URLRequestSlowDownloadJob::kKnownSizeUrl); | 112 GURL url(URLRequestSlowDownloadJob::kKnownSizeUrl); |
112 | 113 |
113 if (num_downloads == 0) | 114 if (num_downloads == 0) |
114 return; | 115 return; |
115 | 116 |
116 // Setup an observer waiting for the given number of downloads | 117 // Setup an observer waiting for the given number of downloads |
117 // to get to IN_PROGRESS. | 118 // to get to IN_PROGRESS. |
118 DownloadManager* download_manager = | 119 DownloadManager* download_manager = |
119 BrowserContext::GetDownloadManager(browser->profile()); | 120 BrowserContext::GetDownloadManager(browser->profile()); |
120 scoped_ptr<DownloadTestObserver> observer( | 121 scoped_ptr<content::DownloadTestObserver> observer( |
121 new DownloadTestObserverInProgress(download_manager, | 122 new content::DownloadTestObserverInProgress(download_manager, |
122 num_downloads)); | 123 num_downloads)); |
123 | 124 |
124 // Set of that number of downloads. | 125 // Set of that number of downloads. |
125 size_t count_downloads = num_downloads; | 126 size_t count_downloads = num_downloads; |
126 while (num_downloads--) | 127 while (num_downloads--) |
127 ui_test_utils::NavigateToURLWithDisposition( | 128 ui_test_utils::NavigateToURLWithDisposition( |
128 browser, url, NEW_BACKGROUND_TAB, | 129 browser, url, NEW_BACKGROUND_TAB, |
129 ui_test_utils::BROWSER_TEST_NONE); | 130 ui_test_utils::BROWSER_TEST_NONE); |
130 | 131 |
131 // Wait for them. | 132 // Wait for them. |
132 observer->WaitForFinished(); | 133 observer->WaitForFinished(); |
(...skipping 10 matching lines...) Expand all Loading... |
143 // Go through and, for every single profile, wait until there are | 144 // Go through and, for every single profile, wait until there are |
144 // no active downloads on that download manager. | 145 // no active downloads on that download manager. |
145 std::vector<Profile*> profiles( | 146 std::vector<Profile*> profiles( |
146 g_browser_process->profile_manager()->GetLoadedProfiles()); | 147 g_browser_process->profile_manager()->GetLoadedProfiles()); |
147 for (std::vector<Profile*>::const_iterator pit = profiles.begin(); | 148 for (std::vector<Profile*>::const_iterator pit = profiles.begin(); |
148 pit != profiles.end(); ++pit) { | 149 pit != profiles.end(); ++pit) { |
149 DownloadService* download_service = | 150 DownloadService* download_service = |
150 DownloadServiceFactory::GetForProfile(*pit); | 151 DownloadServiceFactory::GetForProfile(*pit); |
151 if (download_service->HasCreatedDownloadManager()) { | 152 if (download_service->HasCreatedDownloadManager()) { |
152 DownloadManager *mgr = BrowserContext::GetDownloadManager(*pit); | 153 DownloadManager *mgr = BrowserContext::GetDownloadManager(*pit); |
153 scoped_refptr<DownloadTestFlushObserver> observer( | 154 scoped_refptr<content::DownloadTestFlushObserver> observer( |
154 new DownloadTestFlushObserver(mgr)); | 155 new content::DownloadTestFlushObserver(mgr)); |
155 observer->WaitForFlush(); | 156 observer->WaitForFlush(); |
156 } | 157 } |
157 if ((*pit)->HasOffTheRecordProfile()) { | 158 if ((*pit)->HasOffTheRecordProfile()) { |
158 DownloadService* incognito_download_service = | 159 DownloadService* incognito_download_service = |
159 DownloadServiceFactory::GetForProfile( | 160 DownloadServiceFactory::GetForProfile( |
160 (*pit)->GetOffTheRecordProfile()); | 161 (*pit)->GetOffTheRecordProfile()); |
161 if (incognito_download_service->HasCreatedDownloadManager()) { | 162 if (incognito_download_service->HasCreatedDownloadManager()) { |
162 DownloadManager *mgr = BrowserContext::GetDownloadManager( | 163 DownloadManager *mgr = BrowserContext::GetDownloadManager( |
163 (*pit)->GetOffTheRecordProfile()); | 164 (*pit)->GetOffTheRecordProfile()); |
164 scoped_refptr<DownloadTestFlushObserver> observer( | 165 scoped_refptr<content::DownloadTestFlushObserver> observer( |
165 new DownloadTestFlushObserver(mgr)); | 166 new content::DownloadTestFlushObserver(mgr)); |
166 observer->WaitForFlush(); | 167 observer->WaitForFlush(); |
167 } | 168 } |
168 } | 169 } |
169 } | 170 } |
170 } | 171 } |
171 | 172 |
172 // Create a Browser (with associated window) on the specified profile. | 173 // Create a Browser (with associated window) on the specified profile. |
173 Browser* CreateBrowserOnProfile(Profile* profile) { | 174 Browser* CreateBrowserOnProfile(Profile* profile) { |
174 Browser* new_browser = new Browser(Browser::CreateParams(profile)); | 175 Browser* new_browser = new Browser(Browser::CreateParams(profile)); |
175 chrome::AddSelectedTabWithURL(new_browser, GURL(chrome::kAboutBlankURL), | 176 chrome::AddSelectedTabWithURL(new_browser, GURL(chrome::kAboutBlankURL), |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 } | 575 } |
575 } | 576 } |
576 | 577 |
577 IN_PROC_BROWSER_TEST_F(BrowserCloseTest, MAYBE_DownloadsCloseCheck_5) { | 578 IN_PROC_BROWSER_TEST_F(BrowserCloseTest, MAYBE_DownloadsCloseCheck_5) { |
578 ASSERT_TRUE(SetupForDownloadCloseCheck()); | 579 ASSERT_TRUE(SetupForDownloadCloseCheck()); |
579 for (size_t i = 5 * arraysize(download_close_check_cases) / 6; | 580 for (size_t i = 5 * arraysize(download_close_check_cases) / 6; |
580 i < 6 * arraysize(download_close_check_cases) / 6; ++i) { | 581 i < 6 * arraysize(download_close_check_cases) / 6; ++i) { |
581 ExecuteDownloadCloseCheckCase(i); | 582 ExecuteDownloadCloseCheckCase(i); |
582 } | 583 } |
583 } | 584 } |
OLD | NEW |