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 "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 17 matching lines...) Expand all Loading... |
28 #include "ui/views/controls/image_view.h" | 28 #include "ui/views/controls/image_view.h" |
29 #include "ui/views/controls/label.h" | 29 #include "ui/views/controls/label.h" |
30 #include "ui/views/controls/link.h" | 30 #include "ui/views/controls/link.h" |
31 #include "ui/views/controls/textfield/textfield.h" | 31 #include "ui/views/controls/textfield/textfield.h" |
32 | 32 |
33 class PanelBrowserViewTest : public BasePanelBrowserTest { | 33 class PanelBrowserViewTest : public BasePanelBrowserTest { |
34 public: | 34 public: |
35 PanelBrowserViewTest() : BasePanelBrowserTest() { } | 35 PanelBrowserViewTest() : BasePanelBrowserTest() { } |
36 | 36 |
37 protected: | 37 protected: |
38 class MockMouseWatcher : public PanelBrowserFrameView::MouseWatcher { | |
39 public: | |
40 explicit MockMouseWatcher(PanelBrowserFrameView* view) | |
41 : PanelBrowserFrameView::MouseWatcher(view), | |
42 is_cursor_in_view_(false) { | |
43 } | |
44 | |
45 virtual bool IsCursorInViewBounds() const { | |
46 return is_cursor_in_view_; | |
47 } | |
48 | |
49 void MoveMouse(bool is_cursor_in_view) { | |
50 is_cursor_in_view_ = is_cursor_in_view; | |
51 | |
52 #if defined(OS_WIN) | |
53 MSG msg; | |
54 msg.message = WM_MOUSEMOVE; | |
55 DidProcessEvent(msg); | |
56 #elif defined(USE_AURA) | |
57 NOTIMPLEMENTED(); | |
58 #elif defined(TOOLKIT_GTK) | |
59 GdkEvent event; | |
60 event.type = GDK_MOTION_NOTIFY; | |
61 DidProcessEvent(&event); | |
62 #endif | |
63 } | |
64 | |
65 private: | |
66 bool is_cursor_in_view_; | |
67 }; | |
68 | |
69 PanelBrowserView* GetBrowserView(Panel* panel) const { | 38 PanelBrowserView* GetBrowserView(Panel* panel) const { |
70 return static_cast<PanelBrowserView*>(panel->native_panel()); | 39 return static_cast<PanelBrowserView*>(panel->native_panel()); |
71 } | 40 } |
72 | 41 |
73 gfx::Rect GetViewBounds(Panel* panel) const { | 42 gfx::Rect GetViewBounds(Panel* panel) const { |
74 return GetBrowserView(panel)->GetBounds(); | 43 return GetBrowserView(panel)->GetBounds(); |
75 } | 44 } |
76 | 45 |
77 void SetViewBounds(Panel* panel, const gfx::Rect& rect) const { | 46 void SetViewBounds(Panel* panel, const gfx::Rect& rect) const { |
78 return GetBrowserView(panel)->SetPanelBounds(rect); | 47 return GetBrowserView(panel)->SetPanelBounds(rect); |
79 } | 48 } |
80 | 49 |
81 gfx::NativeWindow GetNativeWindow(Panel* panel) const { | 50 gfx::NativeWindow GetNativeWindow(Panel* panel) const { |
82 return GetBrowserView(panel)->GetNativeHandle(); | 51 return GetBrowserView(panel)->GetNativeHandle(); |
83 } | 52 } |
84 | 53 |
85 PanelBoundsAnimation* GetBoundsAnimator(Panel* panel) const { | 54 PanelBoundsAnimation* GetBoundsAnimator(Panel* panel) const { |
86 return GetBrowserView(panel)->bounds_animator_.get(); | 55 return GetBrowserView(panel)->bounds_animator_.get(); |
87 } | 56 } |
88 | 57 |
89 ui::LinearAnimation* GetSettingsButtonAnimator(Panel* panel) const { | |
90 return GetBrowserView(panel)->GetFrameView()-> | |
91 settings_button_animator_.get(); | |
92 } | |
93 | |
94 int GetTitlebarHeight(Panel* panel) const { | 58 int GetTitlebarHeight(Panel* panel) const { |
95 PanelBrowserFrameView* frame_view = GetBrowserView(panel)->GetFrameView(); | 59 PanelBrowserFrameView* frame_view = GetBrowserView(panel)->GetFrameView(); |
96 return frame_view->NonClientTopBorderHeight() - | 60 return frame_view->NonClientTopBorderHeight() - |
97 frame_view->NonClientBorderThickness(); | 61 frame_view->NonClientBorderThickness(); |
98 } | 62 } |
99 | 63 |
100 MockMouseWatcher* CreateTitlebarMouseWatcher(Panel* panel) { | |
101 PanelBrowserFrameView* frame_view = GetBrowserView(panel)->GetFrameView(); | |
102 MockMouseWatcher* mouse_watcher = new MockMouseWatcher(frame_view); | |
103 frame_view->set_mouse_watcher(mouse_watcher); | |
104 return mouse_watcher; | |
105 } | |
106 | |
107 PanelBrowserFrameView::PaintState GetTitlebarPaintState(Panel* panel) const { | 64 PanelBrowserFrameView::PaintState GetTitlebarPaintState(Panel* panel) const { |
108 return GetBrowserView(panel)->GetFrameView()->paint_state_; | 65 return GetBrowserView(panel)->GetFrameView()->paint_state_; |
109 } | 66 } |
110 | 67 |
111 bool IsTitlebarPaintedAsActive(Panel* panel) const { | 68 bool IsTitlebarPaintedAsActive(Panel* panel) const { |
112 return GetTitlebarPaintState(panel) == | 69 return GetTitlebarPaintState(panel) == |
113 PanelBrowserFrameView::PAINT_AS_ACTIVE; | 70 PanelBrowserFrameView::PAINT_AS_ACTIVE; |
114 } | 71 } |
115 | 72 |
116 bool IsTitlebarPaintedAsInactive(Panel* panel) const { | 73 bool IsTitlebarPaintedAsInactive(Panel* panel) const { |
(...skipping 11 matching lines...) Expand all Loading... |
128 } | 85 } |
129 | 86 |
130 TabIconView* GetTitleIcon(Panel* panel) const { | 87 TabIconView* GetTitleIcon(Panel* panel) const { |
131 return GetBrowserView(panel)->GetFrameView()->title_icon_; | 88 return GetBrowserView(panel)->GetFrameView()->title_icon_; |
132 } | 89 } |
133 | 90 |
134 views::Label* GetTitleText(Panel* panel) const { | 91 views::Label* GetTitleText(Panel* panel) const { |
135 return GetBrowserView(panel)->GetFrameView()->title_label_; | 92 return GetBrowserView(panel)->GetFrameView()->title_label_; |
136 } | 93 } |
137 | 94 |
138 views::Button* GetSettingsButton(Panel* panel) const { | |
139 return GetBrowserView(panel)->GetFrameView()->settings_button_; | |
140 } | |
141 | |
142 views::Button* GetCloseButton(Panel* panel) const { | 95 views::Button* GetCloseButton(Panel* panel) const { |
143 return GetBrowserView(panel)->GetFrameView()->close_button_; | 96 return GetBrowserView(panel)->GetFrameView()->close_button_; |
144 } | 97 } |
145 | 98 |
146 bool ContainsControl(Panel* panel, views::View* control) const { | 99 bool ContainsControl(Panel* panel, views::View* control) const { |
147 return GetBrowserView(panel)->GetFrameView()->Contains(control); | 100 return GetBrowserView(panel)->GetFrameView()->Contains(control); |
148 } | 101 } |
149 | 102 |
150 void WaitTillBoundsAnimationFinished(Panel* panel) { | 103 void WaitTillBoundsAnimationFinished(Panel* panel) { |
151 // The timer for the animation will only kick in as async task. | 104 // The timer for the animation will only kick in as async task. |
152 while (GetBoundsAnimator(panel)->is_animating()) { | 105 while (GetBoundsAnimator(panel)->is_animating()) { |
153 MessageLoopForUI::current()->PostTask(FROM_HERE, | 106 MessageLoopForUI::current()->PostTask(FROM_HERE, |
154 MessageLoop::QuitClosure()); | 107 MessageLoop::QuitClosure()); |
155 MessageLoopForUI::current()->RunAllPending(); | 108 MessageLoopForUI::current()->RunAllPending(); |
156 } | 109 } |
157 } | 110 } |
158 | 111 |
159 void WaitTillSettingsAnimationFinished(Panel* panel) { | |
160 // The timer for the animation will only kick in as async task. | |
161 while (GetSettingsButtonAnimator(panel)->is_animating()) { | |
162 MessageLoopForUI::current()->PostTask(FROM_HERE, | |
163 MessageLoop::QuitClosure()); | |
164 MessageLoopForUI::current()->RunAllPending(); | |
165 } | |
166 } | |
167 | |
168 void ClosePanelAndWaitForNotification(Panel* panel) { | 112 void ClosePanelAndWaitForNotification(Panel* panel) { |
169 ui_test_utils::WindowedNotificationObserver signal( | 113 ui_test_utils::WindowedNotificationObserver signal( |
170 chrome::NOTIFICATION_BROWSER_CLOSED, | 114 chrome::NOTIFICATION_BROWSER_CLOSED, |
171 content::Source<Browser>(panel->browser())); | 115 content::Source<Browser>(panel->browser())); |
172 panel->Close(); | 116 panel->Close(); |
173 signal.Wait(); | 117 signal.Wait(); |
174 } | 118 } |
175 | 119 |
176 // We put all the testing logic in this class instead of the test so that | 120 // We put all the testing logic in this class instead of the test so that |
177 // we do not need to declare each new test as a friend of PanelBrowserView | 121 // we do not need to declare each new test as a friend of PanelBrowserView |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 #endif | 382 #endif |
439 | 383 |
440 panel->Close(); | 384 panel->Close(); |
441 } | 385 } |
442 | 386 |
443 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, PanelLayout) { | 387 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, PanelLayout) { |
444 Panel* panel = CreatePanel("PanelTest"); | 388 Panel* panel = CreatePanel("PanelTest"); |
445 | 389 |
446 views::View* title_icon = GetTitleIcon(panel); | 390 views::View* title_icon = GetTitleIcon(panel); |
447 views::View* title_text = GetTitleText(panel); | 391 views::View* title_text = GetTitleText(panel); |
448 views::View* settings_button = GetSettingsButton(panel); | |
449 views::View* close_button = GetCloseButton(panel); | 392 views::View* close_button = GetCloseButton(panel); |
450 | 393 |
451 // We should have icon, text, settings button and close button. | 394 // We should have icon, text, settings button and close button. |
452 EXPECT_EQ(4, GetControlCount(panel)); | 395 EXPECT_EQ(3, GetControlCount(panel)); |
453 EXPECT_TRUE(ContainsControl(panel, title_icon)); | 396 EXPECT_TRUE(ContainsControl(panel, title_icon)); |
454 EXPECT_TRUE(ContainsControl(panel, title_text)); | 397 EXPECT_TRUE(ContainsControl(panel, title_text)); |
455 EXPECT_TRUE(ContainsControl(panel, settings_button)); | |
456 EXPECT_TRUE(ContainsControl(panel, close_button)); | 398 EXPECT_TRUE(ContainsControl(panel, close_button)); |
457 | 399 |
458 // These controls should be visible. | 400 // These controls should be visible. |
459 EXPECT_TRUE(title_icon->visible()); | 401 EXPECT_TRUE(title_icon->visible()); |
460 EXPECT_TRUE(title_text->visible()); | 402 EXPECT_TRUE(title_text->visible()); |
461 EXPECT_TRUE(close_button->visible()); | 403 EXPECT_TRUE(close_button->visible()); |
462 | 404 |
463 // Validate their layouts. | 405 // Validate their layouts. |
464 int titlebar_height = GetTitlebarHeight(panel); | 406 int titlebar_height = GetTitlebarHeight(panel); |
465 EXPECT_GT(title_icon->width(), 0); | 407 EXPECT_GT(title_icon->width(), 0); |
466 EXPECT_GT(title_icon->height(), 0); | 408 EXPECT_GT(title_icon->height(), 0); |
467 EXPECT_LT(title_icon->height(), titlebar_height); | 409 EXPECT_LT(title_icon->height(), titlebar_height); |
468 EXPECT_GT(title_text->width(), 0); | 410 EXPECT_GT(title_text->width(), 0); |
469 EXPECT_GT(title_text->height(), 0); | 411 EXPECT_GT(title_text->height(), 0); |
470 EXPECT_LT(title_text->height(), titlebar_height); | 412 EXPECT_LT(title_text->height(), titlebar_height); |
471 EXPECT_GT(settings_button->width(), 0); | |
472 EXPECT_GT(settings_button->height(), 0); | |
473 EXPECT_LT(settings_button->height(), titlebar_height); | |
474 EXPECT_GT(close_button->width(), 0); | 413 EXPECT_GT(close_button->width(), 0); |
475 EXPECT_GT(close_button->height(), 0); | 414 EXPECT_GT(close_button->height(), 0); |
476 EXPECT_LT(close_button->height(), titlebar_height); | 415 EXPECT_LT(close_button->height(), titlebar_height); |
477 EXPECT_LT(title_icon->x() + title_icon->width(), title_text->x()); | 416 EXPECT_LT(title_icon->x() + title_icon->width(), title_text->x()); |
478 EXPECT_LT(title_text->x() + title_text->width(), settings_button->x()); | 417 EXPECT_LT(title_text->x() + title_text->width(), close_button->x()); |
479 EXPECT_LT(settings_button->x() + settings_button->width(), close_button->x()); | |
480 } | |
481 | |
482 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, ShowOrHideSettingsButton) { | |
483 Panel* panel = CreatePanel("PanelTest"); | |
484 views::View* settings_button = GetSettingsButton(panel); | |
485 | |
486 // Create and hook up the MockMouseWatcher so that we can simulate if the | |
487 // mouse is over the panel. | |
488 MockMouseWatcher* mouse_watcher = CreateTitlebarMouseWatcher(panel); | |
489 | |
490 // When the panel is created, it is active. Since we cannot programatically | |
491 // bring the panel back to active state once it is deactivated, we have to | |
492 // test the cases that the panel is active first. | |
493 EXPECT_TRUE(panel->IsActive()); | |
494 | |
495 // When the panel is active, the settings button should always be visible. | |
496 mouse_watcher->MoveMouse(true); | |
497 EXPECT_TRUE(settings_button->visible()); | |
498 mouse_watcher->MoveMouse(false); | |
499 EXPECT_TRUE(settings_button->visible()); | |
500 | |
501 // When the panel is inactive, the options button is active per the mouse over | |
502 // the panel or not. | |
503 panel->Deactivate(); | |
504 EXPECT_FALSE(panel->IsActive()); | |
505 WaitTillSettingsAnimationFinished(panel); | |
506 EXPECT_FALSE(settings_button->visible()); | |
507 | |
508 mouse_watcher->MoveMouse(true); | |
509 WaitTillSettingsAnimationFinished(panel); | |
510 EXPECT_TRUE(settings_button->visible()); | |
511 mouse_watcher->MoveMouse(false); | |
512 WaitTillSettingsAnimationFinished(panel); | |
513 EXPECT_FALSE(settings_button->visible()); | |
514 } | 418 } |
515 | 419 |
516 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, SetBoundsAnimation) { | 420 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, SetBoundsAnimation) { |
517 Panel* panel = CreatePanel("PanelTest"); | 421 Panel* panel = CreatePanel("PanelTest"); |
518 PanelBrowserView* browser_view = GetBrowserView(panel); | 422 PanelBrowserView* browser_view = GetBrowserView(panel); |
519 | 423 |
520 // The bounds animation should not be triggered when the panel is up for the | 424 // The bounds animation should not be triggered when the panel is up for the |
521 // first time. | 425 // first time. |
522 EXPECT_FALSE(GetBoundsAnimator(panel)); | 426 EXPECT_FALSE(GetBoundsAnimator(panel)); |
523 | 427 |
(...skipping 29 matching lines...) Expand all Loading... |
553 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, | 457 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, |
554 MinimizeAndRestoreOnAutoHideTaskBar) { | 458 MinimizeAndRestoreOnAutoHideTaskBar) { |
555 TestMinimizeAndRestore(true); | 459 TestMinimizeAndRestore(true); |
556 } | 460 } |
557 | 461 |
558 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, | 462 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, |
559 ChangeAutoHideTaskBarThickness) { | 463 ChangeAutoHideTaskBarThickness) { |
560 TestChangeAutoHideTaskBarThickness(); | 464 TestChangeAutoHideTaskBarThickness(); |
561 } | 465 } |
562 #endif | 466 #endif |
OLD | NEW |