Chromium Code Reviews| 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)); | |
|
David Tseng
2011/12/02 00:33:04
Just for kicks, throw in a subfocus not equal to f
dmazzoni
2011/12/03 00:37:10
Done.
| |
| 377 EXPECT_EQ(75, SCROLL(75, 125, 175, 125, 175, 0, 100)); | |
|
David Tseng
2011/12/02 00:33:04
Curious, do we handle negative scrolling? (i.e. if
dmazzoni
2011/12/03 00:37:10
This function will return a negative value, sure.
| |
| 378 | |
| 379 // Test some cases where the focus needs to be scrolled to fit. | |
| 380 EXPECT_EQ(75, SCROLL(74, 125, 175, 125, 175, 0, 100)); | |
| 381 EXPECT_EQ(75, SCROLL(50, 125, 175, 125, 175, 0, 100)); | |
| 382 EXPECT_EQ(75, SCROLL(0, 125, 175, 125, 175, 0, 100)); | |
| 383 EXPECT_EQ(125, SCROLL(126, 125, 175, 125, 175, 0, 100)); | |
| 384 EXPECT_EQ(125, SCROLL(150, 125, 175, 125, 175, 0, 100)); | |
| 385 EXPECT_EQ(125, SCROLL(200, 125, 175, 125, 175, 0, 100)); | |
| 386 | |
| 387 // Test some cases where the focus doesn't fit, so the subfocus is used. | |
| 388 EXPECT_EQ(125, SCROLL(0, 125, 130, 125, 175, 0, 25)); | |
| 389 EXPECT_EQ(140, SCROLL(0, 140, 145, 125, 175, 0, 25)); | |
| 390 EXPECT_EQ(150, SCROLL(0, 170, 175, 125, 175, 0, 25)); | |
|
David Tseng
2011/12/02 00:33:04
How about adding a case for nonzero initial offset
dmazzoni
2011/12/03 00:37:10
Done.
| |
| 391 | |
| 392 // Test some cases where the viewport is a single point - which can be | |
| 393 // used to force an object to be scrolled to a specific location. | |
| 394 EXPECT_EQ(50, SCROLL(0, 125, 175, 125, 175, 75, 75)); | |
| 395 EXPECT_EQ(25, SCROLL(0, 125, 175, 125, 175, 100, 100)); | |
| 396 EXPECT_EQ(0, SCROLL(0, 125, 175, 125, 175, 125, 125)); | |
| 397 | |
| 398 #undef SCROLL | |
| 399 } | |
| 400 | |
| OLD | NEW |