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