Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 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. |
| 4 | |
| 5 | #include "ash/wm/partial_screenshot_view.h" |
| 6 | |
| 7 | #include "ash/screenshot_delegate.h" |
| 8 | #include "ash/shell.h" |
| 9 | #include "ash/shell_window_ids.h" |
| 10 | #include "ash/test/ash_test_base.h" |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame] | 11 | #include "ash/test/test_screenshot_delegate.h" |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 12 | #include "ui/aura/test/event_generator.h" |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 13 | #include "ui/aura/window_event_dispatcher.h" |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 14 | |
| 15 | namespace ash { |
| 16 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 17 | class PartialScreenshotViewTest : public test::AshTestBase { |
| 18 | public: |
| 19 | PartialScreenshotViewTest() : view_(NULL) {} |
| 20 | virtual ~PartialScreenshotViewTest() {} |
| 21 | |
| 22 | virtual void SetUp() OVERRIDE { |
| 23 | test::AshTestBase::SetUp(); |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 24 | std::vector<PartialScreenshotView*> views = |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame] | 25 | PartialScreenshotView::StartPartialScreenshot(GetScreenshotDelegate()); |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 26 | ASSERT_EQ(1u, views.size()); |
| 27 | view_ = views[0]; |
| 28 | } |
| 29 | |
| 30 | protected: |
| 31 | PartialScreenshotView* view_; |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 32 | |
| 33 | private: |
| 34 | DISALLOW_COPY_AND_ASSIGN(PartialScreenshotViewTest); |
| 35 | }; |
| 36 | |
| 37 | TEST_F(PartialScreenshotViewTest, BasicMouse) { |
| 38 | aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
| 39 | |
| 40 | generator.MoveMouseTo(100, 100); |
| 41 | generator.PressLeftButton(); |
| 42 | EXPECT_FALSE(view_->is_dragging_); |
| 43 | EXPECT_EQ("100,100", view_->start_position_.ToString()); |
| 44 | |
| 45 | generator.MoveMouseTo(200, 200); |
| 46 | EXPECT_TRUE(view_->is_dragging_); |
| 47 | EXPECT_EQ("200,200", view_->current_position_.ToString()); |
| 48 | |
| 49 | generator.ReleaseLeftButton(); |
| 50 | EXPECT_FALSE(view_->is_dragging_); |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame] | 51 | EXPECT_EQ("100,100 100x100", GetScreenshotDelegate()->last_rect().ToString()); |
| 52 | EXPECT_EQ(1, GetScreenshotDelegate()->handle_take_partial_screenshot_count()); |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | TEST_F(PartialScreenshotViewTest, BasicTouch) { |
| 56 | aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
| 57 | |
| 58 | generator.set_current_location(gfx::Point(100,100)); |
| 59 | generator.GestureTapDownAndUp(gfx::Point(100,100)); |
| 60 | EXPECT_FALSE(view_->is_dragging_); |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame] | 61 | EXPECT_EQ(0, GetScreenshotDelegate()->handle_take_partial_screenshot_count()); |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 62 | |
| 63 | generator.PressTouch(); |
| 64 | EXPECT_FALSE(view_->is_dragging_); |
| 65 | EXPECT_EQ("100,100", view_->start_position_.ToString()); |
| 66 | |
| 67 | generator.MoveTouch(gfx::Point(200, 200)); |
| 68 | EXPECT_TRUE(view_->is_dragging_); |
| 69 | EXPECT_EQ("200,200", view_->current_position_.ToString()); |
| 70 | |
| 71 | generator.ReleaseTouch(); |
| 72 | EXPECT_FALSE(view_->is_dragging_); |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame] | 73 | EXPECT_EQ(1, GetScreenshotDelegate()->handle_take_partial_screenshot_count()); |
| 74 | EXPECT_EQ("100,100 100x100", GetScreenshotDelegate()->last_rect().ToString()); |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | } // namespace ash |