Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <memory> | 5 #include <memory> |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 EXPECT_EQ(selection_range, | 297 EXPECT_EQ(selection_range, |
| 298 gfx::Range([AttributeValueAtMidpoint( | 298 gfx::Range([AttributeValueAtMidpoint( |
| 299 NSAccessibilitySelectedTextRangeAttribute) rangeValue])); | 299 NSAccessibilitySelectedTextRangeAttribute) rangeValue])); |
| 300 | 300 |
| 301 // NSAccessibilityVisibleCharacterRangeAttribute. | 301 // NSAccessibilityVisibleCharacterRangeAttribute. |
| 302 EXPECT_EQ(gfx::Range(0, kTestStringValue.length), | 302 EXPECT_EQ(gfx::Range(0, kTestStringValue.length), |
| 303 gfx::Range([AttributeValueAtMidpoint( | 303 gfx::Range([AttributeValueAtMidpoint( |
| 304 NSAccessibilityVisibleCharacterRangeAttribute) rangeValue])); | 304 NSAccessibilityVisibleCharacterRangeAttribute) rangeValue])); |
| 305 } | 305 } |
| 306 | 306 |
| 307 // Test writing accessibility attributes via an accessibility client. | 307 // Test writing accessibility attributes via an accessibility client for normal |
| 308 // Views. | |
| 309 TEST_F(NativeWidgetMacAccessibilityTest, ViewWritableAttributes) { | |
| 310 FlexibleRoleTestView* view = new FlexibleRoleTestView(ui::AX_ROLE_GROUP); | |
| 311 view->SetSize(GetWidgetBounds().size()); | |
| 312 widget()->GetContentsView()->AddChildView(view); | |
| 313 | |
| 314 // Get the FlexibleRoleTestView accessibility object. | |
| 315 NSPoint midpoint = gfx::ScreenPointToNSPoint(GetWidgetBounds().CenterPoint()); | |
| 316 id ax_node = [widget()->GetNativeWindow() accessibilityHitTest:midpoint]; | |
| 317 EXPECT_TRUE(ax_node); | |
| 318 | |
| 319 // Make sure it's the correct accessibility object. | |
| 320 id value = [ax_node accessibilityAttributeValue:NSAccessibilityRoleAttribute]; | |
| 321 EXPECT_NSEQ(NSAccessibilityGroupRole, value); | |
| 322 | |
| 323 // Make sure |view| is focusable, then focus/unfocus it. | |
| 324 view->SetFocusBehavior(ClientView::FocusBehavior::ALWAYS); | |
|
tapted
2016/11/11 00:36:25
ClientView -> View
Patti Lor
2016/11/14 03:51:21
Done.
| |
| 325 EXPECT_FALSE(view->HasFocus()); | |
| 326 EXPECT_EQ(NO, [AttributeValueAtMidpoint(NSAccessibilityFocusedAttribute) | |
|
tapted
2016/11/11 00:36:25
nit: I think I'd prefer EXPECT_FALSE rather than E
Patti Lor
2016/11/14 03:51:21
Done.
| |
| 327 boolValue]); | |
| 328 EXPECT_TRUE([ax_node | |
| 329 accessibilityIsAttributeSettable:NSAccessibilityFocusedAttribute]); | |
| 330 [ax_node accessibilitySetValue:[NSNumber numberWithBool:YES] | |
| 331 forAttribute:NSAccessibilityFocusedAttribute]; | |
| 332 EXPECT_EQ(YES, [AttributeValueAtMidpoint(NSAccessibilityFocusedAttribute) | |
|
tapted
2016/11/11 00:36:25
nit: EXPECT_TRUE
Patti Lor
2016/11/14 03:51:21
Done.
| |
| 333 boolValue]); | |
| 334 EXPECT_TRUE(view->HasFocus()); | |
| 335 } | |
| 336 | |
| 337 // Test writing accessibility attributes via an accessibility client for | |
| 338 // editable controls (in this case, views::Textfields). | |
| 308 TEST_F(NativeWidgetMacAccessibilityTest, TextfieldWritableAttributes) { | 339 TEST_F(NativeWidgetMacAccessibilityTest, TextfieldWritableAttributes) { |
| 309 Textfield* textfield = AddChildTextfield(GetWidgetBounds().size()); | 340 Textfield* textfield = AddChildTextfield(GetWidgetBounds().size()); |
| 310 | 341 |
| 311 // Get the textfield accessibility object. | 342 // Get the Textfield accessibility object. |
| 312 NSPoint midpoint = gfx::ScreenPointToNSPoint(GetWidgetBounds().CenterPoint()); | 343 NSPoint midpoint = gfx::ScreenPointToNSPoint(GetWidgetBounds().CenterPoint()); |
| 313 id ax_node = [widget()->GetNativeWindow() accessibilityHitTest:midpoint]; | 344 id ax_node = [widget()->GetNativeWindow() accessibilityHitTest:midpoint]; |
| 314 EXPECT_TRUE(ax_node); | 345 EXPECT_TRUE(ax_node); |
| 315 | 346 |
| 316 // Make sure it's the correct accessibility object. | 347 // Make sure it's the correct accessibility object. |
| 317 id value = | 348 id value = |
| 318 [ax_node accessibilityAttributeValue:NSAccessibilityValueAttribute]; | 349 [ax_node accessibilityAttributeValue:NSAccessibilityValueAttribute]; |
| 319 EXPECT_NSEQ(kTestStringValue, value); | 350 EXPECT_NSEQ(kTestStringValue, value); |
| 320 | 351 |
| 321 // Write a new NSAccessibilityValueAttribute. | 352 // Write a new NSAccessibilityValueAttribute. |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 376 forAttribute:NSAccessibilitySelectedTextAttribute]; | 407 forAttribute:NSAccessibilitySelectedTextAttribute]; |
| 377 EXPECT_NSEQ(new_string, | 408 EXPECT_NSEQ(new_string, |
| 378 AttributeValueAtMidpoint(NSAccessibilityValueAttribute)); | 409 AttributeValueAtMidpoint(NSAccessibilityValueAttribute)); |
| 379 EXPECT_EQ(base::SysNSStringToUTF16(new_string), textfield->text()); | 410 EXPECT_EQ(base::SysNSStringToUTF16(new_string), textfield->text()); |
| 380 // Make sure the cursor is at the end of the replacement. | 411 // Make sure the cursor is at the end of the replacement. |
| 381 EXPECT_EQ(gfx::Range(front.length() + replacement.length()), | 412 EXPECT_EQ(gfx::Range(front.length() + replacement.length()), |
| 382 textfield->GetSelectedRange()); | 413 textfield->GetSelectedRange()); |
| 383 } | 414 } |
| 384 | 415 |
| 385 } // namespace views | 416 } // namespace views |
| OLD | NEW |