Commit 2e94ca8d authored by Dominique Fauteux-Chapleau's avatar Dominique Fauteux-Chapleau Committed by Commit Bot

Add accessibility alert event when DeepScanningDialogViews changes

This allows a screen reader to read the updated text of the dialog.

Bug: 1131565
Change-Id: I73a2df8067ffc96148ebf5d50a9412cf34b67feb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2424841
Commit-Queue: Dominique Fauteux-Chapleau <domfc@chromium.org>
Reviewed-by: default avatarRoger Tawa <rogerta@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810290}
parent 36f318dc
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "ui/gfx/paint_vector_icon.h" #include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/text_constants.h" #include "ui/gfx/text_constants.h"
#include "ui/native_theme/native_theme.h" #include "ui/native_theme/native_theme.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/background.h" #include "ui/views/background.h"
#include "ui/views/border.h" #include "ui/views/border.h"
#include "ui/views/bubble/bubble_frame_view.h" #include "ui/views/bubble/bubble_frame_view.h"
...@@ -351,8 +352,11 @@ void DeepScanningDialogViews::UpdateDialog() { ...@@ -351,8 +352,11 @@ void DeepScanningDialogViews::UpdateDialog() {
// Update the buttons. // Update the buttons.
SetupButtons(); SetupButtons();
// Update the message's text. // Update the message's text, and send an alert for screen readers since the
message_->SetText(GetDialogMessage()); // text changed.
base::string16 new_message = GetDialogMessage();
message_->SetText(new_message);
message_->GetViewAccessibility().AnnounceText(std::move(new_message));
// Resize the dialog's height. This is needed since the text might take more // Resize the dialog's height. This is needed since the text might take more
// lines after changing. // lines after changing.
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#include "ui/views/controls/image_view.h" #include "ui/views/controls/image_view.h"
#include "ui/views/controls/throbber.h" #include "ui/views/controls/throbber.h"
#include "ui/views/test/ax_event_counter.h"
namespace safe_browsing { namespace safe_browsing {
...@@ -41,13 +42,15 @@ base::string16 text() { ...@@ -41,13 +42,15 @@ base::string16 text() {
// - It respects time constraints (minimum shown time, initial delay, timeout) // - It respects time constraints (minimum shown time, initial delay, timeout)
// - It is always destroyed, therefore |quit_closure_| is called in the dtor // - It is always destroyed, therefore |quit_closure_| is called in the dtor
// observer. // observer.
// - It sends accessibility events correctly.
class DeepScanningDialogViewsBehaviorBrowserTest class DeepScanningDialogViewsBehaviorBrowserTest
: public DeepScanningBrowserTestBase, : public DeepScanningBrowserTestBase,
public DeepScanningDialogViews::TestObserver, public DeepScanningDialogViews::TestObserver,
public testing::WithParamInterface< public testing::WithParamInterface<
std::tuple<bool, bool, base::TimeDelta>> { std::tuple<bool, bool, base::TimeDelta>> {
public: public:
DeepScanningDialogViewsBehaviorBrowserTest() { DeepScanningDialogViewsBehaviorBrowserTest()
: ax_event_counter_(views::AXEventManager::Get()) {
DeepScanningDialogViews::SetObserverForTesting(this); DeepScanningDialogViews::SetObserverForTesting(this);
expected_scan_result_ = dlp_success() && malware_success(); expected_scan_result_ = dlp_success() && malware_success();
...@@ -86,6 +89,11 @@ class DeepScanningDialogViewsBehaviorBrowserTest ...@@ -86,6 +89,11 @@ class DeepScanningDialogViewsBehaviorBrowserTest
// The dialog's buttons should be Cancel in the pending and fail case. // The dialog's buttons should be Cancel in the pending and fail case.
EXPECT_EQ(dialog_->GetDialogButtons(), ui::DIALOG_BUTTON_CANCEL); EXPECT_EQ(dialog_->GetDialogButtons(), ui::DIALOG_BUTTON_CANCEL);
// Record the number of AX events until now to check if the text update adds
// one later.
ax_events_count_when_first_shown_ =
ax_event_counter_.GetCount(ax::mojom::Event::kAlert);
// The dialog should only be shown once some time after being constructed. // The dialog should only be shown once some time after being constructed.
EXPECT_TRUE(ctor_called_); EXPECT_TRUE(ctor_called_);
EXPECT_FALSE(views_first_shown_); EXPECT_FALSE(views_first_shown_);
...@@ -122,6 +130,10 @@ class DeepScanningDialogViewsBehaviorBrowserTest ...@@ -122,6 +130,10 @@ class DeepScanningDialogViewsBehaviorBrowserTest
// The dialog should only be updated once some time after being shown. // The dialog should only be updated once some time after being shown.
EXPECT_TRUE(views_first_shown_); EXPECT_TRUE(views_first_shown_);
EXPECT_FALSE(dialog_updated_); EXPECT_FALSE(dialog_updated_);
// The dialog being updated implies an accessibility alert is sent.
EXPECT_EQ(ax_events_count_when_first_shown_ + 1,
ax_event_counter_.GetCount(ax::mojom::Event::kAlert));
dialog_updated_ = true; dialog_updated_ = true;
} }
...@@ -178,6 +190,9 @@ class DeepScanningDialogViewsBehaviorBrowserTest ...@@ -178,6 +190,9 @@ class DeepScanningDialogViewsBehaviorBrowserTest
bool dialog_updated_ = false; bool dialog_updated_ = false;
bool expected_scan_result_; bool expected_scan_result_;
int ax_events_count_when_first_shown_ = 0;
views::test::AXEventCounter ax_event_counter_;
}; };
// Tests the behavior of the dialog in the following ways: // Tests the behavior of the dialog in the following ways:
......
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