OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/display/display_controller.h" | 5 #include "ash/display/display_controller.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/display/display_info.h" | 8 #include "ash/display/display_info.h" |
9 #include "ash/display/display_layout_store.h" | 9 #include "ash/display/display_layout_store.h" |
10 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 60 |
61 class TestObserver : public DisplayController::Observer, | 61 class TestObserver : public DisplayController::Observer, |
62 public gfx::DisplayObserver, | 62 public gfx::DisplayObserver, |
63 public aura::client::FocusChangeObserver, | 63 public aura::client::FocusChangeObserver, |
64 public aura::client::ActivationChangeObserver { | 64 public aura::client::ActivationChangeObserver { |
65 public: | 65 public: |
66 TestObserver() | 66 TestObserver() |
67 : changing_count_(0), | 67 : changing_count_(0), |
68 changed_count_(0), | 68 changed_count_(0), |
69 bounds_changed_count_(0), | 69 bounds_changed_count_(0), |
70 rotation_changed_count_(0), | |
71 workarea_changed_count_(0), | |
72 changed_display_id_(0), | 70 changed_display_id_(0), |
73 focus_changed_count_(0), | 71 focus_changed_count_(0), |
74 activation_changed_count_(0) { | 72 activation_changed_count_(0) { |
75 Shell::GetInstance()->display_controller()->AddObserver(this); | 73 Shell::GetInstance()->display_controller()->AddObserver(this); |
76 Shell::GetScreen()->AddObserver(this); | 74 Shell::GetScreen()->AddObserver(this); |
77 aura::client::GetFocusClient(Shell::GetPrimaryRootWindow())-> | 75 aura::client::GetFocusClient(Shell::GetPrimaryRootWindow())-> |
78 AddObserver(this); | 76 AddObserver(this); |
79 aura::client::GetActivationClient(Shell::GetPrimaryRootWindow())-> | 77 aura::client::GetActivationClient(Shell::GetPrimaryRootWindow())-> |
80 AddObserver(this); | 78 AddObserver(this); |
81 } | 79 } |
82 | 80 |
83 virtual ~TestObserver() { | 81 virtual ~TestObserver() { |
84 Shell::GetInstance()->display_controller()->RemoveObserver(this); | 82 Shell::GetInstance()->display_controller()->RemoveObserver(this); |
85 Shell::GetScreen()->RemoveObserver(this); | 83 Shell::GetScreen()->RemoveObserver(this); |
86 aura::client::GetFocusClient(Shell::GetPrimaryRootWindow())-> | 84 aura::client::GetFocusClient(Shell::GetPrimaryRootWindow())-> |
87 RemoveObserver(this); | 85 RemoveObserver(this); |
88 aura::client::GetActivationClient(Shell::GetPrimaryRootWindow())-> | 86 aura::client::GetActivationClient(Shell::GetPrimaryRootWindow())-> |
89 RemoveObserver(this); | 87 RemoveObserver(this); |
90 } | 88 } |
91 | 89 |
92 // Overridden from DisplayController::Observer | 90 // Overridden from DisplayController::Observer |
93 virtual void OnDisplayConfigurationChanging() OVERRIDE { | 91 virtual void OnDisplayConfigurationChanging() OVERRIDE { |
94 ++changing_count_; | 92 ++changing_count_; |
95 } | 93 } |
96 virtual void OnDisplayConfigurationChanged() OVERRIDE { | 94 virtual void OnDisplayConfigurationChanged() OVERRIDE { |
97 ++changed_count_; | 95 ++changed_count_; |
98 } | 96 } |
99 | 97 |
100 // Overrideen from gfx::DisplayObserver | 98 // Overrideen from gfx::DisplayObserver |
101 virtual void OnDisplayMetricsChanged(const gfx::Display& display, | 99 virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE { |
102 uint32_t metrics) OVERRIDE { | |
103 changed_display_id_ = display.id(); | 100 changed_display_id_ = display.id(); |
104 if (metrics & DISPLAY_METRIC_BOUNDS) | 101 bounds_changed_count_ ++; |
105 ++bounds_changed_count_; | |
106 if (metrics & DISPLAY_METRIC_ROTATION) | |
107 ++rotation_changed_count_; | |
108 if (metrics & DISPLAY_METRIC_WORK_AREA) | |
109 ++workarea_changed_count_; | |
110 } | 102 } |
111 virtual void OnDisplayAdded(const gfx::Display& new_display) OVERRIDE { | 103 virtual void OnDisplayAdded(const gfx::Display& new_display) OVERRIDE { |
112 } | 104 } |
113 virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE { | 105 virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE { |
114 } | 106 } |
115 | 107 |
116 // Overridden from aura::client::FocusChangeObserver | 108 // Overridden from aura::client::FocusChangeObserver |
117 virtual void OnWindowFocused(aura::Window* gained_focus, | 109 virtual void OnWindowFocused(aura::Window* gained_focus, |
118 aura::Window* lost_focus) OVERRIDE { | 110 aura::Window* lost_focus) OVERRIDE { |
119 focus_changed_count_++; | 111 focus_changed_count_++; |
(...skipping 12 matching lines...) Expand all Loading... |
132 int CountAndReset() { | 124 int CountAndReset() { |
133 EXPECT_EQ(changing_count_, changed_count_); | 125 EXPECT_EQ(changing_count_, changed_count_); |
134 changed_count_ = 0; | 126 changed_count_ = 0; |
135 return Resetter<int>(&changing_count_).value(); | 127 return Resetter<int>(&changing_count_).value(); |
136 } | 128 } |
137 | 129 |
138 int64 GetBoundsChangedCountAndReset() { | 130 int64 GetBoundsChangedCountAndReset() { |
139 return Resetter<int>(&bounds_changed_count_).value(); | 131 return Resetter<int>(&bounds_changed_count_).value(); |
140 } | 132 } |
141 | 133 |
142 int64 GetRotationChangedCountAndReset() { | |
143 return Resetter<int>(&rotation_changed_count_).value(); | |
144 } | |
145 | |
146 int64 GetWorkareaChangedCountAndReset() { | |
147 return Resetter<int>(&workarea_changed_count_).value(); | |
148 } | |
149 | |
150 int64 GetChangedDisplayIdAndReset() { | 134 int64 GetChangedDisplayIdAndReset() { |
151 return Resetter<int64>(&changed_display_id_).value(); | 135 return Resetter<int64>(&changed_display_id_).value(); |
152 } | 136 } |
153 | 137 |
154 int GetFocusChangedCountAndReset() { | 138 int GetFocusChangedCountAndReset() { |
155 return Resetter<int>(&focus_changed_count_).value(); | 139 return Resetter<int>(&focus_changed_count_).value(); |
156 } | 140 } |
157 | 141 |
158 int GetActivationChangedCountAndReset() { | 142 int GetActivationChangedCountAndReset() { |
159 return Resetter<int>(&activation_changed_count_).value(); | 143 return Resetter<int>(&activation_changed_count_).value(); |
160 } | 144 } |
161 | 145 |
162 private: | 146 private: |
163 int changing_count_; | 147 int changing_count_; |
164 int changed_count_; | 148 int changed_count_; |
165 | 149 |
166 int bounds_changed_count_; | 150 int bounds_changed_count_; |
167 int rotation_changed_count_; | |
168 int workarea_changed_count_; | |
169 int64 changed_display_id_; | 151 int64 changed_display_id_; |
170 | 152 |
171 int focus_changed_count_; | 153 int focus_changed_count_; |
172 int activation_changed_count_; | 154 int activation_changed_count_; |
173 | 155 |
174 DISALLOW_COPY_AND_ASSIGN(TestObserver); | 156 DISALLOW_COPY_AND_ASSIGN(TestObserver); |
175 }; | 157 }; |
176 | 158 |
177 gfx::Display GetPrimaryDisplay() { | 159 gfx::Display GetPrimaryDisplay() { |
178 return Shell::GetScreen()->GetDisplayNearestWindow( | 160 return Shell::GetScreen()->GetDisplayNearestWindow( |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 return; | 380 return; |
399 | 381 |
400 // Creates windows to catch activation change event. | 382 // Creates windows to catch activation change event. |
401 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithId(1)); | 383 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithId(1)); |
402 w1->Focus(); | 384 w1->Focus(); |
403 | 385 |
404 TestObserver observer; | 386 TestObserver observer; |
405 UpdateDisplay("500x500,400x400"); | 387 UpdateDisplay("500x500,400x400"); |
406 EXPECT_EQ(1, observer.CountAndReset()); // resize and add | 388 EXPECT_EQ(1, observer.CountAndReset()); // resize and add |
407 EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); | 389 EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); |
408 EXPECT_EQ(1, observer.GetWorkareaChangedCountAndReset()); | |
409 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); | 390 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); |
410 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); | 391 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); |
411 gfx::Insets insets(5, 5, 5, 5); | 392 gfx::Insets insets(5, 5, 5, 5); |
412 int64 secondary_display_id = ScreenUtil::GetSecondaryDisplay().id(); | 393 int64 secondary_display_id = ScreenUtil::GetSecondaryDisplay().id(); |
413 Shell::GetInstance()->display_manager()->UpdateWorkAreaOfDisplay( | 394 Shell::GetInstance()->display_manager()->UpdateWorkAreaOfDisplay( |
414 secondary_display_id, insets); | 395 secondary_display_id, insets); |
415 | 396 |
416 // Default layout is RIGHT. | 397 // Default layout is RIGHT. |
417 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); | 398 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
418 EXPECT_EQ("500,0 400x400", GetSecondaryDisplay().bounds().ToString()); | 399 EXPECT_EQ("500,0 400x400", GetSecondaryDisplay().bounds().ToString()); |
419 EXPECT_EQ("505,5 390x390", GetSecondaryDisplay().work_area().ToString()); | 400 EXPECT_EQ("505,5 390x390", GetSecondaryDisplay().work_area().ToString()); |
420 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); | 401 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); |
421 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); | 402 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); |
422 | 403 |
423 // Layout the secondary display to the bottom of the primary. | 404 // Layout the secondary display to the bottom of the primary. |
424 SetSecondaryDisplayLayout(DisplayLayout::BOTTOM); | 405 SetSecondaryDisplayLayout(DisplayLayout::BOTTOM); |
425 EXPECT_EQ(1, observer.CountAndReset()); | 406 EXPECT_EQ(1, observer.CountAndReset()); |
426 EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); | 407 EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); |
427 EXPECT_EQ(1, observer.GetWorkareaChangedCountAndReset()); | |
428 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); | 408 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); |
429 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); | 409 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); |
430 EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset()); | 410 EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset()); |
431 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); | 411 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
432 EXPECT_EQ("0,500 400x400", GetSecondaryDisplay().bounds().ToString()); | 412 EXPECT_EQ("0,500 400x400", GetSecondaryDisplay().bounds().ToString()); |
433 EXPECT_EQ("5,505 390x390", GetSecondaryDisplay().work_area().ToString()); | 413 EXPECT_EQ("5,505 390x390", GetSecondaryDisplay().work_area().ToString()); |
434 | 414 |
435 // Layout the secondary display to the left of the primary. | 415 // Layout the secondary display to the left of the primary. |
436 SetSecondaryDisplayLayout(DisplayLayout::LEFT); | 416 SetSecondaryDisplayLayout(DisplayLayout::LEFT); |
437 EXPECT_EQ(1, observer.CountAndReset()); | 417 EXPECT_EQ(1, observer.CountAndReset()); |
438 EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); | 418 EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); |
439 EXPECT_EQ(1, observer.GetWorkareaChangedCountAndReset()); | |
440 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); | 419 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); |
441 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); | 420 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); |
442 EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset()); | 421 EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset()); |
443 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); | 422 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
444 EXPECT_EQ("-400,0 400x400", GetSecondaryDisplay().bounds().ToString()); | 423 EXPECT_EQ("-400,0 400x400", GetSecondaryDisplay().bounds().ToString()); |
445 EXPECT_EQ("-395,5 390x390", GetSecondaryDisplay().work_area().ToString()); | 424 EXPECT_EQ("-395,5 390x390", GetSecondaryDisplay().work_area().ToString()); |
446 | 425 |
447 // Layout the secondary display to the top of the primary. | 426 // Layout the secondary display to the top of the primary. |
448 SetSecondaryDisplayLayout(DisplayLayout::TOP); | 427 SetSecondaryDisplayLayout(DisplayLayout::TOP); |
449 EXPECT_EQ(1, observer.CountAndReset()); | 428 EXPECT_EQ(1, observer.CountAndReset()); |
450 EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); | 429 EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); |
451 EXPECT_EQ(1, observer.GetWorkareaChangedCountAndReset()); | |
452 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); | 430 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); |
453 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); | 431 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); |
454 EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset()); | 432 EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset()); |
455 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); | 433 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
456 EXPECT_EQ("0,-400 400x400", GetSecondaryDisplay().bounds().ToString()); | 434 EXPECT_EQ("0,-400 400x400", GetSecondaryDisplay().bounds().ToString()); |
457 EXPECT_EQ("5,-395 390x390", GetSecondaryDisplay().work_area().ToString()); | 435 EXPECT_EQ("5,-395 390x390", GetSecondaryDisplay().work_area().ToString()); |
458 | 436 |
459 // Layout to the right with an offset. | 437 // Layout to the right with an offset. |
460 SetSecondaryDisplayLayoutAndOffset(DisplayLayout::RIGHT, 300); | 438 SetSecondaryDisplayLayoutAndOffset(DisplayLayout::RIGHT, 300); |
461 EXPECT_EQ(1, observer.CountAndReset()); // resize and add | 439 EXPECT_EQ(1, observer.CountAndReset()); // resize and add |
462 EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); | 440 EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); |
463 EXPECT_EQ(1, observer.GetWorkareaChangedCountAndReset()); | |
464 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); | 441 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); |
465 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); | 442 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); |
466 EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset()); | 443 EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset()); |
467 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); | 444 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
468 EXPECT_EQ("500,300 400x400", GetSecondaryDisplay().bounds().ToString()); | 445 EXPECT_EQ("500,300 400x400", GetSecondaryDisplay().bounds().ToString()); |
469 | 446 |
470 // Keep the minimum 100. | 447 // Keep the minimum 100. |
471 SetSecondaryDisplayLayoutAndOffset(DisplayLayout::RIGHT, 490); | 448 SetSecondaryDisplayLayoutAndOffset(DisplayLayout::RIGHT, 490); |
472 EXPECT_EQ(1, observer.CountAndReset()); // resize and add | 449 EXPECT_EQ(1, observer.CountAndReset()); // resize and add |
473 EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); | 450 EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); |
474 EXPECT_EQ(1, observer.GetWorkareaChangedCountAndReset()); | |
475 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); | 451 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); |
476 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); | 452 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); |
477 EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset()); | 453 EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset()); |
478 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); | 454 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
479 EXPECT_EQ("500,400 400x400", GetSecondaryDisplay().bounds().ToString()); | 455 EXPECT_EQ("500,400 400x400", GetSecondaryDisplay().bounds().ToString()); |
480 | 456 |
481 SetSecondaryDisplayLayoutAndOffset(DisplayLayout::RIGHT, -400); | 457 SetSecondaryDisplayLayoutAndOffset(DisplayLayout::RIGHT, -400); |
482 EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset()); | 458 EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset()); |
483 EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); | 459 EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); |
484 EXPECT_EQ(1, observer.GetWorkareaChangedCountAndReset()); | |
485 EXPECT_EQ(1, observer.CountAndReset()); // resize and add | 460 EXPECT_EQ(1, observer.CountAndReset()); // resize and add |
486 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); | 461 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); |
487 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); | 462 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); |
488 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); | 463 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
489 EXPECT_EQ("500,-300 400x400", GetSecondaryDisplay().bounds().ToString()); | 464 EXPECT_EQ("500,-300 400x400", GetSecondaryDisplay().bounds().ToString()); |
490 | 465 |
491 // Layout to the bottom with an offset. | 466 // Layout to the bottom with an offset. |
492 SetSecondaryDisplayLayoutAndOffset(DisplayLayout::BOTTOM, -200); | 467 SetSecondaryDisplayLayoutAndOffset(DisplayLayout::BOTTOM, -200); |
493 EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset()); | 468 EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset()); |
494 EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); | 469 EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); |
495 EXPECT_EQ(1, observer.GetWorkareaChangedCountAndReset()); | |
496 EXPECT_EQ(1, observer.CountAndReset()); // resize and add | 470 EXPECT_EQ(1, observer.CountAndReset()); // resize and add |
497 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); | 471 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); |
498 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); | 472 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); |
499 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); | 473 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
500 EXPECT_EQ("-200,500 400x400", GetSecondaryDisplay().bounds().ToString()); | 474 EXPECT_EQ("-200,500 400x400", GetSecondaryDisplay().bounds().ToString()); |
501 | 475 |
502 // Keep the minimum 100. | 476 // Keep the minimum 100. |
503 SetSecondaryDisplayLayoutAndOffset(DisplayLayout::BOTTOM, 490); | 477 SetSecondaryDisplayLayoutAndOffset(DisplayLayout::BOTTOM, 490); |
504 EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset()); | 478 EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset()); |
505 EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); | 479 EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); |
506 EXPECT_EQ(1, observer.GetWorkareaChangedCountAndReset()); | |
507 EXPECT_EQ(1, observer.CountAndReset()); // resize and add | 480 EXPECT_EQ(1, observer.CountAndReset()); // resize and add |
508 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); | 481 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); |
509 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); | 482 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); |
510 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); | 483 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
511 EXPECT_EQ("400,500 400x400", GetSecondaryDisplay().bounds().ToString()); | 484 EXPECT_EQ("400,500 400x400", GetSecondaryDisplay().bounds().ToString()); |
512 | 485 |
513 SetSecondaryDisplayLayoutAndOffset(DisplayLayout::BOTTOM, -400); | 486 SetSecondaryDisplayLayoutAndOffset(DisplayLayout::BOTTOM, -400); |
514 EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset()); | 487 EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset()); |
515 EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); | 488 EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); |
516 EXPECT_EQ(1, observer.GetWorkareaChangedCountAndReset()); | |
517 EXPECT_EQ(1, observer.CountAndReset()); // resize and add | 489 EXPECT_EQ(1, observer.CountAndReset()); // resize and add |
518 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); | 490 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); |
519 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); | 491 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); |
520 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); | 492 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
521 EXPECT_EQ("-300,500 400x400", GetSecondaryDisplay().bounds().ToString()); | 493 EXPECT_EQ("-300,500 400x400", GetSecondaryDisplay().bounds().ToString()); |
522 | 494 |
523 // Setting the same layout shouldn't invoke observers. | 495 // Setting the same layout shouldn't invoke observers. |
524 SetSecondaryDisplayLayoutAndOffset(DisplayLayout::BOTTOM, -400); | 496 SetSecondaryDisplayLayoutAndOffset(DisplayLayout::BOTTOM, -400); |
525 EXPECT_EQ(0, observer.GetChangedDisplayIdAndReset()); | 497 EXPECT_EQ(0, observer.GetChangedDisplayIdAndReset()); |
526 EXPECT_EQ(0, observer.GetBoundsChangedCountAndReset()); | 498 EXPECT_EQ(0, observer.GetBoundsChangedCountAndReset()); |
527 EXPECT_EQ(0, observer.GetWorkareaChangedCountAndReset()); | |
528 EXPECT_EQ(0, observer.CountAndReset()); // resize and add | 499 EXPECT_EQ(0, observer.CountAndReset()); // resize and add |
529 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); | 500 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); |
530 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); | 501 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); |
531 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); | 502 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); |
532 EXPECT_EQ("-300,500 400x400", GetSecondaryDisplay().bounds().ToString()); | 503 EXPECT_EQ("-300,500 400x400", GetSecondaryDisplay().bounds().ToString()); |
533 | 504 |
534 UpdateDisplay("500x500"); | 505 UpdateDisplay("500x500"); |
535 EXPECT_LE(1, observer.GetFocusChangedCountAndReset()); | 506 EXPECT_LE(1, observer.GetFocusChangedCountAndReset()); |
536 EXPECT_LE(1, observer.GetActivationChangedCountAndReset()); | 507 EXPECT_LE(1, observer.GetActivationChangedCountAndReset()); |
537 } | 508 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 EXPECT_EQ("0,0 250x250", w1->bounds().ToString()); | 552 EXPECT_EQ("0,0 250x250", w1->bounds().ToString()); |
582 // Dock mode. | 553 // Dock mode. |
583 TestObserver observer; | 554 TestObserver observer; |
584 display_info_list.clear(); | 555 display_info_list.clear(); |
585 display_info_list.push_back(external_display_info); | 556 display_info_list.push_back(external_display_info); |
586 display_manager->OnNativeDisplaysChanged(display_info_list); | 557 display_manager->OnNativeDisplaysChanged(display_info_list); |
587 EXPECT_EQ(1U, display_manager->GetNumDisplays()); | 558 EXPECT_EQ(1U, display_manager->GetNumDisplays()); |
588 EXPECT_EQ(1U, display_manager->num_connected_displays()); | 559 EXPECT_EQ(1U, display_manager->num_connected_displays()); |
589 EXPECT_EQ(0, observer.GetChangedDisplayIdAndReset()); | 560 EXPECT_EQ(0, observer.GetChangedDisplayIdAndReset()); |
590 EXPECT_EQ(0, observer.GetBoundsChangedCountAndReset()); | 561 EXPECT_EQ(0, observer.GetBoundsChangedCountAndReset()); |
591 EXPECT_EQ(0, observer.GetWorkareaChangedCountAndReset()); | |
592 EXPECT_EQ(1, observer.CountAndReset()); | 562 EXPECT_EQ(1, observer.CountAndReset()); |
593 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); | 563 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); |
594 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); | 564 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); |
595 | 565 |
596 EXPECT_TRUE(window_state->IsFullscreen()); | 566 EXPECT_TRUE(window_state->IsFullscreen()); |
597 EXPECT_EQ("0,0 500x500", w1->bounds().ToString()); | 567 EXPECT_EQ("0,0 500x500", w1->bounds().ToString()); |
598 } | 568 } |
599 | 569 |
600 TEST_F(DisplayControllerTest, BoundsUpdated) { | 570 TEST_F(DisplayControllerTest, BoundsUpdated) { |
601 if (!SupportsMultipleDisplays()) | 571 if (!SupportsMultipleDisplays()) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 EXPECT_EQ("0,0 200x250", GetPrimaryDisplay().bounds().ToString()); | 620 EXPECT_EQ("0,0 200x250", GetPrimaryDisplay().bounds().ToString()); |
651 EXPECT_EQ("0,250 300x300", GetSecondaryDisplay().bounds().ToString()); | 621 EXPECT_EQ("0,250 300x300", GetSecondaryDisplay().bounds().ToString()); |
652 | 622 |
653 // No change | 623 // No change |
654 UpdateDisplay("400x500*2,300x300"); | 624 UpdateDisplay("400x500*2,300x300"); |
655 EXPECT_EQ(0, observer.CountAndReset()); | 625 EXPECT_EQ(0, observer.CountAndReset()); |
656 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); | 626 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); |
657 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); | 627 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); |
658 | 628 |
659 // Rotation | 629 // Rotation |
660 observer.GetRotationChangedCountAndReset(); // we only want to reset. | |
661 int64 primary_id = GetPrimaryDisplay().id(); | 630 int64 primary_id = GetPrimaryDisplay().id(); |
662 display_manager->SetDisplayRotation(primary_id, gfx::Display::ROTATE_90); | 631 display_manager->SetDisplayRotation(primary_id, gfx::Display::ROTATE_90); |
663 EXPECT_EQ(1, observer.GetRotationChangedCountAndReset()); | |
664 EXPECT_EQ(1, observer.CountAndReset()); | 632 EXPECT_EQ(1, observer.CountAndReset()); |
665 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); | 633 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); |
666 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); | 634 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); |
667 display_manager->SetDisplayRotation(primary_id, gfx::Display::ROTATE_90); | 635 display_manager->SetDisplayRotation(primary_id, gfx::Display::ROTATE_90); |
668 EXPECT_EQ(0, observer.GetRotationChangedCountAndReset()); | |
669 EXPECT_EQ(0, observer.CountAndReset()); | 636 EXPECT_EQ(0, observer.CountAndReset()); |
670 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); | 637 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); |
671 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); | 638 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); |
672 | 639 |
673 // UI scale is eanbled only on internal display. | 640 // UI scale is eanbled only on internal display. |
674 int64 secondary_id = GetSecondaryDisplay().id(); | 641 int64 secondary_id = GetSecondaryDisplay().id(); |
675 gfx::Display::SetInternalDisplayId(secondary_id); | 642 gfx::Display::SetInternalDisplayId(secondary_id); |
676 display_manager->SetDisplayUIScale(secondary_id, 1.125f); | 643 display_manager->SetDisplayUIScale(secondary_id, 1.125f); |
677 EXPECT_EQ(1, observer.CountAndReset()); | 644 EXPECT_EQ(1, observer.CountAndReset()); |
678 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); | 645 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1058 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 1025 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
1059 TestEventHandler event_handler; | 1026 TestEventHandler event_handler; |
1060 Shell::GetInstance()->AddPreTargetHandler(&event_handler); | 1027 Shell::GetInstance()->AddPreTargetHandler(&event_handler); |
1061 | 1028 |
1062 UpdateDisplay("120x200,300x400*2"); | 1029 UpdateDisplay("120x200,300x400*2"); |
1063 gfx::Display display1 = Shell::GetScreen()->GetPrimaryDisplay(); | 1030 gfx::Display display1 = Shell::GetScreen()->GetPrimaryDisplay(); |
1064 int64 display2_id = ScreenUtil::GetSecondaryDisplay().id(); | 1031 int64 display2_id = ScreenUtil::GetSecondaryDisplay().id(); |
1065 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 1032 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
1066 aura::test::EventGenerator generator1(root_windows[0]); | 1033 aura::test::EventGenerator generator1(root_windows[0]); |
1067 | 1034 |
1068 TestObserver observer; | |
1069 EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString()); | 1035 EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString()); |
1070 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString()); | 1036 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString()); |
1071 EXPECT_EQ("120,0 150x200", | 1037 EXPECT_EQ("120,0 150x200", |
1072 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); | 1038 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); |
1073 generator1.MoveMouseToInHost(50, 40); | 1039 generator1.MoveMouseToInHost(50, 40); |
1074 EXPECT_EQ("50,40", event_handler.GetLocationAndReset()); | 1040 EXPECT_EQ("50,40", event_handler.GetLocationAndReset()); |
1075 EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display1.id())); | 1041 EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display1.id())); |
1076 EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display2_id)); | 1042 EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display2_id)); |
1077 EXPECT_EQ(0, observer.GetRotationChangedCountAndReset()); | |
1078 | 1043 |
1079 display_manager->SetDisplayRotation(display1.id(), | 1044 display_manager->SetDisplayRotation(display1.id(), |
1080 gfx::Display::ROTATE_90); | 1045 gfx::Display::ROTATE_90); |
1081 EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString()); | 1046 EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString()); |
1082 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString()); | 1047 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString()); |
1083 EXPECT_EQ("200,0 150x200", | 1048 EXPECT_EQ("200,0 150x200", |
1084 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); | 1049 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); |
1085 generator1.MoveMouseToInHost(50, 40); | 1050 generator1.MoveMouseToInHost(50, 40); |
1086 EXPECT_EQ("40,69", event_handler.GetLocationAndReset()); | 1051 EXPECT_EQ("40,69", event_handler.GetLocationAndReset()); |
1087 EXPECT_EQ(gfx::Display::ROTATE_90, GetStoredRotation(display1.id())); | 1052 EXPECT_EQ(gfx::Display::ROTATE_90, GetStoredRotation(display1.id())); |
1088 EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display2_id)); | 1053 EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display2_id)); |
1089 EXPECT_EQ(1, observer.GetRotationChangedCountAndReset()); | |
1090 | 1054 |
1091 DisplayLayout display_layout(DisplayLayout::BOTTOM, 50); | 1055 DisplayLayout display_layout(DisplayLayout::BOTTOM, 50); |
1092 display_manager->SetLayoutForCurrentDisplays(display_layout); | 1056 display_manager->SetLayoutForCurrentDisplays(display_layout); |
1093 EXPECT_EQ("50,120 150x200", | 1057 EXPECT_EQ("50,120 150x200", |
1094 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); | 1058 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); |
1095 | 1059 |
1096 display_manager->SetDisplayRotation(display2_id, | 1060 display_manager->SetDisplayRotation(display2_id, |
1097 gfx::Display::ROTATE_270); | 1061 gfx::Display::ROTATE_270); |
1098 EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString()); | 1062 EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString()); |
1099 EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString()); | 1063 EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString()); |
1100 EXPECT_EQ("50,120 200x150", | 1064 EXPECT_EQ("50,120 200x150", |
1101 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); | 1065 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); |
1102 EXPECT_EQ(gfx::Display::ROTATE_90, GetStoredRotation(display1.id())); | 1066 EXPECT_EQ(gfx::Display::ROTATE_90, GetStoredRotation(display1.id())); |
1103 EXPECT_EQ(gfx::Display::ROTATE_270, GetStoredRotation(display2_id)); | 1067 EXPECT_EQ(gfx::Display::ROTATE_270, GetStoredRotation(display2_id)); |
1104 EXPECT_EQ(1, observer.GetRotationChangedCountAndReset()); | |
1105 | 1068 |
1106 #if !defined(OS_WIN) | 1069 #if !defined(OS_WIN) |
1107 aura::test::EventGenerator generator2(root_windows[1]); | 1070 aura::test::EventGenerator generator2(root_windows[1]); |
1108 generator2.MoveMouseToInHost(50, 40); | 1071 generator2.MoveMouseToInHost(50, 40); |
1109 EXPECT_EQ("179,25", event_handler.GetLocationAndReset()); | 1072 EXPECT_EQ("179,25", event_handler.GetLocationAndReset()); |
1110 display_manager->SetDisplayRotation(display1.id(), | 1073 display_manager->SetDisplayRotation(display1.id(), |
1111 gfx::Display::ROTATE_180); | 1074 gfx::Display::ROTATE_180); |
1112 | 1075 |
1113 EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString()); | 1076 EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString()); |
1114 EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString()); | 1077 EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString()); |
1115 // Dislay must share at least 100, so the x's offset becomes 20. | 1078 // Dislay must share at least 100, so the x's offset becomes 20. |
1116 EXPECT_EQ("20,200 200x150", | 1079 EXPECT_EQ("20,200 200x150", |
1117 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); | 1080 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); |
1118 EXPECT_EQ(gfx::Display::ROTATE_180, GetStoredRotation(display1.id())); | 1081 EXPECT_EQ(gfx::Display::ROTATE_180, GetStoredRotation(display1.id())); |
1119 EXPECT_EQ(gfx::Display::ROTATE_270, GetStoredRotation(display2_id)); | 1082 EXPECT_EQ(gfx::Display::ROTATE_270, GetStoredRotation(display2_id)); |
1120 EXPECT_EQ(1, observer.GetRotationChangedCountAndReset()); | |
1121 | 1083 |
1122 generator1.MoveMouseToInHost(50, 40); | 1084 generator1.MoveMouseToInHost(50, 40); |
1123 EXPECT_EQ("69,159", event_handler.GetLocationAndReset()); | 1085 EXPECT_EQ("69,159", event_handler.GetLocationAndReset()); |
1124 #endif | 1086 #endif |
1125 | 1087 |
1126 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); | 1088 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); |
1127 } | 1089 } |
1128 | 1090 |
1129 TEST_F(DisplayControllerTest, ScaleRootWindow) { | 1091 TEST_F(DisplayControllerTest, ScaleRootWindow) { |
1130 if (!SupportsMultipleDisplays()) | 1092 if (!SupportsMultipleDisplays()) |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1331 EXPECT_EQ("aura_root_x", GetXWindowName(secondary->GetHost())); | 1293 EXPECT_EQ("aura_root_x", GetXWindowName(secondary->GetHost())); |
1332 | 1294 |
1333 // Switching back to single display. | 1295 // Switching back to single display. |
1334 UpdateDisplay("300x400"); | 1296 UpdateDisplay("300x400"); |
1335 EXPECT_EQ("aura_root_0", GetXWindowName( | 1297 EXPECT_EQ("aura_root_0", GetXWindowName( |
1336 Shell::GetPrimaryRootWindow()->GetHost())); | 1298 Shell::GetPrimaryRootWindow()->GetHost())); |
1337 } | 1299 } |
1338 #endif | 1300 #endif |
1339 | 1301 |
1340 } // namespace ash | 1302 } // namespace ash |
OLD | NEW |