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