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

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

Issue 209613002: Download shelf autohides on showing in shell, just same as regular open Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added browser and unit tests. Renamed 'UserActed' to 'OpenedOrShown'. Created 4 years, 1 month 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
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 "chrome/browser/download/download_browsertest.h" 5 #include "chrome/browser/download/download_browsertest.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <sstream> 8 #include <sstream>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 30 matching lines...) Expand all
41 #include "chrome/browser/download/download_service_factory.h" 41 #include "chrome/browser/download/download_service_factory.h"
42 #include "chrome/browser/download/download_shelf.h" 42 #include "chrome/browser/download/download_shelf.h"
43 #include "chrome/browser/download/download_target_determiner.h" 43 #include "chrome/browser/download/download_target_determiner.h"
44 #include "chrome/browser/download/download_test_file_activity_observer.h" 44 #include "chrome/browser/download/download_test_file_activity_observer.h"
45 #include "chrome/browser/extensions/extension_service.h" 45 #include "chrome/browser/extensions/extension_service.h"
46 #include "chrome/browser/history/history_service_factory.h" 46 #include "chrome/browser/history/history_service_factory.h"
47 #include "chrome/browser/infobars/infobar_service.h" 47 #include "chrome/browser/infobars/infobar_service.h"
48 #include "chrome/browser/net/url_request_mock_util.h" 48 #include "chrome/browser/net/url_request_mock_util.h"
49 #include "chrome/browser/notifications/notification_ui_manager.h" 49 #include "chrome/browser/notifications/notification_ui_manager.h"
50 #include "chrome/browser/permissions/permission_request_manager.h" 50 #include "chrome/browser/permissions/permission_request_manager.h"
51 #include "chrome/browser/platform_util_internal.h"
51 #include "chrome/browser/profiles/profile.h" 52 #include "chrome/browser/profiles/profile.h"
52 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert est_util.h" 53 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert est_util.h"
53 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h" 54 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h"
54 #include "chrome/browser/ui/browser.h" 55 #include "chrome/browser/ui/browser.h"
55 #include "chrome/browser/ui/browser_commands.h" 56 #include "chrome/browser/ui/browser_commands.h"
56 #include "chrome/browser/ui/browser_finder.h" 57 #include "chrome/browser/ui/browser_finder.h"
57 #include "chrome/browser/ui/browser_list.h" 58 #include "chrome/browser/ui/browser_list.h"
58 #include "chrome/browser/ui/browser_tabstrip.h" 59 #include "chrome/browser/ui/browser_tabstrip.h"
59 #include "chrome/browser/ui/browser_window.h" 60 #include "chrome/browser/ui/browser_window.h"
60 #include "chrome/browser/ui/chrome_pages.h" 61 #include "chrome/browser/ui/chrome_pages.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 if (waiting_) 157 if (waiting_)
157 base::MessageLoopForUI::current()->QuitWhenIdle(); 158 base::MessageLoopForUI::current()->QuitWhenIdle();
158 } 159 }
159 160
160 content::DownloadManager* manager_; 161 content::DownloadManager* manager_;
161 bool waiting_; 162 bool waiting_;
162 163
163 DISALLOW_COPY_AND_ASSIGN(CreatedObserver); 164 DISALLOW_COPY_AND_ASSIGN(CreatedObserver);
164 }; 165 };
165 166
167 class ShownObserver : public content::DownloadItem::Observer {
168 public:
169 explicit ShownObserver(DownloadItem* item)
170 : item_(item),
171 waiting_(false) {
172 item->AddObserver(this);
173 }
174
175 ~ShownObserver() override {
176 if (item_)
177 item_->RemoveObserver(this);
178 }
179
180 void Wait() {
181 if (DownloadItemModel(item_).GetOpenedOrShown()) {
182 return;
183 }
184 waiting_ = true;
185 content::RunMessageLoop();
186 waiting_ = false;
187 }
188
189 private:
190 void OnDownloadShown(content::DownloadItem* item) override {
191 DCHECK_EQ(item_, item);
192 if (waiting_)
193 base::MessageLoopForUI::current()->QuitWhenIdle();
194 }
195
196 void OnDownloadDestroyed(content::DownloadItem* item) override {
197 DCHECK_EQ(item_, item);
198 item_->RemoveObserver(this);
199 item_ = NULL;
200 }
201
202 content::DownloadItem* item_;
203 bool waiting_;
204
205 DISALLOW_COPY_AND_ASSIGN(ShownObserver);
206 };
207
166 class PercentWaiter : public content::DownloadItem::Observer { 208 class PercentWaiter : public content::DownloadItem::Observer {
167 public: 209 public:
168 explicit PercentWaiter(DownloadItem* item) 210 explicit PercentWaiter(DownloadItem* item)
169 : item_(item), 211 : item_(item),
170 waiting_(false), 212 waiting_(false),
171 error_(false), 213 error_(false),
172 prev_percent_(0) { 214 prev_percent_(0) {
173 item_->AddObserver(this); 215 item_->AddObserver(this);
174 } 216 }
175 ~PercentWaiter() override { 217 ~PercentWaiter() override {
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 }; 455 };
414 456
415 struct FileErrorInjectInfo { 457 struct FileErrorInjectInfo {
416 DownloadInfo download_info; 458 DownloadInfo download_info;
417 content::TestFileErrorInjector::FileErrorInfo error_info; 459 content::TestFileErrorInjector::FileErrorInfo error_info;
418 }; 460 };
419 461
420 DownloadTest() {} 462 DownloadTest() {}
421 463
422 void SetUpOnMainThread() override { 464 void SetUpOnMainThread() override {
465 // This prevents platfrom_util from invoking any shell or external APIs
466 // during tests. Doing so may result in external applications being launched
467 // and intefering with tests.
468 platform_util::internal::DisableShellOperationsForTesting();
423 BrowserThread::PostTask( 469 BrowserThread::PostTask(
424 BrowserThread::IO, FROM_HERE, 470 BrowserThread::IO, FROM_HERE,
425 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); 471 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true));
426 ASSERT_TRUE(InitialSetup()); 472 ASSERT_TRUE(InitialSetup());
427 } 473 }
428 474
429 void TearDownOnMainThread() override { 475 void TearDownOnMainThread() override {
430 // Needs to be torn down on the main thread. file_activity_observer_ holds a 476 // Needs to be torn down on the main thread. file_activity_observer_ holds a
431 // reference to the ChromeDownloadManagerDelegate which should be destroyed 477 // reference to the ChromeDownloadManagerDelegate which should be destroyed
432 // on the UI thread. 478 // on the UI thread.
(...skipping 3232 matching lines...) Expand 10 before | Expand all | Expand 10 after
3665 DangerousDownloadWaiter( 3711 DangerousDownloadWaiter(
3666 browser(), 1, 3712 browser(), 1,
3667 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); 3713 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY));
3668 ui_test_utils::NavigateToURL(browser(), extension_url); 3714 ui_test_utils::NavigateToURL(browser(), extension_url);
3669 3715
3670 observer->WaitForFinished(); 3716 observer->WaitForFinished();
3671 3717
3672 // Download shelf should close. 3718 // Download shelf should close.
3673 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 3719 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
3674 } 3720 }
3675 #endif // defined(OS_CHROMEOS) 3721
3722 IN_PROC_BROWSER_TEST_F(DownloadTest, OpenClosesShelf) {
3723 base::FilePath file(FILE_PATH_LITERAL(kDownloadTest1Path));
3724 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-test1.lib"));
3725
3726 DownloadAndWait(browser(), url);
3727
3728 std::vector<DownloadItem*> download_items;
3729 GetDownloads(browser(), &download_items);
3730 ASSERT_EQ(1UL, download_items.size());
3731
3732 ShownObserver observer(download_items[0]);
3733 download_items[0]->OpenDownload();
3734 observer.Wait();
3735
3736 EXPECT_TRUE(DownloadItemModel(download_items[0]).GetOpenedOrShown());
3737
3738 // Download shelf should close.
3739 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
3740 }
3741
3742 IN_PROC_BROWSER_TEST_F(DownloadTest, ShowInShellClosesShelf) {
3743 base::FilePath file(FILE_PATH_LITERAL(kDownloadTest1Path));
3744 GURL url(URLRequestMockHTTPJob::GetMockUrl("download-test1.lib"));
3745
3746 DownloadAndWait(browser(), url);
3747
3748 std::vector<DownloadItem*> download_items;
3749 GetDownloads(browser(), &download_items);
3750 ASSERT_EQ(1UL, download_items.size());
3751
3752 ShownObserver observer(download_items[0]);
3753 download_items[0]->ShowDownloadInShell();
3754 observer.Wait();
3755
3756 EXPECT_TRUE(DownloadItemModel(download_items[0]).GetOpenedOrShown());
3757
3758 // Download shelf should close.
3759 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
3760 }
3761
3762 #endif // !defined(OS_CHROMEOS)
OLDNEW
« no previous file with comments | « chrome/browser/download/chrome_download_manager_delegate.cc ('k') | chrome/browser/download/download_item_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698