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
3 // found in the LICENSE file.
5 #include "ash/wm/partial_screenshot_view.h"
7 #include "ash/screenshot_delegate.h"
9 #include "ash/shell_window_ids.h"
10 #include "ash/test/ash_test_base.h"
11 #include "ash/test/test_overlay_delegate.h"
12 #include "ash/test/test_screenshot_delegate.h"
13 #include "ui/aura/window_event_dispatcher.h"
14 #include "ui/events/test/event_generator.h"
15 #include "ui/views/widget/widget.h"
16 #include "ui/views/widget/widget_observer.h"
20 class PartialScreenshotViewTest
: public test::AshTestBase
,
21 public views::WidgetObserver
{
23 PartialScreenshotViewTest() : view_(NULL
) {}
24 ~PartialScreenshotViewTest() override
{
26 view_
->GetWidget()->RemoveObserver(this);
29 void StartPartialScreenshot() {
30 std::vector
<PartialScreenshotView
*> views
=
31 PartialScreenshotView::StartPartialScreenshot(GetScreenshotDelegate());
34 view_
->GetWidget()->AddObserver(this);
39 PartialScreenshotView
* view_
;
42 // views::WidgetObserver:
43 void OnWidgetDestroying(views::Widget
* widget
) override
{
44 if (view_
&& view_
->GetWidget() == widget
)
46 widget
->RemoveObserver(this);
49 DISALLOW_COPY_AND_ASSIGN(PartialScreenshotViewTest
);
52 TEST_F(PartialScreenshotViewTest
, BasicMouse
) {
53 StartPartialScreenshot();
56 ui::test::EventGenerator
generator(Shell::GetPrimaryRootWindow());
58 generator
.MoveMouseTo(100, 100);
59 generator
.PressLeftButton();
60 EXPECT_FALSE(view_
->is_dragging_
);
61 EXPECT_EQ("100,100", view_
->start_position_
.ToString());
63 generator
.MoveMouseTo(200, 200);
64 EXPECT_TRUE(view_
->is_dragging_
);
65 EXPECT_EQ("200,200", view_
->current_position_
.ToString());
67 generator
.ReleaseLeftButton();
68 EXPECT_FALSE(view_
->is_dragging_
);
69 EXPECT_EQ("100,100 100x100", GetScreenshotDelegate()->last_rect().ToString());
70 EXPECT_EQ(1, GetScreenshotDelegate()->handle_take_partial_screenshot_count());
73 TEST_F(PartialScreenshotViewTest
, BasicTouch
) {
74 StartPartialScreenshot();
77 ui::test::EventGenerator
generator(Shell::GetPrimaryRootWindow());
79 generator
.set_current_location(gfx::Point(100,100));
80 generator
.GestureTapDownAndUp(gfx::Point(100,100));
81 EXPECT_FALSE(view_
->is_dragging_
);
82 EXPECT_EQ(0, GetScreenshotDelegate()->handle_take_partial_screenshot_count());
84 generator
.PressTouch();
85 EXPECT_FALSE(view_
->is_dragging_
);
86 EXPECT_EQ("100,100", view_
->start_position_
.ToString());
88 generator
.MoveTouch(gfx::Point(200, 200));
89 EXPECT_TRUE(view_
->is_dragging_
);
90 EXPECT_EQ("200,200", view_
->current_position_
.ToString());
92 generator
.ReleaseTouch();
93 EXPECT_FALSE(view_
->is_dragging_
);
94 EXPECT_EQ(1, GetScreenshotDelegate()->handle_take_partial_screenshot_count());
95 EXPECT_EQ("100,100 100x100", GetScreenshotDelegate()->last_rect().ToString());
98 // Partial screenshot session should not start when there is already another
99 // overlay. See: http://crbug.com/341958
100 TEST_F(PartialScreenshotViewTest
, DontStartOverOverlay
) {
101 OverlayEventFilter
* overlay_filter
= Shell::GetInstance()->overlay_filter();
102 test::TestOverlayDelegate delegate
;
103 overlay_filter
->Activate(&delegate
);
104 EXPECT_EQ(&delegate
, overlay_filter
->delegate_
);
106 StartPartialScreenshot();
107 EXPECT_TRUE(view_
== NULL
);
108 EXPECT_EQ(&delegate
, overlay_filter
->delegate_
);
109 overlay_filter
->Deactivate(&delegate
);
111 StartPartialScreenshot();
112 EXPECT_TRUE(view_
!= NULL
);
114 // Someone else attempts to activate the overlay session, which should cancel
115 // the current partial screenshot session.
116 overlay_filter
->Activate(&delegate
);
117 RunAllPendingInMessageLoop();
118 EXPECT_EQ(&delegate
, overlay_filter
->delegate_
);
119 EXPECT_TRUE(view_
== NULL
);