Commit f5d02ccf authored by Julie Jeongeun Kim's avatar Julie Jeongeun Kim Committed by Commit Bot

[a11y] Return nullopt if GetIndexInParent() is called on the WebView

This CL returns nullopt if GetIndexInParent() is called on the WebView
as it's not the child list in its parent if it has the WebContent. It
fixes DCHECK error on GetIndexInParent().

AX-Relnotes: n/a.
Bug: 1147007
Change-Id: I3def3ac9a4abb2abac8d2ae7702e8979a7c90e35
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2552310
Commit-Queue: Julie Kim <jkim@igalia.com>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#830492}
parent 781c0035
......@@ -16,6 +16,8 @@
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test.h"
#include "ui/accessibility/platform/ax_platform_node.h"
#include "ui/accessibility/platform/ax_platform_node_base.h"
#include "ui/views/accessibility/view_accessibility.h"
class AuraLinuxAccessibilityInProcessBrowserTest : public InProcessBrowserTest {
public:
......@@ -219,3 +221,30 @@ IN_PROC_BROWSER_TEST_F(AuraLinuxAccessibilityInProcessBrowserTest,
DevToolsWindowTesting::CloseDevToolsWindowSync(devtools);
VerifyEmbedRelationships();
}
// Tests that it doesn't have DCHECK() error when GetIndexInParent() is called
// with the WebView.
IN_PROC_BROWSER_TEST_F(AuraLinuxAccessibilityInProcessBrowserTest,
GetIndexInParent) {
content::WebContents* active_web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_NE(nullptr, active_web_contents->GetRenderWidgetHostView()
->GetNativeViewAccessible());
EXPECT_EQ(1, browser()->tab_strip_model()->count());
EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser());
views::WebView* webview = browser_view->contents_web_view();
gfx::NativeViewAccessible accessible =
webview->GetViewAccessibility().GetNativeObject();
// Gets the index in its parents for the WebView.
base::Optional<int> index =
static_cast<ui::AXPlatformNodeBase*>(
ui::AXPlatformNode::FromNativeViewAccessible(accessible))
->GetIndexInParent();
// As the WebView is not exposed in the child list when it has the web
// content, it doesn't have the index in its parent.
EXPECT_EQ(false, index.has_value());
}
......@@ -161,6 +161,14 @@ base::Optional<int> AXPlatformNodeBase::GetIndexInParent() {
if (!parent)
return base::nullopt;
// If this is the webview, it is not in the child in the list of its parent's
// child.
// TODO(jkim): Check if we could remove this after making WebView ignored.
if (delegate_ &&
delegate_->GetNativeViewAccessible() != GetNativeViewAccessible()) {
return base::nullopt;
}
int child_count = parent->GetChildCount();
if (child_count == 0) {
// |child_count| could be 0 if the parent is IsLeaf.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment