| OLD | NEW |
| 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 "base/file_path.h" | 5 #include "base/file_path.h" |
| 6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
| 8 #include "base/scoped_temp_dir.h" | 8 #include "base/scoped_temp_dir.h" |
| 9 #include "base/test/test_file_util.h" | 9 #include "base/test/test_file_util.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/browser_window.h" | 11 #include "chrome/browser/browser_window.h" |
| 12 #include "chrome/browser/download/download_item.h" | 12 #include "chrome/browser/download/download_item.h" |
| 13 #include "chrome/browser/download/download_manager.h" | 13 #include "chrome/browser/download/download_manager.h" |
| 14 #include "chrome/browser/download/download_prefs.h" | 14 #include "chrome/browser/download/download_prefs.h" |
| 15 #include "chrome/browser/download/download_shelf.h" |
| 15 #include "chrome/browser/net/url_request_mock_http_job.h" | 16 #include "chrome/browser/net/url_request_mock_http_job.h" |
| 17 #include "chrome/browser/net/url_request_slow_download_job.h" |
| 16 #include "chrome/browser/prefs/pref_service.h" | 18 #include "chrome/browser/prefs/pref_service.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/ui/browser.h" |
| 21 #include "chrome/browser/ui/browser_list.h" |
| 18 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 19 #include "chrome/common/chrome_paths.h" | 23 #include "chrome/common/chrome_paths.h" |
| 24 #include "chrome/common/page_transition_types.h" |
| 20 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
| 21 #include "chrome/test/in_process_browser_test.h" | 26 #include "chrome/test/in_process_browser_test.h" |
| 22 #include "chrome/test/ui_test_utils.h" | 27 #include "chrome/test/ui_test_utils.h" |
| 28 #include "net/base/net_util.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 30 |
| 25 namespace { | 31 namespace { |
| 26 | 32 |
| 27 // Variation of DownloadsCompleteObserver from ui_test_utils.cc; the | 33 // Variation of DownloadsCompleteObserver from ui_test_utils.cc; the |
| 28 // specifically targeted download tests need finer granularity on waiting. | 34 // specifically targeted download tests need finer granularity on waiting. |
| 29 // Construction of this class defines a system state, based on some number | 35 // Construction of this class defines a system state, based on some number |
| 30 // of downloads being seen in a particular state + other events that | 36 // of downloads being seen in a particular state + other events that |
| 31 // may occur in the download system. That state will be recorded if it | 37 // may occur in the download system. That state will be recorded if it |
| 32 // occurs at any point after construction. When that state occurs, the class | 38 // occurs at any point after construction. When that state occurs, the class |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 // the select file dialog comes up. | 212 // the select file dialog comes up. |
| 207 bool finish_on_select_file_; | 213 bool finish_on_select_file_; |
| 208 | 214 |
| 209 // True if we've seen the select file dialog. | 215 // True if we've seen the select file dialog. |
| 210 bool select_file_dialog_seen_; | 216 bool select_file_dialog_seen_; |
| 211 | 217 |
| 212 DISALLOW_COPY_AND_ASSIGN(DownloadsObserver); | 218 DISALLOW_COPY_AND_ASSIGN(DownloadsObserver); |
| 213 }; | 219 }; |
| 214 | 220 |
| 215 class DownloadTest : public InProcessBrowserTest { | 221 class DownloadTest : public InProcessBrowserTest { |
| 222 public: |
| 223 enum SelectExpectation { |
| 224 EXPECT_NO_SELECT_DIALOG = -1, |
| 225 EXPECT_NOTHING, |
| 226 EXPECT_SELECT_DIALOG |
| 227 }; |
| 228 |
| 229 // Returning false indicates a failure of the setup, and should be asserted |
| 230 // in the caller. |
| 231 virtual bool InitialSetup(bool prompt_for_download) { |
| 232 bool have_test_dir = PathService::Get(chrome::DIR_TEST_DATA, &test_dir_); |
| 233 EXPECT_TRUE(have_test_dir); |
| 234 if (!have_test_dir) |
| 235 return false; |
| 236 |
| 237 // Sanity check default values for window / tab count and shelf visibility. |
| 238 int window_count = BrowserList::size(); |
| 239 EXPECT_EQ(1, window_count); |
| 240 EXPECT_EQ(1, browser()->tab_count()); |
| 241 bool is_shelf_visible = browser()->window()->IsDownloadShelfVisible(); |
| 242 EXPECT_FALSE(is_shelf_visible); |
| 243 |
| 244 // Set up the temporary download folder. |
| 245 bool created_downloads_dir = CreateAndSetDownloadsDirectory(browser()); |
| 246 EXPECT_TRUE(created_downloads_dir); |
| 247 if (!created_downloads_dir) |
| 248 return false; |
| 249 browser()->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, |
| 250 prompt_for_download); |
| 251 |
| 252 return true; |
| 253 } |
| 254 |
| 216 protected: | 255 protected: |
| 217 void SetUpInProcessBrowserTestFixture() { | |
| 218 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir_)); | |
| 219 } | |
| 220 | 256 |
| 221 // Must be called after browser creation. Creates a temporary | 257 // Must be called after browser creation. Creates a temporary |
| 222 // directory for downloads that is auto-deleted on destruction. | 258 // directory for downloads that is auto-deleted on destruction. |
| 223 bool CreateAndSetDownloadsDirectory() { | 259 // Returning false indicates a failure of the function, and should be asserted |
| 224 if (downloads_directory_.CreateUniqueTempDir()) { | 260 // in the caller. |
| 225 browser()->profile()->GetPrefs()->SetFilePath( | 261 bool CreateAndSetDownloadsDirectory(Browser* browser) { |
| 226 prefs::kDownloadDefaultDirectory, | 262 if (!browser) |
| 227 downloads_directory_.path()); | 263 return false; |
| 228 return true; | 264 |
| 229 } | 265 if (!downloads_directory_.CreateUniqueTempDir()) |
| 230 return false; | 266 return false; |
| 267 |
| 268 browser->profile()->GetPrefs()->SetFilePath( |
| 269 prefs::kDownloadDefaultDirectory, |
| 270 downloads_directory_.path()); |
| 271 |
| 272 return true; |
| 231 } | 273 } |
| 232 | 274 |
| 233 // May only be called inside of an individual test; browser() is NULL | 275 FilePath GetDownloadDirectory(Browser* browser) { |
| 234 // outside of that context. | |
| 235 FilePath GetDownloadDirectory() { | |
| 236 DownloadManager* download_mananger = | 276 DownloadManager* download_mananger = |
| 237 browser()->profile()->GetDownloadManager(); | 277 browser->profile()->GetDownloadManager(); |
| 238 return download_mananger->download_prefs()->download_path(); | 278 return download_mananger->download_prefs()->download_path(); |
| 239 } | 279 } |
| 240 | 280 |
| 241 DownloadsObserver* CreateWaiter(int num_downloads) { | 281 DownloadsObserver* CreateWaiter(Browser* browser, int num_downloads) { |
| 242 DownloadManager* download_manager = | 282 DownloadManager* download_manager = |
| 243 browser()->profile()->GetDownloadManager(); | 283 browser->profile()->GetDownloadManager(); |
| 244 return new DownloadsObserver( | 284 return new DownloadsObserver( |
| 245 download_manager, num_downloads, | 285 download_manager, num_downloads, |
| 246 DownloadsObserver::FILE_RENAME, // Really done | 286 DownloadsObserver::FILE_RENAME, // Really done |
| 247 true); // Bail on select file | 287 true); // Bail on select file |
| 288 } |
| 289 |
| 290 // Download |url|, then wait for the download to finish. |
| 291 // |disposition| indicates where the navigation occurs (current tab, new |
| 292 // foreground tab, etc). |
| 293 // |expectation| indicates whether or not a Select File dialog should be |
| 294 // open when the download is finished, or if we don't care. |
| 295 // If the dialog appears, the test completes. The only effect |expectation| |
| 296 // has is whether or not the test succeeds. |
| 297 // |browser_test_flags| indicate what to wait for, and is an OR of 0 or more |
| 298 // values in the ui_test_utils::BrowserTestWaitFlags enum. |
| 299 void DownloadAndWaitWithDisposition(Browser* browser, |
| 300 const GURL& url, |
| 301 WindowOpenDisposition disposition, |
| 302 SelectExpectation expectation, |
| 303 int browser_test_flags) { |
| 304 // Setup notification, navigate, and block. |
| 305 scoped_ptr<DownloadsObserver> observer(CreateWaiter(browser, 1)); |
| 306 // This call will block until the condition specified by |
| 307 // |browser_test_flags|, but will not wait for the download to finish. |
| 308 ui_test_utils::NavigateToURLWithDisposition(browser, |
| 309 url, |
| 310 disposition, |
| 311 browser_test_flags); |
| 312 // Waits for the download to complete. |
| 313 observer->WaitForFinished(); |
| 314 |
| 315 // If specified, check the state of the select file dialog. |
| 316 if (expectation != EXPECT_NOTHING) { |
| 317 EXPECT_EQ(expectation == EXPECT_SELECT_DIALOG, |
| 318 observer->select_file_dialog_seen()); |
| 319 } |
| 320 } |
| 321 |
| 322 // Download a file in the current tab, then wait for the download to finish. |
| 323 void DownloadAndWait(Browser* browser, |
| 324 const GURL& url, |
| 325 SelectExpectation expectation) { |
| 326 DownloadAndWaitWithDisposition( |
| 327 browser, |
| 328 url, |
| 329 CURRENT_TAB, |
| 330 expectation, |
| 331 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 248 } | 332 } |
| 249 | 333 |
| 250 // Should only be called when the download is known to have finished | 334 // Should only be called when the download is known to have finished |
| 251 // (in error or not). | 335 // (in error or not). |
| 252 void CheckDownload(const FilePath& downloaded_filename, | 336 // Returning false indicates a failure of the function, and should be asserted |
| 337 // in the caller. |
| 338 bool CheckDownload(Browser* browser, |
| 339 const FilePath& downloaded_filename, |
| 253 const FilePath& origin_filename) { | 340 const FilePath& origin_filename) { |
| 254 // Find the path to which the data will be downloaded. | 341 // Find the path to which the data will be downloaded. |
| 255 FilePath downloaded_file = | 342 FilePath downloaded_file = |
| 256 GetDownloadDirectory().Append(downloaded_filename); | 343 GetDownloadDirectory(browser).Append(downloaded_filename); |
| 257 | 344 |
| 258 // Find the origin path (from which the data comes). | 345 // Find the origin path (from which the data comes). |
| 259 FilePath origin_file(test_dir_.Append(origin_filename)); | 346 FilePath origin_file(test_dir_.Append(origin_filename)); |
| 260 ASSERT_TRUE(file_util::PathExists(origin_file)); | 347 bool origin_file_exists = file_util::PathExists(origin_file); |
| 348 EXPECT_TRUE(origin_file_exists); |
| 349 if (!origin_file_exists) |
| 350 return false; |
| 261 | 351 |
| 262 // Confirm the downloaded data file exists. | 352 // Confirm the downloaded data file exists. |
| 263 ASSERT_TRUE(file_util::PathExists(downloaded_file)); | 353 bool downloaded_file_exists = file_util::PathExists(downloaded_file); |
| 354 EXPECT_TRUE(downloaded_file_exists); |
| 355 if (!downloaded_file_exists) |
| 356 return false; |
| 357 |
| 264 int64 origin_file_size = 0; | 358 int64 origin_file_size = 0; |
| 265 int64 downloaded_file_size = 0; | 359 int64 downloaded_file_size = 0; |
| 266 EXPECT_TRUE(file_util::GetFileSize(origin_file, &origin_file_size)); | 360 EXPECT_TRUE(file_util::GetFileSize(origin_file, &origin_file_size)); |
| 267 EXPECT_TRUE(file_util::GetFileSize(downloaded_file, &downloaded_file_size)); | 361 EXPECT_TRUE(file_util::GetFileSize(downloaded_file, &downloaded_file_size)); |
| 268 EXPECT_EQ(origin_file_size, downloaded_file_size); | 362 EXPECT_EQ(origin_file_size, downloaded_file_size); |
| 269 EXPECT_TRUE(file_util::ContentsEqual(downloaded_file, origin_file)); | 363 EXPECT_TRUE(file_util::ContentsEqual(downloaded_file, origin_file)); |
| 270 | 364 |
| 271 #if defined(OS_WIN) | 365 #if defined(OS_WIN) |
| 272 // Check if the Zone Identifier is correctly set. | 366 // Check if the Zone Identifier is correctly set. |
| 273 if (file_util::VolumeSupportsADS(downloaded_file)) | 367 if (file_util::VolumeSupportsADS(downloaded_file)) |
| 274 EXPECT_TRUE(file_util::HasInternetZoneIdentifier(downloaded_file)); | 368 EXPECT_TRUE(file_util::HasInternetZoneIdentifier(downloaded_file)); |
| 275 #endif | 369 #endif |
| 276 | 370 |
| 277 // Delete the downloaded copy of the file. | 371 // Delete the downloaded copy of the file. |
| 278 EXPECT_TRUE(file_util::DieFileDie(downloaded_file, false)); | 372 bool downloaded_file_deleted = |
| 373 file_util::DieFileDie(downloaded_file, false); |
| 374 EXPECT_TRUE(downloaded_file_deleted); |
| 375 return downloaded_file_deleted; |
| 376 } |
| 377 |
| 378 // TODO(ahendrickson) -- |expected_title_in_progress| and |
| 379 // |expected_title_in_finished| need to be checked. |
| 380 bool RunSizeTest(Browser* browser, |
| 381 const GURL& url, |
| 382 const std::wstring& expected_title_in_progress, |
| 383 const std::wstring& expected_title_finished) { |
| 384 if (!InitialSetup(false)) |
| 385 return false; |
| 386 |
| 387 // Download a partial web page in a background tab and wait. |
| 388 // The mock system will not complete until it gets a special URL. |
| 389 scoped_ptr<DownloadsObserver> observer(CreateWaiter(browser, 1)); |
| 390 ui_test_utils::NavigateToURL(browser, url); |
| 391 |
| 392 // TODO(ahendrickson): check download status text before downloading. |
| 393 // Need to: |
| 394 // - Add a member function to the |DownloadShelf| interface class, that |
| 395 // indicates how many members it has. |
| 396 // - Add a member function to |DownloadShelf| to get the status text |
| 397 // of a given member (for example, via |DownloadItemView|'s |
| 398 // GetAccessibleName() member function), by index. |
| 399 // - Iterate over browser->window()->GetDownloadShelf()'s members |
| 400 // to see if any match the status text we want. Start with the last one. |
| 401 |
| 402 // Complete sending the request. We do this by loading a second URL in a |
| 403 // separate tab. |
| 404 GURL finish_url(URLRequestSlowDownloadJob::kFinishDownloadUrl); |
| 405 ui_test_utils::NavigateToURLWithDisposition( |
| 406 browser, |
| 407 finish_url, |
| 408 NEW_FOREGROUND_TAB, |
| 409 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 410 observer->WaitForFinished(); |
| 411 |
| 412 EXPECT_EQ(2, browser->tab_count()); |
| 413 |
| 414 // TODO(ahendrickson): check download status text after downloading. |
| 415 |
| 416 // Make sure the download shelf is showing. |
| 417 EXPECT_TRUE(browser->window()->IsDownloadShelfVisible()); |
| 418 |
| 419 FilePath filename; |
| 420 net::FileURLToFilePath(url, &filename); |
| 421 filename = filename.BaseName(); |
| 422 FilePath download_path = downloads_directory_.path().Append(filename); |
| 423 |
| 424 bool downloaded_path_exists = file_util::PathExists(download_path); |
| 425 EXPECT_TRUE(downloaded_path_exists); |
| 426 if (!downloaded_path_exists) |
| 427 return false; |
| 428 |
| 429 // Delete the file we just downloaded. |
| 430 EXPECT_TRUE(file_util::DieFileDie(download_path, true)); |
| 431 EXPECT_FALSE(file_util::PathExists(download_path)); |
| 432 |
| 433 return true; |
| 279 } | 434 } |
| 280 | 435 |
| 281 private: | 436 private: |
| 282 // Location of the test data. | 437 // Location of the test data. |
| 283 FilePath test_dir_; | 438 FilePath test_dir_; |
| 284 | 439 |
| 285 // Location of the downloads directory for these tests | 440 // Location of the downloads directory for these tests |
| 286 ScopedTempDir downloads_directory_; | 441 ScopedTempDir downloads_directory_; |
| 287 }; | 442 }; |
| 288 | 443 |
| 444 // NOTES: |
| 445 // |
| 446 // Files for these tests are found in DIR_TEST_DATA (currently |
| 447 // "chrome\test\data\", see chrome_paths.cc). |
| 448 // Mock responses have extension .mock-http-headers appended to the file name. |
| 449 |
| 450 // Download a file due to the associated MIME type. |
| 451 // |
| 289 // Test is believed good (non-flaky) in itself, but it | 452 // Test is believed good (non-flaky) in itself, but it |
| 290 // sometimes trips over underlying flakiness in the downloads | 453 // sometimes trips over underlying flakiness in the downloads |
| 291 // subsystem in in http://crbug.com/63237. Until that bug is | 454 // subsystem in in http://crbug.com/63237. Until that bug is |
| 292 // fixed, this test should be considered flaky. It's entered as | 455 // fixed, this test should be considered flaky. It's entered as |
| 293 // DISABLED since if 63237 does cause a failure, it'll be a timeout. | 456 // DISABLED since if 63237 does cause a failure, it'll be a timeout. |
| 294 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_DownloadMimeType) { | 457 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_DownloadMimeType) { |
| 295 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 458 ASSERT_TRUE(InitialSetup(false)); |
| 296 ASSERT_TRUE(CreateAndSetDownloadsDirectory()); | 459 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 297 | 460 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 298 EXPECT_EQ(1, browser()->tab_count()); | 461 |
| 299 | 462 // Download the file and wait. We do not expect the Select File dialog. |
| 300 // Setup notification, navigate, and block. | 463 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); |
| 301 scoped_ptr<DownloadsObserver> observer(CreateWaiter(1)); | 464 |
| 302 ui_test_utils::NavigateToURL( | 465 // Check state. |
| 303 browser(), URLRequestMockHTTPJob::GetMockUrl(file)); | 466 EXPECT_EQ(1, browser()->tab_count()); |
| 304 observer->WaitForFinished(); | 467 CheckDownload(browser(), file, file); |
| 305 | 468 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 306 // Download should be finished; check state. | 469 } |
| 307 EXPECT_FALSE(observer->select_file_dialog_seen()); | 470 |
| 308 EXPECT_EQ(1, browser()->tab_count()); | 471 // Put up a Select File dialog when the file is downloaded, due to its MIME |
| 309 CheckDownload(file, file); | 472 // type. |
| 310 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 473 // |
| 311 } | |
| 312 | |
| 313 // This test runs correctly, but leaves behind turds in the test user's | 474 // This test runs correctly, but leaves behind turds in the test user's |
| 314 // download directory because of http://crbug.com/62099. No big loss; it | 475 // download directory because of http://crbug.com/62099. No big loss; it |
| 315 // was primarily confirming DownloadsObserver wait on select file dialog | 476 // was primarily confirming DownloadsObserver wait on select file dialog |
| 316 // functionality anyway. | 477 // functionality anyway. |
| 478 // Additionally, there is Windows-specific flake, http://crbug.com/20809. |
| 317 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_DownloadMimeTypeSelect) { | 479 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_DownloadMimeTypeSelect) { |
| 318 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 480 ASSERT_TRUE(InitialSetup(true)); |
| 319 ASSERT_TRUE(CreateAndSetDownloadsDirectory()); | 481 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 320 browser()->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, true); | 482 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 321 | 483 |
| 322 EXPECT_EQ(1, browser()->tab_count()); | 484 // Download the file and wait. We expect the Select File dialog to appear |
| 323 | 485 // due to the MIME type. |
| 324 // Setup notification, navigate, and block. | 486 DownloadAndWait(browser(), url, EXPECT_SELECT_DIALOG); |
| 325 scoped_ptr<DownloadsObserver> observer(CreateWaiter(1)); | 487 |
| 326 ui_test_utils::NavigateToURL( | 488 // Check state. |
| 327 browser(), URLRequestMockHTTPJob::GetMockUrl(file)); | 489 EXPECT_EQ(1, browser()->tab_count()); |
| 328 observer->WaitForFinished(); | 490 // Since we exited while the Select File dialog was visible, there should not |
| 329 | 491 // be anything in the download shelf and so it should not be visible. |
| 330 // Download should not be finished; check state. | 492 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 331 EXPECT_TRUE(observer->select_file_dialog_seen()); | 493 } |
| 332 EXPECT_EQ(1, browser()->tab_count()); | 494 |
| 333 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 495 // Access a file with a viewable mime-type, verify that a download |
| 496 // did not initiate. |
| 497 IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) { |
| 498 ASSERT_TRUE(InitialSetup(false)); |
| 499 FilePath file(FILE_PATH_LITERAL("download-test2.html")); |
| 500 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 501 FilePath file_path = GetDownloadDirectory(browser()).Append(file); |
| 502 |
| 503 // Open a web page and wait. |
| 504 ui_test_utils::NavigateToURL(browser(), url); |
| 505 |
| 506 // Check that we did not download the web page. |
| 507 EXPECT_FALSE(file_util::PathExists(file_path)); |
| 508 |
| 509 // Check state. |
| 510 EXPECT_EQ(1, browser()->tab_count()); |
| 511 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 512 } |
| 513 |
| 514 // Download a 0-size file with a content-disposition header, verify that the |
| 515 // download tab opened and the file exists as the filename specified in the |
| 516 // header. This also ensures we properly handle empty file downloads. |
| 517 // The download shelf should be visible in the current tab. |
| 518 // |
| 519 // Test is believed mostly good (non-flaky) in itself, but it |
| 520 // sometimes trips over underlying flakiness in the downloads |
| 521 // subsystem in in http://crbug.com/63237. Until that bug is |
| 522 // fixed, this test should be considered flaky. It's entered as |
| 523 // DISABLED since if 63237 does cause a failure, it'll be a timeout. |
| 524 // Additionally, there is Windows-specific flake, http://crbug.com/20809. |
| 525 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_ContentDisposition) { |
| 526 ASSERT_TRUE(InitialSetup(false)); |
| 527 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); |
| 528 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 529 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); |
| 530 |
| 531 // Download a file and wait. |
| 532 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); |
| 533 |
| 534 CheckDownload(browser(), download_file, file); |
| 535 |
| 536 // Check state. |
| 537 EXPECT_EQ(1, browser()->tab_count()); |
| 538 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 539 } |
| 540 |
| 541 // Test that the download shelf is per-window by starting a download in one |
| 542 // tab, opening a second tab, closing the shelf, going back to the first tab, |
| 543 // and checking that the shelf is closed. |
| 544 // |
| 545 // The test sometimes trips over underlying flakiness in the downloads |
| 546 // subsystem in in http://crbug.com/63237. It's entered as |
| 547 // DISABLED since if 63237 does cause a failure, it'll be a timeout. |
| 548 // Additionally, there is Windows-specific flake, http://crbug.com/20809. |
| 549 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_PerWindowShelf) { |
| 550 ASSERT_TRUE(InitialSetup(false)); |
| 551 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); |
| 552 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 553 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); |
| 554 |
| 555 // Download a file and wait. |
| 556 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); |
| 557 |
| 558 CheckDownload(browser(), download_file, file); |
| 559 |
| 560 // Check state. |
| 561 EXPECT_EQ(1, browser()->tab_count()); |
| 562 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 563 |
| 564 // Open a second tab and wait. |
| 565 EXPECT_NE(static_cast<TabContentsWrapper*>(NULL), |
| 566 browser()->AddSelectedTabWithURL(GURL(), PageTransition::TYPED)); |
| 567 EXPECT_EQ(2, browser()->tab_count()); |
| 568 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 569 |
| 570 // Hide the download shelf. |
| 571 browser()->window()->GetDownloadShelf()->Close(); |
| 572 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 573 |
| 574 // Go to the first tab. |
| 575 browser()->SelectTabContentsAt(0, true); |
| 576 EXPECT_EQ(2, browser()->tab_count()); |
| 577 |
| 578 // The download shelf should not be visible. |
| 579 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 580 } |
| 581 |
| 582 // UnknownSize and KnownSize are tests which depend on |
| 583 // URLRequestSlowDownloadJob to serve content in a certain way. Data will be |
| 584 // sent in two chunks where the first chunk is 35K and the second chunk is 10K. |
| 585 // The test will first attempt to download a file; but the server will "pause" |
| 586 // in the middle until the server receives a second request for |
| 587 // "download-finish". At that time, the download will finish. |
| 588 // These tests don't currently test much due to holes in |RunSizeTest()|. See |
| 589 // comments in that routine for details. |
| 590 |
| 591 // Test is believed mostly good (non-flaky) in itself, but it |
| 592 // very occasionally trips over underlying flakiness in the downloads |
| 593 // subsystem in in http://crbug.com/63237. Until that bug is |
| 594 // fixed, this test should be considered flaky. It's entered as |
| 595 // DISABLED since if 63237 does cause a failure, it'll be a timeout. |
| 596 // Additionally, there is Windows-specific flake, http://crbug.com/20809. |
| 597 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_UnknownSize) { |
| 598 GURL url(URLRequestSlowDownloadJob::kUnknownSizeUrl); |
| 599 FilePath filename; |
| 600 net::FileURLToFilePath(url, &filename); |
| 601 filename = filename.BaseName(); |
| 602 ASSERT_TRUE(RunSizeTest(browser(), |
| 603 url, |
| 604 L"32.0 KB - " + filename.ToWStringHack(), |
| 605 L"100% - " + filename.ToWStringHack())); |
| 606 } |
| 607 |
| 608 // Test is believed mostly good (non-flaky) in itself, but it |
| 609 // very occasionally trips over underlying flakiness in the downloads |
| 610 // subsystem in in http://crbug.com/63237. Until that bug is |
| 611 // fixed, this test should be considered flaky. It's entered as |
| 612 // DISABLED since if 63237 does cause a failure, it'll be a timeout. |
| 613 // Additionally, there is Windows-specific flake, http://crbug.com/20809. |
| 614 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_KnownSize) { |
| 615 GURL url(URLRequestSlowDownloadJob::kKnownSizeUrl); |
| 616 FilePath filename; |
| 617 net::FileURLToFilePath(url, &filename); |
| 618 filename = filename.BaseName(); |
| 619 ASSERT_TRUE(RunSizeTest(browser(), |
| 620 url, |
| 621 L"71% - " + filename.ToWStringHack(), |
| 622 L"100% - " + filename.ToWStringHack())); |
| 623 } |
| 624 |
| 625 // Test that when downloading an item in Incognito mode, we don't crash when |
| 626 // closing the last Incognito window (http://crbug.com/13983). |
| 627 // Also check that the download shelf is not visible after closing the |
| 628 // Incognito window. |
| 629 // |
| 630 // Test is believed mostly good (non-flaky) in itself, but it |
| 631 // sometimes trips over underlying flakiness in the downloads |
| 632 // subsystem in in http://crbug.com/63237. Until that bug is |
| 633 // fixed, this test should be considered flaky. It's entered as |
| 634 // DISABLED since if 63237 does cause a failure, it'll be a timeout. |
| 635 // Additionally, there is Windows-specific flake, http://crbug.com/20809. |
| 636 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_IncognitoDownload) { |
| 637 ASSERT_TRUE(InitialSetup(false)); |
| 638 |
| 639 // Open an Incognito window. |
| 640 Browser* incognito = CreateIncognitoBrowser(); // Waits. |
| 641 ASSERT_TRUE(incognito); |
| 642 int window_count = BrowserList::size(); |
| 643 EXPECT_EQ(2, window_count); |
| 644 |
| 645 // Download a file in the Incognito window and wait. |
| 646 CreateAndSetDownloadsDirectory(incognito); |
| 647 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 648 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 649 // Since |incognito| is a separate browser, we have to set it up explicitly. |
| 650 incognito->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, |
| 651 false); |
| 652 DownloadAndWait(incognito, url, EXPECT_NO_SELECT_DIALOG); |
| 653 |
| 654 // We should still have 2 windows. |
| 655 window_count = BrowserList::size(); |
| 656 EXPECT_EQ(2, window_count); |
| 657 |
| 658 // Verify that the download shelf is showing for the Incognito window. |
| 659 bool is_shelf_visible = incognito->window()->IsDownloadShelfVisible(); |
| 660 EXPECT_TRUE(is_shelf_visible); |
| 661 |
| 662 // Close the Incognito window and don't crash. |
| 663 incognito->CloseWindow(); |
| 664 ui_test_utils::WaitForNotificationFrom(NotificationType::BROWSER_CLOSED, |
| 665 Source<Browser>(incognito)); |
| 666 |
| 667 window_count = BrowserList::size(); |
| 668 EXPECT_EQ(1, window_count); |
| 669 |
| 670 // Verify that the regular window does not have a download shelf. |
| 671 is_shelf_visible = browser()->window()->IsDownloadShelfVisible(); |
| 672 EXPECT_FALSE(is_shelf_visible); |
| 673 |
| 674 CheckDownload(browser(), file, file); |
| 675 } |
| 676 |
| 677 // Navigate to a new background page, but don't download. Confirm that the |
| 678 // download shelf is not visible and that we have two tabs. |
| 679 IN_PROC_BROWSER_TEST_F(DownloadTest, DontCloseNewTab1) { |
| 680 ASSERT_TRUE(InitialSetup(false)); |
| 681 // Because it's an HTML link, it should open a web page rather than |
| 682 // downloading. |
| 683 FilePath file1(FILE_PATH_LITERAL("download-test2.html")); |
| 684 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1)); |
| 685 |
| 686 // Open a web page and wait. |
| 687 ui_test_utils::NavigateToURLWithDisposition( |
| 688 browser(), |
| 689 url, |
| 690 NEW_BACKGROUND_TAB, |
| 691 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 692 |
| 693 // We should have two tabs now. |
| 694 EXPECT_EQ(2, browser()->tab_count()); |
| 695 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 696 } |
| 697 |
| 698 // Download a file in a background tab. Verify that the tab is closed |
| 699 // automatically, and that the download shelf is visible in the current tab. |
| 700 // |
| 701 // The test sometimes trips over underlying flakiness in the downloads |
| 702 // subsystem in http://crbug.com/63237. It's entered as |
| 703 // DISABLED since if 63237 does cause a failure, it'll be a timeout. |
| 704 // Additionally, there is Windows-specific flake, http://crbug.com/20809. |
| 705 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_CloseNewTab1) { |
| 706 ASSERT_TRUE(InitialSetup(false)); |
| 707 |
| 708 // Download a file in a new background tab and wait. The tab is automatically |
| 709 // closed when the download begins. |
| 710 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 711 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 712 DownloadAndWaitWithDisposition( |
| 713 browser(), |
| 714 url, |
| 715 NEW_BACKGROUND_TAB, |
| 716 EXPECT_NO_SELECT_DIALOG, |
| 717 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 718 |
| 719 // When the download finishes, we should still have one tab. |
| 720 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 721 EXPECT_EQ(1, browser()->tab_count()); |
| 722 |
| 723 CheckDownload(browser(), file, file); |
| 724 } |
| 725 |
| 726 // Open a web page in the current tab, then download a file in another tab via |
| 727 // a Javascript call. |
| 728 // Verify that we have 2 tabs, and the download shelf is visible in the current |
| 729 // tab. |
| 730 // |
| 731 // The download_page1.html page contains an openNew() function that opens a |
| 732 // tab and then downloads download-test1.lib. |
| 733 // |
| 734 // The test sometimes trips over underlying flakiness in the downloads |
| 735 // subsystem in in http://crbug.com/63237. It's entered as |
| 736 // DISABLED since if 63237 does cause a failure, it'll be a timeout. |
| 737 // Additionally, there is Windows-specific flake, http://crbug.com/20809. |
| 738 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_DontCloseNewTab2) { |
| 739 ASSERT_TRUE(InitialSetup(false)); |
| 740 // Because it's an HTML link, it should open a web page rather than |
| 741 // downloading. |
| 742 FilePath file1(FILE_PATH_LITERAL("download_page1.html")); |
| 743 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1)); |
| 744 |
| 745 // Open a web page and wait. |
| 746 ui_test_utils::NavigateToURL(browser(), url); |
| 747 |
| 748 // Download a file in a new tab and wait (via Javascript). |
| 749 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 750 DownloadAndWaitWithDisposition(browser(), |
| 751 GURL("javascript:openNew()"), |
| 752 CURRENT_TAB, |
| 753 EXPECT_NO_SELECT_DIALOG, |
| 754 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| 755 |
| 756 // When the download finishes, we should have two tabs. |
| 757 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 758 EXPECT_EQ(2, browser()->tab_count()); |
| 759 |
| 760 CheckDownload(browser(), file, file); |
| 761 } |
| 762 |
| 763 // Open a web page in the current tab, open another tab via a Javascript call, |
| 764 // then download a file in the new tab. |
| 765 // Verify that we have 2 tabs, and the download shelf is visible in the current |
| 766 // tab. |
| 767 // |
| 768 // The download_page2.html page contains an openNew() function that opens a |
| 769 // tab. |
| 770 // |
| 771 // The test sometimes trips over underlying flakiness in the downloads |
| 772 // subsystem in in http://crbug.com/63237. It's entered as |
| 773 // DISABLED since if 63237 does cause a failure, it'll be a timeout. |
| 774 // Additionally, there is Windows-specific flake, http://crbug.com/20809. |
| 775 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_DontCloseNewTab3) { |
| 776 ASSERT_TRUE(InitialSetup(false)); |
| 777 // Because it's an HTML link, it should open a web page rather than |
| 778 // downloading. |
| 779 FilePath file1(FILE_PATH_LITERAL("download_page2.html")); |
| 780 GURL url1(URLRequestMockHTTPJob::GetMockUrl(file1)); |
| 781 |
| 782 // Open a web page and wait. |
| 783 ui_test_utils::NavigateToURL(browser(), url1); |
| 784 |
| 785 // Open a new tab and wait. |
| 786 ui_test_utils::NavigateToURLWithDisposition( |
| 787 browser(), |
| 788 GURL("javascript:openNew()"), |
| 789 CURRENT_TAB, |
| 790 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| 791 |
| 792 EXPECT_EQ(2, browser()->tab_count()); |
| 793 |
| 794 // Download a file and wait. |
| 795 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 796 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 797 DownloadAndWaitWithDisposition(browser(), |
| 798 url, |
| 799 CURRENT_TAB, |
| 800 EXPECT_NO_SELECT_DIALOG, |
| 801 ui_test_utils::BROWSER_TEST_NONE); |
| 802 |
| 803 // When the download finishes, we should have two tabs. |
| 804 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 805 EXPECT_EQ(2, browser()->tab_count()); |
| 806 |
| 807 CheckDownload(browser(), file, file); |
| 808 } |
| 809 |
| 810 // Open a web page in the current tab, then download a file via Javascript, |
| 811 // which will do so in a temporary tab. |
| 812 // Verify that we have 1 tab, and the download shelf is visible. |
| 813 // |
| 814 // The download_page3.html page contains an openNew() function that opens a |
| 815 // tab with download-test1.lib in the URL. When the URL is determined to be |
| 816 // a download, the tab is closed automatically. |
| 817 // |
| 818 // The test sometimes trips over underlying flakiness in the downloads |
| 819 // subsystem in in http://crbug.com/63237. It's entered as |
| 820 // DISABLED since if 63237 does cause a failure, it'll be a timeout. |
| 821 // Additionally, there is Windows-specific flake, http://crbug.com/20809. |
| 822 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_CloseNewTab2) { |
| 823 ASSERT_TRUE(InitialSetup(false)); |
| 824 // Because it's an HTML link, it should open a web page rather than |
| 825 // downloading. |
| 826 FilePath file1(FILE_PATH_LITERAL("download_page3.html")); |
| 827 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1)); |
| 828 |
| 829 // Open a web page and wait. |
| 830 ui_test_utils::NavigateToURL(browser(), url); |
| 831 |
| 832 // Download a file and wait. |
| 833 // The file to download is "download-test1.lib". |
| 834 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 835 DownloadAndWaitWithDisposition(browser(), |
| 836 GURL("javascript:openNew()"), |
| 837 CURRENT_TAB, |
| 838 EXPECT_NO_SELECT_DIALOG, |
| 839 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| 840 |
| 841 // When the download finishes, we should still have one tab. |
| 842 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 843 EXPECT_EQ(1, browser()->tab_count()); |
| 844 |
| 845 CheckDownload(browser(), file, file); |
| 846 } |
| 847 |
| 848 // Open a web page in the current tab, then call Javascript via a button to |
| 849 // download a file in a new tab, which is closed automatically when the |
| 850 // download begins. |
| 851 // Verify that we have 1 tab, and the download shelf is visible. |
| 852 // |
| 853 // The download_page4.html page contains a form with download-test1.lib as the |
| 854 // action. |
| 855 // |
| 856 // The test sometimes trips over underlying flakiness in the downloads |
| 857 // subsystem in in http://crbug.com/63237. It's entered as |
| 858 // DISABLED since if 63237 does cause a failure, it'll be a timeout. |
| 859 // Additionally, there is Windows-specific flake, http://crbug.com/20809. |
| 860 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_CloseNewTab3) { |
| 861 ASSERT_TRUE(InitialSetup(false)); |
| 862 // Because it's an HTML link, it should open a web page rather than |
| 863 // downloading. |
| 864 FilePath file1(FILE_PATH_LITERAL("download_page4.html")); |
| 865 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1)); |
| 866 |
| 867 // Open a web page and wait. |
| 868 ui_test_utils::NavigateToURL(browser(), url); |
| 869 |
| 870 // Download a file in a new tab and wait. The tab will automatically close |
| 871 // when the download begins. |
| 872 // The file to download is "download-test1.lib". |
| 873 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 874 DownloadAndWaitWithDisposition( |
| 875 browser(), |
| 876 GURL("javascript:document.getElementById('form').submit()"), |
| 877 CURRENT_TAB, |
| 878 EXPECT_NO_SELECT_DIALOG, |
| 879 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| 880 |
| 881 // When the download finishes, we should still have one tab. |
| 882 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 883 EXPECT_EQ(1, browser()->tab_count()); |
| 884 |
| 885 CheckDownload(browser(), file, file); |
| 886 } |
| 887 |
| 888 // Download a file in a new window. |
| 889 // Verify that we have 2 windows, and the download shelf is not visible in the |
| 890 // first window, but is visible in the second window. |
| 891 // Close the new window. |
| 892 // Verify that we have 1 window, and the download shelf is not visible. |
| 893 // |
| 894 // Regression test for http://crbug.com/44454 |
| 895 // |
| 896 // Test is believed mostly good (non-flaky) in itself, but it |
| 897 // sometimes trips over underlying flakiness in the downloads |
| 898 // subsystem in in http://crbug.com/63237. Until that bug is |
| 899 // fixed, this test should be considered flaky. It's entered as |
| 900 // DISABLED since if 63237 does cause a failure, it'll be a timeout. |
| 901 // Additionally, there is Windows-specific flake, http://crbug.com/20809. |
| 902 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_NewWindow) { |
| 903 ASSERT_TRUE(InitialSetup(false)); |
| 904 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 905 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 906 Browser* first_browser = browser(); |
| 907 |
| 908 // Download a file in a new window and wait. |
| 909 DownloadAndWaitWithDisposition(browser(), |
| 910 url, |
| 911 NEW_WINDOW, |
| 912 EXPECT_NO_SELECT_DIALOG, |
| 913 ui_test_utils::BROWSER_TEST_NONE); |
| 914 |
| 915 // When the download finishes, the download shelf SHOULD NOT be visible in |
| 916 // the first window. |
| 917 int window_count = BrowserList::size(); |
| 918 EXPECT_EQ(2, window_count); |
| 919 EXPECT_EQ(1, browser()->tab_count()); |
| 920 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 921 |
| 922 // The download shelf SHOULD be visible in the second window. |
| 923 std::set<Browser*> original_browsers; |
| 924 original_browsers.insert(browser()); |
| 925 Browser* download_browser = |
| 926 ui_test_utils::GetBrowserNotInSet(original_browsers); |
| 927 ASSERT_TRUE(download_browser != NULL); |
| 928 EXPECT_NE(download_browser, browser()); |
| 929 EXPECT_EQ(1, download_browser->tab_count()); |
| 930 EXPECT_TRUE(download_browser->window()->IsDownloadShelfVisible()); |
| 931 |
| 932 // Close the new window. |
| 933 download_browser->CloseWindow(); |
| 934 ui_test_utils::WaitForNotificationFrom(NotificationType::BROWSER_CLOSED, |
| 935 Source<Browser>(download_browser)); |
| 936 EXPECT_EQ(first_browser, browser()); |
| 937 window_count = BrowserList::size(); |
| 938 EXPECT_EQ(1, window_count); |
| 939 EXPECT_EQ(1, browser()->tab_count()); |
| 940 // The download shelf should not be visible in the remaining window. |
| 941 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 942 |
| 943 CheckDownload(browser(), file, file); |
| 334 } | 944 } |
| 335 | 945 |
| 336 } // namespace | 946 } // namespace |
| OLD | NEW |