Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Side by Side Diff: ash/wm/compact_layout_manager_unittest.cc

Issue 9301016: add compact layout manager window transition unittest. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 = 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.
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();
James Cook 2012/01/30 22:12:20 nit: one space after =
alicet1 2012/01/30 23:52:53 Done.
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,
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
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_HAS_TEXTURE);
130 window->SetBounds(bounds);
131 window->SetParent(default_container());
132 window_util::MaximizeWindow(window);
133 return window;
134 }
135
136 aura::Window* default_container() const {
James Cook 2012/01/30 22:12:20 Hooray for simple utility functions to make the te
137 return ash::Shell::GetInstance()->GetContainer(
138 ash::internal::kShellWindowId_DefaultContainer);
139 }
140
141 int default_container_layer_width() const {
142 return default_container()->layer()->bounds().width();
143 }
144
145 ui::Transform default_container_layer_transform() const {
146 return default_container()->layer()->GetTargetTransform();
147 }
148
149 ui::AnimationContainerElement* animation_element() {
150 return default_container()->layer()->GetAnimator();
151 }
152
153 protected:
154 internal::CompactLayoutManager* layout_manager_;
155 };
156
157
158 TEST_F(CompactLayoutManagerTransitionTest, TransitionTest) {
159 // 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.
160 // to the layout.
161 aura::Window* window1 = CreateNormalWindow(0, kMaxBounds);
162 window1->Show();
163 EXPECT_EQ(kMaxBounds.width(), default_container_layer_width());
164 aura::Window* window2 = CreateNormalWindow(1, kMaxBounds);
165 window2->Show();
166 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
167 aura::Window* window3 = CreateNormalWindow(3, kMaxBounds);
168 window3->Show();
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
OLDNEW
« ash/test/test_shell_delegate.cc ('K') | « ash/wm/compact_layout_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698