OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "base/win/scoped_comptr.h" | 6 #include "base/win/scoped_comptr.h" |
7 #include "content/browser/accessibility/browser_accessibility_manager.h" | 7 #include "content/browser/accessibility/browser_accessibility_manager.h" |
8 #include "content/browser/accessibility/browser_accessibility_win.h" | 8 #include "content/browser/accessibility/browser_accessibility_win.h" |
9 #include "content/common/view_messages.h" | 9 #include "content/common/view_messages.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 | 358 |
359 ASSERT_EQ(S_OK, text1_obj->get_text(0, IA2_TEXT_OFFSET_LENGTH, &text)); | 359 ASSERT_EQ(S_OK, text1_obj->get_text(0, IA2_TEXT_OFFSET_LENGTH, &text)); |
360 ASSERT_EQ(text, string16(L"One two three.\nFour five six.")); | 360 ASSERT_EQ(text, string16(L"One two three.\nFour five six.")); |
361 SysFreeString(text); | 361 SysFreeString(text); |
362 | 362 |
363 // Delete the manager and test that all BrowserAccessibility instances are | 363 // Delete the manager and test that all BrowserAccessibility instances are |
364 // deleted. | 364 // deleted. |
365 delete manager; | 365 delete manager; |
366 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); | 366 ASSERT_EQ(0, CountedBrowserAccessibility::global_obj_count_); |
367 } | 367 } |
| 368 |
| 369 TEST_F(BrowserAccessibilityTest, TestScrollingLogic) { |
| 370 #define SCROLL BrowserAccessibility::ComputeBestScrollOffset |
| 371 |
| 372 // Test some cases where the focus is already within the viewport. |
| 373 EXPECT_EQ(0, SCROLL(0, 25, 75, 25, 75, 0, 100)); |
| 374 EXPECT_EQ(100, SCROLL(100, 125, 175, 125, 175, 0, 100)); |
| 375 EXPECT_EQ(105, SCROLL(105, 125, 175, 125, 175, 0, 100)); |
| 376 EXPECT_EQ(125, SCROLL(125, 125, 175, 125, 175, 0, 100)); |
| 377 EXPECT_EQ(75, SCROLL(75, 125, 175, 125, 175, 0, 100)); |
| 378 |
| 379 // Subfocus should be ignored if focus is already within the viewport. |
| 380 EXPECT_EQ(100, SCROLL(100, 125, 125, 125, 175, 0, 100)); |
| 381 EXPECT_EQ(100, SCROLL(100, 175, 175, 125, 175, 0, 100)); |
| 382 EXPECT_EQ(100, SCROLL(100, -50, -50, 125, 175, 0, 100)); |
| 383 |
| 384 // Test some cases where the focus needs to be scrolled to fit. |
| 385 EXPECT_EQ(75, SCROLL(74, 125, 175, 125, 175, 0, 100)); |
| 386 EXPECT_EQ(75, SCROLL(50, 125, 175, 125, 175, 0, 100)); |
| 387 EXPECT_EQ(75, SCROLL(0, 125, 175, 125, 175, 0, 100)); |
| 388 EXPECT_EQ(125, SCROLL(126, 125, 175, 125, 175, 0, 100)); |
| 389 EXPECT_EQ(125, SCROLL(150, 125, 175, 125, 175, 0, 100)); |
| 390 EXPECT_EQ(125, SCROLL(200, 125, 175, 125, 175, 0, 100)); |
| 391 |
| 392 // Test some cases where the focus doesn't fit, so the subfocus is used. |
| 393 EXPECT_EQ(125, SCROLL(0, 125, 130, 125, 175, 0, 25)); |
| 394 EXPECT_EQ(125, SCROLL(125, 125, 130, 125, 175, 0, 25)); |
| 395 EXPECT_EQ(125, SCROLL(175, 125, 130, 125, 175, 0, 25)); |
| 396 EXPECT_EQ(125, SCROLL(500, 125, 130, 125, 175, 0, 25)); |
| 397 EXPECT_EQ(140, SCROLL(0, 140, 145, 125, 175, 0, 25)); |
| 398 EXPECT_EQ(150, SCROLL(0, 170, 175, 125, 175, 0, 25)); |
| 399 |
| 400 // Test some cases where the viewport is a single point - which can be |
| 401 // used to force an object to be scrolled to a specific location. |
| 402 EXPECT_EQ(50, SCROLL(0, 125, 175, 125, 175, 75, 75)); |
| 403 EXPECT_EQ(25, SCROLL(0, 125, 175, 125, 175, 100, 100)); |
| 404 EXPECT_EQ(0, SCROLL(0, 125, 175, 125, 175, 125, 125)); |
| 405 |
| 406 #undef SCROLL |
| 407 } |
| 408 |
OLD | NEW |