-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[M110] Support copying a file from the download bubble
This CL registers the DownloadBubbleRowView to listen for the copy accelerator so that we can write the file to clipboard. (cherry picked from commit 214f05e) Bug: 1394776 Change-Id: I559e5d944b10cf79eddf8087417a381cf3f60a66 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4093037 Commit-Queue: Daniel Rubery <drubery@chromium.org> Reviewed-by: Xinghui Lu <xinghuilu@chromium.org> Cr-Original-Commit-Position: refs/heads/main@{#1085049} Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4157872 Cr-Commit-Position: refs/branch-heads/5481@{#284} Cr-Branched-From: 130f3e4-refs/heads/main@{#1084008}
- Loading branch information
Daniel Rubery
authored and
Chromium LUCI CQ
committed
Jan 13, 2023
1 parent
ba2820f
commit 23ae4eb
Showing
4 changed files
with
166 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
chrome/browser/ui/views/download/bubble/download_bubble_row_view_unittest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright 2022 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/ui/views/download/bubble/download_bubble_row_view.h" | ||
|
||
#include "chrome/app/chrome_command_ids.h" | ||
#include "chrome/browser/download/download_item_model.h" | ||
#include "chrome/browser/ui/views/frame/browser_view.h" | ||
#include "chrome/browser/ui/views/frame/test_with_browser_view.h" | ||
#include "chrome/browser/ui/views/toolbar/toolbar_view.h" | ||
#include "components/download/public/common/mock_download_item.h" | ||
#include "components/safe_browsing/core/common/features.h" | ||
#include "content/public/browser/download_item_utils.h" | ||
#include "testing/gmock/include/gmock/gmock.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
#include "ui/base/clipboard/test/test_clipboard.h" | ||
|
||
namespace { | ||
|
||
using ::testing::NiceMock; | ||
using ::testing::Return; | ||
using ::testing::ReturnRefOfCopy; | ||
|
||
class DownloadBubbleRowViewTest : public TestWithBrowserView { | ||
public: | ||
DownloadBubbleRowViewTest() { | ||
scoped_feature_list_.InitAndEnableFeature(safe_browsing::kDownloadBubble); | ||
} | ||
|
||
DownloadBubbleRowViewTest(const DownloadBubbleRowViewTest&) = delete; | ||
DownloadBubbleRowViewTest& operator=(const DownloadBubbleRowViewTest&) = | ||
delete; | ||
|
||
void SetUp() override { | ||
TestWithBrowserView::SetUp(); | ||
|
||
content::DownloadItemUtils::AttachInfoForTesting( | ||
&download_item_, browser()->profile(), nullptr); | ||
ON_CALL(download_item_, GetRerouteInfo()) | ||
.WillByDefault(testing::ReturnRefOfCopy( | ||
enterprise_connectors::DownloadItemRerouteInfo())); | ||
|
||
DownloadToolbarButtonView* button = | ||
browser_view()->toolbar()->download_button(); | ||
row_list_view_ = std::make_unique<DownloadBubbleRowListView>( | ||
/*is_partial_view=*/true, browser()); | ||
row_view_ = std::make_unique<DownloadBubbleRowView>( | ||
DownloadItemModel::Wrap(&download_item_), row_list_view_.get(), | ||
button->bubble_controller(), button, browser()); | ||
} | ||
|
||
DownloadBubbleRowView* row_view() { return row_view_.get(); } | ||
download::MockDownloadItem* download_item() { return &download_item_; } | ||
|
||
private: | ||
base::test::ScopedFeatureList scoped_feature_list_; | ||
NiceMock<download::MockDownloadItem> download_item_; | ||
std::unique_ptr<DownloadBubbleRowListView> row_list_view_; | ||
std::unique_ptr<DownloadBubbleRowView> row_view_; | ||
}; | ||
|
||
TEST_F(DownloadBubbleRowViewTest, CopyAcceleratorCopiesFile) { | ||
#if BUILDFLAG(IS_WIN) | ||
base::FilePath target_path(FILE_PATH_LITERAL("\\test.exe")); | ||
#else | ||
base::FilePath target_path(FILE_PATH_LITERAL("/test.exe")); | ||
#endif | ||
ON_CALL(*download_item(), GetState()) | ||
.WillByDefault(Return(download::DownloadItem::COMPLETE)); | ||
ON_CALL(*download_item(), GetTargetFilePath()) | ||
.WillByDefault(ReturnRefOfCopy(target_path)); | ||
|
||
ui::TestClipboard* clipboard = ui::TestClipboard::CreateForCurrentThread(); | ||
|
||
ui::Accelerator accelerator; | ||
ASSERT_TRUE(browser_view()->GetAccelerator(IDC_COPY, &accelerator)); | ||
|
||
row_view()->AcceleratorPressed(accelerator); | ||
|
||
std::vector<ui::FileInfo> filenames; | ||
clipboard->ReadFilenames(ui::ClipboardBuffer::kCopyPaste, nullptr, | ||
&filenames); | ||
ASSERT_EQ(filenames.size(), 1u); | ||
EXPECT_EQ(filenames[0].path, target_path); | ||
|
||
clipboard->DestroyClipboardForCurrentThread(); | ||
} | ||
|
||
} // namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters