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

Side by Side Diff: chrome/browser/download/download_browsertest.cc

Issue 23496076: WIP - Refactor programmatic downloads Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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
« no previous file with comments | « no previous file | chrome/browser/download/download_item_model.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <sstream> 5 #include <sstream>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 #include "chrome/browser/ui/chrome_pages.h" 55 #include "chrome/browser/ui/chrome_pages.h"
56 #include "chrome/browser/ui/host_desktop.h" 56 #include "chrome/browser/ui/host_desktop.h"
57 #include "chrome/browser/ui/tabs/tab_strip_model.h" 57 #include "chrome/browser/ui/tabs/tab_strip_model.h"
58 #include "chrome/common/chrome_paths.h" 58 #include "chrome/common/chrome_paths.h"
59 #include "chrome/common/extensions/feature_switch.h" 59 #include "chrome/common/extensions/feature_switch.h"
60 #include "chrome/common/pref_names.h" 60 #include "chrome/common/pref_names.h"
61 #include "chrome/common/url_constants.h" 61 #include "chrome/common/url_constants.h"
62 #include "chrome/test/base/in_process_browser_test.h" 62 #include "chrome/test/base/in_process_browser_test.h"
63 #include "chrome/test/base/test_switches.h" 63 #include "chrome/test/base/test_switches.h"
64 #include "chrome/test/base/ui_test_utils.h" 64 #include "chrome/test/base/ui_test_utils.h"
65 #include "content/public/browser/download_interrupt_reasons.h"
65 #include "content/public/browser/download_item.h" 66 #include "content/public/browser/download_item.h"
66 #include "content/public/browser/download_manager.h" 67 #include "content/public/browser/download_manager.h"
67 #include "content/public/browser/download_save_info.h" 68 #include "content/public/browser/download_save_info.h"
68 #include "content/public/browser/download_url_parameters.h" 69 #include "content/public/browser/download_url_parameters.h"
69 #include "content/public/browser/notification_source.h" 70 #include "content/public/browser/notification_source.h"
70 #include "content/public/browser/render_view_host.h" 71 #include "content/public/browser/render_view_host.h"
71 #include "content/public/browser/resource_context.h" 72 #include "content/public/browser/resource_context.h"
72 #include "content/public/browser/web_contents.h" 73 #include "content/public/browser/web_contents.h"
73 #include "content/public/common/content_switches.h" 74 #include "content/public/common/content_switches.h"
74 #include "content/public/common/context_menu_params.h" 75 #include "content/public/common/context_menu_params.h"
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 } 362 }
362 363
363 DISALLOW_COPY_AND_ASSIGN(TestRenderViewContextMenu); 364 DISALLOW_COPY_AND_ASSIGN(TestRenderViewContextMenu);
364 }; 365 };
365 366
366 bool WasAutoOpened(DownloadItem* item) { 367 bool WasAutoOpened(DownloadItem* item) {
367 return item->GetAutoOpened(); 368 return item->GetAutoOpened();
368 } 369 }
369 370
370 // Called when a download starts. Marks the download as hidden. 371 // Called when a download starts. Marks the download as hidden.
371 void SetHiddenDownloadCallback(DownloadItem* item, net::Error error) { 372 void SetHiddenDownloadCallback(DownloadItem* item,
373 content::DownloadInterruptReason reason) {
372 DownloadItemModel(item).SetShouldShowInShelf(false); 374 DownloadItemModel(item).SetShouldShowInShelf(false);
373 } 375 }
374 376
375 // Callback for HistoryObserver; used in DownloadHistoryCheck 377 // Callback for HistoryObserver; used in DownloadHistoryCheck
376 bool HasDataAndName(const history::DownloadRow& row) { 378 bool HasDataAndName(const history::DownloadRow& row) {
377 return row.received_bytes > 0 && !row.target_path.empty(); 379 return row.received_bytes > 0 && !row.target_path.empty();
378 } 380 }
379 381
380 } // namespace 382 } // namespace
381 383
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 size_t i) { 869 size_t i) {
868 std::stringstream s; 870 std::stringstream s;
869 s << " " << __FUNCTION__ << "()" 871 s << " " << __FUNCTION__ << "()"
870 << " index = " << i 872 << " index = " << i
871 << " url = '" << download_info.url_name << "'" 873 << " url = '" << download_info.url_name << "'"
872 << " method = " 874 << " method = "
873 << ((download_info.download_method == DOWNLOAD_DIRECT) ? 875 << ((download_info.download_method == DOWNLOAD_DIRECT) ?
874 "DOWNLOAD_DIRECT" : "DOWNLOAD_NAVIGATE") 876 "DOWNLOAD_DIRECT" : "DOWNLOAD_NAVIGATE")
875 << " show_item = " << download_info.show_download_item 877 << " show_item = " << download_info.show_download_item
876 << " reason = " 878 << " reason = "
877 << InterruptReasonDebugString(download_info.reason); 879 << DownloadInterruptReasonToString(download_info.reason);
878 880
879 std::vector<DownloadItem*> download_items; 881 std::vector<DownloadItem*> download_items;
880 GetDownloads(browser(), &download_items); 882 GetDownloads(browser(), &download_items);
881 size_t downloads_expected = download_items.size(); 883 size_t downloads_expected = download_items.size();
882 884
883 std::string server_path = "files/downloads/"; 885 std::string server_path = "files/downloads/";
884 server_path += download_info.url_name; 886 server_path += download_info.url_name;
885 GURL url = test_server()->GetURL(server_path); 887 GURL url = test_server()->GetURL(server_path);
886 ASSERT_TRUE(url.is_valid()) << s.str(); 888 ASSERT_TRUE(url.is_valid()) << s.str();
887 889
(...skipping 18 matching lines...) Expand all
906 params->set_callback(creation_observer->callback()); 908 params->set_callback(creation_observer->callback());
907 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); 909 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass());
908 910
909 // Wait until the item is created, or we have determined that it 911 // Wait until the item is created, or we have determined that it
910 // won't be. 912 // won't be.
911 creation_observer->WaitForDownloadItemCreation(); 913 creation_observer->WaitForDownloadItemCreation();
912 914
913 EXPECT_EQ(download_info.show_download_item, 915 EXPECT_EQ(download_info.show_download_item,
914 creation_observer->succeeded()); 916 creation_observer->succeeded());
915 if (download_info.show_download_item) { 917 if (download_info.show_download_item) {
916 EXPECT_EQ(net::OK, creation_observer->error()); 918 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE,
919 creation_observer->interrupt_reason());
917 EXPECT_NE(content::DownloadItem::kInvalidId, 920 EXPECT_NE(content::DownloadItem::kInvalidId,
918 creation_observer->download_id()); 921 creation_observer->download_id());
919 } else { 922 } else {
920 EXPECT_NE(net::OK, creation_observer->error()); 923 EXPECT_NE(content::DOWNLOAD_INTERRUPT_REASON_NONE,
924 creation_observer->interrupt_reason());
921 EXPECT_EQ(content::DownloadItem::kInvalidId, 925 EXPECT_EQ(content::DownloadItem::kInvalidId,
922 creation_observer->download_id()); 926 creation_observer->download_id());
923 } 927 }
924 } else { 928 } else {
925 // Navigate to URL normally, wait until done. 929 // Navigate to URL normally, wait until done.
926 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), 930 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(),
927 url, 931 url,
928 1); 932 1);
929 } 933 }
930 934
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 const FileErrorInjectInfo& info, 1004 const FileErrorInjectInfo& info,
1001 size_t i) { 1005 size_t i) {
1002 std::stringstream s; 1006 std::stringstream s;
1003 s << " " << __FUNCTION__ << "()" 1007 s << " " << __FUNCTION__ << "()"
1004 << " index = " << i 1008 << " index = " << i
1005 << " url = " << info.error_info.url 1009 << " url = " << info.error_info.url
1006 << " operation code = " << 1010 << " operation code = " <<
1007 content::TestFileErrorInjector::DebugString( 1011 content::TestFileErrorInjector::DebugString(
1008 info.error_info.code) 1012 info.error_info.code)
1009 << " instance = " << info.error_info.operation_instance 1013 << " instance = " << info.error_info.operation_instance
1010 << " error = " << content::InterruptReasonDebugString( 1014 << " error = " << content::DownloadInterruptReasonToString(
1011 info.error_info.error); 1015 info.error_info.error);
1012 1016
1013 injector->ClearErrors(); 1017 injector->ClearErrors();
1014 injector->AddError(info.error_info); 1018 injector->AddError(info.error_info);
1015 1019
1016 injector->InjectErrors(); 1020 injector->InjectErrors();
1017 1021
1018 DownloadFilesCheckErrorsLoopBody(info.download_info, i); 1022 DownloadFilesCheckErrorsLoopBody(info.download_info, i);
1019 1023
1020 size_t expected_successes = info.download_info.show_download_item ? 1u : 0u; 1024 size_t expected_successes = info.download_info.show_download_item ? 1u : 0u;
(...skipping 2224 matching lines...) Expand 10 before | Expand all | Expand 10 after
3245 3249
3246 // No errors this time. The download should complete successfully. 3250 // No errors this time. The download should complete successfully.
3247 EXPECT_FALSE(completion_observer->IsFinished()); 3251 EXPECT_FALSE(completion_observer->IsFinished());
3248 completion_observer->StartObserving(); 3252 completion_observer->StartObserving();
3249 download->Resume(); 3253 download->Resume();
3250 completion_observer->WaitForFinished(); 3254 completion_observer->WaitForFinished();
3251 EXPECT_EQ(DownloadItem::COMPLETE, download->GetState()); 3255 EXPECT_EQ(DownloadItem::COMPLETE, download->GetState());
3252 3256
3253 EXPECT_FALSE(DidShowFileChooser()); 3257 EXPECT_FALSE(DidShowFileChooser());
3254 } 3258 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/download/download_item_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698