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

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

Issue 7055001: Make info button appear only when mouse is over the panel or the panel has focus. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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/command_line.h" 5 #include "base/command_line.h"
6 #include "chrome/browser/profiles/profile.h" 6 #include "chrome/browser/profiles/profile.h"
7 #include "chrome/browser/ui/browser.h" 7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/browser_window.h" 8 #include "chrome/browser/ui/browser_window.h"
9 #include "chrome/browser/ui/panels/panel.h" 9 #include "chrome/browser/ui/panels/panel.h"
10 #include "chrome/browser/ui/panels/panel_browser_frame_view.h" 10 #include "chrome/browser/ui/panels/panel_browser_frame_view.h"
11 #include "chrome/browser/ui/panels/panel_browser_view.h" 11 #include "chrome/browser/ui/panels/panel_browser_view.h"
12 #include "chrome/common/chrome_switches.h" 12 #include "chrome/common/chrome_switches.h"
13 #include "chrome/test/in_process_browser_test.h" 13 #include "chrome/test/in_process_browser_test.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "views/controls/button/image_button.h" 15 #include "views/controls/button/image_button.h"
16 #include "views/controls/button/menu_button.h"
17 #include "views/controls/label.h" 16 #include "views/controls/label.h"
18 #include "views/controls/menu/menu_2.h"
19
20 17
21 class PanelBrowserViewTest : public InProcessBrowserTest { 18 class PanelBrowserViewTest : public InProcessBrowserTest {
22 public: 19 public:
23 PanelBrowserViewTest() : InProcessBrowserTest() { } 20 PanelBrowserViewTest() : InProcessBrowserTest() { }
24 21
25 virtual void SetUpCommandLine(CommandLine* command_line) { 22 virtual void SetUpCommandLine(CommandLine* command_line) {
26 command_line->AppendSwitch(switches::kEnablePanels); 23 command_line->AppendSwitch(switches::kEnablePanels);
27 } 24 }
28 25
29 protected: 26 protected:
27 class MockMouseWatcher : public PanelBrowserFrameView::MouseWatcher {
28 public:
29 explicit MockMouseWatcher(PanelBrowserFrameView* view)
30 : PanelBrowserFrameView::MouseWatcher(view),
31 cursor_in_view_(false) {
Dmitry Titov 2011/05/24 20:21:56 Same: "is_cursor_in_view_"?
jianli 2011/05/24 21:58:56 Done.
32 }
33
34 virtual bool IsCursorInViewBounds() const {
35 return cursor_in_view_;
36 }
37
38 void MoveMouse(bool cursor_in_view) {
39 cursor_in_view_ = cursor_in_view;
40
41 #if defined(OS_WIN)
42 MSG msg;
43 msg.message = WM_MOUSEMOVE;
44 DidProcessMessage(msg);
45 #else
46 GdkEvent event;
47 event.type = GDK_MOTION_NOTIFY;
48 DidProcessEvent(&event);
49 #endif
50 }
51
52 private:
53 bool cursor_in_view_;
54 };
55
30 PanelBrowserView* CreatePanelBrowserView(const std::string& panel_name) { 56 PanelBrowserView* CreatePanelBrowserView(const std::string& panel_name) {
31 Browser* panel_browser = Browser::CreateForApp(Browser::TYPE_PANEL, 57 Browser* panel_browser = Browser::CreateForApp(Browser::TYPE_PANEL,
32 panel_name, 58 panel_name,
33 gfx::Size(), 59 gfx::Size(),
34 browser()->profile()); 60 browser()->profile());
35 panel_browser->window()->Show(); 61 panel_browser->window()->Show();
36 return static_cast<PanelBrowserView*>( 62 return static_cast<PanelBrowserView*>(
37 static_cast<Panel*>(panel_browser->window())->browser_window()); 63 static_cast<Panel*>(panel_browser->window())->browser_window());
38 } 64 }
39 65
40 void ValidateOptionsMenuItems(
41 ui::SimpleMenuModel* options_menu_contents, size_t count, int* ids) {
42 ASSERT_TRUE(options_menu_contents);
43 EXPECT_EQ(static_cast<int>(count), options_menu_contents->GetItemCount());
44 for (size_t i = 0; i < count; ++i) {
45 if (ids[i] == -1) {
46 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR,
47 options_menu_contents->GetTypeAt(i));
48 } else {
49 EXPECT_EQ(ids[i] , options_menu_contents->GetCommandIdAt(i));
50 }
51 }
52 }
53
54 void ValidateDragging(PanelBrowserView** browser_views, 66 void ValidateDragging(PanelBrowserView** browser_views,
55 size_t num_browser_views, 67 size_t num_browser_views,
56 size_t index_to_drag, 68 size_t index_to_drag,
57 int delta_x, 69 int delta_x,
58 int delta_y, 70 int delta_y,
59 int* expected_delta_x_after_drag, 71 int* expected_delta_x_after_drag,
60 int* expected_delta_x_after_release, 72 int* expected_delta_x_after_release,
61 bool cancel_dragging) { 73 bool cancel_dragging) {
62 // Keep track of the initial bounds for comparison. 74 // Keep track of the initial bounds for comparison.
63 scoped_array<gfx::Rect> initial_bounds(new gfx::Rect[num_browser_views]); 75 scoped_array<gfx::Rect> initial_bounds(new gfx::Rect[num_browser_views]);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 // We should have icon, text, options button and close button. 160 // We should have icon, text, options button and close button.
149 EXPECT_EQ(4, frame_view->child_count()); 161 EXPECT_EQ(4, frame_view->child_count());
150 EXPECT_TRUE(frame_view->Contains(frame_view->title_icon_)); 162 EXPECT_TRUE(frame_view->Contains(frame_view->title_icon_));
151 EXPECT_TRUE(frame_view->Contains(frame_view->title_label_)); 163 EXPECT_TRUE(frame_view->Contains(frame_view->title_label_));
152 EXPECT_TRUE(frame_view->Contains(frame_view->info_button_)); 164 EXPECT_TRUE(frame_view->Contains(frame_view->info_button_));
153 EXPECT_TRUE(frame_view->Contains(frame_view->close_button_)); 165 EXPECT_TRUE(frame_view->Contains(frame_view->close_button_));
154 166
155 // These controls should be visible. 167 // These controls should be visible.
156 EXPECT_TRUE(frame_view->title_icon_->IsVisible()); 168 EXPECT_TRUE(frame_view->title_icon_->IsVisible());
157 EXPECT_TRUE(frame_view->title_label_->IsVisible()); 169 EXPECT_TRUE(frame_view->title_label_->IsVisible());
158 EXPECT_TRUE(frame_view->info_button_->IsVisible());
159 EXPECT_TRUE(frame_view->close_button_->IsVisible()); 170 EXPECT_TRUE(frame_view->close_button_->IsVisible());
160 171
161 // Validate their layouts. 172 // Validate their layouts.
162 int title_bar_height = frame_view->NonClientTopBorderHeight() - 173 int title_bar_height = frame_view->NonClientTopBorderHeight() -
163 frame_view->NonClientBorderThickness(); 174 frame_view->NonClientBorderThickness();
164 EXPECT_GT(frame_view->title_icon_->width(), 0); 175 EXPECT_GT(frame_view->title_icon_->width(), 0);
165 EXPECT_GT(frame_view->title_icon_->height(), 0); 176 EXPECT_GT(frame_view->title_icon_->height(), 0);
166 EXPECT_LT(frame_view->title_icon_->height(), title_bar_height); 177 EXPECT_LT(frame_view->title_icon_->height(), title_bar_height);
167 EXPECT_GT(frame_view->title_label_->width(), 0); 178 EXPECT_GT(frame_view->title_label_->width(), 0);
168 EXPECT_GT(frame_view->title_label_->height(), 0); 179 EXPECT_GT(frame_view->title_label_->height(), 0);
(...skipping 14 matching lines...) Expand all
183 194
184 // Validate that the controls should be updated when the activation state is 195 // Validate that the controls should be updated when the activation state is
185 // changed. 196 // changed.
186 frame_view->UpdateControlStyles(PanelBrowserFrameView::PAINT_AS_ACTIVE); 197 frame_view->UpdateControlStyles(PanelBrowserFrameView::PAINT_AS_ACTIVE);
187 gfx::Font title_label_font1 = frame_view->title_label_->font(); 198 gfx::Font title_label_font1 = frame_view->title_label_->font();
188 frame_view->UpdateControlStyles(PanelBrowserFrameView::PAINT_AS_INACTIVE); 199 frame_view->UpdateControlStyles(PanelBrowserFrameView::PAINT_AS_INACTIVE);
189 gfx::Font title_label_font2 = frame_view->title_label_->font(); 200 gfx::Font title_label_font2 = frame_view->title_label_->font();
190 EXPECT_NE(title_label_font1.GetStyle(), title_label_font2.GetStyle()); 201 EXPECT_NE(title_label_font1.GetStyle(), title_label_font2.GetStyle());
191 } 202 }
192 203
204 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, ShowOrHideInfoButton) {
Dmitry Titov 2011/05/24 20:21:56 I wonder if it can be a unit test. The benefit of
jianli 2011/05/24 21:58:56 For this case, probably we need to use browser tes
205 PanelBrowserView* browser_view = CreatePanelBrowserView("PanelTest");
206 PanelBrowserFrameView* frame_view = browser_view->GetFrameView();
207
208 // Create and hook up the MockMouseWatcher so that we can simulate if the
209 // mouse is over the panel.
210 MockMouseWatcher* mouse_watcher = new MockMouseWatcher(frame_view);
211 frame_view->set_mouse_watcher(mouse_watcher);
212
213 // When the panel is created, it is active. Since we cannot programatically
214 // bring the panel back to active state once it is deactivated, we have to
215 // test the cases that the panel is active first.
216 EXPECT_TRUE(browser_view->panel()->IsActive());
217
218 // When the panel is active, the info button should always be visible.
219 mouse_watcher->MoveMouse(true);
220 EXPECT_TRUE(frame_view->info_button_->IsVisible());
221 mouse_watcher->MoveMouse(false);
222 EXPECT_TRUE(frame_view->info_button_->IsVisible());
223
224 // When the panel is inactive, the info button is active per the mouse over
225 // the panel or not.
226 browser_view->panel()->Deactivate();
227 EXPECT_FALSE(browser_view->panel()->IsActive());
228
229 mouse_watcher->MoveMouse(true);
230 EXPECT_TRUE(frame_view->info_button_->IsVisible());
231 mouse_watcher->MoveMouse(false);
232 EXPECT_FALSE(frame_view->info_button_->IsVisible());
233 }
234
193 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, TitleBarMouseEvent) { 235 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, TitleBarMouseEvent) {
194 // TODO(jianli): Move the test to platform-independent PanelManager unittest. 236 // TODO(jianli): Move the test to platform-independent PanelManager unittest.
195 237
196 // Creates the 1st panel. 238 // Creates the 1st panel.
197 PanelBrowserView* browser_view1 = CreatePanelBrowserView("PanelTest1"); 239 PanelBrowserView* browser_view1 = CreatePanelBrowserView("PanelTest1");
198 240
199 // The delta is from the pressed location which is the left-top corner of the 241 // The delta is from the pressed location which is the left-top corner of the
200 // panel to drag. 242 // panel to drag.
201 int small_negative_delta = -5; 243 int small_negative_delta = -5;
202 int small_positive_delta = 5; 244 int small_positive_delta = 5;
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 false); 400 false);
359 } 401 }
360 402
361 // Closes all panels. 403 // Closes all panels.
362 for (size_t i = 0; i < browser_view_count; ++i) { 404 for (size_t i = 0; i < browser_view_count; ++i) {
363 browser_views[i]->panel()->Close(); 405 browser_views[i]->panel()->Close();
364 EXPECT_FALSE(browser_views[i]->panel()); 406 EXPECT_FALSE(browser_views[i]->panel());
365 } 407 }
366 } 408 }
367 #endif 409 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698