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

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

Issue 2700523004: Remove docked windows entirely in M59. (Closed)
Patch Set: Rebase Created 3 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
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/toplevel_window_event_handler.h" 5 #include "ash/wm/toplevel_window_event_handler.h"
6 6
7 #include "ash/common/wm/window_state.h" 7 #include "ash/common/wm/window_state.h"
8 #include "ash/common/wm/wm_event.h" 8 #include "ash/common/wm/wm_event.h"
9 #include "ash/common/wm/workspace_controller.h" 9 #include "ash/common/wm/workspace_controller.h"
10 #include "ash/public/cpp/shell_window_ids.h" 10 #include "ash/public/cpp/shell_window_ids.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 w1->set_id(1); 67 w1->set_id(1);
68 w1->Init(ui::LAYER_TEXTURED); 68 w1->Init(ui::LAYER_TEXTURED);
69 aura::Window* parent = Shell::GetContainer(Shell::GetPrimaryRootWindow(), 69 aura::Window* parent = Shell::GetContainer(Shell::GetPrimaryRootWindow(),
70 kShellWindowId_DefaultContainer); 70 kShellWindowId_DefaultContainer);
71 parent->AddChild(w1); 71 parent->AddChild(w1);
72 w1->SetBounds(gfx::Rect(0, 0, 100, 100)); 72 w1->SetBounds(gfx::Rect(0, 0, 100, 100));
73 w1->Show(); 73 w1->Show();
74 return w1; 74 return w1;
75 } 75 }
76 76
77 aura::Window* CreatePanelWindow(int hittest_code) {
78 TestWindowDelegate* d1 = new TestWindowDelegate(hittest_code);
79 aura::Window* w1 = new aura::Window(d1);
80 w1->SetType(ui::wm::WINDOW_TYPE_PANEL);
81 w1->set_id(1);
82 w1->Init(ui::LAYER_TEXTURED);
83 aura::Window* parent = Shell::GetContainer(Shell::GetPrimaryRootWindow(),
84 kShellWindowId_PanelContainer);
85 parent->AddChild(w1);
86 w1->SetBounds(gfx::Rect(0, 0, 100, 100));
87 w1->Show();
88 return w1;
89 }
90
77 void DragFromCenterBy(aura::Window* window, int dx, int dy) { 91 void DragFromCenterBy(aura::Window* window, int dx, int dy) {
78 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), window); 92 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), window);
79 generator.DragMouseBy(dx, dy); 93 generator.DragMouseBy(dx, dy);
80 } 94 }
81 95
82 void TouchDragFromCenterBy(aura::Window* window, int dx, int dy) { 96 void TouchDragFromCenterBy(aura::Window* window, int dx, int dy) {
83 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), window); 97 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), window);
84 generator.PressMoveAndReleaseTouchBy(dx, dy); 98 generator.PressMoveAndReleaseTouchBy(dx, dy);
85 } 99 }
86 100
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 const gfx::Size size = w1->bounds().size(); 141 const gfx::Size size = w1->bounds().size();
128 wm::WindowState* window_state = ash::wm::GetWindowState(w1.get()); 142 wm::WindowState* window_state = ash::wm::GetWindowState(w1.get());
129 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), w1.get()); 143 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), w1.get());
130 144
131 // Explicitly enable window position auto management, and expect it to be 145 // Explicitly enable window position auto management, and expect it to be
132 // restored after drag completes. 146 // restored after drag completes.
133 window_state->set_window_position_managed(true); 147 window_state->set_window_position_managed(true);
134 generator.PressLeftButton(); 148 generator.PressLeftButton();
135 aura::client::WindowMoveClient* move_client = 149 aura::client::WindowMoveClient* move_client =
136 aura::client::GetWindowMoveClient(w1->GetRootWindow()); 150 aura::client::GetWindowMoveClient(w1->GetRootWindow());
137 // generator.PressLeftButton();
138 base::ThreadTaskRunnerHandle::Get()->PostTask( 151 base::ThreadTaskRunnerHandle::Get()->PostTask(
139 FROM_HERE, 152 FROM_HERE,
140 base::Bind(&ContinueAndCompleteDrag, base::Unretained(&generator), 153 base::Bind(&ContinueAndCompleteDrag, base::Unretained(&generator),
141 base::Unretained(window_state), base::Unretained(w1.get()))); 154 base::Unretained(window_state), base::Unretained(w1.get())));
142 EXPECT_EQ(aura::client::MOVE_SUCCESSFUL, 155 EXPECT_EQ(aura::client::MOVE_SUCCESSFUL,
143 move_client->RunMoveLoop(w1.get(), gfx::Vector2d(100, 100), 156 move_client->RunMoveLoop(w1.get(), gfx::Vector2d(100, 100),
144 aura::client::WINDOW_MOVE_SOURCE_MOUSE)); 157 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
145 // Window position auto manage property should be restored to true. 158 // Window position auto manage property should be restored to true.
146 EXPECT_TRUE(window_state->window_position_managed()); 159 EXPECT_TRUE(window_state->window_position_managed());
147 // Position should have been offset by 100,100. 160 // Position should have been offset by 100,100.
(...skipping 13 matching lines...) Expand all
161 move_client->RunMoveLoop(w1.get(), gfx::Vector2d(100, 100), 174 move_client->RunMoveLoop(w1.get(), gfx::Vector2d(100, 100),
162 aura::client::WINDOW_MOVE_SOURCE_MOUSE)); 175 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
163 // Window position auto manage property should be restored to true. 176 // Window position auto manage property should be restored to true.
164 EXPECT_FALSE(window_state->window_position_managed()); 177 EXPECT_FALSE(window_state->window_position_managed());
165 // Position should have been offset by 100,100. 178 // Position should have been offset by 100,100.
166 EXPECT_EQ("200,200", w1->bounds().origin().ToString()); 179 EXPECT_EQ("200,200", w1->bounds().origin().ToString());
167 // Size should remain the same. 180 // Size should remain the same.
168 EXPECT_EQ(size.ToString(), w1->bounds().size().ToString()); 181 EXPECT_EQ(size.ToString(), w1->bounds().size().ToString());
169 } 182 }
170 183
171 namespace {
172
173 class CancelDragObserver : public aura::WindowObserver {
174 public:
175 CancelDragObserver() {}
176 ~CancelDragObserver() override {}
177
178 void OnWindowHierarchyChanging(const HierarchyChangeParams& params) override {
179 aura::client::CaptureClient* client =
180 aura::client::GetCaptureClient(params.target->GetRootWindow());
181 client->SetCapture(nullptr);
182 }
183
184 private:
185 DISALLOW_COPY_AND_ASSIGN(CancelDragObserver);
186 };
187
188 } // namespace
189
190 // Cancelling drag while starting window drag should not crash. 184 // Cancelling drag while starting window drag should not crash.
191 TEST_F(ToplevelWindowEventHandlerTest, CancelWhileDragStart) { 185 TEST_F(ToplevelWindowEventHandlerTest, CancelWhileDragStart) {
192 std::unique_ptr<aura::Window> w1(CreateWindow(HTCAPTION)); 186 std::unique_ptr<aura::Window> w1(CreatePanelWindow(HTCAPTION));
193 CancelDragObserver observer;
194 w1->AddObserver(&observer);
195 gfx::Point origin = w1->bounds().origin(); 187 gfx::Point origin = w1->bounds().origin();
196 DragFromCenterBy(w1.get(), 100, 100); 188 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), w1.get());
189 generator.PressLeftButton();
190 generator.MoveMouseBy(100, 100);
191 generator.PressKey(ui::VKEY_ESCAPE, 0);
192 generator.ReleaseLeftButton();
197 EXPECT_EQ(origin, w1->bounds().origin()); 193 EXPECT_EQ(origin, w1->bounds().origin());
198 w1->RemoveObserver(&observer);
199 } 194 }
200 195
201 TEST_F(ToplevelWindowEventHandlerTest, BottomRight) { 196 TEST_F(ToplevelWindowEventHandlerTest, BottomRight) {
202 std::unique_ptr<aura::Window> w1(CreateWindow(HTBOTTOMRIGHT)); 197 std::unique_ptr<aura::Window> w1(CreateWindow(HTBOTTOMRIGHT));
203 gfx::Point position = w1->bounds().origin(); 198 gfx::Point position = w1->bounds().origin();
204 DragFromCenterBy(w1.get(), 100, 100); 199 DragFromCenterBy(w1.get(), 100, 100);
205 // Position should not have changed. 200 // Position should not have changed.
206 EXPECT_EQ(position.ToString(), w1->bounds().origin().ToString()); 201 EXPECT_EQ(position.ToString(), w1->bounds().origin().ToString());
207 // Size should have increased by 100,100. 202 // Size should have increased by 100,100.
208 EXPECT_EQ(gfx::Size(200, 200).ToString(), w1->bounds().size().ToString()); 203 EXPECT_EQ(gfx::Size(200, 200).ToString(), w1->bounds().size().ToString());
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 display_manager()->SetLayoutForCurrentDisplays(builder.Build()); 818 display_manager()->SetLayoutForCurrentDisplays(builder.Build());
824 819
825 const gfx::Size initial_window_size(330, 230); 820 const gfx::Size initial_window_size(330, 230);
826 std::unique_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegateAndType( 821 std::unique_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegateAndType(
827 new TestWindowDelegate(HTCAPTION), ui::wm::WINDOW_TYPE_NORMAL, 0, 822 new TestWindowDelegate(HTCAPTION), ui::wm::WINDOW_TYPE_NORMAL, 0,
828 gfx::Rect(initial_window_size))); 823 gfx::Rect(initial_window_size)));
829 824
830 // Snap the window to the right. 825 // Snap the window to the right.
831 wm::WindowState* window_state = wm::GetWindowState(w1.get()); 826 wm::WindowState* window_state = wm::GetWindowState(w1.get());
832 ASSERT_TRUE(window_state->CanSnap()); 827 ASSERT_TRUE(window_state->CanSnap());
833 const wm::WMEvent event(wm::WM_EVENT_CYCLE_SNAP_DOCK_RIGHT); 828 const wm::WMEvent event(wm::WM_EVENT_CYCLE_SNAP_RIGHT);
834 window_state->OnWMEvent(&event); 829 window_state->OnWMEvent(&event);
835 ASSERT_TRUE(window_state->IsSnapped()); 830 ASSERT_TRUE(window_state->IsSnapped());
836 831
837 // Drag the window to the secondary display. 832 // Drag the window to the secondary display.
838 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), w1.get()); 833 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), w1.get());
839 generator.DragMouseTo(472, -462); 834 generator.DragMouseTo(472, -462);
840 835
841 // Expect the window is no longer snapped and its size was restored to the 836 // Expect the window is no longer snapped and its size was restored to the
842 // initial size. 837 // initial size.
843 EXPECT_FALSE(window_state->IsSnapped()); 838 EXPECT_FALSE(window_state->IsSnapped());
844 EXPECT_EQ(initial_window_size.ToString(), w1->bounds().size().ToString()); 839 EXPECT_EQ(initial_window_size.ToString(), w1->bounds().size().ToString());
845 840
846 // The window is now fully contained in the secondary display. 841 // The window is now fully contained in the secondary display.
847 EXPECT_TRUE(display_manager()->GetSecondaryDisplay().bounds().Contains( 842 EXPECT_TRUE(display_manager()->GetSecondaryDisplay().bounds().Contains(
848 w1->GetBoundsInScreen())); 843 w1->GetBoundsInScreen()));
849 } 844 }
850 845
851 // Showing the resize shadows when the mouse is over the window edges is tested 846 // Showing the resize shadows when the mouse is over the window edges is tested
852 // in resize_shadow_and_cursor_test.cc 847 // in resize_shadow_and_cursor_test.cc
853 848
854 } // namespace test 849 } // namespace test
855 } // namespace ash 850 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698