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/file_path.h" | 5 #include "base/file_path.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/scoped_temp_dir.h" | 9 #include "base/scoped_temp_dir.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "base/test/test_file_util.h" | 11 #include "base/test/test_file_util.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/download/download_crx_util.h" | 14 #include "chrome/browser/download/download_crx_util.h" |
15 #include "chrome/browser/download/download_file_manager.h" | 15 #include "chrome/browser/download/download_file_manager.h" |
16 #include "chrome/browser/download/download_history.h" | 16 #include "chrome/browser/download/download_history.h" |
17 #include "chrome/browser/download/download_item.h" | 17 #include "chrome/browser/download/download_item.h" |
18 #include "chrome/browser/download/download_manager.h" | 18 #include "chrome/browser/download/download_manager.h" |
19 #include "chrome/browser/download/download_prefs.h" | 19 #include "chrome/browser/download/download_prefs.h" |
20 #include "chrome/browser/download/download_shelf.h" | 20 #include "chrome/browser/download/download_shelf.h" |
| 21 #include "chrome/browser/download/download_test_observer.h" |
21 #include "chrome/browser/download/download_util.h" | 22 #include "chrome/browser/download/download_util.h" |
22 #include "chrome/browser/extensions/extension_install_ui.h" | 23 #include "chrome/browser/extensions/extension_install_ui.h" |
23 #include "chrome/browser/extensions/extension_service.h" | 24 #include "chrome/browser/extensions/extension_service.h" |
24 #include "chrome/browser/history/download_history_info.h" | 25 #include "chrome/browser/history/download_history_info.h" |
25 #include "chrome/browser/history/history.h" | 26 #include "chrome/browser/history/history.h" |
26 #include "chrome/browser/prefs/pref_service.h" | 27 #include "chrome/browser/prefs/pref_service.h" |
27 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
28 #include "chrome/browser/ui/browser.h" | 29 #include "chrome/browser/ui/browser.h" |
29 #include "chrome/browser/ui/browser_list.h" | 30 #include "chrome/browser/ui/browser_list.h" |
30 #include "chrome/browser/ui/browser_window.h" | 31 #include "chrome/browser/ui/browser_window.h" |
(...skipping 15 matching lines...) Expand all Loading... |
46 | 47 |
47 namespace { | 48 namespace { |
48 | 49 |
49 // IDs and paths of CRX files used in tests. | 50 // IDs and paths of CRX files used in tests. |
50 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; | 51 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
51 const FilePath kGoodCrxPath(FILE_PATH_LITERAL("extensions/good.crx")); | 52 const FilePath kGoodCrxPath(FILE_PATH_LITERAL("extensions/good.crx")); |
52 | 53 |
53 const char kLargeThemeCrxId[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; | 54 const char kLargeThemeCrxId[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; |
54 const FilePath kLargeThemePath(FILE_PATH_LITERAL("extensions/theme2.crx")); | 55 const FilePath kLargeThemePath(FILE_PATH_LITERAL("extensions/theme2.crx")); |
55 | 56 |
56 // Action a test should take if a dangerous download is encountered. | |
57 enum DangerousDownloadAction { | |
58 ON_DANGEROUS_DOWNLOAD_ACCEPT, // Accept the download | |
59 ON_DANGEROUS_DOWNLOAD_DENY, // Deny the download | |
60 ON_DANGEROUS_DOWNLOAD_FAIL // Fail if a dangerous download is seen | |
61 }; | |
62 | |
63 // Fake user click on "Accept". | |
64 void AcceptDangerousDownload(scoped_refptr<DownloadManager> download_manager, | |
65 int32 download_id) { | |
66 DownloadItem* download = download_manager->GetDownloadItem(download_id); | |
67 download->DangerousDownloadValidated(); | |
68 } | |
69 | |
70 // Fake user click on "Deny". | |
71 void DenyDangerousDownload(scoped_refptr<DownloadManager> download_manager, | |
72 int32 download_id) { | |
73 DownloadItem* download = download_manager->GetDownloadItem(download_id); | |
74 ASSERT_TRUE(download->IsPartialDownload()); | |
75 download->Cancel(true); | |
76 download->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); | |
77 } | |
78 | |
79 // Construction of this class defines a system state, based on some number | |
80 // of downloads being seen in a particular state + other events that | |
81 // may occur in the download system. That state will be recorded if it | |
82 // occurs at any point after construction. When that state occurs, the class | |
83 // is considered finished. Callers may either probe for the finished state, or | |
84 // wait on it. | |
85 // | |
86 // TODO(rdsmith): Detect manager going down, remove pointer to | |
87 // DownloadManager, transition to finished. (For right now we | |
88 // just use a scoped_refptr<> to keep it around, but that may cause | |
89 // timeouts on waiting if a DownloadManager::Shutdown() occurs which | |
90 // cancels our in-progress downloads.) | |
91 class DownloadsObserver : public DownloadManager::Observer, | |
92 public DownloadItem::Observer { | |
93 public: | |
94 // Create an object that will be considered finished when |wait_count| | |
95 // download items have entered state |download_finished_state|. | |
96 // If |finish_on_select_file| is true, the object will also be | |
97 // considered finished if the DownloadManager raises a | |
98 // SelectFileDialogDisplayed() notification. | |
99 | |
100 // TODO(rdsmith): Consider rewriting the interface to take a list of events | |
101 // to treat as completion events. | |
102 DownloadsObserver(DownloadManager* download_manager, | |
103 size_t wait_count, | |
104 DownloadItem::DownloadState download_finished_state, | |
105 bool finish_on_select_file, | |
106 DangerousDownloadAction dangerous_download_action) | |
107 : download_manager_(download_manager), | |
108 wait_count_(wait_count), | |
109 finished_downloads_at_construction_(0), | |
110 waiting_(false), | |
111 download_finished_state_(download_finished_state), | |
112 finish_on_select_file_(finish_on_select_file), | |
113 select_file_dialog_seen_(false), | |
114 dangerous_download_action_(dangerous_download_action) { | |
115 download_manager_->AddObserver(this); // Will call initial ModelChanged(). | |
116 finished_downloads_at_construction_ = finished_downloads_.size(); | |
117 EXPECT_NE(DownloadItem::REMOVING, download_finished_state) | |
118 << "Waiting for REMOVING is not supported. Try COMPLETE."; | |
119 } | |
120 | |
121 ~DownloadsObserver() { | |
122 std::set<DownloadItem*>::iterator it = downloads_observed_.begin(); | |
123 for (; it != downloads_observed_.end(); ++it) | |
124 (*it)->RemoveObserver(this); | |
125 | |
126 download_manager_->RemoveObserver(this); | |
127 } | |
128 | |
129 // State accessors. | |
130 bool select_file_dialog_seen() { return select_file_dialog_seen_; } | |
131 | |
132 // Wait for whatever state was specified in the constructor. | |
133 void WaitForFinished() { | |
134 if (!IsFinished()) { | |
135 waiting_ = true; | |
136 ui_test_utils::RunMessageLoop(); | |
137 waiting_ = false; | |
138 } | |
139 } | |
140 | |
141 // Return true if everything's happened that we're configured for. | |
142 bool IsFinished() { | |
143 if (finished_downloads_.size() - finished_downloads_at_construction_ | |
144 >= wait_count_) | |
145 return true; | |
146 return (finish_on_select_file_ && select_file_dialog_seen_); | |
147 } | |
148 | |
149 // DownloadItem::Observer | |
150 virtual void OnDownloadUpdated(DownloadItem* download) { | |
151 // The REMOVING state indicates that the download is being destroyed. | |
152 // Stop observing. Do not do anything with it, as it is about to be gone. | |
153 if (download->state() == DownloadItem::REMOVING) { | |
154 std::set<DownloadItem*>::iterator it = downloads_observed_.find(download); | |
155 ASSERT_TRUE(it != downloads_observed_.end()); | |
156 downloads_observed_.erase(it); | |
157 download->RemoveObserver(this); | |
158 return; | |
159 } | |
160 | |
161 // Real UI code gets the user's response after returning from the observer. | |
162 if (download->safety_state() == DownloadItem::DANGEROUS && | |
163 !ContainsKey(dangerous_downloads_seen_, download->id())) { | |
164 dangerous_downloads_seen_.insert(download->id()); | |
165 | |
166 // Calling DangerousDownloadValidated() at this point will | |
167 // cause the download to be completed twice. Do what the real UI | |
168 // code does: make the call as a delayed task. | |
169 switch (dangerous_download_action_) { | |
170 case ON_DANGEROUS_DOWNLOAD_ACCEPT: | |
171 // Fake user click on "Accept". Delay the actual click, as the | |
172 // real UI would. | |
173 BrowserThread::PostTask( | |
174 BrowserThread::UI, FROM_HERE, | |
175 NewRunnableFunction( | |
176 &AcceptDangerousDownload, | |
177 download_manager_, | |
178 download->id())); | |
179 break; | |
180 | |
181 case ON_DANGEROUS_DOWNLOAD_DENY: | |
182 // Fake a user click on "Deny". Delay the actual click, as the | |
183 // real UI would. | |
184 BrowserThread::PostTask( | |
185 BrowserThread::UI, FROM_HERE, | |
186 NewRunnableFunction( | |
187 &DenyDangerousDownload, | |
188 download_manager_, | |
189 download->id())); | |
190 break; | |
191 | |
192 case ON_DANGEROUS_DOWNLOAD_FAIL: | |
193 ADD_FAILURE() << "Unexpected dangerous download item."; | |
194 break; | |
195 | |
196 default: | |
197 NOTREACHED(); | |
198 } | |
199 } | |
200 | |
201 if (download->state() == download_finished_state_) { | |
202 DownloadInFinalState(download); | |
203 } | |
204 } | |
205 | |
206 virtual void OnDownloadOpened(DownloadItem* download) {} | |
207 | |
208 // DownloadManager::Observer | |
209 virtual void ModelChanged() { | |
210 // Regenerate DownloadItem observers. If there are any download items | |
211 // in our final state, note them in |finished_downloads_| | |
212 // (done by |OnDownloadUpdated()|). | |
213 std::vector<DownloadItem*> downloads; | |
214 download_manager_->GetAllDownloads(FilePath(), &downloads); | |
215 | |
216 std::vector<DownloadItem*>::iterator it = downloads.begin(); | |
217 for (; it != downloads.end(); ++it) { | |
218 OnDownloadUpdated(*it); // Safe to call multiple times; checks state. | |
219 | |
220 std::set<DownloadItem*>::const_iterator | |
221 finished_it(finished_downloads_.find(*it)); | |
222 std::set<DownloadItem*>::iterator | |
223 observed_it(downloads_observed_.find(*it)); | |
224 | |
225 // If it isn't finished and we're aren't observing it, start. | |
226 if (finished_it == finished_downloads_.end() && | |
227 observed_it == downloads_observed_.end()) { | |
228 (*it)->AddObserver(this); | |
229 downloads_observed_.insert(*it); | |
230 continue; | |
231 } | |
232 | |
233 // If it is finished and we are observing it, stop. | |
234 if (finished_it != finished_downloads_.end() && | |
235 observed_it != downloads_observed_.end()) { | |
236 (*it)->RemoveObserver(this); | |
237 downloads_observed_.erase(observed_it); | |
238 continue; | |
239 } | |
240 } | |
241 } | |
242 | |
243 virtual void SelectFileDialogDisplayed(int32 /* id */) { | |
244 select_file_dialog_seen_ = true; | |
245 SignalIfFinished(); | |
246 } | |
247 | |
248 virtual size_t NumDangerousDownloadsSeen() const { | |
249 return dangerous_downloads_seen_.size(); | |
250 } | |
251 | |
252 private: | |
253 // Called when we know that a download item is in a final state. | |
254 // Note that this is not the same as it first transitioning in to the | |
255 // final state; multiple notifications may occur once the item is in | |
256 // that state. So we keep our own track of transitions into final. | |
257 void DownloadInFinalState(DownloadItem* download) { | |
258 if (finished_downloads_.find(download) != finished_downloads_.end()) { | |
259 // We've already seen terminal state on this download. | |
260 return; | |
261 } | |
262 | |
263 // Record the transition. | |
264 finished_downloads_.insert(download); | |
265 | |
266 SignalIfFinished(); | |
267 } | |
268 | |
269 void SignalIfFinished() { | |
270 if (waiting_ && IsFinished()) | |
271 MessageLoopForUI::current()->Quit(); | |
272 } | |
273 | |
274 // The observed download manager. | |
275 scoped_refptr<DownloadManager> download_manager_; | |
276 | |
277 // The set of DownloadItem's that have transitioned to their finished state | |
278 // since construction of this object. When the size of this array | |
279 // reaches wait_count_, we're done. | |
280 std::set<DownloadItem*> finished_downloads_; | |
281 | |
282 // The set of DownloadItem's we are currently observing. Generally there | |
283 // won't be any overlap with the above; once we see the final state | |
284 // on a DownloadItem, we'll stop observing it. | |
285 std::set<DownloadItem*> downloads_observed_; | |
286 | |
287 // The number of downloads to wait on completing. | |
288 size_t wait_count_; | |
289 | |
290 // The number of downloads entered in final state in initial | |
291 // ModelChanged(). We use |finished_downloads_| to track the incoming | |
292 // transitions to final state we should ignore, and to track the | |
293 // number of final state transitions that occurred between | |
294 // construction and return from wait. But some downloads may be in our | |
295 // final state (and thus be entered into |finished_downloads_|) when we | |
296 // construct this class. We don't want to count those in our transition | |
297 // to finished. | |
298 int finished_downloads_at_construction_; | |
299 | |
300 // Whether an internal message loop has been started and must be quit upon | |
301 // all downloads completing. | |
302 bool waiting_; | |
303 | |
304 // The state on which to consider the DownloadItem finished. | |
305 DownloadItem::DownloadState download_finished_state_; | |
306 | |
307 // True if we should transition the DownloadsObserver to finished if | |
308 // the select file dialog comes up. | |
309 bool finish_on_select_file_; | |
310 | |
311 // True if we've seen the select file dialog. | |
312 bool select_file_dialog_seen_; | |
313 | |
314 // Action to take if a dangerous download is encountered. | |
315 DangerousDownloadAction dangerous_download_action_; | |
316 | |
317 // Holds the download ids which were dangerous. | |
318 std::set<int32> dangerous_downloads_seen_; | |
319 | |
320 DISALLOW_COPY_AND_ASSIGN(DownloadsObserver); | |
321 }; | |
322 | |
323 // WaitForFlush() returns after: | |
324 // * There are no IN_PROGRESS download items remaining on the | |
325 // DownloadManager. | |
326 // * There have been two round trip messages through the file and | |
327 // IO threads. | |
328 // This almost certainly means that a Download cancel has propagated through | |
329 // the system. | |
330 class DownloadsFlushObserver | |
331 : public DownloadManager::Observer, | |
332 public DownloadItem::Observer, | |
333 public base::RefCountedThreadSafe<DownloadsFlushObserver> { | |
334 public: | |
335 explicit DownloadsFlushObserver(DownloadManager* download_manager) | |
336 : download_manager_(download_manager), | |
337 waiting_for_zero_inprogress_(true) { } | |
338 | |
339 void WaitForFlush() { | |
340 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
341 download_manager_->AddObserver(this); | |
342 ui_test_utils::RunMessageLoop(); | |
343 } | |
344 | |
345 // DownloadsManager observer methods. | |
346 virtual void ModelChanged() { | |
347 // Model has changed, so there may be more DownloadItems to observe. | |
348 CheckDownloadsInProgress(true); | |
349 } | |
350 | |
351 // DownloadItem observer methods. | |
352 virtual void OnDownloadUpdated(DownloadItem* download) { | |
353 // No change in DownloadItem set on manager. | |
354 CheckDownloadsInProgress(false); | |
355 } | |
356 virtual void OnDownloadOpened(DownloadItem* download) {} | |
357 | |
358 protected: | |
359 friend class base::RefCountedThreadSafe<DownloadsFlushObserver>; | |
360 | |
361 virtual ~DownloadsFlushObserver() { | |
362 download_manager_->RemoveObserver(this); | |
363 for (std::set<DownloadItem*>::iterator it = downloads_observed_.begin(); | |
364 it != downloads_observed_.end(); ++it) { | |
365 (*it)->RemoveObserver(this); | |
366 } | |
367 } | |
368 | |
369 private: | |
370 // If we're waiting for that flush point, check the number | |
371 // of downloads in the IN_PROGRESS state and take appropriate | |
372 // action. If requested, also observes all downloads while iterating. | |
373 void CheckDownloadsInProgress(bool observe_downloads) { | |
374 if (waiting_for_zero_inprogress_) { | |
375 int count = 0; | |
376 | |
377 std::vector<DownloadItem*> downloads; | |
378 download_manager_->SearchDownloads(string16(), &downloads); | |
379 std::vector<DownloadItem*>::iterator it = downloads.begin(); | |
380 for (; it != downloads.end(); ++it) { | |
381 if ((*it)->state() == DownloadItem::IN_PROGRESS) | |
382 count++; | |
383 if (observe_downloads) { | |
384 if (downloads_observed_.find(*it) == downloads_observed_.end()) { | |
385 (*it)->AddObserver(this); | |
386 } | |
387 // Download items are forever, and we don't want to make | |
388 // assumptions about future state transitions, so once we | |
389 // start observing them, we don't stop until destruction. | |
390 } | |
391 } | |
392 | |
393 if (count == 0) { | |
394 waiting_for_zero_inprogress_ = false; | |
395 // Stop observing DownloadItems. We maintain the observation | |
396 // of DownloadManager so that we don't have to independently track | |
397 // whether we are observing it for conditional destruction. | |
398 for (std::set<DownloadItem*>::iterator it = downloads_observed_.begin(); | |
399 it != downloads_observed_.end(); ++it) { | |
400 (*it)->RemoveObserver(this); | |
401 } | |
402 downloads_observed_.clear(); | |
403 | |
404 // Trigger next step. We need to go past the IO thread twice, as | |
405 // there's a self-task posting in the IO thread cancel path. | |
406 BrowserThread::PostTask( | |
407 BrowserThread::FILE, FROM_HERE, | |
408 NewRunnableMethod(this, | |
409 &DownloadsFlushObserver::PingFileThread, 2)); | |
410 } | |
411 } | |
412 } | |
413 | |
414 void PingFileThread(int cycle) { | |
415 BrowserThread::PostTask( | |
416 BrowserThread::IO, FROM_HERE, | |
417 NewRunnableMethod(this, &DownloadsFlushObserver::PingIOThread, | |
418 cycle)); | |
419 } | |
420 | |
421 void PingIOThread(int cycle) { | |
422 if (--cycle) { | |
423 BrowserThread::PostTask( | |
424 BrowserThread::UI, FROM_HERE, | |
425 NewRunnableMethod(this, &DownloadsFlushObserver::PingFileThread, | |
426 cycle)); | |
427 } else { | |
428 BrowserThread::PostTask( | |
429 BrowserThread::UI, FROM_HERE, new MessageLoop::QuitTask()); | |
430 } | |
431 } | |
432 | |
433 DownloadManager* download_manager_; | |
434 std::set<DownloadItem*> downloads_observed_; | |
435 bool waiting_for_zero_inprogress_; | |
436 | |
437 DISALLOW_COPY_AND_ASSIGN(DownloadsFlushObserver); | |
438 }; | |
439 | |
440 // Collect the information from FILE and IO threads needed for the Cancel | 57 // Collect the information from FILE and IO threads needed for the Cancel |
441 // Test, specifically the number of outstanding requests on the | 58 // Test, specifically the number of outstanding requests on the |
442 // ResourceDispatcherHost and the number of pending downloads on the | 59 // ResourceDispatcherHost and the number of pending downloads on the |
443 // DownloadFileManager. | 60 // DownloadFileManager. |
444 class CancelTestDataCollector | 61 class CancelTestDataCollector |
445 : public base::RefCountedThreadSafe<CancelTestDataCollector> { | 62 : public base::RefCountedThreadSafe<CancelTestDataCollector> { |
446 public: | 63 public: |
447 CancelTestDataCollector() | 64 CancelTestDataCollector() |
448 : resource_dispatcher_host_( | 65 : resource_dispatcher_host_( |
449 g_browser_process->resource_dispatcher_host()), | 66 g_browser_process->resource_dispatcher_host()), |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 DownloadPrefs* GetDownloadPrefs(Browser* browser) { | 186 DownloadPrefs* GetDownloadPrefs(Browser* browser) { |
570 return browser->profile()->GetDownloadManager()->download_prefs(); | 187 return browser->profile()->GetDownloadManager()->download_prefs(); |
571 } | 188 } |
572 | 189 |
573 FilePath GetDownloadDirectory(Browser* browser) { | 190 FilePath GetDownloadDirectory(Browser* browser) { |
574 DownloadManager* download_mananger = | 191 DownloadManager* download_mananger = |
575 browser->profile()->GetDownloadManager(); | 192 browser->profile()->GetDownloadManager(); |
576 return download_mananger->download_prefs()->download_path(); | 193 return download_mananger->download_prefs()->download_path(); |
577 } | 194 } |
578 | 195 |
579 // Create a DownloadsObserver that will wait for the | 196 // Create a DownloadTestObserver that will wait for the |
580 // specified number of downloads to finish. | 197 // specified number of downloads to finish. |
581 DownloadsObserver* CreateWaiter(Browser* browser, int num_downloads) { | 198 DownloadTestObserver* CreateWaiter(Browser* browser, int num_downloads) { |
582 DownloadManager* download_manager = | 199 DownloadManager* download_manager = |
583 browser->profile()->GetDownloadManager(); | 200 browser->profile()->GetDownloadManager(); |
584 return new DownloadsObserver( | 201 return new DownloadTestObserver( |
585 download_manager, num_downloads, | 202 download_manager, num_downloads, |
586 DownloadItem::COMPLETE, // Really done | 203 DownloadItem::COMPLETE, // Really done |
587 false, // Bail on select file | 204 false, // Bail on select file |
588 ON_DANGEROUS_DOWNLOAD_FAIL); | 205 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); |
589 } | 206 } |
590 | 207 |
591 // Create a DownloadsObserver that will wait for the | 208 // Create a DownloadTestObserver that will wait for the |
592 // specified number of downloads to start. | 209 // specified number of downloads to start. |
593 DownloadsObserver* CreateInProgressWaiter(Browser* browser, | 210 DownloadTestObserver* CreateInProgressWaiter(Browser* browser, |
594 int num_downloads) { | 211 int num_downloads) { |
595 DownloadManager* download_manager = | 212 DownloadManager* download_manager = |
596 browser->profile()->GetDownloadManager(); | 213 browser->profile()->GetDownloadManager(); |
597 return new DownloadsObserver( | 214 return new DownloadTestObserver( |
598 download_manager, num_downloads, | 215 download_manager, num_downloads, |
599 DownloadItem::IN_PROGRESS, // Has started | 216 DownloadItem::IN_PROGRESS, // Has started |
600 true, // Bail on select file | 217 true, // Bail on select file |
601 ON_DANGEROUS_DOWNLOAD_FAIL); | 218 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); |
602 } | 219 } |
603 | 220 |
604 // Create a DownloadsObserver that will wait for the | 221 // Create a DownloadTestObserver that will wait for the |
605 // specified number of downloads to finish, or for | 222 // specified number of downloads to finish, or for |
606 // a dangerous download warning to be shown. | 223 // a dangerous download warning to be shown. |
607 DownloadsObserver* DangerousInstallWaiter( | 224 DownloadTestObserver* DangerousInstallWaiter( |
608 Browser* browser, | 225 Browser* browser, |
609 int num_downloads, | 226 int num_downloads, |
610 DownloadItem::DownloadState final_state, | 227 DownloadItem::DownloadState final_state, |
611 DangerousDownloadAction dangerous_download_action) { | 228 DownloadTestObserver::DangerousDownloadAction dangerous_download_action) { |
612 DownloadManager* download_manager = | 229 DownloadManager* download_manager = |
613 browser->profile()->GetDownloadManager(); | 230 browser->profile()->GetDownloadManager(); |
614 return new DownloadsObserver( | 231 return new DownloadTestObserver( |
615 download_manager, num_downloads, | 232 download_manager, num_downloads, |
616 final_state, | 233 final_state, |
617 true, // Bail on select file | 234 true, // Bail on select file |
618 dangerous_download_action); | 235 dangerous_download_action); |
619 } | 236 } |
620 | 237 |
621 // Download |url|, then wait for the download to finish. | 238 // Download |url|, then wait for the download to finish. |
622 // |disposition| indicates where the navigation occurs (current tab, new | 239 // |disposition| indicates where the navigation occurs (current tab, new |
623 // foreground tab, etc). | 240 // foreground tab, etc). |
624 // |expectation| indicates whether or not a Select File dialog should be | 241 // |expectation| indicates whether or not a Select File dialog should be |
625 // open when the download is finished, or if we don't care. | 242 // open when the download is finished, or if we don't care. |
626 // If the dialog appears, the routine exits. The only effect |expectation| | 243 // If the dialog appears, the routine exits. The only effect |expectation| |
627 // has is whether or not the test succeeds. | 244 // has is whether or not the test succeeds. |
628 // |browser_test_flags| indicate what to wait for, and is an OR of 0 or more | 245 // |browser_test_flags| indicate what to wait for, and is an OR of 0 or more |
629 // values in the ui_test_utils::BrowserTestWaitFlags enum. | 246 // values in the ui_test_utils::BrowserTestWaitFlags enum. |
630 void DownloadAndWaitWithDisposition(Browser* browser, | 247 void DownloadAndWaitWithDisposition(Browser* browser, |
631 const GURL& url, | 248 const GURL& url, |
632 WindowOpenDisposition disposition, | 249 WindowOpenDisposition disposition, |
633 SelectExpectation expectation, | 250 SelectExpectation expectation, |
634 int browser_test_flags) { | 251 int browser_test_flags) { |
635 // Setup notification, navigate, and block. | 252 // Setup notification, navigate, and block. |
636 scoped_ptr<DownloadsObserver> observer(CreateWaiter(browser, 1)); | 253 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser, 1)); |
637 // This call will block until the condition specified by | 254 // This call will block until the condition specified by |
638 // |browser_test_flags|, but will not wait for the download to finish. | 255 // |browser_test_flags|, but will not wait for the download to finish. |
639 ui_test_utils::NavigateToURLWithDisposition(browser, | 256 ui_test_utils::NavigateToURLWithDisposition(browser, |
640 url, | 257 url, |
641 disposition, | 258 disposition, |
642 browser_test_flags); | 259 browser_test_flags); |
643 // Waits for the download to complete. | 260 // Waits for the download to complete. |
644 observer->WaitForFinished(); | 261 observer->WaitForFinished(); |
645 | 262 |
646 // If specified, check the state of the select file dialog. | 263 // If specified, check the state of the select file dialog. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 // |expected_title_finished| need to be checked. | 334 // |expected_title_finished| need to be checked. |
718 FilePath filename; | 335 FilePath filename; |
719 net::FileURLToFilePath(url, &filename); | 336 net::FileURLToFilePath(url, &filename); |
720 string16 expected_title_in_progress( | 337 string16 expected_title_in_progress( |
721 ASCIIToUTF16(partial_indication) + filename.LossyDisplayName()); | 338 ASCIIToUTF16(partial_indication) + filename.LossyDisplayName()); |
722 string16 expected_title_finished( | 339 string16 expected_title_finished( |
723 ASCIIToUTF16(total_indication) + filename.LossyDisplayName()); | 340 ASCIIToUTF16(total_indication) + filename.LossyDisplayName()); |
724 | 341 |
725 // Download a partial web page in a background tab and wait. | 342 // Download a partial web page in a background tab and wait. |
726 // The mock system will not complete until it gets a special URL. | 343 // The mock system will not complete until it gets a special URL. |
727 scoped_ptr<DownloadsObserver> observer(CreateWaiter(browser, 1)); | 344 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser, 1)); |
728 ui_test_utils::NavigateToURL(browser, url); | 345 ui_test_utils::NavigateToURL(browser, url); |
729 | 346 |
730 // TODO(ahendrickson): check download status text before downloading. | 347 // TODO(ahendrickson): check download status text before downloading. |
731 // Need to: | 348 // Need to: |
732 // - Add a member function to the |DownloadShelf| interface class, that | 349 // - Add a member function to the |DownloadShelf| interface class, that |
733 // indicates how many members it has. | 350 // indicates how many members it has. |
734 // - Add a member function to |DownloadShelf| to get the status text | 351 // - Add a member function to |DownloadShelf| to get the status text |
735 // of a given member (for example, via the name in |DownloadItemView|'s | 352 // of a given member (for example, via the name in |DownloadItemView|'s |
736 // GetAccessibleState() member function), by index. | 353 // GetAccessibleState() member function), by index. |
737 // - Iterate over browser->window()->GetDownloadShelf()'s members | 354 // - Iterate over browser->window()->GetDownloadShelf()'s members |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
978 CheckDownload(browser(), file, file); | 595 CheckDownload(browser(), file, file); |
979 CheckDownloadUI(browser(), true, true, file); | 596 CheckDownloadUI(browser(), true, true, file); |
980 } | 597 } |
981 #endif | 598 #endif |
982 | 599 |
983 // Put up a Select File dialog when the file is downloaded, due to its MIME | 600 // Put up a Select File dialog when the file is downloaded, due to its MIME |
984 // type. | 601 // type. |
985 // | 602 // |
986 // This test runs correctly, but leaves behind turds in the test user's | 603 // This test runs correctly, but leaves behind turds in the test user's |
987 // download directory because of http://crbug.com/62099. No big loss; it | 604 // download directory because of http://crbug.com/62099. No big loss; it |
988 // was primarily confirming DownloadsObserver wait on select file dialog | 605 // was primarily confirming DownloadTestObserver wait on select file dialog |
989 // functionality anyway. | 606 // functionality anyway. |
990 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_DownloadMimeTypeSelect) { | 607 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_DownloadMimeTypeSelect) { |
991 ASSERT_TRUE(InitialSetup(true)); | 608 ASSERT_TRUE(InitialSetup(true)); |
992 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 609 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
993 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 610 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
994 | 611 |
995 // Download the file and wait. We expect the Select File dialog to appear | 612 // Download the file and wait. We expect the Select File dialog to appear |
996 // due to the MIME type. | 613 // due to the MIME type. |
997 DownloadAndWait(browser(), url, EXPECT_SELECT_DIALOG); | 614 DownloadAndWait(browser(), url, EXPECT_SELECT_DIALOG); |
998 | 615 |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1400 CheckDownloadUI(browser(), false, true, file); | 1017 CheckDownloadUI(browser(), false, true, file); |
1401 | 1018 |
1402 CheckDownload(browser(), file, file); | 1019 CheckDownload(browser(), file, file); |
1403 } | 1020 } |
1404 | 1021 |
1405 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadCancelled) { | 1022 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadCancelled) { |
1406 ASSERT_TRUE(InitialSetup(false)); | 1023 ASSERT_TRUE(InitialSetup(false)); |
1407 EXPECT_EQ(1, browser()->tab_count()); | 1024 EXPECT_EQ(1, browser()->tab_count()); |
1408 | 1025 |
1409 // TODO(rdsmith): Fragile code warning! The code below relies on the | 1026 // TODO(rdsmith): Fragile code warning! The code below relies on the |
1410 // DownloadsObserver only finishing when the new download has reached | 1027 // DownloadTestObserver only finishing when the new download has reached |
1411 // the state of being entered into the history and being user-visible | 1028 // the state of being entered into the history and being user-visible |
1412 // (that's what's required for the Remove to be valid and for the | 1029 // (that's what's required for the Remove to be valid and for the |
1413 // download shelf to be visible). By the pure semantics of | 1030 // download shelf to be visible). By the pure semantics of |
1414 // DownloadsObserver, that's not guaranteed; DownloadItems are created | 1031 // DownloadTestObserver, that's not guaranteed; DownloadItems are created |
1415 // in the IN_PROGRESS state and made known to the DownloadManager | 1032 // in the IN_PROGRESS state and made known to the DownloadManager |
1416 // immediately, so any ModelChanged event on the DownloadManager after | 1033 // immediately, so any ModelChanged event on the DownloadManager after |
1417 // navigation would allow the observer to return. However, the only | 1034 // navigation would allow the observer to return. However, the only |
1418 // ModelChanged() event the code will currently fire is in | 1035 // ModelChanged() event the code will currently fire is in |
1419 // OnCreateDownloadEntryComplete, at which point the download item will | 1036 // OnCreateDownloadEntryComplete, at which point the download item will |
1420 // be in the state we need. | 1037 // be in the state we need. |
1421 // The right way to fix this is to create finer grained states on the | 1038 // The right way to fix this is to create finer grained states on the |
1422 // DownloadItem, and wait for the state that indicates the item has been | 1039 // DownloadItem, and wait for the state that indicates the item has been |
1423 // entered in the history and made visible in the UI. | 1040 // entered in the history and made visible in the UI. |
1424 | 1041 |
1425 // Create a download, wait until it's started, and confirm | 1042 // Create a download, wait until it's started, and confirm |
1426 // we're in the expected state. | 1043 // we're in the expected state. |
1427 scoped_ptr<DownloadsObserver> observer( | 1044 scoped_ptr<DownloadTestObserver> observer( |
1428 CreateInProgressWaiter(browser(), 1)); | 1045 CreateInProgressWaiter(browser(), 1)); |
1429 ui_test_utils::NavigateToURL( | 1046 ui_test_utils::NavigateToURL( |
1430 browser(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); | 1047 browser(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); |
1431 observer->WaitForFinished(); | 1048 observer->WaitForFinished(); |
1432 | 1049 |
1433 std::vector<DownloadItem*> downloads; | 1050 std::vector<DownloadItem*> downloads; |
1434 browser()->profile()->GetDownloadManager()->SearchDownloads( | 1051 browser()->profile()->GetDownloadManager()->SearchDownloads( |
1435 string16(), &downloads); | 1052 string16(), &downloads); |
1436 ASSERT_EQ(1u, downloads.size()); | 1053 ASSERT_EQ(1u, downloads.size()); |
1437 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->state()); | 1054 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->state()); |
1438 CheckDownloadUI(browser(), true, true, FilePath()); | 1055 CheckDownloadUI(browser(), true, true, FilePath()); |
1439 | 1056 |
1440 // Cancel the download and wait for download system quiesce. | 1057 // Cancel the download and wait for download system quiesce. |
1441 downloads[0]->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); | 1058 downloads[0]->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); |
1442 scoped_refptr<DownloadsFlushObserver> flush_observer( | 1059 scoped_refptr<DownloadTestFlushObserver> flush_observer( |
1443 new DownloadsFlushObserver(browser()->profile()->GetDownloadManager())); | 1060 new DownloadTestFlushObserver( |
| 1061 browser()->profile()->GetDownloadManager())); |
1444 flush_observer->WaitForFlush(); | 1062 flush_observer->WaitForFlush(); |
1445 | 1063 |
1446 // Get the important info from other threads and check it. | 1064 // Get the important info from other threads and check it. |
1447 scoped_refptr<CancelTestDataCollector> info(new CancelTestDataCollector()); | 1065 scoped_refptr<CancelTestDataCollector> info(new CancelTestDataCollector()); |
1448 info->WaitForDataCollected(); | 1066 info->WaitForDataCollected(); |
1449 EXPECT_EQ(0, info->rdh_pending_requests()); | 1067 EXPECT_EQ(0, info->rdh_pending_requests()); |
1450 EXPECT_EQ(0, info->dfm_pending_downloads()); | 1068 EXPECT_EQ(0, info->dfm_pending_downloads()); |
1451 | 1069 |
1452 // Using "DownloadItem::Remove" follows the discard dangerous download path, | 1070 // Using "DownloadItem::Remove" follows the discard dangerous download path, |
1453 // which completely removes the browser from the shelf and closes the shelf | 1071 // which completely removes the browser from the shelf and closes the shelf |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1577 // Download shelf should close. Download panel stays open on ChromeOS. | 1195 // Download shelf should close. Download panel stays open on ChromeOS. |
1578 CheckDownloadUI(browser(), false, true, FilePath()); | 1196 CheckDownloadUI(browser(), false, true, FilePath()); |
1579 } | 1197 } |
1580 | 1198 |
1581 // Download an extension. Expect a dangerous download warning. | 1199 // Download an extension. Expect a dangerous download warning. |
1582 // Deny the download. | 1200 // Deny the download. |
1583 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxDenyInstall) { | 1201 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxDenyInstall) { |
1584 ASSERT_TRUE(InitialSetup(false)); | 1202 ASSERT_TRUE(InitialSetup(false)); |
1585 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); | 1203 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); |
1586 | 1204 |
1587 scoped_ptr<DownloadsObserver> observer( | 1205 scoped_ptr<DownloadTestObserver> observer( |
1588 DangerousInstallWaiter(browser(), | 1206 DangerousInstallWaiter( |
1589 1, | 1207 browser(), 1, DownloadItem::CANCELLED, |
1590 DownloadItem::CANCELLED, | 1208 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); |
1591 ON_DANGEROUS_DOWNLOAD_DENY)); | |
1592 ui_test_utils::NavigateToURL(browser(), extension_url); | 1209 ui_test_utils::NavigateToURL(browser(), extension_url); |
1593 | 1210 |
1594 observer->WaitForFinished(); | 1211 observer->WaitForFinished(); |
1595 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1212 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
1596 | 1213 |
1597 // Download shelf should close. Download panel stays open on ChromeOS. | 1214 // Download shelf should close. Download panel stays open on ChromeOS. |
1598 CheckDownloadUI(browser(), false, true, FilePath()); | 1215 CheckDownloadUI(browser(), false, true, FilePath()); |
1599 | 1216 |
1600 // Check that the CRX is not installed. | 1217 // Check that the CRX is not installed. |
1601 ExtensionService* extension_service = | 1218 ExtensionService* extension_service = |
1602 browser()->profile()->GetExtensionService(); | 1219 browser()->profile()->GetExtensionService(); |
1603 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1220 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); |
1604 } | 1221 } |
1605 | 1222 |
1606 // Download an extension. Expect a dangerous download warning. | 1223 // Download an extension. Expect a dangerous download warning. |
1607 // Allow the download, deny the install. | 1224 // Allow the download, deny the install. |
1608 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) { | 1225 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) { |
1609 ASSERT_TRUE(InitialSetup(false)); | 1226 ASSERT_TRUE(InitialSetup(false)); |
1610 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); | 1227 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); |
1611 | 1228 |
1612 // Install a mock install UI that simulates a user denying permission to | 1229 // Install a mock install UI that simulates a user denying permission to |
1613 // finish the install. | 1230 // finish the install. |
1614 download_crx_util::SetMockInstallUIForTesting( | 1231 download_crx_util::SetMockInstallUIForTesting( |
1615 new MockAbortExtensionInstallUI()); | 1232 new MockAbortExtensionInstallUI()); |
1616 | 1233 |
1617 scoped_ptr<DownloadsObserver> observer( | 1234 scoped_ptr<DownloadTestObserver> observer( |
1618 DangerousInstallWaiter(browser(), | 1235 DangerousInstallWaiter( |
1619 1, | 1236 browser(), 1, DownloadItem::COMPLETE, |
1620 DownloadItem::COMPLETE, | 1237 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
1621 ON_DANGEROUS_DOWNLOAD_ACCEPT)); | |
1622 ui_test_utils::NavigateToURL(browser(), extension_url); | 1238 ui_test_utils::NavigateToURL(browser(), extension_url); |
1623 | 1239 |
1624 observer->WaitForFinished(); | 1240 observer->WaitForFinished(); |
1625 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1241 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
1626 | 1242 |
1627 // Download shelf should close. Download panel stays open on ChromeOS. | 1243 // Download shelf should close. Download panel stays open on ChromeOS. |
1628 CheckDownloadUI(browser(), false, true, FilePath()); | 1244 CheckDownloadUI(browser(), false, true, FilePath()); |
1629 | 1245 |
1630 // Check that the extension was not installed. | 1246 // Check that the extension was not installed. |
1631 ExtensionService* extension_service = | 1247 ExtensionService* extension_service = |
1632 browser()->profile()->GetExtensionService(); | 1248 browser()->profile()->GetExtensionService(); |
1633 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1249 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); |
1634 } | 1250 } |
1635 | 1251 |
1636 // Download an extension. Expect a dangerous download warning. | 1252 // Download an extension. Expect a dangerous download warning. |
1637 // Allow the download, and the install. | 1253 // Allow the download, and the install. |
1638 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) { | 1254 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) { |
1639 ASSERT_TRUE(InitialSetup(false)); | 1255 ASSERT_TRUE(InitialSetup(false)); |
1640 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); | 1256 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); |
1641 | 1257 |
1642 // Install a mock install UI that simulates a user allowing permission to | 1258 // Install a mock install UI that simulates a user allowing permission to |
1643 // finish the install. | 1259 // finish the install. |
1644 download_crx_util::SetMockInstallUIForTesting( | 1260 download_crx_util::SetMockInstallUIForTesting( |
1645 new MockAutoConfirmExtensionInstallUI(browser()->profile())); | 1261 new MockAutoConfirmExtensionInstallUI(browser()->profile())); |
1646 | 1262 |
1647 scoped_ptr<DownloadsObserver> observer( | 1263 scoped_ptr<DownloadTestObserver> observer( |
1648 DangerousInstallWaiter(browser(), | 1264 DangerousInstallWaiter( |
1649 1, | 1265 browser(), 1, DownloadItem::COMPLETE, |
1650 DownloadItem::COMPLETE, | 1266 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
1651 ON_DANGEROUS_DOWNLOAD_ACCEPT)); | |
1652 ui_test_utils::NavigateToURL(browser(), extension_url); | 1267 ui_test_utils::NavigateToURL(browser(), extension_url); |
1653 | 1268 |
1654 observer->WaitForFinished(); | 1269 observer->WaitForFinished(); |
1655 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1270 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
1656 | 1271 |
1657 // Download shelf should close. Download panel stays open on ChromeOS. | 1272 // Download shelf should close. Download panel stays open on ChromeOS. |
1658 CheckDownloadUI(browser(), false, true, FilePath()); | 1273 CheckDownloadUI(browser(), false, true, FilePath()); |
1659 | 1274 |
1660 // Check that the extension was installed. | 1275 // Check that the extension was installed. |
1661 ExtensionService* extension_service = | 1276 ExtensionService* extension_service = |
1662 browser()->profile()->GetExtensionService(); | 1277 browser()->profile()->GetExtensionService(); |
1663 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1278 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); |
1664 } | 1279 } |
1665 | 1280 |
1666 // Test installing a CRX that fails integrity checks. | 1281 // Test installing a CRX that fails integrity checks. |
1667 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { | 1282 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { |
1668 ASSERT_TRUE(InitialSetup(false)); | 1283 ASSERT_TRUE(InitialSetup(false)); |
1669 FilePath file(FILE_PATH_LITERAL("extensions/bad_signature.crx")); | 1284 FilePath file(FILE_PATH_LITERAL("extensions/bad_signature.crx")); |
1670 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1285 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1671 | 1286 |
1672 // Install a mock install UI that simulates a user allowing permission to | 1287 // Install a mock install UI that simulates a user allowing permission to |
1673 // finish the install, and dismisses any error message. We check that the | 1288 // finish the install, and dismisses any error message. We check that the |
1674 // install failed below. | 1289 // install failed below. |
1675 download_crx_util::SetMockInstallUIForTesting( | 1290 download_crx_util::SetMockInstallUIForTesting( |
1676 new MockAutoConfirmExtensionInstallUI(browser()->profile())); | 1291 new MockAutoConfirmExtensionInstallUI(browser()->profile())); |
1677 | 1292 |
1678 scoped_ptr<DownloadsObserver> observer( | 1293 scoped_ptr<DownloadTestObserver> observer( |
1679 DangerousInstallWaiter(browser(), | 1294 DangerousInstallWaiter( |
1680 1, | 1295 browser(), 1, DownloadItem::COMPLETE, |
1681 DownloadItem::COMPLETE, | 1296 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
1682 ON_DANGEROUS_DOWNLOAD_ACCEPT)); | |
1683 ui_test_utils::NavigateToURL(browser(), extension_url); | 1297 ui_test_utils::NavigateToURL(browser(), extension_url); |
1684 | 1298 |
1685 observer->WaitForFinished(); | 1299 observer->WaitForFinished(); |
1686 | 1300 |
1687 // Check that the extension was not installed. | 1301 // Check that the extension was not installed. |
1688 ExtensionService* extension_service = | 1302 ExtensionService* extension_service = |
1689 browser()->profile()->GetExtensionService(); | 1303 browser()->profile()->GetExtensionService(); |
1690 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1304 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); |
1691 } | 1305 } |
1692 | 1306 |
1693 // Install a large (100kb) theme. | 1307 // Install a large (100kb) theme. |
1694 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) { | 1308 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) { |
1695 ASSERT_TRUE(InitialSetup(false)); | 1309 ASSERT_TRUE(InitialSetup(false)); |
1696 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kLargeThemePath)); | 1310 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kLargeThemePath)); |
1697 | 1311 |
1698 // Install a mock install UI that simulates a user allowing permission to | 1312 // Install a mock install UI that simulates a user allowing permission to |
1699 // finish the install. | 1313 // finish the install. |
1700 download_crx_util::SetMockInstallUIForTesting( | 1314 download_crx_util::SetMockInstallUIForTesting( |
1701 new MockAutoConfirmExtensionInstallUI(browser()->profile())); | 1315 new MockAutoConfirmExtensionInstallUI(browser()->profile())); |
1702 | 1316 |
1703 scoped_ptr<DownloadsObserver> observer( | 1317 scoped_ptr<DownloadTestObserver> observer( |
1704 DangerousInstallWaiter(browser(), | 1318 DangerousInstallWaiter( |
1705 1, | 1319 browser(), 1, DownloadItem::COMPLETE, |
1706 DownloadItem::COMPLETE, | 1320 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
1707 ON_DANGEROUS_DOWNLOAD_ACCEPT)); | |
1708 ui_test_utils::NavigateToURL(browser(), extension_url); | 1321 ui_test_utils::NavigateToURL(browser(), extension_url); |
1709 | 1322 |
1710 observer->WaitForFinished(); | 1323 observer->WaitForFinished(); |
1711 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1324 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
1712 | 1325 |
1713 // Download shelf should close. Download panel stays open on ChromeOS. | 1326 // Download shelf should close. Download panel stays open on ChromeOS. |
1714 CheckDownloadUI(browser(), false, true, FilePath()); | 1327 CheckDownloadUI(browser(), false, true, FilePath()); |
1715 | 1328 |
1716 // Check that the extension was installed. | 1329 // Check that the extension was installed. |
1717 ExtensionService* extension_service = | 1330 ExtensionService* extension_service = |
1718 browser()->profile()->GetExtensionService(); | 1331 browser()->profile()->GetExtensionService(); |
1719 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); | 1332 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); |
1720 } | 1333 } |
OLD | NEW |