OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "core/dom/AccessibleNode.h" | 5 #include "core/dom/AccessibleNode.h" |
6 #include "core/html/HTMLBodyElement.h" | 6 #include "core/html/HTMLBodyElement.h" |
7 #include "modules/accessibility/AXObjectCacheImpl.h" | 7 #include "modules/accessibility/AXObjectCacheImpl.h" |
8 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" | 8 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" |
9 #include "web/tests/sim/SimRequest.h" | 9 #include "web/tests/sim/SimRequest.h" |
10 #include "web/tests/sim/SimTest.h" | 10 #include "web/tests/sim/SimTest.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 | 51 |
52 auto* axButton = cache->GetOrCreate(button); | 52 auto* axButton = cache->GetOrCreate(button); |
53 EXPECT_EQ(kButtonRole, axButton->RoleValue()); | 53 EXPECT_EQ(kButtonRole, axButton->RoleValue()); |
54 | 54 |
55 button->accessibleNode()->setRole("slider"); | 55 button->accessibleNode()->setRole("slider"); |
56 EXPECT_EQ("slider", button->accessibleNode()->role()); | 56 EXPECT_EQ("slider", button->accessibleNode()->role()); |
57 | 57 |
58 EXPECT_EQ(kSliderRole, axButton->RoleValue()); | 58 EXPECT_EQ(kSliderRole, axButton->RoleValue()); |
59 } | 59 } |
60 | 60 |
| 61 TEST_F(AccessibilityObjectModelTest, AOMDoesNotReflectARIA) { |
| 62 SimRequest main_resource("https://example.com/", "text/html"); |
| 63 LoadURL("https://example.com/"); |
| 64 main_resource.Complete("<input id=textbox>"); |
| 65 |
| 66 // Set ARIA attributes. |
| 67 auto* textbox = GetDocument().getElementById("textbox"); |
| 68 ASSERT_NE(nullptr, textbox); |
| 69 textbox->setAttribute("role", "combobox"); |
| 70 textbox->setAttribute("aria-label", "Combo"); |
| 71 textbox->setAttribute("aria-disabled", "true"); |
| 72 |
| 73 // Assert that the ARIA attributes affect the AX object. |
| 74 auto* cache = AXObjectCache(); |
| 75 ASSERT_NE(nullptr, cache); |
| 76 auto* axTextBox = cache->GetOrCreate(textbox); |
| 77 EXPECT_EQ(kComboBoxRole, axTextBox->RoleValue()); |
| 78 AXNameFrom name_from; |
| 79 AXObjectImpl::AXObjectVector name_objects; |
| 80 EXPECT_EQ("Combo", axTextBox->GetName(name_from, &name_objects)); |
| 81 EXPECT_FALSE(axTextBox->IsEnabled()); |
| 82 |
| 83 // The AOM properties should still all be null. |
| 84 EXPECT_EQ(nullptr, textbox->accessibleNode()->role()); |
| 85 EXPECT_EQ(nullptr, textbox->accessibleNode()->label()); |
| 86 bool is_null = false; |
| 87 EXPECT_FALSE(textbox->accessibleNode()->disabled(is_null)); |
| 88 EXPECT_TRUE(is_null); |
| 89 } |
| 90 |
| 91 TEST_F(AccessibilityObjectModelTest, AOMPropertiesCanBeCleared) { |
| 92 SimRequest main_resource("https://example.com/", "text/html"); |
| 93 LoadURL("https://example.com/"); |
| 94 main_resource.Complete("<input type=button id=button>"); |
| 95 |
| 96 // Set ARIA attributes. |
| 97 auto* button = GetDocument().getElementById("button"); |
| 98 ASSERT_NE(nullptr, button); |
| 99 button->setAttribute("role", "checkbox"); |
| 100 button->setAttribute("aria-label", "Check"); |
| 101 button->setAttribute("aria-disabled", "true"); |
| 102 |
| 103 // Assert that the AX object was affected by ARIA attributes. |
| 104 auto* cache = AXObjectCache(); |
| 105 ASSERT_NE(nullptr, cache); |
| 106 auto* axButton = cache->GetOrCreate(button); |
| 107 EXPECT_EQ(kCheckBoxRole, axButton->RoleValue()); |
| 108 AXNameFrom name_from; |
| 109 AXObjectImpl::AXObjectVector name_objects; |
| 110 EXPECT_EQ("Check", axButton->GetName(name_from, &name_objects)); |
| 111 EXPECT_FALSE(axButton->IsEnabled()); |
| 112 |
| 113 // Now set the AOM properties to override. |
| 114 button->accessibleNode()->setRole("radio"); |
| 115 button->accessibleNode()->setLabel("Radio"); |
| 116 button->accessibleNode()->setDisabled(false, false); |
| 117 |
| 118 // Assert that the AX object was affected by AOM properties. |
| 119 EXPECT_EQ(kRadioButtonRole, axButton->RoleValue()); |
| 120 EXPECT_EQ("Radio", axButton->GetName(name_from, &name_objects)); |
| 121 EXPECT_TRUE(axButton->IsEnabled()); |
| 122 |
| 123 // Null the AOM properties. |
| 124 button->accessibleNode()->setRole(g_null_atom); |
| 125 button->accessibleNode()->setLabel(g_null_atom); |
| 126 button->accessibleNode()->setDisabled(false, true); |
| 127 |
| 128 // The AX Object should now revert to ARIA. |
| 129 EXPECT_EQ(kCheckBoxRole, axButton->RoleValue()); |
| 130 EXPECT_EQ("Check", axButton->GetName(name_from, &name_objects)); |
| 131 EXPECT_FALSE(axButton->IsEnabled()); |
| 132 } |
| 133 |
61 } // namespace | 134 } // namespace |
62 | 135 |
63 } // namespace blink | 136 } // namespace blink |
OLD | NEW |