0

[views-ax] Migration of kProtected state in access_code_input

This CL migrates the kProtected state in Views to be updated
whenever its value should change, rather than querying the value
and computing it only when needed.

This CL is part of the ViewsAX project:
https://docs.google.com/document/d/1Ku7HOyDsiZem1yaV6ccZ-tz3lO2XR2NEcm8HjR6d-VY/edit#heading=h.ke1u3utej413

Bug: 325137417
Change-Id: I643f88887ae2683cdfda05d1c6a659a28c2ac87f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5672320
Commit-Queue: Gaurav Kumar <gauravkum@microsoft.com>
Reviewed-by: Javier Contreras <javiercon@microsoft.com>
Reviewed-by: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1329346}
This commit is contained in:
Gaurav Kumar
2024-07-18 06:44:29 +00:00
committed by Chromium LUCI CQ
parent 6f567d3ebb
commit 6674189ad1
2 changed files with 25 additions and 3 deletions

@ -284,6 +284,7 @@ FixedLengthCodeInput::FixedLengthCodeInput(int length,
layout->SetFlexForView(field, 1);
}
text_value_for_a11y_ = std::u16string(length, ' ');
GetViewAccessibility().SetIsProtected(is_obscure_pin_);
}
FixedLengthCodeInput::~FixedLengthCodeInput() = default;
@ -400,9 +401,7 @@ void FixedLengthCodeInput::GetAccessibleNodeData(ui::AXNodeData* node_data) {
const gfx::Range& range = GetSelectedRangeOfTextValueForA11y();
node_data->AddIntAttribute(ax::mojom::IntAttribute::kTextSelStart,
range.start());
if (is_obscure_pin_) {
node_data->AddState(ax::mojom::State::kProtected);
}
node_data->AddIntAttribute(ax::mojom::IntAttribute::kTextSelEnd, range.end());
}

@ -11,7 +11,9 @@
#include "ash/test/ash_test_base.h"
#include "base/strings/string_number_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/ime/text_input_client.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/controls/textfield/textfield.h"
namespace ash {
@ -40,6 +42,15 @@ class FixedLengthCodeInputTest : public AshTestBase {
base::BindRepeating(&FixedLengthCodeInputTest::OnEscape,
base::Unretained(this)),
/*obscure_pin=*/false);
obscure_input_view_ = std::make_unique<FixedLengthCodeInput>(
fixed_pin_length,
base::BindRepeating(&FixedLengthCodeInputTest::OnInputChange,
base::Unretained(this)),
base::BindRepeating(&FixedLengthCodeInputTest::OnEnter,
base::Unretained(this)),
base::BindRepeating(&FixedLengthCodeInputTest::OnEscape,
base::Unretained(this)),
/*obscure_pin=*/true);
}
void TearDown() override { AshTestBase::TearDown(); }
@ -56,6 +67,7 @@ class FixedLengthCodeInputTest : public AshTestBase {
void OnEscape() { ++on_escape_count; }
std::unique_ptr<FixedLengthCodeInput> input_view_;
std::unique_ptr<FixedLengthCodeInput> obscure_input_view_;
int on_input_change_count = 0;
int on_input_change_complete_count = 0;
@ -85,6 +97,17 @@ TEST_F(FixedLengthCodeInputTest, ContentsChangedWithDigits) {
EXPECT_EQ(on_escape_count, 0);
}
TEST_F(FixedLengthCodeInputTest, AccessibilityStateIsProtected) {
ui::AXNodeData data;
input_view_->GetViewAccessibility().GetAccessibleNodeData(&data);
EXPECT_FALSE(data.HasState(ax::mojom::State::kProtected));
data = ui::AXNodeData();
obscure_input_view_->GetViewAccessibility().GetAccessibleNodeData(&data);
EXPECT_TRUE(data.HasState(ax::mojom::State::kProtected));
}
// Validates that the FixedLengthCodeInput::ContentsChanged() method handles
// and ignores correctly when the Textfield::InsertText() method is called
// with multipledigit.