Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / ash / wm / workspace / workspace_event_handler_unittest.cc
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_event_handler.h"
6
7 #include "ash/screen_util.h"
8 #include "ash/shell.h"
9 #include "ash/test/ash_test_base.h"
10 #include "ash/wm/window_state.h"
11 #include "ash/wm/window_util.h"
12 #include "ash/wm/wm_event.h"
13 #include "ash/wm/workspace_controller.h"
14 #include "ash/wm/workspace_controller_test_helper.h"
15 #include "ui/aura/client/aura_constants.h"
16 #include "ui/aura/test/test_window_delegate.h"
17 #include "ui/aura/window.h"
18 #include "ui/aura/window_tree_host.h"
19 #include "ui/base/hit_test.h"
20 #include "ui/events/event_processor.h"
21 #include "ui/events/test/event_generator.h"
22 #include "ui/gfx/screen.h"
23 #include "ui/wm/core/window_util.h"
24 #include "ui/wm/public/window_move_client.h"
25
26 #if defined(OS_WIN)
27 #include "base/win/windows_version.h"
28 #endif
29
30 namespace ash {
31
32 class WorkspaceEventHandlerTest : public test::AshTestBase {
33  public:
34   WorkspaceEventHandlerTest() {}
35   ~WorkspaceEventHandlerTest() override {}
36
37  protected:
38   aura::Window* CreateTestWindow(aura::WindowDelegate* delegate,
39                                  const gfx::Rect& bounds) {
40     aura::Window* window = new aura::Window(delegate);
41     window->SetType(ui::wm::WINDOW_TYPE_NORMAL);
42     window->Init(aura::WINDOW_LAYER_TEXTURED);
43     ParentWindowInPrimaryRootWindow(window);
44     window->SetBounds(bounds);
45     window->Show();
46     return window;
47   }
48
49  private:
50   DISALLOW_COPY_AND_ASSIGN(WorkspaceEventHandlerTest);
51 };
52
53 // Keeps track of the properties changed of a particular window.
54 class WindowPropertyObserver : public aura::WindowObserver {
55  public:
56   explicit WindowPropertyObserver(aura::Window* window)
57       : window_(window) {
58     window->AddObserver(this);
59   }
60
61   ~WindowPropertyObserver() override { window_->RemoveObserver(this); }
62
63   bool DidPropertyChange(const void* property) const {
64     return std::find(properties_changed_.begin(),
65                      properties_changed_.end(),
66                      property) != properties_changed_.end();
67   }
68
69  private:
70   void OnWindowPropertyChanged(aura::Window* window,
71                                const void* key,
72                                intptr_t old) override {
73     properties_changed_.push_back(key);
74   }
75
76   aura::Window* window_;
77   std::vector<const void*> properties_changed_;
78
79   DISALLOW_COPY_AND_ASSIGN(WindowPropertyObserver);
80 };
81
82 TEST_F(WorkspaceEventHandlerTest, DoubleClickSingleAxisResizeEdge) {
83   // Double clicking the vertical resize edge of a window should maximize it
84   // vertically.
85   gfx::Rect restored_bounds(10, 10, 50, 50);
86   aura::test::TestWindowDelegate delegate;
87   scoped_ptr<aura::Window> window(CreateTestWindow(&delegate, restored_bounds));
88
89   wm::ActivateWindow(window.get());
90
91   gfx::Rect work_area = Shell::GetScreen()->GetDisplayNearestWindow(
92       window.get()).work_area();
93
94   ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
95                                      window.get());
96
97   // Double-click the top resize edge.
98   delegate.set_window_component(HTTOP);
99   // On X a double click actually generates a drag between each press/release.
100   // Explicitly trigger this path since we had bugs in dealing with it
101   // correctly.
102   generator.PressLeftButton();
103   generator.ReleaseLeftButton();
104   generator.set_flags(ui::EF_IS_DOUBLE_CLICK);
105   generator.PressLeftButton();
106   generator.MoveMouseTo(generator.current_location(), 1);
107   generator.ReleaseLeftButton();
108   gfx::Rect bounds_in_screen = window->GetBoundsInScreen();
109   EXPECT_EQ(restored_bounds.x(), bounds_in_screen.x());
110   EXPECT_EQ(restored_bounds.width(), bounds_in_screen.width());
111   EXPECT_EQ(work_area.y(), bounds_in_screen.y());
112   EXPECT_EQ(work_area.height(), bounds_in_screen.height());
113
114   wm::WindowState* window_state = wm::GetWindowState(window.get());
115   // Single-axis maximization is not considered real maximization.
116   EXPECT_FALSE(window_state->IsMaximized());
117
118   // Restore.
119   generator.DoubleClickLeftButton();
120   bounds_in_screen = window->GetBoundsInScreen();
121   EXPECT_EQ(restored_bounds.ToString(), bounds_in_screen.ToString());
122   // Note that it should not even be restored at this point, it should have
123   // also cleared the restore rectangle.
124   EXPECT_FALSE(window_state->HasRestoreBounds());
125
126   // Double clicking the left resize edge should maximize horizontally.
127   delegate.set_window_component(HTLEFT);
128   generator.DoubleClickLeftButton();
129   bounds_in_screen = window->GetBoundsInScreen();
130   EXPECT_EQ(restored_bounds.y(), bounds_in_screen.y());
131   EXPECT_EQ(restored_bounds.height(), bounds_in_screen.height());
132   EXPECT_EQ(work_area.x(), bounds_in_screen.x());
133   EXPECT_EQ(work_area.width(), bounds_in_screen.width());
134   // Single-axis maximization is not considered real maximization.
135   EXPECT_FALSE(window_state->IsMaximized());
136
137   // Restore.
138   generator.DoubleClickLeftButton();
139   EXPECT_EQ(restored_bounds.ToString(), window->GetBoundsInScreen().ToString());
140
141 #if defined(OS_WIN)
142   // Multi display test does not run on Win8 bot. crbug.com/247427.
143   if (!SupportsMultipleDisplays())
144     return;
145 #endif
146
147   // Verify the double clicking the resize edge works on 2nd display too.
148   UpdateDisplay("200x200,400x300");
149   gfx::Rect work_area2 = ScreenUtil::GetSecondaryDisplay().work_area();
150   restored_bounds.SetRect(220, 20, 50, 50);
151   window->SetBoundsInScreen(restored_bounds, ScreenUtil::GetSecondaryDisplay());
152   aura::Window* second_root = Shell::GetAllRootWindows()[1];
153   EXPECT_EQ(second_root, window->GetRootWindow());
154   ui::test::EventGenerator generator2(second_root, window.get());
155
156   // Y-axis maximization.
157   delegate.set_window_component(HTTOP);
158   generator2.PressLeftButton();
159   generator2.ReleaseLeftButton();
160   generator2.set_flags(ui::EF_IS_DOUBLE_CLICK);
161   generator2.PressLeftButton();
162   generator2.MoveMouseTo(generator.current_location(), 1);
163   generator2.ReleaseLeftButton();
164   generator.DoubleClickLeftButton();
165   bounds_in_screen = window->GetBoundsInScreen();
166   EXPECT_EQ(restored_bounds.x(), bounds_in_screen.x());
167   EXPECT_EQ(restored_bounds.width(), bounds_in_screen.width());
168   EXPECT_EQ(work_area2.y(), bounds_in_screen.y());
169   EXPECT_EQ(work_area2.height(), bounds_in_screen.height());
170   EXPECT_FALSE(window_state->IsMaximized());
171
172   // Restore.
173   generator2.DoubleClickLeftButton();
174   EXPECT_EQ(restored_bounds.ToString(), window->GetBoundsInScreen().ToString());
175
176   // X-axis maximization.
177   delegate.set_window_component(HTLEFT);
178   generator2.DoubleClickLeftButton();
179   bounds_in_screen = window->GetBoundsInScreen();
180   EXPECT_EQ(restored_bounds.y(), bounds_in_screen.y());
181   EXPECT_EQ(restored_bounds.height(), bounds_in_screen.height());
182   EXPECT_EQ(work_area2.x(), bounds_in_screen.x());
183   EXPECT_EQ(work_area2.width(), bounds_in_screen.width());
184   EXPECT_FALSE(window_state->IsMaximized());
185
186   // Restore.
187   generator2.DoubleClickLeftButton();
188   EXPECT_EQ(restored_bounds.ToString(), window->GetBoundsInScreen().ToString());
189 }
190
191 // Tests the behavior when double clicking the border of a side snapped window.
192 TEST_F(WorkspaceEventHandlerTest, DoubleClickSingleAxisWhenSideSnapped) {
193   gfx::Rect restored_bounds(10, 10, 50, 50);
194   aura::test::TestWindowDelegate delegate;
195   scoped_ptr<aura::Window> window(CreateTestWindow(&delegate, restored_bounds));
196
197   gfx::Rect work_area_in_screen = Shell::GetScreen()->GetDisplayNearestWindow(
198       window.get()).work_area();
199
200   wm::WindowState* window_state = wm::GetWindowState(window.get());
201   const wm::WMEvent snap_event(wm::WM_EVENT_SNAP_LEFT);
202   window_state->OnWMEvent(&snap_event);
203
204   gfx::Rect snapped_bounds_in_screen = window->GetBoundsInScreen();
205   EXPECT_EQ(work_area_in_screen.x(), snapped_bounds_in_screen.x());
206   EXPECT_EQ(work_area_in_screen.y(), snapped_bounds_in_screen.y());
207   EXPECT_GT(work_area_in_screen.width(), snapped_bounds_in_screen.width());
208   EXPECT_EQ(work_area_in_screen.height(), snapped_bounds_in_screen.height());
209
210   // Double clicking the top border should not do anything for side snapped
211   // windows. (They already take up the entire workspace height and reverting
212   // to the restored bounds would be weird).
213   ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
214                                      window.get());
215   delegate.set_window_component(HTTOP);
216   generator.DoubleClickLeftButton();
217   EXPECT_EQ(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType());
218   EXPECT_EQ(snapped_bounds_in_screen.ToString(),
219             window->GetBoundsInScreen().ToString());
220
221   // Double clicking the right border should exit the side snapped state and
222   // make the window take up the entire work area.
223   delegate.set_window_component(HTRIGHT);
224   generator.DoubleClickLeftButton();
225   EXPECT_TRUE(window_state->IsNormalStateType());
226   EXPECT_EQ(work_area_in_screen.ToString(),
227             window->GetBoundsInScreen().ToString());
228 }
229
230 TEST_F(WorkspaceEventHandlerTest,
231        DoubleClickSingleAxisDoesntResizeVerticalEdgeIfConstrained) {
232   gfx::Rect restored_bounds(10, 10, 50, 50);
233   aura::test::TestWindowDelegate delegate;
234   scoped_ptr<aura::Window> window(CreateTestWindow(&delegate, restored_bounds));
235
236   wm::ActivateWindow(window.get());
237
238   gfx::Rect work_area = Shell::GetScreen()->GetDisplayNearestWindow(
239       window.get()).work_area();
240
241   delegate.set_maximum_size(gfx::Size(0, 100));
242
243   ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
244                                      window.get());
245   // Double-click the top resize edge.
246   delegate.set_window_component(HTTOP);
247   generator.DoubleClickLeftButton();
248
249   // The size of the window should be unchanged.
250   EXPECT_EQ(restored_bounds.y(), window->bounds().y());
251   EXPECT_EQ(restored_bounds.height(), window->bounds().height());
252 }
253
254 TEST_F(WorkspaceEventHandlerTest,
255        DoubleClickSingleAxisDoesntResizeHorizontalEdgeIfConstrained) {
256   gfx::Rect restored_bounds(10, 10, 50, 50);
257   aura::test::TestWindowDelegate delegate;
258   scoped_ptr<aura::Window> window(CreateTestWindow(&delegate, restored_bounds));
259
260   wm::ActivateWindow(window.get());
261
262   gfx::Rect work_area = Shell::GetScreen()->GetDisplayNearestWindow(
263       window.get()).work_area();
264
265   delegate.set_maximum_size(gfx::Size(100, 0));
266
267   ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
268                                      window.get());
269   // Double-click the top resize edge.
270   delegate.set_window_component(HTRIGHT);
271   generator.DoubleClickLeftButton();
272
273   // The size of the window should be unchanged.
274   EXPECT_EQ(restored_bounds.x(), window->bounds().x());
275   EXPECT_EQ(restored_bounds.width(), window->bounds().width());
276 }
277
278 TEST_F(WorkspaceEventHandlerTest,
279        DoubleClickOrTapWithModalChildDoesntMaximize) {
280   aura::test::TestWindowDelegate delegate1;
281   aura::test::TestWindowDelegate delegate2;
282   scoped_ptr<aura::Window> window(
283       CreateTestWindow(&delegate1, gfx::Rect(10, 20, 30, 40)));
284   scoped_ptr<aura::Window> child(
285       CreateTestWindow(&delegate2, gfx::Rect(0, 0, 1, 1)));
286   window->SetProperty(aura::client::kCanMaximizeKey, true);
287   delegate1.set_window_component(HTCAPTION);
288
289   child->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
290   ::wm::AddTransientChild(window.get(), child.get());
291
292   wm::WindowState* window_state = wm::GetWindowState(window.get());
293   EXPECT_FALSE(window_state->IsMaximized());
294   aura::Window* root = Shell::GetPrimaryRootWindow();
295   ui::test::EventGenerator generator(root, window.get());
296   generator.DoubleClickLeftButton();
297   EXPECT_EQ("10,20 30x40", window->bounds().ToString());
298   EXPECT_FALSE(window_state->IsMaximized());
299
300   generator.GestureTapAt(gfx::Point(25, 25));
301   generator.GestureTapAt(gfx::Point(25, 25));
302   RunAllPendingInMessageLoop();
303   EXPECT_EQ("10,20 30x40", window->bounds().ToString());
304   EXPECT_FALSE(window_state->IsMaximized());
305 }
306
307 // Test the behavior as a result of double clicking the window header.
308 TEST_F(WorkspaceEventHandlerTest, DoubleClickCaptionTogglesMaximize) {
309   aura::test::TestWindowDelegate delegate;
310   scoped_ptr<aura::Window> window(
311       CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40)));
312   window->SetProperty(aura::client::kCanMaximizeKey, true);
313
314   wm::WindowState* window_state = wm::GetWindowState(window.get());
315   gfx::Rect restore_bounds = window->bounds();
316   gfx::Rect work_area_in_parent = ScreenUtil::GetDisplayWorkAreaBoundsInParent(
317       window.get());
318
319   EXPECT_FALSE(window_state->IsMaximized());
320
321   // 1) Double clicking a normal window should maximize.
322   delegate.set_window_component(HTCAPTION);
323   aura::Window* root = Shell::GetPrimaryRootWindow();
324   ui::test::EventGenerator generator(root, window.get());
325   generator.ClickLeftButton();
326   generator.DoubleClickLeftButton();
327   EXPECT_NE(restore_bounds.ToString(), window->bounds().ToString());
328   EXPECT_TRUE(window_state->IsMaximized());
329
330   generator.ClickLeftButton();
331   generator.DoubleClickLeftButton();
332   EXPECT_TRUE(window_state->IsNormalStateType());
333   EXPECT_EQ(restore_bounds.ToString(), window->bounds().ToString());
334
335   // 2) Double clicking a horizontally maximized window should maximize.
336   delegate.set_window_component(HTLEFT);
337   generator.ClickLeftButton();
338   generator.DoubleClickLeftButton();
339   EXPECT_TRUE(window_state->IsNormalStateType());
340   EXPECT_EQ(work_area_in_parent.x(), window->bounds().x());
341   EXPECT_EQ(restore_bounds.y(), window->bounds().y());
342   EXPECT_EQ(work_area_in_parent.width(), window->bounds().width());
343   EXPECT_EQ(restore_bounds.height(), window->bounds().height());
344
345   delegate.set_window_component(HTCAPTION);
346   generator.ClickLeftButton();
347   generator.DoubleClickLeftButton();
348   EXPECT_TRUE(window_state->IsMaximized());
349
350   generator.ClickLeftButton();
351   generator.DoubleClickLeftButton();
352   EXPECT_TRUE(window_state->IsNormalStateType());
353   EXPECT_EQ(restore_bounds.ToString(), window->bounds().ToString());
354
355   // 3) Double clicking a snapped window should maximize.
356   const wm::WMEvent snap_event(wm::WM_EVENT_SNAP_LEFT);
357   window_state->OnWMEvent(&snap_event);
358   EXPECT_TRUE(window_state->IsSnapped());
359   generator.MoveMouseTo(window->GetBoundsInRootWindow().CenterPoint());
360   generator.ClickLeftButton();
361   generator.DoubleClickLeftButton();
362   EXPECT_TRUE(window_state->IsMaximized());
363
364   generator.ClickLeftButton();
365   generator.DoubleClickLeftButton();
366   EXPECT_TRUE(window_state->IsNormalStateType());
367   EXPECT_EQ(restore_bounds.ToString(), window->bounds().ToString());
368 }
369
370 // Test that double clicking the middle button on the window header does not
371 // toggle the maximized state.
372 TEST_F(WorkspaceEventHandlerTest,
373        DoubleClickMiddleButtonDoesNotToggleMaximize) {
374   aura::test::TestWindowDelegate delegate;
375   scoped_ptr<aura::Window> window(
376       CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40)));
377   window->SetProperty(aura::client::kCanMaximizeKey, true);
378   delegate.set_window_component(HTCAPTION);
379   aura::Window* root = Shell::GetPrimaryRootWindow();
380   ui::test::EventGenerator generator(root, window.get());
381
382   WindowPropertyObserver observer(window.get());
383   ui::MouseEvent press(ui::ET_MOUSE_PRESSED, generator.current_location(),
384                        generator.current_location(),
385                        ui::EF_MIDDLE_MOUSE_BUTTON | ui::EF_IS_DOUBLE_CLICK,
386                        ui::EF_MIDDLE_MOUSE_BUTTON);
387   ui::EventProcessor* dispatcher = root->GetHost()->event_processor();
388   ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&press);
389   ASSERT_FALSE(details.dispatcher_destroyed);
390   ui::MouseEvent release(ui::ET_MOUSE_RELEASED, generator.current_location(),
391                          generator.current_location(),
392                          ui::EF_IS_DOUBLE_CLICK,
393                          ui::EF_MIDDLE_MOUSE_BUTTON);
394   details = dispatcher->OnEventFromSource(&release);
395   ASSERT_FALSE(details.dispatcher_destroyed);
396
397   EXPECT_FALSE(wm::GetWindowState(window.get())->IsMaximized());
398   EXPECT_EQ("1,2 30x40", window->bounds().ToString());
399   EXPECT_FALSE(observer.DidPropertyChange(aura::client::kShowStateKey));
400 }
401
402 TEST_F(WorkspaceEventHandlerTest, DoubleTapCaptionTogglesMaximize) {
403   aura::test::TestWindowDelegate delegate;
404   gfx::Rect bounds(10, 20, 30, 40);
405   scoped_ptr<aura::Window> window(CreateTestWindow(&delegate, bounds));
406   window->SetProperty(aura::client::kCanMaximizeKey, true);
407   delegate.set_window_component(HTCAPTION);
408
409   wm::WindowState* window_state = wm::GetWindowState(window.get());
410   EXPECT_FALSE(window_state->IsMaximized());
411   ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
412                                      window.get());
413   generator.GestureTapAt(gfx::Point(25, 25));
414   generator.GestureTapAt(gfx::Point(25, 25));
415   RunAllPendingInMessageLoop();
416   EXPECT_NE(bounds.ToString(), window->bounds().ToString());
417   EXPECT_TRUE(window_state->IsMaximized());
418
419   generator.GestureTapAt(gfx::Point(5, 5));
420   generator.GestureTapAt(gfx::Point(10, 10));
421
422   EXPECT_FALSE(window_state->IsMaximized());
423   EXPECT_EQ(bounds.ToString(), window->bounds().ToString());
424 }
425
426 // Verifies deleting the window while dragging doesn't crash.
427 TEST_F(WorkspaceEventHandlerTest, DeleteWhenDragging) {
428   // Create a large window in the background. This is necessary so that when we
429   // delete |window| WorkspaceEventHandler is still the active event handler.
430   aura::test::TestWindowDelegate delegate2;
431   scoped_ptr<aura::Window> window2(
432       CreateTestWindow(&delegate2, gfx::Rect(0, 0, 500, 500)));
433
434   aura::test::TestWindowDelegate delegate;
435   const gfx::Rect bounds(10, 20, 30, 40);
436   scoped_ptr<aura::Window> window(CreateTestWindow(&delegate, bounds));
437   delegate.set_window_component(HTCAPTION);
438   ui::test::EventGenerator generator(window->GetRootWindow());
439   generator.MoveMouseToCenterOf(window.get());
440   generator.PressLeftButton();
441   generator.MoveMouseTo(generator.current_location() + gfx::Vector2d(50, 50));
442   DCHECK_NE(bounds.origin().ToString(), window->bounds().origin().ToString());
443   window.reset();
444   generator.MoveMouseTo(generator.current_location() + gfx::Vector2d(50, 50));
445 }
446
447 // Verifies deleting the window while in a run loop doesn't crash.
448 TEST_F(WorkspaceEventHandlerTest, DeleteWhileInRunLoop) {
449   aura::test::TestWindowDelegate delegate;
450   const gfx::Rect bounds(10, 20, 30, 40);
451   scoped_ptr<aura::Window> window(CreateTestWindow(&delegate, bounds));
452   delegate.set_window_component(HTCAPTION);
453
454   ASSERT_TRUE(aura::client::GetWindowMoveClient(window->GetRootWindow()));
455   base::MessageLoop::current()->DeleteSoon(FROM_HERE, window.get());
456   aura::client::GetWindowMoveClient(window->GetRootWindow())
457       ->RunMoveLoop(window.release(),
458                     gfx::Vector2d(),
459                     aura::client::WINDOW_MOVE_SOURCE_MOUSE);
460 }
461
462 // Verifies that double clicking in the header does not maximize if the target
463 // component has changed.
464 TEST_F(WorkspaceEventHandlerTest,
465     DoubleClickTwoDifferentTargetsDoesntMaximize) {
466   aura::test::TestWindowDelegate delegate;
467   scoped_ptr<aura::Window> window(
468       CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40)));
469   window->SetProperty(aura::client::kCanMaximizeKey, true);
470
471   wm::WindowState* window_state = wm::GetWindowState(window.get());
472   gfx::Rect restore_bounds = window->bounds();
473   gfx::Rect work_area_in_parent = ScreenUtil::GetDisplayWorkAreaBoundsInParent(
474       window.get());
475
476   EXPECT_FALSE(window_state->IsMaximized());
477
478   // First click will go to a client
479   delegate.set_window_component(HTCLIENT);
480   aura::Window* root = Shell::GetPrimaryRootWindow();
481   ui::test::EventGenerator generator(root, window.get());
482   generator.ClickLeftButton();
483   EXPECT_FALSE(window_state->IsMaximized());
484
485   // Second click will go to the header
486   delegate.set_window_component(HTCAPTION);
487   generator.DoubleClickLeftButton();
488   EXPECT_FALSE(window_state->IsMaximized());
489 }
490
491 // Verifies that double tapping in the header does not maximize if the target
492 // component has changed.
493 TEST_F(WorkspaceEventHandlerTest, DoubleTapTwoDifferentTargetsDoesntMaximize) {
494   aura::test::TestWindowDelegate delegate;
495   scoped_ptr<aura::Window> window(
496       CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40)));
497   window->SetProperty(aura::client::kCanMaximizeKey, true);
498
499   wm::WindowState* window_state = wm::GetWindowState(window.get());
500   gfx::Rect restore_bounds = window->bounds();
501   gfx::Rect work_area_in_parent = ScreenUtil::GetDisplayWorkAreaBoundsInParent(
502       window.get());
503
504   EXPECT_FALSE(window_state->IsMaximized());
505
506   // First tap will go to a client
507   delegate.set_window_component(HTCLIENT);
508   aura::Window* root = Shell::GetPrimaryRootWindow();
509   ui::test::EventGenerator generator(root, window.get());
510   generator.GestureTapAt(gfx::Point(25, 25));
511   EXPECT_FALSE(window_state->IsMaximized());
512
513   // Second tap will go to the header
514   delegate.set_window_component(HTCAPTION);
515   generator.GestureTapAt(gfx::Point(25, 25));
516   EXPECT_FALSE(window_state->IsMaximized());
517 }
518
519 TEST_F(WorkspaceEventHandlerTest,
520     RightClickDuringDoubleClickDoesntMaximize) {
521   aura::test::TestWindowDelegate delegate;
522   scoped_ptr<aura::Window> window(
523       CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40)));
524   window->SetProperty(aura::client::kCanMaximizeKey, true);
525
526   wm::WindowState* window_state = wm::GetWindowState(window.get());
527   gfx::Rect restore_bounds = window->bounds();
528   gfx::Rect work_area_in_parent = ScreenUtil::GetDisplayWorkAreaBoundsInParent(
529       window.get());
530
531   EXPECT_FALSE(window_state->IsMaximized());
532
533   // First click will go to a client
534   delegate.set_window_component(HTCLIENT);
535   aura::Window* root = Shell::GetPrimaryRootWindow();
536   ui::test::EventGenerator generator(root, window.get());
537   generator.ClickLeftButton();
538   EXPECT_FALSE(window_state->IsMaximized());
539
540   // Second click will go to the header
541   delegate.set_window_component(HTCAPTION);
542   generator.PressRightButton();
543   generator.ReleaseRightButton();
544   EXPECT_FALSE(window_state->IsMaximized());
545   generator.DoubleClickLeftButton();
546   EXPECT_FALSE(window_state->IsMaximized());
547 }
548
549 }  // namespace ash