summaryrefslogtreecommitdiffstats
path: root/ash/display/display_controller_unittest.cc
blob: 48d2babf7b64ab88f9c4af9c7a194db452eea269 (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
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
// Copyright (c) 2012 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/display_controller.h"

#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "ui/aura/root_window.h"
#include "ui/gfx/display.h"
#include "ui/gfx/screen.h"

#include "ui/aura/env.h"
#include "ui/aura/display_manager.h"

namespace ash {
namespace test {
namespace {

gfx::Display GetPrimaryDisplay() {
  return gfx::Screen::GetDisplayNearestWindow(
      Shell::GetAllRootWindows()[0]);
}

gfx::Display GetSecondaryDisplay() {
  return gfx::Screen::GetDisplayNearestWindow(
      Shell::GetAllRootWindows()[1]);
}

}  // namespace

class DisplayControllerTest : public test::AshTestBase {
 public:
  DisplayControllerTest() {}
  virtual ~DisplayControllerTest() {}

  virtual void SetUp() OVERRIDE {
    internal::DisplayController::SetExtendedDesktopEnabled(true);
    AshTestBase::SetUp();
  }

  virtual void TearDown() OVERRIDE {
    AshTestBase::TearDown();
    internal::DisplayController::SetExtendedDesktopEnabled(false);
  }

 private:
  DISALLOW_COPY_AND_ASSIGN(DisplayControllerTest);
};

#if defined(OS_WIN)
// TOD(oshima): Windows creates a window with smaller client area.
// Fix this and enable tests.
#define MAYBE_SecondaryDisplayLayout DISABLED_SecondaryDisplayLayout
#define MAYBE_BoundsUpdated DISABLED_BoundsUpdated
#else
#define MAYBE_SecondaryDisplayLayout SecondaryDisplayLayout
#define MAYBE_BoundsUpdated BoundsUpdated
#endif

TEST_F(DisplayControllerTest, MAYBE_SecondaryDisplayLayout) {
  UpdateDisplay("500x500,400x400");
  gfx::Display* secondary_display =
      aura::Env::GetInstance()->display_manager()->GetDisplayAt(1);
  gfx::Insets insets(5, 5, 5, 5);
  secondary_display->UpdateWorkAreaFromInsets(insets);

  // Default layout is LEFT.
  EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString());
  EXPECT_EQ("500,0 400x400", GetSecondaryDisplay().bounds().ToString());
  EXPECT_EQ("505,5 390x390", GetSecondaryDisplay().work_area().ToString());

  // Layout the secondary display to the bottom of the primary.
  Shell::GetInstance()->display_controller()->SetSecondaryDisplayLayout(
      internal::DisplayController::BOTTOM);
  EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString());
  EXPECT_EQ("0,500 400x400", GetSecondaryDisplay().bounds().ToString());
  EXPECT_EQ("5,505 390x390", GetSecondaryDisplay().work_area().ToString());

  // Layout the secondary display to the left of the primary.
  Shell::GetInstance()->display_controller()->SetSecondaryDisplayLayout(
      internal::DisplayController::LEFT);
  EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString());
  EXPECT_EQ("-400,0 400x400", GetSecondaryDisplay().bounds().ToString());
  EXPECT_EQ("-395,5 390x390", GetSecondaryDisplay().work_area().ToString());

  // Layout the secondary display to the top of the primary.
  Shell::GetInstance()->display_controller()->SetSecondaryDisplayLayout(
      internal::DisplayController::TOP);
  EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString());
  EXPECT_EQ("0,-400 400x400", GetSecondaryDisplay().bounds().ToString());
  EXPECT_EQ("5,-395 390x390", GetSecondaryDisplay().work_area().ToString());
}

TEST_F(DisplayControllerTest, MAYBE_BoundsUpdated) {
  Shell::GetInstance()->display_controller()->SetSecondaryDisplayLayout(
      internal::DisplayController::BOTTOM);
  UpdateDisplay("500x500,400x400");
  gfx::Display* secondary_display =
      aura::Env::GetInstance()->display_manager()->GetDisplayAt(1);
  gfx::Insets insets(5, 5, 5, 5);
  secondary_display->UpdateWorkAreaFromInsets(insets);

  EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString());
  EXPECT_EQ("0,500 400x400", GetSecondaryDisplay().bounds().ToString());
  EXPECT_EQ("5,505 390x390", GetSecondaryDisplay().work_area().ToString());

  UpdateDisplay("600x600,400x400");
  EXPECT_EQ("0,0 600x600", GetPrimaryDisplay().bounds().ToString());
  EXPECT_EQ("0,600 400x400", GetSecondaryDisplay().bounds().ToString());
  EXPECT_EQ("5,605 390x390", GetSecondaryDisplay().work_area().ToString());

  UpdateDisplay("600x600,500x500");
  EXPECT_EQ("0,0 600x600", GetPrimaryDisplay().bounds().ToString());
  EXPECT_EQ("0,600 500x500", GetSecondaryDisplay().bounds().ToString());
  EXPECT_EQ("5,605 490x490", GetSecondaryDisplay().work_area().ToString());

  UpdateDisplay("600x600");
  EXPECT_EQ("0,0 600x600", GetPrimaryDisplay().bounds().ToString());
  EXPECT_EQ(1, gfx::Screen::GetNumDisplays());

  UpdateDisplay("700x700,1000x1000");
  ASSERT_EQ(2, gfx::Screen::GetNumDisplays());
  EXPECT_EQ("0,0 700x700", GetPrimaryDisplay().bounds().ToString());
  EXPECT_EQ("0,700 1000x1000", GetSecondaryDisplay().bounds().ToString());
}

}  // namespace test
}  // namespace ash