| 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/scoped_temp_dir.h" | 8 #include "base/scoped_temp_dir.h" |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "chrome/browser/download/download_extension_api.h" | 10 #include "chrome/browser/download/download_extension_api.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 | 50 |
| 51 DownloadManager* GetDownloadManager() { | 51 DownloadManager* GetDownloadManager() { |
| 52 DownloadService* download_service = | 52 DownloadService* download_service = |
| 53 DownloadServiceFactory::GetForProfile(browser()->profile()); | 53 DownloadServiceFactory::GetForProfile(browser()->profile()); |
| 54 return download_service->GetDownloadManager(); | 54 return download_service->GetDownloadManager(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void CreateSlowTestDownloads( | 57 void CreateSlowTestDownloads( |
| 58 size_t count, DownloadManager::DownloadVector* items) { | 58 size_t count, DownloadManager::DownloadVector* items) { |
| 59 for (size_t i = 0; i < count; ++i) { | 59 for (size_t i = 0; i < count; ++i) { |
| 60 scoped_ptr<DownloadTestObserver> observer( | 60 scoped_ptr<DownloadTestObserverInProgress> observer( |
| 61 CreateDownloadObserver(1, DownloadItem::IN_PROGRESS)); | 61 CreateInProgressDownloadObserver(1)); |
| 62 GURL slow_download_url(URLRequestSlowDownloadJob::kUnknownSizeUrl); | 62 GURL slow_download_url(URLRequestSlowDownloadJob::kUnknownSizeUrl); |
| 63 ui_test_utils::NavigateToURLWithDisposition( | 63 ui_test_utils::NavigateToURLWithDisposition( |
| 64 browser(), slow_download_url, CURRENT_TAB, | 64 browser(), slow_download_url, CURRENT_TAB, |
| 65 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 65 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 66 observer->WaitForFinished(); | 66 observer->WaitForFinished(); |
| 67 // We don't expect a select file dialog. | 67 // We don't expect a select file dialog. |
| 68 CHECK(!observer->select_file_dialog_seen()); | 68 CHECK(!observer->select_file_dialog_seen()); |
| 69 } | 69 } |
| 70 GetDownloadManager()->GetAllDownloads(FilePath(), items); | 70 GetDownloadManager()->GetAllDownloads(FilePath(), items); |
| 71 CHECK_EQ(count, items->size()); | 71 CHECK_EQ(count, items->size()); |
| 72 } | 72 } |
| 73 | 73 |
| 74 DownloadItem* CreateSlowTestDownload() { | 74 DownloadItem* CreateSlowTestDownload() { |
| 75 scoped_ptr<DownloadTestObserver> observer( | 75 scoped_ptr<DownloadTestObserverInProgress> observer( |
| 76 CreateDownloadObserver(1, DownloadItem::IN_PROGRESS)); | 76 CreateInProgressDownloadObserver(1)); |
| 77 GURL slow_download_url(URLRequestSlowDownloadJob::kUnknownSizeUrl); | 77 GURL slow_download_url(URLRequestSlowDownloadJob::kUnknownSizeUrl); |
| 78 DownloadManager* manager = GetDownloadManager(); | 78 DownloadManager* manager = GetDownloadManager(); |
| 79 | 79 |
| 80 EXPECT_EQ(0, manager->InProgressCount()); | 80 EXPECT_EQ(0, manager->InProgressCount()); |
| 81 if (manager->InProgressCount() != 0) | 81 if (manager->InProgressCount() != 0) |
| 82 return NULL; | 82 return NULL; |
| 83 | 83 |
| 84 ui_test_utils::NavigateToURLWithDisposition( | 84 ui_test_utils::NavigateToURLWithDisposition( |
| 85 browser(), slow_download_url, CURRENT_TAB, | 85 browser(), slow_download_url, CURRENT_TAB, |
| 86 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 86 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 99 if ((*iter)->GetState() == DownloadItem::IN_PROGRESS) { | 99 if ((*iter)->GetState() == DownloadItem::IN_PROGRESS) { |
| 100 // There should be only one IN_PROGRESS item. | 100 // There should be only one IN_PROGRESS item. |
| 101 EXPECT_EQ(NULL, new_item); | 101 EXPECT_EQ(NULL, new_item); |
| 102 new_item = *iter; | 102 new_item = *iter; |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 return new_item; | 105 return new_item; |
| 106 } | 106 } |
| 107 | 107 |
| 108 void FinishPendingSlowDownloads() { | 108 void FinishPendingSlowDownloads() { |
| 109 scoped_ptr<DownloadTestObserver> observer( | 109 scoped_ptr<DownloadTestObserverTerminal> observer( |
| 110 CreateDownloadObserver(1, DownloadItem::COMPLETE)); | 110 CreateDownloadObserver(1)); |
| 111 GURL finish_url(URLRequestSlowDownloadJob::kFinishDownloadUrl); | 111 GURL finish_url(URLRequestSlowDownloadJob::kFinishDownloadUrl); |
| 112 ui_test_utils::NavigateToURLWithDisposition( | 112 ui_test_utils::NavigateToURLWithDisposition( |
| 113 browser(), finish_url, NEW_FOREGROUND_TAB, | 113 browser(), finish_url, NEW_FOREGROUND_TAB, |
| 114 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 114 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 115 observer->WaitForFinished(); | 115 observer->WaitForFinished(); |
| 116 } | 116 } |
| 117 | 117 |
| 118 DownloadTestObserver* CreateDownloadObserver( | 118 DownloadTestObserverTerminal* CreateDownloadObserver(size_t download_count) { |
| 119 size_t download_count, | 119 return new DownloadTestObserverTerminal( |
| 120 DownloadItem::DownloadState finished_state) { | 120 GetDownloadManager(), download_count, true, |
| 121 return new DownloadTestObserver( | 121 DownloadTestObserverTerminal::ON_DANGEROUS_DOWNLOAD_FAIL); |
| 122 GetDownloadManager(), download_count, finished_state, true, | 122 } |
| 123 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); | 123 |
| 124 DownloadTestObserverInProgress* CreateInProgressDownloadObserver( |
| 125 size_t download_count) { |
| 126 return new DownloadTestObserverInProgress(GetDownloadManager(), |
| 127 download_count); |
| 124 } | 128 } |
| 125 | 129 |
| 126 bool RunFunction(UIThreadExtensionFunction* function, | 130 bool RunFunction(UIThreadExtensionFunction* function, |
| 127 const std::string& args) { | 131 const std::string& args) { |
| 128 // extension_function_test_utils::RunFunction() does not take | 132 // extension_function_test_utils::RunFunction() does not take |
| 129 // ownership of |function|. | 133 // ownership of |function|. |
| 130 scoped_refptr<ExtensionFunction> function_owner(function); | 134 scoped_refptr<ExtensionFunction> function_owner(function); |
| 131 return extension_function_test_utils::RunFunction( | 135 return extension_function_test_utils::RunFunction( |
| 132 function, args, browser(), extension_function_test_utils::NONE); | 136 function, args, browser(), extension_function_test_utils::NONE); |
| 133 } | 137 } |
| (...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 ASSERT_TRUE(result.get()); | 707 ASSERT_TRUE(result.get()); |
| 704 base::ListValue* result_list = NULL; | 708 base::ListValue* result_list = NULL; |
| 705 ASSERT_TRUE(result->GetAsList(&result_list)); | 709 ASSERT_TRUE(result->GetAsList(&result_list)); |
| 706 ASSERT_EQ(1UL, result_list->GetSize()); | 710 ASSERT_EQ(1UL, result_list->GetSize()); |
| 707 base::DictionaryValue* item_value = NULL; | 711 base::DictionaryValue* item_value = NULL; |
| 708 ASSERT_TRUE(result_list->GetDictionary(0, &item_value)); | 712 ASSERT_TRUE(result_list->GetDictionary(0, &item_value)); |
| 709 FilePath::StringType item_name; | 713 FilePath::StringType item_name; |
| 710 ASSERT_TRUE(item_value->GetString("filename", &item_name)); | 714 ASSERT_TRUE(item_value->GetString("filename", &item_name)); |
| 711 ASSERT_EQ(items[2]->GetFullPath().value(), item_name); | 715 ASSERT_EQ(items[2]->GetFullPath().value(), item_name); |
| 712 } | 716 } |
| OLD | NEW |