OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/views/frame/opaque_browser_frame_view_layout.h" | 5 #include "chrome/browser/ui/views/frame/opaque_browser_frame_view_layout.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/command_line.h" | |
8 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/ui/views/tab_icon_view.h" | 10 #include "chrome/browser/ui/views/tab_icon_view.h" |
10 #include "chrome/browser/ui/views/tabs/tab.h" | 11 #include "chrome/browser/ui/views/tabs/tab.h" |
12 #include "chrome/common/chrome_switches.h" | |
11 #include "ui/gfx/image/image_skia.h" | 13 #include "ui/gfx/image/image_skia.h" |
12 #include "ui/gfx/image/image_skia_rep.h" | 14 #include "ui/gfx/image/image_skia_rep.h" |
13 #include "ui/gfx/text_constants.h" | 15 #include "ui/gfx/text_constants.h" |
14 #include "ui/views/controls/button/image_button.h" | 16 #include "ui/views/controls/button/image_button.h" |
15 #include "ui/views/controls/button/menu_button.h" | 17 #include "ui/views/controls/button/menu_button.h" |
16 #include "ui/views/controls/label.h" | 18 #include "ui/views/controls/label.h" |
17 #include "ui/views/test/views_test_base.h" | 19 #include "ui/views/test/views_test_base.h" |
18 | 20 |
19 using views::Widget; | 21 using views::Widget; |
20 | 22 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 | 75 |
74 virtual gfx::Size GetBrowserViewMinimumSize() const OVERRIDE { | 76 virtual gfx::Size GetBrowserViewMinimumSize() const OVERRIDE { |
75 // Taken from a calculation in BrowserViewLayout. | 77 // Taken from a calculation in BrowserViewLayout. |
76 return gfx::Size(168, 64); | 78 return gfx::Size(168, 64); |
77 } | 79 } |
78 | 80 |
79 virtual bool ShouldShowAvatar() const OVERRIDE { | 81 virtual bool ShouldShowAvatar() const OVERRIDE { |
80 return show_avatar_; | 82 return show_avatar_; |
81 } | 83 } |
82 | 84 |
85 virtual bool IsRegularOrGuestSession() const { | |
86 return true; | |
87 } | |
88 | |
83 virtual gfx::ImageSkia GetOTRAvatarIcon() const OVERRIDE { | 89 virtual gfx::ImageSkia GetOTRAvatarIcon() const OVERRIDE { |
84 // The calculations depend on the size of the OTR resource, and chromeos | 90 // The calculations depend on the size of the OTR resource, and chromeos |
85 // uses a different sized image, so hard code the size of the current | 91 // uses a different sized image, so hard code the size of the current |
86 // windows/linux one. | 92 // windows/linux one. |
87 gfx::ImageSkiaRep rep(gfx::Size(40, 29), 1.0f); | 93 gfx::ImageSkiaRep rep(gfx::Size(40, 29), 1.0f); |
88 gfx::ImageSkia image(rep); | 94 gfx::ImageSkia image(rep); |
89 return image; | 95 return image; |
90 } | 96 } |
91 | 97 |
92 virtual bool IsMaximized() const OVERRIDE { | 98 virtual bool IsMaximized() const OVERRIDE { |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 | 212 |
207 void AddAvatarLabel() { | 213 void AddAvatarLabel() { |
208 avatar_label_ = new views::MenuButton(NULL, string16(), NULL, false); | 214 avatar_label_ = new views::MenuButton(NULL, string16(), NULL, false); |
209 avatar_label_->set_id(VIEW_ID_AVATAR_LABEL); | 215 avatar_label_->set_id(VIEW_ID_AVATAR_LABEL); |
210 root_view_->AddChildView(avatar_label_); | 216 root_view_->AddChildView(avatar_label_); |
211 | 217 |
212 // The avatar label should only be used together with the avatar button. | 218 // The avatar label should only be used together with the avatar button. |
213 AddAvatarButton(); | 219 AddAvatarButton(); |
214 } | 220 } |
215 | 221 |
222 void AddNewAvatarButton() { | |
223 new_avatar_button_ = new views::MenuButton(NULL, string16(), NULL, false); | |
224 new_avatar_button_->set_id(VIEW_ID_NEW_AVATAR_BUTTON); | |
225 root_view_->AddChildView(new_avatar_button_); | |
226 } | |
227 | |
216 void ExpectBasicWindowBounds() { | 228 void ExpectBasicWindowBounds() { |
217 EXPECT_EQ("428,1 25x18", maximize_button_->bounds().ToString()); | 229 EXPECT_EQ("428,1 25x18", maximize_button_->bounds().ToString()); |
218 EXPECT_EQ("402,1 26x18", minimize_button_->bounds().ToString()); | 230 EXPECT_EQ("402,1 26x18", minimize_button_->bounds().ToString()); |
219 EXPECT_EQ("0,0 0x0", restore_button_->bounds().ToString()); | 231 EXPECT_EQ("0,0 0x0", restore_button_->bounds().ToString()); |
220 EXPECT_EQ("453,1 43x18", close_button_->bounds().ToString()); | 232 EXPECT_EQ("453,1 43x18", close_button_->bounds().ToString()); |
221 } | 233 } |
222 | 234 |
223 gfx::Font default_font_; | 235 gfx::Font default_font_; |
224 | 236 |
225 Widget* widget_; | 237 Widget* widget_; |
226 views::View* root_view_; | 238 views::View* root_view_; |
227 OpaqueBrowserFrameViewLayout* layout_manager_; | 239 OpaqueBrowserFrameViewLayout* layout_manager_; |
228 scoped_ptr<TestLayoutDelegate> delegate_; | 240 scoped_ptr<TestLayoutDelegate> delegate_; |
229 | 241 |
230 // Widgets: | 242 // Widgets: |
231 views::ImageButton* minimize_button_; | 243 views::ImageButton* minimize_button_; |
232 views::ImageButton* maximize_button_; | 244 views::ImageButton* maximize_button_; |
233 views::ImageButton* restore_button_; | 245 views::ImageButton* restore_button_; |
234 views::ImageButton* close_button_; | 246 views::ImageButton* close_button_; |
235 | 247 |
236 TabIconView* tab_icon_view_; | 248 TabIconView* tab_icon_view_; |
237 views::Label* window_title_; | 249 views::Label* window_title_; |
238 | 250 |
239 views::MenuButton* menu_button_; | 251 views::MenuButton* menu_button_; |
240 views::MenuButton* avatar_label_; | 252 views::MenuButton* avatar_label_; |
253 views::MenuButton* new_avatar_button_; | |
241 | 254 |
242 DISALLOW_COPY_AND_ASSIGN(OpaqueBrowserFrameViewLayoutTest); | 255 DISALLOW_COPY_AND_ASSIGN(OpaqueBrowserFrameViewLayoutTest); |
243 }; | 256 }; |
244 | 257 |
245 TEST_F(OpaqueBrowserFrameViewLayoutTest, BasicWindow) { | 258 TEST_F(OpaqueBrowserFrameViewLayoutTest, BasicWindow) { |
246 // Tests the layout of a default chrome window with no avatars, no window | 259 // Tests the layout of a default chrome window with no avatars, no window |
247 // titles, and a tabstrip. | 260 // titles, and a tabstrip. |
248 root_view_->Layout(); | 261 root_view_->Layout(); |
249 | 262 |
250 ExpectBasicWindowBounds(); | 263 ExpectBasicWindowBounds(); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
307 ExpectBasicWindowBounds(); | 320 ExpectBasicWindowBounds(); |
308 | 321 |
309 // Check the location of the avatar | 322 // Check the location of the avatar |
310 EXPECT_EQ("7,11 40x29", menu_button_->bounds().ToString()); | 323 EXPECT_EQ("7,11 40x29", menu_button_->bounds().ToString()); |
311 EXPECT_EQ("45,13 352x29", | 324 EXPECT_EQ("45,13 352x29", |
312 layout_manager_->GetBoundsForTabStrip( | 325 layout_manager_->GetBoundsForTabStrip( |
313 delegate_->GetTabstripPreferredSize(), kWidth).ToString()); | 326 delegate_->GetTabstripPreferredSize(), kWidth).ToString()); |
314 EXPECT_EQ("261x73", layout_manager_->GetMinimumSize(kWidth).ToString()); | 327 EXPECT_EQ("261x73", layout_manager_->GetMinimumSize(kWidth).ToString()); |
315 } | 328 } |
316 | 329 |
330 | |
331 TEST_F(OpaqueBrowserFrameViewLayoutTest, WindowWithNewAvatar) { | |
332 CommandLine::ForCurrentProcess()->AppendSwitch( | |
333 switches::kNewProfileManagement); | |
Elliot Glaysher
2013/10/03 21:52:53
Isn't this permanently changing the command line?
noms (inactive)
2013/10/07 21:18:15
The TestClientInitializer has two functions, OnTes
| |
334 | |
335 // Tests a normal tabstrip window with the new style avatar icon. | |
336 AddNewAvatarButton(); | |
337 root_view_->Layout(); | |
338 | |
339 ExpectBasicWindowBounds(); | |
340 | |
341 // Check the location of the caption button | |
342 EXPECT_EQ("385,1 12x20", new_avatar_button_->bounds().ToString()); | |
343 // The basic window bounds are (-1, 13 398x29). There should not be an icon | |
344 // avatar in the left, and the new avatar button has an offset of 5 to its | |
345 // next control. | |
346 EXPECT_EQ("-1,13 381x29", | |
347 layout_manager_->GetBoundsForTabStrip( | |
348 delegate_->GetTabstripPreferredSize(), kWidth).ToString()); | |
349 EXPECT_EQ("261x73", layout_manager_->GetMinimumSize(kWidth).ToString()); | |
350 } | |
351 | |
317 TEST_F(OpaqueBrowserFrameViewLayoutTest, WindowWithAvatarLabelAndButton) { | 352 TEST_F(OpaqueBrowserFrameViewLayoutTest, WindowWithAvatarLabelAndButton) { |
318 AddAvatarLabel(); | 353 AddAvatarLabel(); |
319 root_view_->Layout(); | 354 root_view_->Layout(); |
320 | 355 |
321 ExpectBasicWindowBounds(); | 356 ExpectBasicWindowBounds(); |
322 | 357 |
323 // Check the location of the avatar label relative to the avatar button. | 358 // Check the location of the avatar label relative to the avatar button. |
324 // The label height and width depends on the font size and the text displayed. | 359 // The label height and width depends on the font size and the text displayed. |
325 // This may possibly change, so we don't test it here. | 360 // This may possibly change, so we don't test it here. |
326 EXPECT_EQ(menu_button_->bounds().x() - 2, avatar_label_->bounds().x()); | 361 EXPECT_EQ(menu_button_->bounds().x() - 2, avatar_label_->bounds().x()); |
327 EXPECT_EQ( | 362 EXPECT_EQ( |
328 menu_button_->bounds().bottom() - 3 - avatar_label_->bounds().height(), | 363 menu_button_->bounds().bottom() - 3 - avatar_label_->bounds().height(), |
329 avatar_label_->bounds().y()); | 364 avatar_label_->bounds().y()); |
330 } | 365 } |
OLD | NEW |