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

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

Issue 114193009: [Download] Return DownloadInterruptReason from OnStartedCallback (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 <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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 #include "chrome/browser/ui/browser_window.h" 56 #include "chrome/browser/ui/browser_window.h"
57 #include "chrome/browser/ui/chrome_pages.h" 57 #include "chrome/browser/ui/chrome_pages.h"
58 #include "chrome/browser/ui/host_desktop.h" 58 #include "chrome/browser/ui/host_desktop.h"
59 #include "chrome/browser/ui/tabs/tab_strip_model.h" 59 #include "chrome/browser/ui/tabs/tab_strip_model.h"
60 #include "chrome/common/chrome_paths.h" 60 #include "chrome/common/chrome_paths.h"
61 #include "chrome/common/pref_names.h" 61 #include "chrome/common/pref_names.h"
62 #include "chrome/common/url_constants.h" 62 #include "chrome/common/url_constants.h"
63 #include "chrome/test/base/in_process_browser_test.h" 63 #include "chrome/test/base/in_process_browser_test.h"
64 #include "chrome/test/base/test_switches.h" 64 #include "chrome/test/base/test_switches.h"
65 #include "chrome/test/base/ui_test_utils.h" 65 #include "chrome/test/base/ui_test_utils.h"
66 #include "content/public/browser/download_interrupt_reasons.h"
66 #include "content/public/browser/download_item.h" 67 #include "content/public/browser/download_item.h"
67 #include "content/public/browser/download_manager.h" 68 #include "content/public/browser/download_manager.h"
68 #include "content/public/browser/download_save_info.h" 69 #include "content/public/browser/download_save_info.h"
69 #include "content/public/browser/download_url_parameters.h" 70 #include "content/public/browser/download_url_parameters.h"
70 #include "content/public/browser/notification_source.h" 71 #include "content/public/browser/notification_source.h"
71 #include "content/public/browser/render_view_host.h" 72 #include "content/public/browser/render_view_host.h"
72 #include "content/public/browser/resource_context.h" 73 #include "content/public/browser/resource_context.h"
73 #include "content/public/browser/web_contents.h" 74 #include "content/public/browser/web_contents.h"
74 #include "content/public/common/content_switches.h" 75 #include "content/public/common/content_switches.h"
75 #include "content/public/common/context_menu_params.h" 76 #include "content/public/common/context_menu_params.h"
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 } 338 }
338 339
339 DISALLOW_COPY_AND_ASSIGN(TestRenderViewContextMenu); 340 DISALLOW_COPY_AND_ASSIGN(TestRenderViewContextMenu);
340 }; 341 };
341 342
342 bool WasAutoOpened(DownloadItem* item) { 343 bool WasAutoOpened(DownloadItem* item) {
343 return item->GetAutoOpened(); 344 return item->GetAutoOpened();
344 } 345 }
345 346
346 // Called when a download starts. Marks the download as hidden. 347 // Called when a download starts. Marks the download as hidden.
347 void SetHiddenDownloadCallback(DownloadItem* item, net::Error error) { 348 void SetHiddenDownloadCallback(DownloadItem* item,
349 content::DownloadInterruptReason reason) {
348 DownloadItemModel(item).SetShouldShowInShelf(false); 350 DownloadItemModel(item).SetShouldShowInShelf(false);
349 } 351 }
350 352
351 // Callback for HistoryObserver; used in DownloadHistoryCheck 353 // Callback for HistoryObserver; used in DownloadHistoryCheck
352 bool HasDataAndName(const history::DownloadRow& row) { 354 bool HasDataAndName(const history::DownloadRow& row) {
353 return row.received_bytes > 0 && !row.target_path.empty(); 355 return row.received_bytes > 0 && !row.target_path.empty();
354 } 356 }
355 357
356 } // namespace 358 } // namespace
357 359
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 void DownloadFilesCheckErrorsLoopBody(const DownloadInfo& download_info, 865 void DownloadFilesCheckErrorsLoopBody(const DownloadInfo& download_info,
864 size_t i) { 866 size_t i) {
865 std::stringstream s; 867 std::stringstream s;
866 s << " " << __FUNCTION__ << "()" 868 s << " " << __FUNCTION__ << "()"
867 << " index = " << i 869 << " index = " << i
868 << " url = '" << download_info.url_name << "'" 870 << " url = '" << download_info.url_name << "'"
869 << " method = " 871 << " method = "
870 << ((download_info.download_method == DOWNLOAD_DIRECT) ? 872 << ((download_info.download_method == DOWNLOAD_DIRECT) ?
871 "DOWNLOAD_DIRECT" : "DOWNLOAD_NAVIGATE") 873 "DOWNLOAD_DIRECT" : "DOWNLOAD_NAVIGATE")
872 << " show_item = " << download_info.show_download_item 874 << " show_item = " << download_info.show_download_item
873 << " reason = " 875 << " reason = " << DownloadInterruptReasonToString(download_info.reason);
874 << InterruptReasonDebugString(download_info.reason);
875 876
876 std::vector<DownloadItem*> download_items; 877 std::vector<DownloadItem*> download_items;
877 GetDownloads(browser(), &download_items); 878 GetDownloads(browser(), &download_items);
878 size_t downloads_expected = download_items.size(); 879 size_t downloads_expected = download_items.size();
879 880
880 std::string server_path = "files/downloads/"; 881 std::string server_path = "files/downloads/";
881 server_path += download_info.url_name; 882 server_path += download_info.url_name;
882 GURL url = test_server()->GetURL(server_path); 883 GURL url = test_server()->GetURL(server_path);
883 ASSERT_TRUE(url.is_valid()) << s.str(); 884 ASSERT_TRUE(url.is_valid()) << s.str();
884 885
(...skipping 18 matching lines...) Expand all
903 params->set_callback(creation_observer->callback()); 904 params->set_callback(creation_observer->callback());
904 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); 905 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass());
905 906
906 // Wait until the item is created, or we have determined that it 907 // Wait until the item is created, or we have determined that it
907 // won't be. 908 // won't be.
908 creation_observer->WaitForDownloadItemCreation(); 909 creation_observer->WaitForDownloadItemCreation();
909 910
910 EXPECT_EQ(download_info.show_download_item, 911 EXPECT_EQ(download_info.show_download_item,
911 creation_observer->succeeded()); 912 creation_observer->succeeded());
912 if (download_info.show_download_item) { 913 if (download_info.show_download_item) {
913 EXPECT_EQ(net::OK, creation_observer->error()); 914 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE,
915 creation_observer->interrupt_reason());
914 EXPECT_NE(content::DownloadItem::kInvalidId, 916 EXPECT_NE(content::DownloadItem::kInvalidId,
915 creation_observer->download_id()); 917 creation_observer->download_id());
916 } else { 918 } else {
917 EXPECT_NE(net::OK, creation_observer->error()); 919 EXPECT_NE(content::DOWNLOAD_INTERRUPT_REASON_NONE,
920 creation_observer->interrupt_reason());
918 EXPECT_EQ(content::DownloadItem::kInvalidId, 921 EXPECT_EQ(content::DownloadItem::kInvalidId,
919 creation_observer->download_id()); 922 creation_observer->download_id());
920 } 923 }
921 } else { 924 } else {
922 // Navigate to URL normally, wait until done. 925 // Navigate to URL normally, wait until done.
923 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), 926 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(),
924 url, 927 url,
925 1); 928 1);
926 } 929 }
927 930
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
993 } 996 }
994 997
995 void DownloadInsertFilesErrorCheckErrorsLoopBody( 998 void DownloadInsertFilesErrorCheckErrorsLoopBody(
996 scoped_refptr<content::TestFileErrorInjector> injector, 999 scoped_refptr<content::TestFileErrorInjector> injector,
997 const FileErrorInjectInfo& info, 1000 const FileErrorInjectInfo& info,
998 size_t i) { 1001 size_t i) {
999 std::stringstream s; 1002 std::stringstream s;
1000 s << " " << __FUNCTION__ << "()" 1003 s << " " << __FUNCTION__ << "()"
1001 << " index = " << i 1004 << " index = " << i
1002 << " url = " << info.error_info.url 1005 << " url = " << info.error_info.url
1003 << " operation code = " << 1006 << " operation code = "
1004 content::TestFileErrorInjector::DebugString( 1007 << content::TestFileErrorInjector::DebugString(info.error_info.code)
1005 info.error_info.code)
1006 << " instance = " << info.error_info.operation_instance 1008 << " instance = " << info.error_info.operation_instance
1007 << " error = " << content::InterruptReasonDebugString( 1009 << " error = "
1008 info.error_info.error); 1010 << content::DownloadInterruptReasonToString(info.error_info.error);
1009 1011
1010 injector->ClearErrors(); 1012 injector->ClearErrors();
1011 injector->AddError(info.error_info); 1013 injector->AddError(info.error_info);
1012 1014
1013 injector->InjectErrors(); 1015 injector->InjectErrors();
1014 1016
1015 DownloadFilesCheckErrorsLoopBody(info.download_info, i); 1017 DownloadFilesCheckErrorsLoopBody(info.download_info, i);
1016 1018
1017 size_t expected_successes = info.download_info.show_download_item ? 1u : 0u; 1019 size_t expected_successes = info.download_info.show_download_item ? 1u : 0u;
1018 EXPECT_EQ(expected_successes, injector->TotalFileCount()) << s.str(); 1020 EXPECT_EQ(expected_successes, injector->TotalFileCount()) << s.str();
(...skipping 2221 matching lines...) Expand 10 before | Expand all | Expand 10 after
3240 3242
3241 // No errors this time. The download should complete successfully. 3243 // No errors this time. The download should complete successfully.
3242 EXPECT_FALSE(completion_observer->IsFinished()); 3244 EXPECT_FALSE(completion_observer->IsFinished());
3243 completion_observer->StartObserving(); 3245 completion_observer->StartObserving();
3244 download->Resume(); 3246 download->Resume();
3245 completion_observer->WaitForFinished(); 3247 completion_observer->WaitForFinished();
3246 EXPECT_EQ(DownloadItem::COMPLETE, download->GetState()); 3248 EXPECT_EQ(DownloadItem::COMPLETE, download->GetState());
3247 3249
3248 EXPECT_FALSE(DidShowFileChooser()); 3250 EXPECT_FALSE(DidShowFileChooser());
3249 } 3251 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698