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/workspace/workspace_window_resizer.h" |
| 6 |
| 7 #include "ash/shell.h" |
| 8 #include "ash/test/ash_test_base.h" |
| 9 #include "ui/aura/root_window.h" |
| 10 #include "ui/aura/screen_aura.h" |
| 11 #include "ui/aura/test/test_window_delegate.h" |
| 12 #include "ui/base/hit_test.h" |
| 13 |
| 14 namespace ash { |
| 15 namespace internal { |
| 16 namespace { |
| 17 |
| 18 const int kRootHeight = 600; |
| 19 |
| 20 // A simple window delegate that returns the specified min size. |
| 21 class TestWindowDelegate : public aura::test::TestWindowDelegate { |
| 22 public: |
| 23 TestWindowDelegate() { |
| 24 } |
| 25 virtual ~TestWindowDelegate() {} |
| 26 |
| 27 void set_min_size(const gfx::Size& size) { |
| 28 min_size_ = size; |
| 29 } |
| 30 |
| 31 private: |
| 32 // Overridden from aura::Test::TestWindowDelegate: |
| 33 virtual gfx::Size GetMinimumSize() const OVERRIDE { |
| 34 return min_size_; |
| 35 } |
| 36 |
| 37 gfx::Size min_size_; |
| 38 |
| 39 DISALLOW_COPY_AND_ASSIGN(TestWindowDelegate); |
| 40 }; |
| 41 |
| 42 class WorkspaceWindowResizerTest : public test::AshTestBase { |
| 43 public: |
| 44 WorkspaceWindowResizerTest() : window_(NULL) {} |
| 45 virtual ~WorkspaceWindowResizerTest() {} |
| 46 |
| 47 virtual void SetUp() OVERRIDE { |
| 48 AshTestBase::SetUp(); |
| 49 aura::RootWindow* root = Shell::GetInstance()->GetRootWindow(); |
| 50 root->SetBounds(gfx::Rect(0, 0, 800, kRootHeight)); |
| 51 gfx::Rect root_bounds(root->bounds()); |
| 52 EXPECT_EQ(kRootHeight, root_bounds.height()); |
| 53 root->screen()->set_work_area_insets(gfx::Insets()); |
| 54 window_.reset(new aura::Window(&delegate_)); |
| 55 window_->Init(ui::Layer::LAYER_NOT_DRAWN); |
| 56 window_->SetParent(Shell::GetInstance()->GetRootWindow()); |
| 57 } |
| 58 |
| 59 virtual void TearDown() OVERRIDE { |
| 60 window_.reset(); |
| 61 AshTestBase::TearDown(); |
| 62 } |
| 63 |
| 64 protected: |
| 65 gfx::Point CalculateDragPoint(const WindowResizer& resizer, |
| 66 int delta_y) const { |
| 67 gfx::Point location = resizer.initial_location_in_parent(); |
| 68 location.set_y(location.y() + delta_y); |
| 69 aura::Window::ConvertPointToWindow(window_->parent(), window_.get(), |
| 70 &location); |
| 71 return location; |
| 72 } |
| 73 |
| 74 TestWindowDelegate delegate_; |
| 75 scoped_ptr<aura::Window> window_; |
| 76 |
| 77 private: |
| 78 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizerTest); |
| 79 }; |
| 80 |
| 81 // Assertions around making sure dragging shrinks when appropriate. |
| 82 TEST_F(WorkspaceWindowResizerTest, ShrinkOnDrag) { |
| 83 int initial_y = 300; |
| 84 window_->SetBounds(gfx::Rect(0, initial_y, 400, 296)); |
| 85 |
| 86 // Drag down past the bottom of the screen, height should stop when it hits |
| 87 // the bottom. |
| 88 { |
| 89 WorkspaceWindowResizer resizer(window_.get(), gfx::Point(), HTBOTTOM, 0); |
| 90 EXPECT_TRUE(resizer.is_resizable()); |
| 91 resizer.Drag(CalculateDragPoint(resizer, 600)); |
| 92 EXPECT_EQ(kRootHeight - initial_y, window_->bounds().height()); |
| 93 |
| 94 // Drag up 10 and make sure height is the same. |
| 95 resizer.Drag(CalculateDragPoint(resizer, 590)); |
| 96 EXPECT_EQ(kRootHeight - initial_y, window_->bounds().height()); |
| 97 } |
| 98 |
| 99 { |
| 100 // Move the window down 10 pixels, the height should change. |
| 101 int initial_height = window_->bounds().height(); |
| 102 WorkspaceWindowResizer resizer(window_.get(), gfx::Point(), HTCAPTION, 0); |
| 103 resizer.Drag(CalculateDragPoint(resizer, 10)); |
| 104 EXPECT_EQ(initial_height - 10, window_->bounds().height()); |
| 105 |
| 106 // Move up 10, height should grow. |
| 107 resizer.Drag(CalculateDragPoint(resizer, 0)); |
| 108 EXPECT_EQ(initial_height, window_->bounds().height()); |
| 109 |
| 110 // Move up another 10, height shouldn't change. |
| 111 resizer.Drag(CalculateDragPoint(resizer, -10)); |
| 112 EXPECT_EQ(initial_height, window_->bounds().height()); |
| 113 } |
| 114 } |
| 115 |
| 116 // More assertions around making sure dragging shrinks when appropriate. |
| 117 TEST_F(WorkspaceWindowResizerTest, ShrinkOnDrag2) { |
| 118 window_->SetBounds(gfx::Rect(0, 300, 400, 300)); |
| 119 |
| 120 // Drag down past the bottom of the screen, height should stop when it hits |
| 121 // the bottom. |
| 122 { |
| 123 WorkspaceWindowResizer resizer(window_.get(), gfx::Point(), HTCAPTION, 0); |
| 124 EXPECT_TRUE(resizer.is_resizable()); |
| 125 resizer.Drag(CalculateDragPoint(resizer, 200)); |
| 126 EXPECT_EQ(500, window_->bounds().y()); |
| 127 EXPECT_EQ(100, window_->bounds().height()); |
| 128 // End and start a new drag session. |
| 129 } |
| 130 |
| 131 { |
| 132 // Drag up 400. |
| 133 WorkspaceWindowResizer resizer(window_.get(), gfx::Point(), HTCAPTION, 0); |
| 134 resizer.Drag(CalculateDragPoint(resizer, -400)); |
| 135 EXPECT_EQ(100, window_->bounds().y()); |
| 136 EXPECT_EQ(300, window_->bounds().height()); |
| 137 } |
| 138 } |
| 139 |
| 140 // Moves enough to shrink, then moves up twice to expose more than was initially |
| 141 // exposed. |
| 142 TEST_F(WorkspaceWindowResizerTest, ShrinkMoveThanMoveUp) { |
| 143 window_->SetBounds(gfx::Rect(0, 300, 400, 300)); |
| 144 |
| 145 // Drag down past the bottom of the screen, height should stop when it hits |
| 146 // the bottom. |
| 147 { |
| 148 WorkspaceWindowResizer resizer(window_.get(), gfx::Point(), HTCAPTION, 0); |
| 149 EXPECT_TRUE(resizer.is_resizable()); |
| 150 resizer.Drag(CalculateDragPoint(resizer, 200)); |
| 151 EXPECT_EQ(500, window_->bounds().y()); |
| 152 EXPECT_EQ(100, window_->bounds().height()); |
| 153 // End and start a new drag session. |
| 154 } |
| 155 |
| 156 { |
| 157 WorkspaceWindowResizer resizer(window_.get(), gfx::Point(), HTCAPTION, 0); |
| 158 resizer.Drag(CalculateDragPoint(resizer, -400)); |
| 159 resizer.Drag(CalculateDragPoint(resizer, -450)); |
| 160 EXPECT_EQ(50, window_->bounds().y()); |
| 161 EXPECT_EQ(300, window_->bounds().height()); |
| 162 } |
| 163 } |
| 164 |
| 165 // Makes sure shrinking honors the grid appropriately. |
| 166 TEST_F(WorkspaceWindowResizerTest, ShrinkWithGrid) { |
| 167 window_->SetBounds(gfx::Rect(0, 300, 400, 296)); |
| 168 |
| 169 WorkspaceWindowResizer resizer(window_.get(), gfx::Point(), HTCAPTION, 5); |
| 170 EXPECT_TRUE(resizer.is_resizable()); |
| 171 // Drag down 8 pixels. |
| 172 resizer.Drag(CalculateDragPoint(resizer, 8)); |
| 173 resizer.CompleteDrag(); |
| 174 EXPECT_EQ(310, window_->bounds().y()); |
| 175 EXPECT_EQ(kRootHeight - 310, window_->bounds().height()); |
| 176 } |
| 177 |
| 178 // Makes sure once a window has been shrunk it can grow bigger than obscured |
| 179 // height |
| 180 TEST_F(WorkspaceWindowResizerTest, ShrinkThanGrow) { |
| 181 int initial_y = 400; |
| 182 int initial_height = 150; |
| 183 window_->SetBounds(gfx::Rect(0, initial_y, 400, initial_height)); |
| 184 |
| 185 // Most past the bottom of the screen, height should stop when it hits the |
| 186 // bottom. |
| 187 { |
| 188 WorkspaceWindowResizer resizer(window_.get(), gfx::Point(), HTCAPTION, 0); |
| 189 resizer.Drag(CalculateDragPoint(resizer, 150)); |
| 190 EXPECT_EQ(550, window_->bounds().y()); |
| 191 EXPECT_EQ(50, window_->bounds().height()); |
| 192 } |
| 193 |
| 194 // Resize the window 500 pixels up. |
| 195 { |
| 196 WorkspaceWindowResizer resizer(window_.get(), gfx::Point(), HTTOP, 0); |
| 197 resizer.Drag(CalculateDragPoint(resizer, -500)); |
| 198 EXPECT_EQ(50, window_->bounds().y()); |
| 199 EXPECT_EQ(550, window_->bounds().height()); |
| 200 } |
| 201 } |
| 202 |
| 203 // Makes sure once a window has been shrunk it can grow bigger than obscured |
| 204 // height |
| 205 TEST_F(WorkspaceWindowResizerTest, DontRememberAfterMove) { |
| 206 window_->SetBounds(gfx::Rect(0, 300, 400, 300)); |
| 207 |
| 208 // Most past the bottom of the screen, height should stop when it hits the |
| 209 // bottom. |
| 210 { |
| 211 WorkspaceWindowResizer resizer(window_.get(), gfx::Point(), HTCAPTION, 0); |
| 212 resizer.Drag(CalculateDragPoint(resizer, 150)); |
| 213 EXPECT_EQ(450, window_->bounds().y()); |
| 214 EXPECT_EQ(150, window_->bounds().height()); |
| 215 resizer.Drag(CalculateDragPoint(resizer, -150)); |
| 216 EXPECT_EQ(150, window_->bounds().y()); |
| 217 EXPECT_EQ(300, window_->bounds().height()); |
| 218 } |
| 219 |
| 220 // Resize it slightly. |
| 221 { |
| 222 WorkspaceWindowResizer resizer(window_.get(), gfx::Point(), HTBOTTOM, 0); |
| 223 resizer.Drag(CalculateDragPoint(resizer, -100)); |
| 224 EXPECT_EQ(150, window_->bounds().y()); |
| 225 EXPECT_EQ(200, window_->bounds().height()); |
| 226 } |
| 227 |
| 228 { |
| 229 // Move it down then back up. |
| 230 WorkspaceWindowResizer resizer(window_.get(), gfx::Point(), HTCAPTION, 0); |
| 231 resizer.Drag(CalculateDragPoint(resizer, 400)); |
| 232 EXPECT_EQ(550, window_->bounds().y()); |
| 233 EXPECT_EQ(50, window_->bounds().height()); |
| 234 |
| 235 resizer.Drag(CalculateDragPoint(resizer, 0)); |
| 236 EXPECT_EQ(150, window_->bounds().y()); |
| 237 EXPECT_EQ(200, window_->bounds().height()); |
| 238 } |
| 239 } |
| 240 |
| 241 // Makes sure we honor the min size. |
| 242 TEST_F(WorkspaceWindowResizerTest, HonorMin) { |
| 243 delegate_.set_min_size(gfx::Size(50, 100)); |
| 244 window_->SetBounds(gfx::Rect(0, 300, 400, 300)); |
| 245 |
| 246 // Most past the bottom of the screen, height should stop when it hits the |
| 247 // bottom. |
| 248 { |
| 249 WorkspaceWindowResizer resizer(window_.get(), gfx::Point(), HTCAPTION, 0); |
| 250 resizer.Drag(CalculateDragPoint(resizer, 350)); |
| 251 EXPECT_EQ(500, window_->bounds().y()); |
| 252 EXPECT_EQ(100, window_->bounds().height()); |
| 253 |
| 254 resizer.Drag(CalculateDragPoint(resizer, 300)); |
| 255 EXPECT_EQ(500, window_->bounds().y()); |
| 256 EXPECT_EQ(100, window_->bounds().height()); |
| 257 |
| 258 resizer.Drag(CalculateDragPoint(resizer, 250)); |
| 259 EXPECT_EQ(500, window_->bounds().y()); |
| 260 EXPECT_EQ(100, window_->bounds().height()); |
| 261 |
| 262 resizer.Drag(CalculateDragPoint(resizer, 100)); |
| 263 EXPECT_EQ(400, window_->bounds().y()); |
| 264 EXPECT_EQ(200, window_->bounds().height()); |
| 265 |
| 266 resizer.Drag(CalculateDragPoint(resizer, -100)); |
| 267 EXPECT_EQ(200, window_->bounds().y()); |
| 268 EXPECT_EQ(300, window_->bounds().height()); |
| 269 } |
| 270 } |
| 271 |
| 272 } // namespace |
| 273 } // namespace test |
| 274 } // namespace aura |
OLD | NEW |