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

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

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 7 years, 6 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 <sstream> 5 #include <sstream>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 waiting_ = true; 116 waiting_ = true;
117 content::RunMessageLoop(); 117 content::RunMessageLoop();
118 waiting_ = false; 118 waiting_ = false;
119 } 119 }
120 120
121 private: 121 private:
122 virtual void OnDownloadCreated(content::DownloadManager* manager, 122 virtual void OnDownloadCreated(content::DownloadManager* manager,
123 content::DownloadItem* item) OVERRIDE { 123 content::DownloadItem* item) OVERRIDE {
124 DCHECK_EQ(manager_, manager); 124 DCHECK_EQ(manager_, manager);
125 if (waiting_) 125 if (waiting_)
126 MessageLoopForUI::current()->Quit(); 126 base::MessageLoopForUI::current()->Quit();
127 } 127 }
128 128
129 content::DownloadManager* manager_; 129 content::DownloadManager* manager_;
130 bool waiting_; 130 bool waiting_;
131 131
132 DISALLOW_COPY_AND_ASSIGN(CreatedObserver); 132 DISALLOW_COPY_AND_ASSIGN(CreatedObserver);
133 }; 133 };
134 134
135 class PercentWaiter : public content::DownloadItem::Observer { 135 class PercentWaiter : public content::DownloadItem::Observer {
136 public: 136 public:
(...skipping 21 matching lines...) Expand all
158 158
159 private: 159 private:
160 virtual void OnDownloadUpdated(content::DownloadItem* item) OVERRIDE { 160 virtual void OnDownloadUpdated(content::DownloadItem* item) OVERRIDE {
161 DCHECK_EQ(item_, item); 161 DCHECK_EQ(item_, item);
162 if (!error_ && 162 if (!error_ &&
163 ((prev_percent_ > item_->PercentComplete()) || 163 ((prev_percent_ > item_->PercentComplete()) ||
164 (item_->GetState() == DownloadItem::COMPLETE && 164 (item_->GetState() == DownloadItem::COMPLETE &&
165 (item_->PercentComplete() != 100)))) { 165 (item_->PercentComplete() != 100)))) {
166 error_ = true; 166 error_ = true;
167 if (waiting_) 167 if (waiting_)
168 MessageLoopForUI::current()->Quit(); 168 base::MessageLoopForUI::current()->Quit();
169 } 169 }
170 if (item_->GetState() == DownloadItem::COMPLETE && waiting_) 170 if (item_->GetState() == DownloadItem::COMPLETE && waiting_)
171 MessageLoopForUI::current()->Quit(); 171 base::MessageLoopForUI::current()->Quit();
172 } 172 }
173 173
174 virtual void OnDownloadDestroyed(content::DownloadItem* item) OVERRIDE { 174 virtual void OnDownloadDestroyed(content::DownloadItem* item) OVERRIDE {
175 DCHECK_EQ(item_, item); 175 DCHECK_EQ(item_, item);
176 item_->RemoveObserver(this); 176 item_->RemoveObserver(this);
177 item_ = NULL; 177 item_ = NULL;
178 } 178 }
179 179
180 content::DownloadItem* item_; 180 content::DownloadItem* item_;
181 bool waiting_; 181 bool waiting_;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 *results = results_.Pass(); 213 *results = results_.Pass();
214 } 214 }
215 return result_valid_; 215 return result_valid_;
216 } 216 }
217 217
218 private: 218 private:
219 void OnQueryDownloadsComplete( 219 void OnQueryDownloadsComplete(
220 scoped_ptr<std::vector<history::DownloadRow> > entries) { 220 scoped_ptr<std::vector<history::DownloadRow> > entries) {
221 result_valid_ = true; 221 result_valid_ = true;
222 results_ = entries.Pass(); 222 results_ = entries.Pass();
223 MessageLoopForUI::current()->Quit(); 223 base::MessageLoopForUI::current()->Quit();
224 } 224 }
225 225
226 Profile* profile_; 226 Profile* profile_;
227 scoped_ptr<std::vector<history::DownloadRow> > results_; 227 scoped_ptr<std::vector<history::DownloadRow> > results_;
228 bool result_valid_; 228 bool result_valid_;
229 CancelableRequestConsumer callback_consumer_; 229 CancelableRequestConsumer callback_consumer_;
230 230
231 DISALLOW_COPY_AND_ASSIGN(DownloadsHistoryDataCollector); 231 DISALLOW_COPY_AND_ASSIGN(DownloadsHistoryDataCollector);
232 }; 232 };
233 233
234 // Mock that simulates a permissions dialog where the user denies 234 // Mock that simulates a permissions dialog where the user denies
235 // permission to install. TODO(skerner): This could be shared with 235 // permission to install. TODO(skerner): This could be shared with
236 // extensions tests. Find a common place for this class. 236 // extensions tests. Find a common place for this class.
237 class MockAbortExtensionInstallPrompt : public ExtensionInstallPrompt { 237 class MockAbortExtensionInstallPrompt : public ExtensionInstallPrompt {
238 public: 238 public:
239 MockAbortExtensionInstallPrompt() : 239 MockAbortExtensionInstallPrompt() :
240 ExtensionInstallPrompt(NULL) { 240 ExtensionInstallPrompt(NULL) {
241 } 241 }
242 242
243 // Simulate a user abort on an extension installation. 243 // Simulate a user abort on an extension installation.
244 virtual void ConfirmInstall( 244 virtual void ConfirmInstall(
245 Delegate* delegate, 245 Delegate* delegate,
246 const Extension* extension, 246 const Extension* extension,
247 const ShowDialogCallback& show_dialog_callback) OVERRIDE { 247 const ShowDialogCallback& show_dialog_callback) OVERRIDE {
248 delegate->InstallUIAbort(true); 248 delegate->InstallUIAbort(true);
249 MessageLoopForUI::current()->Quit(); 249 base::MessageLoopForUI::current()->Quit();
250 } 250 }
251 251
252 virtual void OnInstallSuccess(const Extension* extension, 252 virtual void OnInstallSuccess(const Extension* extension,
253 SkBitmap* icon) OVERRIDE { 253 SkBitmap* icon) OVERRIDE {
254 } 254 }
255 virtual void OnInstallFailure( 255 virtual void OnInstallFailure(
256 const extensions::CrxInstallerError& error) OVERRIDE { 256 const extensions::CrxInstallerError& error) OVERRIDE {
257 } 257 }
258 }; 258 };
259 259
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 } 342 }
343 343
344 virtual void OnDownloadStored( 344 virtual void OnDownloadStored(
345 content::DownloadItem* item, 345 content::DownloadItem* item,
346 const history::DownloadRow& info) OVERRIDE { 346 const history::DownloadRow& info) OVERRIDE {
347 if (!callback_.is_null() && (!callback_.Run(info))) 347 if (!callback_.is_null() && (!callback_.Run(info)))
348 return; 348 return;
349 349
350 seen_stored_ = true; 350 seen_stored_ = true;
351 if (waiting_) 351 if (waiting_)
352 MessageLoopForUI::current()->Quit(); 352 base::MessageLoopForUI::current()->Quit();
353 } 353 }
354 354
355 virtual void OnDownloadHistoryDestroyed() OVERRIDE { 355 virtual void OnDownloadHistoryDestroyed() OVERRIDE {
356 DownloadServiceFactory::GetForProfile(profile_)-> 356 DownloadServiceFactory::GetForProfile(profile_)->
357 GetDownloadHistory()->RemoveObserver(this); 357 GetDownloadHistory()->RemoveObserver(this);
358 } 358 }
359 359
360 void WaitForStored() { 360 void WaitForStored() {
361 if (seen_stored_) 361 if (seen_stored_)
362 return; 362 return;
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 download_crx_util::SetMockInstallPromptForTesting( 1000 download_crx_util::SetMockInstallPromptForTesting(
1001 new MockAutoConfirmExtensionInstallPrompt( 1001 new MockAutoConfirmExtensionInstallPrompt(
1002 browser()->tab_strip_model()->GetActiveWebContents())); 1002 browser()->tab_strip_model()->GetActiveWebContents()));
1003 } 1003 }
1004 1004
1005 private: 1005 private:
1006 static void EnsureNoPendingDownloadJobsOnIO(bool* result) { 1006 static void EnsureNoPendingDownloadJobsOnIO(bool* result) {
1007 if (URLRequestSlowDownloadJob::NumberOutstandingRequests()) 1007 if (URLRequestSlowDownloadJob::NumberOutstandingRequests())
1008 *result = false; 1008 *result = false;
1009 BrowserThread::PostTask( 1009 BrowserThread::PostTask(
1010 BrowserThread::UI, FROM_HERE, MessageLoop::QuitClosure()); 1010 BrowserThread::UI, FROM_HERE, base::MessageLoop::QuitClosure());
1011 } 1011 }
1012 1012
1013 // Location of the test data. 1013 // Location of the test data.
1014 base::FilePath test_dir_; 1014 base::FilePath test_dir_;
1015 1015
1016 // Location of the downloads directory for these tests 1016 // Location of the downloads directory for these tests
1017 base::ScopedTempDir downloads_directory_; 1017 base::ScopedTempDir downloads_directory_;
1018 1018
1019 scoped_ptr<DownloadTestFileActivityObserver> file_activity_observer_; 1019 scoped_ptr<DownloadTestFileActivityObserver> file_activity_observer_;
1020 }; 1020 };
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 &web_contents->GetController()), 1179 &web_contents->GetController()),
1180 1); 1180 1);
1181 bool download_assempted; 1181 bool download_assempted;
1182 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( 1182 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
1183 browser()->tab_strip_model()->GetActiveWebContents(), 1183 browser()->tab_strip_model()->GetActiveWebContents(),
1184 "window.domAutomationController.send(startDownload());", 1184 "window.domAutomationController.send(startDownload());",
1185 &download_assempted)); 1185 &download_assempted));
1186 ASSERT_TRUE(download_assempted); 1186 ASSERT_TRUE(download_assempted);
1187 observer.WaitForObservation( 1187 observer.WaitForObservation(
1188 base::Bind(&content::RunMessageLoop), 1188 base::Bind(&content::RunMessageLoop),
1189 base::Bind(&MessageLoop::Quit, 1189 base::Bind(&base::MessageLoop::Quit,
1190 base::Unretained(MessageLoopForUI::current()))); 1190 base::Unretained(base::MessageLoopForUI::current())));
1191 1191
1192 // Check that we did not download the file. 1192 // Check that we did not download the file.
1193 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1193 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1194 base::FilePath file_path(DestinationFile(browser(), file)); 1194 base::FilePath file_path(DestinationFile(browser(), file));
1195 EXPECT_FALSE(file_util::PathExists(file_path)); 1195 EXPECT_FALSE(file_util::PathExists(file_path));
1196 1196
1197 // Check state. 1197 // Check state.
1198 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 1198 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1199 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 1199 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
1200 1200
(...skipping 1735 matching lines...) Expand 10 before | Expand all | Expand 10 after
2936 scoped_ptr<content::DownloadTestObserver> observer( 2936 scoped_ptr<content::DownloadTestObserver> observer(
2937 DangerousDownloadWaiter( 2937 DangerousDownloadWaiter(
2938 browser(), 1, 2938 browser(), 1,
2939 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); 2939 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY));
2940 ui_test_utils::NavigateToURL(browser(), url); 2940 ui_test_utils::NavigateToURL(browser(), url);
2941 observer->WaitForFinished(); 2941 observer->WaitForFinished();
2942 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::CANCELLED)); 2942 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::CANCELLED));
2943 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); 2943 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
2944 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 2944 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
2945 } 2945 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698