OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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/partial_screenshot_view.h" | 5 #include "ash/wm/partial_screenshot_view.h" |
6 | 6 |
7 #include "ash/screenshot_delegate.h" | 7 #include "ash/screenshot_delegate.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/shell_window_ids.h" | 9 #include "ash/shell_window_ids.h" |
10 #include "ash/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
11 #include "ash/test/test_overlay_delegate.h" | |
11 #include "ash/test/test_screenshot_delegate.h" | 12 #include "ash/test/test_screenshot_delegate.h" |
12 #include "ui/aura/window_event_dispatcher.h" | 13 #include "ui/aura/window_event_dispatcher.h" |
13 #include "ui/events/test/event_generator.h" | 14 #include "ui/events/test/event_generator.h" |
15 #include "ui/views/widget/widget.h" | |
16 #include "ui/views/widget/widget_observer.h" | |
14 | 17 |
15 namespace ash { | 18 namespace ash { |
16 | 19 |
17 class PartialScreenshotViewTest : public test::AshTestBase { | 20 class PartialScreenshotViewTest : public test::AshTestBase, |
21 public views::WidgetObserver { | |
18 public: | 22 public: |
19 PartialScreenshotViewTest() : view_(NULL) {} | 23 PartialScreenshotViewTest() : view_(NULL) {} |
20 virtual ~PartialScreenshotViewTest() {} | 24 virtual ~PartialScreenshotViewTest() { |
25 if (view_) | |
26 view_->GetWidget()->RemoveObserver(this); | |
27 } | |
21 | 28 |
22 virtual void SetUp() OVERRIDE { | 29 void StartPartialScreenshot() { |
23 test::AshTestBase::SetUp(); | |
24 std::vector<PartialScreenshotView*> views = | 30 std::vector<PartialScreenshotView*> views = |
25 PartialScreenshotView::StartPartialScreenshot(GetScreenshotDelegate()); | 31 PartialScreenshotView::StartPartialScreenshot(GetScreenshotDelegate()); |
26 ASSERT_EQ(1u, views.size()); | 32 if (!views.empty()) { |
27 view_ = views[0]; | 33 view_ = views[0]; |
34 view_->GetWidget()->AddObserver(this); | |
35 } | |
28 } | 36 } |
29 | 37 |
30 protected: | 38 protected: |
31 PartialScreenshotView* view_; | 39 PartialScreenshotView* view_; |
32 | 40 |
33 private: | 41 private: |
42 // views::WidgetObserver: | |
43 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE { | |
44 if (view_ && view_->GetWidget() == widget) | |
45 view_ = NULL; | |
46 widget->RemoveObserver(this); | |
47 } | |
48 | |
34 DISALLOW_COPY_AND_ASSIGN(PartialScreenshotViewTest); | 49 DISALLOW_COPY_AND_ASSIGN(PartialScreenshotViewTest); |
35 }; | 50 }; |
36 | 51 |
37 TEST_F(PartialScreenshotViewTest, BasicMouse) { | 52 TEST_F(PartialScreenshotViewTest, BasicMouse) { |
53 StartPartialScreenshot(); | |
54 ASSERT_TRUE(view_); | |
55 | |
38 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 56 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
39 | 57 |
40 generator.MoveMouseTo(100, 100); | 58 generator.MoveMouseTo(100, 100); |
41 generator.PressLeftButton(); | 59 generator.PressLeftButton(); |
42 EXPECT_FALSE(view_->is_dragging_); | 60 EXPECT_FALSE(view_->is_dragging_); |
43 EXPECT_EQ("100,100", view_->start_position_.ToString()); | 61 EXPECT_EQ("100,100", view_->start_position_.ToString()); |
44 | 62 |
45 generator.MoveMouseTo(200, 200); | 63 generator.MoveMouseTo(200, 200); |
46 EXPECT_TRUE(view_->is_dragging_); | 64 EXPECT_TRUE(view_->is_dragging_); |
47 EXPECT_EQ("200,200", view_->current_position_.ToString()); | 65 EXPECT_EQ("200,200", view_->current_position_.ToString()); |
48 | 66 |
49 generator.ReleaseLeftButton(); | 67 generator.ReleaseLeftButton(); |
50 EXPECT_FALSE(view_->is_dragging_); | 68 EXPECT_FALSE(view_->is_dragging_); |
51 EXPECT_EQ("100,100 100x100", GetScreenshotDelegate()->last_rect().ToString()); | 69 EXPECT_EQ("100,100 100x100", GetScreenshotDelegate()->last_rect().ToString()); |
52 EXPECT_EQ(1, GetScreenshotDelegate()->handle_take_partial_screenshot_count()); | 70 EXPECT_EQ(1, GetScreenshotDelegate()->handle_take_partial_screenshot_count()); |
53 } | 71 } |
54 | 72 |
55 TEST_F(PartialScreenshotViewTest, BasicTouch) { | 73 TEST_F(PartialScreenshotViewTest, BasicTouch) { |
74 StartPartialScreenshot(); | |
75 ASSERT_TRUE(view_); | |
76 | |
56 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 77 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
57 | 78 |
58 generator.set_current_location(gfx::Point(100,100)); | 79 generator.set_current_location(gfx::Point(100,100)); |
59 generator.GestureTapDownAndUp(gfx::Point(100,100)); | 80 generator.GestureTapDownAndUp(gfx::Point(100,100)); |
60 EXPECT_FALSE(view_->is_dragging_); | 81 EXPECT_FALSE(view_->is_dragging_); |
61 EXPECT_EQ(0, GetScreenshotDelegate()->handle_take_partial_screenshot_count()); | 82 EXPECT_EQ(0, GetScreenshotDelegate()->handle_take_partial_screenshot_count()); |
62 | 83 |
63 generator.PressTouch(); | 84 generator.PressTouch(); |
64 EXPECT_FALSE(view_->is_dragging_); | 85 EXPECT_FALSE(view_->is_dragging_); |
65 EXPECT_EQ("100,100", view_->start_position_.ToString()); | 86 EXPECT_EQ("100,100", view_->start_position_.ToString()); |
66 | 87 |
67 generator.MoveTouch(gfx::Point(200, 200)); | 88 generator.MoveTouch(gfx::Point(200, 200)); |
68 EXPECT_TRUE(view_->is_dragging_); | 89 EXPECT_TRUE(view_->is_dragging_); |
69 EXPECT_EQ("200,200", view_->current_position_.ToString()); | 90 EXPECT_EQ("200,200", view_->current_position_.ToString()); |
70 | 91 |
71 generator.ReleaseTouch(); | 92 generator.ReleaseTouch(); |
72 EXPECT_FALSE(view_->is_dragging_); | 93 EXPECT_FALSE(view_->is_dragging_); |
73 EXPECT_EQ(1, GetScreenshotDelegate()->handle_take_partial_screenshot_count()); | 94 EXPECT_EQ(1, GetScreenshotDelegate()->handle_take_partial_screenshot_count()); |
74 EXPECT_EQ("100,100 100x100", GetScreenshotDelegate()->last_rect().ToString()); | 95 EXPECT_EQ("100,100 100x100", GetScreenshotDelegate()->last_rect().ToString()); |
75 } | 96 } |
76 | 97 |
98 // Partial screenshot session should not start when there is already another | |
99 // overlay. See: crbug.com/341958 | |
James Cook
2014/08/12 21:51:14
nit: I've started putting the "http://" part into
Jun Mukai
2014/08/12 22:51:03
Done.
| |
100 TEST_F(PartialScreenshotViewTest, DontStartOverOverlay) { | |
101 OverlayEventFilter* overlay_filter = Shell::GetInstance()->overlay_filter(); | |
102 test::TestOverlayDelegate delegate; | |
103 overlay_filter->Activate(&delegate); | |
104 | |
105 EXPECT_EQ(&delegate, overlay_filter->delegate_); | |
James Cook
2014/08/12 21:51:15
nit: Maybe move up a line?
Jun Mukai
2014/08/12 22:51:03
Done.
| |
106 | |
107 StartPartialScreenshot(); | |
108 EXPECT_FALSE(view_); | |
109 EXPECT_EQ(&delegate, overlay_filter->delegate_); | |
110 overlay_filter->Deactivate(&delegate); | |
111 | |
112 StartPartialScreenshot(); | |
113 EXPECT_TRUE(view_); | |
114 | |
115 // Someone else attempts to activate the overlay session, which should cancel | |
116 // the current partial screenshot session. | |
117 overlay_filter->Activate(&delegate); | |
118 RunAllPendingInMessageLoop(); | |
119 EXPECT_EQ(&delegate, overlay_filter->delegate_); | |
120 EXPECT_FALSE(view_); | |
121 } | |
James Cook
2014/08/12 21:51:15
Nice test.
Jun Mukai
2014/08/12 22:51:03
thanks :)
| |
122 | |
77 } // namespace ash | 123 } // namespace ash |
OLD | NEW |