Index: ash/frame/caption_buttons/frame_caption_button_container_view_unittest.cc |
diff --git a/ash/frame/caption_buttons/frame_caption_button_container_view_unittest.cc b/ash/frame/caption_buttons/frame_caption_button_container_view_unittest.cc |
index acd72c8e16a8eb56f46e0f5ed966d08f36519198..30e33173b6e9492542b951a60ff9ad9520a41f38 100644 |
--- a/ash/frame/caption_buttons/frame_caption_button_container_view_unittest.cc |
+++ b/ash/frame/caption_buttons/frame_caption_button_container_view_unittest.cc |
@@ -5,8 +5,12 @@ |
#include "ash/frame/caption_buttons/frame_caption_button_container_view.h" |
#include "ash/frame/caption_buttons/frame_caption_button.h" |
+#include "ash/shell.h" |
#include "ash/test/ash_test_base.h" |
+#include "ash/wm/maximize_mode/maximize_mode_controller.h" |
#include "grit/ash_resources.h" |
+#include "ui/compositor/layer.h" |
+#include "ui/gfx/geometry/rect.h" |
#include "ui/views/widget/widget.h" |
#include "ui/views/widget/widget_delegate.h" |
@@ -108,6 +112,7 @@ TEST_F(FrameCaptionButtonContainerViewTest, ButtonVisibility) { |
FrameCaptionButtonContainerView container1(widget_can_maximize.get(), |
FrameCaptionButtonContainerView::MINIMIZE_ALLOWED); |
SetMockImages(&container1); |
+ container1.SetBoundsRect(gfx::Rect(container1.GetPreferredSize())); |
container1.Layout(); |
FrameCaptionButtonContainerView::TestApi t1(&container1); |
EXPECT_TRUE(t1.minimize_button()->visible()); |
@@ -123,6 +128,7 @@ TEST_F(FrameCaptionButtonContainerViewTest, ButtonVisibility) { |
FrameCaptionButtonContainerView container2(widget_cannot_maximize.get(), |
FrameCaptionButtonContainerView::MINIMIZE_ALLOWED); |
SetMockImages(&container2); |
+ container2.SetBoundsRect(gfx::Rect(container2.GetPreferredSize())); |
container2.Layout(); |
FrameCaptionButtonContainerView::TestApi t2(&container2); |
EXPECT_TRUE(t2.minimize_button()->visible()); |
@@ -136,6 +142,7 @@ TEST_F(FrameCaptionButtonContainerViewTest, ButtonVisibility) { |
FrameCaptionButtonContainerView container3(widget_cannot_maximize.get(), |
FrameCaptionButtonContainerView::MINIMIZE_DISALLOWED); |
SetMockImages(&container3); |
+ container3.SetBoundsRect(gfx::Rect(container3.GetPreferredSize())); |
container3.Layout(); |
FrameCaptionButtonContainerView::TestApi t3(&container3); |
EXPECT_FALSE(t3.minimize_button()->visible()); |
@@ -145,4 +152,97 @@ TEST_F(FrameCaptionButtonContainerViewTest, ButtonVisibility) { |
&container3, *t3.close_button(), *t3.close_button())); |
} |
+// Tests that the layout animations trigered by button visibilty result in the |
+// correct placement of the buttons. |
+TEST_F(FrameCaptionButtonContainerViewTest, |
+ TestUpdateSizeButtonVisibilityAnimation) { |
+ scoped_ptr<views::Widget> widget_can_maximize( |
+ CreateTestWidget(MAXIMIZE_ALLOWED)); |
+ FrameCaptionButtonContainerView container(widget_can_maximize.get(), |
+ FrameCaptionButtonContainerView::MINIMIZE_ALLOWED); |
+ SetMockImages(&container); |
+ container.SetBoundsRect(gfx::Rect(container.GetPreferredSize())); |
+ container.Layout(); |
+ |
+ FrameCaptionButtonContainerView::TestApi test(&container); |
+ gfx::Rect initial_minimize_button_bounds = test.minimize_button()->bounds(); |
+ gfx::Rect initial_size_button_bounds = test.size_button()->bounds(); |
+ gfx::Rect initial_close_button_bounds = test.close_button()->bounds(); |
+ gfx::Rect initial_container_bounds = container.bounds(); |
+ |
+ ASSERT_EQ(initial_size_button_bounds.x(), |
+ initial_minimize_button_bounds.right()); |
+ ASSERT_EQ(initial_close_button_bounds.x(), |
+ initial_size_button_bounds.right()); |
+ |
+ // Hidden size button should result in minimize button animating to the |
+ // right. The size button should not be visible, but should not have moved. |
+ Shell::GetInstance()->maximize_mode_controller()-> |
+ EnableMaximizeModeWindowManager(true); |
+ container.UpdateSizeButtonVisibility(); |
+ container.Layout(); |
+ |
+ EXPECT_TRUE(test.minimize_button()->visible()); |
+ EXPECT_FALSE(test.size_button()->visible()); |
+ EXPECT_TRUE(test.close_button()->visible()); |
+ gfx::Rect minimize_button_bounds = test.minimize_button()->bounds(); |
+ gfx::Rect close_button_bounds = test.close_button()->bounds(); |
+ EXPECT_EQ(close_button_bounds.x(), minimize_button_bounds.right()); |
+ EXPECT_EQ(initial_size_button_bounds, test.size_button()->bounds()); |
+ EXPECT_EQ(initial_close_button_bounds, close_button_bounds); |
+ EXPECT_LT(container.GetPreferredSize().width(), |
+ initial_container_bounds.width()); |
+ |
+ // Revealing the size button should cause the minimze button to return to its |
+ // original position. |
+ Shell::GetInstance()->maximize_mode_controller()-> |
+ EnableMaximizeModeWindowManager(false); |
+ container.UpdateSizeButtonVisibility(); |
+ container.Layout(); |
+ EXPECT_TRUE(test.minimize_button()->visible()); |
+ EXPECT_TRUE(test.size_button()->visible()); |
+ EXPECT_TRUE(test.close_button()->visible()); |
+ EXPECT_EQ(initial_minimize_button_bounds, test.minimize_button()->bounds()); |
+ EXPECT_EQ(initial_size_button_bounds, test.size_button()->bounds()); |
+ EXPECT_EQ(initial_close_button_bounds, test.close_button()->bounds()); |
+ EXPECT_EQ(container.GetPreferredSize().width(), |
+ initial_container_bounds.width()); |
+} |
+ |
+// Tests that after an animation to maximized state, that the layer tree has |
+// been updated to reflect the swapped layers. |
+TEST_F(FrameCaptionButtonContainerViewTest, AnimationUpdatesLayerTree) { |
+ scoped_ptr<views::Widget> widget_can_maximize( |
+ CreateTestWidget(MAXIMIZE_ALLOWED)); |
+ FrameCaptionButtonContainerView container(widget_can_maximize.get(), |
+ FrameCaptionButtonContainerView::MINIMIZE_ALLOWED); |
+ SetMockImages(&container); |
+ container.SetBoundsRect(gfx::Rect(container.GetPreferredSize())); |
+ container.Layout(); |
+ ui::Layer* original_layer = container.layer(); |
+ |
+ // The container must be a child of the window to be affected by the |
+ // animation. |
+ widget_can_maximize->non_client_view()->AddChildView(&container); |
+ widget_can_maximize->Show(); |
+ // The original cache of the layer tree must be created before the animation |
+ widget_can_maximize->UpdateRootLayers(); |
+ widget_can_maximize->GetRootLayers(); |
+ |
+ // After the maximizing animation has completed, |original_layer| will have |
+ // been deleted. Dereferencing it could cause a segfault. |
+ widget_can_maximize->Maximize(); |
+ RunAllPendingInMessageLoop(); |
+ EXPECT_TRUE(widget_can_maximize->IsMaximized()); |
+ |
+ std::vector<ui::Layer*> layers = widget_can_maximize->GetRootLayers(); |
+ |
+ EXPECT_GT(layers.size(), 0u); |
+ EXPECT_NE(layers.end(), |
+ std::find(layers.begin(), layers.end(), container.layer())); |
+ EXPECT_EQ(layers.end(), |
+ std::find(layers.begin(), layers.end(), original_layer)); |
+ EXPECT_NE(original_layer, container.layer()); |
+} |
+ |
} // namespace ash |