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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/download/download_browsertest.cc
diff --git a/chrome/browser/download/download_browsertest.cc b/chrome/browser/download/download_browsertest.cc
index 51d3c9ca4c6f4d630b91b4e22728f0fa3176a51b..9a63aa68f9f94a3e9fb6f15e2514a7832c7eed48 100644
--- a/chrome/browser/download/download_browsertest.cc
+++ b/chrome/browser/download/download_browsertest.cc
@@ -48,6 +48,7 @@
#include "chrome/browser/net/url_request_mock_util.h"
#include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/browser/permissions/permission_request_manager.h"
+#include "chrome/browser/platform_util_internal.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/renderer_context_menu/render_view_context_menu_browsertest_util.h"
#include "chrome/browser/renderer_context_menu/render_view_context_menu_test_util.h"
@@ -163,6 +164,47 @@ class CreatedObserver : public content::DownloadManager::Observer {
DISALLOW_COPY_AND_ASSIGN(CreatedObserver);
};
+class ShownObserver : public content::DownloadItem::Observer {
+ public:
+ explicit ShownObserver(DownloadItem* item)
+ : item_(item),
+ waiting_(false) {
+ item->AddObserver(this);
+ }
+
+ ~ShownObserver() override {
+ if (item_)
+ item_->RemoveObserver(this);
+ }
+
+ void Wait() {
+ if (DownloadItemModel(item_).GetOpenedOrShown()) {
+ return;
+ }
+ waiting_ = true;
+ content::RunMessageLoop();
+ waiting_ = false;
+ }
+
+ private:
+ void OnDownloadShown(content::DownloadItem* item) override {
+ DCHECK_EQ(item_, item);
+ if (waiting_)
+ base::MessageLoopForUI::current()->QuitWhenIdle();
+ }
+
+ void OnDownloadDestroyed(content::DownloadItem* item) override {
+ DCHECK_EQ(item_, item);
+ item_->RemoveObserver(this);
+ item_ = NULL;
+ }
+
+ content::DownloadItem* item_;
+ bool waiting_;
+
+ DISALLOW_COPY_AND_ASSIGN(ShownObserver);
+};
+
class PercentWaiter : public content::DownloadItem::Observer {
public:
explicit PercentWaiter(DownloadItem* item)
@@ -420,6 +462,10 @@ class DownloadTest : public InProcessBrowserTest {
DownloadTest() {}
void SetUpOnMainThread() override {
+ // This prevents platfrom_util from invoking any shell or external APIs
+ // during tests. Doing so may result in external applications being launched
+ // and intefering with tests.
+ platform_util::internal::DisableShellOperationsForTesting();
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true));
@@ -3672,4 +3718,45 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, CrxDenyInstallClosesShelf) {
// Download shelf should close.
EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
}
-#endif // defined(OS_CHROMEOS)
+
+IN_PROC_BROWSER_TEST_F(DownloadTest, OpenClosesShelf) {
+ base::FilePath file(FILE_PATH_LITERAL(kDownloadTest1Path));
+ GURL url(URLRequestMockHTTPJob::GetMockUrl("download-test1.lib"));
+
+ DownloadAndWait(browser(), url);
+
+ std::vector<DownloadItem*> download_items;
+ GetDownloads(browser(), &download_items);
+ ASSERT_EQ(1UL, download_items.size());
+
+ ShownObserver observer(download_items[0]);
+ download_items[0]->OpenDownload();
+ observer.Wait();
+
+ EXPECT_TRUE(DownloadItemModel(download_items[0]).GetOpenedOrShown());
+
+ // Download shelf should close.
+ EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
+}
+
+IN_PROC_BROWSER_TEST_F(DownloadTest, ShowInShellClosesShelf) {
+ base::FilePath file(FILE_PATH_LITERAL(kDownloadTest1Path));
+ GURL url(URLRequestMockHTTPJob::GetMockUrl("download-test1.lib"));
+
+ DownloadAndWait(browser(), url);
+
+ std::vector<DownloadItem*> download_items;
+ GetDownloads(browser(), &download_items);
+ ASSERT_EQ(1UL, download_items.size());
+
+ ShownObserver observer(download_items[0]);
+ download_items[0]->ShowDownloadInShell();
+ observer.Wait();
+
+ EXPECT_TRUE(DownloadItemModel(download_items[0]).GetOpenedOrShown());
+
+ // Download shelf should close.
+ EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
+}
+
+#endif // !defined(OS_CHROMEOS)
« 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