| 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_history.h" | 15 #include "chrome/browser/download/download_history.h" |
| 16 #include "chrome/browser/download/download_prefs.h" | 16 #include "chrome/browser/download/download_prefs.h" |
| 17 #include "chrome/browser/download/download_shelf.h" | 17 #include "chrome/browser/download/download_shelf.h" |
| 18 #include "chrome/browser/download/download_test_observer.h" |
| 18 #include "chrome/browser/download/download_util.h" | 19 #include "chrome/browser/download/download_util.h" |
| 19 #include "chrome/browser/extensions/extension_install_ui.h" | 20 #include "chrome/browser/extensions/extension_install_ui.h" |
| 20 #include "chrome/browser/extensions/extension_service.h" | 21 #include "chrome/browser/extensions/extension_service.h" |
| 21 #include "chrome/browser/history/history.h" | 22 #include "chrome/browser/history/history.h" |
| 22 #include "chrome/browser/prefs/pref_service.h" | 23 #include "chrome/browser/prefs/pref_service.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/ui/browser.h" | 25 #include "chrome/browser/ui/browser.h" |
| 25 #include "chrome/browser/ui/browser_list.h" | 26 #include "chrome/browser/ui/browser_list.h" |
| 26 #include "chrome/browser/ui/browser_window.h" | 27 #include "chrome/browser/ui/browser_window.h" |
| 27 #include "chrome/browser/ui/webui/active_downloads_ui.h" | 28 #include "chrome/browser/ui/webui/active_downloads_ui.h" |
| (...skipping 18 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 | 185 |
| 569 DownloadPrefs* GetDownloadPrefs(Browser* browser) { | 186 DownloadPrefs* GetDownloadPrefs(Browser* browser) { |
| 570 return DownloadPrefs::FromDownloadManager( | 187 return DownloadPrefs::FromDownloadManager( |
| 571 browser->profile()->GetDownloadManager()); | 188 browser->profile()->GetDownloadManager()); |
| 572 } | 189 } |
| 573 | 190 |
| 574 FilePath GetDownloadDirectory(Browser* browser) { | 191 FilePath GetDownloadDirectory(Browser* browser) { |
| 575 return GetDownloadPrefs(browser)->download_path(); | 192 return GetDownloadPrefs(browser)->download_path(); |
| 576 } | 193 } |
| 577 | 194 |
| 578 // Create a DownloadsObserver that will wait for the | 195 // Create a DownloadTestObserver that will wait for the |
| 579 // specified number of downloads to finish. | 196 // specified number of downloads to finish. |
| 580 DownloadsObserver* CreateWaiter(Browser* browser, int num_downloads) { | 197 DownloadTestObserver* CreateWaiter(Browser* browser, int num_downloads) { |
| 581 DownloadManager* download_manager = | 198 DownloadManager* download_manager = |
| 582 browser->profile()->GetDownloadManager(); | 199 browser->profile()->GetDownloadManager(); |
| 583 return new DownloadsObserver( | 200 return new DownloadTestObserver( |
| 584 download_manager, num_downloads, | 201 download_manager, num_downloads, |
| 585 DownloadItem::COMPLETE, // Really done | 202 DownloadItem::COMPLETE, // Really done |
| 586 false, // Bail on select file | 203 true, // Bail on select file |
| 587 ON_DANGEROUS_DOWNLOAD_FAIL); | 204 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); |
| 588 } | 205 } |
| 589 | 206 |
| 590 // Create a DownloadsObserver that will wait for the | 207 // Create a DownloadTestObserver that will wait for the |
| 591 // specified number of downloads to start. | 208 // specified number of downloads to start. |
| 592 DownloadsObserver* CreateInProgressWaiter(Browser* browser, | 209 DownloadTestObserver* CreateInProgressWaiter(Browser* browser, |
| 593 int num_downloads) { | 210 int num_downloads) { |
| 594 DownloadManager* download_manager = | 211 DownloadManager* download_manager = |
| 595 browser->profile()->GetDownloadManager(); | 212 browser->profile()->GetDownloadManager(); |
| 596 return new DownloadsObserver( | 213 return new DownloadTestObserver( |
| 597 download_manager, num_downloads, | 214 download_manager, num_downloads, |
| 598 DownloadItem::IN_PROGRESS, // Has started | 215 DownloadItem::IN_PROGRESS, // Has started |
| 599 true, // Bail on select file | 216 true, // Bail on select file |
| 600 ON_DANGEROUS_DOWNLOAD_FAIL); | 217 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); |
| 601 } | 218 } |
| 602 | 219 |
| 603 // Create a DownloadsObserver that will wait for the | 220 // Create a DownloadTestObserver that will wait for the |
| 604 // specified number of downloads to finish, or for | 221 // specified number of downloads to finish, or for |
| 605 // a dangerous download warning to be shown. | 222 // a dangerous download warning to be shown. |
| 606 DownloadsObserver* DangerousInstallWaiter( | 223 DownloadTestObserver* DangerousInstallWaiter( |
| 607 Browser* browser, | 224 Browser* browser, |
| 608 int num_downloads, | 225 int num_downloads, |
| 609 DownloadItem::DownloadState final_state, | 226 DownloadItem::DownloadState final_state, |
| 610 DangerousDownloadAction dangerous_download_action) { | 227 DownloadTestObserver::DangerousDownloadAction dangerous_download_action) { |
| 611 DownloadManager* download_manager = | 228 DownloadManager* download_manager = |
| 612 browser->profile()->GetDownloadManager(); | 229 browser->profile()->GetDownloadManager(); |
| 613 return new DownloadsObserver( | 230 return new DownloadTestObserver( |
| 614 download_manager, num_downloads, | 231 download_manager, num_downloads, |
| 615 final_state, | 232 final_state, |
| 616 true, // Bail on select file | 233 true, // Bail on select file |
| 617 dangerous_download_action); | 234 dangerous_download_action); |
| 618 } | 235 } |
| 619 | 236 |
| 620 // Download |url|, then wait for the download to finish. | 237 // Download |url|, then wait for the download to finish. |
| 621 // |disposition| indicates where the navigation occurs (current tab, new | 238 // |disposition| indicates where the navigation occurs (current tab, new |
| 622 // foreground tab, etc). | 239 // foreground tab, etc). |
| 623 // |expectation| indicates whether or not a Select File dialog should be | 240 // |expectation| indicates whether or not a Select File dialog should be |
| 624 // open when the download is finished, or if we don't care. | 241 // open when the download is finished, or if we don't care. |
| 625 // If the dialog appears, the routine exits. The only effect |expectation| | 242 // If the dialog appears, the routine exits. The only effect |expectation| |
| 626 // has is whether or not the test succeeds. | 243 // has is whether or not the test succeeds. |
| 627 // |browser_test_flags| indicate what to wait for, and is an OR of 0 or more | 244 // |browser_test_flags| indicate what to wait for, and is an OR of 0 or more |
| 628 // values in the ui_test_utils::BrowserTestWaitFlags enum. | 245 // values in the ui_test_utils::BrowserTestWaitFlags enum. |
| 629 void DownloadAndWaitWithDisposition(Browser* browser, | 246 void DownloadAndWaitWithDisposition(Browser* browser, |
| 630 const GURL& url, | 247 const GURL& url, |
| 631 WindowOpenDisposition disposition, | 248 WindowOpenDisposition disposition, |
| 632 SelectExpectation expectation, | 249 SelectExpectation expectation, |
| 633 int browser_test_flags) { | 250 int browser_test_flags) { |
| 634 // Setup notification, navigate, and block. | 251 // Setup notification, navigate, and block. |
| 635 scoped_ptr<DownloadsObserver> observer(CreateWaiter(browser, 1)); | 252 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser, 1)); |
| 636 // This call will block until the condition specified by | 253 // This call will block until the condition specified by |
| 637 // |browser_test_flags|, but will not wait for the download to finish. | 254 // |browser_test_flags|, but will not wait for the download to finish. |
| 638 ui_test_utils::NavigateToURLWithDisposition(browser, | 255 ui_test_utils::NavigateToURLWithDisposition(browser, |
| 639 url, | 256 url, |
| 640 disposition, | 257 disposition, |
| 641 browser_test_flags); | 258 browser_test_flags); |
| 642 // Waits for the download to complete. | 259 // Waits for the download to complete. |
| 643 observer->WaitForFinished(); | 260 observer->WaitForFinished(); |
| 644 | 261 |
| 645 // If specified, check the state of the select file dialog. | 262 // If specified, check the state of the select file dialog. |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 // |expected_title_finished| need to be checked. | 333 // |expected_title_finished| need to be checked. |
| 717 FilePath filename; | 334 FilePath filename; |
| 718 net::FileURLToFilePath(url, &filename); | 335 net::FileURLToFilePath(url, &filename); |
| 719 string16 expected_title_in_progress( | 336 string16 expected_title_in_progress( |
| 720 ASCIIToUTF16(partial_indication) + filename.LossyDisplayName()); | 337 ASCIIToUTF16(partial_indication) + filename.LossyDisplayName()); |
| 721 string16 expected_title_finished( | 338 string16 expected_title_finished( |
| 722 ASCIIToUTF16(total_indication) + filename.LossyDisplayName()); | 339 ASCIIToUTF16(total_indication) + filename.LossyDisplayName()); |
| 723 | 340 |
| 724 // Download a partial web page in a background tab and wait. | 341 // Download a partial web page in a background tab and wait. |
| 725 // The mock system will not complete until it gets a special URL. | 342 // The mock system will not complete until it gets a special URL. |
| 726 scoped_ptr<DownloadsObserver> observer(CreateWaiter(browser, 1)); | 343 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser, 1)); |
| 727 ui_test_utils::NavigateToURL(browser, url); | 344 ui_test_utils::NavigateToURL(browser, url); |
| 728 | 345 |
| 729 // TODO(ahendrickson): check download status text before downloading. | 346 // TODO(ahendrickson): check download status text before downloading. |
| 730 // Need to: | 347 // Need to: |
| 731 // - Add a member function to the |DownloadShelf| interface class, that | 348 // - Add a member function to the |DownloadShelf| interface class, that |
| 732 // indicates how many members it has. | 349 // indicates how many members it has. |
| 733 // - Add a member function to |DownloadShelf| to get the status text | 350 // - Add a member function to |DownloadShelf| to get the status text |
| 734 // of a given member (for example, via the name in |DownloadItemView|'s | 351 // of a given member (for example, via the name in |DownloadItemView|'s |
| 735 // GetAccessibleState() member function), by index. | 352 // GetAccessibleState() member function), by index. |
| 736 // - Iterate over browser->window()->GetDownloadShelf()'s members | 353 // - Iterate over browser->window()->GetDownloadShelf()'s members |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 979 CheckDownload(browser(), file, file); | 596 CheckDownload(browser(), file, file); |
| 980 CheckDownloadUI(browser(), true, true, file); | 597 CheckDownloadUI(browser(), true, true, file); |
| 981 } | 598 } |
| 982 #endif | 599 #endif |
| 983 | 600 |
| 984 // Put up a Select File dialog when the file is downloaded, due to its MIME | 601 // Put up a Select File dialog when the file is downloaded, due to its MIME |
| 985 // type. | 602 // type. |
| 986 // | 603 // |
| 987 // This test runs correctly, but leaves behind turds in the test user's | 604 // This test runs correctly, but leaves behind turds in the test user's |
| 988 // download directory because of http://crbug.com/62099. No big loss; it | 605 // download directory because of http://crbug.com/62099. No big loss; it |
| 989 // was primarily confirming DownloadsObserver wait on select file dialog | 606 // was primarily confirming DownloadTestObserver wait on select file dialog |
| 990 // functionality anyway. | 607 // functionality anyway. |
| 991 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_DownloadMimeTypeSelect) { | 608 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_DownloadMimeTypeSelect) { |
| 992 ASSERT_TRUE(InitialSetup(true)); | 609 ASSERT_TRUE(InitialSetup(true)); |
| 993 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 610 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 994 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 611 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 995 | 612 |
| 996 // Download the file and wait. We expect the Select File dialog to appear | 613 // Download the file and wait. We expect the Select File dialog to appear |
| 997 // due to the MIME type. | 614 // due to the MIME type. |
| 998 DownloadAndWait(browser(), url, EXPECT_SELECT_DIALOG); | 615 DownloadAndWait(browser(), url, EXPECT_SELECT_DIALOG); |
| 999 | 616 |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1401 CheckDownloadUI(browser(), false, true, file); | 1018 CheckDownloadUI(browser(), false, true, file); |
| 1402 | 1019 |
| 1403 CheckDownload(browser(), file, file); | 1020 CheckDownload(browser(), file, file); |
| 1404 } | 1021 } |
| 1405 | 1022 |
| 1406 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadCancelled) { | 1023 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadCancelled) { |
| 1407 ASSERT_TRUE(InitialSetup(false)); | 1024 ASSERT_TRUE(InitialSetup(false)); |
| 1408 EXPECT_EQ(1, browser()->tab_count()); | 1025 EXPECT_EQ(1, browser()->tab_count()); |
| 1409 | 1026 |
| 1410 // TODO(rdsmith): Fragile code warning! The code below relies on the | 1027 // TODO(rdsmith): Fragile code warning! The code below relies on the |
| 1411 // DownloadsObserver only finishing when the new download has reached | 1028 // DownloadTestObserver only finishing when the new download has reached |
| 1412 // the state of being entered into the history and being user-visible | 1029 // the state of being entered into the history and being user-visible |
| 1413 // (that's what's required for the Remove to be valid and for the | 1030 // (that's what's required for the Remove to be valid and for the |
| 1414 // download shelf to be visible). By the pure semantics of | 1031 // download shelf to be visible). By the pure semantics of |
| 1415 // DownloadsObserver, that's not guaranteed; DownloadItems are created | 1032 // DownloadTestObserver, that's not guaranteed; DownloadItems are created |
| 1416 // in the IN_PROGRESS state and made known to the DownloadManager | 1033 // in the IN_PROGRESS state and made known to the DownloadManager |
| 1417 // immediately, so any ModelChanged event on the DownloadManager after | 1034 // immediately, so any ModelChanged event on the DownloadManager after |
| 1418 // navigation would allow the observer to return. However, the only | 1035 // navigation would allow the observer to return. However, the only |
| 1419 // ModelChanged() event the code will currently fire is in | 1036 // ModelChanged() event the code will currently fire is in |
| 1420 // OnCreateDownloadEntryComplete, at which point the download item will | 1037 // OnCreateDownloadEntryComplete, at which point the download item will |
| 1421 // be in the state we need. | 1038 // be in the state we need. |
| 1422 // The right way to fix this is to create finer grained states on the | 1039 // The right way to fix this is to create finer grained states on the |
| 1423 // DownloadItem, and wait for the state that indicates the item has been | 1040 // DownloadItem, and wait for the state that indicates the item has been |
| 1424 // entered in the history and made visible in the UI. | 1041 // entered in the history and made visible in the UI. |
| 1425 | 1042 |
| 1426 // Create a download, wait until it's started, and confirm | 1043 // Create a download, wait until it's started, and confirm |
| 1427 // we're in the expected state. | 1044 // we're in the expected state. |
| 1428 scoped_ptr<DownloadsObserver> observer( | 1045 scoped_ptr<DownloadTestObserver> observer( |
| 1429 CreateInProgressWaiter(browser(), 1)); | 1046 CreateInProgressWaiter(browser(), 1)); |
| 1430 ui_test_utils::NavigateToURL( | 1047 ui_test_utils::NavigateToURL( |
| 1431 browser(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); | 1048 browser(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); |
| 1432 observer->WaitForFinished(); | 1049 observer->WaitForFinished(); |
| 1433 | 1050 |
| 1434 std::vector<DownloadItem*> downloads; | 1051 std::vector<DownloadItem*> downloads; |
| 1435 browser()->profile()->GetDownloadManager()->SearchDownloads( | 1052 browser()->profile()->GetDownloadManager()->SearchDownloads( |
| 1436 string16(), &downloads); | 1053 string16(), &downloads); |
| 1437 ASSERT_EQ(1u, downloads.size()); | 1054 ASSERT_EQ(1u, downloads.size()); |
| 1438 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->state()); | 1055 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->state()); |
| 1439 CheckDownloadUI(browser(), true, true, FilePath()); | 1056 CheckDownloadUI(browser(), true, true, FilePath()); |
| 1440 | 1057 |
| 1441 // Cancel the download and wait for download system quiesce. | 1058 // Cancel the download and wait for download system quiesce. |
| 1442 downloads[0]->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); | 1059 downloads[0]->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); |
| 1443 scoped_refptr<DownloadsFlushObserver> flush_observer( | 1060 scoped_refptr<DownloadTestFlushObserver> flush_observer( |
| 1444 new DownloadsFlushObserver(browser()->profile()->GetDownloadManager())); | 1061 new DownloadTestFlushObserver( |
| 1062 browser()->profile()->GetDownloadManager())); |
| 1445 flush_observer->WaitForFlush(); | 1063 flush_observer->WaitForFlush(); |
| 1446 | 1064 |
| 1447 // Get the important info from other threads and check it. | 1065 // Get the important info from other threads and check it. |
| 1448 scoped_refptr<CancelTestDataCollector> info(new CancelTestDataCollector()); | 1066 scoped_refptr<CancelTestDataCollector> info(new CancelTestDataCollector()); |
| 1449 info->WaitForDataCollected(); | 1067 info->WaitForDataCollected(); |
| 1450 EXPECT_EQ(0, info->rdh_pending_requests()); | 1068 EXPECT_EQ(0, info->rdh_pending_requests()); |
| 1451 EXPECT_EQ(0, info->dfm_pending_downloads()); | 1069 EXPECT_EQ(0, info->dfm_pending_downloads()); |
| 1452 | 1070 |
| 1453 // Using "DownloadItem::Remove" follows the discard dangerous download path, | 1071 // Using "DownloadItem::Remove" follows the discard dangerous download path, |
| 1454 // which completely removes the browser from the shelf and closes the shelf | 1072 // which completely removes the browser from the shelf and closes the shelf |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1550 } | 1168 } |
| 1551 | 1169 |
| 1552 // Test to make sure the 'download' attribute in anchor tag is respected. | 1170 // Test to make sure the 'download' attribute in anchor tag is respected. |
| 1553 IN_PROC_BROWSER_TEST_F(DownloadTest, AnchorDownloadTag) { | 1171 IN_PROC_BROWSER_TEST_F(DownloadTest, AnchorDownloadTag) { |
| 1554 ASSERT_TRUE(InitialSetup(false)); | 1172 ASSERT_TRUE(InitialSetup(false)); |
| 1555 FilePath file(FILE_PATH_LITERAL("download-anchor-attrib.html")); | 1173 FilePath file(FILE_PATH_LITERAL("download-anchor-attrib.html")); |
| 1556 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1174 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1557 | 1175 |
| 1558 // Create a download, wait until it's complete, and confirm | 1176 // Create a download, wait until it's complete, and confirm |
| 1559 // we're in the expected state. | 1177 // we're in the expected state. |
| 1560 scoped_ptr<DownloadsObserver> observer(CreateWaiter(browser(), 1)); | 1178 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser(), 1)); |
| 1561 ui_test_utils::NavigateToURL(browser(), url); | 1179 ui_test_utils::NavigateToURL(browser(), url); |
| 1562 observer->WaitForFinished(); | 1180 observer->WaitForFinished(); |
| 1563 | 1181 |
| 1564 // Confirm the downloaded data exists. | 1182 // Confirm the downloaded data exists. |
| 1565 FilePath downloaded_file = GetDownloadDirectory(browser()); | 1183 FilePath downloaded_file = GetDownloadDirectory(browser()); |
| 1566 downloaded_file = downloaded_file.Append(FILE_PATH_LITERAL("a_red_dot.png")); | 1184 downloaded_file = downloaded_file.Append(FILE_PATH_LITERAL("a_red_dot.png")); |
| 1567 EXPECT_TRUE(file_util::PathExists(downloaded_file)); | 1185 EXPECT_TRUE(file_util::PathExists(downloaded_file)); |
| 1568 } | 1186 } |
| 1569 | 1187 |
| 1570 // Test to make sure auto-open works. | 1188 // Test to make sure auto-open works. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1596 // Download shelf should close. Download panel stays open on ChromeOS. | 1214 // Download shelf should close. Download panel stays open on ChromeOS. |
| 1597 CheckDownloadUI(browser(), false, true, FilePath()); | 1215 CheckDownloadUI(browser(), false, true, FilePath()); |
| 1598 } | 1216 } |
| 1599 | 1217 |
| 1600 // Download an extension. Expect a dangerous download warning. | 1218 // Download an extension. Expect a dangerous download warning. |
| 1601 // Deny the download. | 1219 // Deny the download. |
| 1602 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxDenyInstall) { | 1220 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxDenyInstall) { |
| 1603 ASSERT_TRUE(InitialSetup(false)); | 1221 ASSERT_TRUE(InitialSetup(false)); |
| 1604 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); | 1222 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); |
| 1605 | 1223 |
| 1606 scoped_ptr<DownloadsObserver> observer( | 1224 scoped_ptr<DownloadTestObserver> observer( |
| 1607 DangerousInstallWaiter(browser(), | 1225 DangerousInstallWaiter( |
| 1608 1, | 1226 browser(), 1, DownloadItem::CANCELLED, |
| 1609 DownloadItem::CANCELLED, | 1227 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); |
| 1610 ON_DANGEROUS_DOWNLOAD_DENY)); | |
| 1611 ui_test_utils::NavigateToURL(browser(), extension_url); | 1228 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 1612 | 1229 |
| 1613 observer->WaitForFinished(); | 1230 observer->WaitForFinished(); |
| 1614 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1231 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
| 1615 | 1232 |
| 1616 // Download shelf should close. Download panel stays open on ChromeOS. | 1233 // Download shelf should close. Download panel stays open on ChromeOS. |
| 1617 CheckDownloadUI(browser(), false, true, FilePath()); | 1234 CheckDownloadUI(browser(), false, true, FilePath()); |
| 1618 | 1235 |
| 1619 // Check that the CRX is not installed. | 1236 // Check that the CRX is not installed. |
| 1620 ExtensionService* extension_service = | 1237 ExtensionService* extension_service = |
| 1621 browser()->profile()->GetExtensionService(); | 1238 browser()->profile()->GetExtensionService(); |
| 1622 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1239 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); |
| 1623 } | 1240 } |
| 1624 | 1241 |
| 1625 // Download an extension. Expect a dangerous download warning. | 1242 // Download an extension. Expect a dangerous download warning. |
| 1626 // Allow the download, deny the install. | 1243 // Allow the download, deny the install. |
| 1627 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) { | 1244 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) { |
| 1628 ASSERT_TRUE(InitialSetup(false)); | 1245 ASSERT_TRUE(InitialSetup(false)); |
| 1629 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); | 1246 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); |
| 1630 | 1247 |
| 1631 // Install a mock install UI that simulates a user denying permission to | 1248 // Install a mock install UI that simulates a user denying permission to |
| 1632 // finish the install. | 1249 // finish the install. |
| 1633 download_crx_util::SetMockInstallUIForTesting( | 1250 download_crx_util::SetMockInstallUIForTesting( |
| 1634 new MockAbortExtensionInstallUI()); | 1251 new MockAbortExtensionInstallUI()); |
| 1635 | 1252 |
| 1636 scoped_ptr<DownloadsObserver> observer( | 1253 scoped_ptr<DownloadTestObserver> observer( |
| 1637 DangerousInstallWaiter(browser(), | 1254 DangerousInstallWaiter( |
| 1638 1, | 1255 browser(), 1, DownloadItem::COMPLETE, |
| 1639 DownloadItem::COMPLETE, | 1256 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
| 1640 ON_DANGEROUS_DOWNLOAD_ACCEPT)); | |
| 1641 ui_test_utils::NavigateToURL(browser(), extension_url); | 1257 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 1642 | 1258 |
| 1643 observer->WaitForFinished(); | 1259 observer->WaitForFinished(); |
| 1644 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1260 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
| 1645 | 1261 |
| 1646 // Download shelf should close. Download panel stays open on ChromeOS. | 1262 // Download shelf should close. Download panel stays open on ChromeOS. |
| 1647 CheckDownloadUI(browser(), false, true, FilePath()); | 1263 CheckDownloadUI(browser(), false, true, FilePath()); |
| 1648 | 1264 |
| 1649 // Check that the extension was not installed. | 1265 // Check that the extension was not installed. |
| 1650 ExtensionService* extension_service = | 1266 ExtensionService* extension_service = |
| 1651 browser()->profile()->GetExtensionService(); | 1267 browser()->profile()->GetExtensionService(); |
| 1652 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1268 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); |
| 1653 } | 1269 } |
| 1654 | 1270 |
| 1655 // Download an extension. Expect a dangerous download warning. | 1271 // Download an extension. Expect a dangerous download warning. |
| 1656 // Allow the download, and the install. | 1272 // Allow the download, and the install. |
| 1657 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) { | 1273 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) { |
| 1658 ASSERT_TRUE(InitialSetup(false)); | 1274 ASSERT_TRUE(InitialSetup(false)); |
| 1659 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); | 1275 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); |
| 1660 | 1276 |
| 1661 // Install a mock install UI that simulates a user allowing permission to | 1277 // Install a mock install UI that simulates a user allowing permission to |
| 1662 // finish the install. | 1278 // finish the install. |
| 1663 download_crx_util::SetMockInstallUIForTesting( | 1279 download_crx_util::SetMockInstallUIForTesting( |
| 1664 new MockAutoConfirmExtensionInstallUI(browser()->profile())); | 1280 new MockAutoConfirmExtensionInstallUI(browser()->profile())); |
| 1665 | 1281 |
| 1666 scoped_ptr<DownloadsObserver> observer( | 1282 scoped_ptr<DownloadTestObserver> observer( |
| 1667 DangerousInstallWaiter(browser(), | 1283 DangerousInstallWaiter( |
| 1668 1, | 1284 browser(), 1, DownloadItem::COMPLETE, |
| 1669 DownloadItem::COMPLETE, | 1285 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
| 1670 ON_DANGEROUS_DOWNLOAD_ACCEPT)); | |
| 1671 ui_test_utils::NavigateToURL(browser(), extension_url); | 1286 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 1672 | 1287 |
| 1673 observer->WaitForFinished(); | 1288 observer->WaitForFinished(); |
| 1674 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1289 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
| 1675 | 1290 |
| 1676 // Download shelf should close. Download panel stays open on ChromeOS. | 1291 // Download shelf should close. Download panel stays open on ChromeOS. |
| 1677 CheckDownloadUI(browser(), false, true, FilePath()); | 1292 CheckDownloadUI(browser(), false, true, FilePath()); |
| 1678 | 1293 |
| 1679 // Check that the extension was installed. | 1294 // Check that the extension was installed. |
| 1680 ExtensionService* extension_service = | 1295 ExtensionService* extension_service = |
| 1681 browser()->profile()->GetExtensionService(); | 1296 browser()->profile()->GetExtensionService(); |
| 1682 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1297 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); |
| 1683 } | 1298 } |
| 1684 | 1299 |
| 1685 // Test installing a CRX that fails integrity checks. | 1300 // Test installing a CRX that fails integrity checks. |
| 1686 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { | 1301 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { |
| 1687 ASSERT_TRUE(InitialSetup(false)); | 1302 ASSERT_TRUE(InitialSetup(false)); |
| 1688 FilePath file(FILE_PATH_LITERAL("extensions/bad_signature.crx")); | 1303 FilePath file(FILE_PATH_LITERAL("extensions/bad_signature.crx")); |
| 1689 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1304 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1690 | 1305 |
| 1691 // Install a mock install UI that simulates a user allowing permission to | 1306 // Install a mock install UI that simulates a user allowing permission to |
| 1692 // finish the install, and dismisses any error message. We check that the | 1307 // finish the install, and dismisses any error message. We check that the |
| 1693 // install failed below. | 1308 // install failed below. |
| 1694 download_crx_util::SetMockInstallUIForTesting( | 1309 download_crx_util::SetMockInstallUIForTesting( |
| 1695 new MockAutoConfirmExtensionInstallUI(browser()->profile())); | 1310 new MockAutoConfirmExtensionInstallUI(browser()->profile())); |
| 1696 | 1311 |
| 1697 scoped_ptr<DownloadsObserver> observer( | 1312 scoped_ptr<DownloadTestObserver> observer( |
| 1698 DangerousInstallWaiter(browser(), | 1313 DangerousInstallWaiter( |
| 1699 1, | 1314 browser(), 1, DownloadItem::COMPLETE, |
| 1700 DownloadItem::COMPLETE, | 1315 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
| 1701 ON_DANGEROUS_DOWNLOAD_ACCEPT)); | |
| 1702 ui_test_utils::NavigateToURL(browser(), extension_url); | 1316 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 1703 | 1317 |
| 1704 observer->WaitForFinished(); | 1318 observer->WaitForFinished(); |
| 1705 | 1319 |
| 1706 // Check that the extension was not installed. | 1320 // Check that the extension was not installed. |
| 1707 ExtensionService* extension_service = | 1321 ExtensionService* extension_service = |
| 1708 browser()->profile()->GetExtensionService(); | 1322 browser()->profile()->GetExtensionService(); |
| 1709 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1323 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); |
| 1710 } | 1324 } |
| 1711 | 1325 |
| 1712 // Install a large (100kb) theme. | 1326 // Install a large (100kb) theme. |
| 1713 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) { | 1327 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) { |
| 1714 ASSERT_TRUE(InitialSetup(false)); | 1328 ASSERT_TRUE(InitialSetup(false)); |
| 1715 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kLargeThemePath)); | 1329 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kLargeThemePath)); |
| 1716 | 1330 |
| 1717 // Install a mock install UI that simulates a user allowing permission to | 1331 // Install a mock install UI that simulates a user allowing permission to |
| 1718 // finish the install. | 1332 // finish the install. |
| 1719 download_crx_util::SetMockInstallUIForTesting( | 1333 download_crx_util::SetMockInstallUIForTesting( |
| 1720 new MockAutoConfirmExtensionInstallUI(browser()->profile())); | 1334 new MockAutoConfirmExtensionInstallUI(browser()->profile())); |
| 1721 | 1335 |
| 1722 scoped_ptr<DownloadsObserver> observer( | 1336 scoped_ptr<DownloadTestObserver> observer( |
| 1723 DangerousInstallWaiter(browser(), | 1337 DangerousInstallWaiter( |
| 1724 1, | 1338 browser(), 1, DownloadItem::COMPLETE, |
| 1725 DownloadItem::COMPLETE, | 1339 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
| 1726 ON_DANGEROUS_DOWNLOAD_ACCEPT)); | |
| 1727 ui_test_utils::NavigateToURL(browser(), extension_url); | 1340 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 1728 | 1341 |
| 1729 observer->WaitForFinished(); | 1342 observer->WaitForFinished(); |
| 1730 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1343 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
| 1731 | 1344 |
| 1732 // Download shelf should close. Download panel stays open on ChromeOS. | 1345 // Download shelf should close. Download panel stays open on ChromeOS. |
| 1733 CheckDownloadUI(browser(), false, true, FilePath()); | 1346 CheckDownloadUI(browser(), false, true, FilePath()); |
| 1734 | 1347 |
| 1735 // Check that the extension was installed. | 1348 // Check that the extension was installed. |
| 1736 ExtensionService* extension_service = | 1349 ExtensionService* extension_service = |
| 1737 browser()->profile()->GetExtensionService(); | 1350 browser()->profile()->GetExtensionService(); |
| 1738 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); | 1351 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); |
| 1739 } | 1352 } |
| OLD | NEW |