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

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

Powered by Google App Engine
This is Rietveld 408576698