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
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138
  139
  140
  141
  142
  143
  144
  145
  146
  147
  148
  149
  150
  151
  152
  153
  154
  155
  156
  157
  158
  159
  160
  161
  162
  163
  164
  165
  166
  167
  168
  169
  170
  171
  172
  173
  174
  175
  176
  177
  178
  179
  180
  181
  182
  183
  184
  185
  186
  187
  188
  189
  190
  191
  192
  193
  194
  195
  196
  197
  198
  199
  200
  201
  202
  203
  204
  205
  206
  207
  208
  209
  210
  211
  212
  213
  214
  215
  216
  217
  218
  219
  220
  221
  222
  223
  224
  225
  226
  227
  228
  229
  230
  231
  232
  233
  234
  235
  236
  237
  238
  239
  240
  241
  242
  243
  244
  245
  246
  247
  248
  249
  250
  251
  252
  253
  254
  255
  256
  257
  258
  259
  260
  261
  262
  263
  264
  265
  266
  267
  268
  269
  270
  271
  272
  273
  274
  275
  276
  277
  278
  279
  280
  281
  282
  283
  284
  285
  286
  287
  288
  289
  290
  291
  292
  293
  294
  295
  296
  297
  298
  299
  300
  301
  302
  303
  304
  305
  306
  307
  308
  309
  310
  311
  312
  313
  314
  315
  316
  317
  318
  319
  320
  321
  322
  323
  324
  325
  326
  327
  328
  329
  330
  331
  332
  333
  334
  335
  336
  337
  338
  339
  340
  341
  342
  343
  344
  345
  346
  347
  348
  349
  350
  351
  352
  353
  354
  355
  356
  357
  358
  359
  360
  361
  362
  363
  364
  365
  366
  367
  368
  369
  370
  371
  372
  373
  374
  375
  376
  377
  378
  379
  380
  381
  382
  383
  384
  385
  386
  387
  388
  389
  390
  391
  392
  393
  394
  395
  396
  397
  398
  399
  400
  401
  402
  403
  404
  405
  406
  407
  408
  409
  410
  411
  412
  413
  414
  415
  416
  417
  418
  419
  420
  421
  422
  423
  424
  425
  426
  427
  428
  429
  430
  431
  432
  433
  434
  435
  436
  437
  438
  439
  440
  441
  442
  443
  444
  445
  446
  447
  448
  449
  450
  451
  452
  453
  454
  455
  456
  457
  458
  459
  460
  461
  462
  463
  464
  465
  466
  467
  468
  469
  470
  471
  472
  473
  474
  475
  476
  477
  478
  479
  480
  481
  482
  483
  484
  485
  486
  487
  488
  489
  490
  491
  492
  493
  494
  495
  496
  497

ash / display / extended_mouse_warp_controller_unittest.cc [blame]

// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/display/extended_mouse_warp_controller.h"

#include "ash/display/mouse_cursor_event_filter.h"
#include "ash/display/screen_position_controller.h"
#include "ash/host/ash_window_tree_host_platform.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "ui/aura/env.h"
#include "ui/aura/test/test_windows.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/hit_test.h"
#include "ui/display/display.h"
#include "ui/display/display_layout.h"
#include "ui/display/display_layout_builder.h"
#include "ui/display/manager/display_manager.h"
#include "ui/display/screen.h"
#include "ui/display/test/display_manager_test_api.h"
#include "ui/events/base_event_utils.h"
#include "ui/events/test/event_generator.h"
#include "ui/wm/core/coordinate_conversion.h"

namespace ash {

class ExtendedMouseWarpControllerTest : public AshTestBase {
 public:
  ExtendedMouseWarpControllerTest() = default;

  ExtendedMouseWarpControllerTest(const ExtendedMouseWarpControllerTest&) =
      delete;
  ExtendedMouseWarpControllerTest& operator=(
      const ExtendedMouseWarpControllerTest&) = delete;

  ~ExtendedMouseWarpControllerTest() override = default;

 protected:
  MouseCursorEventFilter* event_filter() {
    return Shell::Get()->mouse_cursor_filter();
  }

  ExtendedMouseWarpController* mouse_warp_controller() {
    return static_cast<ExtendedMouseWarpController*>(
        event_filter()->mouse_warp_controller_for_test());
  }

  size_t GetWarpRegionsCount() {
    return mouse_warp_controller()->warp_regions_.size();
  }

  const ExtendedMouseWarpController::WarpRegion* GetWarpRegion(size_t index) {
    return mouse_warp_controller()->warp_regions_[index].get();
  }

  const gfx::Rect& GetIndicatorBounds(int64_t id) {
    return GetWarpRegion(0)->GetIndicatorBoundsForTest(id);
  }

  const gfx::Rect& GetIndicatorNativeBounds(int64_t id) {
    return GetWarpRegion(0)->GetIndicatorNativeBoundsForTest(id);
  }

  // Send mouse event with native event through AshWindowTreeHostPlatform.
  void DispatchMouseEventWithNative(AshWindowTreeHostPlatform* host,
                                    const gfx::Point& location_in_host_native,
                                    ui::EventType event_type,
                                    int event_flag1,
                                    int event_flag2) {
    ui::MouseEvent native_event(event_type, location_in_host_native,
                                location_in_host_native, ui::EventTimeForNow(),
                                event_flag1, event_flag2);
    ui::MouseEvent mouseev(&native_event);
    host->DispatchEvent(&mouseev);

    // The test relies on the last_mouse_location, which will be updated by
    // a synthesized event posted asynchronusly. Wait until the synthesized
    // event is handled and last mouse location is updated.
    base::RunLoop().RunUntilIdle();
  }
};

// Verifies if MouseCursorEventFilter's bounds calculation works correctly.
TEST_F(ExtendedMouseWarpControllerTest, IndicatorBoundsTestOnRight) {
  UpdateDisplay("360x350,800x700");
  aura::Window::Windows root_windows = Shell::GetAllRootWindows();
  int64_t display_0_id = display::Screen::GetScreen()
                             ->GetDisplayNearestWindow(root_windows[0])
                             .id();
  int64_t display_1_id = display::Screen::GetScreen()
                             ->GetDisplayNearestWindow(root_windows[1])
                             .id();

  std::unique_ptr<display::DisplayLayout> layout(
      display::test::CreateDisplayLayout(display_manager(),
                                         display::DisplayPlacement::RIGHT, 0));

  display_manager()->SetLayoutForCurrentDisplays(layout->Copy());
  event_filter()->ShowSharedEdgeIndicator(root_windows[0] /* primary */);

  ASSERT_EQ(1U, GetWarpRegionsCount());
  EXPECT_EQ(gfx::Rect(359, 32, 1, 318), GetIndicatorBounds(display_0_id));
  EXPECT_EQ(gfx::Rect(360, 0, 1, 350), GetIndicatorBounds(display_1_id));

  event_filter()->ShowSharedEdgeIndicator(root_windows[1] /* secondary */);
  EXPECT_EQ(gfx::Rect(359, 0, 1, 350), GetIndicatorBounds(display_0_id));
  EXPECT_EQ(gfx::Rect(360, 32, 1, 318), GetIndicatorBounds(display_1_id));

  // Move 2nd display downwards a bit.
  layout->placement_list[0].offset = 5;
  display_manager()->SetLayoutForCurrentDisplays(layout->Copy());
  event_filter()->ShowSharedEdgeIndicator(root_windows[0] /* primary */);
  // This is same as before because the 2nd display's y is above
  // the indicator's x.
  ASSERT_EQ(1U, GetWarpRegionsCount());
  EXPECT_EQ(gfx::Rect(359, 32, 1, 318), GetIndicatorBounds(display_0_id));
  EXPECT_EQ(gfx::Rect(360, 5, 1, 345), GetIndicatorBounds(display_1_id));

  event_filter()->ShowSharedEdgeIndicator(root_windows[1] /* secondary */);
  EXPECT_EQ(gfx::Rect(359, 5, 1, 345), GetIndicatorBounds(display_0_id));
  EXPECT_EQ(gfx::Rect(360, 37, 1, 313), GetIndicatorBounds(display_1_id));

  // Move it down further so that the shared edge is shorter than
  // minimum hole size (160).
  layout->placement_list[0].offset = 200;
  display_manager()->SetLayoutForCurrentDisplays(layout->Copy());
  event_filter()->ShowSharedEdgeIndicator(root_windows[0] /* primary */);
  ASSERT_EQ(1U, GetWarpRegionsCount());
  EXPECT_EQ(gfx::Rect(359, 200, 1, 150), GetIndicatorBounds(display_0_id));
  EXPECT_EQ(gfx::Rect(360, 200, 1, 150), GetIndicatorBounds(display_1_id));

  event_filter()->ShowSharedEdgeIndicator(root_windows[1] /* secondary */);
  ASSERT_EQ(1U, GetWarpRegionsCount());
  EXPECT_EQ(gfx::Rect(359, 200, 1, 150), GetIndicatorBounds(display_0_id));
  EXPECT_EQ(gfx::Rect(360, 200, 1, 150), GetIndicatorBounds(display_1_id));

  // Now move 2nd display upwards.
  layout->placement_list[0].offset = -5;
  display_manager()->SetLayoutForCurrentDisplays(layout->Copy());
  event_filter()->ShowSharedEdgeIndicator(root_windows[0] /* primary */);
  ASSERT_EQ(1U, GetWarpRegionsCount());
  EXPECT_EQ(gfx::Rect(359, 32, 1, 318), GetIndicatorBounds(display_0_id));
  EXPECT_EQ(gfx::Rect(360, 0, 1, 350), GetIndicatorBounds(display_1_id));
  event_filter()->ShowSharedEdgeIndicator(root_windows[1] /* secondary */);
  // 32 px are reserved on 2nd display from top, so y must be
  // (32 - 5) = 27.
  ASSERT_EQ(1U, GetWarpRegionsCount());
  EXPECT_EQ(gfx::Rect(359, 0, 1, 350), GetIndicatorBounds(display_0_id));
  EXPECT_EQ(gfx::Rect(360, 27, 1, 323), GetIndicatorBounds(display_1_id));

  event_filter()->HideSharedEdgeIndicator();
}

TEST_F(ExtendedMouseWarpControllerTest, IndicatorBoundsTestOnLeft) {
  UpdateDisplay("360x350,800x700");
  aura::Window::Windows root_windows = Shell::GetAllRootWindows();

  int64_t display_0_id = display::Screen::GetScreen()
                             ->GetDisplayNearestWindow(root_windows[0])
                             .id();
  int64_t display_1_id = display::Screen::GetScreen()
                             ->GetDisplayNearestWindow(root_windows[1])
                             .id();

  std::unique_ptr<display::DisplayLayout> layout(
      display::test::CreateDisplayLayout(display_manager(),
                                         display::DisplayPlacement::LEFT, 0));
  display_manager()->SetLayoutForCurrentDisplays(layout->Copy());

  event_filter()->ShowSharedEdgeIndicator(root_windows[0] /* primary */);
  ASSERT_EQ(1U, GetWarpRegionsCount());
  EXPECT_EQ(gfx::Rect(0, 32, 1, 318), GetIndicatorBounds(display_0_id));
  EXPECT_EQ(gfx::Rect(-1, 0, 1, 350), GetIndicatorBounds(display_1_id));

  event_filter()->ShowSharedEdgeIndicator(root_windows[1] /* secondary */);
  ASSERT_EQ(1U, GetWarpRegionsCount());
  EXPECT_EQ(gfx::Rect(0, 0, 1, 350), GetIndicatorBounds(display_0_id));
  EXPECT_EQ(gfx::Rect(-1, 32, 1, 318), GetIndicatorBounds(display_1_id));

  layout->placement_list[0].offset = 250;
  display_manager()->SetLayoutForCurrentDisplays(layout->Copy());
  event_filter()->ShowSharedEdgeIndicator(root_windows[0] /* primary */);
  ASSERT_EQ(1U, GetWarpRegionsCount());
  EXPECT_EQ(gfx::Rect(0, 250, 1, 100), GetIndicatorBounds(display_0_id));
  EXPECT_EQ(gfx::Rect(-1, 250, 1, 100), GetIndicatorBounds(display_1_id));

  event_filter()->ShowSharedEdgeIndicator(root_windows[1] /* secondary */);
  ASSERT_EQ(1U, GetWarpRegionsCount());
  EXPECT_EQ(gfx::Rect(0, 250, 1, 100), GetIndicatorBounds(display_0_id));
  EXPECT_EQ(gfx::Rect(-1, 250, 1, 100), GetIndicatorBounds(display_1_id));

  event_filter()->HideSharedEdgeIndicator();
}

TEST_F(ExtendedMouseWarpControllerTest, IndicatorBoundsTestOnTopBottom) {
  UpdateDisplay("360x350,800x700");
  aura::Window::Windows root_windows = Shell::GetAllRootWindows();
  int64_t display_0_id = display::Screen::GetScreen()
                             ->GetDisplayNearestWindow(root_windows[0])
                             .id();
  int64_t display_1_id = display::Screen::GetScreen()
                             ->GetDisplayNearestWindow(root_windows[1])
                             .id();

  std::unique_ptr<display::DisplayLayout> layout(
      display::test::CreateDisplayLayout(display_manager(),
                                         display::DisplayPlacement::TOP, 0));
  display_manager()->SetLayoutForCurrentDisplays(layout->Copy());
  event_filter()->ShowSharedEdgeIndicator(root_windows[0] /* primary */);
  ASSERT_EQ(1U, GetWarpRegionsCount());
  EXPECT_EQ(gfx::Rect(0, 0, 360, 1), GetIndicatorBounds(display_0_id));
  EXPECT_EQ(gfx::Rect(0, -1, 360, 1), GetIndicatorBounds(display_1_id));

  event_filter()->ShowSharedEdgeIndicator(root_windows[1] /* secondary */);
  ASSERT_EQ(1U, GetWarpRegionsCount());
  EXPECT_EQ(gfx::Rect(0, 0, 360, 1), GetIndicatorBounds(display_0_id));
  EXPECT_EQ(gfx::Rect(0, -1, 360, 1), GetIndicatorBounds(display_1_id));

  layout->placement_list[0].offset = 250;
  display_manager()->SetLayoutForCurrentDisplays(layout->Copy());
  event_filter()->ShowSharedEdgeIndicator(root_windows[0] /* primary */);
  ASSERT_EQ(1U, GetWarpRegionsCount());
  EXPECT_EQ(gfx::Rect(250, 0, 110, 1), GetIndicatorBounds(display_0_id));
  EXPECT_EQ(gfx::Rect(250, -1, 110, 1), GetIndicatorBounds(display_1_id));

  event_filter()->ShowSharedEdgeIndicator(root_windows[1] /* secondary */);
  ASSERT_EQ(1U, GetWarpRegionsCount());
  EXPECT_EQ(gfx::Rect(250, 0, 110, 1), GetIndicatorBounds(display_0_id));
  EXPECT_EQ(gfx::Rect(250, -1, 110, 1), GetIndicatorBounds(display_1_id));

  layout->placement_list[0].position = display::DisplayPlacement::BOTTOM;
  layout->placement_list[0].offset = 0;
  display_manager()->SetLayoutForCurrentDisplays(layout->Copy());
  event_filter()->ShowSharedEdgeIndicator(root_windows[0] /* primary */);
  ASSERT_EQ(1U, GetWarpRegionsCount());
  EXPECT_EQ(gfx::Rect(0, 349, 360, 1), GetIndicatorBounds(display_0_id));
  EXPECT_EQ(gfx::Rect(0, 350, 360, 1), GetIndicatorBounds(display_1_id));

  event_filter()->ShowSharedEdgeIndicator(root_windows[1] /* secondary */);
  ASSERT_EQ(1U, GetWarpRegionsCount());
  EXPECT_EQ(gfx::Rect(0, 349, 360, 1), GetIndicatorBounds(display_0_id));
  EXPECT_EQ(gfx::Rect(0, 350, 360, 1), GetIndicatorBounds(display_1_id));

  event_filter()->HideSharedEdgeIndicator();
}

// Verify indicators show up as expected with 3+ displays.
TEST_F(ExtendedMouseWarpControllerTest, IndicatorBoundsTestThreeDisplays) {
  UpdateDisplay("360x350,800x700,1000x900");
  aura::Window::Windows root_windows = Shell::GetAllRootWindows();
  display::Screen* screen = display::Screen::GetScreen();
  int64_t display_0_id = screen->GetDisplayNearestWindow(root_windows[0]).id();
  int64_t display_1_id = screen->GetDisplayNearestWindow(root_windows[1]).id();
  int64_t display_2_id = screen->GetDisplayNearestWindow(root_windows[2]).id();

  // Drag from left most display
  event_filter()->ShowSharedEdgeIndicator(root_windows[0]);
  ASSERT_EQ(2U, GetWarpRegionsCount());
  const ExtendedMouseWarpController::WarpRegion* region_0 = GetWarpRegion(0);
  const ExtendedMouseWarpController::WarpRegion* region_1 = GetWarpRegion(1);
  EXPECT_EQ(gfx::Rect(359, 32, 1, 318),
            region_1->GetIndicatorBoundsForTest(display_0_id));
  EXPECT_EQ(gfx::Rect(360, 0, 1, 350),
            region_1->GetIndicatorBoundsForTest(display_1_id));
  EXPECT_EQ(gfx::Rect(1159, 0, 1, 700),
            region_0->GetIndicatorBoundsForTest(display_1_id));
  EXPECT_EQ(gfx::Rect(1160, 0, 1, 700),
            region_0->GetIndicatorBoundsForTest(display_2_id));

  // Drag from middle display
  event_filter()->ShowSharedEdgeIndicator(root_windows[1]);
  ASSERT_EQ(2U, mouse_warp_controller()->warp_regions_.size());
  region_0 = GetWarpRegion(0);
  region_1 = GetWarpRegion(1);
  EXPECT_EQ(gfx::Rect(359, 0, 1, 350),
            region_1->GetIndicatorBoundsForTest(display_0_id));
  EXPECT_EQ(gfx::Rect(360, 32, 1, 318),
            region_1->GetIndicatorBoundsForTest(display_1_id));
  EXPECT_EQ(gfx::Rect(1159, 32, 1, 668),
            region_0->GetIndicatorBoundsForTest(display_1_id));
  EXPECT_EQ(gfx::Rect(1160, 0, 1, 700),
            region_0->GetIndicatorBoundsForTest(display_2_id));

  // Right most display
  event_filter()->ShowSharedEdgeIndicator(root_windows[2]);
  ASSERT_EQ(2U, mouse_warp_controller()->warp_regions_.size());
  region_0 = GetWarpRegion(0);
  region_1 = GetWarpRegion(1);
  EXPECT_EQ(gfx::Rect(359, 0, 1, 350),
            region_1->GetIndicatorBoundsForTest(display_0_id));
  EXPECT_EQ(gfx::Rect(360, 0, 1, 350),
            region_1->GetIndicatorBoundsForTest(display_1_id));
  EXPECT_EQ(gfx::Rect(1159, 0, 1, 700),
            region_0->GetIndicatorBoundsForTest(display_1_id));
  EXPECT_EQ(gfx::Rect(1160, 32, 1, 668),
            region_0->GetIndicatorBoundsForTest(display_2_id));
  event_filter()->HideSharedEdgeIndicator();
  // TODO(oshima): Add test cases primary swap.
}

TEST_F(ExtendedMouseWarpControllerTest,
       IndicatorBoundsTestThreeDisplaysWithLayout) {
  UpdateDisplay("700x500,600x500,1000x900");
  aura::Window::Windows root_windows = Shell::GetAllRootWindows();
  display::Screen* screen = display::Screen::GetScreen();
  int64_t display_0_id = screen->GetDisplayNearestWindow(root_windows[0]).id();
  int64_t display_1_id = screen->GetDisplayNearestWindow(root_windows[1]).id();
  int64_t display_2_id = screen->GetDisplayNearestWindow(root_windows[2]).id();

  // Layout so that all displays touches togter like this:
  //  +-----+---+
  //  |  0  | 1 |
  //  +-+---+--++
  //    |  2   |
  //    +------+
  display::DisplayLayoutBuilder builder(display_0_id);
  builder.AddDisplayPlacement(display_1_id, display_0_id,
                              display::DisplayPlacement::RIGHT, 0);
  builder.AddDisplayPlacement(display_2_id, display_0_id,
                              display::DisplayPlacement::BOTTOM, 100);

  display_manager()->SetLayoutForCurrentDisplays(builder.Build());
  ASSERT_EQ(3U, GetWarpRegionsCount());

  // Drag from 0.
  event_filter()->ShowSharedEdgeIndicator(root_windows[0]);
  ASSERT_EQ(3U, GetWarpRegionsCount());
  const ExtendedMouseWarpController::WarpRegion* region_0 = GetWarpRegion(0);
  const ExtendedMouseWarpController::WarpRegion* region_1 = GetWarpRegion(1);
  const ExtendedMouseWarpController::WarpRegion* region_2 = GetWarpRegion(2);
  // between 2 and 0
  EXPECT_EQ(gfx::Rect(100, 499, 600, 1),
            region_0->GetIndicatorBoundsForTest(display_0_id));
  EXPECT_EQ(gfx::Rect(100, 500, 600, 1),
            region_0->GetIndicatorBoundsForTest(display_2_id));
  // between 2 and 1
  EXPECT_EQ(gfx::Rect(700, 499, 400, 1),
            region_1->GetIndicatorBoundsForTest(display_1_id));
  EXPECT_EQ(gfx::Rect(700, 500, 400, 1),
            region_1->GetIndicatorBoundsForTest(display_2_id));
  // between 1 and 0
  EXPECT_EQ(gfx::Rect(699, 32, 1, 468),
            region_2->GetIndicatorBoundsForTest(display_0_id));
  EXPECT_EQ(gfx::Rect(700, 0, 1, 500),
            region_2->GetIndicatorBoundsForTest(display_1_id));
  event_filter()->HideSharedEdgeIndicator();
}

TEST_F(ExtendedMouseWarpControllerTest,
       IndicatorBoundsTestThreeDisplaysWithLayout2) {
  UpdateDisplay("700x500,600x500,1000x900");
  aura::Window::Windows root_windows = Shell::GetAllRootWindows();
  display::Screen* screen = display::Screen::GetScreen();
  int64_t display_0_id = screen->GetDisplayNearestWindow(root_windows[0]).id();
  int64_t display_1_id = screen->GetDisplayNearestWindow(root_windows[1]).id();
  int64_t display_2_id = screen->GetDisplayNearestWindow(root_windows[2]).id();

  // Layout so that 0 and 1 displays are disconnected.
  //  +-----+ +---+
  //  |  0  | |1 |
  //  +-+---+-+++
  //    |  2   |
  //    +------+
  display::DisplayLayoutBuilder builder(display_0_id);
  builder.AddDisplayPlacement(display_2_id, display_0_id,
                              display::DisplayPlacement::BOTTOM, 100);
  builder.AddDisplayPlacement(display_1_id, display_2_id,
                              display::DisplayPlacement::TOP, 800);

  display_manager()->SetLayoutForCurrentDisplays(builder.Build());
  ASSERT_EQ(2U, GetWarpRegionsCount());

  // Drag from 0.
  event_filter()->ShowSharedEdgeIndicator(root_windows[0]);
  ASSERT_EQ(2U, GetWarpRegionsCount());
  const ExtendedMouseWarpController::WarpRegion* region_0 = GetWarpRegion(0);
  const ExtendedMouseWarpController::WarpRegion* region_1 = GetWarpRegion(1);
  // between 2 and 0
  EXPECT_EQ(gfx::Rect(100, 499, 600, 1),
            region_0->GetIndicatorBoundsForTest(display_0_id));
  EXPECT_EQ(gfx::Rect(100, 500, 600, 1),
            region_0->GetIndicatorBoundsForTest(display_2_id));
  // between 2 and 1
  EXPECT_EQ(gfx::Rect(900, 499, 200, 1),
            region_1->GetIndicatorBoundsForTest(display_1_id));
  EXPECT_EQ(gfx::Rect(900, 500, 200, 1),
            region_1->GetIndicatorBoundsForTest(display_2_id));
  event_filter()->HideSharedEdgeIndicator();
}

// Check that the point in the rotated secondary display's warp region is
// converted correctly from native host coordinates to screen DIP coordinates.
// (see https://crbug.com/905035)
// Flaky. https://crbug.com/1217187.
TEST_F(ExtendedMouseWarpControllerTest,
       DISABLED_CheckHostPointToScreenInMouseWarpRegion) {
  // Zoom factor is needed to trigger rounding error which occured in previous
  // code.
  UpdateDisplay("50+50-300x200@0.8,50+300-300x100/r");

  aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows();

  // Check the primary display's size and scale.
  display::Display primary_display =
      display::Screen::GetScreen()->GetDisplayNearestWindow(root_windows[0]);
  ASSERT_EQ("250x250", primary_display.size().ToString());
  ASSERT_EQ(0.8f, primary_display.device_scale_factor());

  // Create a window to be dragged in primary display.
  std::unique_ptr<aura::test::TestWindowDelegate> test_window_delegate =
      std::make_unique<aura::test::TestWindowDelegate>();
  test_window_delegate->set_window_component(HTCAPTION);
  const gfx::Size initial_window_size(100, 100);
  std::unique_ptr<aura::Window> test_window(
      CreateTestWindowInShellWithDelegateAndType(
          test_window_delegate.get(), aura::client::WINDOW_TYPE_NORMAL, 0,
          gfx::Rect(initial_window_size)));
  ASSERT_EQ(root_windows[0], test_window->GetRootWindow());
  ASSERT_FALSE(test_window->HasCapture());

  AshWindowTreeHostPlatform* window_host =
      static_cast<AshWindowTreeHostPlatform*>(root_windows[0]->GetHost());

  // Move mouse cursor and capture the window.
  gfx::Point location_in_host_native(0, 0);
  DispatchMouseEventWithNative(window_host, location_in_host_native,
                               ui::EventType::kMouseMoved, ui::EF_NONE,
                               ui::EF_NONE);
  DispatchMouseEventWithNative(
      window_host, location_in_host_native, ui::EventType::kMousePressed,
      ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);

  // Window should be captured.
  ASSERT_TRUE(test_window->HasCapture());

  int64_t display_0_id = primary_display.id();
  const gfx::Rect indicator_in_primary_display =
      GetIndicatorNativeBounds(display_0_id);
  int64_t display_1_id = display::Screen::GetScreen()
                             ->GetDisplayNearestWindow(root_windows[1])
                             .id();
  const gfx::Rect indicator_in_secondary_display =
      GetIndicatorNativeBounds(display_1_id);

  gfx::Point location_in_screen_native, location_in_screen_dip;

  // Move mouse cursor to the warp region of first display.
  location_in_screen_native = indicator_in_primary_display.CenterPoint();
  location_in_host_native =
      location_in_screen_native -
      root_windows[0]->GetHost()->GetBoundsInPixels().OffsetFromOrigin();
  DispatchMouseEventWithNative(window_host, location_in_host_native,
                               ui::EventType::kMouseDragged,
                               ui::EF_LEFT_MOUSE_BUTTON, 0);

  // Mouse cursor should be warped into secondary display.
  location_in_screen_dip = aura::Env::GetInstance()->last_mouse_location();
  EXPECT_TRUE(
      root_windows[1]->GetBoundsInScreen().Contains(location_in_screen_dip));

  // Move mouse cursor to the warp region of secondary display.
  location_in_screen_native = indicator_in_secondary_display.CenterPoint();
  location_in_host_native =
      location_in_screen_native -
      root_windows[0]->GetHost()->GetBoundsInPixels().OffsetFromOrigin();
  DispatchMouseEventWithNative(window_host, location_in_host_native,
                               ui::EventType::kMouseDragged,
                               ui::EF_LEFT_MOUSE_BUTTON, 0);

  // Mouse cursor should be warped into first display.
  location_in_screen_dip = aura::Env::GetInstance()->last_mouse_location();
  EXPECT_TRUE(
      root_windows[0]->GetBoundsInScreen().Contains(location_in_screen_dip));

  // After mouse warping, x-coordinate of mouse location in native coordinates
  // should be 2 px away from end. Primary display has zoom factor of 0.8. So
  // the offset in screen coordinates should be 2/0.8, which is 2.5. The end of
  // primary display in screen coordinates is 250. So x-coordinate of mouse
  // cursor in screen coordinates should be 247.
  EXPECT_EQ(247, aura::Env::GetInstance()->last_mouse_location().x());

  // Get cursor's location in host native coordinates.
  gfx::Point location_in_host_dip;
  location_in_screen_dip = aura::Env::GetInstance()->last_mouse_location();
  location_in_host_dip = location_in_screen_dip;
  ::wm::ConvertPointFromScreen(root_windows[0], &location_in_host_dip);
  location_in_host_native = location_in_host_dip;
  root_windows[0]->GetHost()->ConvertDIPToPixels(&location_in_host_native);

  // Release mouse button.
  DispatchMouseEventWithNative(
      window_host, location_in_host_native, ui::EventType::kMouseReleased,
      ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
}

}  // namespace ash