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

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) {
32 }
33
34 virtual bool IsCursorInViewBounds() const {
35 return cursor_in_view_;
36 }
37
38 void set_cursor_in_view(bool cursor_in_view) {
39 cursor_in_view_ = cursor_in_view;
40 }
41
42 private:
43 bool cursor_in_view_;
44 };
45
30 PanelBrowserView* CreatePanelBrowserView(const std::string& panel_name) { 46 PanelBrowserView* CreatePanelBrowserView(const std::string& panel_name) {
31 Browser* panel_browser = Browser::CreateForApp(Browser::TYPE_PANEL, 47 Browser* panel_browser = Browser::CreateForApp(Browser::TYPE_PANEL,
32 panel_name, 48 panel_name,
33 gfx::Size(), 49 gfx::Size(),
34 browser()->profile()); 50 browser()->profile());
35 panel_browser->window()->Show(); 51 panel_browser->window()->Show();
36 return static_cast<PanelBrowserView*>( 52 return static_cast<PanelBrowserView*>(
37 static_cast<Panel*>(panel_browser->window())->browser_window()); 53 static_cast<Panel*>(panel_browser->window())->browser_window());
38 } 54 }
39 55
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, 56 void ValidateDragging(PanelBrowserView** browser_views,
55 size_t num_browser_views, 57 size_t num_browser_views,
56 size_t index_to_drag, 58 size_t index_to_drag,
57 int delta_x, 59 int delta_x,
58 int delta_y, 60 int delta_y,
59 int* expected_delta_x_after_drag, 61 int* expected_delta_x_after_drag,
60 int* expected_delta_x_after_release, 62 int* expected_delta_x_after_release,
61 bool cancel_dragging) { 63 bool cancel_dragging) {
62 // Keep track of the initial bounds for comparison. 64 // Keep track of the initial bounds for comparison.
63 scoped_array<gfx::Rect> initial_bounds(new gfx::Rect[num_browser_views]); 65 scoped_array<gfx::Rect> initial_bounds(new gfx::Rect[num_browser_views]);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 EXPECT_EQ(initial_bounds[i], 137 EXPECT_EQ(initial_bounds[i],
136 browser_views[i]->panel()->GetRestoredBounds()); 138 browser_views[i]->panel()->GetRestoredBounds());
137 } 139 }
138 } 140 }
139 } 141 }
140 }; 142 };
141 143
142 // Panel is not supported for Linux view yet. 144 // Panel is not supported for Linux view yet.
143 #if !defined(OS_LINUX) || !defined(TOOLKIT_VIEWS) 145 #if !defined(OS_LINUX) || !defined(TOOLKIT_VIEWS)
144 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, CreatePanel) { 146 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, CreatePanel) {
145 PanelBrowserFrameView* frame_view = 147 PanelBrowserView* browser_view = CreatePanelBrowserView("PanelTest");
146 CreatePanelBrowserView("PanelTest")->GetFrameView(); 148 PanelBrowserFrameView* frame_view = browser_view->GetFrameView();
147 149
148 // We should have icon, text, options button and close button. 150 // We should have icon, text, options button and close button.
149 EXPECT_EQ(4, frame_view->child_count()); 151 EXPECT_EQ(4, frame_view->child_count());
150 EXPECT_TRUE(frame_view->Contains(frame_view->title_icon_)); 152 EXPECT_TRUE(frame_view->Contains(frame_view->title_icon_));
151 EXPECT_TRUE(frame_view->Contains(frame_view->title_label_)); 153 EXPECT_TRUE(frame_view->Contains(frame_view->title_label_));
152 EXPECT_TRUE(frame_view->Contains(frame_view->info_button_)); 154 EXPECT_TRUE(frame_view->Contains(frame_view->info_button_));
153 EXPECT_TRUE(frame_view->Contains(frame_view->close_button_)); 155 EXPECT_TRUE(frame_view->Contains(frame_view->close_button_));
154 156
155 // These controls should be visible. 157 // These controls should be visible.
156 EXPECT_TRUE(frame_view->title_icon_->IsVisible()); 158 EXPECT_TRUE(frame_view->title_icon_->IsVisible());
157 EXPECT_TRUE(frame_view->title_label_->IsVisible()); 159 EXPECT_TRUE(frame_view->title_label_->IsVisible());
158 EXPECT_TRUE(frame_view->info_button_->IsVisible());
159 EXPECT_TRUE(frame_view->close_button_->IsVisible()); 160 EXPECT_TRUE(frame_view->close_button_->IsVisible());
160 161
161 // Validate their layouts. 162 // Validate their layouts.
162 int title_bar_height = frame_view->NonClientTopBorderHeight() - 163 int title_bar_height = frame_view->NonClientTopBorderHeight() -
163 frame_view->NonClientBorderThickness(); 164 frame_view->NonClientBorderThickness();
164 EXPECT_GT(frame_view->title_icon_->width(), 0); 165 EXPECT_GT(frame_view->title_icon_->width(), 0);
165 EXPECT_GT(frame_view->title_icon_->height(), 0); 166 EXPECT_GT(frame_view->title_icon_->height(), 0);
166 EXPECT_LT(frame_view->title_icon_->height(), title_bar_height); 167 EXPECT_LT(frame_view->title_icon_->height(), title_bar_height);
167 EXPECT_GT(frame_view->title_label_->width(), 0); 168 EXPECT_GT(frame_view->title_label_->width(), 0);
168 EXPECT_GT(frame_view->title_label_->height(), 0); 169 EXPECT_GT(frame_view->title_label_->height(), 0);
(...skipping 12 matching lines...) Expand all
181 frame_view->info_button_->x() + frame_view->info_button_->width(), 182 frame_view->info_button_->x() + frame_view->info_button_->width(),
182 frame_view->close_button_->x()); 183 frame_view->close_button_->x());
183 184
184 // Validate that the controls should be updated when the activation state is 185 // Validate that the controls should be updated when the activation state is
185 // changed. 186 // changed.
186 frame_view->UpdateControlStyles(PanelBrowserFrameView::PAINT_AS_ACTIVE); 187 frame_view->UpdateControlStyles(PanelBrowserFrameView::PAINT_AS_ACTIVE);
187 gfx::Font title_label_font1 = frame_view->title_label_->font(); 188 gfx::Font title_label_font1 = frame_view->title_label_->font();
188 frame_view->UpdateControlStyles(PanelBrowserFrameView::PAINT_AS_INACTIVE); 189 frame_view->UpdateControlStyles(PanelBrowserFrameView::PAINT_AS_INACTIVE);
189 gfx::Font title_label_font2 = frame_view->title_label_->font(); 190 gfx::Font title_label_font2 = frame_view->title_label_->font();
190 EXPECT_NE(title_label_font1.GetStyle(), title_label_font2.GetStyle()); 191 EXPECT_NE(title_label_font1.GetStyle(), title_label_font2.GetStyle());
192
193 // The info button should be visible if the panel is activated or the cursor
jennb 2011/05/20 23:13:12 Suggest making this a separate test so we can chec
jianli 2011/05/23 21:21:03 Made it a separate test.
194 // is over the window (simulated by MockMouseWatcher).
195 MockMouseWatcher* mouse_watcher = new MockMouseWatcher(frame_view);
196 mouse_watcher->set_cursor_in_view(false);
197 frame_view->set_mouse_watcher(mouse_watcher);
198 browser_view->panel()->Activate();
199 EXPECT_TRUE(frame_view->info_button_->IsVisible());
200 browser_view->panel()->Deactivate();
201 EXPECT_FALSE(frame_view->info_button_->IsVisible());
202
203 mouse_watcher->set_cursor_in_view(true);
204 browser_view->panel()->Activate();
205 EXPECT_TRUE(frame_view->info_button_->IsVisible());
206 browser_view->panel()->Deactivate();
207 EXPECT_TRUE(frame_view->info_button_->IsVisible());
208
209 mouse_watcher->set_cursor_in_view(false);
210 #if defined(OS_WIN)
211 MSG msg;
212 msg.message = WM_MOUSEMOVE;
213 mouse_watcher->DidProcessMessage(msg);
214 #else
215 GdkEvent event;
216 event.type = GDK_MOTION_NOTIFY;
217 mouse_watcher->DidProcessEvent(&event);
218 #endif
219 EXPECT_FALSE(frame_view->info_button_->IsVisible());
220 mouse_watcher->set_cursor_in_view(true);
221 #if defined(OS_WIN)
222 mouse_watcher->DidProcessMessage(msg);
223 #else
224 mouse_watcher->DidProcessEvent(&event);
225 #endif
226 EXPECT_TRUE(frame_view->info_button_->IsVisible());
191 } 227 }
192 228
193 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, TitleBarMouseEvent) { 229 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, TitleBarMouseEvent) {
194 // TODO(jianli): Move the test to platform-independent PanelManager unittest. 230 // TODO(jianli): Move the test to platform-independent PanelManager unittest.
195 231
196 // Creates the 1st panel. 232 // Creates the 1st panel.
197 PanelBrowserView* browser_view1 = CreatePanelBrowserView("PanelTest1"); 233 PanelBrowserView* browser_view1 = CreatePanelBrowserView("PanelTest1");
198 234
199 // The delta is from the pressed location which is the left-top corner of the 235 // The delta is from the pressed location which is the left-top corner of the
200 // panel to drag. 236 // panel to drag.
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 false); 394 false);
359 } 395 }
360 396
361 // Closes all panels. 397 // Closes all panels.
362 for (size_t i = 0; i < browser_view_count; ++i) { 398 for (size_t i = 0; i < browser_view_count; ++i) {
363 browser_views[i]->panel()->Close(); 399 browser_views[i]->panel()->Close();
364 EXPECT_FALSE(browser_views[i]->panel()); 400 EXPECT_FALSE(browser_views[i]->panel());
365 } 401 }
366 } 402 }
367 #endif 403 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698