Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(412)

Unified Diff: content/browser/accessibility/hit_testing_browsertest.cc

Issue 2393123002: Implement caching asynchronous accessibility hit testing. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/accessibility/hit_testing_browsertest.cc
diff --git a/content/browser/accessibility/hit_testing_browsertest.cc b/content/browser/accessibility/hit_testing_browsertest.cc
index f1e6d9e3179e9836e83bf9cb9bec2a4d70a810e6..f854e9e6895904c3f69f0fe06ff3b7960ada5225 100644
--- a/content/browser/accessibility/hit_testing_browsertest.cc
+++ b/content/browser/accessibility/hit_testing_browsertest.cc
@@ -2,28 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include <set>
-#include <string>
-#include <vector>
-
-#include "base/command_line.h"
-#include "base/files/file_util.h"
#include "base/logging.h"
-#include "base/strings/string16.h"
-#include "base/strings/string_split.h"
-#include "base/strings/string_util.h"
-#include "base/strings/utf_string_conversions.h"
-#include "content/browser/accessibility/accessibility_tree_formatter.h"
#include "content/browser/accessibility/browser_accessibility.h"
#include "content/browser/accessibility/browser_accessibility_manager.h"
#include "content/browser/web_contents/web_contents_impl.h"
-#include "content/public/browser/web_contents.h"
-#include "content/public/common/content_paths.h"
-#include "content/public/common/content_switches.h"
-#include "content/public/common/url_constants.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
+#include "content/public/test/test_utils.h"
#include "content/shell/browser/shell.h"
#include "content/test/accessibility_browser_test_utils.h"
#include "net/dns/mock_host_resolver.h"
@@ -59,6 +45,16 @@ class AccessibilityHitTestingBrowserTest : public ContentBrowserTest {
target_manager->GetFromID(hover_target_id);
return hovered_node;
}
+
+ BrowserAccessibility* CallCachingAsyncHitTest(const gfx::Point& point) {
+ WebContentsImpl* web_contents =
+ static_cast<WebContentsImpl*>(shell()->web_contents());
+ BrowserAccessibilityManager* manager =
+ web_contents->GetRootBrowserAccessibilityManager();
+ gfx::Point screen_point =
+ point + manager->GetViewBounds().OffsetFromOrigin();
+ return manager->CachingAsyncHitTest(screen_point);
+ }
};
IN_PROC_BROWSER_TEST_F(AccessibilityHitTestingBrowserTest,
@@ -144,4 +140,82 @@ IN_PROC_BROWSER_TEST_F(AccessibilityHitTestingBrowserTest,
ASSERT_EQ(ui::AX_ROLE_DIV, hovered_node->GetRole());
}
+IN_PROC_BROWSER_TEST_F(AccessibilityHitTestingBrowserTest,
+ CachingAsyncHitTestingInIframes) {
+ host_resolver()->AddRule("*", "127.0.0.1");
+ ASSERT_TRUE(embedded_test_server()->Start());
+
+ NavigateToURL(shell(), GURL(url::kAboutBlankURL));
+
+ AccessibilityNotificationWaiter waiter(shell()->web_contents(),
+ AccessibilityModeComplete,
+ ui::AX_EVENT_LOAD_COMPLETE);
+ GURL url(embedded_test_server()->GetURL(
+ "/accessibility/hit_testing/hit_testing.html"));
+ NavigateToURL(shell(), url);
+ waiter.WaitForNotification();
+
+ WaitForAccessibilityTreeToContainNodeWithName(
+ shell()->web_contents(), "Ordinary Button");
+ WaitForAccessibilityTreeToContainNodeWithName(
+ shell()->web_contents(), "Scrolled Button");
+
+ // For each point we try, the first time we call CachingAsyncHitTest it
+ // should FAIL and return the wrong object, because this test page has
+ // been designed to confound local synchronous hit testing using
+ // z-indexes. However, calling CachingAsyncHitTest repeatedly should
+ // soon return the correct result.
+
+ // (50, 50) -> "Button"
+ BrowserAccessibility* hovered_node;
+ hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 50));
+ ASSERT_TRUE(hovered_node != NULL);
+ ASSERT_NE(ui::AX_ROLE_BUTTON, hovered_node->GetRole());
+ while (hovered_node->GetRole() != ui::AX_ROLE_BUTTON) {
+ RunAllPendingInMessageLoop();
+ hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 50));
+ }
+ ASSERT_EQ("Button", hovered_node->GetStringAttribute(ui::AX_ATTR_NAME));
+
+ // (50, 305) -> div in first iframe
+ hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 305));
+ ASSERT_TRUE(hovered_node != NULL);
+ ASSERT_NE(ui::AX_ROLE_DIV, hovered_node->GetRole());
+ while (hovered_node->GetRole() != ui::AX_ROLE_DIV) {
+ RunAllPendingInMessageLoop();
+ hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 305));
+ }
+
+ // (50, 350) -> "Ordinary Button"
+ hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 350));
+ ASSERT_TRUE(hovered_node != NULL);
+ ASSERT_NE(ui::AX_ROLE_BUTTON, hovered_node->GetRole());
+ while (hovered_node->GetRole() != ui::AX_ROLE_BUTTON) {
+ RunAllPendingInMessageLoop();
+ hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 350));
+ }
+ ASSERT_EQ("Ordinary Button",
+ hovered_node->GetStringAttribute(ui::AX_ATTR_NAME));
+
+ // (50, 455) -> "Scrolled Button"
+ hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 455));
+ ASSERT_TRUE(hovered_node != NULL);
+ ASSERT_NE(ui::AX_ROLE_BUTTON, hovered_node->GetRole());
+ while (hovered_node->GetRole() != ui::AX_ROLE_BUTTON) {
+ RunAllPendingInMessageLoop();
+ hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 455));
+ }
+ ASSERT_EQ("Scrolled Button",
+ hovered_node->GetStringAttribute(ui::AX_ATTR_NAME));
+
+ // (50, 505) -> div in second iframe
+ hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 505));
+ ASSERT_TRUE(hovered_node != NULL);
+ ASSERT_NE(ui::AX_ROLE_DIV, hovered_node->GetRole());
+ while (hovered_node->GetRole() != ui::AX_ROLE_DIV) {
+ RunAllPendingInMessageLoop();
+ hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 505));
+ }
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698