Commit 627dabbe authored by Nikita Podguzov's avatar Nikita Podguzov Committed by Commit Bot

Printing API: Fix broken browser tests

This CL:
* Changes the dialog modal type if it's anchored.
* Removes the extension name from dialog header getter call, as
corresponding string doesn't require it anymore.
* Adds the ability to skip confirmation dialog, as it's complicated to
interact with the dialog from the browser tests.

Bug: 1128197
Change-Id: Ie830049dde68398f605fd59025c7f4c985e3434b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2421673Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Commit-Queue: Nikita Podguzov <nikitapodguzov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809284}
parent 57aa838d
......@@ -57,9 +57,15 @@ constexpr int kIconSize = 64;
// handle requests.
bool g_disable_pdf_flattening_for_testing = false;
// Returns true if |extension_id| is in the allowlist.
// There is no easy way to interact with UI dialogs, so we want to have an
// ability to skip this stage for browser tests.
bool g_skip_confirmation_dialog_for_testing = false;
// Returns true if print job request dialog should be shown.
bool IsUserConfirmationRequired(content::BrowserContext* browser_context,
const std::string& extension_id) {
if (g_skip_confirmation_dialog_for_testing)
return false;
const base::ListValue* list =
Profile::FromBrowserContext(browser_context)
->GetPrefs()
......@@ -284,4 +290,9 @@ base::AutoReset<bool> PrintJobSubmitter::DisablePdfFlatteningForTesting() {
return base::AutoReset<bool>(&g_disable_pdf_flattening_for_testing, true);
}
// static
base::AutoReset<bool> PrintJobSubmitter::SkipConfirmationDialogForTesting() {
return base::AutoReset<bool>(&g_skip_confirmation_dialog_for_testing, true);
}
} // namespace extensions
......@@ -79,6 +79,8 @@ class PrintJobSubmitter {
static base::AutoReset<bool> DisablePdfFlatteningForTesting();
static base::AutoReset<bool> SkipConfirmationDialogForTesting();
private:
bool CheckContentType() const;
......
......@@ -157,6 +157,9 @@ IN_PROC_BROWSER_TEST_F(PrintingApiTest, SubmitJob) {
->SetPrintJobControllerForTesting(
std::make_unique<FakePrintJobController>(GetPrintJobManager(),
GetPrintersManager()));
base::AutoReset<bool> skip_confirmation_dialog_reset(
PrintJobSubmitter::SkipConfirmationDialogForTesting());
ASSERT_TRUE(RunExtensionSubtest("printing", "submit_job.html"));
}
......@@ -171,6 +174,8 @@ IN_PROC_BROWSER_TEST_F(PrintingApiTest, CancelJob) {
->SetPrintJobControllerForTesting(
std::make_unique<FakePrintJobController>(GetPrintJobManager(),
GetPrintersManager()));
base::AutoReset<bool> skip_confirmation_dialog_reset(
PrintJobSubmitter::SkipConfirmationDialogForTesting());
ASSERT_TRUE(RunExtensionSubtest("printing", "cancel_job.html"));
}
......
......@@ -94,6 +94,7 @@ PrintJobConfirmationDialogView::PrintJobConfirmationDialogView(
: views::BubbleBorder::NONE),
callback_(std::move(callback)),
dialog_is_bubble_(anchor_view != nullptr) {
SetModalType(dialog_is_bubble_ ? ui::MODAL_TYPE_NONE : ui::MODAL_TYPE_WINDOW);
SetButtonLabel(ui::DIALOG_BUTTON_OK,
l10n_util::GetStringUTF16(
IDS_EXTENSIONS_PRINTING_API_PRINT_REQUEST_ALLOW));
......@@ -106,8 +107,8 @@ PrintJobConfirmationDialogView::PrintJobConfirmationDialogView(
extension_icon, skia::ImageOperations::ResizeMethod::RESIZE_GOOD,
gfx::Size(extension_misc::EXTENSION_ICON_SMALL,
extension_misc::EXTENSION_ICON_SMALL)));
SetTitle(l10n_util::GetStringFUTF16(
IDS_EXTENSIONS_PRINTING_API_PRINT_REQUEST_BUBBLE_TITLE, extension_name));
SetTitle(l10n_util::GetStringUTF16(
IDS_EXTENSIONS_PRINTING_API_PRINT_REQUEST_BUBBLE_TITLE));
auto run_callback = [](PrintJobConfirmationDialogView* dialog, bool accept) {
std::move(dialog->callback_).Run(accept);
......@@ -153,10 +154,6 @@ gfx::Size PrintJobConfirmationDialogView::CalculatePreferredSize() const {
return gfx::Size(width, GetHeightForWidth(width));
}
ui::ModalType PrintJobConfirmationDialogView::GetModalType() const {
return ui::MODAL_TYPE_WINDOW;
}
namespace chrome {
void ShowPrintJobConfirmationDialog(gfx::NativeWindow parent,
......
......@@ -45,9 +45,6 @@ class PrintJobConfirmationDialogView : public views::BubbleDialogDelegateView {
// views::DialogDelegateView:
gfx::Size CalculatePreferredSize() const override;
// views::WidgetDelegate:
ui::ModalType GetModalType() const override;
// The name of the extension we are showing the dialog for.
const base::string16 extension_name_;
......
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