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

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

Issue 2595163002: Add origin() method on View and use it to simplify some callers. (Closed)
Patch Set: Resync Created 3 years, 11 months 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
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/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/test/test_timeouts.h" 10 #include "base/test/test_timeouts.h"
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 CustomView* contents = new CustomView; 534 CustomView* contents = new CustomView;
535 scroll_view_.SetContents(contents); 535 scroll_view_.SetContents(contents);
536 contents->SetPreferredSize(gfx::Size(500, 500)); 536 contents->SetPreferredSize(gfx::Size(500, 500));
537 537
538 CustomView* header = new CustomView; 538 CustomView* header = new CustomView;
539 scroll_view_.SetHeader(header); 539 scroll_view_.SetHeader(header);
540 header->SetPreferredSize(gfx::Size(500, 20)); 540 header->SetPreferredSize(gfx::Size(500, 20));
541 541
542 scroll_view_.SetBoundsRect(gfx::Rect(0, 0, 100, 100)); 542 scroll_view_.SetBoundsRect(gfx::Rect(0, 0, 100, 100));
543 EXPECT_EQ("0,0", test_api.IntegralViewOffset().ToString()); 543 EXPECT_EQ("0,0", test_api.IntegralViewOffset().ToString());
544 EXPECT_EQ("0,0", header->bounds().origin().ToString()); 544 EXPECT_EQ("0,0", header->origin().ToString());
545 545
546 // Scroll the horizontal scrollbar. 546 // Scroll the horizontal scrollbar.
547 ASSERT_TRUE(scroll_view_.horizontal_scroll_bar()); 547 ASSERT_TRUE(scroll_view_.horizontal_scroll_bar());
548 scroll_view_.ScrollToPosition(test_api.GetBaseScrollBar(HORIZONTAL), 1); 548 scroll_view_.ScrollToPosition(test_api.GetBaseScrollBar(HORIZONTAL), 1);
549 EXPECT_EQ("-1,0", test_api.IntegralViewOffset().ToString()); 549 EXPECT_EQ("-1,0", test_api.IntegralViewOffset().ToString());
550 EXPECT_EQ("-1,0", header->bounds().origin().ToString()); 550 EXPECT_EQ("-1,0", header->origin().ToString());
551 551
552 // Scrolling the vertical scrollbar shouldn't effect the header. 552 // Scrolling the vertical scrollbar shouldn't effect the header.
553 ASSERT_TRUE(scroll_view_.vertical_scroll_bar()); 553 ASSERT_TRUE(scroll_view_.vertical_scroll_bar());
554 scroll_view_.ScrollToPosition(test_api.GetBaseScrollBar(VERTICAL), 1); 554 scroll_view_.ScrollToPosition(test_api.GetBaseScrollBar(VERTICAL), 1);
555 EXPECT_EQ("-1,-1", test_api.IntegralViewOffset().ToString()); 555 EXPECT_EQ("-1,-1", test_api.IntegralViewOffset().ToString());
556 EXPECT_EQ("-1,0", header->bounds().origin().ToString()); 556 EXPECT_EQ("-1,0", header->origin().ToString());
557 } 557 }
558 558
559 // Verifies ScrollRectToVisible() on the child works. 559 // Verifies ScrollRectToVisible() on the child works.
560 TEST_F(ScrollViewTest, ScrollRectToVisible) { 560 TEST_F(ScrollViewTest, ScrollRectToVisible) {
561 ScrollViewTestApi test_api(&scroll_view_); 561 ScrollViewTestApi test_api(&scroll_view_);
562 CustomView* contents = new CustomView; 562 CustomView* contents = new CustomView;
563 scroll_view_.SetContents(contents); 563 scroll_view_.SetContents(contents);
564 contents->SetPreferredSize(gfx::Size(500, 1000)); 564 contents->SetPreferredSize(gfx::Size(500, 1000));
565 565
566 scroll_view_.SetBoundsRect(gfx::Rect(0, 0, 100, 100)); 566 scroll_view_.SetBoundsRect(gfx::Rect(0, 0, 100, 100));
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 // Scroll via ScrollView API. Should be reflected on the impl side. 1032 // Scroll via ScrollView API. Should be reflected on the impl side.
1033 offset.set_y(kDefaultHeight * 4); 1033 offset.set_y(kDefaultHeight * 4);
1034 scroll_view->contents()->ScrollRectToVisible(offset); 1034 scroll_view->contents()->ScrollRectToVisible(offset);
1035 EXPECT_EQ(gfx::ScrollOffset(0, offset.y()), test_api.CurrentOffset()); 1035 EXPECT_EQ(gfx::ScrollOffset(0, offset.y()), test_api.CurrentOffset());
1036 1036
1037 EXPECT_TRUE(compositor->GetScrollOffsetForLayer(layer_id, &impl_offset)); 1037 EXPECT_TRUE(compositor->GetScrollOffsetForLayer(layer_id, &impl_offset));
1038 EXPECT_EQ(gfx::ScrollOffset(0, offset.y()), impl_offset); 1038 EXPECT_EQ(gfx::ScrollOffset(0, offset.y()), impl_offset);
1039 } 1039 }
1040 1040
1041 } // namespace views 1041 } // namespace views
OLDNEW
« no previous file with comments | « ui/message_center/views/notification_view_unittest.cc ('k') | ui/views/controls/styled_label_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698