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

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

Issue 976823002: Add new test: DownloadTest.TestMultipleDownloadsBubble (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Wait until bubble is shown Created 5 years, 9 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
« no previous file with comments | « no previous file | no next file » | 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/files/file.h" 10 #include "base/files/file.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h" 49 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h"
50 #include "chrome/browser/ui/browser.h" 50 #include "chrome/browser/ui/browser.h"
51 #include "chrome/browser/ui/browser_commands.h" 51 #include "chrome/browser/ui/browser_commands.h"
52 #include "chrome/browser/ui/browser_finder.h" 52 #include "chrome/browser/ui/browser_finder.h"
53 #include "chrome/browser/ui/browser_list.h" 53 #include "chrome/browser/ui/browser_list.h"
54 #include "chrome/browser/ui/browser_tabstrip.h" 54 #include "chrome/browser/ui/browser_tabstrip.h"
55 #include "chrome/browser/ui/browser_window.h" 55 #include "chrome/browser/ui/browser_window.h"
56 #include "chrome/browser/ui/chrome_pages.h" 56 #include "chrome/browser/ui/chrome_pages.h"
57 #include "chrome/browser/ui/host_desktop.h" 57 #include "chrome/browser/ui/host_desktop.h"
58 #include "chrome/browser/ui/tabs/tab_strip_model.h" 58 #include "chrome/browser/ui/tabs/tab_strip_model.h"
59 #include "chrome/browser/ui/website_settings/mock_permission_bubble_view.h"
60 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
59 #include "chrome/common/chrome_paths.h" 61 #include "chrome/common/chrome_paths.h"
62 #include "chrome/common/chrome_switches.h"
60 #include "chrome/common/pref_names.h" 63 #include "chrome/common/pref_names.h"
61 #include "chrome/common/safe_browsing/csd.pb.h" 64 #include "chrome/common/safe_browsing/csd.pb.h"
62 #include "chrome/common/url_constants.h" 65 #include "chrome/common/url_constants.h"
63 #include "chrome/grit/generated_resources.h" 66 #include "chrome/grit/generated_resources.h"
64 #include "chrome/test/base/in_process_browser_test.h" 67 #include "chrome/test/base/in_process_browser_test.h"
65 #include "chrome/test/base/test_switches.h" 68 #include "chrome/test/base/test_switches.h"
66 #include "chrome/test/base/ui_test_utils.h" 69 #include "chrome/test/base/ui_test_utils.h"
67 #include "components/history/content/browser/download_constants_utils.h" 70 #include "components/history/content/browser/download_constants_utils.h"
68 #include "components/history/core/browser/download_constants.h" 71 #include "components/history/core/browser/download_constants.h"
69 #include "components/history/core/browser/download_row.h" 72 #include "components/history/core/browser/download_row.h"
(...skipping 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 return NULL; 1086 return NULL;
1084 1087
1085 error_injector->ClearErrors(); 1088 error_injector->ClearErrors();
1086 error_injector->InjectErrors(); 1089 error_injector->InjectErrors();
1087 DownloadItem* download = downloads[0]; 1090 DownloadItem* download = downloads[0];
1088 EXPECT_EQ(DownloadItem::INTERRUPTED, download->GetState()); 1091 EXPECT_EQ(DownloadItem::INTERRUPTED, download->GetState());
1089 EXPECT_EQ(error, download->GetLastReason()); 1092 EXPECT_EQ(error, download->GetLastReason());
1090 return download; 1093 return download;
1091 } 1094 }
1092 1095
1096 void WaitForBubble(MockPermissionBubbleView* mock_bubble) {
1097 if (mock_bubble->IsVisible())
1098 return;
1099 content::RunMessageLoop();
1100 }
1101
1093 private: 1102 private:
1094 static void EnsureNoPendingDownloadJobsOnIO(bool* result) { 1103 static void EnsureNoPendingDownloadJobsOnIO(bool* result) {
1095 if (net::URLRequestSlowDownloadJob::NumberOutstandingRequests()) 1104 if (net::URLRequestSlowDownloadJob::NumberOutstandingRequests())
1096 *result = false; 1105 *result = false;
1097 BrowserThread::PostTask( 1106 BrowserThread::PostTask(
1098 BrowserThread::UI, FROM_HERE, base::MessageLoop::QuitClosure()); 1107 BrowserThread::UI, FROM_HERE, base::MessageLoop::QuitClosure());
1099 } 1108 }
1100 1109
1101 // Location of the test data. 1110 // Location of the test data.
1102 base::FilePath test_dir_; 1111 base::FilePath test_dir_;
(...skipping 1782 matching lines...) Expand 10 before | Expand all | Expand 10 after
2885 IN_PROC_BROWSER_TEST_F(DownloadTest, TestMultipleDownloadsInfobar) { 2894 IN_PROC_BROWSER_TEST_F(DownloadTest, TestMultipleDownloadsInfobar) {
2886 #if defined(OS_WIN) && defined(USE_ASH) 2895 #if defined(OS_WIN) && defined(USE_ASH)
2887 // Disable this test in Metro+Ash for now (http://crbug.com/262796). 2896 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
2888 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 2897 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
2889 switches::kAshBrowserTests)) 2898 switches::kAshBrowserTests))
2890 return; 2899 return;
2891 #endif 2900 #endif
2892 2901
2893 ASSERT_TRUE(test_server()->Start()); 2902 ASSERT_TRUE(test_server()->Start());
2894 2903
2904 // Ensure that infobars are being used instead of bubbles.
2905 base::CommandLine::ForCurrentProcess()->AppendSwitch(
2906 switches::kDisablePermissionsBubbles);
2907
2895 // Create a downloads observer. 2908 // Create a downloads observer.
2896 scoped_ptr<content::DownloadTestObserver> downloads_observer( 2909 scoped_ptr<content::DownloadTestObserver> downloads_observer(
2897 CreateWaiter(browser(), 2)); 2910 CreateWaiter(browser(), 2));
2898 2911
2899 // Create an infobar observer. 2912 // Create an infobar observer.
2900 content::WindowedNotificationObserver infobar_added_1( 2913 content::WindowedNotificationObserver infobar_added_1(
2901 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, 2914 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED,
2902 content::NotificationService::AllSources()); 2915 content::NotificationService::AllSources());
2903 ui_test_utils::NavigateToURL( 2916 ui_test_utils::NavigateToURL(
2904 browser(), 2917 browser(),
(...skipping 20 matching lines...) Expand all
2925 infobar_service->RemoveInfoBar(infobar); 2938 infobar_service->RemoveInfoBar(infobar);
2926 // Verify that there are no more infobars. 2939 // Verify that there are no more infobars.
2927 EXPECT_EQ(0u, infobar_service->infobar_count()); 2940 EXPECT_EQ(0u, infobar_service->infobar_count());
2928 2941
2929 // Waits for the download to complete. 2942 // Waits for the download to complete.
2930 downloads_observer->WaitForFinished(); 2943 downloads_observer->WaitForFinished();
2931 EXPECT_EQ(2u, downloads_observer->NumDownloadsSeenInState( 2944 EXPECT_EQ(2u, downloads_observer->NumDownloadsSeenInState(
2932 DownloadItem::COMPLETE)); 2945 DownloadItem::COMPLETE));
2933 } 2946 }
2934 2947
2948 IN_PROC_BROWSER_TEST_F(DownloadTest, TestMultipleDownloadsBubble) {
2949 #if defined(OS_WIN) && defined(USE_ASH)
2950 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
2951 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
2952 switches::kAshBrowserTests))
2953 return;
2954 #endif
2955
2956 #if defined(OS_ANDROID) || defined(OS_IOS)
2957 // Permission bubbles are not supported on mobile.
2958 return;
2959 #endif
2960
2961 ASSERT_TRUE(test_server()->Start());
2962
2963 // Enable permision bubbles.
2964 base::CommandLine::ForCurrentProcess()->AppendSwitch(
2965 switches::kEnablePermissionsBubbles);
2966
2967 // Create a downloads observer.
2968 scoped_ptr<content::DownloadTestObserver> downloads_observer(
2969 CreateWaiter(browser(), 2));
2970
2971 MockPermissionBubbleView* mock_bubble_view = new MockPermissionBubbleView();
2972 PermissionBubbleManager::FromWebContents(
2973 browser()->tab_strip_model()->GetActiveWebContents())->
2974 SetView(mock_bubble_view);
2975 mock_bubble_view->SetBrowserTest(true);
2976 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
2977 browser(),
2978 test_server()->GetURL("files/downloads/download-a_zip_file.html"), 1);
2979
2980 WaitForBubble(mock_bubble_view);
2981
2982 ASSERT_TRUE(mock_bubble_view->IsVisible());
2983 mock_bubble_view->Accept();
2984 ASSERT_FALSE(mock_bubble_view->IsVisible());
2985
2986 // Waits for the download to complete.
2987 downloads_observer->WaitForFinished();
2988 EXPECT_EQ(2u, downloads_observer->NumDownloadsSeenInState(
2989 DownloadItem::COMPLETE));
2990
2991 browser()->tab_strip_model()->GetActiveWebContents()->Close();
2992 delete mock_bubble_view;
2993 }
2994
2935 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadTest_Renaming) { 2995 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadTest_Renaming) {
2936 ASSERT_TRUE(test_server()->Start()); 2996 ASSERT_TRUE(test_server()->Start());
2937 GURL url(test_server()->GetURL("files/downloads/a_zip_file.zip")); 2997 GURL url(test_server()->GetURL("files/downloads/a_zip_file.zip"));
2938 content::DownloadManager* manager = DownloadManagerForBrowser(browser()); 2998 content::DownloadManager* manager = DownloadManagerForBrowser(browser());
2939 base::FilePath origin_file(OriginFile(base::FilePath(FILE_PATH_LITERAL( 2999 base::FilePath origin_file(OriginFile(base::FilePath(FILE_PATH_LITERAL(
2940 "downloads/a_zip_file.zip")))); 3000 "downloads/a_zip_file.zip"))));
2941 ASSERT_TRUE(base::PathExists(origin_file)); 3001 ASSERT_TRUE(base::PathExists(origin_file));
2942 std::string origin_contents; 3002 std::string origin_contents;
2943 ASSERT_TRUE(base::ReadFileToString(origin_file, &origin_contents)); 3003 ASSERT_TRUE(base::ReadFileToString(origin_file, &origin_contents));
2944 3004
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
3525 *(downloads[0]))); 3585 *(downloads[0])));
3526 3586
3527 // Begin feedback and check that the file is "stolen". 3587 // Begin feedback and check that the file is "stolen".
3528 download_protection_service->feedback_service()->BeginFeedbackForDownload( 3588 download_protection_service->feedback_service()->BeginFeedbackForDownload(
3529 downloads[0]); 3589 downloads[0]);
3530 std::vector<DownloadItem*> updated_downloads; 3590 std::vector<DownloadItem*> updated_downloads;
3531 GetDownloads(browser(), &updated_downloads); 3591 GetDownloads(browser(), &updated_downloads);
3532 ASSERT_TRUE(updated_downloads.empty()); 3592 ASSERT_TRUE(updated_downloads.empty());
3533 } 3593 }
3534 #endif 3594 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698