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 const int kMaxWidth = 800; |
| 94 const int kMaxHeight = 600; |
| 95 |
| 96 } // namespace |
| 97 |
| 98 namespace internal { |
| 99 |
| 100 class CompactLayoutManagerTransitionTest : public aura::test::AuraTestBase { |
| 101 public: |
| 102 CompactLayoutManagerTransitionTest() : layout_manager_(NULL) { |
| 103 } |
| 104 virtual ~CompactLayoutManagerTransitionTest() {} |
| 105 |
| 106 virtual void SetUp() OVERRIDE { |
| 107 aura::test::AuraTestBase::SetUp(); |
| 108 ash::Shell::CreateInstance(new ash::test::TestShellDelegate); |
| 109 aura::RootWindow::GetInstance()->Show(); |
| 110 aura::RootWindow::GetInstance()->SetHostSize( |
| 111 gfx::Size(kMaxWidth, kMaxHeight)); |
| 112 default_container()->SetBounds(gfx::Rect(0, 0, kMaxWidth, kMaxHeight)); |
| 113 layout_manager_ = new internal::CompactLayoutManager(); |
| 114 default_container()->SetLayoutManager(layout_manager_); |
| 115 default_container()->Show(); |
| 116 // Control layer animation stepping. |
| 117 default_container()->layer()->GetAnimator()-> |
| 118 set_disable_timer_for_test(true); |
| 119 } |
| 120 |
| 121 virtual void TearDown() OVERRIDE { |
| 122 ash::Shell::DeleteInstance(); |
| 123 aura::test::AuraTestBase::TearDown(); |
| 124 } |
| 125 |
| 126 aura::Window* CreateNormalWindow(int id) { |
| 127 aura::Window* window = new aura::Window(NULL); |
| 128 window->set_id(id); |
| 129 window->SetType(aura::client::WINDOW_TYPE_NORMAL); |
| 130 window->Init(ui::Layer::LAYER_TEXTURED); |
| 131 window->SetBounds(gfx::Rect(0, 0, kMaxWidth, kMaxHeight)); |
| 132 window->SetParent(default_container()); |
| 133 window_util::MaximizeWindow(window); |
| 134 window->Show(); |
| 135 RunAllPendingInMessageLoop(); |
| 136 return window; |
| 137 } |
| 138 |
| 139 aura::Window* default_container() const { |
| 140 return ash::Shell::GetInstance()->GetContainer( |
| 141 ash::internal::kShellWindowId_DefaultContainer); |
| 142 } |
| 143 |
| 144 int default_container_layer_width() const { |
| 145 return default_container()->layer()->bounds().width(); |
| 146 } |
| 147 |
| 148 ui::Transform default_container_layer_transform() const { |
| 149 return default_container()->layer()->GetTargetTransform(); |
| 150 } |
| 151 |
| 152 ui::AnimationContainerElement* animation_element() { |
| 153 return default_container()->layer()->GetAnimator(); |
| 154 } |
| 155 |
| 156 protected: |
| 157 internal::CompactLayoutManager* layout_manager_; |
| 158 |
| 159 private: |
| 160 DISALLOW_COPY_AND_ASSIGN(CompactLayoutManagerTransitionTest); |
| 161 }; |
| 162 |
| 163 TEST_F(CompactLayoutManagerTransitionTest, TransitionTest) { |
| 164 // Assert on viewport size to be the host size. |
| 165 ASSERT_EQ(kMaxWidth, default_container_layer_width()); |
| 166 // Create 3 windows, check that the layer grow as each one is added |
| 167 // to the layout. |
| 168 aura::Window* window1 = CreateNormalWindow(0); |
| 169 EXPECT_EQ(kMaxWidth, default_container_layer_width()); |
| 170 aura::Window* window2 = CreateNormalWindow(1); |
| 171 EXPECT_EQ(kMaxWidth * 2, default_container_layer_width()); |
| 172 aura::Window* window3 = CreateNormalWindow(2); |
| 173 EXPECT_EQ(kMaxWidth * 3, default_container_layer_width()); |
| 174 animation_element()->Step(base::TimeTicks::Now() + |
| 175 base::TimeDelta::FromSeconds(1)); |
| 176 RunAllPendingInMessageLoop(); |
| 177 |
| 178 // Check laid out position of the windows. |
| 179 EXPECT_EQ(0, window1->bounds().x()); |
| 180 EXPECT_EQ(kMaxWidth, window2->bounds().x()); |
| 181 EXPECT_EQ(kMaxWidth * 2, window3->bounds().x()); |
| 182 |
| 183 // Check layer transformation. |
| 184 ui::Transform target_transform; |
| 185 target_transform.ConcatTranslate(-window3->bounds().x(), 0); |
| 186 EXPECT_EQ(target_transform, default_container_layer_transform()); |
| 187 RunAllPendingInMessageLoop(); |
| 188 |
| 189 // Check that only one window is visible. |
| 190 EXPECT_EQ(window3, layout_manager_->current_window_); |
| 191 EXPECT_FALSE(window1->IsVisible()); |
| 192 EXPECT_FALSE(window2->IsVisible()); |
| 193 EXPECT_TRUE(window3->IsVisible()); |
| 194 |
| 195 // That window disappear, check that we transform the layer, and |
| 196 // again only have one window visible. |
| 197 window3->Hide(); |
| 198 animation_element()->Step(base::TimeTicks::Now() + |
| 199 base::TimeDelta::FromSeconds(1)); |
| 200 ui::Transform target_transform1; |
| 201 target_transform1.ConcatTranslate(-window1->bounds().x(), 0); |
| 202 EXPECT_EQ(target_transform1, default_container_layer_transform()); |
| 203 EXPECT_TRUE(window1->IsVisible()); |
| 204 EXPECT_FALSE(window2->IsVisible()); |
| 205 EXPECT_FALSE(window3->IsVisible()); |
| 206 EXPECT_EQ(window1, layout_manager_->current_window_); |
| 207 } |
| 208 |
| 209 } // namespace internal |
87 } // namespace ash | 210 } // namespace ash |
OLD | NEW |