OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/views/controls/scroll_view.h" | 5 #include "ui/views/controls/scroll_view.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/test/test_timeouts.h" | 9 #include "base/test/test_timeouts.h" |
10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 CustomView* contents = new CustomView; | 533 CustomView* contents = new CustomView; |
534 scroll_view_.SetContents(contents); | 534 scroll_view_.SetContents(contents); |
535 contents->SetPreferredSize(gfx::Size(500, 500)); | 535 contents->SetPreferredSize(gfx::Size(500, 500)); |
536 | 536 |
537 CustomView* header = new CustomView; | 537 CustomView* header = new CustomView; |
538 scroll_view_.SetHeader(header); | 538 scroll_view_.SetHeader(header); |
539 header->SetPreferredSize(gfx::Size(500, 20)); | 539 header->SetPreferredSize(gfx::Size(500, 20)); |
540 | 540 |
541 scroll_view_.SetBoundsRect(gfx::Rect(0, 0, 100, 100)); | 541 scroll_view_.SetBoundsRect(gfx::Rect(0, 0, 100, 100)); |
542 EXPECT_EQ("0,0", test_api.IntegralViewOffset().ToString()); | 542 EXPECT_EQ("0,0", test_api.IntegralViewOffset().ToString()); |
543 EXPECT_EQ("0,0", header->bounds().origin().ToString()); | 543 EXPECT_EQ("0,0", header->origin().ToString()); |
544 | 544 |
545 // Scroll the horizontal scrollbar. | 545 // Scroll the horizontal scrollbar. |
546 ASSERT_TRUE(scroll_view_.horizontal_scroll_bar()); | 546 ASSERT_TRUE(scroll_view_.horizontal_scroll_bar()); |
547 scroll_view_.ScrollToPosition(test_api.GetBaseScrollBar(HORIZONTAL), 1); | 547 scroll_view_.ScrollToPosition(test_api.GetBaseScrollBar(HORIZONTAL), 1); |
548 EXPECT_EQ("-1,0", test_api.IntegralViewOffset().ToString()); | 548 EXPECT_EQ("-1,0", test_api.IntegralViewOffset().ToString()); |
549 EXPECT_EQ("-1,0", header->bounds().origin().ToString()); | 549 EXPECT_EQ("-1,0", header->origin().ToString()); |
550 | 550 |
551 // Scrolling the vertical scrollbar shouldn't effect the header. | 551 // Scrolling the vertical scrollbar shouldn't effect the header. |
552 ASSERT_TRUE(scroll_view_.vertical_scroll_bar()); | 552 ASSERT_TRUE(scroll_view_.vertical_scroll_bar()); |
553 scroll_view_.ScrollToPosition(test_api.GetBaseScrollBar(VERTICAL), 1); | 553 scroll_view_.ScrollToPosition(test_api.GetBaseScrollBar(VERTICAL), 1); |
554 EXPECT_EQ("-1,-1", test_api.IntegralViewOffset().ToString()); | 554 EXPECT_EQ("-1,-1", test_api.IntegralViewOffset().ToString()); |
555 EXPECT_EQ("-1,0", header->bounds().origin().ToString()); | 555 EXPECT_EQ("-1,0", header->origin().ToString()); |
556 } | 556 } |
557 | 557 |
558 // Verifies ScrollRectToVisible() on the child works. | 558 // Verifies ScrollRectToVisible() on the child works. |
559 TEST_F(ScrollViewTest, ScrollRectToVisible) { | 559 TEST_F(ScrollViewTest, ScrollRectToVisible) { |
560 ScrollViewTestApi test_api(&scroll_view_); | 560 ScrollViewTestApi test_api(&scroll_view_); |
561 CustomView* contents = new CustomView; | 561 CustomView* contents = new CustomView; |
562 scroll_view_.SetContents(contents); | 562 scroll_view_.SetContents(contents); |
563 contents->SetPreferredSize(gfx::Size(500, 1000)); | 563 contents->SetPreferredSize(gfx::Size(500, 1000)); |
564 | 564 |
565 scroll_view_.SetBoundsRect(gfx::Rect(0, 0, 100, 100)); | 565 scroll_view_.SetBoundsRect(gfx::Rect(0, 0, 100, 100)); |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1031 // Scroll via ScrollView API. Should be reflected on the impl side. | 1031 // Scroll via ScrollView API. Should be reflected on the impl side. |
1032 offset.set_y(kDefaultHeight * 4); | 1032 offset.set_y(kDefaultHeight * 4); |
1033 scroll_view->contents()->ScrollRectToVisible(offset); | 1033 scroll_view->contents()->ScrollRectToVisible(offset); |
1034 EXPECT_EQ(gfx::ScrollOffset(0, offset.y()), test_api.CurrentOffset()); | 1034 EXPECT_EQ(gfx::ScrollOffset(0, offset.y()), test_api.CurrentOffset()); |
1035 | 1035 |
1036 EXPECT_TRUE(compositor->GetScrollOffsetForLayer(layer_id, &impl_offset)); | 1036 EXPECT_TRUE(compositor->GetScrollOffsetForLayer(layer_id, &impl_offset)); |
1037 EXPECT_EQ(gfx::ScrollOffset(0, offset.y()), impl_offset); | 1037 EXPECT_EQ(gfx::ScrollOffset(0, offset.y()), impl_offset); |
1038 } | 1038 } |
1039 | 1039 |
1040 } // namespace views | 1040 } // namespace views |
OLD | NEW |