Commit 2aa99b91 authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

views: run callback when download-in-progress dialog closes

Fixed: 1064138
Change-Id: I6693327ee56c6d70eac93a2bb1fabe81a4a45e31
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2134389
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#755983}
parent 44babb59
......@@ -55,6 +55,8 @@ DownloadInProgressDialogView::DownloadInProgressDialogView(
base::BindOnce(run_callback, base::Unretained(this), true));
DialogDelegate::SetCancelCallback(
base::BindOnce(run_callback, base::Unretained(this), false));
DialogDelegate::SetCloseCallback(
base::BindOnce(run_callback, base::Unretained(this), false));
int message_id = 0;
switch (dialog_type) {
......@@ -83,7 +85,7 @@ DownloadInProgressDialogView::DownloadInProgressDialogView(
chrome::RecordDialogCreation(chrome::DialogIdentifier::DOWNLOAD_IN_PROGRESS);
}
DownloadInProgressDialogView::~DownloadInProgressDialogView() {}
DownloadInProgressDialogView::~DownloadInProgressDialogView() = default;
gfx::Size DownloadInProgressDialogView::CalculatePreferredSize() const {
const int width = ChromeLayoutProvider::Get()->GetDistanceMetric(
......@@ -104,3 +106,7 @@ base::string16 DownloadInProgressDialogView::GetWindowTitle() const {
return l10n_util::GetPluralStringFUTF16(IDS_ABANDON_DOWNLOAD_DIALOG_TITLE,
download_count_);
}
BEGIN_METADATA(DownloadInProgressDialogView)
METADATA_PARENT_CLASS(views::DialogDelegateView);
END_METADATA()
......@@ -14,6 +14,8 @@
// while a download is in progress.
class DownloadInProgressDialogView : public views::DialogDelegateView {
public:
METADATA_HEADER(DownloadInProgressDialogView);
// |dialog_type| should be either DOWNLOAD_CLOSE_BROWSER_SHUTDOWN to indicate
// the user is closing the browser or
// DOWNLOAD_CLOSE_LAST_WINDOW_IN_INCOGNITO_PROFILE to indicate the user is
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// 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/download_in_progress_dialog_view.h"
#include "base/optional.h"
#include "base/test/bind_test_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/views/chrome_constrained_window_views_client.h"
#include "chrome/test/views/chrome_views_test_base.h"
#include "components/constrained_window/constrained_window_views.h"
#include "ui/views/widget/any_widget_observer.h"
using DownloadInProgressDialogTest = ChromeViewsTestBase;
// This checks that DownloadInProgressDialogView runs its completion callback
// even if the dialog is closed by the user without selecting an option. It is a
// regression test for https://crbug.com/1064138.
TEST_F(DownloadInProgressDialogTest, CallbackIsRunOnClose) {
SetConstrainedWindowViewsClient(CreateChromeConstrainedWindowViewsClient());
auto parent = CreateTestWidget();
parent->Show();
base::Optional<bool> result;
views::NamedWidgetShownWaiter waiter(views::test::AnyWidgetTestPasskey(),
"DownloadInProgressDialogView");
DownloadInProgressDialogView::Show(
parent->GetNativeWindow(), 1,
Browser::DownloadCloseType::kBrowserShutdown, false,
base::BindLambdaForTesting([&](bool b) { result = b; }));
waiter.WaitIfNeededAndGet()->Close();
ASSERT_TRUE(result.has_value());
EXPECT_FALSE(result.value());
}
......@@ -5305,6 +5305,7 @@ test("unit_tests") {
"../browser/ui/views/content_setting_bubble_contents_unittest.cc",
"../browser/ui/views/desktop_capture/desktop_media_picker_views_unittest.cc",
"../browser/ui/views/device_chooser_content_view_unittest.cc",
"../browser/ui/views/download/download_in_progress_dialog_view_unittest.cc",
"../browser/ui/views/download/download_item_view_unittest.cc",
"../browser/ui/views/extensions/chooser_dialog_view_unittest.cc",
"../browser/ui/views/extensions/extensions_menu_item_unittest.cc",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment