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)
2411320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  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");
6581320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // We still call into Pre/PostDisplayConfigurationChange().
6591320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  EXPECT_EQ(1, observer.CountAndReset());
660d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
661d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
6622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Rotation
664cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  observer.GetRotationChangedCountAndReset();  // we only want to reset.
6652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int64 primary_id = GetPrimaryDisplay().id();
6662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  display_manager->SetDisplayRotation(primary_id, gfx::Display::ROTATE_90);
667cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_EQ(1, observer.GetRotationChangedCountAndReset());
6682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(1, observer.CountAndReset());
669d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
670d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
6712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  display_manager->SetDisplayRotation(primary_id, gfx::Display::ROTATE_90);
672cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_EQ(0, observer.GetRotationChangedCountAndReset());
6732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(0, observer.CountAndReset());
674d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
675d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
6762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
677c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // UI scale is eanbled only on internal display.
6782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int64 secondary_id = GetSecondaryDisplay().id();
6792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  gfx::Display::SetInternalDisplayId(secondary_id);
680c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  display_manager->SetDisplayUIScale(secondary_id, 1.125f);
6812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(1, observer.CountAndReset());
682d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
683d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
684c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  display_manager->SetDisplayUIScale(secondary_id, 1.125f);
685c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(0, observer.CountAndReset());
686d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
687d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
688c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  display_manager->SetDisplayUIScale(primary_id, 1.125f);
689c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_EQ(0, observer.CountAndReset());
690d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
691d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
692c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  display_manager->SetDisplayUIScale(primary_id, 1.125f);
6932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(0, observer.CountAndReset());
694d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetFocusChangedCountAndReset());
695d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(0, observer.GetActivationChangedCountAndReset());
6962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
6972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6987d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_F(DisplayControllerTest, SwapPrimary) {
6997d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (!SupportsMultipleDisplays())
7007d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    return;
7017d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
7025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DisplayController* display_controller =
7035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      Shell::GetInstance()->display_controller();
704c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  DisplayManager* display_manager = Shell::GetInstance()->display_manager();
7055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  UpdateDisplay("200x200,300x300");
7075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  gfx::Display primary_display = Shell::GetScreen()->GetPrimaryDisplay();
7085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  gfx::Display secondary_display = ScreenUtil::GetSecondaryDisplay();
70958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
71058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  DisplayLayout display_layout(DisplayLayout::RIGHT, 50);
7118bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  display_manager->SetLayoutForCurrentDisplays(display_layout);
71258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
71358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_NE(primary_display.id(), secondary_display.id());
7141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  aura::Window* primary_root =
71558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      display_controller->GetRootWindowForDisplayId(primary_display.id());
7161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  aura::Window* secondary_root =
71758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      display_controller->GetRootWindowForDisplayId(secondary_display.id());
71858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_NE(primary_root, secondary_root);
7195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  aura::Window* shelf_window =
7205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      Shelf::ForPrimaryDisplay()->shelf_widget()->GetNativeView();
7215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_TRUE(primary_root->Contains(shelf_window));
7225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_FALSE(secondary_root->Contains(shelf_window));
72358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ(primary_display.id(),
72458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)            Shell::GetScreen()->GetDisplayNearestPoint(
72558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                gfx::Point(-100, -100)).id());
72658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ(primary_display.id(),
72758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)            Shell::GetScreen()->GetDisplayNearestWindow(NULL).id());
72858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
72958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ("0,0 200x200", primary_display.bounds().ToString());
73058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ("0,0 200x153", primary_display.work_area().ToString());
73158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ("200,0 300x300", secondary_display.bounds().ToString());
73258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ("200,0 300x253", secondary_display.work_area().ToString());
73358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ("right, 50",
73458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)            display_manager->GetCurrentDisplayLayout().ToString());
73558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
73658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Switch primary and secondary
73758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  display_controller->SetPrimaryDisplay(secondary_display);
73858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  const DisplayLayout& inverted_layout =
73958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      display_manager->GetCurrentDisplayLayout();
74058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ("left, -50", inverted_layout.ToString());
74158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
74258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ(secondary_display.id(),
74358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)            Shell::GetScreen()->GetPrimaryDisplay().id());
7445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(primary_display.id(), ScreenUtil::GetSecondaryDisplay().id());
7455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(primary_display.id(),
74658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)            Shell::GetScreen()->GetDisplayNearestPoint(
74758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                gfx::Point(-100, -100)).id());
74858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ(secondary_display.id(),
74958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)            Shell::GetScreen()->GetDisplayNearestWindow(NULL).id());
75058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
75158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ(
75258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      primary_root,
75358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      display_controller->GetRootWindowForDisplayId(secondary_display.id()));
75458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ(
75558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      secondary_root,
75658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      display_controller->GetRootWindowForDisplayId(primary_display.id()));
7575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_TRUE(primary_root->Contains(shelf_window));
7585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_FALSE(secondary_root->Contains(shelf_window));
75958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
76058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Test if the bounds are correctly swapped.
76158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  gfx::Display swapped_primary = Shell::GetScreen()->GetPrimaryDisplay();
7625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  gfx::Display swapped_secondary = ScreenUtil::GetSecondaryDisplay();
76358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ("0,0 300x300", swapped_primary.bounds().ToString());
76458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ("0,0 300x253", swapped_primary.work_area().ToString());
76558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ("-200,-50 200x200", swapped_secondary.bounds().ToString());
76658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
76758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ("-200,-50 200x153", swapped_secondary.work_area().ToString());
76858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
76958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  aura::WindowTracker tracker;
77058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  tracker.Add(primary_root);
77158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  tracker.Add(secondary_root);
77258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
77358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Deleting 2nd display should move the primary to original primary display.
77458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  UpdateDisplay("200x200");
77558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  RunAllPendingInMessageLoop();  // RootWindow is deleted in a posted task.
77658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ(1, Shell::GetScreen()->GetNumDisplays());
77758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ(primary_display.id(), Shell::GetScreen()->GetPrimaryDisplay().id());
77858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ(primary_display.id(),
77958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)            Shell::GetScreen()->GetDisplayNearestPoint(
78058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                gfx::Point(-100, -100)).id());
78158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_EQ(primary_display.id(),
78258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)            Shell::GetScreen()->GetDisplayNearestWindow(NULL).id());
78358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_TRUE(tracker.Contains(primary_root));
78458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  EXPECT_FALSE(tracker.Contains(secondary_root));
7855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_TRUE(primary_root->Contains(shelf_window));
7865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
7875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(DisplayControllerTest, FindNearestDisplay) {
7895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!SupportsMultipleDisplays())
7905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
7915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DisplayController* display_controller =
7935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      Shell::GetInstance()->display_controller();
794c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  DisplayManager* display_manager = Shell::GetInstance()->display_manager();
7955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UpdateDisplay("200x200,300x300");
7975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DisplayLayout display_layout(DisplayLayout::RIGHT, 50);
7985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  display_manager->SetLayoutForCurrentDisplays(display_layout);
7995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
8005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  gfx::Display primary_display = Shell::GetScreen()->GetPrimaryDisplay();
8015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  gfx::Display secondary_display = ScreenUtil::GetSecondaryDisplay();
8025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_NE(primary_display.id(), secondary_display.id());
8035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  aura::Window* primary_root =
8045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      display_controller->GetRootWindowForDisplayId(primary_display.id());
8055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  aura::Window* secondary_root =
8065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      display_controller->GetRootWindowForDisplayId(secondary_display.id());
8075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_NE(primary_root, secondary_root);
8085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
8095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Test that points outside of any display return the nearest display.
8105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(primary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint(
8115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      gfx::Point(-100, 0)).id());
8125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(primary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint(
8135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      gfx::Point(0, -100)).id());
8145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(primary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint(
8155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      gfx::Point(100, 100)).id());
8165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(primary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint(
8175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      gfx::Point(224, 25)).id());
8185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(secondary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint(
8195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      gfx::Point(226, 25)).id());
8205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(secondary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint(
8215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      gfx::Point(600, 100)).id());
8225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(primary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint(
8235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      gfx::Point(174, 225)).id());
8245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(secondary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint(
8255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      gfx::Point(176, 225)).id());
8265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(secondary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint(
8275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      gfx::Point(300, 400)).id());
82858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)}
82958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
8307d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_F(DisplayControllerTest, SwapPrimaryById) {
8317d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (!SupportsMultipleDisplays())
8327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    return;
8337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
8345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DisplayController* display_controller =
8355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      Shell::GetInstance()->display_controller();
836c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  DisplayManager* display_manager = Shell::GetInstance()->display_manager();
8375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  UpdateDisplay("200x200,300x300");
8395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  gfx::Display primary_display = Shell::GetScreen()->GetPrimaryDisplay();
8405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  gfx::Display secondary_display = ScreenUtil::GetSecondaryDisplay();
8415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DisplayLayout display_layout(DisplayLayout::RIGHT, 50);
8438bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  display_manager->SetLayoutForCurrentDisplays(display_layout);
8445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_NE(primary_display.id(), secondary_display.id());
8461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  aura::Window* primary_root =
8475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      display_controller->GetRootWindowForDisplayId(primary_display.id());
8481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  aura::Window* secondary_root =
8495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      display_controller->GetRootWindowForDisplayId(secondary_display.id());
8505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  aura::Window* shelf_window =
8515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      Shelf::ForPrimaryDisplay()->shelf_widget()->GetNativeView();
8525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_TRUE(primary_root->Contains(shelf_window));
8535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_FALSE(secondary_root->Contains(shelf_window));
8545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_NE(primary_root, secondary_root);
8555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(primary_display.id(),
8565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            Shell::GetScreen()->GetDisplayNearestPoint(
8575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                gfx::Point(-100, -100)).id());
8585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(primary_display.id(),
8595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            Shell::GetScreen()->GetDisplayNearestWindow(NULL).id());
8605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Switch primary and secondary by display ID.
8625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  TestObserver observer;
8635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  display_controller->SetPrimaryDisplayId(secondary_display.id());
8645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(secondary_display.id(),
8655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            Shell::GetScreen()->GetPrimaryDisplay().id());
8665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(primary_display.id(), ScreenUtil::GetSecondaryDisplay().id());
8675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_LT(0, observer.CountAndReset());
8685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(
8705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      primary_root,
8715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      display_controller->GetRootWindowForDisplayId(secondary_display.id()));
8725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(
8735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      secondary_root,
8745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      display_controller->GetRootWindowForDisplayId(primary_display.id()));
8755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_TRUE(primary_root->Contains(shelf_window));
8765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_FALSE(secondary_root->Contains(shelf_window));
8775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const DisplayLayout& inverted_layout =
8793551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      display_manager->GetCurrentDisplayLayout();
8805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("left, -50", inverted_layout.ToString());
8825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Calling the same ID don't do anything.
8845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  display_controller->SetPrimaryDisplayId(secondary_display.id());
8855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(0, observer.CountAndReset());
8865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  aura::WindowTracker tracker;
8885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  tracker.Add(primary_root);
8895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  tracker.Add(secondary_root);
8905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Deleting 2nd display should move the primary to original primary display.
8925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  UpdateDisplay("200x200");
8935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RunAllPendingInMessageLoop();  // RootWindow is deleted in a posted task.
8945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(1, Shell::GetScreen()->GetNumDisplays());
8955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(primary_display.id(), Shell::GetScreen()->GetPrimaryDisplay().id());
8965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(primary_display.id(),
8975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            Shell::GetScreen()->GetDisplayNearestPoint(
8985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                gfx::Point(-100, -100)).id());
8995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(primary_display.id(),
9005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            Shell::GetScreen()->GetDisplayNearestWindow(NULL).id());
9015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(tracker.Contains(primary_root));
9025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_FALSE(tracker.Contains(secondary_root));
9035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_TRUE(primary_root->Contains(shelf_window));
9045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Adding 2nd display with the same ID.  The 2nd display should become primary
9065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // since secondary id is still stored as desirable_primary_id.
907c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  std::vector<DisplayInfo> display_info_list;
9082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  display_info_list.push_back(
9092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      display_manager->GetDisplayInfo(primary_display.id()));
9102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  display_info_list.push_back(
9112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      display_manager->GetDisplayInfo(secondary_display.id()));
9122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  display_manager->OnNativeDisplaysChanged(display_info_list);
9135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(2, Shell::GetScreen()->GetNumDisplays());
9155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(secondary_display.id(),
9165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            Shell::GetScreen()->GetPrimaryDisplay().id());
9175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(primary_display.id(), ScreenUtil::GetSecondaryDisplay().id());
9185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(
9195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      primary_root,
9205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      display_controller->GetRootWindowForDisplayId(secondary_display.id()));
9215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_NE(
9225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      primary_root,
9235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      display_controller->GetRootWindowForDisplayId(primary_display.id()));
9245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_TRUE(primary_root->Contains(shelf_window));
9255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Deleting 2nd display and adding 2nd display with a different ID.  The 2nd
9275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // display shouldn't become primary.
9285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  UpdateDisplay("200x200");
929c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  DisplayInfo third_display_info(
9302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      secondary_display.id() + 1, std::string(), false);
9312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  third_display_info.SetBounds(secondary_display.bounds());
9322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ASSERT_NE(primary_display.id(), third_display_info.id());
9332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
934