| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ash/wm/compact_layout_manager.h" | |
| 6 | |
| 7 #include "ash/shell.h" | |
| 8 #include "ash/shell_window_ids.h" | |
| 9 #include "ash/test/ash_test_base.h" | |
| 10 #include "ash/wm/shelf_layout_manager.h" | |
| 11 #include "ash/wm/window_util.h" | |
| 12 #include "base/basictypes.h" | |
| 13 #include "base/compiler_specific.h" | |
| 14 #include "ui/aura/client/aura_constants.h" | |
| 15 #include "ui/aura/root_window.h" | |
| 16 #include "ui/aura/screen_aura.h" | |
| 17 #include "ui/aura/test/test_windows.h" | |
| 18 #include "ui/aura/window.h" | |
| 19 #include "ui/base/ui_base_types.h" | |
| 20 #include "ui/views/widget/widget.h" | |
| 21 | |
| 22 namespace ash { | |
| 23 | |
| 24 namespace { | |
| 25 | |
| 26 const int kMaxWidth = 800; | |
| 27 const int kMaxHeight = 600; | |
| 28 | |
| 29 } // namespace | |
| 30 | |
| 31 namespace internal { | |
| 32 | |
| 33 class CompactLayoutManagerTest : public ash::test::AshTestBase { | |
| 34 public: | |
| 35 CompactLayoutManagerTest() : layout_manager_(NULL) { | |
| 36 } | |
| 37 virtual ~CompactLayoutManagerTest() {} | |
| 38 | |
| 39 virtual void SetUp() OVERRIDE { | |
| 40 ash::test::AshTestBase::SetUp(); | |
| 41 Shell::GetRootWindow()->Show(); | |
| 42 Shell::GetRootWindow()->SetHostSize(gfx::Size(kMaxWidth, kMaxHeight)); | |
| 43 default_container()->SetBounds(gfx::Rect(0, 0, kMaxWidth, kMaxHeight)); | |
| 44 layout_manager_ = new internal::CompactLayoutManager(); | |
| 45 default_container()->SetLayoutManager(layout_manager_); | |
| 46 default_container()->Show(); | |
| 47 // Control layer animation stepping. | |
| 48 default_container()->layer()->GetAnimator()-> | |
| 49 set_disable_timer_for_test(true); | |
| 50 RunAllPendingInMessageLoop(); | |
| 51 } | |
| 52 | |
| 53 aura::Window* CreateNormalWindow(int id) { | |
| 54 aura::Window* window = new aura::Window(NULL); | |
| 55 window->set_id(id); | |
| 56 window->SetType(aura::client::WINDOW_TYPE_NORMAL); | |
| 57 window->Init(ui::Layer::LAYER_TEXTURED); | |
| 58 window->SetBounds(gfx::Rect(0, 0, kMaxWidth, kMaxHeight)); | |
| 59 window->SetParent(default_container()); | |
| 60 wm::MaximizeWindow(window); | |
| 61 window->Show(); | |
| 62 RunAllPendingInMessageLoop(); | |
| 63 return window; | |
| 64 } | |
| 65 | |
| 66 aura::Window* CreateTestWindow(const gfx::Rect& bounds) { | |
| 67 return aura::test::CreateTestWindowWithBounds(bounds, default_container()); | |
| 68 } | |
| 69 | |
| 70 // Returns widget owned by its parent, so doesn't need scoped_ptr<>. | |
| 71 views::Widget* CreateTestWidget() { | |
| 72 views::Widget* widget = new views::Widget; | |
| 73 views::Widget::InitParams params( | |
| 74 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | |
| 75 params.bounds = gfx::Rect(11, 22, 33, 44); | |
| 76 widget->Init(params); | |
| 77 widget->Show(); | |
| 78 return widget; | |
| 79 } | |
| 80 | |
| 81 internal::CompactLayoutManager* layout_manager() { | |
| 82 return layout_manager_; | |
| 83 } | |
| 84 | |
| 85 aura::Window* default_container() const { | |
| 86 return ash::Shell::GetInstance()->GetContainer( | |
| 87 ash::internal::kShellWindowId_DefaultContainer); | |
| 88 } | |
| 89 | |
| 90 int default_container_layer_width() const { | |
| 91 return default_container()->layer()->bounds().width(); | |
| 92 } | |
| 93 | |
| 94 ui::Transform default_container_layer_transform() const { | |
| 95 return default_container()->layer()->GetTargetTransform(); | |
| 96 } | |
| 97 | |
| 98 ui::AnimationContainerElement* animation_element() { | |
| 99 return default_container()->layer()->GetAnimator(); | |
| 100 } | |
| 101 | |
| 102 protected: | |
| 103 internal::CompactLayoutManager* layout_manager_; | |
| 104 | |
| 105 private: | |
| 106 DISALLOW_COPY_AND_ASSIGN(CompactLayoutManagerTest); | |
| 107 }; | |
| 108 | |
| 109 // Tests status area visibility during window maximize and fullscreen. | |
| 110 TEST_F(CompactLayoutManagerTest, StatusAreaVisibility) { | |
| 111 gfx::Rect bounds(100, 100, 200, 200); | |
| 112 scoped_ptr<aura::Window> window(CreateTestWindow(bounds)); | |
| 113 views::Widget* widget = CreateTestWidget(); | |
| 114 layout_manager()->set_status_area_widget(widget); | |
| 115 EXPECT_TRUE(widget->IsVisible()); | |
| 116 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | |
| 117 EXPECT_TRUE(widget->IsVisible()); | |
| 118 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | |
| 119 EXPECT_TRUE(widget->IsVisible()); | |
| 120 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | |
| 121 EXPECT_FALSE(widget->IsVisible()); | |
| 122 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | |
| 123 EXPECT_TRUE(widget->IsVisible()); | |
| 124 } | |
| 125 | |
| 126 #if defined(OS_MACOSX) | |
| 127 #define MAYBE_TransitionTest FAILS_TransitionTest | |
| 128 #else | |
| 129 #define MAYBE_TransitionTest TransitionTest | |
| 130 #endif | |
| 131 TEST_F(CompactLayoutManagerTest, MAYBE_TransitionTest) { | |
| 132 // Assert on viewport size to be the host size. | |
| 133 ASSERT_EQ(kMaxWidth, default_container_layer_width()); | |
| 134 // Create 3 windows, check that the layer grow as each one is added | |
| 135 // to the layout. | |
| 136 aura::Window* window1 = CreateNormalWindow(0); | |
| 137 EXPECT_EQ(kMaxWidth, default_container_layer_width()); | |
| 138 aura::Window* window2 = CreateNormalWindow(1); | |
| 139 EXPECT_EQ(kMaxWidth * 2, default_container_layer_width()); | |
| 140 aura::Window* window3 = CreateNormalWindow(2); | |
| 141 EXPECT_EQ(kMaxWidth * 3, default_container_layer_width()); | |
| 142 animation_element()->Step(base::TimeTicks::Now() + | |
| 143 base::TimeDelta::FromSeconds(1)); | |
| 144 RunAllPendingInMessageLoop(); | |
| 145 | |
| 146 // Check laid out position of the windows. | |
| 147 EXPECT_EQ(0, window1->bounds().x()); | |
| 148 EXPECT_EQ(kMaxWidth, window2->bounds().x()); | |
| 149 EXPECT_EQ(kMaxWidth * 2, window3->bounds().x()); | |
| 150 | |
| 151 // Check layer transformation. | |
| 152 ui::Transform target_transform; | |
| 153 target_transform.ConcatTranslate(-window3->bounds().x(), 0); | |
| 154 EXPECT_EQ(target_transform, default_container_layer_transform()); | |
| 155 RunAllPendingInMessageLoop(); | |
| 156 | |
| 157 // Check that only one window is visible. | |
| 158 EXPECT_EQ(window3, layout_manager_->current_window_); | |
| 159 EXPECT_FALSE(window1->IsVisible()); | |
| 160 EXPECT_FALSE(window2->IsVisible()); | |
| 161 EXPECT_TRUE(window3->IsVisible()); | |
| 162 | |
| 163 // That window disappear, check that we transform the layer, and | |
| 164 // again only have one window visible. | |
| 165 window3->Hide(); | |
| 166 animation_element()->Step(base::TimeTicks::Now() + | |
| 167 base::TimeDelta::FromSeconds(1)); | |
| 168 ui::Transform target_transform1; | |
| 169 target_transform1.ConcatTranslate(-window1->bounds().x(), 0); | |
| 170 EXPECT_EQ(target_transform1, default_container_layer_transform()); | |
| 171 EXPECT_TRUE(window1->IsVisible()); | |
| 172 EXPECT_FALSE(window2->IsVisible()); | |
| 173 EXPECT_FALSE(window3->IsVisible()); | |
| 174 EXPECT_EQ(window1, layout_manager_->current_window_); | |
| 175 } | |
| 176 | |
| 177 TEST_F(CompactLayoutManagerTest, SwitchToNextVisibleWindow) { | |
| 178 // Create 3 windows | |
| 179 aura::Window* window1 = CreateNormalWindow(0); | |
| 180 window1->Hide(); // Hide window1 before its layer marked invisible. | |
| 181 aura::Window* window2 = CreateNormalWindow(1); | |
| 182 aura::Window* window3 = CreateNormalWindow(2); | |
| 183 | |
| 184 // Check that only window3 is visible. | |
| 185 EXPECT_FALSE(window1->IsVisible()); | |
| 186 EXPECT_FALSE(window2->IsVisible()); | |
| 187 EXPECT_TRUE(window3->IsVisible()); | |
| 188 | |
| 189 // Hide the current active window. | |
| 190 window3->Hide(); | |
| 191 | |
| 192 // And window2 becomes the current window because window1 is hidden. | |
| 193 EXPECT_FALSE(window1->IsVisible()); | |
| 194 EXPECT_TRUE(window2->IsVisible()); | |
| 195 EXPECT_FALSE(window3->IsVisible()); | |
| 196 | |
| 197 // Show window3 and it becomes the current window. | |
| 198 window3->Show(); | |
| 199 EXPECT_FALSE(window1->IsVisible()); | |
| 200 EXPECT_FALSE(window2->IsVisible()); | |
| 201 EXPECT_TRUE(window3->IsVisible()); | |
| 202 | |
| 203 // Close the current active window. | |
| 204 delete window3; | |
| 205 | |
| 206 // And window2 becomes active again. | |
| 207 EXPECT_FALSE(window1->IsVisible()); | |
| 208 EXPECT_TRUE(window2->IsVisible()); | |
| 209 } | |
| 210 | |
| 211 TEST_F(CompactLayoutManagerTest, CloseAllWindows) { | |
| 212 // Create 3 windows | |
| 213 aura::Window* window1 = CreateNormalWindow(0); | |
| 214 aura::Window* window2 = CreateNormalWindow(1); | |
| 215 aura::Window* window3 = CreateNormalWindow(2); | |
| 216 | |
| 217 // Check that only window3 is visible. | |
| 218 EXPECT_FALSE(window1->IsVisible()); | |
| 219 EXPECT_FALSE(window2->IsVisible()); | |
| 220 EXPECT_TRUE(window3->IsVisible()); | |
| 221 | |
| 222 // Close all windows. Note they should not be accessed after here. | |
| 223 delete window1; | |
| 224 delete window2; | |
| 225 delete window3; | |
| 226 | |
| 227 // No current window now. | |
| 228 EXPECT_EQ(NULL, layout_manager_->current_window_); | |
| 229 } | |
| 230 | |
| 231 } // namespace internal | |
| 232 } // namespace ash | |
| OLD | NEW |