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

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: Merged with trunk. 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
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 #define MOCK_ASSERT_TRUE(test) \
Paweł Hajdan Jr. 2011/01/03 09:06:47 I'd strongly prefer to avoid that macro. Instead,
ahendrickson 2011/01/05 00:32:09 I'd rather have information about the failure in t
34 do \
35 { \
36 bool condition = test; \
37 GTEST_TEST_BOOLEAN_(condition, #test, false, true, \
38 GTEST_NONFATAL_FAILURE_); \
39 if (!condition) return false; \
40 } while(false)
Randy Smith (Not in Mondays) 2010/12/23 18:00:34 Include a comment about how this macro will be use
ahendrickson 2011/01/05 00:32:09 I'm doing it this way so |test| doesn't get evalua
41
25 namespace { 42 namespace {
26 43
27 // Variation of DownloadsCompleteObserver from ui_test_utils.cc; the 44 // Variation of DownloadsCompleteObserver from ui_test_utils.cc; the
28 // specifically targeted download tests need finer granularity on waiting. 45 // specifically targeted download tests need finer granularity on waiting.
29 // Construction of this class defines a system state, based on some number 46 // Construction of this class defines a system state, based on some number
30 // of downloads being seen in a particular state + other events that 47 // 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 48 // 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 49 // 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 50 // is considered finished. Callers may either probe for the finished state, or
34 // wait on it. 51 // wait on it.
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 // the select file dialog comes up. 223 // the select file dialog comes up.
207 bool finish_on_select_file_; 224 bool finish_on_select_file_;
208 225
209 // True if we've seen the select file dialog. 226 // True if we've seen the select file dialog.
210 bool select_file_dialog_seen_; 227 bool select_file_dialog_seen_;
211 228
212 DISALLOW_COPY_AND_ASSIGN(DownloadsObserver); 229 DISALLOW_COPY_AND_ASSIGN(DownloadsObserver);
213 }; 230 };
214 231
215 class DownloadTest : public InProcessBrowserTest { 232 class DownloadTest : public InProcessBrowserTest {
233 public:
234 enum SelectExpectation {
235 EXPECT_NO_SELECT_DIALOG = -1,
236 EXPECT_NOTHING,
237 EXPECT_SELECT_DIALOG
238 };
239
240 virtual bool InitialSetup(bool prompt_for_download) {
241 MOCK_ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir_));
Paweł Hajdan Jr. 2011/01/03 09:06:47 Alternatively, you can do if (!PathService::Get(..
242
243 PushBrowser(InProcessBrowserTest::browser()); // Set the initial browser.
244
245 // Sanity check default values for window / tab count and shelf visibility.
246 int window_count = BrowserList::size();
247 EXPECT_EQ(1, window_count);
248 EXPECT_EQ(1, browser()->tab_count());
249 bool is_shelf_visible = browser()->window()->IsDownloadShelfVisible();
250 EXPECT_FALSE(is_shelf_visible);
251
252 // Set up the temporary download folder.
253 MOCK_ASSERT_TRUE(CreateAndSetDownloadsDirectory());
254 browser()->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload,
255 prompt_for_download);
256
257 return true;
258 }
259
216 protected: 260 protected:
217 void SetUpInProcessBrowserTestFixture() { 261
218 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir_)); 262 // We now use a browser stack.
Paweł Hajdan Jr. 2011/01/03 09:06:47 nit: It would deserve some more explanations. It's
ahendrickson 2011/01/05 00:32:09 Removing the browser stack.
263 void PushBrowser(Browser* browser) { browsers_.push(browser); }
264 void PopBrowser() { browsers_.pop(); }
265
266 virtual Browser* browser() const {
Paweł Hajdan Jr. 2011/01/03 09:06:47 Nooooo! Don't do that, it's going to be super-conf
ahendrickson 2011/01/05 00:32:09 Removing the browser stack.
267 return browsers_.empty() ? NULL : browsers_.top();
Randy Smith (Not in Mondays) 2010/12/23 18:00:34 I think we agreed that overall it made sense to re
ahendrickson 2011/01/05 00:32:09 Removing the browser stack.
219 } 268 }
220 269
221 // Must be called after browser creation. Creates a temporary 270 // Must be called after browser creation. Creates a temporary
222 // directory for downloads that is auto-deleted on destruction. 271 // directory for downloads that is auto-deleted on destruction.
223 bool CreateAndSetDownloadsDirectory() { 272 bool CreateAndSetDownloadsDirectory() {
224 if (downloads_directory_.CreateUniqueTempDir()) { 273 if (!browser())
225 browser()->profile()->GetPrefs()->SetFilePath( 274 return false;
226 prefs::kDownloadDefaultDirectory, 275
227 downloads_directory_.path()); 276 if (!downloads_directory_.CreateUniqueTempDir())
228 return true; 277 return false;
229 } 278
230 return false; 279 browser()->profile()->GetPrefs()->SetFilePath(
280 prefs::kDownloadDefaultDirectory,
281 downloads_directory_.path());
282
283 return true;
231 } 284 }
232 285
233 // May only be called inside of an individual test; browser() is NULL 286 // May only be called inside of an individual test; browser() is NULL
234 // outside of that context. 287 // outside of that context.
235 FilePath GetDownloadDirectory() { 288 FilePath GetDownloadDirectory() {
236 DownloadManager* download_mananger = 289 DownloadManager* download_mananger =
237 browser()->profile()->GetDownloadManager(); 290 browser()->profile()->GetDownloadManager();
238 return download_mananger->download_prefs()->download_path(); 291 return download_mananger->download_prefs()->download_path();
239 } 292 }
240 293
241 DownloadsObserver* CreateWaiter(int num_downloads) { 294 DownloadsObserver* CreateWaiter(int num_downloads) {
242 DownloadManager* download_manager = 295 DownloadManager* download_manager =
243 browser()->profile()->GetDownloadManager(); 296 browser()->profile()->GetDownloadManager();
244 return new DownloadsObserver( 297 return new DownloadsObserver(
245 download_manager, num_downloads, 298 download_manager, num_downloads,
246 DownloadsObserver::FILE_RENAME, // Really done 299 DownloadsObserver::FILE_RENAME, // Really done
247 true); // Bail on select file 300 true); // Bail on select file
301 }
302
303 // Download |url|, then wait for the download to finish.
304 // |disposition| indicates where the navigation occurs (current tab, new
305 // foreground tab, etc).
306 // |expectation| indicates whether or not a Select File dialog should be
307 // open when the download is finished, or if we don't care.
308 // If the dialog appears, the test completes. The only effect |expectation|
309 // has is whether or not the test succeeds.
310 // |browser_test_flags| indicate what to wait for, and is an OR of 0 or more
311 // values in the BrowserTestFlags enum.
312 void DownloadAndWaitWithDisposition(Browser* browser,
313 const GURL& url,
314 WindowOpenDisposition disposition,
315 SelectExpectation expectation,
316 int browser_test_flags) {
317 // Setup notification, navigate, and block.
318 scoped_ptr<DownloadsObserver> observer(CreateWaiter(1));
319 // This call will block until the condition specified by
320 // |browser_test_flags|, but will not wait for the download to finish.
321 ui_test_utils::NavigateToURLWithDisposition(browser,
322 url,
323 disposition,
324 browser_test_flags);
325 // Waits for the download to complete.
326 observer->WaitForFinished();
327
328 // If specified, check the state of the select file dialog.
329 if (expectation != EXPECT_NOTHING) {
330 EXPECT_EQ(expectation == EXPECT_SELECT_DIALOG,
331 observer->select_file_dialog_seen());
332 }
333 }
334
335 // Download a file in the current tab, then wait for the download to finish.
336 void DownloadAndWait(Browser* browser,
337 const GURL& url,
338 SelectExpectation expectation) {
339 DownloadAndWaitWithDisposition(
340 browser,
341 url,
342 CURRENT_TAB,
343 expectation,
344 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
248 } 345 }
249 346
250 // Should only be called when the download is known to have finished 347 // Should only be called when the download is known to have finished
251 // (in error or not). 348 // (in error or not).
252 void CheckDownload(const FilePath& downloaded_filename, 349 bool CheckDownload(const FilePath& downloaded_filename,
253 const FilePath& origin_filename) { 350 const FilePath& origin_filename) {
254 // Find the path to which the data will be downloaded. 351 // Find the path to which the data will be downloaded.
255 FilePath downloaded_file = 352 FilePath downloaded_file =
256 GetDownloadDirectory().Append(downloaded_filename); 353 GetDownloadDirectory().Append(downloaded_filename);
257 354
258 // Find the origin path (from which the data comes). 355 // Find the origin path (from which the data comes).
259 FilePath origin_file(test_dir_.Append(origin_filename)); 356 FilePath origin_file(test_dir_.Append(origin_filename));
260 ASSERT_TRUE(file_util::PathExists(origin_file)); 357 MOCK_ASSERT_TRUE(file_util::PathExists(origin_file));
261 358
262 // Confirm the downloaded data file exists. 359 // Confirm the downloaded data file exists.
263 ASSERT_TRUE(file_util::PathExists(downloaded_file)); 360 MOCK_ASSERT_TRUE(file_util::PathExists(downloaded_file));
264 int64 origin_file_size = 0; 361 int64 origin_file_size = 0;
265 int64 downloaded_file_size = 0; 362 int64 downloaded_file_size = 0;
266 EXPECT_TRUE(file_util::GetFileSize(origin_file, &origin_file_size)); 363 EXPECT_TRUE(file_util::GetFileSize(origin_file, &origin_file_size));
267 EXPECT_TRUE(file_util::GetFileSize(downloaded_file, &downloaded_file_size)); 364 EXPECT_TRUE(file_util::GetFileSize(downloaded_file, &downloaded_file_size));
268 EXPECT_EQ(origin_file_size, downloaded_file_size); 365 EXPECT_EQ(origin_file_size, downloaded_file_size);
269 EXPECT_TRUE(file_util::ContentsEqual(downloaded_file, origin_file)); 366 EXPECT_TRUE(file_util::ContentsEqual(downloaded_file, origin_file));
270 367
271 #if defined(OS_WIN) 368 #if defined(OS_WIN)
272 // Check if the Zone Identifier is correctly set. 369 // Check if the Zone Identifier is correctly set.
273 if (file_util::VolumeSupportsADS(downloaded_file)) 370 if (file_util::VolumeSupportsADS(downloaded_file))
274 EXPECT_TRUE(file_util::HasInternetZoneIdentifier(downloaded_file)); 371 EXPECT_TRUE(file_util::HasInternetZoneIdentifier(downloaded_file));
275 #endif 372 #endif
276 373
277 // Delete the downloaded copy of the file. 374 // Delete the downloaded copy of the file.
278 EXPECT_TRUE(file_util::DieFileDie(downloaded_file, false)); 375 MOCK_ASSERT_TRUE(file_util::DieFileDie(downloaded_file, false));
376
377 return true;
378 }
379
380 // TODO(ahendrickson) -- |expected_title_in_progress| and
381 // |expected_title_in_finished| need to be checked.
382 bool RunSizeTest(const GURL& url,
383 const std::wstring& expected_title_in_progress,
384 const std::wstring& expected_title_finished) {
385 if (!InitialSetup(false))
386 return false;
387
388 // Download a partial web page in a background tab and wait.
389 // The mock system will not complete until it gets a special URL.
390 scoped_ptr<DownloadsObserver> observer(CreateWaiter(1));
391 ui_test_utils::NavigateToURL(browser(), url);
392
393 // TODO(ahendrickson): check download status text before downloading.
394 // Need to:
395 // - Add a member function to the |DownloadShelf| interface class, that
396 // indicates how many members it has.
397 // - Add a member function to |DownloadShelf| to get the status text
398 // of a given member (for example, via |DownloadItemView|'s
399 // GetAccessibleName() member function), by index.
400 // - Iterate over browser()->window()->GetDownloadShelf()'s members
401 // to see if any match the status text we want. Start with the last one.
402
403 // Complete sending the request. We do this by loading a second URL in a
404 // separate tab.
405 GURL finish_url(URLRequestSlowDownloadJob::kFinishDownloadUrl);
406 ui_test_utils::NavigateToURLWithDisposition(
407 browser(),
408 finish_url,
409 NEW_FOREGROUND_TAB,
410 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
411 observer->WaitForFinished();
412
413 EXPECT_EQ(2, browser()->tab_count());
414
415 // TODO(ahendrickson): check download status text after downloading.
416
417 // Make sure the download shelf is showing.
418 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
419
420 FilePath filename;
421 net::FileURLToFilePath(url, &filename);
422 filename = filename.BaseName();
423 FilePath download_path = downloads_directory_.path().Append(filename);
424 MOCK_ASSERT_TRUE(file_util::PathExists(download_path));
425
426 // Delete the file we just downloaded.
427 EXPECT_TRUE(file_util::DieFileDie(download_path, true));
428 EXPECT_FALSE(file_util::PathExists(download_path));
429
430 return true;
279 } 431 }
280 432
281 private: 433 private:
282 // Location of the test data. 434 // Location of the test data.
283 FilePath test_dir_; 435 FilePath test_dir_;
284 436
285 // Location of the downloads directory for these tests 437 // Location of the downloads directory for these tests
286 ScopedTempDir downloads_directory_; 438 ScopedTempDir downloads_directory_;
439
440 std::stack<Browser *> browsers_;
Paweł Hajdan Jr. 2011/01/03 09:06:47 nit: No space between Browser and "*". Please add
ahendrickson 2011/01/05 00:32:09 Removing the browser stack.
287 }; 441 };
288 442
443 // NOTES:
Paweł Hajdan Jr. 2011/01/03 09:06:47 nit: Those notes are not download test specific, a
ahendrickson 2011/01/05 00:32:09 Changed the note's text. I needed this informatio
444 //
445 // Files for these tests are found in chrome\test\data\.
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().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),
Paweł Hajdan Jr. 2011/01/03 09:06:47 nit: No space before "*", please make sure to fix
ahendrickson 2011/01/05 00:32:09 The style guide is ambiguous about this, so I've a
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 PushBrowser(incognito);
643 CreateAndSetDownloadsDirectory(); // Must be called after PushBrowser().
644 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
645 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
646 // Since |incognito| is a separate browser, we have to set it up explicitly.
647 browser()->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload,
648 false);
649 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG);
650
651 // We should still have 2 windows.
652 window_count = BrowserList::size();
653 EXPECT_EQ(2, window_count);
654
655 // Verify that the download shelf is showing for the Incognito window.
656 bool is_shelf_visible = browser()->window()->IsDownloadShelfVisible();
657 EXPECT_TRUE(is_shelf_visible);
658
659 // Close the Incognito window and don't crash.
660 browser()->CloseWindow();
661 ui_test_utils::WaitForWindowClosed(browser());
662
663 PopBrowser(); // We're done with the incognito window.
664
665 window_count = BrowserList::size();
666 EXPECT_EQ(1, window_count);
667
668 // Verify that the regular window does not have a download shelf.
669 is_shelf_visible = browser()->window()->IsDownloadShelfVisible();
670 EXPECT_FALSE(is_shelf_visible);
671
672 CheckDownload(file, file);
673 }
674
675 // Navigate to a new background page, but don't download. Confirm that the
676 // download shelf is not visible and that we have two tabs.
677 IN_PROC_BROWSER_TEST_F(DownloadTest, DontCloseNewTab1) {
678 ASSERT_TRUE(InitialSetup(false));
679 // Because it's an HTML link, it should open a web page rather than
680 // downloading.
681 FilePath file1(FILE_PATH_LITERAL("download-test2.html"));
682 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1));
683
684 // Open a web page and wait.
685 ui_test_utils::NavigateToURLWithDisposition(
686 browser(),
687 url,
688 NEW_BACKGROUND_TAB,
689 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
690
691 // We should have two tabs now.
692 EXPECT_EQ(2, browser()->tab_count());
693 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
694 }
695
696 // Download a file in a background tab. Verify that the tab is closed
697 // automatically, and that the download shelf is visible in the current tab.
698 //
699 // The test sometimes trips over underlying flakiness in the downloads
700 // subsystem in http://crbug.com/63237. It's entered as
701 // DISABLED since if 63237 does cause a failure, it'll be a timeout.
702 // Additionally, there is Windows-specific flake, http://crbug.com/20809.
703 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_CloseNewTab1) {
704 ASSERT_TRUE(InitialSetup(false));
705
706 // Download a file in a new background tab and wait. The tab is automatically
707 // closed when the download begins.
708 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
709 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
710 DownloadAndWaitWithDisposition(
711 browser(),
712 url,
713 NEW_BACKGROUND_TAB,
714 EXPECT_NO_SELECT_DIALOG,
715 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
716
717 // When the download finishes, we should still have one tab.
718 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
719 EXPECT_EQ(1, browser()->tab_count());
720
721 CheckDownload(file, file);
722 }
723
724 // Open a web page in the current tab, then download a file in another tab via
725 // a Javascript call.
726 // Verify that we have 2 tabs, and the download shelf is visible in the current
727 // tab.
728 //
729 // The download_page1.html page contains an openNew() function that opens a
730 // tab and then downloads download-test1.lib.
731 //
732 // The test sometimes trips over underlying flakiness in the downloads
733 // subsystem in in http://crbug.com/63237. It's entered as
734 // DISABLED since if 63237 does cause a failure, it'll be a timeout.
735 // Additionally, there is Windows-specific flake, http://crbug.com/20809.
736 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_DontCloseNewTab2) {
737 ASSERT_TRUE(InitialSetup(false));
738 // Because it's an HTML link, it should open a web page rather than
739 // downloading.
740 FilePath file1(FILE_PATH_LITERAL("download_page1.html"));
741 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1));
742
743 // Open a web page and wait.
744 ui_test_utils::NavigateToURL(browser(), url);
745
746 // Download a file in a new tab and wait (via Javascript).
747 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
748 DownloadAndWaitWithDisposition(browser(),
749 GURL("javascript:openNew()"),
750 CURRENT_TAB,
751 EXPECT_NO_SELECT_DIALOG,
752 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
753
754 // When the download finishes, we should have two tabs.
755 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
756 EXPECT_EQ(2, browser()->tab_count());
757
758 CheckDownload(file, file);
759 }
760
761 // Open a web page in the current tab, open another tab via a Javascript call,
762 // then download a file in the new tab.
763 // Verify that we have 2 tabs, and the download shelf is visible in the current
764 // tab.
765 //
766 // The download_page2.html page contains an openNew() function that opens a
767 // tab.
768 //
769 // The test sometimes trips over underlying flakiness in the downloads
770 // subsystem in in http://crbug.com/63237. It's entered as
771 // DISABLED since if 63237 does cause a failure, it'll be a timeout.
772 // Additionally, there is Windows-specific flake, http://crbug.com/20809.
773 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_DontCloseNewTab3) {
774 ASSERT_TRUE(InitialSetup(false));
775 // Because it's an HTML link, it should open a web page rather than
776 // downloading.
777 FilePath file1(FILE_PATH_LITERAL("download_page2.html"));
778 GURL url1(URLRequestMockHTTPJob::GetMockUrl(file1));
779
780 // Open a web page and wait.
781 ui_test_utils::NavigateToURL(browser(), url1);
782
783 // Open a new tab and wait.
784 ui_test_utils::NavigateToURLWithDisposition(
785 browser(),
786 GURL("javascript:openNew()"),
787 CURRENT_TAB,
788 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
789
790 EXPECT_EQ(2, browser()->tab_count());
791
792 // Download a file and wait.
793 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
794 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
795 DownloadAndWaitWithDisposition(browser(),
796 url,
797 CURRENT_TAB,
798 EXPECT_NO_SELECT_DIALOG,
799 ui_test_utils::BROWSER_TEST_NONE);
800
801 // When the download finishes, we should have two tabs.
802 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
803 EXPECT_EQ(2, browser()->tab_count());
804
805 CheckDownload(file, file);
806 }
807
808 // Open a web page in the current tab, then download a file via Javascript,
809 // which will do so in a temporary tab.
810 // Verify that we have 1 tab, and the download shelf is visible.
811 //
812 // The download_page3.html page contains an openNew() function that opens a
813 // tab with download-test1.lib in the URL. When the URL is determined to be
814 // a download, the tab is closed automatically.
815 //
816 // The test sometimes trips over underlying flakiness in the downloads
817 // subsystem in in http://crbug.com/63237. It's entered as
818 // DISABLED since if 63237 does cause a failure, it'll be a timeout.
819 // Additionally, there is Windows-specific flake, http://crbug.com/20809.
820 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_CloseNewTab2) {
821 ASSERT_TRUE(InitialSetup(false));
822 // Because it's an HTML link, it should open a web page rather than
823 // downloading.
824 FilePath file1(FILE_PATH_LITERAL("download_page3.html"));
825 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1));
826
827 // Open a web page and wait.
828 ui_test_utils::NavigateToURL(browser(), url);
829
830 // Download a file and wait.
831 // The file to download is "download-test1.lib".
832 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
833 DownloadAndWaitWithDisposition(browser(),
834 GURL("javascript:openNew()"),
835 CURRENT_TAB,
836 EXPECT_NO_SELECT_DIALOG,
837 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
838
839 // When the download finishes, we should still have one tab.
840 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
841 EXPECT_EQ(1, browser()->tab_count());
842
843 CheckDownload(file, file);
844 }
845
846 // Open a web page in the current tab, then call Javascript via a button to
847 // download a file in a new tab, which is closed automatically when the
848 // download begins.
849 // Verify that we have 1 tab, and the download shelf is visible.
850 //
851 // The download_page4.html page contains a form with download-test1.lib as the
852 // action.
853 //
854 // The test sometimes trips over underlying flakiness in the downloads
855 // subsystem in in http://crbug.com/63237. It's entered as
856 // DISABLED since if 63237 does cause a failure, it'll be a timeout.
857 // Additionally, there is Windows-specific flake, http://crbug.com/20809.
858 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_CloseNewTab3) {
859 ASSERT_TRUE(InitialSetup(false));
860 // Because it's an HTML link, it should open a web page rather than
861 // downloading.
862 FilePath file1(FILE_PATH_LITERAL("download_page4.html"));
863 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1));
864
865 // Open a web page and wait.
866 ui_test_utils::NavigateToURL(browser(), url);
867
868 // Download a file in a new tab and wait. The tab will automatically close
869 // when the download begins.
870 // The file to download is "download-test1.lib".
871 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
872 DownloadAndWaitWithDisposition(
873 browser(),
874 GURL("javascript:document.getElementById('form').submit()"),
875 CURRENT_TAB,
876 EXPECT_NO_SELECT_DIALOG,
877 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
878
879 // When the download finishes, we should still have one tab.
880 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
881 EXPECT_EQ(1, browser()->tab_count());
882
883 CheckDownload(file, file);
884 }
885
886 // Download a file in a new window.
887 // Verify that we have 2 windows, and the download shelf is not visible in the
888 // first window, but is visible in the second window.
889 // Close the new window.
890 // Verify that we have 1 window, and the download shelf is not visible.
891 //
892 // Regression test for http://crbug.com/44454
893 //
894 // Test is believed mostly good (non-flaky) in itself, but it
895 // sometimes trips over underlying flakiness in the downloads
896 // subsystem in in http://crbug.com/63237. Until that bug is
897 // fixed, this test should be considered flaky. It's entered as
898 // DISABLED since if 63237 does cause a failure, it'll be a timeout.
899 // Additionally, there is Windows-specific flake, http://crbug.com/20809.
900 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_NewWindow) {
901 ASSERT_TRUE(InitialSetup(false));
902 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
903 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
904
905 // Download a file in a new window and wait.
906 DownloadAndWaitWithDisposition(browser(),
907 url,
908 NEW_WINDOW,
909 EXPECT_NO_SELECT_DIALOG,
910 ui_test_utils::BROWSER_TEST_NONE);
911
912 // When the download finishes, the download shelf SHOULD NOT be visible in
913 // the first window.
914 int window_count = BrowserList::size();
915 EXPECT_EQ(2, window_count);
916 EXPECT_EQ(1, browser()->tab_count());
917 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
918
919 // The download shelf SHOULD be visible in the second window.
920 Browser* download_browser = ui_test_utils::GetBrowser(1);
Randy Smith (Not in Mondays) 2010/12/23 18:00:34 For the reasons we discussed (reliance on the inte
ahendrickson 2011/01/05 00:32:09 Done.
921 ASSERT_TRUE(download_browser != NULL);
922 EXPECT_NE(download_browser, browser());
923 EXPECT_EQ(1, download_browser->tab_count());
924 EXPECT_TRUE(download_browser->window()->IsDownloadShelfVisible());
925
926 // Close the new window.
927 download_browser->CloseWindow();
928 ui_test_utils::WaitForWindowClosed(download_browser);
929 window_count = BrowserList::size();
930 EXPECT_EQ(1, window_count);
931 EXPECT_EQ(1, browser()->tab_count());
932 // The download shelf should not be visible in the remaining window.
933 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
934
935 CheckDownload(file, file);
334 } 936 }
335 937
336 } // namespace 938 } // 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