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

Side by Side Diff: ash/wm/dock/docked_window_resizer_unittest.cc

Issue 115153002: wm: public window_types. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ozone deps Created 7 years 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
« no previous file with comments | « ash/wm/dock/docked_window_resizer.cc ('k') | ash/wm/drag_window_resizer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/dock/docked_window_resizer.h" 5 #include "ash/wm/dock/docked_window_resizer.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/launcher/launcher.h" 8 #include "ash/launcher/launcher.h"
9 #include "ash/root_window_controller.h" 9 #include "ash/root_window_controller.h"
10 #include "ash/screen_ash.h" 10 #include "ash/screen_ash.h"
(...skipping 21 matching lines...) Expand all
32 #include "ui/aura/test/test_window_delegate.h" 32 #include "ui/aura/test/test_window_delegate.h"
33 #include "ui/base/hit_test.h" 33 #include "ui/base/hit_test.h"
34 #include "ui/base/ui_base_types.h" 34 #include "ui/base/ui_base_types.h"
35 #include "ui/views/widget/widget.h" 35 #include "ui/views/widget/widget.h"
36 36
37 namespace ash { 37 namespace ash {
38 namespace internal { 38 namespace internal {
39 39
40 class DockedWindowResizerTest 40 class DockedWindowResizerTest
41 : public test::AshTestBase, 41 : public test::AshTestBase,
42 public testing::WithParamInterface<aura::client::WindowType> { 42 public testing::WithParamInterface<ui::wm::WindowType> {
43 public: 43 public:
44 DockedWindowResizerTest() : model_(NULL), window_type_(GetParam()) {} 44 DockedWindowResizerTest() : model_(NULL), window_type_(GetParam()) {}
45 virtual ~DockedWindowResizerTest() {} 45 virtual ~DockedWindowResizerTest() {}
46 46
47 virtual void SetUp() OVERRIDE { 47 virtual void SetUp() OVERRIDE {
48 CommandLine::ForCurrentProcess()->AppendSwitch( 48 CommandLine::ForCurrentProcess()->AppendSwitch(
49 ash::switches::kAshEnableDockedWindows); 49 ash::switches::kAshEnableDockedWindows);
50 AshTestBase::SetUp(); 50 AshTestBase::SetUp();
51 UpdateDisplay("600x400"); 51 UpdateDisplay("600x400");
52 test::ShellTestApi test_api(Shell::GetInstance()); 52 test::ShellTestApi test_api(Shell::GetInstance());
(...skipping 19 matching lines...) Expand all
72 } 72 }
73 int docked_alignment(const DockedWindowLayoutManager* layout_manager) const { 73 int docked_alignment(const DockedWindowLayoutManager* layout_manager) const {
74 return layout_manager->alignment_; 74 return layout_manager->alignment_;
75 } 75 }
76 aura::Window* CreateTestWindow(const gfx::Rect& bounds) { 76 aura::Window* CreateTestWindow(const gfx::Rect& bounds) {
77 aura::Window* window = CreateTestWindowInShellWithDelegateAndType( 77 aura::Window* window = CreateTestWindowInShellWithDelegateAndType(
78 &delegate_, 78 &delegate_,
79 window_type_, 79 window_type_,
80 0, 80 0,
81 bounds); 81 bounds);
82 if (window_type_ == aura::client::WINDOW_TYPE_PANEL) { 82 if (window_type_ == ui::wm::WINDOW_TYPE_PANEL) {
83 test::TestShelfDelegate* shelf_delegate = 83 test::TestShelfDelegate* shelf_delegate =
84 test::TestShelfDelegate::instance(); 84 test::TestShelfDelegate::instance();
85 shelf_delegate->AddLauncherItem(window); 85 shelf_delegate->AddLauncherItem(window);
86 PanelLayoutManager* manager = 86 PanelLayoutManager* manager =
87 static_cast<PanelLayoutManager*>( 87 static_cast<PanelLayoutManager*>(
88 Shell::GetContainer(window->GetRootWindow(), 88 Shell::GetContainer(window->GetRootWindow(),
89 internal::kShellWindowId_PanelContainer)-> 89 internal::kShellWindowId_PanelContainer)->
90 layout_manager()); 90 layout_manager());
91 manager->Relayout(); 91 manager->Relayout();
92 } 92 }
93 return window; 93 return window;
94 } 94 }
95 95
96 aura::Window* CreateModalWindow(const gfx::Rect& bounds) { 96 aura::Window* CreateModalWindow(const gfx::Rect& bounds) {
97 aura::Window* window = new aura::Window(&delegate_); 97 aura::Window* window = new aura::Window(&delegate_);
98 window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM); 98 window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM);
99 window->SetType(aura::client::WINDOW_TYPE_NORMAL); 99 window->SetType(ui::wm::WINDOW_TYPE_NORMAL);
100 window->Init(ui::LAYER_TEXTURED); 100 window->Init(ui::LAYER_TEXTURED);
101 window->Show(); 101 window->Show();
102 102
103 if (bounds.IsEmpty()) { 103 if (bounds.IsEmpty()) {
104 ParentWindowInPrimaryRootWindow(window); 104 ParentWindowInPrimaryRootWindow(window);
105 } else { 105 } else {
106 gfx::Display display = 106 gfx::Display display =
107 Shell::GetScreen()->GetDisplayMatching(bounds); 107 Shell::GetScreen()->GetDisplayMatching(bounds);
108 aura::Window* root = ash::Shell::GetInstance()->display_controller()-> 108 aura::Window* root = ash::Shell::GetInstance()->display_controller()->
109 GetRootWindowForDisplayId(display.id()); 109 GetRootWindowForDisplayId(display.id());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 162
163 void DragRevert() { 163 void DragRevert() {
164 resizer_->RevertDrag(); 164 resizer_->RevertDrag();
165 resizer_.reset(); 165 resizer_.reset();
166 } 166 }
167 167
168 // Panels are parented by panel container during drags. 168 // Panels are parented by panel container during drags.
169 // All other windows that are tested here are parented by dock container 169 // All other windows that are tested here are parented by dock container
170 // during drags. 170 // during drags.
171 int CorrectContainerIdDuringDrag() { 171 int CorrectContainerIdDuringDrag() {
172 if (window_type_ == aura::client::WINDOW_TYPE_PANEL) 172 if (window_type_ == ui::wm::WINDOW_TYPE_PANEL)
173 return internal::kShellWindowId_PanelContainer; 173 return internal::kShellWindowId_PanelContainer;
174 return internal::kShellWindowId_DockedContainer; 174 return internal::kShellWindowId_DockedContainer;
175 } 175 }
176 176
177 // Test dragging the window vertically (to detach if it is a panel) and then 177 // Test dragging the window vertically (to detach if it is a panel) and then
178 // horizontally to the edge with an added offset from the edge of |dx|. 178 // horizontally to the edge with an added offset from the edge of |dx|.
179 void DragRelativeToEdge(DockedEdge edge, 179 void DragRelativeToEdge(DockedEdge edge,
180 aura::Window* window, 180 aura::Window* window,
181 int dx) { 181 int dx) {
182 DragVerticallyAndRelativeToEdge( 182 DragVerticallyAndRelativeToEdge(
183 edge, 183 edge,
184 window, 184 window,
185 dx, window_type_ == aura::client::WINDOW_TYPE_PANEL ? -100 : 20, 185 dx,
186 25, 5); 186 window_type_ == ui::wm::WINDOW_TYPE_PANEL ? -100 : 20,
187 25,
188 5);
187 } 189 }
188 190
189 void DragToVerticalPositionAndToEdge(DockedEdge edge, 191 void DragToVerticalPositionAndToEdge(DockedEdge edge,
190 aura::Window* window, 192 aura::Window* window,
191 int y) { 193 int y) {
192 DragToVerticalPositionRelativeToEdge(edge, window, 0, y); 194 DragToVerticalPositionRelativeToEdge(edge, window, 0, y);
193 } 195 }
194 196
195 void DragToVerticalPositionRelativeToEdge(DockedEdge edge, 197 void DragToVerticalPositionRelativeToEdge(DockedEdge edge,
196 aura::Window* window, 198 aura::Window* window,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 DragEnd(); 231 DragEnd();
230 232
231 // x-coordinate can get adjusted by snapping or sticking. 233 // x-coordinate can get adjusted by snapping or sticking.
232 // y-coordinate could be changed by possible automatic layout if docked. 234 // y-coordinate could be changed by possible automatic layout if docked.
233 if (window->parent()->id() != internal::kShellWindowId_DockedContainer && 235 if (window->parent()->id() != internal::kShellWindowId_DockedContainer &&
234 !wm::GetWindowState(window)->HasRestoreBounds()) { 236 !wm::GetWindowState(window)->HasRestoreBounds()) {
235 EXPECT_EQ(initial_bounds.y() + dy, window->GetBoundsInScreen().y()); 237 EXPECT_EQ(initial_bounds.y() + dy, window->GetBoundsInScreen().y());
236 } 238 }
237 } 239 }
238 240
239 bool test_panels() const { 241 bool test_panels() const { return window_type_ == ui::wm::WINDOW_TYPE_PANEL; }
240 return window_type_ == aura::client::WINDOW_TYPE_PANEL;
241 }
242 242
243 const gfx::Point& initial_location_in_parent() const { 243 const gfx::Point& initial_location_in_parent() const {
244 return initial_location_in_parent_; 244 return initial_location_in_parent_;
245 } 245 }
246 246
247 private: 247 private:
248 scoped_ptr<WindowResizer> resizer_; 248 scoped_ptr<WindowResizer> resizer_;
249 ShelfModel* model_; 249 ShelfModel* model_;
250 aura::client::WindowType window_type_; 250 ui::wm::WindowType window_type_;
251 aura::test::TestWindowDelegate delegate_; 251 aura::test::TestWindowDelegate delegate_;
252 252
253 // Location at start of the drag in |window->parent()|'s coordinates. 253 // Location at start of the drag in |window->parent()|'s coordinates.
254 gfx::Point initial_location_in_parent_; 254 gfx::Point initial_location_in_parent_;
255 255
256 DISALLOW_COPY_AND_ASSIGN(DockedWindowResizerTest); 256 DISALLOW_COPY_AND_ASSIGN(DockedWindowResizerTest);
257 }; 257 };
258 258
259 // Verifies a window can be dragged and attached to the dock. 259 // Verifies a window can be dragged and attached to the dock.
260 TEST_P(DockedWindowResizerTest, AttachRightPrecise) { 260 TEST_P(DockedWindowResizerTest, AttachRightPrecise) {
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 534
535 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); 535 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
536 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); 536 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20);
537 537
538 // w1 should be docked at the right edge. 538 // w1 should be docked at the right edge.
539 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), 539 EXPECT_EQ(w1->GetRootWindow()->bounds().right(),
540 w1->GetBoundsInScreen().right()); 540 w1->GetBoundsInScreen().right());
541 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); 541 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id());
542 542
543 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegateAndType( 543 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegateAndType(
544 NULL, aura::client::WINDOW_TYPE_NORMAL, 0, gfx::Rect(20, 20, 150, 20))); 544 NULL, ui::wm::WINDOW_TYPE_NORMAL, 0, gfx::Rect(20, 20, 150, 20)));
545 wm::GetWindowState(w2.get())->Maximize(); 545 wm::GetWindowState(w2.get())->Maximize();
546 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w2->parent()->id()); 546 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w2->parent()->id());
547 EXPECT_TRUE(wm::GetWindowState(w2.get())->IsMaximized()); 547 EXPECT_TRUE(wm::GetWindowState(w2.get())->IsMaximized());
548 548
549 gfx::Rect work_area = 549 gfx::Rect work_area =
550 Shell::GetScreen()->GetDisplayNearestWindow(w1.get()).work_area(); 550 Shell::GetScreen()->GetDisplayNearestWindow(w1.get()).work_area();
551 DockedWindowLayoutManager* manager = 551 DockedWindowLayoutManager* manager =
552 static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager()); 552 static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager());
553 553
554 // Docked window should be centered vertically in the work area. 554 // Docked window should be centered vertically in the work area.
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after
1289 1289
1290 // Tests that docking and undocking a |window| with a transient child properly 1290 // Tests that docking and undocking a |window| with a transient child properly
1291 // maintains the parent of that transient child to be the same as the |window|. 1291 // maintains the parent of that transient child to be the same as the |window|.
1292 TEST_P(DockedWindowResizerTest, DragWindowWithTransientChild) { 1292 TEST_P(DockedWindowResizerTest, DragWindowWithTransientChild) {
1293 if (!SupportsHostWindowResize()) 1293 if (!SupportsHostWindowResize())
1294 return; 1294 return;
1295 1295
1296 // Create a window with a transient child. 1296 // Create a window with a transient child.
1297 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); 1297 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
1298 scoped_ptr<aura::Window> child(CreateTestWindowInShellWithDelegateAndType( 1298 scoped_ptr<aura::Window> child(CreateTestWindowInShellWithDelegateAndType(
1299 NULL, aura::client::WINDOW_TYPE_NORMAL, 0, gfx::Rect(20, 20, 150, 20))); 1299 NULL, ui::wm::WINDOW_TYPE_NORMAL, 0, gfx::Rect(20, 20, 150, 20)));
1300 window->AddTransientChild(child.get()); 1300 window->AddTransientChild(child.get());
1301 if (window->parent() != child->parent()) 1301 if (window->parent() != child->parent())
1302 window->parent()->AddChild(child.get()); 1302 window->parent()->AddChild(child.get());
1303 EXPECT_EQ(window.get(), child->transient_parent()); 1303 EXPECT_EQ(window.get(), child->transient_parent());
1304 1304
1305 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, window.get(), 20); 1305 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, window.get(), 20);
1306 1306
1307 // A window should be docked at the right edge. 1307 // A window should be docked at the right edge.
1308 EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id()); 1308 EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id());
1309 EXPECT_EQ(internal::kShellWindowId_DockedContainer, child->parent()->id()); 1309 EXPECT_EQ(internal::kShellWindowId_DockedContainer, child->parent()->id());
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1423 EXPECT_EQ(work_area.height(), w1->bounds().height()); 1423 EXPECT_EQ(work_area.height(), w1->bounds().height());
1424 EXPECT_EQ(work_area.x(), w1->bounds().x()); 1424 EXPECT_EQ(work_area.x(), w1->bounds().x());
1425 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w1->parent()->id()); 1425 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w1->parent()->id());
1426 EXPECT_FALSE(window_state->IsDocked()); 1426 EXPECT_FALSE(window_state->IsDocked());
1427 EXPECT_TRUE(window_state->IsSnapped()); 1427 EXPECT_TRUE(window_state->IsSnapped());
1428 } 1428 }
1429 1429
1430 // Tests run twice - on both panels and normal windows 1430 // Tests run twice - on both panels and normal windows
1431 INSTANTIATE_TEST_CASE_P(NormalOrPanel, 1431 INSTANTIATE_TEST_CASE_P(NormalOrPanel,
1432 DockedWindowResizerTest, 1432 DockedWindowResizerTest,
1433 testing::Values(aura::client::WINDOW_TYPE_NORMAL, 1433 testing::Values(ui::wm::WINDOW_TYPE_NORMAL,
1434 aura::client::WINDOW_TYPE_PANEL)); 1434 ui::wm::WINDOW_TYPE_PANEL));
1435 } // namespace internal 1435 } // namespace internal
1436 } // namespace ash 1436 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/dock/docked_window_resizer.cc ('k') | ash/wm/drag_window_resizer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698