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

Side by Side Diff: ash/wm/workspace/workspace_window_resizer_unittest.cc

Issue 10836065: Improve WorkspaceWindowResizer::CompleteDrag() so that the function moves the window to a root windo (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: final rebase Created 8 years, 4 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
« no previous file with comments | « ash/wm/workspace/workspace_window_resizer.cc ('k') | ui/aura/client/screen_position_client.h » ('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) 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/workspace/workspace_window_resizer.h" 5 #include "ash/wm/workspace/workspace_window_resizer.h"
6 6
7 #include "ash/screen_ash.h" 7 #include "ash/screen_ash.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "ash/shell_window_ids.h"
9 #include "ash/test/ash_test_base.h" 10 #include "ash/test/ash_test_base.h"
10 #include "ash/wm/property_util.h" 11 #include "ash/wm/property_util.h"
11 #include "ash/wm/workspace_controller.h" 12 #include "ash/wm/workspace_controller.h"
12 #include "base/string_number_conversions.h" 13 #include "base/string_number_conversions.h"
13 #include "ui/aura/root_window.h" 14 #include "ui/aura/root_window.h"
14 #include "ui/aura/test/test_window_delegate.h" 15 #include "ui/aura/test/test_window_delegate.h"
15 #include "ui/base/hit_test.h" 16 #include "ui/base/hit_test.h"
16 #include "ui/gfx/insets.h" 17 #include "ui/gfx/insets.h"
18 #include "ui/gfx/screen.h"
17 19
18 namespace ash { 20 namespace ash {
19 namespace internal { 21 namespace internal {
20 namespace { 22 namespace {
21 23
22 const int kRootHeight = 600; 24 const int kRootHeight = 600;
23 25
24 // A simple window delegate that returns the specified min size. 26 // A simple window delegate that returns the specified min size.
25 class TestWindowDelegate : public aura::test::TestWindowDelegate { 27 class TestWindowDelegate : public aura::test::TestWindowDelegate {
26 public: 28 public:
(...skipping 19 matching lines...) Expand all
46 class WorkspaceWindowResizerTest : public test::AshTestBase { 48 class WorkspaceWindowResizerTest : public test::AshTestBase {
47 public: 49 public:
48 WorkspaceWindowResizerTest() : window_(NULL) {} 50 WorkspaceWindowResizerTest() : window_(NULL) {}
49 virtual ~WorkspaceWindowResizerTest() {} 51 virtual ~WorkspaceWindowResizerTest() {}
50 52
51 virtual void SetUp() OVERRIDE { 53 virtual void SetUp() OVERRIDE {
52 AshTestBase::SetUp(); 54 AshTestBase::SetUp();
53 aura::RootWindow* root = Shell::GetPrimaryRootWindow(); 55 aura::RootWindow* root = Shell::GetPrimaryRootWindow();
54 root->SetHostSize(gfx::Size(800, kRootHeight)); 56 root->SetHostSize(gfx::Size(800, kRootHeight));
55 57
58 aura::Window* default_container =
59 Shell::GetContainer(root, kShellWindowId_DefaultContainer);
60
56 gfx::Rect root_bounds(root->bounds()); 61 gfx::Rect root_bounds(root->bounds());
57 EXPECT_EQ(kRootHeight, root_bounds.height()); 62 EXPECT_EQ(kRootHeight, root_bounds.height());
58 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets()); 63 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
59 window_.reset(new aura::Window(&delegate_)); 64 window_.reset(new aura::Window(&delegate_));
60 window_->Init(ui::LAYER_NOT_DRAWN); 65 window_->Init(ui::LAYER_NOT_DRAWN);
61 window_->SetParent(root); 66 window_->SetParent(default_container);
62 window_->set_id(1); 67 window_->set_id(1);
63 68
64 window2_.reset(new aura::Window(&delegate2_)); 69 window2_.reset(new aura::Window(&delegate2_));
65 window2_->Init(ui::LAYER_NOT_DRAWN); 70 window2_->Init(ui::LAYER_NOT_DRAWN);
66 window2_->SetParent(root); 71 window2_->SetParent(default_container);
67 window2_->set_id(2); 72 window2_->set_id(2);
68 73
69 window3_.reset(new aura::Window(&delegate3_)); 74 window3_.reset(new aura::Window(&delegate3_));
70 window3_->Init(ui::LAYER_NOT_DRAWN); 75 window3_->Init(ui::LAYER_NOT_DRAWN);
71 window3_->SetParent(root); 76 window3_->SetParent(default_container);
72 window3_->set_id(3); 77 window3_->set_id(3);
73 } 78 }
74 79
75 virtual void TearDown() OVERRIDE { 80 virtual void TearDown() OVERRIDE {
76 window_.reset(); 81 window_.reset();
77 window2_.reset(); 82 window2_.reset();
78 window3_.reset(); 83 window3_.reset();
79 AshTestBase::TearDown(); 84 AshTestBase::TearDown();
80 } 85 }
81 86
82 // Returns a string identifying the z-order of each of the known windows. 87 // Returns a string identifying the z-order of each of the known windows.
83 // The returned string constains the id of the known windows and is ordered 88 // The returned string constains the id of the known windows and is ordered
84 // from topmost to bottomost windows. 89 // from topmost to bottomost windows.
85 std::string WindowOrderAsString() const { 90 std::string WindowOrderAsString() const {
86 std::string result; 91 std::string result;
87 const aura::Window::Windows& windows = 92 aura::Window* default_container = Shell::GetContainer(
88 Shell::GetPrimaryRootWindow()->children(); 93 Shell::GetPrimaryRootWindow(), kShellWindowId_DefaultContainer);
94 const aura::Window::Windows& windows = default_container->children();
89 for (aura::Window::Windows::const_reverse_iterator i = windows.rbegin(); 95 for (aura::Window::Windows::const_reverse_iterator i = windows.rbegin();
90 i != windows.rend(); ++i) { 96 i != windows.rend(); ++i) {
91 if (*i == window_.get() || *i == window2_.get() || *i == window3_.get()) { 97 if (*i == window_.get() || *i == window2_.get() || *i == window3_.get()) {
92 if (!result.empty()) 98 if (!result.empty())
93 result += " "; 99 result += " ";
94 result += base::IntToString((*i)->id()); 100 result += base::IntToString((*i)->id());
95 } 101 }
96 } 102 }
97 return result; 103 return result;
98 } 104 }
99 105
100 protected: 106 protected:
101 void SetGridSize(int grid_size) { 107 void SetGridSize(int grid_size) {
102 Shell::TestApi shell_test(Shell::GetInstance()); 108 Shell::TestApi shell_test(Shell::GetInstance());
103 shell_test.workspace_controller()->SetGridSize(grid_size); 109 shell_test.workspace_controller()->SetGridSize(grid_size);
104 } 110 }
111
105 gfx::Point CalculateDragPoint(const WorkspaceWindowResizer& resizer, 112 gfx::Point CalculateDragPoint(const WorkspaceWindowResizer& resizer,
106 int delta_x, 113 int delta_x,
107 int delta_y) const { 114 int delta_y) const {
108 gfx::Point location = resizer.initial_location_in_parent(); 115 gfx::Point location = resizer.initial_location_in_parent();
109 location.set_x(location.x() + delta_x); 116 location.set_x(location.x() + delta_x);
110 location.set_y(location.y() + delta_y); 117 location.set_y(location.y() + delta_y);
111 return location; 118 return location;
112 } 119 }
113 120
114 std::vector<aura::Window*> empty_windows() const { 121 std::vector<aura::Window*> empty_windows() const {
115 return std::vector<aura::Window*>(); 122 return std::vector<aura::Window*>();
116 } 123 }
117 124
118 TestWindowDelegate delegate_; 125 TestWindowDelegate delegate_;
119 TestWindowDelegate delegate2_; 126 TestWindowDelegate delegate2_;
120 TestWindowDelegate delegate3_; 127 TestWindowDelegate delegate3_;
121 scoped_ptr<aura::Window> window_; 128 scoped_ptr<aura::Window> window_;
122 scoped_ptr<aura::Window> window2_; 129 scoped_ptr<aura::Window> window2_;
123 scoped_ptr<aura::Window> window3_; 130 scoped_ptr<aura::Window> window3_;
124 131
125 private: 132 private:
126 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizerTest); 133 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizerTest);
127 }; 134 };
128 135
136 // Fails on win_aura since wm::GetRootWindowRelativeToWindow is not implemented
137 // yet for the platform.
138 #if defined(OS_WIN)
139 #define MAYBE_WindowDragWithMultiMonitors \
140 DISABLED_WindowDragWithMultiMonitors
141 #define MAYBE_WindowDragWithMultiMonitorsRightToLeft \
142 DISABLED_WindowDragWithMultiMonitorsRightToLeft
143 #else
144 #define MAYBE_WindowDragWithMultiMonitors WindowDragWithMultiMonitors
145 #define MAYBE_WindowDragWithMultiMonitorsRightToLeft \
146 WindowDragWithMultiMonitorsRightToLeft
147 #endif
148
129 // Assertions around attached window resize dragging from the right with 2 149 // Assertions around attached window resize dragging from the right with 2
130 // windows. 150 // windows.
131 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_2) { 151 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_2) {
132 window_->SetBounds(gfx::Rect(0, 300, 400, 300)); 152 window_->SetBounds(gfx::Rect(0, 300, 400, 300));
133 window2_->SetBounds(gfx::Rect(400, 200, 100, 200)); 153 window2_->SetBounds(gfx::Rect(400, 200, 100, 200));
134 154
135 std::vector<aura::Window*> windows; 155 std::vector<aura::Window*> windows;
136 windows.push_back(window2_.get()); 156 windows.push_back(window2_.get());
137 SetGridSize(0); 157 SetGridSize(0);
138 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 158 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 467 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
448 ASSERT_TRUE(resizer.get()); 468 ASSERT_TRUE(resizer.get());
449 resizer->Drag(CalculateDragPoint(*resizer, 800, 10), 0); 469 resizer->Drag(CalculateDragPoint(*resizer, 800, 10), 0);
450 resizer->CompleteDrag(0); 470 resizer->CompleteDrag(0);
451 EXPECT_EQ("400,0 400x" + base::IntToString(bottom), 471 EXPECT_EQ("400,0 400x" + base::IntToString(bottom),
452 window_->bounds().ToString()); 472 window_->bounds().ToString());
453 ASSERT_TRUE(GetRestoreBoundsInScreen(window_.get())); 473 ASSERT_TRUE(GetRestoreBoundsInScreen(window_.get()));
454 EXPECT_EQ("20,30 50x60", GetRestoreBoundsInScreen(window_.get())->ToString()); 474 EXPECT_EQ("20,30 50x60", GetRestoreBoundsInScreen(window_.get())->ToString());
455 } 475 }
456 476
477 // Verifies a window can be moved from the primary display to another.
478 TEST_F(WorkspaceWindowResizerTest, MAYBE_WindowDragWithMultiMonitors) {
479 // The secondary display is logically on the right, but on the system (e.g. X)
480 // layer, it's below the primary one. See UpdateDisplay() in ash_test_base.cc.
481 UpdateDisplay("800x600,800x600");
482 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
483 ASSERT_EQ(2U, root_windows.size());
484
485 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60),
486 gfx::Screen::GetPrimaryDisplay());
487 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
488 {
489 SetGridSize(0);
490 // Grab (0, 0) of the window.
491 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
492 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
493 ASSERT_TRUE(resizer.get());
494 // Drag the pointer to the right. Once it reaches the right edge of the
495 // primary display, it warps to the secondary. Since the secondary root
496 // window's native origin held by aura::RootWindowHost is (0, 600), and a
497 // mouse drag event has a location in the primary root window's coordinates,
498 // (0, 610) below means (0, 10) in the second root window's coordinates.
499 resizer->Drag(CalculateDragPoint(*resizer, 0, 610), 0);
500 resizer->CompleteDrag(0);
501 // The whole window is on the secondary display now. The parent should be
502 // changed.
503 EXPECT_EQ(root_windows[1], window_->GetRootWindow());
504 EXPECT_EQ("0,10 50x60", window_->bounds().ToString());
505 }
506
507 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60),
508 gfx::Screen::GetPrimaryDisplay());
509 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
510 {
511 // Grab (0, 0) of the window and move the pointer to (790, 10).
512 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
513 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
514 ASSERT_TRUE(resizer.get());
515 resizer->Drag(CalculateDragPoint(*resizer, 790, 10), 0);
516 resizer->CompleteDrag(0);
517 // Since the pointer is still on the primary root window, the parent should
518 // not be changed.
519 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
520 EXPECT_EQ("790,10 50x60", window_->bounds().ToString());
521 }
522
523 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60),
524 gfx::Screen::GetPrimaryDisplay());
525 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
526 {
527 // Grab the top-right edge of the window and move the pointer to (0, 10)
528 // in the secondary root window's coordinates.
529 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
530 window_.get(), gfx::Point(49, 0), HTCAPTION, empty_windows()));
531 ASSERT_TRUE(resizer.get());
532 resizer->Drag(CalculateDragPoint(*resizer, -49, 610), 0);
533 resizer->CompleteDrag(0);
534 // Since the pointer is on the secondary, the parent should not be changed
535 // even though only small fraction of the window is within the secondary
536 // root window's bounds.
537 EXPECT_EQ(root_windows[1], window_->GetRootWindow());
538 EXPECT_EQ("-49,10 50x60", window_->bounds().ToString());
539 }
540 }
541
542 // Verifies a window can be moved from the secondary display to primary.
543 TEST_F(WorkspaceWindowResizerTest,
544 MAYBE_WindowDragWithMultiMonitorsRightToLeft) {
545 UpdateDisplay("800x600,800x600");
546 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
547 ASSERT_EQ(2U, root_windows.size());
548
549 window_->SetBoundsInScreen(
550 gfx::Rect(800, 00, 50, 60),
551 gfx::Screen::GetDisplayNearestWindow(root_windows[1]));
552 EXPECT_EQ(root_windows[1], window_->GetRootWindow());
553 {
554 SetGridSize(0);
555 // Grab (0, 0) of the window.
556 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
557 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
558 ASSERT_TRUE(resizer.get());
559 // Move the mouse near the right edge, (798, 0), of the primary display.
560 resizer->Drag(CalculateDragPoint(*resizer, 798, -600), 0);
561 resizer->CompleteDrag(0);
562 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
563 EXPECT_EQ("798,0 50x60", window_->bounds().ToString());
564 }
565 }
566
457 // Verifies windows are correctly restacked when reordering multiple windows. 567 // Verifies windows are correctly restacked when reordering multiple windows.
458 TEST_F(WorkspaceWindowResizerTest, RestackAttached) { 568 TEST_F(WorkspaceWindowResizerTest, RestackAttached) {
459 window_->SetBounds(gfx::Rect( 0, 0, 200, 300)); 569 window_->SetBounds(gfx::Rect( 0, 0, 200, 300));
460 window2_->SetBounds(gfx::Rect(200, 0, 100, 200)); 570 window2_->SetBounds(gfx::Rect(200, 0, 100, 200));
461 window3_->SetBounds(gfx::Rect(300, 0, 100, 100)); 571 window3_->SetBounds(gfx::Rect(300, 0, 100, 100));
462 572
463 { 573 {
464 std::vector<aura::Window*> windows; 574 std::vector<aura::Window*> windows;
465 windows.push_back(window2_.get()); 575 windows.push_back(window2_.get());
466 SetGridSize(10); 576 SetGridSize(10);
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 // Ctrl + drag the window to new poistion by adding (10, 12) to its origin, 756 // Ctrl + drag the window to new poistion by adding (10, 12) to its origin,
647 // the window should move to the exact position. 757 // the window should move to the exact position.
648 resizer->Drag(CalculateDragPoint(*resizer, 10, 12), 0); 758 resizer->Drag(CalculateDragPoint(*resizer, 10, 12), 0);
649 resizer->CompleteDrag(ui::EF_CONTROL_DOWN); 759 resizer->CompleteDrag(ui::EF_CONTROL_DOWN);
650 EXPECT_EQ("106,124 320x160", window_->bounds().ToString()); 760 EXPECT_EQ("106,124 320x160", window_->bounds().ToString());
651 } 761 }
652 762
653 } // namespace 763 } // namespace
654 } // namespace test 764 } // namespace test
655 } // namespace ash 765 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/workspace/workspace_window_resizer.cc ('k') | ui/aura/client/screen_position_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698