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

Side by Side Diff: chrome/browser/download/download_extension_test.cc

Issue 9568003: Fixed issue with DownloadTestObserver. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Split DownloadTestObserver in two Created 8 years, 9 months 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) 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
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 // 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<DownloadTestObserver> 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 13 matching lines...) Expand all
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<DownloadTestObserver> 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 DownloadTestObserver* CreateDownloadObserver(size_t download_count) {
119 size_t download_count,
120 DownloadItem::DownloadState finished_state) {
121 return new DownloadTestObserver( 119 return new DownloadTestObserver(
122 GetDownloadManager(), download_count, finished_state, true, 120 GetDownloadManager(), download_count, true,
123 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); 121 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL);
124 } 122 }
125 123
124 DownloadTestObserver* CreateInProgressDownloadObserver(
125 size_t download_count) {
126 return new DownloadTestObserverInProgress(GetDownloadManager(),
127 download_count);
128 }
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 }
134 138
135 base::Value* RunFunctionAndReturnResult(UIThreadExtensionFunction* function, 139 base::Value* RunFunctionAndReturnResult(UIThreadExtensionFunction* function,
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698