| 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" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 | 111 |
| 112 if (num_downloads == 0) | 112 if (num_downloads == 0) |
| 113 return; | 113 return; |
| 114 | 114 |
| 115 // Setup an observer waiting for the given number of downloads | 115 // Setup an observer waiting for the given number of downloads |
| 116 // to get to IN_PROGRESS. | 116 // to get to IN_PROGRESS. |
| 117 DownloadManager* download_manager = | 117 DownloadManager* download_manager = |
| 118 BrowserContext::GetDownloadManager(browser->profile()); | 118 BrowserContext::GetDownloadManager(browser->profile()); |
| 119 scoped_ptr<DownloadTestObserver> observer( | 119 scoped_ptr<DownloadTestObserver> observer( |
| 120 new DownloadTestObserverInProgress(download_manager, | 120 new DownloadTestObserverInProgress(download_manager, |
| 121 num_downloads, | 121 num_downloads)); |
| 122 true)); // Bail on select file. | |
| 123 | 122 |
| 124 // Set of that number of downloads. | 123 // Set of that number of downloads. |
| 125 size_t count_downloads = num_downloads; | 124 size_t count_downloads = num_downloads; |
| 126 while (num_downloads--) | 125 while (num_downloads--) |
| 127 ui_test_utils::NavigateToURLWithDisposition( | 126 ui_test_utils::NavigateToURLWithDisposition( |
| 128 browser, url, NEW_BACKGROUND_TAB, | 127 browser, url, NEW_BACKGROUND_TAB, |
| 129 ui_test_utils::BROWSER_TEST_NONE); | 128 ui_test_utils::BROWSER_TEST_NONE); |
| 130 | 129 |
| 131 // Wait for them. | 130 // Wait for them. |
| 132 observer->WaitForFinished(); | 131 observer->WaitForFinished(); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 EXPECT_TRUE(result); | 231 EXPECT_TRUE(result); |
| 233 if (!result) return false; | 232 if (!result) return false; |
| 234 first_profile_->GetPrefs()->SetFilePath( | 233 first_profile_->GetPrefs()->SetFilePath( |
| 235 prefs::kDownloadDefaultDirectory, | 234 prefs::kDownloadDefaultDirectory, |
| 236 first_profile_downloads_dir_.path()); | 235 first_profile_downloads_dir_.path()); |
| 237 | 236 |
| 238 second_profile_ = CreateSecondProfile(); | 237 second_profile_ = CreateSecondProfile(); |
| 239 EXPECT_TRUE(second_profile_); | 238 EXPECT_TRUE(second_profile_); |
| 240 if (!second_profile_) return false; | 239 if (!second_profile_) return false; |
| 241 | 240 |
| 241 DownloadTestFileChooserObserver(first_profile_) .EnableFileChooser(false); |
| 242 DownloadTestFileChooserObserver(second_profile_).EnableFileChooser(false); |
| 242 return true; | 243 return true; |
| 243 } | 244 } |
| 244 | 245 |
| 245 // Test a specific DownloadsCloseCheckCase. Returns false if | 246 // Test a specific DownloadsCloseCheckCase. Returns false if |
| 246 // an assertion has failed and the test should be aborted. | 247 // an assertion has failed and the test should be aborted. |
| 247 bool ExecuteDownloadCloseCheckCase(size_t i) { | 248 bool ExecuteDownloadCloseCheckCase(size_t i) { |
| 248 const DownloadsCloseCheckCase& check_case(download_close_check_cases[i]); | 249 const DownloadsCloseCheckCase& check_case(download_close_check_cases[i]); |
| 249 | 250 |
| 250 // Test invariant: so that we don't actually try and close the browser, | 251 // Test invariant: so that we don't actually try and close the browser, |
| 251 // we always enter the function with a single browser window open on the | 252 // we always enter the function with a single browser window open on the |
| (...skipping 17 matching lines...) Expand all Loading... |
| 269 int total_download_count = DownloadService::DownloadCountAllProfiles(); | 270 int total_download_count = DownloadService::DownloadCountAllProfiles(); |
| 270 EXPECT_EQ(0, total_download_count) | 271 EXPECT_EQ(0, total_download_count) |
| 271 << "Case " << i | 272 << "Case " << i |
| 272 << ": " << check_case.DebugString(); | 273 << ": " << check_case.DebugString(); |
| 273 if (0 != total_download_count) | 274 if (0 != total_download_count) |
| 274 return false; | 275 return false; |
| 275 | 276 |
| 276 Profile* first_profile_incognito = first_profile_->GetOffTheRecordProfile(); | 277 Profile* first_profile_incognito = first_profile_->GetOffTheRecordProfile(); |
| 277 Profile* second_profile_incognito = | 278 Profile* second_profile_incognito = |
| 278 second_profile_->GetOffTheRecordProfile(); | 279 second_profile_->GetOffTheRecordProfile(); |
| 280 DownloadTestFileChooserObserver(first_profile_incognito) |
| 281 .EnableFileChooser(false); |
| 282 DownloadTestFileChooserObserver(second_profile_incognito) |
| 283 .EnableFileChooser(false); |
| 279 | 284 |
| 280 // For simplicty of coding, we create a window on each profile so that | 285 // For simplicty of coding, we create a window on each profile so that |
| 281 // we can easily create downloads, then we destroy or create windows | 286 // we can easily create downloads, then we destroy or create windows |
| 282 // as necessary. | 287 // as necessary. |
| 283 Browser* browser_a_regular(CreateBrowserOnProfile(first_profile_)); | 288 Browser* browser_a_regular(CreateBrowserOnProfile(first_profile_)); |
| 284 Browser* browser_a_incognito( | 289 Browser* browser_a_incognito( |
| 285 CreateBrowserOnProfile(first_profile_incognito)); | 290 CreateBrowserOnProfile(first_profile_incognito)); |
| 286 Browser* browser_b_regular(CreateBrowserOnProfile(second_profile_)); | 291 Browser* browser_b_regular(CreateBrowserOnProfile(second_profile_)); |
| 287 Browser* browser_b_incognito( | 292 Browser* browser_b_incognito( |
| 288 CreateBrowserOnProfile(second_profile_incognito)); | 293 CreateBrowserOnProfile(second_profile_incognito)); |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 } | 574 } |
| 570 } | 575 } |
| 571 | 576 |
| 572 IN_PROC_BROWSER_TEST_F(BrowserCloseTest, MAYBE_DownloadsCloseCheck_5) { | 577 IN_PROC_BROWSER_TEST_F(BrowserCloseTest, MAYBE_DownloadsCloseCheck_5) { |
| 573 ASSERT_TRUE(SetupForDownloadCloseCheck()); | 578 ASSERT_TRUE(SetupForDownloadCloseCheck()); |
| 574 for (size_t i = 5 * arraysize(download_close_check_cases) / 6; | 579 for (size_t i = 5 * arraysize(download_close_check_cases) / 6; |
| 575 i < 6 * arraysize(download_close_check_cases) / 6; ++i) { | 580 i < 6 * arraysize(download_close_check_cases) / 6; ++i) { |
| 576 ExecuteDownloadCloseCheckCase(i); | 581 ExecuteDownloadCloseCheckCase(i); |
| 577 } | 582 } |
| 578 } | 583 } |
| OLD | NEW |