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" 11 #include "ui/aura/root_window.h" 12 #include "ui/aura/test/event_generator.h" 13 14 namespace ash { 15 16 class FakeScreenshotDelegate : public ScreenshotDelegate { 17 public: 18 FakeScreenshotDelegate() : screenshot_count_(0) {} 19 20 virtual void HandleTakeScreenshotForAllRootWindows() OVERRIDE {} 21 virtual void HandleTakePartialScreenshot(aura::Window* window, 22 const gfx::Rect& rect) OVERRIDE { 23 rect_ = rect; 24 screenshot_count_++; 25 } 26 27 virtual bool CanTakeScreenshot() OVERRIDE { 28 return true; 29 } 30 31 const gfx::Rect& rect() const { return rect_; }; 32 int screenshot_count() const { return screenshot_count_; }; 33 34 private: 35 gfx::Rect rect_; 36 int screenshot_count_; 37 38 DISALLOW_COPY_AND_ASSIGN(FakeScreenshotDelegate); 39 }; 40 41 class PartialScreenshotViewTest : public test::AshTestBase { 42 public: 43 PartialScreenshotViewTest() : view_(NULL) {} 44 virtual ~PartialScreenshotViewTest() {} 45 46 virtual void SetUp() OVERRIDE { 47 test::AshTestBase::SetUp(); 48 delegate_.reset(new FakeScreenshotDelegate()); 49 std::vector<PartialScreenshotView*> views = 50 PartialScreenshotView::StartPartialScreenshot(delegate_.get()); 51 ASSERT_EQ(1u, views.size()); 52 view_ = views[0]; 53 } 54 55 protected: 56 PartialScreenshotView* view_; 57 scoped_ptr<FakeScreenshotDelegate> delegate_; 58 59 private: 60 DISALLOW_COPY_AND_ASSIGN(PartialScreenshotViewTest); 61 }; 62 63 TEST_F(PartialScreenshotViewTest, BasicMouse) { 64 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 65 66 generator.MoveMouseTo(100, 100); 67 generator.PressLeftButton(); 68 EXPECT_FALSE(view_->is_dragging_); 69 EXPECT_EQ("100,100", view_->start_position_.ToString()); 70 71 generator.MoveMouseTo(200, 200); 72 EXPECT_TRUE(view_->is_dragging_); 73 EXPECT_EQ("200,200", view_->current_position_.ToString()); 74 75 generator.ReleaseLeftButton(); 76 EXPECT_FALSE(view_->is_dragging_); 77 EXPECT_EQ("100,100 100x100", delegate_->rect().ToString()); 78 EXPECT_EQ(1, delegate_->screenshot_count()); 79 } 80 81 TEST_F(PartialScreenshotViewTest, BasicTouch) { 82 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 83 84 generator.set_current_location(gfx::Point(100,100)); 85 generator.GestureTapDownAndUp(gfx::Point(100,100)); 86 EXPECT_FALSE(view_->is_dragging_); 87 EXPECT_EQ(0, delegate_->screenshot_count()); 88 89 generator.PressTouch(); 90 EXPECT_FALSE(view_->is_dragging_); 91 EXPECT_EQ("100,100", view_->start_position_.ToString()); 92 93 generator.MoveTouch(gfx::Point(200, 200)); 94 EXPECT_TRUE(view_->is_dragging_); 95 EXPECT_EQ("200,200", view_->current_position_.ToString()); 96 97 generator.ReleaseTouch(); 98 EXPECT_FALSE(view_->is_dragging_); 99 EXPECT_EQ(1, delegate_->screenshot_count()); 100 EXPECT_EQ("100,100 100x100", delegate_->rect().ToString()); 101 } 102 103 } // namespace ash 104