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

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: Address comments Created 8 years, 5 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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 BrowserThread::PostTask( 268 BrowserThread::PostTask(
269 BrowserThread::IO, FROM_HERE, 269 BrowserThread::IO, FROM_HERE,
270 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); 270 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true));
271 InProcessBrowserTest::SetUpOnMainThread(); 271 InProcessBrowserTest::SetUpOnMainThread();
272 GoOnTheRecord(); 272 GoOnTheRecord();
273 CreateAndSetDownloadsDirectory(); 273 CreateAndSetDownloadsDirectory();
274 current_browser()->profile()->GetPrefs()->SetBoolean( 274 current_browser()->profile()->GetPrefs()->SetBoolean(
275 prefs::kPromptForDownload, false); 275 prefs::kPromptForDownload, false);
276 GetOnRecordManager()->RemoveAllDownloads(); 276 GetOnRecordManager()->RemoveAllDownloads();
277 events_listener_.reset(new DownloadsEventsListener()); 277 events_listener_.reset(new DownloadsEventsListener());
278 // Disable file chooser for current profile.
279 DownloadTestFileChooserObserver observer(current_browser()->profile());
280 observer.EnableFileChooser(false);
278 } 281 }
279 282
280 void GoOnTheRecord() { current_browser_ = browser(); } 283 void GoOnTheRecord() { current_browser_ = browser(); }
281 284
282 void GoOffTheRecord() { 285 void GoOffTheRecord() {
283 if (!incognito_browser_) { 286 if (!incognito_browser_) {
284 incognito_browser_ = CreateIncognitoBrowser(); 287 incognito_browser_ = CreateIncognitoBrowser();
285 GetOffRecordManager()->RemoveAllDownloads(); 288 GetOffRecordManager()->RemoveAllDownloads();
289 // Disable file chooser for incognito profile.
290 DownloadTestFileChooserObserver observer(incognito_browser_->profile());
291 observer.EnableFileChooser(false);
286 } 292 }
287 current_browser_ = incognito_browser_; 293 current_browser_ = incognito_browser_;
288 } 294 }
289 295
290 bool WaitFor(const std::string& event_name, const std::string& json_args) { 296 bool WaitFor(const std::string& event_name, const std::string& json_args) {
291 return events_listener_->WaitFor( 297 return events_listener_->WaitFor(
292 current_browser()->profile(), event_name, json_args); 298 current_browser()->profile(), event_name, json_args);
293 } 299 }
294 300
295 bool WaitForInterruption(DownloadItem* item, int expected_error, 301 bool WaitForInterruption(DownloadItem* item, int expected_error,
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 for (size_t i = 0; i < count; ++i) { 409 for (size_t i = 0; i < count; ++i) {
404 scoped_ptr<DownloadTestObserver> observer( 410 scoped_ptr<DownloadTestObserver> observer(
405 CreateInProgressDownloadObserver(1)); 411 CreateInProgressDownloadObserver(1));
406 GURL slow_download_url(URLRequestSlowDownloadJob::kUnknownSizeUrl); 412 GURL slow_download_url(URLRequestSlowDownloadJob::kUnknownSizeUrl);
407 ui_test_utils::NavigateToURLWithDisposition( 413 ui_test_utils::NavigateToURLWithDisposition(
408 current_browser(), slow_download_url, CURRENT_TAB, 414 current_browser(), slow_download_url, CURRENT_TAB,
409 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 415 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
410 observer->WaitForFinished(); 416 observer->WaitForFinished();
411 EXPECT_EQ( 417 EXPECT_EQ(
412 1u, observer->NumDownloadsSeenInState(DownloadItem::IN_PROGRESS)); 418 1u, observer->NumDownloadsSeenInState(DownloadItem::IN_PROGRESS));
413 // We don't expect a select file dialog.
414 ASSERT_FALSE(observer->select_file_dialog_seen());
415 } 419 }
416 GetCurrentManager()->GetAllDownloads(FilePath(), items); 420 GetCurrentManager()->GetAllDownloads(FilePath(), items);
417 ASSERT_EQ(count, items->size()); 421 ASSERT_EQ(count, items->size());
418 } 422 }
419 423
420 DownloadItem* CreateSlowTestDownload() { 424 DownloadItem* CreateSlowTestDownload() {
421 scoped_ptr<DownloadTestObserver> observer( 425 scoped_ptr<DownloadTestObserver> observer(
422 CreateInProgressDownloadObserver(1)); 426 CreateInProgressDownloadObserver(1));
423 GURL slow_download_url(URLRequestSlowDownloadJob::kUnknownSizeUrl); 427 GURL slow_download_url(URLRequestSlowDownloadJob::kUnknownSizeUrl);
424 DownloadManager* manager = GetCurrentManager(); 428 DownloadManager* manager = GetCurrentManager();
425 429
426 EXPECT_EQ(0, manager->InProgressCount()); 430 EXPECT_EQ(0, manager->InProgressCount());
427 if (manager->InProgressCount() != 0) 431 if (manager->InProgressCount() != 0)
428 return NULL; 432 return NULL;
429 433
430 ui_test_utils::NavigateToURLWithDisposition( 434 ui_test_utils::NavigateToURLWithDisposition(
431 current_browser(), slow_download_url, CURRENT_TAB, 435 current_browser(), slow_download_url, CURRENT_TAB,
432 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 436 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
433 437
434 observer->WaitForFinished(); 438 observer->WaitForFinished();
435 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::IN_PROGRESS)); 439 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::IN_PROGRESS));
436 // We don't expect a select file dialog.
437 if (observer->select_file_dialog_seen())
438 return NULL;
439 440
440 DownloadManager::DownloadVector items; 441 DownloadManager::DownloadVector items;
441 manager->GetAllDownloads(FilePath(), &items); 442 manager->GetAllDownloads(FilePath(), &items);
442 443
443 DownloadItem* new_item = NULL; 444 DownloadItem* new_item = NULL;
444 for (DownloadManager::DownloadVector::iterator iter = items.begin(); 445 for (DownloadManager::DownloadVector::iterator iter = items.begin();
445 iter != items.end(); ++iter) { 446 iter != items.end(); ++iter) {
446 if ((*iter)->GetState() == DownloadItem::IN_PROGRESS) { 447 if ((*iter)->GetState() == DownloadItem::IN_PROGRESS) {
447 // There should be only one IN_PROGRESS item. 448 // There should be only one IN_PROGRESS item.
448 EXPECT_EQ(NULL, new_item); 449 EXPECT_EQ(NULL, new_item);
449 new_item = *iter; 450 new_item = *iter;
450 } 451 }
451 } 452 }
452 return new_item; 453 return new_item;
453 } 454 }
454 455
455 void FinishPendingSlowDownloads() { 456 void FinishPendingSlowDownloads() {
456 scoped_ptr<DownloadTestObserver> observer( 457 scoped_ptr<DownloadTestObserver> observer(
457 CreateDownloadObserver(1)); 458 CreateDownloadObserver(1));
458 GURL finish_url(URLRequestSlowDownloadJob::kFinishDownloadUrl); 459 GURL finish_url(URLRequestSlowDownloadJob::kFinishDownloadUrl);
459 ui_test_utils::NavigateToURLWithDisposition( 460 ui_test_utils::NavigateToURLWithDisposition(
460 current_browser(), finish_url, NEW_FOREGROUND_TAB, 461 current_browser(), finish_url, NEW_FOREGROUND_TAB,
461 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 462 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
462 observer->WaitForFinished(); 463 observer->WaitForFinished();
463 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 464 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
464 } 465 }
465 466
466 DownloadTestObserver* CreateDownloadObserver(size_t download_count) { 467 DownloadTestObserver* CreateDownloadObserver(size_t download_count) {
467 return new DownloadTestObserverTerminal( 468 return new DownloadTestObserverTerminal(
468 GetCurrentManager(), download_count, true, 469 GetCurrentManager(), download_count,
469 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); 470 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL);
470 } 471 }
471 472
472 DownloadTestObserver* CreateInProgressDownloadObserver( 473 DownloadTestObserver* CreateInProgressDownloadObserver(
473 size_t download_count) { 474 size_t download_count) {
474 return new DownloadTestObserverInProgress( 475 return new DownloadTestObserverInProgress(
475 GetCurrentManager(), download_count, true); 476 GetCurrentManager(), download_count);
476 } 477 }
477 478
478 bool RunFunction(UIThreadExtensionFunction* function, 479 bool RunFunction(UIThreadExtensionFunction* function,
479 const std::string& args) { 480 const std::string& args) {
480 scoped_refptr<UIThreadExtensionFunction> delete_function(function); 481 scoped_refptr<UIThreadExtensionFunction> delete_function(function);
481 SetUpExtensionFunction(function); 482 SetUpExtensionFunction(function);
482 return extension_function_test_utils::RunFunction( 483 return extension_function_test_utils::RunFunction(
483 function, args, browser(), GetFlags()); 484 function, args, browser(), GetFlags());
484 } 485 }
485 486
(...skipping 1665 matching lines...) Expand 10 before | Expand all | Expand 10 after
2151 " \"state\": {" 2152 " \"state\": {"
2152 " \"previous\": \"in_progress\"," 2153 " \"previous\": \"in_progress\","
2153 " \"current\": \"complete\"}}]", 2154 " \"current\": \"complete\"}}]",
2154 result_id, 2155 result_id,
2155 GetFilename("on_record.txt.crdownload").c_str(), 2156 GetFilename("on_record.txt.crdownload").c_str(),
2156 GetFilename("on_record.txt").c_str()))); 2157 GetFilename("on_record.txt").c_str())));
2157 std::string disk_data; 2158 std::string disk_data;
2158 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data)); 2159 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data));
2159 EXPECT_STREQ(kPayloadData, disk_data.c_str()); 2160 EXPECT_STREQ(kPayloadData, disk_data.c_str());
2160 } 2161 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698