| 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 // Send a series of hit test requests, and for each one | 119 // Send a series of hit test requests, and for each one |
| 120 // wait for the hover event in response, verifying we hit the | 120 // wait for the hover event in response, verifying we hit the |
| 121 // correct object. | 121 // correct object. |
| 122 | 122 |
| 123 // (50, 50) -> "Button" | 123 // (50, 50) -> "Button" |
| 124 BrowserAccessibility* hovered_node; | 124 BrowserAccessibility* hovered_node; |
| 125 hovered_node = HitTestAndWaitForResult(gfx::Point(50, 50)); | 125 hovered_node = HitTestAndWaitForResult(gfx::Point(50, 50)); |
| 126 ASSERT_TRUE(hovered_node != NULL); | 126 ASSERT_TRUE(hovered_node != NULL); |
| 127 ASSERT_EQ(ui::AX_ROLE_BUTTON, hovered_node->GetRole()); | 127 ASSERT_EQ(ui::AX_ROLE_BUTTON, hovered_node->GetRole()); |
| 128 ASSERT_EQ("Button", hovered_node->GetStringAttribute(ui::AX_ATTR_NAME)); | 128 ASSERT_EQ("Button", hovered_node->GetStringAttribute(ui::AX_ATTR_NAME)); |
| 129 gfx::Rect bounds = hovered_node->GetScreenBoundsRect(); |
| 130 EXPECT_EQ(250, bounds.width()); |
| 131 EXPECT_EQ(50, bounds.height()); |
| 129 | 132 |
| 130 // (50, 305) -> div in first iframe | 133 // (50, 305) -> div in first iframe |
| 131 hovered_node = HitTestAndWaitForResult(gfx::Point(50, 305)); | 134 hovered_node = HitTestAndWaitForResult(gfx::Point(50, 305)); |
| 132 ASSERT_TRUE(hovered_node != NULL); | 135 ASSERT_TRUE(hovered_node != NULL); |
| 133 ASSERT_EQ(ui::AX_ROLE_DIV, hovered_node->GetRole()); | 136 ASSERT_EQ(ui::AX_ROLE_DIV, hovered_node->GetRole()); |
| 134 | 137 |
| 135 // (50, 350) -> "Ordinary Button" | 138 // (50, 350) -> "Ordinary Button" |
| 136 hovered_node = HitTestAndWaitForResult(gfx::Point(50, 350)); | 139 hovered_node = HitTestAndWaitForResult(gfx::Point(50, 350)); |
| 137 ASSERT_TRUE(hovered_node != NULL); | 140 ASSERT_TRUE(hovered_node != NULL); |
| 138 ASSERT_EQ(ui::AX_ROLE_BUTTON, hovered_node->GetRole()); | 141 ASSERT_EQ(ui::AX_ROLE_BUTTON, hovered_node->GetRole()); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 hovered_node->GetStringAttribute(ui::AX_ATTR_NAME)); | 216 hovered_node->GetStringAttribute(ui::AX_ATTR_NAME)); |
| 214 | 217 |
| 215 // (50, 505) -> div in second iframe | 218 // (50, 505) -> div in second iframe |
| 216 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 505)); | 219 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 505)); |
| 217 ASSERT_TRUE(hovered_node != NULL); | 220 ASSERT_TRUE(hovered_node != NULL); |
| 218 ASSERT_NE(ui::AX_ROLE_DIV, hovered_node->GetRole()); | 221 ASSERT_NE(ui::AX_ROLE_DIV, hovered_node->GetRole()); |
| 219 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 505)); | 222 hovered_node = CallCachingAsyncHitTest(gfx::Point(50, 505)); |
| 220 ASSERT_EQ(ui::AX_ROLE_DIV, hovered_node->GetRole()); | 223 ASSERT_EQ(ui::AX_ROLE_DIV, hovered_node->GetRole()); |
| 221 } | 224 } |
| 222 | 225 |
| 226 #if defined(OS_WIN) |
| 227 IN_PROC_BROWSER_TEST_F(AccessibilityHitTestingBrowserTest, |
| 228 HitTestingWithDeviceScaleFactorOnWin) { |
| 229 host_resolver()->AddRule("*", "127.0.0.1"); |
| 230 ASSERT_TRUE(embedded_test_server()->Start()); |
| 231 |
| 232 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); |
| 233 |
| 234 AccessibilityNotificationWaiter waiter(shell()->web_contents(), |
| 235 kAccessibilityModeComplete, |
| 236 ui::AX_EVENT_LOAD_COMPLETE); |
| 237 GURL url(embedded_test_server()->GetURL( |
| 238 "/accessibility/html/iframe-coordinates.html")); |
| 239 NavigateToURL(shell(), url); |
| 240 waiter.WaitForNotification(); |
| 241 |
| 242 WaitForAccessibilityTreeToContainNodeWithName(shell()->web_contents(), |
| 243 "Ordinary Button"); |
| 244 WaitForAccessibilityTreeToContainNodeWithName(shell()->web_contents(), |
| 245 "Scrolled Button"); |
| 246 |
| 247 // Set device scale factor to 2.0. |
| 248 WebContentsImpl* web_contents = |
| 249 static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 250 BrowserAccessibilityManager* manager = |
| 251 web_contents->GetRootBrowserAccessibilityManager(); |
| 252 manager->UseCustomDeviceScaleFactorForTesting(2.0); |
| 253 |
| 254 // We're calling the hit test function internally, so the input coordinates |
| 255 // should not be transformed, but the resulting object's dimensions should |
| 256 // be halved (give or take a pixel due to rounding). |
| 257 |
| 258 // (50, 50) -> "Button" |
| 259 BrowserAccessibility* hovered_node; |
| 260 hovered_node = HitTestAndWaitForResult(gfx::Point(50, 50)); |
| 261 ASSERT_TRUE(hovered_node != NULL); |
| 262 ASSERT_EQ(ui::AX_ROLE_BUTTON, hovered_node->GetRole()); |
| 263 ASSERT_EQ("Button", hovered_node->GetStringAttribute(ui::AX_ATTR_NAME)); |
| 264 gfx::Rect bounds = hovered_node->GetScreenBoundsRect(); |
| 265 EXPECT_LE(std::abs(bounds.width() - 125), 1); |
| 266 EXPECT_LE(std::abs(bounds.height() - 25), 1); |
| 267 } |
| 268 #endif // defined(OS_WIN) |
| 269 |
| 223 } // namespace content | 270 } // namespace content |
| OLD | NEW |