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

Side by Side Diff: chrome/browser/extensions/api/downloads/downloads_api_unittest.cc

Issue 10704052: Download filename determination refactor (3/3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with r148594 to and resolve conflicts with r148576 Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 BrowserThread::PostTask( 270 BrowserThread::PostTask(
271 BrowserThread::IO, FROM_HERE, 271 BrowserThread::IO, FROM_HERE,
272 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); 272 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true));
273 InProcessBrowserTest::SetUpOnMainThread(); 273 InProcessBrowserTest::SetUpOnMainThread();
274 GoOnTheRecord(); 274 GoOnTheRecord();
275 CreateAndSetDownloadsDirectory(); 275 CreateAndSetDownloadsDirectory();
276 current_browser()->profile()->GetPrefs()->SetBoolean( 276 current_browser()->profile()->GetPrefs()->SetBoolean(
277 prefs::kPromptForDownload, false); 277 prefs::kPromptForDownload, false);
278 GetOnRecordManager()->RemoveAllDownloads(); 278 GetOnRecordManager()->RemoveAllDownloads();
279 events_listener_.reset(new DownloadsEventsListener()); 279 events_listener_.reset(new DownloadsEventsListener());
280 // Disable file chooser for current profile.
281 DownloadTestFileChooserObserver observer(current_browser()->profile());
282 observer.EnableFileChooser(false);
280 } 283 }
281 284
282 void GoOnTheRecord() { current_browser_ = browser(); } 285 void GoOnTheRecord() { current_browser_ = browser(); }
283 286
284 void GoOffTheRecord() { 287 void GoOffTheRecord() {
285 if (!incognito_browser_) { 288 if (!incognito_browser_) {
286 incognito_browser_ = CreateIncognitoBrowser(); 289 incognito_browser_ = CreateIncognitoBrowser();
287 GetOffRecordManager()->RemoveAllDownloads(); 290 GetOffRecordManager()->RemoveAllDownloads();
291 // Disable file chooser for incognito profile.
292 DownloadTestFileChooserObserver observer(incognito_browser_->profile());
293 observer.EnableFileChooser(false);
288 } 294 }
289 current_browser_ = incognito_browser_; 295 current_browser_ = incognito_browser_;
290 } 296 }
291 297
292 bool WaitFor(const std::string& event_name, const std::string& json_args) { 298 bool WaitFor(const std::string& event_name, const std::string& json_args) {
293 return events_listener_->WaitFor( 299 return events_listener_->WaitFor(
294 current_browser()->profile(), event_name, json_args); 300 current_browser()->profile(), event_name, json_args);
295 } 301 }
296 302
297 bool WaitForInterruption(DownloadItem* item, int expected_error, 303 bool WaitForInterruption(DownloadItem* item, int expected_error,
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 for (size_t i = 0; i < count; ++i) { 392 for (size_t i = 0; i < count; ++i) {
387 scoped_ptr<DownloadTestObserver> observer( 393 scoped_ptr<DownloadTestObserver> observer(
388 CreateInProgressDownloadObserver(1)); 394 CreateInProgressDownloadObserver(1));
389 GURL slow_download_url(URLRequestSlowDownloadJob::kUnknownSizeUrl); 395 GURL slow_download_url(URLRequestSlowDownloadJob::kUnknownSizeUrl);
390 ui_test_utils::NavigateToURLWithDisposition( 396 ui_test_utils::NavigateToURLWithDisposition(
391 current_browser(), slow_download_url, CURRENT_TAB, 397 current_browser(), slow_download_url, CURRENT_TAB,
392 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 398 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
393 observer->WaitForFinished(); 399 observer->WaitForFinished();
394 EXPECT_EQ( 400 EXPECT_EQ(
395 1u, observer->NumDownloadsSeenInState(DownloadItem::IN_PROGRESS)); 401 1u, observer->NumDownloadsSeenInState(DownloadItem::IN_PROGRESS));
396 // We don't expect a select file dialog.
397 ASSERT_FALSE(observer->select_file_dialog_seen());
398 } 402 }
399 GetCurrentManager()->GetAllDownloads(FilePath(), items); 403 GetCurrentManager()->GetAllDownloads(FilePath(), items);
400 ASSERT_EQ(count, items->size()); 404 ASSERT_EQ(count, items->size());
401 } 405 }
402 406
403 DownloadItem* CreateSlowTestDownload() { 407 DownloadItem* CreateSlowTestDownload() {
404 scoped_ptr<DownloadTestObserver> observer( 408 scoped_ptr<DownloadTestObserver> observer(
405 CreateInProgressDownloadObserver(1)); 409 CreateInProgressDownloadObserver(1));
406 GURL slow_download_url(URLRequestSlowDownloadJob::kUnknownSizeUrl); 410 GURL slow_download_url(URLRequestSlowDownloadJob::kUnknownSizeUrl);
407 DownloadManager* manager = GetCurrentManager(); 411 DownloadManager* manager = GetCurrentManager();
408 412
409 EXPECT_EQ(0, manager->InProgressCount()); 413 EXPECT_EQ(0, manager->InProgressCount());
410 if (manager->InProgressCount() != 0) 414 if (manager->InProgressCount() != 0)
411 return NULL; 415 return NULL;
412 416
413 ui_test_utils::NavigateToURLWithDisposition( 417 ui_test_utils::NavigateToURLWithDisposition(
414 current_browser(), slow_download_url, CURRENT_TAB, 418 current_browser(), slow_download_url, CURRENT_TAB,
415 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 419 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
416 420
417 observer->WaitForFinished(); 421 observer->WaitForFinished();
418 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::IN_PROGRESS)); 422 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::IN_PROGRESS));
419 // We don't expect a select file dialog.
420 if (observer->select_file_dialog_seen())
421 return NULL;
422 423
423 DownloadManager::DownloadVector items; 424 DownloadManager::DownloadVector items;
424 manager->GetAllDownloads(FilePath(), &items); 425 manager->GetAllDownloads(FilePath(), &items);
425 426
426 DownloadItem* new_item = NULL; 427 DownloadItem* new_item = NULL;
427 for (DownloadManager::DownloadVector::iterator iter = items.begin(); 428 for (DownloadManager::DownloadVector::iterator iter = items.begin();
428 iter != items.end(); ++iter) { 429 iter != items.end(); ++iter) {
429 if ((*iter)->GetState() == DownloadItem::IN_PROGRESS) { 430 if ((*iter)->GetState() == DownloadItem::IN_PROGRESS) {
430 // There should be only one IN_PROGRESS item. 431 // There should be only one IN_PROGRESS item.
431 EXPECT_EQ(NULL, new_item); 432 EXPECT_EQ(NULL, new_item);
432 new_item = *iter; 433 new_item = *iter;
433 } 434 }
434 } 435 }
435 return new_item; 436 return new_item;
436 } 437 }
437 438
438 void FinishPendingSlowDownloads() { 439 void FinishPendingSlowDownloads() {
439 scoped_ptr<DownloadTestObserver> observer( 440 scoped_ptr<DownloadTestObserver> observer(
440 CreateDownloadObserver(1)); 441 CreateDownloadObserver(1));
441 GURL finish_url(URLRequestSlowDownloadJob::kFinishDownloadUrl); 442 GURL finish_url(URLRequestSlowDownloadJob::kFinishDownloadUrl);
442 ui_test_utils::NavigateToURLWithDisposition( 443 ui_test_utils::NavigateToURLWithDisposition(
443 current_browser(), finish_url, NEW_FOREGROUND_TAB, 444 current_browser(), finish_url, NEW_FOREGROUND_TAB,
444 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 445 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
445 observer->WaitForFinished(); 446 observer->WaitForFinished();
446 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 447 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
447 } 448 }
448 449
449 DownloadTestObserver* CreateDownloadObserver(size_t download_count) { 450 DownloadTestObserver* CreateDownloadObserver(size_t download_count) {
450 return new DownloadTestObserverTerminal( 451 return new DownloadTestObserverTerminal(
451 GetCurrentManager(), download_count, true, 452 GetCurrentManager(), download_count,
452 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); 453 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL);
453 } 454 }
454 455
455 DownloadTestObserver* CreateInProgressDownloadObserver( 456 DownloadTestObserver* CreateInProgressDownloadObserver(
456 size_t download_count) { 457 size_t download_count) {
457 return new DownloadTestObserverInProgress( 458 return new DownloadTestObserverInProgress(
458 GetCurrentManager(), download_count, true); 459 GetCurrentManager(), download_count);
459 } 460 }
460 461
461 bool RunFunction(UIThreadExtensionFunction* function, 462 bool RunFunction(UIThreadExtensionFunction* function,
462 const std::string& args) { 463 const std::string& args) {
463 scoped_refptr<UIThreadExtensionFunction> delete_function(function); 464 scoped_refptr<UIThreadExtensionFunction> delete_function(function);
464 SetUpExtensionFunction(function); 465 SetUpExtensionFunction(function);
465 return extension_function_test_utils::RunFunction( 466 return extension_function_test_utils::RunFunction(
466 function, args, browser(), GetFlags()); 467 function, args, browser(), GetFlags());
467 } 468 }
468 469
(...skipping 1684 matching lines...) Expand 10 before | Expand all | Expand 10 after
2153 " \"state\": {" 2154 " \"state\": {"
2154 " \"previous\": \"in_progress\"," 2155 " \"previous\": \"in_progress\","
2155 " \"current\": \"complete\"}}]", 2156 " \"current\": \"complete\"}}]",
2156 result_id, 2157 result_id,
2157 GetFilename("on_record.txt.crdownload").c_str(), 2158 GetFilename("on_record.txt.crdownload").c_str(),
2158 GetFilename("on_record.txt").c_str()))); 2159 GetFilename("on_record.txt").c_str())));
2159 std::string disk_data; 2160 std::string disk_data;
2160 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data)); 2161 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data));
2161 EXPECT_STREQ(kPayloadData, disk_data.c_str()); 2162 EXPECT_STREQ(kPayloadData, disk_data.c_str());
2162 } 2163 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_test_observer.cc ('k') | chrome/browser/extensions/crx_installer_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698