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

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

Issue 7466033: Fix warning prompting on closing a window that will cancel downloads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make sure to use temporary download directory Created 9 years, 2 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
« no previous file with comments | « no previous file | chrome/browser/download/download_service.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/scoped_temp_dir.h" 11 #include "base/scoped_temp_dir.h"
12 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/test/test_file_util.h" 14 #include "base/test/test_file_util.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/download/chrome_download_manager_delegate.h" 17 #include "chrome/browser/download/chrome_download_manager_delegate.h"
18 #include "chrome/browser/download/download_crx_util.h" 18 #include "chrome/browser/download/download_crx_util.h"
19 #include "chrome/browser/download/download_history.h" 19 #include "chrome/browser/download/download_history.h"
20 #include "chrome/browser/download/download_prefs.h" 20 #include "chrome/browser/download/download_prefs.h"
21 #include "chrome/browser/download/download_service.h" 21 #include "chrome/browser/download/download_service.h"
22 #include "chrome/browser/download/download_service_factory.h" 22 #include "chrome/browser/download/download_service_factory.h"
23 #include "chrome/browser/download/download_shelf.h" 23 #include "chrome/browser/download/download_shelf.h"
24 #include "chrome/browser/download/download_test_observer.h"
24 #include "chrome/browser/download/download_util.h" 25 #include "chrome/browser/download/download_util.h"
25 #include "chrome/browser/extensions/extension_install_ui.h" 26 #include "chrome/browser/extensions/extension_install_ui.h"
26 #include "chrome/browser/extensions/extension_service.h" 27 #include "chrome/browser/extensions/extension_service.h"
27 #include "chrome/browser/history/history.h" 28 #include "chrome/browser/history/history.h"
28 #include "chrome/browser/net/url_request_mock_util.h" 29 #include "chrome/browser/net/url_request_mock_util.h"
29 #include "chrome/browser/prefs/pref_service.h" 30 #include "chrome/browser/prefs/pref_service.h"
30 #include "chrome/browser/profiles/profile.h" 31 #include "chrome/browser/profiles/profile.h"
31 #include "chrome/browser/ui/browser.h" 32 #include "chrome/browser/ui/browser.h"
32 #include "chrome/browser/ui/browser_list.h" 33 #include "chrome/browser/ui/browser_list.h"
33 #include "chrome/browser/ui/browser_window.h" 34 #include "chrome/browser/ui/browser_window.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 77
77 // Fake user click on "Deny". 78 // Fake user click on "Deny".
78 void DenyDangerousDownload(scoped_refptr<DownloadManager> download_manager, 79 void DenyDangerousDownload(scoped_refptr<DownloadManager> download_manager,
79 int32 download_id) { 80 int32 download_id) {
80 DownloadItem* download = download_manager->GetDownloadItem(download_id); 81 DownloadItem* download = download_manager->GetDownloadItem(download_id);
81 ASSERT_TRUE(download->IsPartialDownload()); 82 ASSERT_TRUE(download->IsPartialDownload());
82 download->Cancel(true); 83 download->Cancel(true);
83 download->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); 84 download->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD);
84 } 85 }
85 86
86 // Construction of this class defines a system state, based on some number
87 // of downloads being seen in a particular state + other events that
88 // may occur in the download system. That state will be recorded if it
89 // occurs at any point after construction. When that state occurs, the class
90 // is considered finished. Callers may either probe for the finished state, or
91 // wait on it.
92 //
93 // TODO(rdsmith): Detect manager going down, remove pointer to
94 // DownloadManager, transition to finished. (For right now we
95 // just use a scoped_refptr<> to keep it around, but that may cause
96 // timeouts on waiting if a DownloadManager::Shutdown() occurs which
97 // cancels our in-progress downloads.)
98 class DownloadsObserver : public DownloadManager::Observer,
99 public DownloadItem::Observer {
100 public:
101 // Create an object that will be considered finished when |wait_count|
102 // download items have entered state |download_finished_state|.
103 // If |finish_on_select_file| is true, the object will also be
104 // considered finished if the DownloadManager raises a
105 // SelectFileDialogDisplayed() notification.
106
107 // TODO(rdsmith): Consider rewriting the interface to take a list of events
108 // to treat as completion events.
109 DownloadsObserver(DownloadManager* download_manager,
110 size_t wait_count,
111 DownloadItem::DownloadState download_finished_state,
112 bool finish_on_select_file,
113 DangerousDownloadAction dangerous_download_action)
114 : download_manager_(download_manager),
115 wait_count_(wait_count),
116 finished_downloads_at_construction_(0),
117 waiting_(false),
118 download_finished_state_(download_finished_state),
119 finish_on_select_file_(finish_on_select_file),
120 select_file_dialog_seen_(false),
121 dangerous_download_action_(dangerous_download_action) {
122 download_manager_->AddObserver(this); // Will call initial ModelChanged().
123 finished_downloads_at_construction_ = finished_downloads_.size();
124 EXPECT_NE(DownloadItem::REMOVING, download_finished_state)
125 << "Waiting for REMOVING is not supported. Try COMPLETE.";
126 }
127
128 ~DownloadsObserver() {
129 std::set<DownloadItem*>::iterator it = downloads_observed_.begin();
130 for (; it != downloads_observed_.end(); ++it)
131 (*it)->RemoveObserver(this);
132
133 download_manager_->RemoveObserver(this);
134 }
135
136 // State accessors.
137 bool select_file_dialog_seen() { return select_file_dialog_seen_; }
138
139 // Wait for whatever state was specified in the constructor.
140 void WaitForFinished() {
141 if (!IsFinished()) {
142 waiting_ = true;
143 ui_test_utils::RunMessageLoop();
144 waiting_ = false;
145 }
146 }
147
148 // Return true if everything's happened that we're configured for.
149 bool IsFinished() {
150 if (finished_downloads_.size() - finished_downloads_at_construction_
151 >= wait_count_)
152 return true;
153 return (finish_on_select_file_ && select_file_dialog_seen_);
154 }
155
156 // DownloadItem::Observer
157 virtual void OnDownloadUpdated(DownloadItem* download) {
158 // The REMOVING state indicates that the download is being destroyed.
159 // Stop observing. Do not do anything with it, as it is about to be gone.
160 if (download->state() == DownloadItem::REMOVING) {
161 std::set<DownloadItem*>::iterator it = downloads_observed_.find(download);
162 ASSERT_TRUE(it != downloads_observed_.end());
163 downloads_observed_.erase(it);
164 download->RemoveObserver(this);
165 return;
166 }
167
168 // Real UI code gets the user's response after returning from the observer.
169 if (download->safety_state() == DownloadItem::DANGEROUS &&
170 !ContainsKey(dangerous_downloads_seen_, download->id())) {
171 dangerous_downloads_seen_.insert(download->id());
172
173 // Calling DangerousDownloadValidated() at this point will
174 // cause the download to be completed twice. Do what the real UI
175 // code does: make the call as a delayed task.
176 switch (dangerous_download_action_) {
177 case ON_DANGEROUS_DOWNLOAD_ACCEPT:
178 // Fake user click on "Accept". Delay the actual click, as the
179 // real UI would.
180 BrowserThread::PostTask(
181 BrowserThread::UI, FROM_HERE,
182 base::Bind(&AcceptDangerousDownload, download_manager_,
183 download->id()));
184 break;
185
186 case ON_DANGEROUS_DOWNLOAD_DENY:
187 // Fake a user click on "Deny". Delay the actual click, as the
188 // real UI would.
189 BrowserThread::PostTask(
190 BrowserThread::UI, FROM_HERE,
191 base::Bind(&DenyDangerousDownload, download_manager_,
192 download->id()));
193 break;
194
195 case ON_DANGEROUS_DOWNLOAD_FAIL:
196 ADD_FAILURE() << "Unexpected dangerous download item.";
197 break;
198
199 default:
200 NOTREACHED();
201 }
202 }
203
204 if (download->state() == download_finished_state_)
205 DownloadInFinalState(download);
206 }
207
208 virtual void OnDownloadOpened(DownloadItem* download) {}
209
210 // DownloadManager::Observer
211 virtual void ModelChanged() {
212 // Regenerate DownloadItem observers. If there are any download items
213 // in our final state, note them in |finished_downloads_|
214 // (done by |OnDownloadUpdated()|).
215 std::vector<DownloadItem*> downloads;
216 download_manager_->GetAllDownloads(FilePath(), &downloads);
217
218 std::vector<DownloadItem*>::iterator it = downloads.begin();
219 for (; it != downloads.end(); ++it) {
220 OnDownloadUpdated(*it); // Safe to call multiple times; checks state.
221
222 std::set<DownloadItem*>::const_iterator
223 finished_it(finished_downloads_.find(*it));
224 std::set<DownloadItem*>::iterator
225 observed_it(downloads_observed_.find(*it));
226
227 // If it isn't finished and we're aren't observing it, start.
228 if (finished_it == finished_downloads_.end() &&
229 observed_it == downloads_observed_.end()) {
230 (*it)->AddObserver(this);
231 downloads_observed_.insert(*it);
232 continue;
233 }
234
235 // If it is finished and we are observing it, stop.
236 if (finished_it != finished_downloads_.end() &&
237 observed_it != downloads_observed_.end()) {
238 (*it)->RemoveObserver(this);
239 downloads_observed_.erase(observed_it);
240 continue;
241 }
242 }
243 }
244
245 virtual void SelectFileDialogDisplayed(int32 /* id */) {
246 select_file_dialog_seen_ = true;
247 SignalIfFinished();
248 }
249
250 virtual size_t NumDangerousDownloadsSeen() const {
251 return dangerous_downloads_seen_.size();
252 }
253
254 private:
255 // Called when we know that a download item is in a final state.
256 // Note that this is not the same as it first transitioning in to the
257 // final state; multiple notifications may occur once the item is in
258 // that state. So we keep our own track of transitions into final.
259 void DownloadInFinalState(DownloadItem* download) {
260 if (finished_downloads_.find(download) != finished_downloads_.end()) {
261 // We've already seen terminal state on this download.
262 return;
263 }
264
265 // Record the transition.
266 finished_downloads_.insert(download);
267
268 SignalIfFinished();
269 }
270
271 void SignalIfFinished() {
272 if (waiting_ && IsFinished())
273 MessageLoopForUI::current()->Quit();
274 }
275
276 // The observed download manager.
277 scoped_refptr<DownloadManager> download_manager_;
278
279 // The set of DownloadItem's that have transitioned to their finished state
280 // since construction of this object. When the size of this array
281 // reaches wait_count_, we're done.
282 std::set<DownloadItem*> finished_downloads_;
283
284 // The set of DownloadItem's we are currently observing. Generally there
285 // won't be any overlap with the above; once we see the final state
286 // on a DownloadItem, we'll stop observing it.
287 std::set<DownloadItem*> downloads_observed_;
288
289 // The number of downloads to wait on completing.
290 size_t wait_count_;
291
292 // The number of downloads entered in final state in initial
293 // ModelChanged(). We use |finished_downloads_| to track the incoming
294 // transitions to final state we should ignore, and to track the
295 // number of final state transitions that occurred between
296 // construction and return from wait. But some downloads may be in our
297 // final state (and thus be entered into |finished_downloads_|) when we
298 // construct this class. We don't want to count those in our transition
299 // to finished.
300 int finished_downloads_at_construction_;
301
302 // Whether an internal message loop has been started and must be quit upon
303 // all downloads completing.
304 bool waiting_;
305
306 // The state on which to consider the DownloadItem finished.
307 DownloadItem::DownloadState download_finished_state_;
308
309 // True if we should transition the DownloadsObserver to finished if
310 // the select file dialog comes up.
311 bool finish_on_select_file_;
312
313 // True if we've seen the select file dialog.
314 bool select_file_dialog_seen_;
315
316 // Action to take if a dangerous download is encountered.
317 DangerousDownloadAction dangerous_download_action_;
318
319 // Holds the download ids which were dangerous.
320 std::set<int32> dangerous_downloads_seen_;
321
322 DISALLOW_COPY_AND_ASSIGN(DownloadsObserver);
323 };
324
325 // WaitForFlush() returns after:
326 // * There are no IN_PROGRESS download items remaining on the
327 // DownloadManager.
328 // * There have been two round trip messages through the file and
329 // IO threads.
330 // This almost certainly means that a Download cancel has propagated through
331 // the system.
332 class DownloadsFlushObserver
333 : public DownloadManager::Observer,
334 public DownloadItem::Observer,
335 public base::RefCountedThreadSafe<DownloadsFlushObserver> {
336 public:
337 explicit DownloadsFlushObserver(DownloadManager* download_manager)
338 : download_manager_(download_manager),
339 waiting_for_zero_inprogress_(true) {}
340
341 void WaitForFlush() {
342 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
343 download_manager_->AddObserver(this);
344 ui_test_utils::RunMessageLoop();
345 }
346
347 // DownloadsManager observer methods.
348 virtual void ModelChanged() {
349 // Model has changed, so there may be more DownloadItems to observe.
350 CheckDownloadsInProgress(true);
351 }
352
353 // DownloadItem observer methods.
354 virtual void OnDownloadUpdated(DownloadItem* download) {
355 // No change in DownloadItem set on manager.
356 CheckDownloadsInProgress(false);
357 }
358 virtual void OnDownloadOpened(DownloadItem* download) {}
359
360 protected:
361 friend class base::RefCountedThreadSafe<DownloadsFlushObserver>;
362
363 virtual ~DownloadsFlushObserver() {
364 download_manager_->RemoveObserver(this);
365 for (std::set<DownloadItem*>::iterator it = downloads_observed_.begin();
366 it != downloads_observed_.end(); ++it) {
367 (*it)->RemoveObserver(this);
368 }
369 }
370
371 private:
372 // If we're waiting for that flush point, check the number
373 // of downloads in the IN_PROGRESS state and take appropriate
374 // action. If requested, also observes all downloads while iterating.
375 void CheckDownloadsInProgress(bool observe_downloads) {
376 if (waiting_for_zero_inprogress_) {
377 int count = 0;
378
379 std::vector<DownloadItem*> downloads;
380 download_manager_->SearchDownloads(string16(), &downloads);
381 std::vector<DownloadItem*>::iterator it = downloads.begin();
382 for (; it != downloads.end(); ++it) {
383 if ((*it)->state() == DownloadItem::IN_PROGRESS)
384 count++;
385 if (observe_downloads) {
386 if (downloads_observed_.find(*it) == downloads_observed_.end()) {
387 (*it)->AddObserver(this);
388 }
389 // Download items are forever, and we don't want to make
390 // assumptions about future state transitions, so once we
391 // start observing them, we don't stop until destruction.
392 }
393 }
394
395 if (count == 0) {
396 waiting_for_zero_inprogress_ = false;
397 // Stop observing DownloadItems. We maintain the observation
398 // of DownloadManager so that we don't have to independently track
399 // whether we are observing it for conditional destruction.
400 for (std::set<DownloadItem*>::iterator it = downloads_observed_.begin();
401 it != downloads_observed_.end(); ++it) {
402 (*it)->RemoveObserver(this);
403 }
404 downloads_observed_.clear();
405
406 // Trigger next step. We need to go past the IO thread twice, as
407 // there's a self-task posting in the IO thread cancel path.
408 BrowserThread::PostTask(
409 BrowserThread::FILE, FROM_HERE,
410 base::Bind(&DownloadsFlushObserver::PingFileThread, this, 2));
411 }
412 }
413 }
414
415 void PingFileThread(int cycle) {
416 BrowserThread::PostTask(
417 BrowserThread::IO, FROM_HERE,
418 base::Bind(&DownloadsFlushObserver::PingIOThread, this, cycle));
419 }
420
421 void PingIOThread(int cycle) {
422 if (--cycle) {
423 BrowserThread::PostTask(
424 BrowserThread::UI, FROM_HERE,
425 base::Bind(&DownloadsFlushObserver::PingFileThread, this, cycle));
426 } else {
427 BrowserThread::PostTask(
428 BrowserThread::UI, FROM_HERE, new MessageLoop::QuitTask());
429 }
430 }
431
432 DownloadManager* download_manager_;
433 std::set<DownloadItem*> downloads_observed_;
434 bool waiting_for_zero_inprogress_;
435
436 DISALLOW_COPY_AND_ASSIGN(DownloadsFlushObserver);
437 };
438
439 // Collect the information from FILE and IO threads needed for the Cancel 87 // Collect the information from FILE and IO threads needed for the Cancel
440 // Test, specifically the number of outstanding requests on the 88 // Test, specifically the number of outstanding requests on the
441 // ResourceDispatcherHost and the number of pending downloads on the 89 // ResourceDispatcherHost and the number of pending downloads on the
442 // DownloadFileManager. 90 // DownloadFileManager.
443 class CancelTestDataCollector 91 class CancelTestDataCollector
444 : public base::RefCountedThreadSafe<CancelTestDataCollector> { 92 : public base::RefCountedThreadSafe<CancelTestDataCollector> {
445 public: 93 public:
446 CancelTestDataCollector() 94 CancelTestDataCollector()
447 : resource_dispatcher_host_( 95 : resource_dispatcher_host_(
448 g_browser_process->resource_dispatcher_host()), 96 g_browser_process->resource_dispatcher_host()),
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 359
712 DownloadPrefs* GetDownloadPrefs(Browser* browser) { 360 DownloadPrefs* GetDownloadPrefs(Browser* browser) {
713 return DownloadPrefs::FromDownloadManager( 361 return DownloadPrefs::FromDownloadManager(
714 DownloadManagerForBrowser(browser)); 362 DownloadManagerForBrowser(browser));
715 } 363 }
716 364
717 FilePath GetDownloadDirectory(Browser* browser) { 365 FilePath GetDownloadDirectory(Browser* browser) {
718 return GetDownloadPrefs(browser)->download_path(); 366 return GetDownloadPrefs(browser)->download_path();
719 } 367 }
720 368
721 // Create a DownloadsObserver that will wait for the 369 // Create a DownloadTestObserver that will wait for the
722 // specified number of downloads to finish. 370 // specified number of downloads to finish.
723 DownloadsObserver* CreateWaiter(Browser* browser, int num_downloads) { 371 DownloadTestObserver* CreateWaiter(Browser* browser, int num_downloads) {
724 DownloadManager* download_manager = DownloadManagerForBrowser(browser); 372 DownloadManager* download_manager = DownloadManagerForBrowser(browser);
725 return new DownloadsObserver( 373 return new DownloadTestObserver(
726 download_manager, num_downloads, 374 download_manager, num_downloads,
727 DownloadItem::COMPLETE, // Really done 375 DownloadItem::COMPLETE, // Really done
728 true, // Bail on select file 376 true, // Bail on select file
729 ON_DANGEROUS_DOWNLOAD_FAIL); 377 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL);
730 } 378 }
731 379
732 // Create a DownloadsObserver that will wait for the 380 // Create a DownloadTestObserver that will wait for the
733 // specified number of downloads to start. 381 // specified number of downloads to start.
734 DownloadsObserver* CreateInProgressWaiter(Browser* browser, 382 DownloadTestObserver* CreateInProgressWaiter(Browser* browser,
735 int num_downloads) { 383 int num_downloads) {
736 DownloadManager* download_manager = DownloadManagerForBrowser(browser); 384 DownloadManager* download_manager = DownloadManagerForBrowser(browser);
737 return new DownloadsObserver( 385 return new DownloadTestObserver(
738 download_manager, num_downloads, 386 download_manager, num_downloads,
739 DownloadItem::IN_PROGRESS, // Has started 387 DownloadItem::IN_PROGRESS, // Has started
740 true, // Bail on select file 388 true, // Bail on select file
741 ON_DANGEROUS_DOWNLOAD_FAIL); 389 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL);
742 } 390 }
743 391
744 // Create a DownloadsObserver that will wait for the 392 // Create a DownloadTestObserver that will wait for the
745 // specified number of downloads to finish, or for 393 // specified number of downloads to finish, or for
746 // a dangerous download warning to be shown. 394 // a dangerous download warning to be shown.
747 DownloadsObserver* DangerousInstallWaiter( 395 DownloadTestObserver* DangerousInstallWaiter(
748 Browser* browser, 396 Browser* browser,
749 int num_downloads, 397 int num_downloads,
750 DownloadItem::DownloadState final_state, 398 DownloadItem::DownloadState final_state,
751 DangerousDownloadAction dangerous_download_action) { 399 DownloadTestObserver::DangerousDownloadAction dangerous_download_action) {
752 DownloadManager* download_manager = DownloadManagerForBrowser(browser); 400 DownloadManager* download_manager = DownloadManagerForBrowser(browser);
753 return new DownloadsObserver( 401 return new DownloadTestObserver(
754 download_manager, num_downloads, 402 download_manager, num_downloads,
755 final_state, 403 final_state,
756 true, // Bail on select file 404 true, // Bail on select file
757 dangerous_download_action); 405 dangerous_download_action);
758 } 406 }
759 407
760 // Download |url|, then wait for the download to finish. 408 // Download |url|, then wait for the download to finish.
761 // |disposition| indicates where the navigation occurs (current tab, new 409 // |disposition| indicates where the navigation occurs (current tab, new
762 // foreground tab, etc). 410 // foreground tab, etc).
763 // |expectation| indicates whether or not a Select File dialog should be 411 // |expectation| indicates whether or not a Select File dialog should be
764 // open when the download is finished, or if we don't care. 412 // open when the download is finished, or if we don't care.
765 // If the dialog appears, the routine exits. The only effect |expectation| 413 // If the dialog appears, the routine exits. The only effect |expectation|
766 // has is whether or not the test succeeds. 414 // has is whether or not the test succeeds.
767 // |browser_test_flags| indicate what to wait for, and is an OR of 0 or more 415 // |browser_test_flags| indicate what to wait for, and is an OR of 0 or more
768 // values in the ui_test_utils::BrowserTestWaitFlags enum. 416 // values in the ui_test_utils::BrowserTestWaitFlags enum.
769 void DownloadAndWaitWithDisposition(Browser* browser, 417 void DownloadAndWaitWithDisposition(Browser* browser,
770 const GURL& url, 418 const GURL& url,
771 WindowOpenDisposition disposition, 419 WindowOpenDisposition disposition,
772 SelectExpectation expectation, 420 SelectExpectation expectation,
773 int browser_test_flags) { 421 int browser_test_flags) {
774 // Setup notification, navigate, and block. 422 // Setup notification, navigate, and block.
775 scoped_ptr<DownloadsObserver> observer(CreateWaiter(browser, 1)); 423 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser, 1));
776 // This call will block until the condition specified by 424 // This call will block until the condition specified by
777 // |browser_test_flags|, but will not wait for the download to finish. 425 // |browser_test_flags|, but will not wait for the download to finish.
778 ui_test_utils::NavigateToURLWithDisposition(browser, 426 ui_test_utils::NavigateToURLWithDisposition(browser,
779 url, 427 url,
780 disposition, 428 disposition,
781 browser_test_flags); 429 browser_test_flags);
782 // Waits for the download to complete. 430 // Waits for the download to complete.
783 observer->WaitForFinished(); 431 observer->WaitForFinished();
784 432
785 // If specified, check the state of the select file dialog. 433 // If specified, check the state of the select file dialog.
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 // |expected_title_finished| need to be checked. 505 // |expected_title_finished| need to be checked.
858 FilePath filename; 506 FilePath filename;
859 net::FileURLToFilePath(url, &filename); 507 net::FileURLToFilePath(url, &filename);
860 string16 expected_title_in_progress( 508 string16 expected_title_in_progress(
861 ASCIIToUTF16(partial_indication) + filename.LossyDisplayName()); 509 ASCIIToUTF16(partial_indication) + filename.LossyDisplayName());
862 string16 expected_title_finished( 510 string16 expected_title_finished(
863 ASCIIToUTF16(total_indication) + filename.LossyDisplayName()); 511 ASCIIToUTF16(total_indication) + filename.LossyDisplayName());
864 512
865 // Download a partial web page in a background tab and wait. 513 // Download a partial web page in a background tab and wait.
866 // The mock system will not complete until it gets a special URL. 514 // The mock system will not complete until it gets a special URL.
867 scoped_ptr<DownloadsObserver> observer(CreateWaiter(browser, 1)); 515 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser, 1));
868 ui_test_utils::NavigateToURL(browser, url); 516 ui_test_utils::NavigateToURL(browser, url);
869 517
870 // TODO(ahendrickson): check download status text before downloading. 518 // TODO(ahendrickson): check download status text before downloading.
871 // Need to: 519 // Need to:
872 // - Add a member function to the |DownloadShelf| interface class, that 520 // - Add a member function to the |DownloadShelf| interface class, that
873 // indicates how many members it has. 521 // indicates how many members it has.
874 // - Add a member function to |DownloadShelf| to get the status text 522 // - Add a member function to |DownloadShelf| to get the status text
875 // of a given member (for example, via the name in |DownloadItemView|'s 523 // of a given member (for example, via the name in |DownloadItemView|'s
876 // GetAccessibleState() member function), by index. 524 // GetAccessibleState() member function), by index.
877 // - Iterate over browser->window()->GetDownloadShelf()'s members 525 // - Iterate over browser->window()->GetDownloadShelf()'s members
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 // downloads preferences settings. 713 // downloads preferences settings.
1066 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeTypeSelect) { 714 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeTypeSelect) {
1067 ASSERT_TRUE(InitialSetup(true)); 715 ASSERT_TRUE(InitialSetup(true));
1068 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 716 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1069 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 717 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1070 718
1071 NullSelectFile(browser()); 719 NullSelectFile(browser());
1072 720
1073 // Download the file and wait. We expect the Select File dialog to appear 721 // Download the file and wait. We expect the Select File dialog to appear
1074 // due to the MIME type, but we still wait until the download completes. 722 // due to the MIME type, but we still wait until the download completes.
1075 scoped_ptr<DownloadsObserver> observer( 723 scoped_ptr<DownloadTestObserver> observer(
1076 new DownloadsObserver( 724 new DownloadTestObserver(
1077 DownloadManagerForBrowser(browser()), 725 DownloadManagerForBrowser(browser()),
1078 1, 726 1,
1079 DownloadItem::COMPLETE, // Really done 727 DownloadItem::COMPLETE, // Really done
1080 false, // Continue on select file. 728 false, // Continue on select file.
1081 ON_DANGEROUS_DOWNLOAD_FAIL)); 729 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
1082 ui_test_utils::NavigateToURLWithDisposition( 730 ui_test_utils::NavigateToURLWithDisposition(
1083 browser(), url, CURRENT_TAB, 731 browser(), url, CURRENT_TAB,
1084 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 732 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1085 observer->WaitForFinished(); 733 observer->WaitForFinished();
1086 EXPECT_TRUE(observer->select_file_dialog_seen()); 734 EXPECT_TRUE(observer->select_file_dialog_seen());
1087 735
1088 // Check state. 736 // Check state.
1089 EXPECT_EQ(1, browser()->tab_count()); 737 EXPECT_EQ(1, browser()->tab_count());
1090 CheckDownload(browser(), file, file); 738 CheckDownload(browser(), file, file);
1091 CheckDownloadUI(browser(), true, true, file); 739 CheckDownloadUI(browser(), true, true, file);
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
1492 } 1140 }
1493 1141
1494 // Check that downloading multiple (in this case, 2) files does not result in 1142 // Check that downloading multiple (in this case, 2) files does not result in
1495 // corrupted files. 1143 // corrupted files.
1496 IN_PROC_BROWSER_TEST_F(DownloadTest, MultiDownload) { 1144 IN_PROC_BROWSER_TEST_F(DownloadTest, MultiDownload) {
1497 ASSERT_TRUE(InitialSetup(false)); 1145 ASSERT_TRUE(InitialSetup(false));
1498 EXPECT_EQ(1, browser()->tab_count()); 1146 EXPECT_EQ(1, browser()->tab_count());
1499 1147
1500 // Create a download, wait until it's started, and confirm 1148 // Create a download, wait until it's started, and confirm
1501 // we're in the expected state. 1149 // we're in the expected state.
1502 scoped_ptr<DownloadsObserver> observer1(CreateInProgressWaiter(browser(), 1)); 1150 scoped_ptr<DownloadTestObserver> observer1(
1151 CreateInProgressWaiter(browser(), 1));
1503 ui_test_utils::NavigateToURL( 1152 ui_test_utils::NavigateToURL(
1504 browser(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); 1153 browser(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl));
1505 observer1->WaitForFinished(); 1154 observer1->WaitForFinished();
1506 1155
1507 std::vector<DownloadItem*> downloads; 1156 std::vector<DownloadItem*> downloads;
1508 browser()->profile()->GetDownloadManager()->SearchDownloads( 1157 browser()->profile()->GetDownloadManager()->SearchDownloads(
1509 string16(), &downloads); 1158 string16(), &downloads);
1510 ASSERT_EQ(1u, downloads.size()); 1159 ASSERT_EQ(1u, downloads.size());
1511 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->state()); 1160 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->state());
1512 CheckDownloadUI(browser(), true, true, FilePath()); 1161 CheckDownloadUI(browser(), true, true, FilePath());
(...skipping 13 matching lines...) Expand all
1526 // We don't know the order of the downloads. 1175 // We don't know the order of the downloads.
1527 DownloadItem* download2 = downloads[(download1 == downloads[0]) ? 1 : 0]; 1176 DownloadItem* download2 = downloads[(download1 == downloads[0]) ? 1 : 0];
1528 1177
1529 ASSERT_EQ(DownloadItem::IN_PROGRESS, download1->state()); 1178 ASSERT_EQ(DownloadItem::IN_PROGRESS, download1->state());
1530 ASSERT_EQ(DownloadItem::COMPLETE, download2->state()); 1179 ASSERT_EQ(DownloadItem::COMPLETE, download2->state());
1531 // The download shelf should be open. 1180 // The download shelf should be open.
1532 CheckDownloadUI(browser(), true, true, FilePath()); 1181 CheckDownloadUI(browser(), true, true, FilePath());
1533 1182
1534 // Allow the first request to finish. We do this by loading a third URL 1183 // Allow the first request to finish. We do this by loading a third URL
1535 // in a separate tab. 1184 // in a separate tab.
1536 scoped_ptr<DownloadsObserver> observer2(CreateWaiter(browser(), 1)); 1185 scoped_ptr<DownloadTestObserver> observer2(CreateWaiter(browser(), 1));
1537 GURL finish_url(URLRequestSlowDownloadJob::kFinishDownloadUrl); 1186 GURL finish_url(URLRequestSlowDownloadJob::kFinishDownloadUrl);
1538 ui_test_utils::NavigateToURLWithDisposition( 1187 ui_test_utils::NavigateToURLWithDisposition(
1539 browser(), 1188 browser(),
1540 finish_url, 1189 finish_url,
1541 NEW_FOREGROUND_TAB, 1190 NEW_FOREGROUND_TAB,
1542 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 1191 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1543 observer2->WaitForFinished(); // Wait for the third request. 1192 observer2->WaitForFinished(); // Wait for the third request.
1544 1193
1545 // Get the important info from other threads and check it. 1194 // Get the important info from other threads and check it.
1546 scoped_refptr<CancelTestDataCollector> info(new CancelTestDataCollector()); 1195 scoped_refptr<CancelTestDataCollector> info(new CancelTestDataCollector());
(...skipping 14 matching lines...) Expand all
1561 1210
1562 FilePath file2(download2->full_path()); 1211 FilePath file2(download2->full_path());
1563 ASSERT_TRUE(file_util::ContentsEqual(OriginFile(file), file2)); 1212 ASSERT_TRUE(file_util::ContentsEqual(OriginFile(file), file2));
1564 } 1213 }
1565 1214
1566 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadCancelled) { 1215 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadCancelled) {
1567 ASSERT_TRUE(InitialSetup(false)); 1216 ASSERT_TRUE(InitialSetup(false));
1568 EXPECT_EQ(1, browser()->tab_count()); 1217 EXPECT_EQ(1, browser()->tab_count());
1569 1218
1570 // TODO(rdsmith): Fragile code warning! The code below relies on the 1219 // TODO(rdsmith): Fragile code warning! The code below relies on the
1571 // DownloadsObserver only finishing when the new download has reached 1220 // DownloadTestObserver only finishing when the new download has reached
1572 // the state of being entered into the history and being user-visible 1221 // the state of being entered into the history and being user-visible
1573 // (that's what's required for the Remove to be valid and for the 1222 // (that's what's required for the Remove to be valid and for the
1574 // download shelf to be visible). By the pure semantics of 1223 // download shelf to be visible). By the pure semantics of
1575 // DownloadsObserver, that's not guaranteed; DownloadItems are created 1224 // DownloadTestObserver, that's not guaranteed; DownloadItems are created
1576 // in the IN_PROGRESS state and made known to the DownloadManager 1225 // in the IN_PROGRESS state and made known to the DownloadManager
1577 // immediately, so any ModelChanged event on the DownloadManager after 1226 // immediately, so any ModelChanged event on the DownloadManager after
1578 // navigation would allow the observer to return. However, the only 1227 // navigation would allow the observer to return. However, the only
1579 // ModelChanged() event the code will currently fire is in 1228 // ModelChanged() event the code will currently fire is in
1580 // OnCreateDownloadEntryComplete, at which point the download item will 1229 // OnCreateDownloadEntryComplete, at which point the download item will
1581 // be in the state we need. 1230 // be in the state we need.
1582 // The right way to fix this is to create finer grained states on the 1231 // The right way to fix this is to create finer grained states on the
1583 // DownloadItem, and wait for the state that indicates the item has been 1232 // DownloadItem, and wait for the state that indicates the item has been
1584 // entered in the history and made visible in the UI. 1233 // entered in the history and made visible in the UI.
1585 1234
1586 // Create a download, wait until it's started, and confirm 1235 // Create a download, wait until it's started, and confirm
1587 // we're in the expected state. 1236 // we're in the expected state.
1588 scoped_ptr<DownloadsObserver> observer( 1237 scoped_ptr<DownloadTestObserver> observer(
1589 CreateInProgressWaiter(browser(), 1)); 1238 CreateInProgressWaiter(browser(), 1));
1590 ui_test_utils::NavigateToURL( 1239 ui_test_utils::NavigateToURL(
1591 browser(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); 1240 browser(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl));
1592 observer->WaitForFinished(); 1241 observer->WaitForFinished();
1593 1242
1594 std::vector<DownloadItem*> downloads; 1243 std::vector<DownloadItem*> downloads;
1595 DownloadManagerForBrowser(browser())->SearchDownloads( 1244 DownloadManagerForBrowser(browser())->SearchDownloads(
1596 string16(), &downloads); 1245 string16(), &downloads);
1597 ASSERT_EQ(1u, downloads.size()); 1246 ASSERT_EQ(1u, downloads.size());
1598 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->state()); 1247 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->state());
1599 CheckDownloadUI(browser(), true, true, FilePath()); 1248 CheckDownloadUI(browser(), true, true, FilePath());
1600 1249
1601 // Cancel the download and wait for download system quiesce. 1250 // Cancel the download and wait for download system quiesce.
1602 downloads[0]->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); 1251 downloads[0]->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD);
1603 scoped_refptr<DownloadsFlushObserver> flush_observer( 1252 scoped_refptr<DownloadTestFlushObserver> flush_observer(
1604 new DownloadsFlushObserver(DownloadManagerForBrowser(browser()))); 1253 new DownloadTestFlushObserver(
1254 DownloadManagerForBrowser(browser())));
1605 flush_observer->WaitForFlush(); 1255 flush_observer->WaitForFlush();
1606 1256
1607 // Get the important info from other threads and check it. 1257 // Get the important info from other threads and check it.
1608 scoped_refptr<CancelTestDataCollector> info(new CancelTestDataCollector()); 1258 scoped_refptr<CancelTestDataCollector> info(new CancelTestDataCollector());
1609 info->WaitForDataCollected(); 1259 info->WaitForDataCollected();
1610 EXPECT_EQ(0, info->rdh_pending_requests()); 1260 EXPECT_EQ(0, info->rdh_pending_requests());
1611 EXPECT_EQ(0, info->dfm_pending_downloads()); 1261 EXPECT_EQ(0, info->dfm_pending_downloads());
1612 1262
1613 // Using "DownloadItem::Remove" follows the discard dangerous download path, 1263 // Using "DownloadItem::Remove" follows the discard dangerous download path,
1614 // which completely removes the browser from the shelf and closes the shelf 1264 // which completely removes the browser from the shelf and closes the shelf
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1708 } 1358 }
1709 1359
1710 // Test to make sure the 'download' attribute in anchor tag is respected. 1360 // Test to make sure the 'download' attribute in anchor tag is respected.
1711 IN_PROC_BROWSER_TEST_F(DownloadTest, AnchorDownloadTag) { 1361 IN_PROC_BROWSER_TEST_F(DownloadTest, AnchorDownloadTag) {
1712 ASSERT_TRUE(InitialSetup(false)); 1362 ASSERT_TRUE(InitialSetup(false));
1713 FilePath file(FILE_PATH_LITERAL("download-anchor-attrib.html")); 1363 FilePath file(FILE_PATH_LITERAL("download-anchor-attrib.html"));
1714 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1364 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1715 1365
1716 // Create a download, wait until it's complete, and confirm 1366 // Create a download, wait until it's complete, and confirm
1717 // we're in the expected state. 1367 // we're in the expected state.
1718 scoped_ptr<DownloadsObserver> observer(CreateWaiter(browser(), 1)); 1368 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser(), 1));
1719 ui_test_utils::NavigateToURL(browser(), url); 1369 ui_test_utils::NavigateToURL(browser(), url);
1720 observer->WaitForFinished(); 1370 observer->WaitForFinished();
1721 1371
1722 // Confirm the downloaded data exists. 1372 // Confirm the downloaded data exists.
1723 FilePath downloaded_file = GetDownloadDirectory(browser()); 1373 FilePath downloaded_file = GetDownloadDirectory(browser());
1724 downloaded_file = downloaded_file.Append(FILE_PATH_LITERAL("a_red_dot.png")); 1374 downloaded_file = downloaded_file.Append(FILE_PATH_LITERAL("a_red_dot.png"));
1725 EXPECT_TRUE(file_util::PathExists(downloaded_file)); 1375 EXPECT_TRUE(file_util::PathExists(downloaded_file));
1726 } 1376 }
1727 1377
1728 // Test to make sure auto-open works. 1378 // Test to make sure auto-open works.
(...skipping 25 matching lines...) Expand all
1754 // Download shelf should close. Download panel stays open on ChromeOS. 1404 // Download shelf should close. Download panel stays open on ChromeOS.
1755 CheckDownloadUI(browser(), false, true, FilePath()); 1405 CheckDownloadUI(browser(), false, true, FilePath());
1756 } 1406 }
1757 1407
1758 // Download an extension. Expect a dangerous download warning. 1408 // Download an extension. Expect a dangerous download warning.
1759 // Deny the download. 1409 // Deny the download.
1760 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxDenyInstall) { 1410 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxDenyInstall) {
1761 ASSERT_TRUE(InitialSetup(false)); 1411 ASSERT_TRUE(InitialSetup(false));
1762 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); 1412 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath));
1763 1413
1764 scoped_ptr<DownloadsObserver> observer( 1414 scoped_ptr<DownloadTestObserver> observer(
1765 DangerousInstallWaiter(browser(), 1415 DangerousInstallWaiter(
1766 1, 1416 browser(), 1, DownloadItem::CANCELLED,
1767 DownloadItem::CANCELLED, 1417 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY));
1768 ON_DANGEROUS_DOWNLOAD_DENY));
1769 ui_test_utils::NavigateToURL(browser(), extension_url); 1418 ui_test_utils::NavigateToURL(browser(), extension_url);
1770 1419
1771 observer->WaitForFinished(); 1420 observer->WaitForFinished();
1772 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); 1421 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
1773 1422
1774 // Download shelf should close. Download panel stays open on ChromeOS. 1423 // Download shelf should close. Download panel stays open on ChromeOS.
1775 CheckDownloadUI(browser(), false, true, FilePath()); 1424 CheckDownloadUI(browser(), false, true, FilePath());
1776 1425
1777 // Check that the CRX is not installed. 1426 // Check that the CRX is not installed.
1778 ExtensionService* extension_service = 1427 ExtensionService* extension_service =
1779 browser()->profile()->GetExtensionService(); 1428 browser()->profile()->GetExtensionService();
1780 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); 1429 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false));
1781 } 1430 }
1782 1431
1783 // Download an extension. Expect a dangerous download warning. 1432 // Download an extension. Expect a dangerous download warning.
1784 // Allow the download, deny the install. 1433 // Allow the download, deny the install.
1785 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) { 1434 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) {
1786 ASSERT_TRUE(InitialSetup(false)); 1435 ASSERT_TRUE(InitialSetup(false));
1787 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); 1436 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath));
1788 1437
1789 // Install a mock install UI that simulates a user denying permission to 1438 // Install a mock install UI that simulates a user denying permission to
1790 // finish the install. 1439 // finish the install.
1791 download_crx_util::SetMockInstallUIForTesting( 1440 download_crx_util::SetMockInstallUIForTesting(
1792 new MockAbortExtensionInstallUI()); 1441 new MockAbortExtensionInstallUI());
1793 1442
1794 scoped_ptr<DownloadsObserver> observer( 1443 scoped_ptr<DownloadTestObserver> observer(
1795 DangerousInstallWaiter(browser(), 1444 DangerousInstallWaiter(
1796 1, 1445 browser(), 1, DownloadItem::COMPLETE,
1797 DownloadItem::COMPLETE, 1446 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
1798 ON_DANGEROUS_DOWNLOAD_ACCEPT));
1799 ui_test_utils::NavigateToURL(browser(), extension_url); 1447 ui_test_utils::NavigateToURL(browser(), extension_url);
1800 1448
1801 observer->WaitForFinished(); 1449 observer->WaitForFinished();
1802 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); 1450 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
1803 1451
1804 // Download shelf should close. Download panel stays open on ChromeOS. 1452 // Download shelf should close. Download panel stays open on ChromeOS.
1805 CheckDownloadUI(browser(), false, true, FilePath()); 1453 CheckDownloadUI(browser(), false, true, FilePath());
1806 1454
1807 // Check that the extension was not installed. 1455 // Check that the extension was not installed.
1808 ExtensionService* extension_service = 1456 ExtensionService* extension_service =
1809 browser()->profile()->GetExtensionService(); 1457 browser()->profile()->GetExtensionService();
1810 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); 1458 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false));
1811 } 1459 }
1812 1460
1813 // Download an extension. Expect a dangerous download warning. 1461 // Download an extension. Expect a dangerous download warning.
1814 // Allow the download, and the install. 1462 // Allow the download, and the install.
1815 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) { 1463 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) {
1816 ASSERT_TRUE(InitialSetup(false)); 1464 ASSERT_TRUE(InitialSetup(false));
1817 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); 1465 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath));
1818 1466
1819 // Install a mock install UI that simulates a user allowing permission to 1467 // Install a mock install UI that simulates a user allowing permission to
1820 // finish the install. 1468 // finish the install.
1821 download_crx_util::SetMockInstallUIForTesting( 1469 download_crx_util::SetMockInstallUIForTesting(
1822 new MockAutoConfirmExtensionInstallUI(browser()->profile())); 1470 new MockAutoConfirmExtensionInstallUI(browser()->profile()));
1823 1471
1824 scoped_ptr<DownloadsObserver> observer( 1472 scoped_ptr<DownloadTestObserver> observer(
1825 DangerousInstallWaiter(browser(), 1473 DangerousInstallWaiter(
1826 1, 1474 browser(), 1, DownloadItem::COMPLETE,
1827 DownloadItem::COMPLETE, 1475 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
1828 ON_DANGEROUS_DOWNLOAD_ACCEPT));
1829 ui_test_utils::NavigateToURL(browser(), extension_url); 1476 ui_test_utils::NavigateToURL(browser(), extension_url);
1830 1477
1831 observer->WaitForFinished(); 1478 observer->WaitForFinished();
1832 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); 1479 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
1833 1480
1834 // Download shelf should close. Download panel stays open on ChromeOS. 1481 // Download shelf should close. Download panel stays open on ChromeOS.
1835 CheckDownloadUI(browser(), false, true, FilePath()); 1482 CheckDownloadUI(browser(), false, true, FilePath());
1836 1483
1837 // Check that the extension was installed. 1484 // Check that the extension was installed.
1838 ExtensionService* extension_service = 1485 ExtensionService* extension_service =
1839 browser()->profile()->GetExtensionService(); 1486 browser()->profile()->GetExtensionService();
1840 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); 1487 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false));
1841 } 1488 }
1842 1489
1843 // Test installing a CRX that fails integrity checks. 1490 // Test installing a CRX that fails integrity checks.
1844 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { 1491 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) {
1845 ASSERT_TRUE(InitialSetup(false)); 1492 ASSERT_TRUE(InitialSetup(false));
1846 FilePath file(FILE_PATH_LITERAL("extensions/bad_signature.crx")); 1493 FilePath file(FILE_PATH_LITERAL("extensions/bad_signature.crx"));
1847 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(file)); 1494 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(file));
1848 1495
1849 // Install a mock install UI that simulates a user allowing permission to 1496 // Install a mock install UI that simulates a user allowing permission to
1850 // finish the install, and dismisses any error message. We check that the 1497 // finish the install, and dismisses any error message. We check that the
1851 // install failed below. 1498 // install failed below.
1852 download_crx_util::SetMockInstallUIForTesting( 1499 download_crx_util::SetMockInstallUIForTesting(
1853 new MockAutoConfirmExtensionInstallUI(browser()->profile())); 1500 new MockAutoConfirmExtensionInstallUI(browser()->profile()));
1854 1501
1855 scoped_ptr<DownloadsObserver> observer( 1502 scoped_ptr<DownloadTestObserver> observer(
1856 DangerousInstallWaiter(browser(), 1503 DangerousInstallWaiter(
1857 1, 1504 browser(), 1, DownloadItem::COMPLETE,
1858 DownloadItem::COMPLETE, 1505 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
1859 ON_DANGEROUS_DOWNLOAD_ACCEPT));
1860 ui_test_utils::NavigateToURL(browser(), extension_url); 1506 ui_test_utils::NavigateToURL(browser(), extension_url);
1861 1507
1862 observer->WaitForFinished(); 1508 observer->WaitForFinished();
1863 1509
1864 // Check that the extension was not installed. 1510 // Check that the extension was not installed.
1865 ExtensionService* extension_service = 1511 ExtensionService* extension_service =
1866 browser()->profile()->GetExtensionService(); 1512 browser()->profile()->GetExtensionService();
1867 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); 1513 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false));
1868 } 1514 }
1869 1515
1870 // Install a large (100kb) theme. 1516 // Install a large (100kb) theme.
1871 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) { 1517 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) {
1872 ASSERT_TRUE(InitialSetup(false)); 1518 ASSERT_TRUE(InitialSetup(false));
1873 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kLargeThemePath)); 1519 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kLargeThemePath));
1874 1520
1875 // Install a mock install UI that simulates a user allowing permission to 1521 // Install a mock install UI that simulates a user allowing permission to
1876 // finish the install. 1522 // finish the install.
1877 download_crx_util::SetMockInstallUIForTesting( 1523 download_crx_util::SetMockInstallUIForTesting(
1878 new MockAutoConfirmExtensionInstallUI(browser()->profile())); 1524 new MockAutoConfirmExtensionInstallUI(browser()->profile()));
1879 1525
1880 scoped_ptr<DownloadsObserver> observer( 1526 scoped_ptr<DownloadTestObserver> observer(
1881 DangerousInstallWaiter(browser(), 1527 DangerousInstallWaiter(
1882 1, 1528 browser(), 1, DownloadItem::COMPLETE,
1883 DownloadItem::COMPLETE, 1529 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
1884 ON_DANGEROUS_DOWNLOAD_ACCEPT));
1885 ui_test_utils::NavigateToURL(browser(), extension_url); 1530 ui_test_utils::NavigateToURL(browser(), extension_url);
1886 1531
1887 observer->WaitForFinished(); 1532 observer->WaitForFinished();
1888 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); 1533 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
1889 1534
1890 // Download shelf should close. Download panel stays open on ChromeOS. 1535 // Download shelf should close. Download panel stays open on ChromeOS.
1891 CheckDownloadUI(browser(), false, true, FilePath()); 1536 CheckDownloadUI(browser(), false, true, FilePath());
1892 1537
1893 // Check that the extension was installed. 1538 // Check that the extension was installed.
1894 ExtensionService* extension_service = 1539 ExtensionService* extension_service =
1895 browser()->profile()->GetExtensionService(); 1540 browser()->profile()->GetExtensionService();
1896 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); 1541 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false));
1897 } 1542 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/download/download_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698