Index: ash/wm/compact_layout_manager_unittest.cc |
diff --git a/ash/wm/compact_layout_manager_unittest.cc b/ash/wm/compact_layout_manager_unittest.cc |
index 8ec2decea66cc7126fa95ea4c178487162919c0c..587aa26b4dbd222f25844a314035457a1955692c 100644 |
--- a/ash/wm/compact_layout_manager_unittest.cc |
+++ b/ash/wm/compact_layout_manager_unittest.cc |
@@ -4,7 +4,11 @@ |
#include "ash/wm/compact_layout_manager.h" |
+#include "ash/shell.h" |
+#include "ash/shell_window_ids.h" |
+#include "ash/test/test_shell_delegate.h" |
#include "ash/wm/shelf_layout_manager.h" |
+#include "ash/wm/window_util.h" |
#include "base/basictypes.h" |
#include "base/compiler_specific.h" |
#include "ui/aura/client/aura_constants.h" |
@@ -84,4 +88,119 @@ TEST_F(CompactLayoutManagerTest, StatusAreaVisibility) { |
EXPECT_TRUE(widget->IsVisible()); |
} |
+namespace { |
+ |
+static gfx::Rect kMaxBounds = gfx::Rect(0, 0, 600, 600); |
James Cook
2012/01/30 22:12:20
Are static class initializers allowed in test code
alicet1
2012/01/30 23:52:53
changed.
|
+ |
+} // namespace |
+ |
+namespace internal { |
+ |
+class CompactLayoutManagerTransitionTest : public aura::test::AuraTestBase { |
+ public: |
+ CompactLayoutManagerTransitionTest() : layout_manager_(NULL) { |
+ } |
+ virtual ~CompactLayoutManagerTransitionTest() {} |
+ |
+ virtual void SetUp() OVERRIDE { |
+ aura::test::AuraTestBase::SetUp(); |
+ ash::Shell::CreateInstance(new ash::test::TestShellDelegate); |
+ aura::RootWindow::GetInstance()->Show(); |
+ aura::RootWindow::GetInstance()->SetHostSize(kMaxBounds.size()); |
+ default_container()->SetBounds(kMaxBounds); |
+ layout_manager_ = new internal::CompactLayoutManager(); |
James Cook
2012/01/30 22:12:20
nit: one space after =
alicet1
2012/01/30 23:52:53
Done.
|
+ default_container()->SetLayoutManager(layout_manager_); |
+ default_container()->Show(); |
+ // Control layer animation stepping. |
+ default_container()->layer()->GetAnimator()-> |
+ set_disable_timer_for_test(true); |
+ } |
+ |
+ virtual void TearDown() OVERRIDE { |
+ ash::Shell::DeleteInstance(); |
+ aura::test::AuraTestBase::TearDown(); |
+ } |
+ |
+ aura::Window* CreateNormalWindow(int id, |
James Cook
2012/01/30 22:12:20
Is there some sort of Aura test utility class or w
alicet1
2012/01/30 23:52:53
kinda, test_windows.cc, but here I need to create
|
+ const gfx::Rect& bounds) { |
+ aura::Window* window = new aura::Window(NULL); |
+ window->set_id(id); |
+ window->SetType(aura::client::WINDOW_TYPE_NORMAL); |
+ window->Init(ui::Layer::LAYER_HAS_TEXTURE); |
+ window->SetBounds(bounds); |
+ window->SetParent(default_container()); |
+ window_util::MaximizeWindow(window); |
+ return window; |
+ } |
+ |
+ aura::Window* default_container() const { |
James Cook
2012/01/30 22:12:20
Hooray for simple utility functions to make the te
|
+ return ash::Shell::GetInstance()->GetContainer( |
+ ash::internal::kShellWindowId_DefaultContainer); |
+ } |
+ |
+ int default_container_layer_width() const { |
+ return default_container()->layer()->bounds().width(); |
+ } |
+ |
+ ui::Transform default_container_layer_transform() const { |
+ return default_container()->layer()->GetTargetTransform(); |
+ } |
+ |
+ ui::AnimationContainerElement* animation_element() { |
+ return default_container()->layer()->GetAnimator(); |
+ } |
+ |
+ protected: |
+ internal::CompactLayoutManager* layout_manager_; |
+}; |
+ |
+ |
+TEST_F(CompactLayoutManagerTransitionTest, TransitionTest) { |
+ // Create 3 windows, check that the layer grow as each one is added |
James Cook
2012/01/30 22:12:20
Maybe assert the initial state of the container, b
alicet1
2012/01/30 23:52:53
Done.
|
+ // to the layout. |
+ aura::Window* window1 = CreateNormalWindow(0, kMaxBounds); |
+ window1->Show(); |
+ EXPECT_EQ(kMaxBounds.width(), default_container_layer_width()); |
+ aura::Window* window2 = CreateNormalWindow(1, kMaxBounds); |
+ window2->Show(); |
+ EXPECT_EQ(kMaxBounds.width() * 2, default_container_layer_width()); |
James Cook
2012/01/30 22:12:20
I like that you're using constant * 2 instead of a
|
+ aura::Window* window3 = CreateNormalWindow(3, kMaxBounds); |
+ window3->Show(); |
+ EXPECT_EQ(kMaxBounds.width() * 3, default_container_layer_width()); |
+ animation_element()->Step(base::TimeTicks::Now() + |
+ base::TimeDelta::FromSeconds(1)); |
+ RunAllPendingInMessageLoop(); |
+ |
+ // Check laid out position of the windows. |
+ EXPECT_EQ(0, window1->bounds().x()); |
+ EXPECT_EQ(600, window2->bounds().x()); |
+ EXPECT_EQ(1200, window3->bounds().x()); |
+ |
+ // Check layer transformation. |
+ ui::Transform target_transform; |
+ target_transform.ConcatTranslate(-window3->bounds().x(), 0); |
+ EXPECT_EQ(target_transform, default_container_layer_transform()); |
+ RunAllPendingInMessageLoop(); |
+ |
+ // Check that only one window is visible. |
+ EXPECT_EQ(window3, layout_manager_->current_window_); |
+ EXPECT_FALSE(window1->IsVisible()); |
+ EXPECT_FALSE(window2->IsVisible()); |
+ EXPECT_TRUE(window3->IsVisible()); |
+ |
+ // That window disappear, check that we transform the layer, and |
+ // again only have one window visible. |
+ window3->Hide(); |
+ animation_element()->Step(base::TimeTicks::Now() + |
+ base::TimeDelta::FromSeconds(1)); |
+ ui::Transform target_transform1; |
+ target_transform1.ConcatTranslate(-window1->bounds().x(), 0); |
+ EXPECT_EQ(target_transform1, default_container_layer_transform()); |
+ EXPECT_TRUE(window1->IsVisible()); |
+ EXPECT_FALSE(window2->IsVisible()); |
+ EXPECT_FALSE(window3->IsVisible()); |
+ EXPECT_EQ(window1, layout_manager_->current_window_); |
+} |
+ |
+} // namespace internal |
} // namespace ash |