Chromium Code Reviews| 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 "ash/wm/compact_layout_manager.h" | 5 #include "ash/wm/compact_layout_manager.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | |
| 8 #include "ash/shell_window_ids.h" | |
| 9 #include "ash/test/test_shell_delegate.h" | |
| 7 #include "ash/wm/shelf_layout_manager.h" | 10 #include "ash/wm/shelf_layout_manager.h" |
| 11 #include "ash/wm/window_util.h" | |
| 8 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 9 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 10 #include "ui/aura/client/aura_constants.h" | 14 #include "ui/aura/client/aura_constants.h" |
| 11 #include "ui/aura/root_window.h" | 15 #include "ui/aura/root_window.h" |
| 12 #include "ui/aura/screen_aura.h" | 16 #include "ui/aura/screen_aura.h" |
| 13 #include "ui/aura/test/aura_test_base.h" | 17 #include "ui/aura/test/aura_test_base.h" |
| 14 #include "ui/aura/test/test_windows.h" | 18 #include "ui/aura/test/test_windows.h" |
| 15 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
| 16 #include "ui/base/ui_base_types.h" | 20 #include "ui/base/ui_base_types.h" |
| 17 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 EXPECT_TRUE(widget->IsVisible()); | 81 EXPECT_TRUE(widget->IsVisible()); |
| 78 window->SetIntProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | 82 window->SetIntProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
| 79 EXPECT_TRUE(widget->IsVisible()); | 83 EXPECT_TRUE(widget->IsVisible()); |
| 80 window->SetIntProperty(aura::client::kShowStateKey, | 84 window->SetIntProperty(aura::client::kShowStateKey, |
| 81 ui::SHOW_STATE_FULLSCREEN); | 85 ui::SHOW_STATE_FULLSCREEN); |
| 82 EXPECT_FALSE(widget->IsVisible()); | 86 EXPECT_FALSE(widget->IsVisible()); |
| 83 window->SetIntProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | 87 window->SetIntProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
| 84 EXPECT_TRUE(widget->IsVisible()); | 88 EXPECT_TRUE(widget->IsVisible()); |
| 85 } | 89 } |
| 86 | 90 |
| 91 namespace { | |
| 92 | |
| 93 static gfx::Rect kMaxBounds(0, 0, 600, 600); | |
|
James Cook
2012/01/31 00:45:09
I meant, do you need to use plain-old-data for con
alicet1
2012/02/01 00:32:54
good point, I really only need the sizes. changed.
| |
| 94 | |
| 95 } // namespace | |
| 96 | |
| 97 namespace internal { | |
| 98 | |
| 99 class CompactLayoutManagerTransitionTest : public aura::test::AuraTestBase { | |
| 100 public: | |
| 101 CompactLayoutManagerTransitionTest() : layout_manager_(NULL) { | |
| 102 } | |
| 103 virtual ~CompactLayoutManagerTransitionTest() {} | |
| 104 | |
| 105 virtual void SetUp() OVERRIDE { | |
| 106 aura::test::AuraTestBase::SetUp(); | |
| 107 ash::Shell::CreateInstance(new ash::test::TestShellDelegate); | |
| 108 aura::RootWindow::GetInstance()->Show(); | |
| 109 aura::RootWindow::GetInstance()->SetHostSize(kMaxBounds.size()); | |
| 110 default_container()->SetBounds(kMaxBounds); | |
| 111 layout_manager_ = new internal::CompactLayoutManager(); | |
| 112 default_container()->SetLayoutManager(layout_manager_); | |
| 113 default_container()->Show(); | |
| 114 // Control layer animation stepping. | |
| 115 default_container()->layer()->GetAnimator()-> | |
| 116 set_disable_timer_for_test(true); | |
| 117 } | |
| 118 | |
| 119 virtual void TearDown() OVERRIDE { | |
| 120 ash::Shell::DeleteInstance(); | |
| 121 aura::test::AuraTestBase::TearDown(); | |
| 122 } | |
| 123 | |
| 124 aura::Window* CreateNormalWindow(int id, | |
| 125 const gfx::Rect& bounds) { | |
| 126 aura::Window* window = new aura::Window(NULL); | |
| 127 window->set_id(id); | |
| 128 window->SetType(aura::client::WINDOW_TYPE_NORMAL); | |
| 129 window->Init(ui::Layer::LAYER_TEXTURED); | |
| 130 window->SetBounds(bounds); | |
| 131 window->SetParent(default_container()); | |
| 132 window_util::MaximizeWindow(window); | |
| 133 window->Show(); | |
| 134 return window; | |
| 135 } | |
| 136 | |
| 137 aura::Window* default_container() const { | |
| 138 return ash::Shell::GetInstance()->GetContainer( | |
| 139 ash::internal::kShellWindowId_DefaultContainer); | |
| 140 } | |
| 141 | |
| 142 int default_container_layer_width() const { | |
| 143 return default_container()->layer()->bounds().width(); | |
| 144 } | |
| 145 | |
| 146 ui::Transform default_container_layer_transform() const { | |
| 147 return default_container()->layer()->GetTargetTransform(); | |
| 148 } | |
| 149 | |
| 150 ui::AnimationContainerElement* animation_element() { | |
| 151 return default_container()->layer()->GetAnimator(); | |
| 152 } | |
| 153 | |
| 154 protected: | |
| 155 internal::CompactLayoutManager* layout_manager_; | |
| 156 }; | |
|
sky
2012/01/31 01:20:14
nit: private: DISALLOW_COPY_AND_ASSIGN
alicet1
2012/02/01 00:32:54
Done.
| |
| 157 | |
| 158 | |
|
sky
2012/01/31 01:20:14
nit: only one empty line.
alicet1
2012/02/01 00:32:54
Done.
| |
| 159 TEST_F(CompactLayoutManagerTransitionTest, TransitionTest) { | |
| 160 // Assert on viewport size to be the host size. | |
| 161 ASSERT_EQ(kMaxBounds.width(), default_container_layer_width()); | |
| 162 // Create 3 windows, check that the layer grow as each one is added | |
| 163 // to the layout. | |
| 164 aura::Window* window1 = CreateNormalWindow(0, kMaxBounds); | |
| 165 EXPECT_EQ(kMaxBounds.width(), default_container_layer_width()); | |
| 166 aura::Window* window2 = CreateNormalWindow(1, kMaxBounds); | |
| 167 EXPECT_EQ(kMaxBounds.width() * 2, default_container_layer_width()); | |
| 168 aura::Window* window3 = CreateNormalWindow(3, kMaxBounds); | |
| 169 EXPECT_EQ(kMaxBounds.width() * 3, default_container_layer_width()); | |
| 170 animation_element()->Step(base::TimeTicks::Now() + | |
| 171 base::TimeDelta::FromSeconds(1)); | |
| 172 RunAllPendingInMessageLoop(); | |
| 173 | |
| 174 // Check laid out position of the windows. | |
| 175 EXPECT_EQ(0, window1->bounds().x()); | |
| 176 EXPECT_EQ(600, window2->bounds().x()); | |
| 177 EXPECT_EQ(1200, window3->bounds().x()); | |
| 178 | |
| 179 // Check layer transformation. | |
| 180 ui::Transform target_transform; | |
| 181 target_transform.ConcatTranslate(-window3->bounds().x(), 0); | |
| 182 EXPECT_EQ(target_transform, default_container_layer_transform()); | |
| 183 RunAllPendingInMessageLoop(); | |
| 184 | |
| 185 // Check that only one window is visible. | |
| 186 EXPECT_EQ(window3, layout_manager_->current_window_); | |
| 187 EXPECT_FALSE(window1->IsVisible()); | |
| 188 EXPECT_FALSE(window2->IsVisible()); | |
| 189 EXPECT_TRUE(window3->IsVisible()); | |
| 190 | |
| 191 // That window disappear, check that we transform the layer, and | |
| 192 // again only have one window visible. | |
| 193 window3->Hide(); | |
| 194 animation_element()->Step(base::TimeTicks::Now() + | |
| 195 base::TimeDelta::FromSeconds(1)); | |
| 196 ui::Transform target_transform1; | |
| 197 target_transform1.ConcatTranslate(-window1->bounds().x(), 0); | |
| 198 EXPECT_EQ(target_transform1, default_container_layer_transform()); | |
| 199 EXPECT_TRUE(window1->IsVisible()); | |
| 200 EXPECT_FALSE(window2->IsVisible()); | |
| 201 EXPECT_FALSE(window3->IsVisible()); | |
| 202 EXPECT_EQ(window1, layout_manager_->current_window_); | |
| 203 } | |
| 204 | |
| 205 } // namespace internal | |
| 87 } // namespace ash | 206 } // namespace ash |
| OLD | NEW |