Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(270)

Side by Side Diff: ash/display/display_controller_unittest.cc

Issue 12438016: Save display preference when all display configuration changes has been completed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: replace dcheck Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/display/display_controller.cc ('k') | ash/display/display_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/display/display_info.h" 7 #include "ash/display/display_info.h"
8 #include "ash/display/display_manager.h" 8 #include "ash/display/display_manager.h"
9 #include "ash/launcher/launcher.h" 9 #include "ash/launcher/launcher.h"
10 #include "ash/screen_ash.h" 10 #include "ash/screen_ash.h"
11 #include "ash/shelf/shelf_widget.h" 11 #include "ash/shelf/shelf_widget.h"
12 #include "ash/shell.h" 12 #include "ash/shell.h"
13 #include "ash/test/ash_test_base.h" 13 #include "ash/test/ash_test_base.h"
14 #include "ash/test/cursor_manager_test_api.h" 14 #include "ash/test/cursor_manager_test_api.h"
15 #include "ui/aura/env.h" 15 #include "ui/aura/env.h"
16 #include "ui/aura/root_window.h" 16 #include "ui/aura/root_window.h"
17 #include "ui/aura/test/event_generator.h" 17 #include "ui/aura/test/event_generator.h"
18 #include "ui/aura/window_tracker.h" 18 #include "ui/aura/window_tracker.h"
19 #include "ui/base/events/event_handler.h" 19 #include "ui/base/events/event_handler.h"
20 #include "ui/gfx/display.h" 20 #include "ui/gfx/display.h"
21 #include "ui/gfx/screen.h" 21 #include "ui/gfx/screen.h"
22 #include "ui/views/widget/widget.h" 22 #include "ui/views/widget/widget.h"
23 23
24 namespace ash { 24 namespace ash {
25 namespace test { 25 namespace test {
26 namespace { 26 namespace {
27 27
28 class TestObserver : public DisplayController::Observer { 28 class TestObserver : public DisplayController::Observer {
29 public: 29 public:
30 TestObserver() : count_(0) { 30 TestObserver() : changing_count_(0), changed_count_(0) {
31 Shell::GetInstance()->display_controller()->AddObserver(this); 31 Shell::GetInstance()->display_controller()->AddObserver(this);
32 } 32 }
33 33
34 virtual ~TestObserver() { 34 virtual ~TestObserver() {
35 Shell::GetInstance()->display_controller()->RemoveObserver(this); 35 Shell::GetInstance()->display_controller()->RemoveObserver(this);
36 } 36 }
37 37
38 virtual void OnDisplayConfigurationChanging() OVERRIDE { 38 virtual void OnDisplayConfigurationChanging() OVERRIDE {
39 ++count_; 39 ++changing_count_;
40 }
41
42 virtual void OnDisplayConfigurationChanged() OVERRIDE {
43 ++changed_count_;
40 } 44 }
41 45
42 int CountAndReset() { 46 int CountAndReset() {
43 int c = count_; 47 EXPECT_EQ(changing_count_, changed_count_);
44 count_ = 0; 48 int c = changing_count_;
49 changing_count_ = changed_count_ = 0;
45 return c; 50 return c;
46 } 51 }
47 52
48 private: 53 private:
49 int count_; 54 int changing_count_;
55 int changed_count_;
50 56
51 DISALLOW_COPY_AND_ASSIGN(TestObserver); 57 DISALLOW_COPY_AND_ASSIGN(TestObserver);
52 }; 58 };
53 59
54 gfx::Display GetPrimaryDisplay() { 60 gfx::Display GetPrimaryDisplay() {
55 return Shell::GetScreen()->GetDisplayNearestWindow( 61 return Shell::GetScreen()->GetDisplayNearestWindow(
56 Shell::GetAllRootWindows()[0]); 62 Shell::GetAllRootWindows()[0]);
57 } 63 }
58 64
59 gfx::Display GetSecondaryDisplay() { 65 gfx::Display GetSecondaryDisplay() {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 126
121 typedef test::AshTestBase DisplayControllerTest; 127 typedef test::AshTestBase DisplayControllerTest;
122 128
123 TEST_F(DisplayControllerShutdownTest, Shutdown) { 129 TEST_F(DisplayControllerShutdownTest, Shutdown) {
124 UpdateDisplay("444x333, 200x200"); 130 UpdateDisplay("444x333, 200x200");
125 } 131 }
126 132
127 TEST_F(DisplayControllerTest, SecondaryDisplayLayout) { 133 TEST_F(DisplayControllerTest, SecondaryDisplayLayout) {
128 TestObserver observer; 134 TestObserver observer;
129 UpdateDisplay("500x500,400x400"); 135 UpdateDisplay("500x500,400x400");
130 EXPECT_EQ(2, observer.CountAndReset()); // resize and add 136 EXPECT_EQ(1, observer.CountAndReset()); // resize and add
131 gfx::Display* secondary_display = 137 gfx::Display* secondary_display =
132 Shell::GetInstance()->display_manager()->GetDisplayAt(1); 138 Shell::GetInstance()->display_manager()->GetDisplayAt(1);
133 gfx::Insets insets(5, 5, 5, 5); 139 gfx::Insets insets(5, 5, 5, 5);
134 secondary_display->UpdateWorkAreaFromInsets(insets); 140 secondary_display->UpdateWorkAreaFromInsets(insets);
135 141
136 // Default layout is RIGHT. 142 // Default layout is RIGHT.
137 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); 143 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString());
138 EXPECT_EQ("500,0 400x400", GetSecondaryDisplay().bounds().ToString()); 144 EXPECT_EQ("500,0 400x400", GetSecondaryDisplay().bounds().ToString());
139 EXPECT_EQ("505,5 390x390", GetSecondaryDisplay().work_area().ToString()); 145 EXPECT_EQ("505,5 390x390", GetSecondaryDisplay().work_area().ToString());
140 146
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 SetSecondaryDisplayLayoutAndOffset(DisplayLayout::BOTTOM, -400); 197 SetSecondaryDisplayLayoutAndOffset(DisplayLayout::BOTTOM, -400);
192 EXPECT_EQ(1, observer.CountAndReset()); // resize and add 198 EXPECT_EQ(1, observer.CountAndReset()); // resize and add
193 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); 199 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString());
194 EXPECT_EQ("-300,500 400x400", GetSecondaryDisplay().bounds().ToString()); 200 EXPECT_EQ("-300,500 400x400", GetSecondaryDisplay().bounds().ToString());
195 } 201 }
196 202
197 TEST_F(DisplayControllerTest, BoundsUpdated) { 203 TEST_F(DisplayControllerTest, BoundsUpdated) {
198 TestObserver observer; 204 TestObserver observer;
199 SetSecondaryDisplayLayout(DisplayLayout::BOTTOM); 205 SetSecondaryDisplayLayout(DisplayLayout::BOTTOM);
200 UpdateDisplay("200x200,300x300"); // layout, resize and add. 206 UpdateDisplay("200x200,300x300"); // layout, resize and add.
201 EXPECT_EQ(3, observer.CountAndReset()); 207 EXPECT_EQ(2, observer.CountAndReset());
202 208
203 gfx::Display* secondary_display = 209 internal::DisplayManager* display_manager =
204 Shell::GetInstance()->display_manager()->GetDisplayAt(1); 210 Shell::GetInstance()->display_manager();
211 gfx::Display* secondary_display = display_manager->GetDisplayAt(1);
205 gfx::Insets insets(5, 5, 5, 5); 212 gfx::Insets insets(5, 5, 5, 5);
206 secondary_display->UpdateWorkAreaFromInsets(insets); 213 secondary_display->UpdateWorkAreaFromInsets(insets);
207 214
208 EXPECT_EQ("0,0 200x200", GetPrimaryDisplay().bounds().ToString()); 215 EXPECT_EQ("0,0 200x200", GetPrimaryDisplay().bounds().ToString());
209 EXPECT_EQ("0,200 300x300", GetSecondaryDisplay().bounds().ToString()); 216 EXPECT_EQ("0,200 300x300", GetSecondaryDisplay().bounds().ToString());
210 EXPECT_EQ("5,205 290x290", GetSecondaryDisplay().work_area().ToString()); 217 EXPECT_EQ("5,205 290x290", GetSecondaryDisplay().work_area().ToString());
211 218
212 UpdateDisplay("400x400,200x200"); 219 UpdateDisplay("400x400,200x200");
213 EXPECT_EQ(2, observer.CountAndReset()); // two resizes 220 EXPECT_EQ(1, observer.CountAndReset()); // two resizes
214 EXPECT_EQ("0,0 400x400", GetPrimaryDisplay().bounds().ToString()); 221 EXPECT_EQ("0,0 400x400", GetPrimaryDisplay().bounds().ToString());
215 EXPECT_EQ("0,400 200x200", GetSecondaryDisplay().bounds().ToString()); 222 EXPECT_EQ("0,400 200x200", GetSecondaryDisplay().bounds().ToString());
216 if (!ash::Shell::IsLauncherPerDisplayEnabled()) 223 if (!ash::Shell::IsLauncherPerDisplayEnabled())
217 EXPECT_EQ("5,405 190x190", GetSecondaryDisplay().work_area().ToString()); 224 EXPECT_EQ("5,405 190x190", GetSecondaryDisplay().work_area().ToString());
218 225
219 UpdateDisplay("400x400,300x300"); 226 UpdateDisplay("400x400,300x300");
220 EXPECT_EQ(1, observer.CountAndReset()); 227 EXPECT_EQ(1, observer.CountAndReset());
221 EXPECT_EQ("0,0 400x400", GetPrimaryDisplay().bounds().ToString()); 228 EXPECT_EQ("0,0 400x400", GetPrimaryDisplay().bounds().ToString());
222 EXPECT_EQ("0,400 300x300", GetSecondaryDisplay().bounds().ToString()); 229 EXPECT_EQ("0,400 300x300", GetSecondaryDisplay().bounds().ToString());
223 if (!ash::Shell::IsLauncherPerDisplayEnabled()) 230 if (!ash::Shell::IsLauncherPerDisplayEnabled())
224 EXPECT_EQ("5,405 290x290", GetSecondaryDisplay().work_area().ToString()); 231 EXPECT_EQ("5,405 290x290", GetSecondaryDisplay().work_area().ToString());
225 232
226 UpdateDisplay("400x400"); 233 UpdateDisplay("400x400");
227 EXPECT_EQ(1, observer.CountAndReset()); 234 EXPECT_EQ(1, observer.CountAndReset());
228 EXPECT_EQ("0,0 400x400", GetPrimaryDisplay().bounds().ToString()); 235 EXPECT_EQ("0,0 400x400", GetPrimaryDisplay().bounds().ToString());
229 EXPECT_EQ(1, Shell::GetScreen()->GetNumDisplays()); 236 EXPECT_EQ(1, Shell::GetScreen()->GetNumDisplays());
230 237
231 UpdateDisplay("500x500,700x700"); 238 UpdateDisplay("400x500,700x700*2");
232 EXPECT_EQ(2, observer.CountAndReset()); 239 EXPECT_EQ(1, observer.CountAndReset());
233 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays()); 240 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays());
234 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); 241 EXPECT_EQ("0,0 400x500", GetPrimaryDisplay().bounds().ToString());
235 EXPECT_EQ("0,500 700x700", GetSecondaryDisplay().bounds().ToString()); 242 EXPECT_EQ("0,500 350x350", GetSecondaryDisplay().bounds().ToString());
243
244 // No change
245 UpdateDisplay("400x500,700x700*2");
246 EXPECT_EQ(0, observer.CountAndReset());
247
248 // Rotation
249 int64 primary_id = GetPrimaryDisplay().id();
250 display_manager->SetDisplayRotation(primary_id, gfx::Display::ROTATE_90);
251 EXPECT_EQ(1, observer.CountAndReset());
252 display_manager->SetDisplayRotation(primary_id, gfx::Display::ROTATE_90);
253 EXPECT_EQ(0, observer.CountAndReset());
254
255 // UI scale
256 int64 secondary_id = GetSecondaryDisplay().id();
257 gfx::Display::SetInternalDisplayId(secondary_id);
258 display_manager->SetDisplayUIScale(secondary_id, 1.25f);
259 EXPECT_EQ(1, observer.CountAndReset());
260 display_manager->SetDisplayUIScale(secondary_id, 1.25f);
261 EXPECT_EQ(0, observer.CountAndReset());
236 } 262 }
237 263
238 TEST_F(DisplayControllerTest, InvertLayout) { 264 TEST_F(DisplayControllerTest, InvertLayout) {
239 EXPECT_EQ("left, 0", 265 EXPECT_EQ("left, 0",
240 DisplayLayout(DisplayLayout::RIGHT, 0).Invert().ToString()); 266 DisplayLayout(DisplayLayout::RIGHT, 0).Invert().ToString());
241 EXPECT_EQ("left, -100", 267 EXPECT_EQ("left, -100",
242 DisplayLayout(DisplayLayout::RIGHT, 100).Invert().ToString()); 268 DisplayLayout(DisplayLayout::RIGHT, 100).Invert().ToString());
243 EXPECT_EQ("left, 50", 269 EXPECT_EQ("left, 50",
244 DisplayLayout(DisplayLayout::RIGHT, -50).Invert().ToString()); 270 DisplayLayout(DisplayLayout::RIGHT, -50).Invert().ToString());
245 271
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 726
701 aura::test::EventGenerator generator(root_windows[0]); 727 aura::test::EventGenerator generator(root_windows[0]);
702 generator.MoveMouseTo(599, 200); 728 generator.MoveMouseTo(599, 200);
703 EXPECT_EQ("449,150", event_handler.GetLocationAndReset()); 729 EXPECT_EQ("449,150", event_handler.GetLocationAndReset());
704 730
705 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); 731 Shell::GetInstance()->RemovePreTargetHandler(&event_handler);
706 } 732 }
707 733
708 } // namespace test 734 } // namespace test
709 } // namespace ash 735 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/display_controller.cc ('k') | ash/display/display_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698