OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 BrowserThread::PostTask( | 268 BrowserThread::PostTask( |
269 BrowserThread::IO, FROM_HERE, | 269 BrowserThread::IO, FROM_HERE, |
270 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); | 270 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); |
271 InProcessBrowserTest::SetUpOnMainThread(); | 271 InProcessBrowserTest::SetUpOnMainThread(); |
272 GoOnTheRecord(); | 272 GoOnTheRecord(); |
273 CreateAndSetDownloadsDirectory(); | 273 CreateAndSetDownloadsDirectory(); |
274 current_browser()->profile()->GetPrefs()->SetBoolean( | 274 current_browser()->profile()->GetPrefs()->SetBoolean( |
275 prefs::kPromptForDownload, false); | 275 prefs::kPromptForDownload, false); |
276 GetOnRecordManager()->RemoveAllDownloads(); | 276 GetOnRecordManager()->RemoveAllDownloads(); |
277 events_listener_.reset(new DownloadsEventsListener()); | 277 events_listener_.reset(new DownloadsEventsListener()); |
| 278 file_chooser_observer_.reset(new DownloadTestFileChooserObserver( |
| 279 current_browser()->profile())); |
278 } | 280 } |
279 | 281 |
280 void GoOnTheRecord() { current_browser_ = browser(); } | 282 void GoOnTheRecord() { current_browser_ = browser(); } |
281 | 283 |
282 void GoOffTheRecord() { | 284 void GoOffTheRecord() { |
283 if (!incognito_browser_) { | 285 if (!incognito_browser_) { |
284 incognito_browser_ = CreateIncognitoBrowser(); | 286 incognito_browser_ = CreateIncognitoBrowser(); |
285 GetOffRecordManager()->RemoveAllDownloads(); | 287 GetOffRecordManager()->RemoveAllDownloads(); |
286 } | 288 } |
287 current_browser_ = incognito_browser_; | 289 current_browser_ = incognito_browser_; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 for (size_t i = 0; i < count; ++i) { | 405 for (size_t i = 0; i < count; ++i) { |
404 scoped_ptr<DownloadTestObserver> observer( | 406 scoped_ptr<DownloadTestObserver> observer( |
405 CreateInProgressDownloadObserver(1)); | 407 CreateInProgressDownloadObserver(1)); |
406 GURL slow_download_url(URLRequestSlowDownloadJob::kUnknownSizeUrl); | 408 GURL slow_download_url(URLRequestSlowDownloadJob::kUnknownSizeUrl); |
407 ui_test_utils::NavigateToURLWithDisposition( | 409 ui_test_utils::NavigateToURLWithDisposition( |
408 current_browser(), slow_download_url, CURRENT_TAB, | 410 current_browser(), slow_download_url, CURRENT_TAB, |
409 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 411 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
410 observer->WaitForFinished(); | 412 observer->WaitForFinished(); |
411 EXPECT_EQ( | 413 EXPECT_EQ( |
412 1u, observer->NumDownloadsSeenInState(DownloadItem::IN_PROGRESS)); | 414 1u, observer->NumDownloadsSeenInState(DownloadItem::IN_PROGRESS)); |
413 // We don't expect a select file dialog. | |
414 ASSERT_FALSE(observer->select_file_dialog_seen()); | |
415 } | 415 } |
416 GetCurrentManager()->GetAllDownloads(FilePath(), items); | 416 GetCurrentManager()->GetAllDownloads(FilePath(), items); |
417 ASSERT_EQ(count, items->size()); | 417 ASSERT_EQ(count, items->size()); |
418 } | 418 } |
419 | 419 |
420 DownloadItem* CreateSlowTestDownload() { | 420 DownloadItem* CreateSlowTestDownload() { |
421 scoped_ptr<DownloadTestObserver> observer( | 421 scoped_ptr<DownloadTestObserver> observer( |
422 CreateInProgressDownloadObserver(1)); | 422 CreateInProgressDownloadObserver(1)); |
423 GURL slow_download_url(URLRequestSlowDownloadJob::kUnknownSizeUrl); | 423 GURL slow_download_url(URLRequestSlowDownloadJob::kUnknownSizeUrl); |
424 DownloadManager* manager = GetCurrentManager(); | 424 DownloadManager* manager = GetCurrentManager(); |
425 | 425 |
426 EXPECT_EQ(0, manager->InProgressCount()); | 426 EXPECT_EQ(0, manager->InProgressCount()); |
427 if (manager->InProgressCount() != 0) | 427 if (manager->InProgressCount() != 0) |
428 return NULL; | 428 return NULL; |
429 | 429 |
430 ui_test_utils::NavigateToURLWithDisposition( | 430 ui_test_utils::NavigateToURLWithDisposition( |
431 current_browser(), slow_download_url, CURRENT_TAB, | 431 current_browser(), slow_download_url, CURRENT_TAB, |
432 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 432 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
433 | 433 |
434 observer->WaitForFinished(); | 434 observer->WaitForFinished(); |
435 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::IN_PROGRESS)); | 435 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::IN_PROGRESS)); |
436 // We don't expect a select file dialog. | |
437 if (observer->select_file_dialog_seen()) | |
438 return NULL; | |
439 | 436 |
440 DownloadManager::DownloadVector items; | 437 DownloadManager::DownloadVector items; |
441 manager->GetAllDownloads(FilePath(), &items); | 438 manager->GetAllDownloads(FilePath(), &items); |
442 | 439 |
443 DownloadItem* new_item = NULL; | 440 DownloadItem* new_item = NULL; |
444 for (DownloadManager::DownloadVector::iterator iter = items.begin(); | 441 for (DownloadManager::DownloadVector::iterator iter = items.begin(); |
445 iter != items.end(); ++iter) { | 442 iter != items.end(); ++iter) { |
446 if ((*iter)->GetState() == DownloadItem::IN_PROGRESS) { | 443 if ((*iter)->GetState() == DownloadItem::IN_PROGRESS) { |
447 // There should be only one IN_PROGRESS item. | 444 // There should be only one IN_PROGRESS item. |
448 EXPECT_EQ(NULL, new_item); | 445 EXPECT_EQ(NULL, new_item); |
449 new_item = *iter; | 446 new_item = *iter; |
450 } | 447 } |
451 } | 448 } |
452 return new_item; | 449 return new_item; |
453 } | 450 } |
454 | 451 |
455 void FinishPendingSlowDownloads() { | 452 void FinishPendingSlowDownloads() { |
456 scoped_ptr<DownloadTestObserver> observer( | 453 scoped_ptr<DownloadTestObserver> observer( |
457 CreateDownloadObserver(1)); | 454 CreateDownloadObserver(1)); |
458 GURL finish_url(URLRequestSlowDownloadJob::kFinishDownloadUrl); | 455 GURL finish_url(URLRequestSlowDownloadJob::kFinishDownloadUrl); |
459 ui_test_utils::NavigateToURLWithDisposition( | 456 ui_test_utils::NavigateToURLWithDisposition( |
460 current_browser(), finish_url, NEW_FOREGROUND_TAB, | 457 current_browser(), finish_url, NEW_FOREGROUND_TAB, |
461 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 458 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
462 observer->WaitForFinished(); | 459 observer->WaitForFinished(); |
463 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 460 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
464 } | 461 } |
465 | 462 |
466 DownloadTestObserver* CreateDownloadObserver(size_t download_count) { | 463 DownloadTestObserver* CreateDownloadObserver(size_t download_count) { |
467 return new DownloadTestObserverTerminal( | 464 return new DownloadTestObserverTerminal( |
468 GetCurrentManager(), download_count, true, | 465 GetCurrentManager(), download_count, |
469 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); | 466 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); |
470 } | 467 } |
471 | 468 |
472 DownloadTestObserver* CreateInProgressDownloadObserver( | 469 DownloadTestObserver* CreateInProgressDownloadObserver( |
473 size_t download_count) { | 470 size_t download_count) { |
474 return new DownloadTestObserverInProgress( | 471 return new DownloadTestObserverInProgress( |
475 GetCurrentManager(), download_count, true); | 472 GetCurrentManager(), download_count); |
476 } | 473 } |
477 | 474 |
478 bool RunFunction(UIThreadExtensionFunction* function, | 475 bool RunFunction(UIThreadExtensionFunction* function, |
479 const std::string& args) { | 476 const std::string& args) { |
480 scoped_refptr<UIThreadExtensionFunction> delete_function(function); | 477 scoped_refptr<UIThreadExtensionFunction> delete_function(function); |
481 SetUpExtensionFunction(function); | 478 SetUpExtensionFunction(function); |
482 return extension_function_test_utils::RunFunction( | 479 return extension_function_test_utils::RunFunction( |
483 function, args, browser(), GetFlags()); | 480 function, args, browser(), GetFlags()); |
484 } | 481 } |
485 | 482 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 current_browser()->profile()->GetPrefs()->SetFilePath( | 564 current_browser()->profile()->GetPrefs()->SetFilePath( |
568 prefs::kDownloadDefaultDirectory, | 565 prefs::kDownloadDefaultDirectory, |
569 downloads_directory_.path()); | 566 downloads_directory_.path()); |
570 } | 567 } |
571 | 568 |
572 ScopedTempDir downloads_directory_; | 569 ScopedTempDir downloads_directory_; |
573 const extensions::Extension* extension_; | 570 const extensions::Extension* extension_; |
574 Browser* incognito_browser_; | 571 Browser* incognito_browser_; |
575 Browser* current_browser_; | 572 Browser* current_browser_; |
576 scoped_ptr<DownloadsEventsListener> events_listener_; | 573 scoped_ptr<DownloadsEventsListener> events_listener_; |
| 574 scoped_ptr<DownloadTestFileChooserObserver> file_chooser_observer_; |
577 | 575 |
578 DISALLOW_COPY_AND_ASSIGN(DownloadExtensionTest); | 576 DISALLOW_COPY_AND_ASSIGN(DownloadExtensionTest); |
579 }; | 577 }; |
580 | 578 |
581 class MockIconExtractorImpl : public DownloadFileIconExtractor { | 579 class MockIconExtractorImpl : public DownloadFileIconExtractor { |
582 public: | 580 public: |
583 MockIconExtractorImpl(const FilePath& path, IconLoader::IconSize icon_size, | 581 MockIconExtractorImpl(const FilePath& path, IconLoader::IconSize icon_size, |
584 const std::string& response) | 582 const std::string& response) |
585 : expected_path_(path), | 583 : expected_path_(path), |
586 expected_icon_size_(icon_size), | 584 expected_icon_size_(icon_size), |
(...skipping 1564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2151 " \"state\": {" | 2149 " \"state\": {" |
2152 " \"previous\": \"in_progress\"," | 2150 " \"previous\": \"in_progress\"," |
2153 " \"current\": \"complete\"}}]", | 2151 " \"current\": \"complete\"}}]", |
2154 result_id, | 2152 result_id, |
2155 GetFilename("on_record.txt.crdownload").c_str(), | 2153 GetFilename("on_record.txt.crdownload").c_str(), |
2156 GetFilename("on_record.txt").c_str()))); | 2154 GetFilename("on_record.txt").c_str()))); |
2157 std::string disk_data; | 2155 std::string disk_data; |
2158 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data)); | 2156 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data)); |
2159 EXPECT_STREQ(kPayloadData, disk_data.c_str()); | 2157 EXPECT_STREQ(kPayloadData, disk_data.c_str()); |
2160 } | 2158 } |
OLD | NEW |