display_controller_unittest.cc revision 5f1c94371a64b3196d4be9466099bb892df9b88e
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/display/display_controller.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "ash/ash_switches.h"
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/display/display_info.h"
97dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "ash/display/display_layout_store.h"
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/display/display_manager.h"
115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/screen_util.h"
125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/shelf/shelf.h"
132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/shelf/shelf_widget.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/shell.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/test/ash_test_base.h"
16a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ash/test/ash_test_helper.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/test/cursor_manager_test_api.h"
18f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ash/test/display_manager_test_api.h"
19a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ash/test/test_shell_delegate.h"
20f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ash/wm/window_state.h"
21a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ash/wm/wm_event.h"
2258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "base/command_line.h"
23d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/aura/client/focus_change_observer.h"
24d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/aura/client/focus_client.h"
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/env.h"
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/window_tracker.h"
2723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)#include "ui/aura/window_tree_host.h"
28d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/events/event_handler.h"
295f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "ui/events/test/event_generator.h"
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/display.h"
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/screen.h"
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/widget.h"
33effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "ui/wm/public/activation_change_observer.h"
34effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "ui/wm/public/activation_client.h"
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
36eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#if defined(USE_X11)
37eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include <X11/Xlib.h>
385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/gfx/x/x11_types.h"
39eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#undef RootWindow
40eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#endif
41eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ash {
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace {
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
45c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)const char kDesktopBackgroundView[] = "DesktopBackgroundView";
46c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
47d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)template<typename T>
48d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)class Resetter {
49d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) public:
50d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  explicit Resetter(T* value) : value_(*value) {
51d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    *value = 0;
52d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  }
53d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  ~Resetter() { }
54d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  T value() { return value_; }
55d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
56d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) private:
57d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  T value_;
58d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(Resetter);
59d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)};
60d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
61ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdochclass TestObserver : public DisplayController::Observer,
62d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                     public gfx::DisplayObserver,
63d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                     public aura::client::FocusChangeObserver,
64d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                     public aura::client::ActivationChangeObserver {
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
66ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  TestObserver()
67ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch      : changing_count_(0),
68ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch        changed_count_(0),
69ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch        bounds_changed_count_(0),
70cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)        rotation_changed_count_(0),
71cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)        workarea_changed_count_(0),
72d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)        changed_display_id_(0),
73d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)        focus_changed_count_(0),
74d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)        activation_changed_count_(0) {
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    Shell::GetInstance()->display_controller()->AddObserver(this);
76ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    Shell::GetScreen()->AddObserver(this);
77d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    aura::client::GetFocusClient(Shell::GetPrimaryRootWindow())->
78d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)        AddObserver(this);
79d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    aura::client::GetActivationClient(Shell::GetPrimaryRootWindow())->
80d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)        AddObserver(this);
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~TestObserver() {
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    Shell::GetInstance()->display_controller()->RemoveObserver(this);
85ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    Shell::GetScreen()->RemoveObserver(this);
86d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    aura::client::GetFocusClient(Shell::GetPrimaryRootWindow())->
87d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)        RemoveObserver(this);
88d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    aura::client::GetActivationClient(Shell::GetPrimaryRootWindow())->
89d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)        RemoveObserver(this);
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
92ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // Overridden from DisplayController::Observer
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnDisplayConfigurationChanging() OVERRIDE {
942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    ++changing_count_;
952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnDisplayConfigurationChanged() OVERRIDE {
972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    ++changed_count_;
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
100ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // Overrideen from gfx::DisplayObserver
101cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual void OnDisplayMetricsChanged(const gfx::Display& display,
102cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                                       uint32_t metrics) OVERRIDE {
103ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    changed_display_id_ = display.id();
104cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    if (metrics & DISPLAY_METRIC_BOUNDS)
105cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      ++bounds_changed_count_;
106cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    if (metrics & DISPLAY_METRIC_ROTATION)
107cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      ++rotation_changed_count_;
108cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    if (metrics & DISPLAY_METRIC_WORK_AREA)
109cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      ++workarea_changed_count_;
110ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  }
111ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  virtual void OnDisplayAdded(const gfx::Display& new_display) OVERRIDE {
112ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  }
113ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE {
114ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  }
115ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
116d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Overridden from aura::client::FocusChangeObserver
117d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  virtual void OnWindowFocused(aura::Window* gained_focus,
118d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                               aura::Window* lost_focus) OVERRIDE {
119d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    focus_changed_count_++;
120d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  }
121d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
122d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Overridden from aura::client::ActivationChangeObserver
123d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  virtual void OnWindowActivated(aura::Window* gained_active,
124d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                                 aura::Window* lost_active) OVERRIDE {
125d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    activation_changed_count_++;
126d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  }
127d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  virtual void OnAttemptToReactivateWindow(
128d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      aura::Window* request_active,
129d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      aura::Window* actual_active) OVERRIDE {
130d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  }
131d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int CountAndReset() {
1332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_EQ(changing_count_, changed_count_);
134d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    changed_count_ = 0;
135d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    return Resetter<int>(&changing_count_).value();
136ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  }
137ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
138ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  int64 GetBoundsChangedCountAndReset() {
139d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    return Resetter<int>(&bounds_changed_count_).value();
140ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  }
141ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
142cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  int64 GetRotationChangedCountAndReset() {
143cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    return Resetter<int>(&rotation_changed_count_).value();
144cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  }
145cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
146cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  int64 GetWorkareaChangedCountAndReset() {
147cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    return Resetter<int>(&workarea_changed_count_).value();
148cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  }
149cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
150ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  int64 GetChangedDisplayIdAndReset() {
151d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    return Resetter<int64>(&changed_display_id_).value();
152d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  }
153d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
154d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  int GetFocusChangedCountAndReset() {
155d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    return Resetter<int>(&focus_changed_count_).value();
156d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  }
157d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
158d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  int GetActivationChangedCountAndReset() {
159d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    return Resetter<int>(&activation_changed_count_).value();
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
1632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int changing_count_;
1642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int changed_count_;
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
166ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  int bounds_changed_count_;
167cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  int rotation_changed_count_;
168cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  int workarea_changed_count_;
169ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  int64 changed_display_id_;
170ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
171d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  int focus_changed_count_;
172d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  int activation_changed_count_;
173d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(TestObserver);
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::Display GetPrimaryDisplay() {
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return Shell::GetScreen()->GetDisplayNearestWindow(
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      Shell::GetAllRootWindows()[0]);
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)gfx::Display GetSecondaryDisplay() {
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return Shell::GetScreen()->GetDisplayNearestWindow(
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      Shell::GetAllRootWindows()[1]);
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void SetSecondaryDisplayLayoutAndOffset(DisplayLayout::Position position,
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                        int offset) {
189c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  DisplayLayout layout(position, offset);
190c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ASSERT_GT(Shell::GetScreen()->GetNumDisplays(), 1);
1918bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  Shell::GetInstance()->display_manager()->
1927dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      SetLayoutForCurrentDisplays(layout);
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void SetSecondaryDisplayLayout(DisplayLayout::Position position) {
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SetSecondaryDisplayLayoutAndOffset(position, 0);
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
199c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)void SetDefaultDisplayLayout(DisplayLayout::Position position) {
2007dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  Shell::GetInstance()->display_manager()->layout_store()->
201c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      SetDefaultDisplayLayout(DisplayLayout(position, 0));
202c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
203c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
2042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class DisplayControllerShutdownTest : public test::AshTestBase {
2052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
206a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  DisplayControllerShutdownTest() {}
207a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual ~DisplayControllerShutdownTest() {}
208a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
2092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void TearDown() OVERRIDE {
2102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    test::AshTestBase::TearDown();
2117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    if (!SupportsMultipleDisplays())
2127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      return;
2137d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
2142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // Make sure that primary display is accessible after shutdown.
2152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    gfx::Display primary = Shell::GetScreen()->GetPrimaryDisplay();
2162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_EQ("0,0 444x333", primary.bounds().ToString());
2172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    EXPECT_EQ(2, Shell::GetScreen()->GetNumDisplays());
2182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
219a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
220a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) private:
221a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(DisplayControllerShutdownTest);
222a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)};
223a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
224a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class StartupHelper : public test::TestShellDelegate,
225a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                      public DisplayController::Observer {
226a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) public:
227a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  StartupHelper() : displays_initialized_(false) {}
228a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual ~StartupHelper() {}
229a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
230a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // ash::ShellSelegate:
231a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual void PreInit() OVERRIDE {
232a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    Shell::GetInstance()->display_controller()->AddObserver(this);
233a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
234a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
235a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // ash::DisplayController::Observer:
236a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual void OnDisplaysInitialized() OVERRIDE {
237a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    DCHECK(!displays_initialized_);
238a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    displays_initialized_ = true;
239a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
240a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
241a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  const bool displays_initialized() const {
242a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return displays_initialized_;
243a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
244a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
245a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) private:
246a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bool displays_initialized_;
247a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
248a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(StartupHelper);
249a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)};
250a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
251a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class DisplayControllerStartupTest : public test::AshTestBase {
252a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) public:
253a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  DisplayControllerStartupTest() : startup_helper_(new StartupHelper) {}
254a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual ~DisplayControllerStartupTest() {}
255a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
256a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // ash::test::AshTestBase:
257a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual void SetUp() OVERRIDE {
258a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    ash_test_helper()->set_test_shell_delegate(startup_helper_);
259a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    test::AshTestBase::SetUp();
260a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
261a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual void TearDown() OVERRIDE {
262a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    Shell::GetInstance()->display_controller()->RemoveObserver(startup_helper_);
263a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    test::AshTestBase::TearDown();
264a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
265a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
266a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  const StartupHelper* startup_helper() const { return startup_helper_; }
267a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
268a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) private:
269a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  StartupHelper* startup_helper_;  // Owned by ash::Shell.
270a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
271a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(DisplayControllerStartupTest);
2722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
2732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class TestEventHandler : public ui::EventHandler {
2752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
276c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  TestEventHandler() : target_root_(NULL),
277c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                       touch_radius_x_(0.0),
278c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                       touch_radius_y_(0.0),
279c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                       scroll_x_offset_(0.0),
280c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                       scroll_y_offset_(0.0),
281c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                       scroll_x_offset_ordinal_(0.0),
282c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                       scroll_y_offset_ordinal_(0.0) {}
2832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~TestEventHandler() {}
2842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
286eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    if (event->flags() & ui::EF_IS_SYNTHESIZED &&
287eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch        event->type() != ui::ET_MOUSE_EXITED &&
288eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch        event->type() != ui::ET_MOUSE_ENTERED) {
289c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      return;
290eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    }
291c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    aura::Window* target = static_cast<aura::Window*>(event->target());
292c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    mouse_location_ = event->root_location();
293c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    target_root_ = target->GetRootWindow();
294c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    event->StopPropagation();
295c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
296c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
297c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE {
2982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    aura::Window* target = static_cast<aura::Window*>(event->target());
2992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // Only record when the target is the background which covers
3002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // entire root window.
301c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    if (target->name() != kDesktopBackgroundView)
3022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      return;
303c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    touch_radius_x_ = event->radius_x();
304c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    touch_radius_y_ = event->radius_y();
305c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    event->StopPropagation();
306c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
307c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
308c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE {
309c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    aura::Window* target = static_cast<aura::Window*>(event->target());
310c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    // Only record when the target is the background which covers
311c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    // entire root window.
312c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    if (target->name() != kDesktopBackgroundView)
313c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      return;
314c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
315c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    if (event->type() == ui::ET_SCROLL) {
316c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      scroll_x_offset_ = event->x_offset();
317c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      scroll_y_offset_ = event->y_offset();
318c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      scroll_x_offset_ordinal_ = event->x_offset_ordinal();
319c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      scroll_y_offset_ordinal_ = event->y_offset_ordinal();
320c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    }
3212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    event->StopPropagation();
3222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
3232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::string GetLocationAndReset() {
3252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    std::string result = mouse_location_.ToString();
3262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    mouse_location_.SetPoint(0, 0);
3272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    target_root_ = NULL;
3282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return result;
3292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
3302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
331c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  float touch_radius_x() { return touch_radius_x_; }
332c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  float touch_radius_y() { return touch_radius_y_; }
333c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  float scroll_x_offset() { return scroll_x_offset_; }
334c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  float scroll_y_offset() { return scroll_y_offset_; }
335c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  float scroll_x_offset_ordinal() { return scroll_x_offset_ordinal_; }
336c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  float scroll_y_offset_ordinal() { return scroll_y_offset_ordinal_; }
337c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
3382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private:
3392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  gfx::Point mouse_location_;
3401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  aura::Window* target_root_;
3412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
342c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  float touch_radius_x_;
343c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  float touch_radius_y_;
344c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  float scroll_x_offset_;
345c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  float scroll_y_offset_;
346c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  float scroll_x_offset_ordinal_;
347c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  float scroll_y_offset_ordinal_;
348c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
3492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(TestEventHandler);
3502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
3512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)gfx::Display::Rotation GetStoredRotation(int64 id) {
3532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return Shell::GetInstance()->display_manager()->GetDisplayInfo(id).rotation();
3542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
3552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)float GetStoredUIScale(int64 id) {
357f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  return Shell::GetInstance()->display_manager()->GetDisplayInfo(id).
358f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      GetEffectiveUIScale();
3592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
3602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
361eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#if defined(USE_X11)
3621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)void GetPrimaryAndSeconary(aura::Window** primary,
3631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                           aura::Window** secondary) {
364eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  *primary = Shell::GetPrimaryRootWindow();
365f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  aura::Window::Windows root_windows = Shell::GetAllRootWindows();
366eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  *secondary = root_windows[0] == *primary ? root_windows[1] : root_windows[0];
367eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
368eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
369a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)std::string GetXWindowName(aura::WindowTreeHost* host) {
370eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  char* name = NULL;
371a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  XFetchName(gfx::GetXDisplay(), host->GetAcceleratedWidget(), &name);
372ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  std::string ret(name);
373ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  XFree(name);
374ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  return ret;
375eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
376eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#endif
377eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace
3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef test::AshTestBase DisplayControllerTest;
3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(DisplayControllerShutdownTest, Shutdown) {
3837d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (!SupportsMultipleDisplays())
3847d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    return;
3857d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
3862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  UpdateDisplay("444x333, 200x200");
3872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
389a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)TEST_F(DisplayControllerStartupTest, Startup) {
390a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (!SupportsMultipleDisplays())
391a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return;
392a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
393a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  EXPECT_TRUE(startup_helper()->displays_initialized());
394a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
395a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
3962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(DisplayControllerTest, SecondaryDisplayLayout) {
3977d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (!SupportsMultipleDisplays())
3987d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    return;
3997d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
400d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Creates windows to catch activation change event.
401d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithId(1));
402d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  w1->Focus();
403d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  TestObserver observer;
4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  UpdateDisplay("500x500,400x400");
4062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(1, observer.CountAndReset());  // resize and add
407ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset());
408cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_EQ(1, observer.GetWorkareaChangedCountAndReset());
409d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
410d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  gfx::Insets insets(5, 5, 5, 5);
4125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  int64 secondary_display_id = ScreenUtil::GetSecondaryDisplay().id();
413ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  Shell::GetInstance()->display_manager()->UpdateWorkAreaOfDisplay(
414ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch      secondary_display_id, insets);
4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Default layout is RIGHT.
4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString());
4185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("500,0 400x400", GetSecondaryDisplay().bounds().ToString());
4195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("505,5 390x390", GetSecondaryDisplay().work_area().ToString());
420d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
421d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Layout the secondary display to the bottom of the primary.
4245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SetSecondaryDisplayLayout(DisplayLayout::BOTTOM);
4255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(1, observer.CountAndReset());
426ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset());
427cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_EQ(1, observer.GetWorkareaChangedCountAndReset());
428d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
429d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
430ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset());
4315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString());
4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("0,500 400x400", GetSecondaryDisplay().bounds().ToString());
4335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("5,505 390x390", GetSecondaryDisplay().work_area().ToString());
4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Layout the secondary display to the left of the primary.
4365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SetSecondaryDisplayLayout(DisplayLayout::LEFT);
4375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(1, observer.CountAndReset());
438ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset());
439cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_EQ(1, observer.GetWorkareaChangedCountAndReset());
440d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
441d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
442ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset());
4435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString());
4445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("-400,0 400x400", GetSecondaryDisplay().bounds().ToString());
4455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("-395,5 390x390", GetSecondaryDisplay().work_area().ToString());
4465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Layout the secondary display to the top of the primary.
4485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SetSecondaryDisplayLayout(DisplayLayout::TOP);
4495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(1, observer.CountAndReset());
450ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset());
451cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_EQ(1, observer.GetWorkareaChangedCountAndReset());
452d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
453d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
454ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset());
4555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString());
4565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("0,-400 400x400", GetSecondaryDisplay().bounds().ToString());
4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("5,-395 390x390", GetSecondaryDisplay().work_area().ToString());
4585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Layout to the right with an offset.
4605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SetSecondaryDisplayLayoutAndOffset(DisplayLayout::RIGHT, 300);
4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(1, observer.CountAndReset());  // resize and add
462ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset());
463cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_EQ(1, observer.GetWorkareaChangedCountAndReset());
464d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
465d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
466ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset());
4675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString());
4685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("500,300 400x400", GetSecondaryDisplay().bounds().ToString());
4695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Keep the minimum 100.
4715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SetSecondaryDisplayLayoutAndOffset(DisplayLayout::RIGHT, 490);
4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(1, observer.CountAndReset());  // resize and add
473ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset());
474cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_EQ(1, observer.GetWorkareaChangedCountAndReset());
475d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
476d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
477ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset());
4785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString());
4795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("500,400 400x400", GetSecondaryDisplay().bounds().ToString());
4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SetSecondaryDisplayLayoutAndOffset(DisplayLayout::RIGHT, -400);
482ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset());
483ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset());
484cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_EQ(1, observer.GetWorkareaChangedCountAndReset());
4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(1, observer.CountAndReset());  // resize and add
486d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
487d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
4885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString());
4895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("500,-300 400x400", GetSecondaryDisplay().bounds().ToString());
4905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //  Layout to the bottom with an offset.
4925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SetSecondaryDisplayLayoutAndOffset(DisplayLayout::BOTTOM, -200);
493ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset());
494ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset());
495cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_EQ(1, observer.GetWorkareaChangedCountAndReset());
4965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(1, observer.CountAndReset());  // resize and add
497d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
498d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString());
5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("-200,500 400x400", GetSecondaryDisplay().bounds().ToString());
5015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Keep the minimum 100.
5035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SetSecondaryDisplayLayoutAndOffset(DisplayLayout::BOTTOM, 490);
504ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset());
505ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset());
506cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_EQ(1, observer.GetWorkareaChangedCountAndReset());
5075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(1, observer.CountAndReset());  // resize and add
508d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
509d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString());
5115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("400,500 400x400", GetSecondaryDisplay().bounds().ToString());
5125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SetSecondaryDisplayLayoutAndOffset(DisplayLayout::BOTTOM, -400);
514ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset());
515ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset());
516cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_EQ(1, observer.GetWorkareaChangedCountAndReset());
5175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(1, observer.CountAndReset());  // resize and add
518d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
519d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
5205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString());
5215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("-300,500 400x400", GetSecondaryDisplay().bounds().ToString());
522ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
523ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // Setting the same layout shouldn't invoke observers.
524ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  SetSecondaryDisplayLayoutAndOffset(DisplayLayout::BOTTOM, -400);
525ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_EQ(0, observer.GetChangedDisplayIdAndReset());
526ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_EQ(0, observer.GetBoundsChangedCountAndReset());
527cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_EQ(0, observer.GetWorkareaChangedCountAndReset());
528ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_EQ(0, observer.CountAndReset());  // resize and add
529d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
530d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
531ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString());
532ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_EQ("-300,500 400x400", GetSecondaryDisplay().bounds().ToString());
533d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
534d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  UpdateDisplay("500x500");
535d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_LE(1, observer.GetFocusChangedCountAndReset());
536d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_LE(1, observer.GetActivationChangedCountAndReset());
5375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
539f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)namespace {
540f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
541c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen MurdochDisplayInfo CreateDisplayInfo(int64 id,
542c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch                              const gfx::Rect& bounds,
543c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch                              float device_scale_factor) {
544c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  DisplayInfo info(id, "", false);
545f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  info.SetBounds(bounds);
546f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  info.set_device_scale_factor(device_scale_factor);
547f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  return info;
548f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
549f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
550f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}  // namespace
551f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
552f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)TEST_F(DisplayControllerTest, MirrorToDockedWithFullscreen) {
5535f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  if (!SupportsMultipleDisplays())
5545f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    return;
5555f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
556f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Creates windows to catch activation change event.
557f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithId(1));
558f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  w1->Focus();
559f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
560f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Docked mode.
561c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  DisplayManager* display_manager = Shell::GetInstance()->display_manager();
562f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
563c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  const DisplayInfo internal_display_info =
564f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      CreateDisplayInfo(1, gfx::Rect(0, 0, 500, 500), 2.0f);
565c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  const DisplayInfo external_display_info =
566f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      CreateDisplayInfo(2, gfx::Rect(0, 0, 500, 500), 1.0f);
567f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
568c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  std::vector<DisplayInfo> display_info_list;
569f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Mirror.
570f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  display_info_list.push_back(internal_display_info);
571f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  display_info_list.push_back(external_display_info);
572f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  display_manager->OnNativeDisplaysChanged(display_info_list);
573f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  const int64 internal_display_id =
574f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      test::DisplayManagerTestApi(display_manager).
575f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      SetFirstDisplayAsInternalDisplay();
576f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(1, internal_display_id);
577f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(2U, display_manager->num_connected_displays());
578f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(1U, display_manager->GetNumDisplays());
579f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
580f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  wm::WindowState* window_state = wm::GetWindowState(w1.get());
581a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  const wm::WMEvent toggle_fullscreen_event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
582a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  window_state->OnWMEvent(&toggle_fullscreen_event);
583f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_TRUE(window_state->IsFullscreen());
584f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ("0,0 250x250", w1->bounds().ToString());
585f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Dock mode.
586f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  TestObserver observer;
587f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  display_info_list.clear();
588f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  display_info_list.push_back(external_display_info);
589f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  display_manager->OnNativeDisplaysChanged(display_info_list);
590f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(1U, display_manager->GetNumDisplays());
591f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(1U, display_manager->num_connected_displays());
592f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(0, observer.GetChangedDisplayIdAndReset());
593f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(0, observer.GetBoundsChangedCountAndReset());
594cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_EQ(0, observer.GetWorkareaChangedCountAndReset());
595f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(1, observer.CountAndReset());
596f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
597f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
598f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
599f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_TRUE(window_state->IsFullscreen());
600f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ("0,0 500x500", w1->bounds().ToString());
601f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
602f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
6032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(DisplayControllerTest, BoundsUpdated) {
6047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (!SupportsMultipleDisplays())
6057d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    return;
6067d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
607d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Creates windows to catch activation change event.
608d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithId(1));
609d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  w1->Focus();
610d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
6115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  TestObserver observer;
612c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  SetDefaultDisplayLayout(DisplayLayout::BOTTOM);
6135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  UpdateDisplay("200x200,300x300");  // layout, resize and add.
614c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(1, observer.CountAndReset());
615d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
616d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
6175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
618c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  DisplayManager* display_manager = Shell::GetInstance()->display_manager();
6195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  gfx::Insets insets(5, 5, 5, 5);
620ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  display_manager->UpdateWorkAreaOfDisplay(
6215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ScreenUtil::GetSecondaryDisplay().id(), insets);
6225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("0,0 200x200", GetPrimaryDisplay().bounds().ToString());
6245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("0,200 300x300", GetSecondaryDisplay().bounds().ToString());
6255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("5,205 290x290", GetSecondaryDisplay().work_area().ToString());
6265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  UpdateDisplay("400x400,200x200");
6282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(1, observer.CountAndReset());  // two resizes
629d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
630d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
6315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("0,0 400x400", GetPrimaryDisplay().bounds().ToString());
6325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("0,400 200x200", GetSecondaryDisplay().bounds().ToString());
6335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  UpdateDisplay("400x400,300x300");
6355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(1, observer.CountAndReset());
636d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
637d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
6385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("0,0 400x400", GetPrimaryDisplay().bounds().ToString());
6395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("0,400 300x300", GetSecondaryDisplay().bounds().ToString());
6405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  UpdateDisplay("400x400");
6425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(1, observer.CountAndReset());
643d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_LE(1, observer.GetFocusChangedCountAndReset());
644d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_LE(1, observer.GetActivationChangedCountAndReset());
6455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("0,0 400x400", GetPrimaryDisplay().bounds().ToString());
6465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(1, Shell::GetScreen()->GetNumDisplays());
6475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
648c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  UpdateDisplay("400x500*2,300x300");
6492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(1, observer.CountAndReset());
650d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
651d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
6525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays());
653c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ("0,0 200x250", GetPrimaryDisplay().bounds().ToString());
654c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ("0,250 300x300", GetSecondaryDisplay().bounds().ToString());
6552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // No change
657c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  UpdateDisplay("400x500*2,300x300");
6582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(0, observer.CountAndReset());
659d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
660d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
6612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Rotation
663cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  observer.GetRotationChangedCountAndReset();  // we only want to reset.
6642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int64 primary_id = GetPrimaryDisplay().id();
6652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  display_manager->SetDisplayRotation(primary_id, gfx::Display::ROTATE_90);
666cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_EQ(1, observer.GetRotationChangedCountAndReset());
6672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(1, observer.CountAndReset());
668d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
669d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
6702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  display_manager->SetDisplayRotation(primary_id, gfx::Display::ROTATE_90);
671cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_EQ(0, observer.GetRotationChangedCountAndReset());
6722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(0, observer.CountAndReset());
673d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
674d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
6752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
676c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // UI scale is eanbled only on internal display.
6772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int64 secondary_id = GetSecondaryDisplay().id();
6782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  gfx::Display::SetInternalDisplayId(secondary_id);
679c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  display_manager->SetDisplayUIScale(secondary_id, 1.125f);
6802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(1, observer.CountAndReset());
681d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
682d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
683c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  display_manager->SetDisplayUIScale(secondary_id, 1.125f);
684c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(0, observer.CountAndReset());
685d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
686d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
687c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  display_manager->SetDisplayUIScale(primary_id, 1.125f);
688c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(0, observer.CountAndReset());
689d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
690d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
691c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  display_manager->SetDisplayUIScale(primary_id, 1.125f);
6922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(0, observer.CountAndReset());
693d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
694d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
6952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
6962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6977d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_F(DisplayControllerTest, SwapPrimary) {
6987d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (!SupportsMultipleDisplays())
6997d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    return;
7007d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
7015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DisplayController* display_controller =
7025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      Shell::GetInstance()->display_controller();
703c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  DisplayManager* display_manager = Shell::GetInstance()->display_manager();
7045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  UpdateDisplay("200x200,300x300");
7065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  gfx::Display primary_display = Shell::GetScreen()->GetPrimaryDisplay();
7075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  gfx::Display secondary_display = ScreenUtil::GetSecondaryDisplay();
70858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
70958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  DisplayLayout display_layout(DisplayLayout::RIGHT, 50);
7108bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  display_manager->SetLayoutForCurrentDisplays(display_layout);
71158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
71258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_NE(primary_display.id(), secondary_display.id());
7131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  aura::Window* primary_root =
71458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      display_controller->GetRootWindowForDisplayId(primary_display.id());
7151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  aura::Window* secondary_root =
71658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      display_controller->GetRootWindowForDisplayId(secondary_display.id());
71758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_NE(primary_root, secondary_root);
7185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  aura::Window* shelf_window =
7195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      Shelf::ForPrimaryDisplay()->shelf_widget()->GetNativeView();
7205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_TRUE(primary_root->Contains(shelf_window));
7215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_FALSE(secondary_root->Contains(shelf_window));
72258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ(primary_display.id(),
72358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)            Shell::GetScreen()->GetDisplayNearestPoint(
72458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                gfx::Point(-100, -100)).id());
72558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ(primary_display.id(),
72658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)            Shell::GetScreen()->GetDisplayNearestWindow(NULL).id());
72758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
72858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ("0,0 200x200", primary_display.bounds().ToString());
72958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ("0,0 200x153", primary_display.work_area().ToString());
73058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ("200,0 300x300", secondary_display.bounds().ToString());
73158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ("200,0 300x253", secondary_display.work_area().ToString());
73258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ("right, 50",
73358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)            display_manager->GetCurrentDisplayLayout().ToString());
73458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
73558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Switch primary and secondary
73658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  display_controller->SetPrimaryDisplay(secondary_display);
73758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  const DisplayLayout& inverted_layout =
73858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      display_manager->GetCurrentDisplayLayout();
73958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ("left, -50", inverted_layout.ToString());
74058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
74158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ(secondary_display.id(),
74258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)            Shell::GetScreen()->GetPrimaryDisplay().id());
7435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(primary_display.id(), ScreenUtil::GetSecondaryDisplay().id());
7445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(primary_display.id(),
74558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)            Shell::GetScreen()->GetDisplayNearestPoint(
74658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                gfx::Point(-100, -100)).id());
74758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ(secondary_display.id(),
74858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)            Shell::GetScreen()->GetDisplayNearestWindow(NULL).id());
74958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
75058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ(
75158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      primary_root,
75258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      display_controller->GetRootWindowForDisplayId(secondary_display.id()));
75358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ(
75458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      secondary_root,
75558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      display_controller->GetRootWindowForDisplayId(primary_display.id()));
7565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_TRUE(primary_root->Contains(shelf_window));
7575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_FALSE(secondary_root->Contains(shelf_window));
75858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
75958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Test if the bounds are correctly swapped.
76058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  gfx::Display swapped_primary = Shell::GetScreen()->GetPrimaryDisplay();
7615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  gfx::Display swapped_secondary = ScreenUtil::GetSecondaryDisplay();
76258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ("0,0 300x300", swapped_primary.bounds().ToString());
76358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ("0,0 300x253", swapped_primary.work_area().ToString());
76458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ("-200,-50 200x200", swapped_secondary.bounds().ToString());
76558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
76658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ("-200,-50 200x153", swapped_secondary.work_area().ToString());
76758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
76858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  aura::WindowTracker tracker;
76958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  tracker.Add(primary_root);
77058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  tracker.Add(secondary_root);
77158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
77258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Deleting 2nd display should move the primary to original primary display.
77358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  UpdateDisplay("200x200");
77458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  RunAllPendingInMessageLoop();  // RootWindow is deleted in a posted task.
77558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ(1, Shell::GetScreen()->GetNumDisplays());
77658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ(primary_display.id(), Shell::GetScreen()->GetPrimaryDisplay().id());
77758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ(primary_display.id(),
77858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)            Shell::GetScreen()->GetDisplayNearestPoint(
77958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                gfx::Point(-100, -100)).id());
78058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ(primary_display.id(),
78158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)            Shell::GetScreen()->GetDisplayNearestWindow(NULL).id());
78258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_TRUE(tracker.Contains(primary_root));
78358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_FALSE(tracker.Contains(secondary_root));
7845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_TRUE(primary_root->Contains(shelf_window));
7855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
7865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(DisplayControllerTest, FindNearestDisplay) {
7885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!SupportsMultipleDisplays())
7895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
7905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DisplayController* display_controller =
7925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      Shell::GetInstance()->display_controller();
793c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  DisplayManager* display_manager = Shell::GetInstance()->display_manager();
7945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UpdateDisplay("200x200,300x300");
7965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DisplayLayout display_layout(DisplayLayout::RIGHT, 50);
7975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  display_manager->SetLayoutForCurrentDisplays(display_layout);
7985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  gfx::Display primary_display = Shell::GetScreen()->GetPrimaryDisplay();
8005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  gfx::Display secondary_display = ScreenUtil::GetSecondaryDisplay();
8015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_NE(primary_display.id(), secondary_display.id());
8025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  aura::Window* primary_root =
8035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      display_controller->GetRootWindowForDisplayId(primary_display.id());
8045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  aura::Window* secondary_root =
8055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      display_controller->GetRootWindowForDisplayId(secondary_display.id());
8065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_NE(primary_root, secondary_root);
8075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
8085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Test that points outside of any display return the nearest display.
8095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(primary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint(
8105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      gfx::Point(-100, 0)).id());
8115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(primary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint(
8125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      gfx::Point(0, -100)).id());
8135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(primary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint(
8145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      gfx::Point(100, 100)).id());
8155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(primary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint(
8165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      gfx::Point(224, 25)).id());
8175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(secondary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint(
8185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      gfx::Point(226, 25)).id());
8195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(secondary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint(
8205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      gfx::Point(600, 100)).id());
8215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(primary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint(
8225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      gfx::Point(174, 225)).id());
8235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(secondary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint(
8245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      gfx::Point(176, 225)).id());
8255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(secondary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint(
8265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      gfx::Point(300, 400)).id());
82758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)}
82858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
8297d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_F(DisplayControllerTest, SwapPrimaryById) {
8307d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (!SupportsMultipleDisplays())
8317d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    return;
8327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
8335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DisplayController* display_controller =
8345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      Shell::GetInstance()->display_controller();
835c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  DisplayManager* display_manager = Shell::GetInstance()->display_manager();
8365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  UpdateDisplay("200x200,300x300");
8385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  gfx::Display primary_display = Shell::GetScreen()->GetPrimaryDisplay();
8395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  gfx::Display secondary_display = ScreenUtil::GetSecondaryDisplay();
8405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DisplayLayout display_layout(DisplayLayout::RIGHT, 50);
8428bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  display_manager->SetLayoutForCurrentDisplays(display_layout);
8435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_NE(primary_display.id(), secondary_display.id());
8451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  aura::Window* primary_root =
8465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      display_controller->GetRootWindowForDisplayId(primary_display.id());
8471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  aura::Window* secondary_root =
8485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      display_controller->GetRootWindowForDisplayId(secondary_display.id());
8495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  aura::Window* shelf_window =
8505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      Shelf::ForPrimaryDisplay()->shelf_widget()->GetNativeView();
8515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_TRUE(primary_root->Contains(shelf_window));
8525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_FALSE(secondary_root->Contains(shelf_window));
8535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_NE(primary_root, secondary_root);
8545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(primary_display.id(),
8555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            Shell::GetScreen()->GetDisplayNearestPoint(
8565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                gfx::Point(-100, -100)).id());
8575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(primary_display.id(),
8585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            Shell::GetScreen()->GetDisplayNearestWindow(NULL).id());
8595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Switch primary and secondary by display ID.
8615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  TestObserver observer;
8625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  display_controller->SetPrimaryDisplayId(secondary_display.id());
8635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(secondary_display.id(),
8645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            Shell::GetScreen()->GetPrimaryDisplay().id());
8655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(primary_display.id(), ScreenUtil::GetSecondaryDisplay().id());
8665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_LT(0, observer.CountAndReset());
8675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(
8695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      primary_root,
8705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      display_controller->GetRootWindowForDisplayId(secondary_display.id()));
8715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(
8725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      secondary_root,
8735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      display_controller->GetRootWindowForDisplayId(primary_display.id()));
8745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_TRUE(primary_root->Contains(shelf_window));
8755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_FALSE(secondary_root->Contains(shelf_window));
8765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const DisplayLayout& inverted_layout =
8783551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      display_manager->GetCurrentDisplayLayout();
8795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("left, -50", inverted_layout.ToString());
8815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Calling the same ID don't do anything.
8835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  display_controller->SetPrimaryDisplayId(secondary_display.id());
8845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(0, observer.CountAndReset());
8855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  aura::WindowTracker tracker;
8875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  tracker.Add(primary_root);
8885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  tracker.Add(secondary_root);
8895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Deleting 2nd display should move the primary to original primary display.
8915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  UpdateDisplay("200x200");
8925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RunAllPendingInMessageLoop();  // RootWindow is deleted in a posted task.
8935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(1, Shell::GetScreen()->GetNumDisplays());
8945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(primary_display.id(), Shell::GetScreen()->GetPrimaryDisplay().id());
8955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(primary_display.id(),
8965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            Shell::GetScreen()->GetDisplayNearestPoint(
8975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                gfx::Point(-100, -100)).id());
8985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(primary_display.id(),
8995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            Shell::GetScreen()->GetDisplayNearestWindow(NULL).id());
9005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(tracker.Contains(primary_root));
9015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_FALSE(tracker.Contains(secondary_root));
9025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_TRUE(primary_root->Contains(shelf_window));
9035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Adding 2nd display with the same ID.  The 2nd display should become primary
9055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // since secondary id is still stored as desirable_primary_id.
906c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  std::vector<DisplayInfo> display_info_list;
9072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  display_info_list.push_back(
9082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      display_manager->GetDisplayInfo(primary_display.id()));
9092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  display_info_list.push_back(
9102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      display_manager->GetDisplayInfo(secondary_display.id()));
9112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  display_manager->OnNativeDisplaysChanged(display_info_list);
9125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(2, Shell::GetScreen()->GetNumDisplays());
9145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(secondary_display.id(),
9155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            Shell::GetScreen()->GetPrimaryDisplay().id());
9165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(primary_display.id(), ScreenUtil::GetSecondaryDisplay().id());
9175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(
9185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      primary_root,
9195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      display_controller->GetRootWindowForDisplayId(secondary_display.id()));
9205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_NE(
9215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      primary_root,
9225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      display_controller->GetRootWindowForDisplayId(primary_display.id()));
9235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_TRUE(primary_root->Contains(shelf_window));
9245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Deleting 2nd display and adding 2nd display with a different ID.  The 2nd
9265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // display shouldn't become primary.
9275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  UpdateDisplay("200x200");
928c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  DisplayInfo third_display_info(
9292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      secondary_display.id() + 1, std::string(), false);
9302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  third_display_info.SetBounds(secondary_display.bounds());
9312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ASSERT_NE(primary_display.id(), third_display_info.id());
9322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
933c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  const DisplayInfo& primary_display_info =
9342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      display_manager->GetDisplayInfo(primary_display.id());
935c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  std::vector<DisplayInfo> display_info_list2;
9362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  display_info_list2.push_back(primary_display_info);
9372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  display_info_list2.push_back(third_display_info);
9382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  display_manager->OnNativeDisplaysChanged(display_info_list2);
9395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(2, Shell::GetScreen()->GetNumDisplays());
9405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(primary_display.id(),
9415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            Shell::GetScreen()->GetPrimaryDisplay().id());
9425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(third_display_info.id(), ScreenUtil::GetSecondaryDisplay().id());
9435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(
9445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      primary_root,
9455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      display_controller->GetRootWindowForDisplayId(primary_display.id()));
9465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_NE(
9475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      primary_root,
9482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      display_controller->GetRootWindowForDisplayId(third_display_info.id()));
9495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_TRUE(primary_root->Contains(shelf_window));
9505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9527d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_F(DisplayControllerTest, CursorDeviceScaleFactorSwapPrimary) {
9537d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (!SupportsMultipleDisplays())
9547d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    return;
9557d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
9565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DisplayController* display_controller =
9575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      Shell::GetInstance()->display_controller();
9585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  UpdateDisplay("200x200,200x200*2");
9605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  gfx::Display primary_display = Shell::GetScreen()->GetPrimaryDisplay();
9615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  gfx::Display secondary_display = ScreenUtil::GetSecondaryDisplay();
9625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  aura::Window* primary_root =
9645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      display_controller->GetRootWindowForDisplayId(primary_display.id());
9651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  aura::Window* secondary_root =
9665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      display_controller->GetRootWindowForDisplayId(secondary_display.id());
9675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_NE(primary_root, secondary_root);
9685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  test::CursorManagerTestApi test_api(Shell::GetInstance()->cursor_manager());
9705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
971a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  EXPECT_EQ(1.0f, primary_root->GetHost()->compositor()->
9725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      device_scale_factor());
9735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  primary_root->MoveCursorTo(gfx::Point(50, 50));
9740529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor());
975a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  EXPECT_EQ(2.0f, secondary_root->GetHost()->compositor()->
9765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      device_scale_factor());
9775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  secondary_root->MoveCursorTo(gfx::Point(50, 50));
9780529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor());
9795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Switch primary and secondary
9815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  display_controller->SetPrimaryDisplay(secondary_display);
9825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Cursor's device scale factor should be updated accroding to the swap of
9845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // primary and secondary.
985a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  EXPECT_EQ(1.0f, secondary_root->GetHost()->compositor()->
9865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      device_scale_factor());
9875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  secondary_root->MoveCursorTo(gfx::Point(50, 50));
9880529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor());
9895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  primary_root->MoveCursorTo(gfx::Point(50, 50));
990a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  EXPECT_EQ(2.0f, primary_root->GetHost()->compositor()->
9915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      device_scale_factor());
9920529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor());
9935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Deleting 2nd display.
9955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  UpdateDisplay("200x200");
9965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RunAllPendingInMessageLoop();  // RootWindow is deleted in a posted task.
9975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Cursor's device scale factor should be updated even without moving cursor.
9990529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor());
10005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  primary_root->MoveCursorTo(gfx::Point(50, 50));
1002a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  EXPECT_EQ(1.0f, primary_root->GetHost()->compositor()->
10035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      device_scale_factor());
10040529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor());
10055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
10065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10077d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_F(DisplayControllerTest, OverscanInsets) {
10087d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (!SupportsMultipleDisplays())
10097d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    return;
10102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
10112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DisplayController* display_controller =
10122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      Shell::GetInstance()->display_controller();
10132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TestEventHandler event_handler;
10142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  Shell::GetInstance()->AddPreTargetHandler(&event_handler);
10152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
10162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  UpdateDisplay("120x200,300x400*2");
10172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  gfx::Display display1 = Shell::GetScreen()->GetPrimaryDisplay();
1018f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  aura::Window::Windows root_windows = Shell::GetAllRootWindows();
10192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
10202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  display_controller->SetOverscanInsets(display1.id(),
10212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                        gfx::Insets(10, 15, 20, 25));
10222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ("0,0 80x170", root_windows[0]->bounds().ToString());
10232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString());
10242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ("80,0 150x200",
10255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            ScreenUtil::GetSecondaryDisplay().bounds().ToString());
10262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
10275f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  ui::test::EventGenerator generator(root_windows[0]);
1028c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  generator.MoveMouseToInHost(20, 25);
10292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ("5,15", event_handler.GetLocationAndReset());
10302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1031eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  display_controller->SetOverscanInsets(display1.id(), gfx::Insets());
10322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ("0,0 120x200", root_windows[0]->bounds().ToString());
10332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ("120,0 150x200",
10345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            ScreenUtil::GetSecondaryDisplay().bounds().ToString());
10352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1036c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  generator.MoveMouseToInHost(30, 20);
10372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ("30,20", event_handler.GetLocationAndReset());
10382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1039eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Make sure the root window transformer uses correct scale
1040eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // factor when swapping display. Test crbug.com/253690.
1041eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  UpdateDisplay("400x300*2,600x400/o");
1042eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  root_windows = Shell::GetAllRootWindows();
1043eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  gfx::Point point;
1044a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  Shell::GetAllRootWindows()[1]->GetHost()->
1045f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      GetRootTransform().TransformPoint(&point);
1046eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ("15,10", point.ToString());
1047eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
1048eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  display_controller->SwapPrimaryDisplay();
1049eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  point.SetPoint(0, 0);
1050a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  Shell::GetAllRootWindows()[1]->GetHost()->
1051f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      GetRootTransform().TransformPoint(&point);
1052eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  EXPECT_EQ("15,10", point.ToString());
1053eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
10542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  Shell::GetInstance()->RemovePreTargetHandler(&event_handler);
10552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
10562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
10577d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_F(DisplayControllerTest, Rotate) {
10587d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (!SupportsMultipleDisplays())
10597d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    return;
10602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1061c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  DisplayManager* display_manager = Shell::GetInstance()->display_manager();
10622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TestEventHandler event_handler;
10632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  Shell::GetInstance()->AddPreTargetHandler(&event_handler);
10642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
10652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  UpdateDisplay("120x200,300x400*2");
10662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  gfx::Display display1 = Shell::GetScreen()->GetPrimaryDisplay();
10675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  int64 display2_id = ScreenUtil::GetSecondaryDisplay().id();
1068f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  aura::Window::Windows root_windows = Shell::GetAllRootWindows();
10695f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  ui::test::EventGenerator generator1(root_windows[0]);
10702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1071cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  TestObserver observer;
10722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString());
10732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString());
10742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ("120,0 150x200",
10755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            ScreenUtil::GetSecondaryDisplay().bounds().ToString());
1076c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  generator1.MoveMouseToInHost(50, 40);
10772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ("50,40", event_handler.GetLocationAndReset());
10782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display1.id()));
10792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display2_id));
1080cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_EQ(0, observer.GetRotationChangedCountAndReset());
10812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
10822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  display_manager->SetDisplayRotation(display1.id(),
10832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                      gfx::Display::ROTATE_90);
10842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString());
10852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString());
10862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ("200,0 150x200",
10875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            ScreenUtil::GetSecondaryDisplay().bounds().ToString());
1088c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  generator1.MoveMouseToInHost(50, 40);
10892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ("40,69", event_handler.GetLocationAndReset());
10902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(gfx::Display::ROTATE_90, GetStoredRotation(display1.id()));
10912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display2_id));
1092cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_EQ(1, observer.GetRotationChangedCountAndReset());
10932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
10942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DisplayLayout display_layout(DisplayLayout::BOTTOM, 50);
10958bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  display_manager->SetLayoutForCurrentDisplays(display_layout);
10962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ("50,120 150x200",
10975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            ScreenUtil::GetSecondaryDisplay().bounds().ToString());
10982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
10992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  display_manager->SetDisplayRotation(display2_id,
11002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                      gfx::Display::ROTATE_270);
11012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString());
11022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString());
11032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ("50,120 200x150",
11045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            ScreenUtil::GetSecondaryDisplay().bounds().ToString());
11052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(gfx::Display::ROTATE_90, GetStoredRotation(display1.id()));
11062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(gfx::Display::ROTATE_270, GetStoredRotation(display2_id));
1107cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_EQ(1, observer.GetRotationChangedCountAndReset());
11082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1109eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#if !defined(OS_WIN)
11105f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  ui::test::EventGenerator generator2(root_windows[1]);
1111c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  generator2.MoveMouseToInHost(50, 40);
11122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ("179,25", event_handler.GetLocationAndReset());
11132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  display_manager->SetDisplayRotation(display1.id(),
11142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                      gfx::Display::ROTATE_180);
11152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
11162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString());
11172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString());
11182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Dislay must share at least 100, so the x's offset becomes 20.
11192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ("20,200 200x150",
11205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            ScreenUtil::GetSecondaryDisplay().bounds().ToString());
11212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(gfx::Display::ROTATE_180, GetStoredRotation(display1.id()));
11222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(gfx::Display::ROTATE_270, GetStoredRotation(display2_id));
1123cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_EQ(1, observer.GetRotationChangedCountAndReset());
11242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1125c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  generator1.MoveMouseToInHost(50, 40);
11262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ("69,159", event_handler.GetLocationAndReset());
1127eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#endif
11282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
11292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  Shell::GetInstance()->RemovePreTargetHandler(&event_handler);
11302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
11312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
11327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_F(DisplayControllerTest, ScaleRootWindow) {
11337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (!SupportsMultipleDisplays())
11347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    return;
11357d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
11362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TestEventHandler event_handler;
11372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  Shell::GetInstance()->AddPreTargetHandler(&event_handler);
11382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
11392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  UpdateDisplay("600x400*2@1.5,500x300");
11402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
11412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  gfx::Display display1 = Shell::GetScreen()->GetPrimaryDisplay();
1142c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  gfx::Display::SetInternalDisplayId(display1.id());
1143c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
11445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  gfx::Display display2 = ScreenUtil::GetSecondaryDisplay();
1145f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  aura::Window::Windows root_windows = Shell::GetAllRootWindows();
11462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ("0,0 450x300", display1.bounds().ToString());
11472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ("0,0 450x300", root_windows[0]->bounds().ToString());
11482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ("450,0 500x300", display2.bounds().ToString());
11492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(1.5f, GetStoredUIScale(display1.id()));
11502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(1.0f, GetStoredUIScale(display2.id()));
11512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
11525f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  ui::test::EventGenerator generator(root_windows[0]);
1153c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  generator.MoveMouseToInHost(599, 200);
11542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ("449,150", event_handler.GetLocationAndReset());
11552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1156c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  DisplayManager* display_manager = Shell::GetInstance()->display_manager();
1157c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  display_manager->SetDisplayUIScale(display1.id(), 1.25f);
11582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  display1 = Shell::GetScreen()->GetPrimaryDisplay();
11595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  display2 = ScreenUtil::GetSecondaryDisplay();
11602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ("0,0 375x250", display1.bounds().ToString());
11612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ("0,0 375x250", root_windows[0]->bounds().ToString());
11622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ("375,0 500x300", display2.bounds().ToString());
11632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(1.25f, GetStoredUIScale(display1.id()));
11642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(1.0f, GetStoredUIScale(display2.id()));
11652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
11662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  Shell::GetInstance()->RemovePreTargetHandler(&event_handler);
11672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
11682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
11697d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_F(DisplayControllerTest, TouchScale) {
11707d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (!SupportsMultipleDisplays())
11717d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    return;
11727d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
1173c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  TestEventHandler event_handler;
1174c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  Shell::GetInstance()->AddPreTargetHandler(&event_handler);
1175c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1176c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  UpdateDisplay("200x200*2");
1177c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  gfx::Display display = Shell::GetScreen()->GetPrimaryDisplay();
1178f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  aura::Window::Windows root_windows = Shell::GetAllRootWindows();
1179f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  aura::Window* root_window = root_windows[0];
11805f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  ui::test::EventGenerator generator(root_window);
1181c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1182c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  generator.PressMoveAndReleaseTouchTo(50, 50);
1183c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Default test touches have radius_x/y = 1.0, with device scale
1184c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // factor = 2, the scaled radius_x/y should be 0.5.
1185c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(0.5, event_handler.touch_radius_x());
1186c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(0.5, event_handler.touch_radius_y());
1187c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1188c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  generator.ScrollSequence(gfx::Point(0,0),
1189c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                           base::TimeDelta::FromMilliseconds(100),
1190c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                           10.0, 1.0, 5, 1);
1191c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
11924e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // ordinal_offset is invariant to the device scale factor.
1193c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(event_handler.scroll_x_offset(),
11944e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)            event_handler.scroll_x_offset_ordinal());
1195c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(event_handler.scroll_y_offset(),
11964e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)            event_handler.scroll_y_offset_ordinal());
1197c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1198c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  Shell::GetInstance()->RemovePreTargetHandler(&event_handler);
1199c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
1200c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
12017d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_F(DisplayControllerTest, ConvertHostToRootCoords) {
12027d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (!SupportsMultipleDisplays())
12037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    return;
12047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
1205c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  TestEventHandler event_handler;
1206c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  Shell::GetInstance()->AddPreTargetHandler(&event_handler);
1207c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1208c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  UpdateDisplay("600x400*2/r@1.5");
1209c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1210c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  gfx::Display display1 = Shell::GetScreen()->GetPrimaryDisplay();
1211f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  aura::Window::Windows root_windows = Shell::GetAllRootWindows();
1212c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ("0,0 300x450", display1.bounds().ToString());
1213c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ("0,0 300x450", root_windows[0]->bounds().ToString());
1214c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(1.5f, GetStoredUIScale(display1.id()));
1215c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
12165f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  ui::test::EventGenerator generator(root_windows[0]);
1217c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  generator.MoveMouseToInHost(0, 0);
1218c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ("0,449", event_handler.GetLocationAndReset());
1219c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  generator.MoveMouseToInHost(599, 0);
1220c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ("0,0", event_handler.GetLocationAndReset());
1221c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  generator.MoveMouseToInHost(599, 399);
1222c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ("299,0", event_handler.GetLocationAndReset());
1223c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  generator.MoveMouseToInHost(0, 399);
1224c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ("299,449", event_handler.GetLocationAndReset());
1225c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1226c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  UpdateDisplay("600x400*2/u@1.5");
1227c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  display1 = Shell::GetScreen()->GetPrimaryDisplay();
1228c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  root_windows = Shell::GetAllRootWindows();
1229c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ("0,0 450x300", display1.bounds().ToString());
1230c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ("0,0 450x300", root_windows[0]->bounds().ToString());
1231c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(1.5f, GetStoredUIScale(display1.id()));
1232c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1233c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  generator.MoveMouseToInHost(0, 0);
1234c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ("449,299", event_handler.GetLocationAndReset());
1235c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  generator.MoveMouseToInHost(599, 0);
1236c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ("0,299", event_handler.GetLocationAndReset());
1237c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  generator.MoveMouseToInHost(599, 399);
1238c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ("0,0", event_handler.GetLocationAndReset());
1239c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  generator.MoveMouseToInHost(0, 399);
1240c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ("449,0", event_handler.GetLocationAndReset());
1241c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1242c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  UpdateDisplay("600x400*2/l@1.5");
1243c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  display1 = Shell::GetScreen()->GetPrimaryDisplay();
1244c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  root_windows = Shell::GetAllRootWindows();
1245c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ("0,0 300x450", display1.bounds().ToString());
1246c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ("0,0 300x450", root_windows[0]->bounds().ToString());
1247c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(1.5f, GetStoredUIScale(display1.id()));
1248c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1249c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  generator.MoveMouseToInHost(0, 0);
1250c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ("299,0", event_handler.GetLocationAndReset());
1251c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  generator.MoveMouseToInHost(599, 0);
1252c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ("299,449", event_handler.GetLocationAndReset());
1253c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  generator.MoveMouseToInHost(599, 399);
1254c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ("0,449", event_handler.GetLocationAndReset());
1255c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  generator.MoveMouseToInHost(0, 399);
1256c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ("0,0", event_handler.GetLocationAndReset());
1257c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1258c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  Shell::GetInstance()->RemovePreTargetHandler(&event_handler);
1259c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
1260c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1261f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)namespace {
1262f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1263c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen MurdochDisplayInfo CreateDisplayInfo(int64 id,
1264c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch                              int y,
1265c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch                              gfx::Display::Rotation rotation) {
1266c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  DisplayInfo info(id, "", false);
1267f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  info.SetBounds(gfx::Rect(0, y, 500, 500));
1268f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  info.set_rotation(rotation);
1269f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  return info;
1270f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
1271f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1272f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}  // namespace
1273f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1274f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Make sure that the compositor based mirroring can switch
1275f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// from/to dock mode.
1276f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)TEST_F(DisplayControllerTest, DockToSingle) {
1277f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  if (!SupportsMultipleDisplays())
1278f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    return;
1279f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1280c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  DisplayManager* display_manager = Shell::GetInstance()->display_manager();
1281f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1282f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  const int64 internal_id = 1;
1283f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1284c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  const DisplayInfo internal_display_info =
1285f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      CreateDisplayInfo(internal_id, 0, gfx::Display::ROTATE_0);
1286c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  const DisplayInfo external_display_info =
1287f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      CreateDisplayInfo(2, 1, gfx::Display::ROTATE_90);
1288f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1289c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  std::vector<DisplayInfo> display_info_list;
1290f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Extended
1291f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  display_info_list.push_back(internal_display_info);
1292f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  display_info_list.push_back(external_display_info);
1293f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  display_manager->OnNativeDisplaysChanged(display_info_list);
1294f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  const int64 internal_display_id =
1295f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      test::DisplayManagerTestApi(display_manager).
1296f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      SetFirstDisplayAsInternalDisplay();
1297f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(internal_id, internal_display_id);
1298f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(2U, display_manager->GetNumDisplays());
1299f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1300f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Dock mode.
1301f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  display_info_list.clear();
1302f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  display_info_list.push_back(external_display_info);
1303f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  display_manager->OnNativeDisplaysChanged(display_info_list);
1304f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(1U, display_manager->GetNumDisplays());
1305a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  EXPECT_FALSE(Shell::GetPrimaryRootWindow()->GetHost()->
1306f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)               GetRootTransform().IsIdentityOrIntegerTranslation());
1307f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1308f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Switch to single mode and make sure the transform is the one
1309f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // for the internal display.
1310f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  display_info_list.clear();
1311f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  display_info_list.push_back(internal_display_info);
1312f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  display_manager->OnNativeDisplaysChanged(display_info_list);
1313a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  EXPECT_TRUE(Shell::GetPrimaryRootWindow()->GetHost()->
1314f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)              GetRootTransform().IsIdentityOrIntegerTranslation());
1315f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
1316f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1317eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#if defined(USE_X11)
1318eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTEST_F(DisplayControllerTest, XWidowNameForRootWindow) {
13191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EXPECT_EQ("aura_root_0", GetXWindowName(
1320a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      Shell::GetPrimaryRootWindow()->GetHost()));
1321eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
1322eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Multiple display.
1323eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  UpdateDisplay("200x200,300x300");
13241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  aura::Window* primary, *secondary;
1325eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  GetPrimaryAndSeconary(&primary, &secondary);
1326a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  EXPECT_EQ("aura_root_0", GetXWindowName(primary->GetHost()));
1327a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  EXPECT_EQ("aura_root_x", GetXWindowName(secondary->GetHost()));
1328eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
1329eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Swap primary.
1330eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  primary = secondary = NULL;
1331eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  Shell::GetInstance()->display_controller()->SwapPrimaryDisplay();
1332eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  GetPrimaryAndSeconary(&primary, &secondary);
1333a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  EXPECT_EQ("aura_root_0", GetXWindowName(primary->GetHost()));
1334a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  EXPECT_EQ("aura_root_x", GetXWindowName(secondary->GetHost()));
1335eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
1336eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Switching back to single display.
1337eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  UpdateDisplay("300x400");
13381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EXPECT_EQ("aura_root_0", GetXWindowName(
1339a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      Shell::GetPrimaryRootWindow()->GetHost()));
1340eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch}
1341eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#endif
1342eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
13435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace ash
1344