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

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

Powered by Google App Engine
This is Rietveld 408576698