OLD | NEW |
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/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "base/test/test_file_util.h" | 13 #include "base/test/test_file_util.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 16 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
17 #include "chrome/browser/download/download_crx_util.h" | 17 #include "chrome/browser/download/download_crx_util.h" |
18 #include "chrome/browser/download/download_history.h" | 18 #include "chrome/browser/download/download_history.h" |
19 #include "chrome/browser/download/download_prefs.h" | 19 #include "chrome/browser/download/download_prefs.h" |
20 #include "chrome/browser/download/download_service.h" | 20 #include "chrome/browser/download/download_service.h" |
21 #include "chrome/browser/download/download_service_factory.h" | 21 #include "chrome/browser/download/download_service_factory.h" |
22 #include "chrome/browser/download/download_shelf.h" | 22 #include "chrome/browser/download/download_shelf.h" |
| 23 #include "chrome/browser/download/download_test_observer.h" |
23 #include "chrome/browser/download/download_util.h" | 24 #include "chrome/browser/download/download_util.h" |
24 #include "chrome/browser/extensions/extension_install_ui.h" | 25 #include "chrome/browser/extensions/extension_install_ui.h" |
25 #include "chrome/browser/extensions/extension_service.h" | 26 #include "chrome/browser/extensions/extension_service.h" |
26 #include "chrome/browser/history/history.h" | 27 #include "chrome/browser/history/history.h" |
27 #include "chrome/browser/net/url_request_mock_util.h" | 28 #include "chrome/browser/net/url_request_mock_util.h" |
28 #include "chrome/browser/prefs/pref_service.h" | 29 #include "chrome/browser/prefs/pref_service.h" |
29 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
30 #include "chrome/browser/ui/browser.h" | 31 #include "chrome/browser/ui/browser.h" |
31 #include "chrome/browser/ui/browser_list.h" | 32 #include "chrome/browser/ui/browser_list.h" |
32 #include "chrome/browser/ui/browser_window.h" | 33 #include "chrome/browser/ui/browser_window.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 76 |
76 // Fake user click on "Deny". | 77 // Fake user click on "Deny". |
77 void DenyDangerousDownload(scoped_refptr<DownloadManager> download_manager, | 78 void DenyDangerousDownload(scoped_refptr<DownloadManager> download_manager, |
78 int32 download_id) { | 79 int32 download_id) { |
79 DownloadItem* download = download_manager->GetDownloadItem(download_id); | 80 DownloadItem* download = download_manager->GetDownloadItem(download_id); |
80 ASSERT_TRUE(download->IsPartialDownload()); | 81 ASSERT_TRUE(download->IsPartialDownload()); |
81 download->Cancel(true); | 82 download->Cancel(true); |
82 download->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); | 83 download->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); |
83 } | 84 } |
84 | 85 |
85 // Construction of this class defines a system state, based on some number | |
86 // of downloads being seen in a particular state + other events that | |
87 // may occur in the download system. That state will be recorded if it | |
88 // occurs at any point after construction. When that state occurs, the class | |
89 // is considered finished. Callers may either probe for the finished state, or | |
90 // wait on it. | |
91 // | |
92 // TODO(rdsmith): Detect manager going down, remove pointer to | |
93 // DownloadManager, transition to finished. (For right now we | |
94 // just use a scoped_refptr<> to keep it around, but that may cause | |
95 // timeouts on waiting if a DownloadManager::Shutdown() occurs which | |
96 // cancels our in-progress downloads.) | |
97 class DownloadsObserver : public DownloadManager::Observer, | |
98 public DownloadItem::Observer { | |
99 public: | |
100 // Create an object that will be considered finished when |wait_count| | |
101 // download items have entered state |download_finished_state|. | |
102 // If |finish_on_select_file| is true, the object will also be | |
103 // considered finished if the DownloadManager raises a | |
104 // SelectFileDialogDisplayed() notification. | |
105 | |
106 // TODO(rdsmith): Consider rewriting the interface to take a list of events | |
107 // to treat as completion events. | |
108 DownloadsObserver(DownloadManager* download_manager, | |
109 size_t wait_count, | |
110 DownloadItem::DownloadState download_finished_state, | |
111 bool finish_on_select_file, | |
112 DangerousDownloadAction dangerous_download_action) | |
113 : download_manager_(download_manager), | |
114 wait_count_(wait_count), | |
115 finished_downloads_at_construction_(0), | |
116 waiting_(false), | |
117 download_finished_state_(download_finished_state), | |
118 finish_on_select_file_(finish_on_select_file), | |
119 select_file_dialog_seen_(false), | |
120 dangerous_download_action_(dangerous_download_action) { | |
121 download_manager_->AddObserver(this); // Will call initial ModelChanged(). | |
122 finished_downloads_at_construction_ = finished_downloads_.size(); | |
123 EXPECT_NE(DownloadItem::REMOVING, download_finished_state) | |
124 << "Waiting for REMOVING is not supported. Try COMPLETE."; | |
125 } | |
126 | |
127 ~DownloadsObserver() { | |
128 std::set<DownloadItem*>::iterator it = downloads_observed_.begin(); | |
129 for (; it != downloads_observed_.end(); ++it) | |
130 (*it)->RemoveObserver(this); | |
131 | |
132 download_manager_->RemoveObserver(this); | |
133 } | |
134 | |
135 // State accessors. | |
136 bool select_file_dialog_seen() { return select_file_dialog_seen_; } | |
137 | |
138 // Wait for whatever state was specified in the constructor. | |
139 void WaitForFinished() { | |
140 if (!IsFinished()) { | |
141 waiting_ = true; | |
142 ui_test_utils::RunMessageLoop(); | |
143 waiting_ = false; | |
144 } | |
145 } | |
146 | |
147 // Return true if everything's happened that we're configured for. | |
148 bool IsFinished() { | |
149 if (finished_downloads_.size() - finished_downloads_at_construction_ | |
150 >= wait_count_) | |
151 return true; | |
152 return (finish_on_select_file_ && select_file_dialog_seen_); | |
153 } | |
154 | |
155 // DownloadItem::Observer | |
156 virtual void OnDownloadUpdated(DownloadItem* download) { | |
157 // The REMOVING state indicates that the download is being destroyed. | |
158 // Stop observing. Do not do anything with it, as it is about to be gone. | |
159 if (download->state() == DownloadItem::REMOVING) { | |
160 std::set<DownloadItem*>::iterator it = downloads_observed_.find(download); | |
161 ASSERT_TRUE(it != downloads_observed_.end()); | |
162 downloads_observed_.erase(it); | |
163 download->RemoveObserver(this); | |
164 return; | |
165 } | |
166 | |
167 // Real UI code gets the user's response after returning from the observer. | |
168 if (download->safety_state() == DownloadItem::DANGEROUS && | |
169 !ContainsKey(dangerous_downloads_seen_, download->id())) { | |
170 dangerous_downloads_seen_.insert(download->id()); | |
171 | |
172 // Calling DangerousDownloadValidated() at this point will | |
173 // cause the download to be completed twice. Do what the real UI | |
174 // code does: make the call as a delayed task. | |
175 switch (dangerous_download_action_) { | |
176 case ON_DANGEROUS_DOWNLOAD_ACCEPT: | |
177 // Fake user click on "Accept". Delay the actual click, as the | |
178 // real UI would. | |
179 BrowserThread::PostTask( | |
180 BrowserThread::UI, FROM_HERE, | |
181 base::Bind(&AcceptDangerousDownload, download_manager_, | |
182 download->id())); | |
183 break; | |
184 | |
185 case ON_DANGEROUS_DOWNLOAD_DENY: | |
186 // Fake a user click on "Deny". Delay the actual click, as the | |
187 // real UI would. | |
188 BrowserThread::PostTask( | |
189 BrowserThread::UI, FROM_HERE, | |
190 base::Bind(&DenyDangerousDownload, download_manager_, | |
191 download->id())); | |
192 break; | |
193 | |
194 case ON_DANGEROUS_DOWNLOAD_FAIL: | |
195 ADD_FAILURE() << "Unexpected dangerous download item."; | |
196 break; | |
197 | |
198 default: | |
199 NOTREACHED(); | |
200 } | |
201 } | |
202 | |
203 if (download->state() == download_finished_state_) | |
204 DownloadInFinalState(download); | |
205 } | |
206 | |
207 virtual void OnDownloadOpened(DownloadItem* download) {} | |
208 | |
209 // DownloadManager::Observer | |
210 virtual void ModelChanged() { | |
211 // Regenerate DownloadItem observers. If there are any download items | |
212 // in our final state, note them in |finished_downloads_| | |
213 // (done by |OnDownloadUpdated()|). | |
214 std::vector<DownloadItem*> downloads; | |
215 download_manager_->GetAllDownloads(FilePath(), &downloads); | |
216 | |
217 std::vector<DownloadItem*>::iterator it = downloads.begin(); | |
218 for (; it != downloads.end(); ++it) { | |
219 OnDownloadUpdated(*it); // Safe to call multiple times; checks state. | |
220 | |
221 std::set<DownloadItem*>::const_iterator | |
222 finished_it(finished_downloads_.find(*it)); | |
223 std::set<DownloadItem*>::iterator | |
224 observed_it(downloads_observed_.find(*it)); | |
225 | |
226 // If it isn't finished and we're aren't observing it, start. | |
227 if (finished_it == finished_downloads_.end() && | |
228 observed_it == downloads_observed_.end()) { | |
229 (*it)->AddObserver(this); | |
230 downloads_observed_.insert(*it); | |
231 continue; | |
232 } | |
233 | |
234 // If it is finished and we are observing it, stop. | |
235 if (finished_it != finished_downloads_.end() && | |
236 observed_it != downloads_observed_.end()) { | |
237 (*it)->RemoveObserver(this); | |
238 downloads_observed_.erase(observed_it); | |
239 continue; | |
240 } | |
241 } | |
242 } | |
243 | |
244 virtual void SelectFileDialogDisplayed(int32 /* id */) { | |
245 select_file_dialog_seen_ = true; | |
246 SignalIfFinished(); | |
247 } | |
248 | |
249 virtual size_t NumDangerousDownloadsSeen() const { | |
250 return dangerous_downloads_seen_.size(); | |
251 } | |
252 | |
253 private: | |
254 // Called when we know that a download item is in a final state. | |
255 // Note that this is not the same as it first transitioning in to the | |
256 // final state; multiple notifications may occur once the item is in | |
257 // that state. So we keep our own track of transitions into final. | |
258 void DownloadInFinalState(DownloadItem* download) { | |
259 if (finished_downloads_.find(download) != finished_downloads_.end()) { | |
260 // We've already seen terminal state on this download. | |
261 return; | |
262 } | |
263 | |
264 // Record the transition. | |
265 finished_downloads_.insert(download); | |
266 | |
267 SignalIfFinished(); | |
268 } | |
269 | |
270 void SignalIfFinished() { | |
271 if (waiting_ && IsFinished()) | |
272 MessageLoopForUI::current()->Quit(); | |
273 } | |
274 | |
275 // The observed download manager. | |
276 scoped_refptr<DownloadManager> download_manager_; | |
277 | |
278 // The set of DownloadItem's that have transitioned to their finished state | |
279 // since construction of this object. When the size of this array | |
280 // reaches wait_count_, we're done. | |
281 std::set<DownloadItem*> finished_downloads_; | |
282 | |
283 // The set of DownloadItem's we are currently observing. Generally there | |
284 // won't be any overlap with the above; once we see the final state | |
285 // on a DownloadItem, we'll stop observing it. | |
286 std::set<DownloadItem*> downloads_observed_; | |
287 | |
288 // The number of downloads to wait on completing. | |
289 size_t wait_count_; | |
290 | |
291 // The number of downloads entered in final state in initial | |
292 // ModelChanged(). We use |finished_downloads_| to track the incoming | |
293 // transitions to final state we should ignore, and to track the | |
294 // number of final state transitions that occurred between | |
295 // construction and return from wait. But some downloads may be in our | |
296 // final state (and thus be entered into |finished_downloads_|) when we | |
297 // construct this class. We don't want to count those in our transition | |
298 // to finished. | |
299 int finished_downloads_at_construction_; | |
300 | |
301 // Whether an internal message loop has been started and must be quit upon | |
302 // all downloads completing. | |
303 bool waiting_; | |
304 | |
305 // The state on which to consider the DownloadItem finished. | |
306 DownloadItem::DownloadState download_finished_state_; | |
307 | |
308 // True if we should transition the DownloadsObserver to finished if | |
309 // the select file dialog comes up. | |
310 bool finish_on_select_file_; | |
311 | |
312 // True if we've seen the select file dialog. | |
313 bool select_file_dialog_seen_; | |
314 | |
315 // Action to take if a dangerous download is encountered. | |
316 DangerousDownloadAction dangerous_download_action_; | |
317 | |
318 // Holds the download ids which were dangerous. | |
319 std::set<int32> dangerous_downloads_seen_; | |
320 | |
321 DISALLOW_COPY_AND_ASSIGN(DownloadsObserver); | |
322 }; | |
323 | |
324 // WaitForFlush() returns after: | |
325 // * There are no IN_PROGRESS download items remaining on the | |
326 // DownloadManager. | |
327 // * There have been two round trip messages through the file and | |
328 // IO threads. | |
329 // This almost certainly means that a Download cancel has propagated through | |
330 // the system. | |
331 class DownloadsFlushObserver | |
332 : public DownloadManager::Observer, | |
333 public DownloadItem::Observer, | |
334 public base::RefCountedThreadSafe<DownloadsFlushObserver> { | |
335 public: | |
336 explicit DownloadsFlushObserver(DownloadManager* download_manager) | |
337 : download_manager_(download_manager), | |
338 waiting_for_zero_inprogress_(true) {} | |
339 | |
340 void WaitForFlush() { | |
341 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
342 download_manager_->AddObserver(this); | |
343 ui_test_utils::RunMessageLoop(); | |
344 } | |
345 | |
346 // DownloadsManager observer methods. | |
347 virtual void ModelChanged() { | |
348 // Model has changed, so there may be more DownloadItems to observe. | |
349 CheckDownloadsInProgress(true); | |
350 } | |
351 | |
352 // DownloadItem observer methods. | |
353 virtual void OnDownloadUpdated(DownloadItem* download) { | |
354 // No change in DownloadItem set on manager. | |
355 CheckDownloadsInProgress(false); | |
356 } | |
357 virtual void OnDownloadOpened(DownloadItem* download) {} | |
358 | |
359 protected: | |
360 friend class base::RefCountedThreadSafe<DownloadsFlushObserver>; | |
361 | |
362 virtual ~DownloadsFlushObserver() { | |
363 download_manager_->RemoveObserver(this); | |
364 for (std::set<DownloadItem*>::iterator it = downloads_observed_.begin(); | |
365 it != downloads_observed_.end(); ++it) { | |
366 (*it)->RemoveObserver(this); | |
367 } | |
368 } | |
369 | |
370 private: | |
371 // If we're waiting for that flush point, check the number | |
372 // of downloads in the IN_PROGRESS state and take appropriate | |
373 // action. If requested, also observes all downloads while iterating. | |
374 void CheckDownloadsInProgress(bool observe_downloads) { | |
375 if (waiting_for_zero_inprogress_) { | |
376 int count = 0; | |
377 | |
378 std::vector<DownloadItem*> downloads; | |
379 download_manager_->SearchDownloads(string16(), &downloads); | |
380 std::vector<DownloadItem*>::iterator it = downloads.begin(); | |
381 for (; it != downloads.end(); ++it) { | |
382 if ((*it)->state() == DownloadItem::IN_PROGRESS) | |
383 count++; | |
384 if (observe_downloads) { | |
385 if (downloads_observed_.find(*it) == downloads_observed_.end()) { | |
386 (*it)->AddObserver(this); | |
387 } | |
388 // Download items are forever, and we don't want to make | |
389 // assumptions about future state transitions, so once we | |
390 // start observing them, we don't stop until destruction. | |
391 } | |
392 } | |
393 | |
394 if (count == 0) { | |
395 waiting_for_zero_inprogress_ = false; | |
396 // Stop observing DownloadItems. We maintain the observation | |
397 // of DownloadManager so that we don't have to independently track | |
398 // whether we are observing it for conditional destruction. | |
399 for (std::set<DownloadItem*>::iterator it = downloads_observed_.begin(); | |
400 it != downloads_observed_.end(); ++it) { | |
401 (*it)->RemoveObserver(this); | |
402 } | |
403 downloads_observed_.clear(); | |
404 | |
405 // Trigger next step. We need to go past the IO thread twice, as | |
406 // there's a self-task posting in the IO thread cancel path. | |
407 BrowserThread::PostTask( | |
408 BrowserThread::FILE, FROM_HERE, | |
409 base::Bind(&DownloadsFlushObserver::PingFileThread, this, 2)); | |
410 } | |
411 } | |
412 } | |
413 | |
414 void PingFileThread(int cycle) { | |
415 BrowserThread::PostTask( | |
416 BrowserThread::IO, FROM_HERE, | |
417 base::Bind(&DownloadsFlushObserver::PingIOThread, this, cycle)); | |
418 } | |
419 | |
420 void PingIOThread(int cycle) { | |
421 if (--cycle) { | |
422 BrowserThread::PostTask( | |
423 BrowserThread::UI, FROM_HERE, | |
424 base::Bind(&DownloadsFlushObserver::PingFileThread, this, cycle)); | |
425 } else { | |
426 BrowserThread::PostTask( | |
427 BrowserThread::UI, FROM_HERE, new MessageLoop::QuitTask()); | |
428 } | |
429 } | |
430 | |
431 DownloadManager* download_manager_; | |
432 std::set<DownloadItem*> downloads_observed_; | |
433 bool waiting_for_zero_inprogress_; | |
434 | |
435 DISALLOW_COPY_AND_ASSIGN(DownloadsFlushObserver); | |
436 }; | |
437 | |
438 // Collect the information from FILE and IO threads needed for the Cancel | 86 // Collect the information from FILE and IO threads needed for the Cancel |
439 // Test, specifically the number of outstanding requests on the | 87 // Test, specifically the number of outstanding requests on the |
440 // ResourceDispatcherHost and the number of pending downloads on the | 88 // ResourceDispatcherHost and the number of pending downloads on the |
441 // DownloadFileManager. | 89 // DownloadFileManager. |
442 class CancelTestDataCollector | 90 class CancelTestDataCollector |
443 : public base::RefCountedThreadSafe<CancelTestDataCollector> { | 91 : public base::RefCountedThreadSafe<CancelTestDataCollector> { |
444 public: | 92 public: |
445 CancelTestDataCollector() | 93 CancelTestDataCollector() |
446 : resource_dispatcher_host_( | 94 : resource_dispatcher_host_( |
447 g_browser_process->resource_dispatcher_host()), | 95 g_browser_process->resource_dispatcher_host()), |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 | 358 |
711 DownloadPrefs* GetDownloadPrefs(Browser* browser) { | 359 DownloadPrefs* GetDownloadPrefs(Browser* browser) { |
712 return DownloadPrefs::FromDownloadManager( | 360 return DownloadPrefs::FromDownloadManager( |
713 DownloadManagerForBrowser(browser)); | 361 DownloadManagerForBrowser(browser)); |
714 } | 362 } |
715 | 363 |
716 FilePath GetDownloadDirectory(Browser* browser) { | 364 FilePath GetDownloadDirectory(Browser* browser) { |
717 return GetDownloadPrefs(browser)->download_path(); | 365 return GetDownloadPrefs(browser)->download_path(); |
718 } | 366 } |
719 | 367 |
720 // Create a DownloadsObserver that will wait for the | 368 // Create a DownloadTestObserver that will wait for the |
721 // specified number of downloads to finish. | 369 // specified number of downloads to finish. |
722 DownloadsObserver* CreateWaiter(Browser* browser, int num_downloads) { | 370 DownloadTestObserver* CreateWaiter(Browser* browser, int num_downloads) { |
723 DownloadManager* download_manager = DownloadManagerForBrowser(browser); | 371 DownloadManager* download_manager = DownloadManagerForBrowser(browser); |
724 return new DownloadsObserver( | 372 return new DownloadTestObserver( |
725 download_manager, num_downloads, | 373 download_manager, num_downloads, |
726 DownloadItem::COMPLETE, // Really done | 374 DownloadItem::COMPLETE, // Really done |
727 true, // Bail on select file | 375 true, // Bail on select file |
728 ON_DANGEROUS_DOWNLOAD_FAIL); | 376 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); |
729 } | 377 } |
730 | 378 |
731 // Create a DownloadsObserver that will wait for the | 379 // Create a DownloadTestObserver that will wait for the |
732 // specified number of downloads to start. | 380 // specified number of downloads to start. |
733 DownloadsObserver* CreateInProgressWaiter(Browser* browser, | 381 DownloadTestObserver* CreateInProgressWaiter(Browser* browser, |
734 int num_downloads) { | 382 int num_downloads) { |
735 DownloadManager* download_manager = DownloadManagerForBrowser(browser); | 383 DownloadManager* download_manager = DownloadManagerForBrowser(browser); |
736 return new DownloadsObserver( | 384 return new DownloadTestObserver( |
737 download_manager, num_downloads, | 385 download_manager, num_downloads, |
738 DownloadItem::IN_PROGRESS, // Has started | 386 DownloadItem::IN_PROGRESS, // Has started |
739 true, // Bail on select file | 387 true, // Bail on select file |
740 ON_DANGEROUS_DOWNLOAD_FAIL); | 388 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); |
741 } | 389 } |
742 | 390 |
743 // Create a DownloadsObserver that will wait for the | 391 // Create a DownloadTestObserver that will wait for the |
744 // specified number of downloads to finish, or for | 392 // specified number of downloads to finish, or for |
745 // a dangerous download warning to be shown. | 393 // a dangerous download warning to be shown. |
746 DownloadsObserver* DangerousInstallWaiter( | 394 DownloadTestObserver* DangerousInstallWaiter( |
747 Browser* browser, | 395 Browser* browser, |
748 int num_downloads, | 396 int num_downloads, |
749 DownloadItem::DownloadState final_state, | 397 DownloadItem::DownloadState final_state, |
750 DangerousDownloadAction dangerous_download_action) { | 398 DownloadTestObserver::DangerousDownloadAction dangerous_download_action) { |
751 DownloadManager* download_manager = DownloadManagerForBrowser(browser); | 399 DownloadManager* download_manager = DownloadManagerForBrowser(browser); |
752 return new DownloadsObserver( | 400 return new DownloadTestObserver( |
753 download_manager, num_downloads, | 401 download_manager, num_downloads, |
754 final_state, | 402 final_state, |
755 true, // Bail on select file | 403 true, // Bail on select file |
756 dangerous_download_action); | 404 dangerous_download_action); |
757 } | 405 } |
758 | 406 |
759 // Download |url|, then wait for the download to finish. | 407 // Download |url|, then wait for the download to finish. |
760 // |disposition| indicates where the navigation occurs (current tab, new | 408 // |disposition| indicates where the navigation occurs (current tab, new |
761 // foreground tab, etc). | 409 // foreground tab, etc). |
762 // |expectation| indicates whether or not a Select File dialog should be | 410 // |expectation| indicates whether or not a Select File dialog should be |
763 // open when the download is finished, or if we don't care. | 411 // open when the download is finished, or if we don't care. |
764 // If the dialog appears, the routine exits. The only effect |expectation| | 412 // If the dialog appears, the routine exits. The only effect |expectation| |
765 // has is whether or not the test succeeds. | 413 // has is whether or not the test succeeds. |
766 // |browser_test_flags| indicate what to wait for, and is an OR of 0 or more | 414 // |browser_test_flags| indicate what to wait for, and is an OR of 0 or more |
767 // values in the ui_test_utils::BrowserTestWaitFlags enum. | 415 // values in the ui_test_utils::BrowserTestWaitFlags enum. |
768 void DownloadAndWaitWithDisposition(Browser* browser, | 416 void DownloadAndWaitWithDisposition(Browser* browser, |
769 const GURL& url, | 417 const GURL& url, |
770 WindowOpenDisposition disposition, | 418 WindowOpenDisposition disposition, |
771 SelectExpectation expectation, | 419 SelectExpectation expectation, |
772 int browser_test_flags) { | 420 int browser_test_flags) { |
773 // Setup notification, navigate, and block. | 421 // Setup notification, navigate, and block. |
774 scoped_ptr<DownloadsObserver> observer(CreateWaiter(browser, 1)); | 422 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser, 1)); |
775 // This call will block until the condition specified by | 423 // This call will block until the condition specified by |
776 // |browser_test_flags|, but will not wait for the download to finish. | 424 // |browser_test_flags|, but will not wait for the download to finish. |
777 ui_test_utils::NavigateToURLWithDisposition(browser, | 425 ui_test_utils::NavigateToURLWithDisposition(browser, |
778 url, | 426 url, |
779 disposition, | 427 disposition, |
780 browser_test_flags); | 428 browser_test_flags); |
781 // Waits for the download to complete. | 429 // Waits for the download to complete. |
782 observer->WaitForFinished(); | 430 observer->WaitForFinished(); |
783 | 431 |
784 // If specified, check the state of the select file dialog. | 432 // If specified, check the state of the select file dialog. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
855 // |expected_title_finished| need to be checked. | 503 // |expected_title_finished| need to be checked. |
856 FilePath filename; | 504 FilePath filename; |
857 net::FileURLToFilePath(url, &filename); | 505 net::FileURLToFilePath(url, &filename); |
858 string16 expected_title_in_progress( | 506 string16 expected_title_in_progress( |
859 ASCIIToUTF16(partial_indication) + filename.LossyDisplayName()); | 507 ASCIIToUTF16(partial_indication) + filename.LossyDisplayName()); |
860 string16 expected_title_finished( | 508 string16 expected_title_finished( |
861 ASCIIToUTF16(total_indication) + filename.LossyDisplayName()); | 509 ASCIIToUTF16(total_indication) + filename.LossyDisplayName()); |
862 | 510 |
863 // Download a partial web page in a background tab and wait. | 511 // Download a partial web page in a background tab and wait. |
864 // The mock system will not complete until it gets a special URL. | 512 // The mock system will not complete until it gets a special URL. |
865 scoped_ptr<DownloadsObserver> observer(CreateWaiter(browser, 1)); | 513 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser, 1)); |
866 ui_test_utils::NavigateToURL(browser, url); | 514 ui_test_utils::NavigateToURL(browser, url); |
867 | 515 |
868 // TODO(ahendrickson): check download status text before downloading. | 516 // TODO(ahendrickson): check download status text before downloading. |
869 // Need to: | 517 // Need to: |
870 // - Add a member function to the |DownloadShelf| interface class, that | 518 // - Add a member function to the |DownloadShelf| interface class, that |
871 // indicates how many members it has. | 519 // indicates how many members it has. |
872 // - Add a member function to |DownloadShelf| to get the status text | 520 // - Add a member function to |DownloadShelf| to get the status text |
873 // of a given member (for example, via the name in |DownloadItemView|'s | 521 // of a given member (for example, via the name in |DownloadItemView|'s |
874 // GetAccessibleState() member function), by index. | 522 // GetAccessibleState() member function), by index. |
875 // - Iterate over browser->window()->GetDownloadShelf()'s members | 523 // - Iterate over browser->window()->GetDownloadShelf()'s members |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1030 // downloads preferences settings. | 678 // downloads preferences settings. |
1031 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeTypeSelect) { | 679 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeTypeSelect) { |
1032 ASSERT_TRUE(InitialSetup(true)); | 680 ASSERT_TRUE(InitialSetup(true)); |
1033 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 681 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1034 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 682 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1035 | 683 |
1036 NullSelectFile(browser()); | 684 NullSelectFile(browser()); |
1037 | 685 |
1038 // Download the file and wait. We expect the Select File dialog to appear | 686 // Download the file and wait. We expect the Select File dialog to appear |
1039 // due to the MIME type, but we still wait until the download completes. | 687 // due to the MIME type, but we still wait until the download completes. |
1040 scoped_ptr<DownloadsObserver> observer( | 688 scoped_ptr<DownloadTestObserver> observer( |
1041 new DownloadsObserver( | 689 new DownloadTestObserver( |
1042 DownloadManagerForBrowser(browser()), | 690 DownloadManagerForBrowser(browser()), |
1043 1, | 691 1, |
1044 DownloadItem::COMPLETE, // Really done | 692 DownloadItem::COMPLETE, // Really done |
1045 false, // Continue on select file. | 693 false, // Continue on select file. |
1046 ON_DANGEROUS_DOWNLOAD_FAIL)); | 694 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
1047 ui_test_utils::NavigateToURLWithDisposition( | 695 ui_test_utils::NavigateToURLWithDisposition( |
1048 browser(), url, CURRENT_TAB, | 696 browser(), url, CURRENT_TAB, |
1049 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 697 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
1050 observer->WaitForFinished(); | 698 observer->WaitForFinished(); |
1051 EXPECT_TRUE(observer->select_file_dialog_seen()); | 699 EXPECT_TRUE(observer->select_file_dialog_seen()); |
1052 | 700 |
1053 // Check state. | 701 // Check state. |
1054 EXPECT_EQ(1, browser()->tab_count()); | 702 EXPECT_EQ(1, browser()->tab_count()); |
1055 CheckDownload(browser(), file, file); | 703 CheckDownload(browser(), file, file); |
1056 CheckDownloadUI(browser(), true, true, file); | 704 CheckDownloadUI(browser(), true, true, file); |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1454 CheckDownloadUI(browser(), false, true, file); | 1102 CheckDownloadUI(browser(), false, true, file); |
1455 | 1103 |
1456 CheckDownload(browser(), file, file); | 1104 CheckDownload(browser(), file, file); |
1457 } | 1105 } |
1458 | 1106 |
1459 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadCancelled) { | 1107 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadCancelled) { |
1460 ASSERT_TRUE(InitialSetup(false)); | 1108 ASSERT_TRUE(InitialSetup(false)); |
1461 EXPECT_EQ(1, browser()->tab_count()); | 1109 EXPECT_EQ(1, browser()->tab_count()); |
1462 | 1110 |
1463 // TODO(rdsmith): Fragile code warning! The code below relies on the | 1111 // TODO(rdsmith): Fragile code warning! The code below relies on the |
1464 // DownloadsObserver only finishing when the new download has reached | 1112 // DownloadTestObserver only finishing when the new download has reached |
1465 // the state of being entered into the history and being user-visible | 1113 // the state of being entered into the history and being user-visible |
1466 // (that's what's required for the Remove to be valid and for the | 1114 // (that's what's required for the Remove to be valid and for the |
1467 // download shelf to be visible). By the pure semantics of | 1115 // download shelf to be visible). By the pure semantics of |
1468 // DownloadsObserver, that's not guaranteed; DownloadItems are created | 1116 // DownloadTestObserver, that's not guaranteed; DownloadItems are created |
1469 // in the IN_PROGRESS state and made known to the DownloadManager | 1117 // in the IN_PROGRESS state and made known to the DownloadManager |
1470 // immediately, so any ModelChanged event on the DownloadManager after | 1118 // immediately, so any ModelChanged event on the DownloadManager after |
1471 // navigation would allow the observer to return. However, the only | 1119 // navigation would allow the observer to return. However, the only |
1472 // ModelChanged() event the code will currently fire is in | 1120 // ModelChanged() event the code will currently fire is in |
1473 // OnCreateDownloadEntryComplete, at which point the download item will | 1121 // OnCreateDownloadEntryComplete, at which point the download item will |
1474 // be in the state we need. | 1122 // be in the state we need. |
1475 // The right way to fix this is to create finer grained states on the | 1123 // The right way to fix this is to create finer grained states on the |
1476 // DownloadItem, and wait for the state that indicates the item has been | 1124 // DownloadItem, and wait for the state that indicates the item has been |
1477 // entered in the history and made visible in the UI. | 1125 // entered in the history and made visible in the UI. |
1478 | 1126 |
1479 // Create a download, wait until it's started, and confirm | 1127 // Create a download, wait until it's started, and confirm |
1480 // we're in the expected state. | 1128 // we're in the expected state. |
1481 scoped_ptr<DownloadsObserver> observer( | 1129 scoped_ptr<DownloadTestObserver> observer( |
1482 CreateInProgressWaiter(browser(), 1)); | 1130 CreateInProgressWaiter(browser(), 1)); |
1483 ui_test_utils::NavigateToURL( | 1131 ui_test_utils::NavigateToURL( |
1484 browser(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); | 1132 browser(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); |
1485 observer->WaitForFinished(); | 1133 observer->WaitForFinished(); |
1486 | 1134 |
1487 std::vector<DownloadItem*> downloads; | 1135 std::vector<DownloadItem*> downloads; |
1488 DownloadManagerForBrowser(browser())->SearchDownloads( | 1136 DownloadManagerForBrowser(browser())->SearchDownloads( |
1489 string16(), &downloads); | 1137 string16(), &downloads); |
1490 ASSERT_EQ(1u, downloads.size()); | 1138 ASSERT_EQ(1u, downloads.size()); |
1491 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->state()); | 1139 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->state()); |
1492 CheckDownloadUI(browser(), true, true, FilePath()); | 1140 CheckDownloadUI(browser(), true, true, FilePath()); |
1493 | 1141 |
1494 // Cancel the download and wait for download system quiesce. | 1142 // Cancel the download and wait for download system quiesce. |
1495 downloads[0]->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); | 1143 downloads[0]->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); |
1496 scoped_refptr<DownloadsFlushObserver> flush_observer( | 1144 scoped_refptr<DownloadTestFlushObserver> flush_observer( |
1497 new DownloadsFlushObserver(DownloadManagerForBrowser(browser()))); | 1145 new DownloadTestFlushObserver( |
| 1146 DownloadManagerForBrowser(browser()))); |
1498 flush_observer->WaitForFlush(); | 1147 flush_observer->WaitForFlush(); |
1499 | 1148 |
1500 // Get the important info from other threads and check it. | 1149 // Get the important info from other threads and check it. |
1501 scoped_refptr<CancelTestDataCollector> info(new CancelTestDataCollector()); | 1150 scoped_refptr<CancelTestDataCollector> info(new CancelTestDataCollector()); |
1502 info->WaitForDataCollected(); | 1151 info->WaitForDataCollected(); |
1503 EXPECT_EQ(0, info->rdh_pending_requests()); | 1152 EXPECT_EQ(0, info->rdh_pending_requests()); |
1504 EXPECT_EQ(0, info->dfm_pending_downloads()); | 1153 EXPECT_EQ(0, info->dfm_pending_downloads()); |
1505 | 1154 |
1506 // Using "DownloadItem::Remove" follows the discard dangerous download path, | 1155 // Using "DownloadItem::Remove" follows the discard dangerous download path, |
1507 // which completely removes the browser from the shelf and closes the shelf | 1156 // which completely removes the browser from the shelf and closes the shelf |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1601 } | 1250 } |
1602 | 1251 |
1603 // Test to make sure the 'download' attribute in anchor tag is respected. | 1252 // Test to make sure the 'download' attribute in anchor tag is respected. |
1604 IN_PROC_BROWSER_TEST_F(DownloadTest, AnchorDownloadTag) { | 1253 IN_PROC_BROWSER_TEST_F(DownloadTest, AnchorDownloadTag) { |
1605 ASSERT_TRUE(InitialSetup(false)); | 1254 ASSERT_TRUE(InitialSetup(false)); |
1606 FilePath file(FILE_PATH_LITERAL("download-anchor-attrib.html")); | 1255 FilePath file(FILE_PATH_LITERAL("download-anchor-attrib.html")); |
1607 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1256 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1608 | 1257 |
1609 // Create a download, wait until it's complete, and confirm | 1258 // Create a download, wait until it's complete, and confirm |
1610 // we're in the expected state. | 1259 // we're in the expected state. |
1611 scoped_ptr<DownloadsObserver> observer(CreateWaiter(browser(), 1)); | 1260 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser(), 1)); |
1612 ui_test_utils::NavigateToURL(browser(), url); | 1261 ui_test_utils::NavigateToURL(browser(), url); |
1613 observer->WaitForFinished(); | 1262 observer->WaitForFinished(); |
1614 | 1263 |
1615 // Confirm the downloaded data exists. | 1264 // Confirm the downloaded data exists. |
1616 FilePath downloaded_file = GetDownloadDirectory(browser()); | 1265 FilePath downloaded_file = GetDownloadDirectory(browser()); |
1617 downloaded_file = downloaded_file.Append(FILE_PATH_LITERAL("a_red_dot.png")); | 1266 downloaded_file = downloaded_file.Append(FILE_PATH_LITERAL("a_red_dot.png")); |
1618 EXPECT_TRUE(file_util::PathExists(downloaded_file)); | 1267 EXPECT_TRUE(file_util::PathExists(downloaded_file)); |
1619 } | 1268 } |
1620 | 1269 |
1621 // Test to make sure auto-open works. | 1270 // Test to make sure auto-open works. |
(...skipping 25 matching lines...) Expand all Loading... |
1647 // Download shelf should close. Download panel stays open on ChromeOS. | 1296 // Download shelf should close. Download panel stays open on ChromeOS. |
1648 CheckDownloadUI(browser(), false, true, FilePath()); | 1297 CheckDownloadUI(browser(), false, true, FilePath()); |
1649 } | 1298 } |
1650 | 1299 |
1651 // Download an extension. Expect a dangerous download warning. | 1300 // Download an extension. Expect a dangerous download warning. |
1652 // Deny the download. | 1301 // Deny the download. |
1653 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxDenyInstall) { | 1302 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxDenyInstall) { |
1654 ASSERT_TRUE(InitialSetup(false)); | 1303 ASSERT_TRUE(InitialSetup(false)); |
1655 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); | 1304 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); |
1656 | 1305 |
1657 scoped_ptr<DownloadsObserver> observer( | 1306 scoped_ptr<DownloadTestObserver> observer( |
1658 DangerousInstallWaiter(browser(), | 1307 DangerousInstallWaiter( |
1659 1, | 1308 browser(), 1, DownloadItem::CANCELLED, |
1660 DownloadItem::CANCELLED, | 1309 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); |
1661 ON_DANGEROUS_DOWNLOAD_DENY)); | |
1662 ui_test_utils::NavigateToURL(browser(), extension_url); | 1310 ui_test_utils::NavigateToURL(browser(), extension_url); |
1663 | 1311 |
1664 observer->WaitForFinished(); | 1312 observer->WaitForFinished(); |
1665 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1313 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
1666 | 1314 |
1667 // Download shelf should close. Download panel stays open on ChromeOS. | 1315 // Download shelf should close. Download panel stays open on ChromeOS. |
1668 CheckDownloadUI(browser(), false, true, FilePath()); | 1316 CheckDownloadUI(browser(), false, true, FilePath()); |
1669 | 1317 |
1670 // Check that the CRX is not installed. | 1318 // Check that the CRX is not installed. |
1671 ExtensionService* extension_service = | 1319 ExtensionService* extension_service = |
1672 browser()->profile()->GetExtensionService(); | 1320 browser()->profile()->GetExtensionService(); |
1673 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1321 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); |
1674 } | 1322 } |
1675 | 1323 |
1676 // Download an extension. Expect a dangerous download warning. | 1324 // Download an extension. Expect a dangerous download warning. |
1677 // Allow the download, deny the install. | 1325 // Allow the download, deny the install. |
1678 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) { | 1326 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) { |
1679 ASSERT_TRUE(InitialSetup(false)); | 1327 ASSERT_TRUE(InitialSetup(false)); |
1680 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); | 1328 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); |
1681 | 1329 |
1682 // Install a mock install UI that simulates a user denying permission to | 1330 // Install a mock install UI that simulates a user denying permission to |
1683 // finish the install. | 1331 // finish the install. |
1684 download_crx_util::SetMockInstallUIForTesting( | 1332 download_crx_util::SetMockInstallUIForTesting( |
1685 new MockAbortExtensionInstallUI()); | 1333 new MockAbortExtensionInstallUI()); |
1686 | 1334 |
1687 scoped_ptr<DownloadsObserver> observer( | 1335 scoped_ptr<DownloadTestObserver> observer( |
1688 DangerousInstallWaiter(browser(), | 1336 DangerousInstallWaiter( |
1689 1, | 1337 browser(), 1, DownloadItem::COMPLETE, |
1690 DownloadItem::COMPLETE, | 1338 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
1691 ON_DANGEROUS_DOWNLOAD_ACCEPT)); | |
1692 ui_test_utils::NavigateToURL(browser(), extension_url); | 1339 ui_test_utils::NavigateToURL(browser(), extension_url); |
1693 | 1340 |
1694 observer->WaitForFinished(); | 1341 observer->WaitForFinished(); |
1695 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1342 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
1696 | 1343 |
1697 // Download shelf should close. Download panel stays open on ChromeOS. | 1344 // Download shelf should close. Download panel stays open on ChromeOS. |
1698 CheckDownloadUI(browser(), false, true, FilePath()); | 1345 CheckDownloadUI(browser(), false, true, FilePath()); |
1699 | 1346 |
1700 // Check that the extension was not installed. | 1347 // Check that the extension was not installed. |
1701 ExtensionService* extension_service = | 1348 ExtensionService* extension_service = |
1702 browser()->profile()->GetExtensionService(); | 1349 browser()->profile()->GetExtensionService(); |
1703 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1350 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); |
1704 } | 1351 } |
1705 | 1352 |
1706 // Download an extension. Expect a dangerous download warning. | 1353 // Download an extension. Expect a dangerous download warning. |
1707 // Allow the download, and the install. | 1354 // Allow the download, and the install. |
1708 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) { | 1355 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) { |
1709 ASSERT_TRUE(InitialSetup(false)); | 1356 ASSERT_TRUE(InitialSetup(false)); |
1710 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); | 1357 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); |
1711 | 1358 |
1712 // Install a mock install UI that simulates a user allowing permission to | 1359 // Install a mock install UI that simulates a user allowing permission to |
1713 // finish the install. | 1360 // finish the install. |
1714 download_crx_util::SetMockInstallUIForTesting( | 1361 download_crx_util::SetMockInstallUIForTesting( |
1715 new MockAutoConfirmExtensionInstallUI(browser()->profile())); | 1362 new MockAutoConfirmExtensionInstallUI(browser()->profile())); |
1716 | 1363 |
1717 scoped_ptr<DownloadsObserver> observer( | 1364 scoped_ptr<DownloadTestObserver> observer( |
1718 DangerousInstallWaiter(browser(), | 1365 DangerousInstallWaiter( |
1719 1, | 1366 browser(), 1, DownloadItem::COMPLETE, |
1720 DownloadItem::COMPLETE, | 1367 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
1721 ON_DANGEROUS_DOWNLOAD_ACCEPT)); | |
1722 ui_test_utils::NavigateToURL(browser(), extension_url); | 1368 ui_test_utils::NavigateToURL(browser(), extension_url); |
1723 | 1369 |
1724 observer->WaitForFinished(); | 1370 observer->WaitForFinished(); |
1725 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1371 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
1726 | 1372 |
1727 // Download shelf should close. Download panel stays open on ChromeOS. | 1373 // Download shelf should close. Download panel stays open on ChromeOS. |
1728 CheckDownloadUI(browser(), false, true, FilePath()); | 1374 CheckDownloadUI(browser(), false, true, FilePath()); |
1729 | 1375 |
1730 // Check that the extension was installed. | 1376 // Check that the extension was installed. |
1731 ExtensionService* extension_service = | 1377 ExtensionService* extension_service = |
1732 browser()->profile()->GetExtensionService(); | 1378 browser()->profile()->GetExtensionService(); |
1733 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1379 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); |
1734 } | 1380 } |
1735 | 1381 |
1736 // Test installing a CRX that fails integrity checks. | 1382 // Test installing a CRX that fails integrity checks. |
1737 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { | 1383 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { |
1738 ASSERT_TRUE(InitialSetup(false)); | 1384 ASSERT_TRUE(InitialSetup(false)); |
1739 FilePath file(FILE_PATH_LITERAL("extensions/bad_signature.crx")); | 1385 FilePath file(FILE_PATH_LITERAL("extensions/bad_signature.crx")); |
1740 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1386 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1741 | 1387 |
1742 // Install a mock install UI that simulates a user allowing permission to | 1388 // Install a mock install UI that simulates a user allowing permission to |
1743 // finish the install, and dismisses any error message. We check that the | 1389 // finish the install, and dismisses any error message. We check that the |
1744 // install failed below. | 1390 // install failed below. |
1745 download_crx_util::SetMockInstallUIForTesting( | 1391 download_crx_util::SetMockInstallUIForTesting( |
1746 new MockAutoConfirmExtensionInstallUI(browser()->profile())); | 1392 new MockAutoConfirmExtensionInstallUI(browser()->profile())); |
1747 | 1393 |
1748 scoped_ptr<DownloadsObserver> observer( | 1394 scoped_ptr<DownloadTestObserver> observer( |
1749 DangerousInstallWaiter(browser(), | 1395 DangerousInstallWaiter( |
1750 1, | 1396 browser(), 1, DownloadItem::COMPLETE, |
1751 DownloadItem::COMPLETE, | 1397 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
1752 ON_DANGEROUS_DOWNLOAD_ACCEPT)); | |
1753 ui_test_utils::NavigateToURL(browser(), extension_url); | 1398 ui_test_utils::NavigateToURL(browser(), extension_url); |
1754 | 1399 |
1755 observer->WaitForFinished(); | 1400 observer->WaitForFinished(); |
1756 | 1401 |
1757 // Check that the extension was not installed. | 1402 // Check that the extension was not installed. |
1758 ExtensionService* extension_service = | 1403 ExtensionService* extension_service = |
1759 browser()->profile()->GetExtensionService(); | 1404 browser()->profile()->GetExtensionService(); |
1760 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1405 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); |
1761 } | 1406 } |
1762 | 1407 |
1763 // Install a large (100kb) theme. | 1408 // Install a large (100kb) theme. |
1764 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) { | 1409 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) { |
1765 ASSERT_TRUE(InitialSetup(false)); | 1410 ASSERT_TRUE(InitialSetup(false)); |
1766 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kLargeThemePath)); | 1411 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kLargeThemePath)); |
1767 | 1412 |
1768 // Install a mock install UI that simulates a user allowing permission to | 1413 // Install a mock install UI that simulates a user allowing permission to |
1769 // finish the install. | 1414 // finish the install. |
1770 download_crx_util::SetMockInstallUIForTesting( | 1415 download_crx_util::SetMockInstallUIForTesting( |
1771 new MockAutoConfirmExtensionInstallUI(browser()->profile())); | 1416 new MockAutoConfirmExtensionInstallUI(browser()->profile())); |
1772 | 1417 |
1773 scoped_ptr<DownloadsObserver> observer( | 1418 scoped_ptr<DownloadTestObserver> observer( |
1774 DangerousInstallWaiter(browser(), | 1419 DangerousInstallWaiter( |
1775 1, | 1420 browser(), 1, DownloadItem::COMPLETE, |
1776 DownloadItem::COMPLETE, | 1421 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
1777 ON_DANGEROUS_DOWNLOAD_ACCEPT)); | |
1778 ui_test_utils::NavigateToURL(browser(), extension_url); | 1422 ui_test_utils::NavigateToURL(browser(), extension_url); |
1779 | 1423 |
1780 observer->WaitForFinished(); | 1424 observer->WaitForFinished(); |
1781 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1425 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
1782 | 1426 |
1783 // Download shelf should close. Download panel stays open on ChromeOS. | 1427 // Download shelf should close. Download panel stays open on ChromeOS. |
1784 CheckDownloadUI(browser(), false, true, FilePath()); | 1428 CheckDownloadUI(browser(), false, true, FilePath()); |
1785 | 1429 |
1786 // Check that the extension was installed. | 1430 // Check that the extension was installed. |
1787 ExtensionService* extension_service = | 1431 ExtensionService* extension_service = |
1788 browser()->profile()->GetExtensionService(); | 1432 browser()->profile()->GetExtensionService(); |
1789 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); | 1433 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); |
1790 } | 1434 } |
OLD | NEW |