| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/logging.h" | 5 #include "base/logging.h" |
| 6 #include "content/browser/accessibility/browser_accessibility.h" | 6 #include "content/browser/accessibility/browser_accessibility.h" |
| 7 #include "content/browser/accessibility/browser_accessibility_manager.h" | 7 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| 8 #include "content/browser/web_contents/web_contents_impl.h" | 8 #include "content/browser/web_contents/web_contents_impl.h" |
| 9 #include "content/public/test/browser_test_utils.h" | 9 #include "content/public/test/browser_test_utils.h" |
| 10 #include "content/public/test/content_browser_test.h" | 10 #include "content/public/test/content_browser_test.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 // Send a series of hit test requests, and for each one | 126 // Send a series of hit test requests, and for each one |
| 127 // wait for the hover event in response, verifying we hit the | 127 // wait for the hover event in response, verifying we hit the |
| 128 // correct object. | 128 // correct object. |
| 129 | 129 |
| 130 // (50, 50) -> "Button" | 130 // (50, 50) -> "Button" |
| 131 BrowserAccessibility* hit_node; | 131 BrowserAccessibility* hit_node; |
| 132 hit_node = HitTestAndWaitForResult(gfx::Point(50, 50)); | 132 hit_node = HitTestAndWaitForResult(gfx::Point(50, 50)); |
| 133 ASSERT_TRUE(hit_node != NULL); | 133 ASSERT_TRUE(hit_node != NULL); |
| 134 ASSERT_EQ(ui::AX_ROLE_BUTTON, hit_node->GetRole()); | 134 ASSERT_EQ(ui::AX_ROLE_BUTTON, hit_node->GetRole()); |
| 135 ASSERT_EQ("Button", hit_node->GetStringAttribute(ui::AX_ATTR_NAME)); | 135 ASSERT_EQ("Button", hit_node->GetStringAttribute(ui::AX_ATTR_NAME)); |
| 136 gfx::Rect bounds = hit_node->GetScreenBoundsRect(); | |
| 137 EXPECT_EQ(250, bounds.width()); | |
| 138 EXPECT_EQ(50, bounds.height()); | |
| 139 | 136 |
| 140 // (50, 305) -> div in first iframe | 137 // (50, 305) -> div in first iframe |
| 141 hit_node = HitTestAndWaitForResult(gfx::Point(50, 305)); | 138 hit_node = HitTestAndWaitForResult(gfx::Point(50, 305)); |
| 142 ASSERT_TRUE(hit_node != NULL); | 139 ASSERT_TRUE(hit_node != NULL); |
| 143 ASSERT_EQ(ui::AX_ROLE_DIV, hit_node->GetRole()); | 140 ASSERT_EQ(ui::AX_ROLE_DIV, hit_node->GetRole()); |
| 144 | 141 |
| 145 // (50, 350) -> "Ordinary Button" | 142 // (50, 350) -> "Ordinary Button" |
| 146 hit_node = HitTestAndWaitForResult(gfx::Point(50, 350)); | 143 hit_node = HitTestAndWaitForResult(gfx::Point(50, 350)); |
| 147 ASSERT_TRUE(hit_node != NULL); | 144 ASSERT_TRUE(hit_node != NULL); |
| 148 ASSERT_EQ(ui::AX_ROLE_BUTTON, hit_node->GetRole()); | 145 ASSERT_EQ(ui::AX_ROLE_BUTTON, hit_node->GetRole()); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 ASSERT_EQ("Scrolled Button", hit_node->GetStringAttribute(ui::AX_ATTR_NAME)); | 223 ASSERT_EQ("Scrolled Button", hit_node->GetStringAttribute(ui::AX_ATTR_NAME)); |
| 227 | 224 |
| 228 // (50, 505) -> div in second iframe | 225 // (50, 505) -> div in second iframe |
| 229 hit_node = CallCachingAsyncHitTest(gfx::Point(50, 505)); | 226 hit_node = CallCachingAsyncHitTest(gfx::Point(50, 505)); |
| 230 ASSERT_TRUE(hit_node != NULL); | 227 ASSERT_TRUE(hit_node != NULL); |
| 231 ASSERT_NE(ui::AX_ROLE_DIV, hit_node->GetRole()); | 228 ASSERT_NE(ui::AX_ROLE_DIV, hit_node->GetRole()); |
| 232 hit_node = CallCachingAsyncHitTest(gfx::Point(50, 505)); | 229 hit_node = CallCachingAsyncHitTest(gfx::Point(50, 505)); |
| 233 ASSERT_EQ(ui::AX_ROLE_DIV, hit_node->GetRole()); | 230 ASSERT_EQ(ui::AX_ROLE_DIV, hit_node->GetRole()); |
| 234 } | 231 } |
| 235 | 232 |
| 236 #if defined(OS_WIN) | |
| 237 IN_PROC_BROWSER_TEST_F(AccessibilityHitTestingBrowserTest, | |
| 238 HitTestingWithDeviceScaleFactorOnWin) { | |
| 239 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 240 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 241 | |
| 242 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); | |
| 243 | |
| 244 AccessibilityNotificationWaiter waiter(shell()->web_contents(), | |
| 245 kAccessibilityModeComplete, | |
| 246 ui::AX_EVENT_LOAD_COMPLETE); | |
| 247 GURL url(embedded_test_server()->GetURL( | |
| 248 "/accessibility/html/iframe-coordinates.html")); | |
| 249 NavigateToURL(shell(), url); | |
| 250 waiter.WaitForNotification(); | |
| 251 | |
| 252 WaitForAccessibilityTreeToContainNodeWithName(shell()->web_contents(), | |
| 253 "Ordinary Button"); | |
| 254 WaitForAccessibilityTreeToContainNodeWithName(shell()->web_contents(), | |
| 255 "Scrolled Button"); | |
| 256 | |
| 257 // Set device scale factor to 2.0. | |
| 258 WebContentsImpl* web_contents = | |
| 259 static_cast<WebContentsImpl*>(shell()->web_contents()); | |
| 260 BrowserAccessibilityManager* manager = | |
| 261 web_contents->GetRootBrowserAccessibilityManager(); | |
| 262 manager->UseCustomDeviceScaleFactorForTesting(2.0); | |
| 263 | |
| 264 // We're calling the hit test function internally, so the input coordinates | |
| 265 // should not be transformed, but the resulting object's dimensions should | |
| 266 // be halved (give or take a pixel due to rounding). | |
| 267 | |
| 268 // (50, 50) -> "Button" | |
| 269 BrowserAccessibility* hovered_node; | |
| 270 hovered_node = HitTestAndWaitForResult(gfx::Point(50, 50)); | |
| 271 ASSERT_TRUE(hovered_node != NULL); | |
| 272 ASSERT_EQ(ui::AX_ROLE_BUTTON, hovered_node->GetRole()); | |
| 273 ASSERT_EQ("Button", hovered_node->GetStringAttribute(ui::AX_ATTR_NAME)); | |
| 274 gfx::Rect bounds = hovered_node->GetScreenBoundsRect(); | |
| 275 EXPECT_LE(std::abs(bounds.width() - 125), 1); | |
| 276 EXPECT_LE(std::abs(bounds.height() - 25), 1); | |
| 277 } | |
| 278 #endif // defined(OS_WIN) | |
| 279 | |
| 280 } // namespace content | 233 } // namespace content |
| OLD | NEW |