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 "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "ui/views/controls/scrollbar/overlay_scroll_bar.h" | 8 #include "ui/views/controls/scrollbar/overlay_scroll_bar.h" |
9 #include "ui/views/test/test_views.h" | 9 #include "ui/views/test/test_views.h" |
10 | 10 |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 scroll_view.SetSize(new_size); | 327 scroll_view.SetSize(new_size); |
328 scroll_view.Layout(); | 328 scroll_view.Layout(); |
329 | 329 |
330 int scroll_bar_width = scroll_view.GetScrollBarWidth(); | 330 int scroll_bar_width = scroll_view.GetScrollBarWidth(); |
331 int expected_width = kWidth - scroll_bar_width; | 331 int expected_width = kWidth - scroll_bar_width; |
332 EXPECT_EQ(scroll_view.contents()->size().width(), expected_width); | 332 EXPECT_EQ(scroll_view.contents()->size().width(), expected_width); |
333 EXPECT_EQ(scroll_view.contents()->size().height(), 1000 * expected_width); | 333 EXPECT_EQ(scroll_view.contents()->size().height(), 1000 * expected_width); |
334 EXPECT_EQ(gfx::Size(kWidth, kMaxHeight), scroll_view.size()); | 334 EXPECT_EQ(gfx::Size(kWidth, kMaxHeight), scroll_view.size()); |
335 } | 335 } |
336 | 336 |
| 337 TEST(ScrollViewTest, CornerViewVisibility) { |
| 338 ScrollView scroll_view; |
| 339 View* contents = new View; |
| 340 scroll_view.SetContents(contents); |
| 341 scroll_view.SetBoundsRect(gfx::Rect(0, 0, 100, 100)); |
| 342 View* corner_view = scroll_view.corner_view_; |
| 343 |
| 344 // Corner view should be visible when both scrollbars are visible. |
| 345 contents->SetBounds(0, 0, 200, 200); |
| 346 scroll_view.Layout(); |
| 347 EXPECT_EQ(&scroll_view, corner_view->parent()); |
| 348 EXPECT_TRUE(corner_view->visible()); |
| 349 |
| 350 // Corner view should be aligned to the scrollbars. |
| 351 EXPECT_EQ(scroll_view.vertical_scroll_bar()->x(), corner_view->x()); |
| 352 EXPECT_EQ(scroll_view.horizontal_scroll_bar()->y(), corner_view->y()); |
| 353 EXPECT_EQ(scroll_view.GetScrollBarWidth(), corner_view->width()); |
| 354 EXPECT_EQ(scroll_view.GetScrollBarHeight(), corner_view->height()); |
| 355 |
| 356 // Corner view should be removed when only the vertical scrollbar is visible. |
| 357 contents->SetBounds(0, 0, 50, 200); |
| 358 scroll_view.Layout(); |
| 359 EXPECT_FALSE(corner_view->parent()); |
| 360 |
| 361 // ... or when only the horizontal scrollbar is visible. |
| 362 contents->SetBounds(0, 0, 200, 50); |
| 363 scroll_view.Layout(); |
| 364 EXPECT_FALSE(corner_view->parent()); |
| 365 |
| 366 // ... or when no scrollbar is visible. |
| 367 contents->SetBounds(0, 0, 50, 50); |
| 368 scroll_view.Layout(); |
| 369 EXPECT_FALSE(corner_view->parent()); |
| 370 |
| 371 // Corner view should reappear when both scrollbars reappear. |
| 372 contents->SetBounds(0, 0, 200, 200); |
| 373 scroll_view.Layout(); |
| 374 EXPECT_EQ(&scroll_view, corner_view->parent()); |
| 375 EXPECT_TRUE(corner_view->visible()); |
| 376 } |
| 377 |
337 } // namespace views | 378 } // namespace views |
OLD | NEW |