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 "chrome/browser/ui/window_sizer.h" | 5 #include "chrome/browser/ui/window_sizer.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/shell_window_ids.h" | 10 #include "ash/shell_window_ids.h" |
(...skipping 12 matching lines...) Expand all Loading... | |
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" |
24 #include "ui/aura/env.h" | 24 #include "ui/aura/env.h" |
25 #include "ui/aura/root_window.h" | 25 #include "ui/aura/root_window.h" |
26 #include "ui/aura/test/test_windows.h" | 26 #include "ui/aura/test/test_windows.h" |
27 | 27 |
28 | 28 |
29 namespace { | 29 namespace { |
30 | 30 |
31 typedef ash::test::AshTestBase WindowSizerTest; | 31 typedef ash::test::AshTestBase WindowSizerTest; |
32 | 32 |
33 // A function which aligns a size to a step within the grid. | |
34 int align(int size, int alignment_factor) { | |
sky
2012/04/13 23:37:29
Replace this (and the copy in your other test) wit
Mr4D (OOO till 08-26)
2012/04/14 00:19:45
Same here - This isn't my code anymore.
| |
35 if (alignment_factor > 1) { | |
36 return size - size % alignment_factor; | |
37 } | |
38 return size; | |
39 } | |
40 | |
33 // A special test class for use with browser creation - it will create a | 41 // A special test class for use with browser creation - it will create a |
34 // browser thread and deletes it after all other things have been destroyed. | 42 // browser thread and deletes it after all other things have been destroyed. |
35 class WindowSizerTestWithBrowser : public WindowSizerTest { | 43 class WindowSizerTestWithBrowser : public WindowSizerTest { |
36 public: | 44 public: |
37 WindowSizerTestWithBrowser(); | 45 WindowSizerTestWithBrowser(); |
38 ~WindowSizerTestWithBrowser(); | 46 ~WindowSizerTestWithBrowser(); |
39 | 47 |
40 private: | 48 private: |
41 // Note: It is important to delete the thread after the browser instances got | 49 // Note: It is important to delete the thread after the browser instances got |
42 // deleted. For this we transfer the thread here. | 50 // deleted. For this we transfer the thread here. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 aura::Window *native_window) : | 84 aura::Window *native_window) : |
77 TestBrowserWindow(browser), | 85 TestBrowserWindow(browser), |
78 native_window_(native_window) { | 86 native_window_(native_window) { |
79 } | 87 } |
80 | 88 |
81 TestBrowserWindowAura::~TestBrowserWindowAura() {} | 89 TestBrowserWindowAura::~TestBrowserWindowAura() {} |
82 | 90 |
83 // Test that the window is sized appropriately for the first run experience | 91 // Test that the window is sized appropriately for the first run experience |
84 // where the default window bounds calculation is invoked. | 92 // where the default window bounds calculation is invoked. |
85 TEST_F(WindowSizerTest, DefaultSizeCase) { | 93 TEST_F(WindowSizerTest, DefaultSizeCase) { |
86 EXPECT_EQ(WindowSizer::kDesktopBorderSize, | 94 int grid = ash::Shell::GetInstance()->GetGridSize(); |
87 ash::Shell::GetInstance()->GetGridSize()); | 95 EXPECT_EQ(WindowSizer::kDesktopBorderSize, grid); |
88 { // 4:3 monitor case, 1024x768, no taskbar | 96 { // 4:3 monitor case, 1024x768, no taskbar |
89 gfx::Rect window_bounds; | 97 gfx::Rect window_bounds; |
90 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(), | 98 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(), |
91 gfx::Rect(), DEFAULT, &window_bounds, NULL); | 99 gfx::Rect(), DEFAULT, &window_bounds, NULL); |
92 EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, | 100 EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, |
93 WindowSizer::kDesktopBorderSize, | 101 WindowSizer::kDesktopBorderSize, |
94 1024 - WindowSizer::kDesktopBorderSize * 2, | 102 1024 - WindowSizer::kDesktopBorderSize * 2, |
95 768 - WindowSizer::kDesktopBorderSize), | 103 768 - WindowSizer::kDesktopBorderSize), |
96 window_bounds); | 104 window_bounds); |
97 } | 105 } |
98 | 106 |
99 { // 4:3 monitor case, 1024x768, taskbar on bottom | 107 { // 4:3 monitor case, 1024x768, taskbar on bottom |
100 gfx::Rect window_bounds; | 108 gfx::Rect window_bounds; |
101 GetWindowBounds(tentwentyfour, taskbar_bottom_work_area, gfx::Rect(), | 109 GetWindowBounds(tentwentyfour, taskbar_bottom_work_area, gfx::Rect(), |
102 gfx::Rect(), gfx::Rect(), DEFAULT, &window_bounds, NULL); | 110 gfx::Rect(), gfx::Rect(), DEFAULT, &window_bounds, NULL); |
103 EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, | 111 EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, |
104 WindowSizer::kDesktopBorderSize, | 112 WindowSizer::kDesktopBorderSize, |
105 1024 - WindowSizer::kDesktopBorderSize * 2, | 113 1024 - WindowSizer::kDesktopBorderSize * 2, |
106 (taskbar_bottom_work_area.height() - | 114 align(taskbar_bottom_work_area.height() - |
107 WindowSizer::kDesktopBorderSize)), | 115 WindowSizer::kDesktopBorderSize, grid)), |
108 window_bounds); | 116 window_bounds); |
109 } | 117 } |
110 | 118 |
111 { // 4:3 monitor case, 1024x768, taskbar on right | 119 { // 4:3 monitor case, 1024x768, taskbar on right |
112 gfx::Rect window_bounds; | 120 gfx::Rect window_bounds; |
113 GetWindowBounds(tentwentyfour, taskbar_right_work_area, gfx::Rect(), | 121 GetWindowBounds(tentwentyfour, taskbar_right_work_area, gfx::Rect(), |
114 gfx::Rect(), gfx::Rect(), DEFAULT, &window_bounds, NULL); | 122 gfx::Rect(), gfx::Rect(), DEFAULT, &window_bounds, NULL); |
115 EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, | 123 EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, |
116 WindowSizer::kDesktopBorderSize, | 124 WindowSizer::kDesktopBorderSize, |
117 taskbar_right_work_area.width() - | 125 align(taskbar_right_work_area.width() - |
118 WindowSizer::kDesktopBorderSize*2, | 126 WindowSizer::kDesktopBorderSize * 2, grid), |
119 768 - WindowSizer::kDesktopBorderSize), | 127 768 - WindowSizer::kDesktopBorderSize), |
120 window_bounds); | 128 window_bounds); |
121 } | 129 } |
122 | 130 |
123 { // 4:3 monitor case, 1024x768, taskbar on left | 131 { // 4:3 monitor case, 1024x768, taskbar on left |
124 gfx::Rect window_bounds; | 132 gfx::Rect window_bounds; |
125 GetWindowBounds(tentwentyfour, taskbar_left_work_area, gfx::Rect(), | 133 GetWindowBounds(tentwentyfour, taskbar_left_work_area, gfx::Rect(), |
126 gfx::Rect(), gfx::Rect(), DEFAULT, &window_bounds, NULL); | 134 gfx::Rect(), gfx::Rect(), DEFAULT, &window_bounds, NULL); |
127 EXPECT_EQ(gfx::Rect(taskbar_left_work_area.x() + | 135 EXPECT_EQ(gfx::Rect(taskbar_left_work_area.x() + |
128 WindowSizer::kDesktopBorderSize, | 136 WindowSizer::kDesktopBorderSize, |
129 WindowSizer::kDesktopBorderSize, | 137 WindowSizer::kDesktopBorderSize, |
130 taskbar_left_work_area.width() - | 138 align(taskbar_left_work_area.width() - |
131 WindowSizer::kDesktopBorderSize * 2, | 139 WindowSizer::kDesktopBorderSize * 2, grid), |
132 taskbar_left_work_area.height() - | 140 align(taskbar_left_work_area.height() - |
133 WindowSizer::kDesktopBorderSize), | 141 WindowSizer::kDesktopBorderSize, grid)), |
134 window_bounds); | 142 window_bounds); |
135 } | 143 } |
136 | 144 |
137 { // 4:3 monitor case, 1024x768, taskbar on top | 145 { // 4:3 monitor case, 1024x768, taskbar on top |
138 gfx::Rect window_bounds; | 146 gfx::Rect window_bounds; |
139 GetWindowBounds(tentwentyfour, taskbar_top_work_area, gfx::Rect(), | 147 GetWindowBounds(tentwentyfour, taskbar_top_work_area, gfx::Rect(), |
140 gfx::Rect(), gfx::Rect(), DEFAULT, &window_bounds, NULL); | 148 gfx::Rect(), gfx::Rect(), DEFAULT, &window_bounds, NULL); |
141 EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, | 149 EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, |
142 taskbar_top_work_area.y() + | 150 taskbar_top_work_area.y() + |
143 WindowSizer::kDesktopBorderSize, | 151 WindowSizer::kDesktopBorderSize, |
144 1024 - WindowSizer::kDesktopBorderSize * 2, | 152 1024 - WindowSizer::kDesktopBorderSize * 2, |
145 taskbar_top_work_area.height() - | 153 align(taskbar_top_work_area.height() - |
146 WindowSizer::kDesktopBorderSize), | 154 WindowSizer::kDesktopBorderSize, grid)), |
147 window_bounds); | 155 window_bounds); |
148 } | 156 } |
149 | 157 |
150 { // 4:3 monitor case, 1280x1024 | 158 { // 4:3 monitor case, 1280x1024 |
151 gfx::Rect window_bounds; | 159 gfx::Rect window_bounds; |
152 GetWindowBounds(twelveeighty, twelveeighty, gfx::Rect(), gfx::Rect(), | 160 GetWindowBounds(twelveeighty, twelveeighty, gfx::Rect(), gfx::Rect(), |
153 gfx::Rect(), DEFAULT, &window_bounds, NULL); | 161 gfx::Rect(), DEFAULT, &window_bounds, NULL); |
154 EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, | 162 EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, |
155 WindowSizer::kDesktopBorderSize, | 163 WindowSizer::kDesktopBorderSize, |
156 1280 - 2 * WindowSizer::kDesktopBorderSize, | 164 1280 - 2 * WindowSizer::kDesktopBorderSize, |
(...skipping 10 matching lines...) Expand all Loading... | |
167 1200 - WindowSizer::kDesktopBorderSize), | 175 1200 - WindowSizer::kDesktopBorderSize), |
168 window_bounds); | 176 window_bounds); |
169 } | 177 } |
170 | 178 |
171 { // 16:10 monitor case, 1680x1050 | 179 { // 16:10 monitor case, 1680x1050 |
172 gfx::Rect window_bounds; | 180 gfx::Rect window_bounds; |
173 GetWindowBounds(sixteeneighty, sixteeneighty, gfx::Rect(), gfx::Rect(), | 181 GetWindowBounds(sixteeneighty, sixteeneighty, gfx::Rect(), gfx::Rect(), |
174 gfx::Rect(), DEFAULT, &window_bounds, NULL); | 182 gfx::Rect(), DEFAULT, &window_bounds, NULL); |
175 EXPECT_EQ(gfx::Rect((1680 - 1280) / 2, WindowSizer::kDesktopBorderSize, | 183 EXPECT_EQ(gfx::Rect((1680 - 1280) / 2, WindowSizer::kDesktopBorderSize, |
176 1280, | 184 1280, |
177 1050 - WindowSizer::kDesktopBorderSize), | 185 align(1050 - WindowSizer::kDesktopBorderSize, grid)), |
178 window_bounds); | 186 window_bounds); |
179 } | 187 } |
180 | 188 |
181 { // 16:10 monitor case, 1920x1200 | 189 { // 16:10 monitor case, 1920x1200 |
182 gfx::Rect window_bounds; | 190 gfx::Rect window_bounds; |
183 GetWindowBounds(nineteentwenty, nineteentwenty, gfx::Rect(), gfx::Rect(), | 191 GetWindowBounds(nineteentwenty, nineteentwenty, gfx::Rect(), gfx::Rect(), |
184 gfx::Rect(), DEFAULT, &window_bounds, NULL); | 192 gfx::Rect(), DEFAULT, &window_bounds, NULL); |
185 EXPECT_EQ(gfx::Rect((1920 - 1280) / 2, WindowSizer::kDesktopBorderSize, | 193 EXPECT_EQ(gfx::Rect((1920 - 1280) / 2, WindowSizer::kDesktopBorderSize, |
186 1280, | 194 1280, |
187 1200 - WindowSizer::kDesktopBorderSize), | 195 1200 - WindowSizer::kDesktopBorderSize), |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
659 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), | 667 GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), |
660 gfx::Rect(50, 100, 300, 150), bottom_nonprimary, | 668 gfx::Rect(50, 100, 300, 150), bottom_nonprimary, |
661 PERSISTED, &window_bounds, browser.get()); | 669 PERSISTED, &window_bounds, browser.get()); |
662 EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, | 670 EXPECT_EQ(gfx::Rect(WindowSizer::kDesktopBorderSize, |
663 WindowSizer::kDesktopBorderSize, | 671 WindowSizer::kDesktopBorderSize, |
664 1024 - 2 * WindowSizer::kDesktopBorderSize, | 672 1024 - 2 * WindowSizer::kDesktopBorderSize, |
665 768 - WindowSizer::kDesktopBorderSize), | 673 768 - WindowSizer::kDesktopBorderSize), |
666 window_bounds); | 674 window_bounds); |
667 } | 675 } |
668 } | 676 } |
OLD | NEW |