summaryrefslogtreecommitdiffstats
path: root/ash/display/mirror_window_controller_unittest.cc
blob: 4b99bdd8c41ab537f49a9fa4d9281c48f1037812 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/display/mirror_window_controller.h"

#include "ash/display/display_manager.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/mirror_window_test_api.h"
#include "ui/aura/root_window.h"
#include "ui/aura/test/event_generator.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/test/test_windows.h"
#include "ui/aura/window.h"
#include "ui/base/hit_test.h"

namespace ash {
namespace internal {

typedef test::AshTestBase MirrorWindowControllerTest;

#if defined(OS_WIN)
// Software mirroring does not work on win.
#define MAYBE_MirrorCursor DISABLED_MirrorCursor
#else
#define MAYBE_MirrorCursor MirrorCursor
#endif

TEST_F(MirrorWindowControllerTest, MAYBE_MirrorCursor) {
  test::MirrorWindowTestApi test_api;
  aura::test::TestWindowDelegate test_window_delegate;
  test_window_delegate.set_window_component(HTTOP);

  DisplayManager* display_manager = Shell::GetInstance()->display_manager();
  display_manager->SetSoftwareMirroring(true);
  UpdateDisplay("400x400,400x400");
  aura::RootWindow* root = Shell::GetInstance()->GetPrimaryRootWindow();
  scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate(
      &test_window_delegate,
      0,
      gfx::Rect(50, 50, 100, 100),
      root));
  window->Show();
  window->SetName("foo");

  EXPECT_TRUE(test_api.GetCursorWindow());
  EXPECT_EQ("50,50 100x100", window->bounds().ToString());

  aura::test::EventGenerator generator(root);
  generator.MoveMouseTo(10, 10);

  // Test if cursor movement is propertly reflected in mirror window.
  gfx::Point hot_point = test_api.GetCursorHotPoint();
  gfx::Point cursor_window_origin =
      test_api.GetCursorWindow()->bounds().origin();
  EXPECT_EQ(10 - hot_point.x(), cursor_window_origin.x());
  EXPECT_EQ(10 - hot_point.y(), cursor_window_origin.y());
  EXPECT_EQ(ui::kCursorNull, test_api.GetCurrentCursorType());
  EXPECT_TRUE(test_api.GetCursorWindow()->IsVisible());

  // Test if cursor type change is propertly reflected in mirror window.
  generator.MoveMouseTo(100, 100);
  hot_point = test_api.GetCursorHotPoint();
  cursor_window_origin = test_api.GetCursorWindow()->bounds().origin();
  EXPECT_EQ(100 - hot_point.x(), cursor_window_origin.x());
  EXPECT_EQ(100 - hot_point.y(), cursor_window_origin.y());
  EXPECT_EQ(ui::kCursorNorthResize, test_api.GetCurrentCursorType());

  // Test if visibility change is propertly reflected in mirror window.
  // A key event hides cursor.
  generator.PressKey(ui::VKEY_A, 0);
  generator.ReleaseKey(ui::VKEY_A, 0);
  EXPECT_FALSE(test_api.GetCursorWindow()->IsVisible());

  // Mouse event makes it visible again.
  generator.MoveMouseTo(300, 300);
  hot_point = test_api.GetCursorHotPoint();
  cursor_window_origin = test_api.GetCursorWindow()->bounds().origin();
  EXPECT_EQ(300 - hot_point.x(), cursor_window_origin.x());
  EXPECT_EQ(300 - hot_point.y(), cursor_window_origin.y());
  EXPECT_EQ(ui::kCursorNull, test_api.GetCurrentCursorType());
  EXPECT_TRUE(test_api.GetCursorWindow()->IsVisible());
}

}  // namsspace internal
}  // namespace ash