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

Side by Side Diff: chrome/browser/download/download_browsertest.cc

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

Powered by Google App Engine
This is Rietveld 408576698