Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1072)

Side by Side Diff: ui/views/controls/scroll_view_unittest.cc

Issue 2535943002: Fix event targeting for overlay scrollbar thumbs (in native UI). (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ui/views/controls/scrollbar/base_scroll_bar.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 CustomView* header = new CustomView; 525 CustomView* header = new CustomView;
526 scroll_view_.SetHeader(header); 526 scroll_view_.SetHeader(header);
527 header->SetPreferredSize(gfx::Size(500, 20)); 527 header->SetPreferredSize(gfx::Size(500, 20));
528 528
529 scroll_view_.SetBoundsRect(gfx::Rect(0, 0, 100, 100)); 529 scroll_view_.SetBoundsRect(gfx::Rect(0, 0, 100, 100));
530 EXPECT_EQ("0,0", test_api.IntegralViewOffset().ToString()); 530 EXPECT_EQ("0,0", test_api.IntegralViewOffset().ToString());
531 EXPECT_EQ("0,0", header->bounds().origin().ToString()); 531 EXPECT_EQ("0,0", header->bounds().origin().ToString());
532 532
533 // Scroll the horizontal scrollbar. 533 // Scroll the horizontal scrollbar.
534 ASSERT_TRUE(scroll_view_.horizontal_scroll_bar()); 534 ASSERT_TRUE(scroll_view_.horizontal_scroll_bar());
535 scroll_view_.ScrollToPosition( 535 scroll_view_.ScrollToPosition(test_api.GetBaseScrollBar(HORIZONTAL), 1);
536 const_cast<ScrollBar*>(scroll_view_.horizontal_scroll_bar()), 1);
537 EXPECT_EQ("-1,0", test_api.IntegralViewOffset().ToString()); 536 EXPECT_EQ("-1,0", test_api.IntegralViewOffset().ToString());
538 EXPECT_EQ("-1,0", header->bounds().origin().ToString()); 537 EXPECT_EQ("-1,0", header->bounds().origin().ToString());
539 538
540 // Scrolling the vertical scrollbar shouldn't effect the header. 539 // Scrolling the vertical scrollbar shouldn't effect the header.
541 ASSERT_TRUE(scroll_view_.vertical_scroll_bar()); 540 ASSERT_TRUE(scroll_view_.vertical_scroll_bar());
542 scroll_view_.ScrollToPosition( 541 scroll_view_.ScrollToPosition(test_api.GetBaseScrollBar(VERTICAL), 1);
543 const_cast<ScrollBar*>(scroll_view_.vertical_scroll_bar()), 1);
544 EXPECT_EQ("-1,-1", test_api.IntegralViewOffset().ToString()); 542 EXPECT_EQ("-1,-1", test_api.IntegralViewOffset().ToString());
545 EXPECT_EQ("-1,0", header->bounds().origin().ToString()); 543 EXPECT_EQ("-1,0", header->bounds().origin().ToString());
546 } 544 }
547 545
548 // Verifies ScrollRectToVisible() on the child works. 546 // Verifies ScrollRectToVisible() on the child works.
549 TEST_F(ScrollViewTest, ScrollRectToVisible) { 547 TEST_F(ScrollViewTest, ScrollRectToVisible) {
550 ScrollViewTestApi test_api(&scroll_view_); 548 ScrollViewTestApi test_api(&scroll_view_);
551 CustomView* contents = new CustomView; 549 CustomView* contents = new CustomView;
552 scroll_view_.SetContents(contents); 550 scroll_view_.SetContents(contents);
553 contents->SetPreferredSize(gfx::Size(500, 1000)); 551 contents->SetPreferredSize(gfx::Size(500, 1000));
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 CustomView* contents = new CustomView; 874 CustomView* contents = new CustomView;
877 contents->SetPreferredSize(gfx::Size(300, 300)); 875 contents->SetPreferredSize(gfx::Size(300, 300));
878 scroll_view_.SetContents(contents); 876 scroll_view_.SetContents(contents);
879 scroll_view_.ClipHeightTo(0, 150); 877 scroll_view_.ClipHeightTo(0, 150);
880 scroll_view_.SizeToPreferredSize(); 878 scroll_view_.SizeToPreferredSize();
881 // ScrollView preferred width matches that of |contents|, with the height 879 // ScrollView preferred width matches that of |contents|, with the height
882 // capped at the value we clipped to. 880 // capped at the value we clipped to.
883 EXPECT_EQ(gfx::Size(300, 150), scroll_view_.size()); 881 EXPECT_EQ(gfx::Size(300, 150), scroll_view_.size());
884 882
885 // Scroll down. 883 // Scroll down.
886 scroll_view_.ScrollToPosition( 884 scroll_view_.ScrollToPosition(test_api.GetBaseScrollBar(VERTICAL), 25);
887 const_cast<ScrollBar*>(scroll_view_.vertical_scroll_bar()), 25);
888 EXPECT_EQ(25, test_api.CurrentOffset().y()); 885 EXPECT_EQ(25, test_api.CurrentOffset().y());
889 // Call Layout; no change to scroll position. 886 // Call Layout; no change to scroll position.
890 scroll_view_.Layout(); 887 scroll_view_.Layout();
891 EXPECT_EQ(25, test_api.CurrentOffset().y()); 888 EXPECT_EQ(25, test_api.CurrentOffset().y());
892 // Change contents of |contents|, call Layout; still no change to scroll 889 // Change contents of |contents|, call Layout; still no change to scroll
893 // position. 890 // position.
894 contents->SetPreferredSize(gfx::Size(300, 500)); 891 contents->SetPreferredSize(gfx::Size(300, 500));
895 contents->InvalidateLayout(); 892 contents->InvalidateLayout();
896 scroll_view_.Layout(); 893 scroll_view_.Layout();
897 EXPECT_EQ(25, test_api.CurrentOffset().y()); 894 EXPECT_EQ(25, test_api.CurrentOffset().y());
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 // Scroll via ScrollView API. Should be reflected on the impl side. 1018 // Scroll via ScrollView API. Should be reflected on the impl side.
1022 offset.set_y(kDefaultHeight * 4); 1019 offset.set_y(kDefaultHeight * 4);
1023 scroll_view->contents()->ScrollRectToVisible(offset); 1020 scroll_view->contents()->ScrollRectToVisible(offset);
1024 EXPECT_EQ(gfx::ScrollOffset(0, offset.y()), test_api.CurrentOffset()); 1021 EXPECT_EQ(gfx::ScrollOffset(0, offset.y()), test_api.CurrentOffset());
1025 1022
1026 EXPECT_TRUE(compositor->GetScrollOffsetForLayer(layer_id, &impl_offset)); 1023 EXPECT_TRUE(compositor->GetScrollOffsetForLayer(layer_id, &impl_offset));
1027 EXPECT_EQ(gfx::ScrollOffset(0, offset.y()), impl_offset); 1024 EXPECT_EQ(gfx::ScrollOffset(0, offset.y()), impl_offset);
1028 } 1025 }
1029 1026
1030 } // namespace views 1027 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | ui/views/controls/scrollbar/base_scroll_bar.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698