- add sources.
[platform/framework/web/crosswalk.git] / src / ash / wm / partial_screenshot_view_unittest.cc
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 "ash/test/test_screenshot_delegate.h"
12 #include "ui/aura/root_window.h"
13 #include "ui/aura/test/event_generator.h"
14
15 namespace ash {
16
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();
24     std::vector<PartialScreenshotView*> views =
25         PartialScreenshotView::StartPartialScreenshot(GetScreenshotDelegate());
26     ASSERT_EQ(1u, views.size());
27     view_ = views[0];
28   }
29
30  protected:
31   PartialScreenshotView* view_;
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_);
51   EXPECT_EQ("100,100 100x100", GetScreenshotDelegate()->last_rect().ToString());
52   EXPECT_EQ(1, GetScreenshotDelegate()->handle_take_partial_screenshot_count());
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_);
61   EXPECT_EQ(0, GetScreenshotDelegate()->handle_take_partial_screenshot_count());
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_);
73   EXPECT_EQ(1, GetScreenshotDelegate()->handle_take_partial_screenshot_count());
74   EXPECT_EQ("100,100 100x100", GetScreenshotDelegate()->last_rect().ToString());
75 }
76
77 }  // namespace ash