OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <tuple> | 5 #include <tuple> |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 GetLastAccEvent(&event); | 261 GetLastAccEvent(&event); |
262 | 262 |
263 ASSERT_EQ(3U, event.update.nodes.size()); | 263 ASSERT_EQ(3U, event.update.nodes.size()); |
264 EXPECT_EQ(node_a.axID(), event.update.node_id_to_clear); | 264 EXPECT_EQ(node_a.axID(), event.update.node_id_to_clear); |
265 EXPECT_EQ(node_a.axID(), event.update.nodes[0].id); | 265 EXPECT_EQ(node_a.axID(), event.update.nodes[0].id); |
266 EXPECT_EQ(node_b.axID(), event.update.nodes[1].id); | 266 EXPECT_EQ(node_b.axID(), event.update.nodes[1].id); |
267 EXPECT_EQ(node_c.axID(), event.update.nodes[2].id); | 267 EXPECT_EQ(node_c.axID(), event.update.nodes[2].id); |
268 EXPECT_EQ(3, CountAccessibilityNodesSentToBrowser()); | 268 EXPECT_EQ(3, CountAccessibilityNodesSentToBrowser()); |
269 } | 269 } |
270 | 270 |
| 271 TEST_F(RenderAccessibilityImplTest, DetachAccessibilityObject) { |
| 272 // Test RenderAccessibilityImpl and make sure it sends the |
| 273 // proper event to the browser when an object in the tree |
| 274 // is detached, but its children are not. This can happen when |
| 275 // a layout occurs and an anonymous render block is no longer needed. |
| 276 std::string html = |
| 277 "<body aria-label='Body'>" |
| 278 "<span>1</span><span style='display:block'>2</span>" |
| 279 "</body>"; |
| 280 LoadHTML(html.c_str()); |
| 281 |
| 282 std::unique_ptr<TestRenderAccessibilityImpl> accessibility( |
| 283 new TestRenderAccessibilityImpl(frame())); |
| 284 accessibility->SendPendingAccessibilityEvents(); |
| 285 EXPECT_EQ(7, CountAccessibilityNodesSentToBrowser()); |
| 286 |
| 287 // Initially, the accessibility tree looks like this: |
| 288 // |
| 289 // Document |
| 290 // +--Body |
| 291 // +--Anonymous Block |
| 292 // +--Static Text "1" |
| 293 // +--Inline Text Box "1" |
| 294 // +--Static Text "2" |
| 295 // +--Inline Text Box "2" |
| 296 WebDocument document = view()->GetWebView()->mainFrame()->document(); |
| 297 WebAXObject root_obj = document.accessibilityObject(); |
| 298 WebAXObject body = root_obj.childAt(0); |
| 299 WebAXObject anonymous_block = body.childAt(0); |
| 300 WebAXObject text_1 = anonymous_block.childAt(0); |
| 301 WebAXObject text_2 = body.childAt(1); |
| 302 |
| 303 // Change the display of the second 'span' back to inline, which causes the |
| 304 // anonymous block to be destroyed. |
| 305 ExecuteJavaScriptForTests( |
| 306 "document.querySelectorAll('span')[1].style.display = 'inline';"); |
| 307 // Force layout now. |
| 308 ExecuteJavaScriptForTests("document.body.offsetLeft;"); |
| 309 |
| 310 // Send a childrenChanged on the body. |
| 311 sink_->ClearMessages(); |
| 312 accessibility->HandleAXEvent( |
| 313 body, |
| 314 ui::AX_EVENT_CHILDREN_CHANGED); |
| 315 |
| 316 accessibility->SendPendingAccessibilityEvents(); |
| 317 |
| 318 // Afterwards, the accessibility tree looks like this: |
| 319 // |
| 320 // Document |
| 321 // +--Body |
| 322 // +--Static Text "1" |
| 323 // +--Inline Text Box "1" |
| 324 // +--Static Text "2" |
| 325 // +--Inline Text Box "2" |
| 326 // |
| 327 // We just assert that there are now four nodes in the |
| 328 // accessibility tree and that only three nodes needed |
| 329 // to be updated (the body, the static text 1, and |
| 330 // the static text 2). |
| 331 |
| 332 AccessibilityHostMsg_EventParams event; |
| 333 GetLastAccEvent(&event); |
| 334 ASSERT_EQ(5U, event.update.nodes.size()); |
| 335 |
| 336 EXPECT_EQ(body.axID(), event.update.nodes[0].id); |
| 337 EXPECT_EQ(text_1.axID(), event.update.nodes[1].id); |
| 338 // The third event is to update text_2, but its id changes |
| 339 // so we don't have a test expectation for it. |
| 340 } |
| 341 |
271 } // namespace content | 342 } // namespace content |
OLD | NEW |