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

Side by Side Diff: chrome/browser/ui/panels/panel_browser_view_browsertest.cc

Issue 8114006: Reland the patch to fix the problem that sometimes panel on Windows is not set to top-most. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 2 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/i18n/time_formatting.h" 5 #include "base/i18n/time_formatting.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "chrome/browser/extensions/extension_service.h" 7 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/browser_window.h" 9 #include "chrome/browser/ui/browser_window.h"
10 #include "chrome/browser/ui/panels/base_panel_browser_test.h" 10 #include "chrome/browser/ui/panels/base_panel_browser_test.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 GdkEvent event; 53 GdkEvent event;
54 event.type = GDK_MOTION_NOTIFY; 54 event.type = GDK_MOTION_NOTIFY;
55 DidProcessEvent(&event); 55 DidProcessEvent(&event);
56 #endif 56 #endif
57 } 57 }
58 58
59 private: 59 private:
60 bool is_cursor_in_view_; 60 bool is_cursor_in_view_;
61 }; 61 };
62 62
63 PanelBrowserView* GetBrowserView(Panel* panel) { 63 PanelBrowserView* GetBrowserView(Panel* panel) const {
64 return static_cast<PanelBrowserView*>(panel->native_panel()); 64 return static_cast<PanelBrowserView*>(panel->native_panel());
65 } 65 }
66 66
67 void WaitTillBoundsAnimationFinished(PanelBrowserView* browser_view) { 67 gfx::Rect GetViewBounds(Panel* panel) const {
68 return GetBrowserView(panel)->GetBounds();
69 }
70
71 void SetViewBounds(Panel* panel, const gfx::Rect& rect) const {
72 return GetBrowserView(panel)->SetPanelBounds(rect);
73 }
74
75 gfx::NativeWindow GetNativeWindow(Panel* panel) const {
76 return GetBrowserView(panel)->GetNativeHandle();
77 }
78
79 ui::SlideAnimation* GetBoundsAnimator(Panel* panel) const {
80 return GetBrowserView(panel)->bounds_animator_.get();
81 }
82
83 ui::SlideAnimation* GetSettingsButtonAnimator(Panel* panel) const {
84 return GetBrowserView(panel)->GetFrameView()->
85 settings_button_animator_.get();
86 }
87
88 int GetTitlebarHeight(Panel* panel) const {
89 PanelBrowserFrameView* frame_view = GetBrowserView(panel)->GetFrameView();
90 return frame_view->NonClientTopBorderHeight() -
91 frame_view->NonClientBorderThickness();
92 }
93
94 MockMouseWatcher* CreateTitlebarMouseWatcher(Panel* panel) {
95 PanelBrowserFrameView* frame_view = GetBrowserView(panel)->GetFrameView();
96 MockMouseWatcher* mouse_watcher = new MockMouseWatcher(frame_view);
97 frame_view->set_mouse_watcher(mouse_watcher);
98 return mouse_watcher;
99 }
100
101 PanelBrowserFrameView::PaintState GetTitlebarPaintState(Panel* panel) const {
102 return GetBrowserView(panel)->GetFrameView()->paint_state_;
103 }
104
105 bool IsTitlebarPaintedAsActive(Panel* panel) const {
106 return GetTitlebarPaintState(panel) ==
107 PanelBrowserFrameView::PAINT_AS_ACTIVE;
108 }
109
110 bool IsTitlebarPaintedAsInactive(Panel* panel) const {
111 return GetTitlebarPaintState(panel) ==
112 PanelBrowserFrameView::PAINT_AS_INACTIVE;
113 }
114
115 bool IsTitlebarPaintedForAttention(Panel* panel) const {
116 return GetTitlebarPaintState(panel) ==
117 PanelBrowserFrameView::PAINT_FOR_ATTENTION;
118 }
119
120 int GetControlCount(Panel* panel) const {
121 return GetBrowserView(panel)->GetFrameView()->child_count();
122 }
123
124 TabIconView* GetTitleIcon(Panel* panel) const {
125 return GetBrowserView(panel)->GetFrameView()->title_icon_;
126 }
127
128 views::Label* GetTitleText(Panel* panel) const {
129 return GetBrowserView(panel)->GetFrameView()->title_label_;
130 }
131
132 views::Button* GetSettingsButton(Panel* panel) const {
133 return GetBrowserView(panel)->GetFrameView()->settings_button_;
134 }
135
136 views::Button* GetCloseButton(Panel* panel) const {
137 return GetBrowserView(panel)->GetFrameView()->close_button_;
138 }
139
140 bool ContainsControl(Panel* panel, views::View* control) const {
141 return GetBrowserView(panel)->GetFrameView()->Contains(control);
142 }
143
144 void WaitTillBoundsAnimationFinished(Panel* panel) {
68 // The timer for the animation will only kick in as async task. 145 // The timer for the animation will only kick in as async task.
69 while (browser_view->bounds_animator_->is_animating()) { 146 while (GetBoundsAnimator(panel)->is_animating()) {
70 MessageLoopForUI::current()->PostTask(FROM_HERE, 147 MessageLoopForUI::current()->PostTask(FROM_HERE,
71 new MessageLoop::QuitTask()); 148 new MessageLoop::QuitTask());
72 MessageLoopForUI::current()->RunAllPending(); 149 MessageLoopForUI::current()->RunAllPending();
73 } 150 }
74 } 151 }
75 152
76 void WaitTillSettingsAnimationFinished(PanelBrowserFrameView* frame_view) { 153 void WaitTillSettingsAnimationFinished(Panel* panel) {
77 // The timer for the animation will only kick in as async task. 154 // The timer for the animation will only kick in as async task.
78 while (frame_view->settings_button_animator_->is_animating()) { 155 while (GetSettingsButtonAnimator(panel)->is_animating()) {
79 MessageLoopForUI::current()->PostTask(FROM_HERE, 156 MessageLoopForUI::current()->PostTask(FROM_HERE,
80 new MessageLoop::QuitTask()); 157 new MessageLoop::QuitTask());
81 MessageLoopForUI::current()->RunAllPending(); 158 MessageLoopForUI::current()->RunAllPending();
82 } 159 }
83 } 160 }
84 161
85 void TestShowPanelActiveOrInactive() {
86 CreatePanelParams params1("PanelTest1", gfx::Rect(), SHOW_AS_ACTIVE);
87 Panel* panel1 = CreatePanelWithParams(params1);
88 PanelBrowserView* browser_view1 = GetBrowserView(panel1);
89 PanelBrowserFrameView* frame_view1 = browser_view1->GetFrameView();
90 EXPECT_TRUE(panel1->IsActive());
91 EXPECT_EQ(PanelBrowserFrameView::PAINT_AS_ACTIVE,
92 frame_view1->paint_state_);
93
94 CreatePanelParams params2("PanelTest2", gfx::Rect(), SHOW_AS_INACTIVE);
95 Panel* panel2 = CreatePanelWithParams(params2);
96 PanelBrowserView* browser_view2 = GetBrowserView(panel2);
97 PanelBrowserFrameView* frame_view2 = browser_view2->GetFrameView();
98 EXPECT_FALSE(panel2->IsActive());
99 EXPECT_EQ(PanelBrowserFrameView::PAINT_AS_INACTIVE,
100 frame_view2->paint_state_);
101
102 panel1->Close();
103 panel2->Close();
104 }
105
106 // We put all the testing logic in this class instead of the test so that 162 // We put all the testing logic in this class instead of the test so that
107 // we do not need to declare each new test as a friend of PanelBrowserView 163 // we do not need to declare each new test as a friend of PanelBrowserView
108 // for the purpose of accessing its private members. 164 // for the purpose of accessing its private members.
109 void TestMinimizeAndRestore(bool enable_auto_hiding) { 165 void TestMinimizeAndRestore(bool enable_auto_hiding) {
110 PanelManager* panel_manager = PanelManager::GetInstance(); 166 PanelManager* panel_manager = PanelManager::GetInstance();
111 int expected_bottom_on_minimized = testing_work_area().height(); 167 int expected_bottom_on_minimized = testing_work_area().height();
112 int expected_bottom_on_unminimized = expected_bottom_on_minimized; 168 int expected_bottom_on_unminimized = expected_bottom_on_minimized;
113 169
114 // Turn on auto-hiding if requested. 170 // Turn on auto-hiding if requested.
115 static const int bottom_thickness = 40; 171 static const int bottom_thickness = 40;
(...skipping 14 matching lines...) Expand all
130 EXPECT_EQ(0, panel_manager->minimized_panel_count()); 186 EXPECT_EQ(0, panel_manager->minimized_panel_count());
131 int initial_height = panel1->GetBounds().height(); 187 int initial_height = panel1->GetBounds().height();
132 int titlebar_height = frame_view1->NonClientTopBorderHeight(); 188 int titlebar_height = frame_view1->NonClientTopBorderHeight();
133 189
134 panel1->SetExpansionState(Panel::MINIMIZED); 190 panel1->SetExpansionState(Panel::MINIMIZED);
135 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); 191 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state());
136 EXPECT_LT(panel1->GetBounds().height(), titlebar_height); 192 EXPECT_LT(panel1->GetBounds().height(), titlebar_height);
137 EXPECT_GT(panel1->GetBounds().height(), 0); 193 EXPECT_GT(panel1->GetBounds().height(), 0);
138 EXPECT_EQ(expected_bottom_on_minimized, panel1->GetBounds().bottom()); 194 EXPECT_EQ(expected_bottom_on_minimized, panel1->GetBounds().bottom());
139 EXPECT_EQ(1, panel_manager->minimized_panel_count()); 195 EXPECT_EQ(1, panel_manager->minimized_panel_count());
140 WaitTillBoundsAnimationFinished(browser_view1); 196 WaitTillBoundsAnimationFinished(panel1);
141 EXPECT_FALSE(panel1->IsActive()); 197 EXPECT_FALSE(panel1->IsActive());
142 198
143 panel1->SetExpansionState(Panel::TITLE_ONLY); 199 panel1->SetExpansionState(Panel::TITLE_ONLY);
144 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); 200 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
145 EXPECT_EQ(titlebar_height, panel1->GetBounds().height()); 201 EXPECT_EQ(titlebar_height, panel1->GetBounds().height());
146 EXPECT_EQ(expected_bottom_on_unminimized, panel1->GetBounds().bottom()); 202 EXPECT_EQ(expected_bottom_on_unminimized, panel1->GetBounds().bottom());
147 EXPECT_EQ(1, panel_manager->minimized_panel_count()); 203 EXPECT_EQ(1, panel_manager->minimized_panel_count());
148 WaitTillBoundsAnimationFinished(browser_view1); 204 WaitTillBoundsAnimationFinished(panel1);
149 EXPECT_TRUE(frame_view1->close_button_->IsVisible()); 205 EXPECT_TRUE(frame_view1->close_button_->IsVisible());
150 EXPECT_TRUE(frame_view1->title_icon_->IsVisible()); 206 EXPECT_TRUE(frame_view1->title_icon_->IsVisible());
151 EXPECT_TRUE(frame_view1->title_label_->IsVisible()); 207 EXPECT_TRUE(frame_view1->title_label_->IsVisible());
152 208
153 panel1->SetExpansionState(Panel::EXPANDED); 209 panel1->SetExpansionState(Panel::EXPANDED);
154 EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state()); 210 EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state());
155 EXPECT_EQ(initial_height, panel1->GetBounds().height()); 211 EXPECT_EQ(initial_height, panel1->GetBounds().height());
156 EXPECT_EQ(expected_bottom_on_unminimized, panel1->GetBounds().bottom()); 212 EXPECT_EQ(expected_bottom_on_unminimized, panel1->GetBounds().bottom());
157 EXPECT_EQ(0, panel_manager->minimized_panel_count()); 213 EXPECT_EQ(0, panel_manager->minimized_panel_count());
158 WaitTillBoundsAnimationFinished(browser_view1); 214 WaitTillBoundsAnimationFinished(panel1);
159 EXPECT_TRUE(frame_view1->close_button_->IsVisible()); 215 EXPECT_TRUE(frame_view1->close_button_->IsVisible());
160 EXPECT_TRUE(frame_view1->title_icon_->IsVisible()); 216 EXPECT_TRUE(frame_view1->title_icon_->IsVisible());
161 EXPECT_TRUE(frame_view1->title_label_->IsVisible()); 217 EXPECT_TRUE(frame_view1->title_label_->IsVisible());
162 218
163 panel1->SetExpansionState(Panel::MINIMIZED); 219 panel1->SetExpansionState(Panel::MINIMIZED);
164 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); 220 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state());
165 EXPECT_LT(panel1->GetBounds().height(), titlebar_height); 221 EXPECT_LT(panel1->GetBounds().height(), titlebar_height);
166 EXPECT_GT(panel1->GetBounds().height(), 0); 222 EXPECT_GT(panel1->GetBounds().height(), 0);
167 EXPECT_EQ(expected_bottom_on_minimized, panel1->GetBounds().bottom()); 223 EXPECT_EQ(expected_bottom_on_minimized, panel1->GetBounds().bottom());
168 EXPECT_EQ(1, panel_manager->minimized_panel_count()); 224 EXPECT_EQ(1, panel_manager->minimized_panel_count());
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 panel->GetBounds().bottom()); 382 panel->GetBounds().bottom());
327 EXPECT_EQ(testing_work_area().right() - right_bar_thickness, 383 EXPECT_EQ(testing_work_area().right() - right_bar_thickness,
328 panel->GetBounds().right()); 384 panel->GetBounds().right());
329 385
330 panel->Close(); 386 panel->Close();
331 } 387 }
332 }; 388 };
333 389
334 // Panel is not supported for Linux view yet. 390 // Panel is not supported for Linux view yet.
335 #if !defined(OS_LINUX) || !defined(TOOLKIT_VIEWS) 391 #if !defined(OS_LINUX) || !defined(TOOLKIT_VIEWS)
336 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, CreatePanel) { 392 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, CreatePanelBasic) {
337 Panel* panel = CreatePanel("PanelTest"); 393 CreatePanelParams params(
338 PanelBrowserView* browser_view = GetBrowserView(panel); 394 "PanelTest", gfx::Rect(0, 0, 200, 150), SHOW_AS_ACTIVE);
339 PanelBrowserFrameView* frame_view = browser_view->GetFrameView(); 395 Panel* panel = CreatePanelWithParams(params);
340 396
341 // The bounds animation should not be triggered when the panel is up for the 397 // Validate basic window properties.
342 // first time. 398 #if defined(OS_WIN)
343 EXPECT_FALSE(browser_view->bounds_animator_.get()); 399 HWND native_window = GetNativeWindow(panel);
344 400
345 // We should have icon, text, settings button and close button. 401 RECT window_rect;
346 EXPECT_EQ(4, frame_view->child_count()); 402 EXPECT_TRUE(::GetWindowRect(native_window, &window_rect));
347 EXPECT_TRUE(frame_view->Contains(frame_view->title_icon_)); 403 EXPECT_EQ(200, window_rect.right - window_rect.left);
348 EXPECT_TRUE(frame_view->Contains(frame_view->title_label_)); 404 EXPECT_EQ(150, window_rect.bottom - window_rect.top);
349 EXPECT_TRUE(frame_view->Contains(frame_view->settings_button_));
350 EXPECT_TRUE(frame_view->Contains(frame_view->close_button_));
351 405
352 // These controls should be visible. 406 EXPECT_TRUE(::IsWindowVisible(native_window));
353 EXPECT_TRUE(frame_view->title_icon_->IsVisible()); 407 #endif
354 EXPECT_TRUE(frame_view->title_label_->IsVisible());
355 EXPECT_TRUE(frame_view->close_button_->IsVisible());
356
357 // Validate their layouts.
358 int titlebar_height = frame_view->NonClientTopBorderHeight() -
359 frame_view->NonClientBorderThickness();
360 EXPECT_GT(frame_view->title_icon_->width(), 0);
361 EXPECT_GT(frame_view->title_icon_->height(), 0);
362 EXPECT_LT(frame_view->title_icon_->height(), titlebar_height);
363 EXPECT_GT(frame_view->title_label_->width(), 0);
364 EXPECT_GT(frame_view->title_label_->height(), 0);
365 EXPECT_LT(frame_view->title_label_->height(), titlebar_height);
366 EXPECT_GT(frame_view->settings_button_->width(), 0);
367 EXPECT_GT(frame_view->settings_button_->height(), 0);
368 EXPECT_LT(frame_view->settings_button_->height(), titlebar_height);
369 EXPECT_GT(frame_view->close_button_->width(), 0);
370 EXPECT_GT(frame_view->close_button_->height(), 0);
371 EXPECT_LT(frame_view->close_button_->height(), titlebar_height);
372 EXPECT_LT(frame_view->title_icon_->x() + frame_view->title_icon_->width(),
373 frame_view->title_label_->x());
374 EXPECT_LT(frame_view->title_label_->x() + frame_view->title_label_->width(),
375 frame_view->settings_button_->x());
376 EXPECT_LT(
377 frame_view->settings_button_->x() + frame_view->settings_button_->width(),
378 frame_view->close_button_->x());
379
380 // Validate that the controls should be updated when the activation state is
381 // changed.
382 frame_view->UpdateControlStyles(PanelBrowserFrameView::PAINT_AS_ACTIVE);
383 SkColor title_label_color1 = frame_view->title_label_->GetColor();
384 frame_view->UpdateControlStyles(PanelBrowserFrameView::PAINT_AS_INACTIVE);
385 SkColor title_label_color2 = frame_view->title_label_->GetColor();
386 EXPECT_NE(title_label_color1, title_label_color2);
387 408
388 panel->Close(); 409 panel->Close();
389 } 410 }
390 411
391 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, ShowPanelActiveOrInactive) { 412 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, CreatePanelActive) {
392 TestShowPanelActiveOrInactive(); 413 CreatePanelParams params("PanelTest", gfx::Rect(), SHOW_AS_ACTIVE);
414 Panel* panel = CreatePanelWithParams(params);
415
416 // Validate it is active.
417 EXPECT_TRUE(panel->IsActive());
418 EXPECT_TRUE(IsTitlebarPaintedAsActive(panel));
419
420 // Validate window styles. We want to ensure that the window is created
421 // with expected styles regardless of its active state.
422 #if defined(OS_WIN)
423 HWND native_window = GetNativeWindow(panel);
424
425 LONG styles = ::GetWindowLong(native_window, GWL_STYLE);
426 EXPECT_EQ(0, styles & WS_MAXIMIZEBOX);
427 EXPECT_EQ(0, styles & WS_MINIMIZEBOX);
428 EXPECT_EQ(0, styles & WS_THICKFRAME);
429
430 LONG ext_styles = ::GetWindowLong(native_window, GWL_EXSTYLE);
431 EXPECT_EQ(WS_EX_TOPMOST, ext_styles & WS_EX_TOPMOST);
432 #endif
433
434 panel->Close();
435 }
436
437 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, CreatePanelInactive) {
438 CreatePanelParams params("PanelTest", gfx::Rect(), SHOW_AS_INACTIVE);
439 Panel* panel = CreatePanelWithParams(params);
440
441 // Validate it is inactive.
442 EXPECT_FALSE(panel->IsActive());
443 EXPECT_FALSE(IsTitlebarPaintedAsActive(panel));
444
445 // Validate window styles. We want to ensure that the window is created
446 // with expected styles regardless of its active state.
447 #if defined(OS_WIN)
448 HWND native_window = GetNativeWindow(panel);
449
450 LONG styles = ::GetWindowLong(native_window, GWL_STYLE);
451 EXPECT_EQ(0, styles & WS_MAXIMIZEBOX);
452 EXPECT_EQ(0, styles & WS_MINIMIZEBOX);
453 EXPECT_EQ(0, styles & WS_THICKFRAME);
454
455 LONG ext_styles = ::GetWindowLong(native_window, GWL_EXSTYLE);
456 EXPECT_EQ(WS_EX_TOPMOST, ext_styles & WS_EX_TOPMOST);
457 #endif
458
459 panel->Close();
460 }
461
462 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, PanelLayout) {
463 Panel* panel = CreatePanel("PanelTest");
464
465 views::View* title_icon = GetTitleIcon(panel);
466 views::View* title_text = GetTitleText(panel);
467 views::View* settings_button = GetSettingsButton(panel);
468 views::View* close_button = GetCloseButton(panel);
469
470 // We should have icon, text, settings button and close button.
471 EXPECT_EQ(4, GetControlCount(panel));
472 EXPECT_TRUE(ContainsControl(panel, title_icon));
473 EXPECT_TRUE(ContainsControl(panel, title_text));
474 EXPECT_TRUE(ContainsControl(panel, settings_button));
475 EXPECT_TRUE(ContainsControl(panel, close_button));
476
477 // These controls should be visible.
478 EXPECT_TRUE(title_icon->IsVisible());
479 EXPECT_TRUE(title_text->IsVisible());
480 EXPECT_TRUE(close_button->IsVisible());
481
482 // Validate their layouts.
483 int titlebar_height = GetTitlebarHeight(panel);
484 EXPECT_GT(title_icon->width(), 0);
485 EXPECT_GT(title_icon->height(), 0);
486 EXPECT_LT(title_icon->height(), titlebar_height);
487 EXPECT_GT(title_text->width(), 0);
488 EXPECT_GT(title_text->height(), 0);
489 EXPECT_LT(title_text->height(), titlebar_height);
490 EXPECT_GT(settings_button->width(), 0);
491 EXPECT_GT(settings_button->height(), 0);
492 EXPECT_LT(settings_button->height(), titlebar_height);
493 EXPECT_GT(close_button->width(), 0);
494 EXPECT_GT(close_button->height(), 0);
495 EXPECT_LT(close_button->height(), titlebar_height);
496 EXPECT_LT(title_icon->x() + title_icon->width(), title_text->x());
497 EXPECT_LT(title_text->x() + title_text->width(), settings_button->x());
498 EXPECT_LT(settings_button->x() + settings_button->width(), close_button->x());
499 }
500
501 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, Deactivate) {
502 // When a panel is created, it should be active at first.
503 Panel* panel = CreatePanel("PanelTest");
504 EXPECT_TRUE(panel->IsActive());
505
506 // When the panel is deactivated, the appearance of controls should be
507 // updated.
508 views::Label* title_text = GetTitleText(panel);
509 SkColor title_text_color_before = title_text->GetColor();
510
511 panel->Deactivate();
512 EXPECT_FALSE(panel->IsActive());
513
514 SkColor title_text_color_after = title_text->GetColor();
515 EXPECT_NE(title_text_color_before, title_text_color_after);
393 } 516 }
394 517
395 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, ShowOrHideSettingsButton) { 518 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, ShowOrHideSettingsButton) {
396 Panel* panel = CreatePanel("PanelTest"); 519 Panel* panel = CreatePanel("PanelTest");
397 PanelBrowserFrameView* frame_view = GetBrowserView(panel)->GetFrameView(); 520 views::View* settings_button = GetSettingsButton(panel);
398 521
399 // Create and hook up the MockMouseWatcher so that we can simulate if the 522 // Create and hook up the MockMouseWatcher so that we can simulate if the
400 // mouse is over the panel. 523 // mouse is over the panel.
401 MockMouseWatcher* mouse_watcher = new MockMouseWatcher(frame_view); 524 MockMouseWatcher* mouse_watcher = CreateTitlebarMouseWatcher(panel);
402 frame_view->set_mouse_watcher(mouse_watcher);
403 525
404 // When the panel is created, it is active. Since we cannot programatically 526 // When the panel is created, it is active. Since we cannot programatically
405 // bring the panel back to active state once it is deactivated, we have to 527 // bring the panel back to active state once it is deactivated, we have to
406 // test the cases that the panel is active first. 528 // test the cases that the panel is active first.
407 EXPECT_TRUE(panel->IsActive()); 529 EXPECT_TRUE(panel->IsActive());
408 530
409 // When the panel is active, the settings button should always be visible. 531 // When the panel is active, the settings button should always be visible.
410 mouse_watcher->MoveMouse(true); 532 mouse_watcher->MoveMouse(true);
411 EXPECT_TRUE(frame_view->settings_button_->IsVisible()); 533 EXPECT_TRUE(settings_button->IsVisible());
412 mouse_watcher->MoveMouse(false); 534 mouse_watcher->MoveMouse(false);
413 EXPECT_TRUE(frame_view->settings_button_->IsVisible()); 535 EXPECT_TRUE(settings_button->IsVisible());
414 536
415 // When the panel is inactive, the options button is active per the mouse over 537 // When the panel is inactive, the options button is active per the mouse over
416 // the panel or not. 538 // the panel or not.
417 panel->Deactivate(); 539 panel->Deactivate();
418 EXPECT_FALSE(panel->IsActive()); 540 EXPECT_FALSE(panel->IsActive());
419 WaitTillSettingsAnimationFinished(frame_view); 541 WaitTillSettingsAnimationFinished(panel);
420 EXPECT_FALSE(frame_view->settings_button_->IsVisible()); 542 EXPECT_FALSE(settings_button->IsVisible());
421 543
422 mouse_watcher->MoveMouse(true); 544 mouse_watcher->MoveMouse(true);
423 WaitTillSettingsAnimationFinished(frame_view); 545 WaitTillSettingsAnimationFinished(panel);
424 EXPECT_TRUE(frame_view->settings_button_->IsVisible()); 546 EXPECT_TRUE(settings_button->IsVisible());
425 mouse_watcher->MoveMouse(false); 547 mouse_watcher->MoveMouse(false);
426 WaitTillSettingsAnimationFinished(frame_view); 548 WaitTillSettingsAnimationFinished(panel);
427 EXPECT_FALSE(frame_view->settings_button_->IsVisible()); 549 EXPECT_FALSE(settings_button->IsVisible());
428 } 550 }
429 551
430 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, SetBoundsAnimation) { 552 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, SetBoundsAnimation) {
431 Panel* panel = CreatePanel("PanelTest"); 553 Panel* panel = CreatePanel("PanelTest");
432 PanelBrowserView* browser_view = GetBrowserView(panel); 554 PanelBrowserView* browser_view = GetBrowserView(panel);
433 555
556 // The bounds animation should not be triggered when the panel is up for the
557 // first time.
558 EXPECT_FALSE(GetBoundsAnimator(panel));
559
434 // Validate that animation should be triggered when bounds are changed. 560 // Validate that animation should be triggered when bounds are changed.
435 gfx::Rect target_bounds(browser_view->GetBounds()); 561 gfx::Rect target_bounds(GetViewBounds(panel));
436 target_bounds.Offset(20, -30); 562 target_bounds.Offset(20, -30);
437 target_bounds.set_width(target_bounds.width() + 100); 563 target_bounds.set_width(target_bounds.width() + 100);
438 target_bounds.set_height(target_bounds.height() + 50); 564 target_bounds.set_height(target_bounds.height() + 50);
439 browser_view->SetPanelBounds(target_bounds); 565 SetViewBounds(panel, target_bounds);
440 ASSERT_TRUE(browser_view->bounds_animator_.get()); 566 ASSERT_TRUE(GetBoundsAnimator(panel));
441 EXPECT_TRUE(browser_view->bounds_animator_->is_animating()); 567 EXPECT_TRUE(GetBoundsAnimator(panel)->is_animating());
442 EXPECT_NE(browser_view->GetBounds(), target_bounds); 568 EXPECT_NE(GetViewBounds(panel), target_bounds);
443 WaitTillBoundsAnimationFinished(browser_view); 569 WaitTillBoundsAnimationFinished(panel);
444 EXPECT_EQ(browser_view->GetBounds(), target_bounds); 570 EXPECT_EQ(GetViewBounds(panel), target_bounds);
445 571
446 // Validates that no animation should be triggered for the panel currently 572 // Validates that no animation should be triggered for the panel currently
447 // being dragged. 573 // being dragged.
448 browser_view->OnTitlebarMousePressed(gfx::Point( 574 browser_view->OnTitlebarMousePressed(gfx::Point(
449 target_bounds.x(), target_bounds.y())); 575 target_bounds.x(), target_bounds.y()));
450 browser_view->OnTitlebarMouseDragged(gfx::Point( 576 browser_view->OnTitlebarMouseDragged(gfx::Point(
451 target_bounds.x() + 5, target_bounds.y() + 5)); 577 target_bounds.x() + 5, target_bounds.y() + 5));
452 EXPECT_FALSE(browser_view->bounds_animator_->is_animating()); 578 EXPECT_FALSE(GetBoundsAnimator(panel)->is_animating());
453 browser_view->OnTitlebarMouseCaptureLost(); 579 browser_view->OnTitlebarMouseCaptureLost();
454 580
455 panel->Close(); 581 panel->Close();
456 } 582 }
457 583
458 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, 584 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest,
459 MinimizeAndRestoreOnNormalTaskBar) { 585 MinimizeAndRestoreOnNormalTaskBar) {
460 TestMinimizeAndRestore(false); 586 TestMinimizeAndRestore(false);
461 } 587 }
462 588
463 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, 589 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest,
464 MinimizeAndRestoreOnAutoHideTaskBar) { 590 MinimizeAndRestoreOnAutoHideTaskBar) {
465 TestMinimizeAndRestore(true); 591 TestMinimizeAndRestore(true);
466 } 592 }
467 593
468 // TODO(jianli): Investigate why this fails on win trunk build. 594 // TODO(jianli): Investigate why this fails on win trunk build.
469 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, DISABLED_DrawAttention) { 595 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, DISABLED_DrawAttention) {
470 TestDrawAttention(); 596 TestDrawAttention();
471 } 597 }
472 598
473 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, ChangeAutoHideTaskBarThickness) { 599 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, ChangeAutoHideTaskBarThickness) {
474 TestChangeAutoHideTaskBarThickness(); 600 TestChangeAutoHideTaskBarThickness();
475 } 601 }
476 #endif 602 #endif
OLDNEW
« no previous file with comments | « chrome/browser/ui/panels/panel_browser_view.cc ('k') | chrome/browser/ui/views/frame/browser_frame.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698