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 "base/macros.h" | 5 #include "base/macros.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "base/time/time.h" | 7 #include "base/time/time.h" |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "content/common/accessibility_messages.h" | 9 #include "content/common/accessibility_messages.h" |
10 #include "content/common/frame_messages.h" | 10 #include "content/common/frame_messages.h" |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 AccessibilityHostMsg_EventParams event; | 396 AccessibilityHostMsg_EventParams event; |
397 GetLastAccEvent(&event); | 397 GetLastAccEvent(&event); |
398 ASSERT_EQ(5U, event.update.nodes.size()); | 398 ASSERT_EQ(5U, event.update.nodes.size()); |
399 | 399 |
400 EXPECT_EQ(body.axID(), event.update.nodes[0].id); | 400 EXPECT_EQ(body.axID(), event.update.nodes[0].id); |
401 EXPECT_EQ(text_1.axID(), event.update.nodes[1].id); | 401 EXPECT_EQ(text_1.axID(), event.update.nodes[1].id); |
402 // The third event is to update text_2, but its id changes | 402 // The third event is to update text_2, but its id changes |
403 // so we don't have a test expectation for it. | 403 // so we don't have a test expectation for it. |
404 } | 404 } |
405 | 405 |
406 TEST_F(RendererAccessibilityTest, EventOnDetachedNodeTriggersMainFrameLayout) { | |
407 std::string html = | |
408 "<body>" | |
409 " <iframe srcdoc='<input>'></iframe>" | |
410 " <button>Button</button>" | |
411 "</body>"; | |
412 LoadHTML(html.c_str()); | |
413 | |
414 scoped_ptr<TestRendererAccessibility> accessibility( | |
415 new TestRendererAccessibility(frame())); | |
416 accessibility->SendPendingAccessibilityEvents(); | |
417 | |
418 WebDocument document = view()->GetWebView()->mainFrame()->document(); | |
419 WebAXObject root_obj = document.accessibilityObject(); | |
420 ASSERT_EQ(blink::WebAXRoleWebArea, root_obj.role()); | |
421 WebAXObject group = root_obj.childAt(0); | |
422 ASSERT_EQ(blink::WebAXRoleGroup, group.role()); | |
423 WebAXObject iframe = group.childAt(0); | |
424 ASSERT_EQ(blink::WebAXRoleIframe, iframe.role()); | |
425 WebAXObject child_doc = iframe.childAt(0); | |
426 ASSERT_EQ(blink::WebAXRoleWebArea, child_doc.role()); | |
427 WebAXObject child_group = child_doc.childAt(0); | |
428 ASSERT_EQ(blink::WebAXRoleGroup, child_group.role()); | |
429 WebAXObject child_textfield = child_group.childAt(0); | |
430 ASSERT_EQ(blink::WebAXRoleTextField, child_textfield.role()); | |
431 | |
432 // Hide the input element inside the iframe. | |
433 ExecuteJavaScriptForTests( | |
434 "document.querySelector('iframe').contentDocument" | |
435 ".querySelector('input').style.display = 'none';"); | |
436 accessibility->HandleAXEvent( | |
437 child_textfield, | |
438 ui::AX_EVENT_LAYOUT_COMPLETE); | |
439 accessibility->SendPendingAccessibilityEvents(); | |
440 | |
441 // Make sure |child_textfield| is invalid now. | |
442 ASSERT_TRUE(child_textfield.isDetached()); | |
443 | |
444 // Now do a random style change in the iframe to make its layout not clean. | |
445 ExecuteJavaScriptForTests( | |
446 "var doc = document.querySelector('iframe').contentDocument; " | |
447 "doc.body.style.backgroundColor = '#f00';"); | |
448 | |
449 // Now try to handle a "layout complete" event on the detached textfield | |
450 // object. The event handling will be a no-op, but the layout complete | |
451 // will trigger calling SendLocationChanges. Make sure that | |
452 // SendLocationChanges doesn't depend on layout in the main frame being | |
453 // clean. | |
454 // | |
455 // If this doesn't crash, the test passes. | |
456 accessibility->HandleAXEvent(child_textfield, | |
457 ui::AX_EVENT_LAYOUT_COMPLETE); | |
458 accessibility->SendPendingAccessibilityEvents(); | |
459 } | |
460 | |
461 } // namespace content | 406 } // namespace content |
OLD | NEW |