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

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

Issue 7646003: Support auto-hide taskbar for panels on Windows. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 3 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"
6 #include "base/i18n/time_formatting.h" 5 #include "base/i18n/time_formatting.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.h"
10 #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"
11 #include "chrome/browser/ui/panels/panel.h" 11 #include "chrome/browser/ui/panels/panel.h"
12 #include "chrome/browser/ui/panels/panel_browser_frame_view.h" 12 #include "chrome/browser/ui/panels/panel_browser_frame_view.h"
13 #include "chrome/browser/ui/panels/panel_browser_view.h" 13 #include "chrome/browser/ui/panels/panel_browser_view.h"
14 #include "chrome/browser/ui/panels/panel_manager.h" 14 #include "chrome/browser/ui/panels/panel_manager.h"
15 #include "chrome/browser/ui/panels/panel_mouse_watcher_win.h" 15 #include "chrome/browser/ui/panels/panel_mouse_watcher_win.h"
16 #include "chrome/browser/web_applications/web_app.h" 16 #include "chrome/browser/web_applications/web_app.h"
17 #include "chrome/common/chrome_switches.h" 17 #include "chrome/common/chrome_switches.h"
18 #include "chrome/common/extensions/extension.h" 18 #include "chrome/common/extensions/extension.h"
19 #include "chrome/test/base/in_process_browser_test.h"
20 #include "grit/generated_resources.h" 19 #include "grit/generated_resources.h"
21 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
22 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
23 #include "ui/base/animation/slide_animation.h" 22 #include "ui/base/animation/slide_animation.h"
24 #include "views/controls/button/image_button.h" 23 #include "views/controls/button/image_button.h"
25 #include "views/controls/button/menu_button.h" 24 #include "views/controls/button/menu_button.h"
26 #include "views/controls/image_view.h" 25 #include "views/controls/image_view.h"
27 #include "views/controls/label.h" 26 #include "views/controls/label.h"
28 #include "views/controls/link.h" 27 #include "views/controls/link.h"
29 #include "views/controls/textfield/textfield.h" 28 #include "views/controls/textfield/textfield.h"
30 29
31 class PanelBrowserViewTest : public InProcessBrowserTest { 30 class PanelBrowserViewTest : public BasePanelBrowserTest {
32 public: 31 public:
33 PanelBrowserViewTest() : InProcessBrowserTest() { } 32 PanelBrowserViewTest() : BasePanelBrowserTest() { }
34
35 virtual void SetUpCommandLine(CommandLine* command_line) {
36 command_line->AppendSwitch(switches::kEnablePanels);
37 }
38 33
39 protected: 34 protected:
40 struct MenuItem { 35 struct MenuItem {
41 int id; 36 int id;
42 bool enabled; 37 bool enabled;
43 }; 38 };
44 39
45 class MockMouseWatcher : public PanelBrowserFrameView::MouseWatcher { 40 class MockMouseWatcher : public PanelBrowserFrameView::MouseWatcher {
46 public: 41 public:
47 explicit MockMouseWatcher(PanelBrowserFrameView* view) 42 explicit MockMouseWatcher(PanelBrowserFrameView* view)
(...skipping 16 matching lines...) Expand all
64 GdkEvent event; 59 GdkEvent event;
65 event.type = GDK_MOTION_NOTIFY; 60 event.type = GDK_MOTION_NOTIFY;
66 DidProcessEvent(&event); 61 DidProcessEvent(&event);
67 #endif 62 #endif
68 } 63 }
69 64
70 private: 65 private:
71 bool is_cursor_in_view_; 66 bool is_cursor_in_view_;
72 }; 67 };
73 68
74 enum ShowFlag { SHOW_AS_ACTIVE, SHOW_AS_INACTIVE }; 69 PanelBrowserView* GetBrowserView(Panel* panel) {
75
76 PanelBrowserView* CreatePanelBrowserView(const std::string& panel_name,
77 ShowFlag show_flag) {
78 Browser* panel_browser = Browser::CreateForApp(Browser::TYPE_PANEL,
79 panel_name,
80 gfx::Rect(),
81 browser()->profile());
82 Panel* panel = static_cast<Panel*>(panel_browser->window());
83 if (show_flag == SHOW_AS_ACTIVE)
84 panel->Show();
85 else
86 panel->ShowInactive();
87 return static_cast<PanelBrowserView*>(panel->native_panel()); 70 return static_cast<PanelBrowserView*>(panel->native_panel());
88 } 71 }
89 72
90 void WaitTillBoundsAnimationFinished(PanelBrowserView* browser_view) { 73 void WaitTillBoundsAnimationFinished(PanelBrowserView* browser_view) {
91 // The timer for the animation will only kick in as async task. 74 // The timer for the animation will only kick in as async task.
92 while (browser_view->bounds_animator_->is_animating()) { 75 while (browser_view->bounds_animator_->is_animating()) {
93 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); 76 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask());
94 MessageLoop::current()->RunAllPending(); 77 MessageLoop::current()->RunAllPending();
95 } 78 }
96 } 79 }
(...skipping 15 matching lines...) Expand all
112 settings_menu_contents->IsEnabledAt(i)); 95 settings_menu_contents->IsEnabledAt(i));
113 } 96 }
114 } 97 }
115 } 98 }
116 99
117 void TestCreateSettingsMenuForExtension(const FilePath::StringType& path, 100 void TestCreateSettingsMenuForExtension(const FilePath::StringType& path,
118 Extension::Location location, 101 Extension::Location location,
119 const std::string& homepage_url, 102 const std::string& homepage_url,
120 const std::string& options_page) { 103 const std::string& options_page) {
121 // Creates a testing extension. 104 // Creates a testing extension.
122 #if defined(OS_WIN) 105 DictionaryValue extra_value;
123 FilePath full_path(FILE_PATH_LITERAL("c:\\"));
124 #else
125 FilePath full_path(FILE_PATH_LITERAL("/"));
126 #endif
127 full_path = full_path.Append(path);
128 DictionaryValue input_value;
129 input_value.SetString(extension_manifest_keys::kVersion, "1.0.0.0");
130 input_value.SetString(extension_manifest_keys::kName, "Sample Extension");
131 if (!homepage_url.empty()) { 106 if (!homepage_url.empty()) {
132 input_value.SetString(extension_manifest_keys::kHomepageURL, 107 extra_value.SetString(extension_manifest_keys::kHomepageURL,
133 homepage_url); 108 homepage_url);
134 } 109 }
135 if (!options_page.empty()) { 110 if (!options_page.empty()) {
136 input_value.SetString(extension_manifest_keys::kOptionsPage, 111 extra_value.SetString(extension_manifest_keys::kOptionsPage,
137 options_page); 112 options_page);
138 } 113 }
139 std::string error; 114 scoped_refptr<Extension> extension = CreateExtension(
140 scoped_refptr<Extension> extension = Extension::Create( 115 path, location, extra_value);
141 full_path, location, input_value, Extension::STRICT_ERROR_CHECKS,
142 &error);
143 ASSERT_TRUE(extension.get());
144 EXPECT_STREQ("", error.c_str());
145 browser()->GetProfile()->GetExtensionService()->OnLoadSingleExtension(
146 extension.get(), false);
147 116
148 // Creates a panel with the app name that comes from the extension ID. 117 // Creates a panel with the app name that comes from the extension ID.
149 PanelBrowserView* browser_view = CreatePanelBrowserView( 118 Panel* panel = CreatePanel(
150 web_app::GenerateApplicationNameFromExtensionId(extension->id()), 119 web_app::GenerateApplicationNameFromExtensionId(extension->id()));
151 SHOW_AS_ACTIVE); 120 PanelBrowserFrameView* frame_view = GetBrowserView(panel)->GetFrameView();
152 PanelBrowserFrameView* frame_view = browser_view->GetFrameView();
153 121
154 frame_view->EnsureSettingsMenuCreated(); 122 frame_view->EnsureSettingsMenuCreated();
155 123
156 // Validates the settings menu items. 124 // Validates the settings menu items.
157 MenuItem expected_panel_menu_items[] = { 125 MenuItem expected_panel_menu_items[] = {
158 { PanelBrowserFrameView::COMMAND_NAME, false }, 126 { PanelBrowserFrameView::COMMAND_NAME, false },
159 { -1, false }, // Separator 127 { -1, false }, // Separator
160 { PanelBrowserFrameView::COMMAND_CONFIGURE, false }, 128 { PanelBrowserFrameView::COMMAND_CONFIGURE, false },
161 { PanelBrowserFrameView::COMMAND_DISABLE, false }, 129 { PanelBrowserFrameView::COMMAND_DISABLE, false },
162 { PanelBrowserFrameView::COMMAND_UNINSTALL, false }, 130 { PanelBrowserFrameView::COMMAND_UNINSTALL, false },
163 { -1, false }, // Separator 131 { -1, false }, // Separator
164 { PanelBrowserFrameView::COMMAND_MANAGE, true } 132 { PanelBrowserFrameView::COMMAND_MANAGE, true }
165 }; 133 };
166 if (!homepage_url.empty()) 134 if (!homepage_url.empty())
167 expected_panel_menu_items[0].enabled = true; 135 expected_panel_menu_items[0].enabled = true;
168 if (!options_page.empty()) 136 if (!options_page.empty())
169 expected_panel_menu_items[2].enabled = true; 137 expected_panel_menu_items[2].enabled = true;
170 if (location != Extension::EXTERNAL_POLICY_DOWNLOAD) { 138 if (location != Extension::EXTERNAL_POLICY_DOWNLOAD) {
171 expected_panel_menu_items[3].enabled = true; 139 expected_panel_menu_items[3].enabled = true;
172 expected_panel_menu_items[4].enabled = true; 140 expected_panel_menu_items[4].enabled = true;
173 } 141 }
174 ValidateSettingsMenuItems(&frame_view->settings_menu_contents_, 142 ValidateSettingsMenuItems(&frame_view->settings_menu_contents_,
175 arraysize(expected_panel_menu_items), 143 arraysize(expected_panel_menu_items),
176 expected_panel_menu_items); 144 expected_panel_menu_items);
177 145
178 browser_view->panel()->Close(); 146 panel->Close();
179 } 147 }
180 148
181 void TestShowPanelActiveOrInactive() { 149 void TestShowPanelActiveOrInactive() {
182 PanelBrowserView* browser_view1 = CreatePanelBrowserView("PanelTest1", 150 CreatePanelParams params1("PanelTest1", gfx::Rect(), SHOW_AS_ACTIVE);
183 SHOW_AS_ACTIVE); 151 Panel* panel1 = CreatePanelWithParams(params1);
152 PanelBrowserView* browser_view1 = GetBrowserView(panel1);
184 PanelBrowserFrameView* frame_view1 = browser_view1->GetFrameView(); 153 PanelBrowserFrameView* frame_view1 = browser_view1->GetFrameView();
185 EXPECT_TRUE(browser_view1->panel()->IsActive()); 154 EXPECT_TRUE(panel1->IsActive());
186 EXPECT_EQ(PanelBrowserFrameView::PAINT_AS_ACTIVE, 155 EXPECT_EQ(PanelBrowserFrameView::PAINT_AS_ACTIVE,
187 frame_view1->paint_state_); 156 frame_view1->paint_state_);
188 157
189 PanelBrowserView* browser_view2 = CreatePanelBrowserView("PanelTest2", 158 CreatePanelParams params2("PanelTest2", gfx::Rect(), SHOW_AS_INACTIVE);
190 SHOW_AS_INACTIVE); 159 Panel* panel2 = CreatePanelWithParams(params2);
160 PanelBrowserView* browser_view2 = GetBrowserView(panel2);
191 PanelBrowserFrameView* frame_view2 = browser_view2->GetFrameView(); 161 PanelBrowserFrameView* frame_view2 = browser_view2->GetFrameView();
192 EXPECT_FALSE(browser_view2->panel()->IsActive()); 162 EXPECT_FALSE(panel2->IsActive());
193 EXPECT_EQ(PanelBrowserFrameView::PAINT_AS_INACTIVE, 163 EXPECT_EQ(PanelBrowserFrameView::PAINT_AS_INACTIVE,
194 frame_view2->paint_state_); 164 frame_view2->paint_state_);
195 165
196 browser_view1->panel()->Close(); 166 panel1->Close();
197 browser_view2->panel()->Close(); 167 panel2->Close();
198 } 168 }
199 169
200 // We put all the testing logic in this class instead of the test so that 170 // We put all the testing logic in this class instead of the test so that
201 // we do not need to declare each new test as a friend of PanelBrowserView 171 // we do not need to declare each new test as a friend of PanelBrowserView
202 // for the purpose of accessing its private members. 172 // for the purpose of accessing its private members.
203 void TestMinimizeAndRestore() { 173 void TestMinimizeAndRestore(bool enable_auto_hiding) {
204 PanelBrowserView* browser_view1 = CreatePanelBrowserView("PanelTest1", 174 PanelManager* panel_manager = PanelManager::GetInstance();
205 SHOW_AS_ACTIVE); 175 int expected_bottom_on_minimized = testing_work_area().height();
206 Panel* panel1 = browser_view1->panel_.get(); 176 int expected_bottom_on_unminimized = expected_bottom_on_minimized;
177
178 // Turn on auto-hiding if requested.
179 static const int bottom_thickness = 40;
180 mock_auto_hiding_desktop_bar()->EnableAutoHiding(
181 AutoHidingDesktopBar::ALIGN_BOTTOM,
182 enable_auto_hiding,
183 bottom_thickness);
184 if (enable_auto_hiding)
185 expected_bottom_on_unminimized -= bottom_thickness;
186
187 // Create and test one panel first.
188 Panel* panel1 = CreatePanel("PanelTest1");
189 PanelBrowserView* browser_view1 = GetBrowserView(panel1);
207 PanelBrowserFrameView* frame_view1 = browser_view1->GetFrameView(); 190 PanelBrowserFrameView* frame_view1 = browser_view1->GetFrameView();
208 191
209 // Test minimizing/restoring an individual panel. 192 // Test minimizing/restoring an individual panel.
210 EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state()); 193 EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state());
211 int initial_height = panel1->GetBounds().height(); 194 int initial_height = panel1->GetBounds().height();
212 int titlebar_height = 195 int titlebar_height = frame_view1->NonClientTopBorderHeight();
213 browser_view1->GetFrameView()->NonClientTopBorderHeight();
214 196
215 panel1->SetExpansionState(Panel::MINIMIZED); 197 panel1->SetExpansionState(Panel::MINIMIZED);
216 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); 198 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state());
217 EXPECT_LT(panel1->GetBounds().height(), titlebar_height); 199 EXPECT_LT(panel1->GetBounds().height(), titlebar_height);
218 EXPECT_GT(panel1->GetBounds().height(), 0); 200 EXPECT_GT(panel1->GetBounds().height(), 0);
201 EXPECT_EQ(expected_bottom_on_minimized, panel1->GetBounds().bottom());
219 EXPECT_TRUE(IsMouseWatcherStarted()); 202 EXPECT_TRUE(IsMouseWatcherStarted());
220 EXPECT_FALSE(panel1->IsActive()); 203 EXPECT_FALSE(panel1->IsActive());
221 WaitTillBoundsAnimationFinished(browser_view1); 204 WaitTillBoundsAnimationFinished(browser_view1);
222 205
223 panel1->SetExpansionState(Panel::TITLE_ONLY); 206 panel1->SetExpansionState(Panel::TITLE_ONLY);
224 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); 207 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
225 EXPECT_EQ(titlebar_height, panel1->GetBounds().height()); 208 EXPECT_EQ(titlebar_height, panel1->GetBounds().height());
209 EXPECT_EQ(expected_bottom_on_unminimized, panel1->GetBounds().bottom());
226 WaitTillBoundsAnimationFinished(browser_view1); 210 WaitTillBoundsAnimationFinished(browser_view1);
227 EXPECT_TRUE(frame_view1->close_button_->IsVisible()); 211 EXPECT_TRUE(frame_view1->close_button_->IsVisible());
228 EXPECT_TRUE(frame_view1->title_icon_->IsVisible()); 212 EXPECT_TRUE(frame_view1->title_icon_->IsVisible());
229 EXPECT_TRUE(frame_view1->title_label_->IsVisible()); 213 EXPECT_TRUE(frame_view1->title_label_->IsVisible());
230 214
231 panel1->SetExpansionState(Panel::EXPANDED); 215 panel1->SetExpansionState(Panel::EXPANDED);
232 EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state()); 216 EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state());
233 EXPECT_EQ(initial_height, panel1->GetBounds().height()); 217 EXPECT_EQ(initial_height, panel1->GetBounds().height());
218 EXPECT_EQ(expected_bottom_on_unminimized, panel1->GetBounds().bottom());
234 WaitTillBoundsAnimationFinished(browser_view1); 219 WaitTillBoundsAnimationFinished(browser_view1);
235 EXPECT_TRUE(frame_view1->close_button_->IsVisible()); 220 EXPECT_TRUE(frame_view1->close_button_->IsVisible());
236 EXPECT_TRUE(frame_view1->title_icon_->IsVisible()); 221 EXPECT_TRUE(frame_view1->title_icon_->IsVisible());
237 EXPECT_TRUE(frame_view1->title_label_->IsVisible()); 222 EXPECT_TRUE(frame_view1->title_label_->IsVisible());
238 223
239 panel1->SetExpansionState(Panel::TITLE_ONLY); 224 panel1->SetExpansionState(Panel::TITLE_ONLY);
240 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); 225 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
241 EXPECT_EQ(titlebar_height, panel1->GetBounds().height()); 226 EXPECT_EQ(titlebar_height, panel1->GetBounds().height());
227 EXPECT_EQ(expected_bottom_on_unminimized, panel1->GetBounds().bottom());
242 228
243 panel1->SetExpansionState(Panel::MINIMIZED); 229 panel1->SetExpansionState(Panel::MINIMIZED);
244 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); 230 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state());
245 EXPECT_LT(panel1->GetBounds().height(), titlebar_height); 231 EXPECT_LT(panel1->GetBounds().height(), titlebar_height);
246 EXPECT_GT(panel1->GetBounds().height(), 0); 232 EXPECT_GT(panel1->GetBounds().height(), 0);
233 EXPECT_EQ(expected_bottom_on_minimized, panel1->GetBounds().bottom());
247 234
248 // Create 2 more panels for more testing. 235 // Create 2 more panels for more testing.
249 PanelBrowserView* browser_view2 = CreatePanelBrowserView("PanelTest2", 236 Panel* panel2 = CreatePanel("PanelTest2");
250 SHOW_AS_ACTIVE); 237 Panel* panel3 = CreatePanel("PanelTest3");
251 Panel* panel2 = browser_view2->panel_.get();
252
253 PanelBrowserView* browser_view3 = CreatePanelBrowserView("PanelTest3",
254 SHOW_AS_ACTIVE);
255 Panel* panel3 = browser_view3->panel_.get();
256 238
257 // Test bringing up or down the title-bar of all minimized panels. 239 // Test bringing up or down the title-bar of all minimized panels.
258 EXPECT_EQ(Panel::EXPANDED, panel2->expansion_state()); 240 EXPECT_EQ(Panel::EXPANDED, panel2->expansion_state());
259 panel3->SetExpansionState(Panel::MINIMIZED); 241 panel3->SetExpansionState(Panel::MINIMIZED);
260 EXPECT_EQ(Panel::MINIMIZED, panel3->expansion_state()); 242 EXPECT_EQ(Panel::MINIMIZED, panel3->expansion_state());
261 243
262 PanelManager* panel_manager = PanelManager::GetInstance(); 244 mock_auto_hiding_desktop_bar()->SetVisibility(
263 245 AutoHidingDesktopBar::ALIGN_BOTTOM, AutoHidingDesktopBar::VISIBLE);
264 panel_manager->BringUpOrDownTitlebarForAllMinimizedPanels(true); 246 panel_manager->BringUpOrDownTitlebars(true);
247 MessageLoop::current()->RunAllPending();
265 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); 248 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state());
266 EXPECT_EQ(Panel::EXPANDED, panel2->expansion_state()); 249 EXPECT_EQ(Panel::EXPANDED, panel2->expansion_state());
267 EXPECT_EQ(Panel::TITLE_ONLY, panel3->expansion_state()); 250 EXPECT_EQ(Panel::TITLE_ONLY, panel3->expansion_state());
268 251
269 panel_manager->BringUpOrDownTitlebarForAllMinimizedPanels(false); 252 mock_auto_hiding_desktop_bar()->SetVisibility(
253 AutoHidingDesktopBar::ALIGN_BOTTOM, AutoHidingDesktopBar::HIDDEN);
254 panel_manager->BringUpOrDownTitlebars(false);
255 MessageLoop::current()->RunAllPending();
270 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); 256 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state());
271 EXPECT_EQ(Panel::EXPANDED, panel2->expansion_state()); 257 EXPECT_EQ(Panel::EXPANDED, panel2->expansion_state());
272 EXPECT_EQ(Panel::MINIMIZED, panel3->expansion_state()); 258 EXPECT_EQ(Panel::MINIMIZED, panel3->expansion_state());
273 259
274 // Test if it is OK to bring up title-bar given the mouse position. 260 // Test if it is OK to bring up title-bar given the mouse position.
275 EXPECT_TRUE(panel_manager->ShouldBringUpTitlebarForAllMinimizedPanels( 261 EXPECT_TRUE(panel_manager->ShouldBringUpTitlebars(
276 panel1->GetBounds().x(), panel1->GetBounds().y())); 262 panel1->GetBounds().x(), panel1->GetBounds().y()));
277 EXPECT_FALSE(panel_manager->ShouldBringUpTitlebarForAllMinimizedPanels( 263 EXPECT_FALSE(panel_manager->ShouldBringUpTitlebars(
278 panel2->GetBounds().x(), panel2->GetBounds().y())); 264 panel2->GetBounds().x(), panel2->GetBounds().y()));
279 EXPECT_TRUE(panel_manager->ShouldBringUpTitlebarForAllMinimizedPanels( 265 EXPECT_TRUE(panel_manager->ShouldBringUpTitlebars(
280 panel3->GetBounds().right() - 1, panel3->GetBounds().bottom() - 1)); 266 panel3->GetBounds().right() - 1, panel3->GetBounds().bottom() - 1));
281 EXPECT_TRUE(panel_manager->ShouldBringUpTitlebarForAllMinimizedPanels( 267 EXPECT_TRUE(panel_manager->ShouldBringUpTitlebars(
282 panel3->GetBounds().right() - 1, panel3->GetBounds().bottom() + 10)); 268 panel3->GetBounds().right() - 1, panel3->GetBounds().bottom() + 10));
283 EXPECT_FALSE(panel_manager->ShouldBringUpTitlebarForAllMinimizedPanels( 269 EXPECT_FALSE(panel_manager->ShouldBringUpTitlebars(
284 0, 0)); 270 0, 0));
285 271
286 // Test that the panel in title-only state should not be minimized 272 // Test that the panel in title-only state should not be minimized
287 // regardless of the current mouse position when the panel is being dragged. 273 // regardless of the current mouse position when the panel is being dragged.
288 panel1->SetExpansionState(Panel::TITLE_ONLY); 274 panel1->SetExpansionState(Panel::TITLE_ONLY);
289 EXPECT_FALSE(panel_manager->ShouldBringUpTitlebarForAllMinimizedPanels( 275 EXPECT_FALSE(panel_manager->ShouldBringUpTitlebars(
290 0, 0)); 276 0, 0));
291 browser_view1->OnTitlebarMousePressed(panel1->GetBounds().origin()); 277 browser_view1->OnTitlebarMousePressed(panel1->GetBounds().origin());
292 browser_view1->OnTitlebarMouseDragged( 278 browser_view1->OnTitlebarMouseDragged(
293 panel1->GetBounds().origin().Subtract(gfx::Point(5, 5))); 279 panel1->GetBounds().origin().Subtract(gfx::Point(5, 5)));
294 EXPECT_TRUE(panel_manager->ShouldBringUpTitlebarForAllMinimizedPanels( 280 EXPECT_TRUE(panel_manager->ShouldBringUpTitlebars(
295 0, 0)); 281 0, 0));
296 browser_view1->OnTitlebarMouseReleased(); 282 browser_view1->OnTitlebarMouseReleased();
297 283
298 panel1->Close(); 284 panel1->Close();
299 EXPECT_TRUE(IsMouseWatcherStarted()); 285 EXPECT_TRUE(IsMouseWatcherStarted());
300 panel2->Close(); 286 panel2->Close();
301 EXPECT_TRUE(IsMouseWatcherStarted()); 287 EXPECT_TRUE(IsMouseWatcherStarted());
302 panel3->Close(); 288 panel3->Close();
303 EXPECT_FALSE(IsMouseWatcherStarted()); 289 EXPECT_FALSE(IsMouseWatcherStarted());
304 } 290 }
305 291
306 void TestDrawAttention() { 292 void TestDrawAttention() {
307 PanelBrowserView* browser_view = CreatePanelBrowserView("PanelTest", 293 Panel* panel = CreatePanel("PanelTest");
308 SHOW_AS_ACTIVE); 294 PanelBrowserView* browser_view = GetBrowserView(panel);
309 PanelBrowserFrameView* frame_view = browser_view->GetFrameView(); 295 PanelBrowserFrameView* frame_view = browser_view->GetFrameView();
310 Panel* panel = browser_view->panel_.get();
311 SkColor attention_color = frame_view->GetTitleColor( 296 SkColor attention_color = frame_view->GetTitleColor(
312 PanelBrowserFrameView::PAINT_FOR_ATTENTION); 297 PanelBrowserFrameView::PAINT_FOR_ATTENTION);
313 298
314 // Test that the attention should not be drawn if the expanded panel is in 299 // Test that the attention should not be drawn if the expanded panel is in
315 // focus. 300 // focus.
316 browser_view->DrawAttention(); 301 browser_view->DrawAttention();
317 EXPECT_FALSE(browser_view->IsDrawingAttention()); 302 EXPECT_FALSE(browser_view->IsDrawingAttention());
318 MessageLoop::current()->RunAllPending(); 303 MessageLoop::current()->RunAllPending();
319 EXPECT_NE(attention_color, frame_view->title_label_->GetColor()); 304 EXPECT_NE(attention_color, frame_view->title_label_->GetColor());
320 305
(...skipping 17 matching lines...) Expand all
338 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state()); 323 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state());
339 browser_view->DrawAttention(); 324 browser_view->DrawAttention();
340 EXPECT_TRUE(browser_view->IsDrawingAttention()); 325 EXPECT_TRUE(browser_view->IsDrawingAttention());
341 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); 326 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state());
342 MessageLoop::current()->RunAllPending(); 327 MessageLoop::current()->RunAllPending();
343 EXPECT_EQ(attention_color, frame_view->title_label_->GetColor()); 328 EXPECT_EQ(attention_color, frame_view->title_label_->GetColor());
344 329
345 // Test that we cannot bring up other minimized panel if the mouse is over 330 // Test that we cannot bring up other minimized panel if the mouse is over
346 // the panel that draws attension. 331 // the panel that draws attension.
347 EXPECT_FALSE(PanelManager::GetInstance()-> 332 EXPECT_FALSE(PanelManager::GetInstance()->
348 ShouldBringUpTitlebarForAllMinimizedPanels( 333 ShouldBringUpTitlebars(panel->GetBounds().x(), panel->GetBounds().y()));
349 panel->GetBounds().x(), panel->GetBounds().y()));
350 334
351 // Test that we cannot bring down the panel that is drawing the attention. 335 // Test that we cannot bring down the panel that is drawing the attention.
352 PanelManager::GetInstance()->BringUpOrDownTitlebarForAllMinimizedPanels( 336 PanelManager::GetInstance()->BringUpOrDownTitlebars(false);
353 false);
354 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); 337 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state());
355 338
356 // Test that the attention is cleared. 339 // Test that the attention is cleared.
357 browser_view->StopDrawingAttention(); 340 browser_view->StopDrawingAttention();
358 EXPECT_FALSE(browser_view->IsDrawingAttention()); 341 EXPECT_FALSE(browser_view->IsDrawingAttention());
359 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state()); 342 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state());
360 MessageLoop::current()->RunAllPending(); 343 MessageLoop::current()->RunAllPending();
361 EXPECT_NE(attention_color, frame_view->title_label_->GetColor()); 344 EXPECT_NE(attention_color, frame_view->title_label_->GetColor());
362 345
363 panel->Close(); 346 panel->Close();
364 } 347 }
348
349 void TestChangeAutoHideTaskBarThickness() {
350 int bottom_bar_thickness = 20;
351 int right_bar_thickness = 30;
352 mock_auto_hiding_desktop_bar()->EnableAutoHiding(
353 AutoHidingDesktopBar::ALIGN_BOTTOM, true, bottom_bar_thickness);
354 mock_auto_hiding_desktop_bar()->EnableAutoHiding(
355 AutoHidingDesktopBar::ALIGN_RIGHT, true, right_bar_thickness);
356
357 Panel* panel = CreatePanel("PanelTest");
358 EXPECT_EQ(testing_work_area().height() - bottom_bar_thickness,
359 panel->GetBounds().bottom());
360 EXPECT_EQ(testing_work_area().right() - right_bar_thickness,
361 panel->GetBounds().right());
362
363 bottom_bar_thickness += 10;
364 right_bar_thickness += 15;
365 mock_auto_hiding_desktop_bar()->SetThickness(
366 AutoHidingDesktopBar::ALIGN_BOTTOM, bottom_bar_thickness);
367 mock_auto_hiding_desktop_bar()->SetThickness(
368 AutoHidingDesktopBar::ALIGN_RIGHT, right_bar_thickness);
369 MessageLoop::current()->RunAllPending();
370 EXPECT_EQ(testing_work_area().height() - bottom_bar_thickness,
371 panel->GetBounds().bottom());
372 EXPECT_EQ(testing_work_area().right() - right_bar_thickness,
373 panel->GetBounds().right());
374
375 bottom_bar_thickness -= 20;
376 right_bar_thickness -= 10;
377 mock_auto_hiding_desktop_bar()->SetThickness(
378 AutoHidingDesktopBar::ALIGN_BOTTOM, bottom_bar_thickness);
379 mock_auto_hiding_desktop_bar()->SetThickness(
380 AutoHidingDesktopBar::ALIGN_RIGHT, right_bar_thickness);
381 MessageLoop::current()->RunAllPending();
382 EXPECT_EQ(testing_work_area().height() - bottom_bar_thickness,
383 panel->GetBounds().bottom());
384 EXPECT_EQ(testing_work_area().right() - right_bar_thickness,
385 panel->GetBounds().right());
386
387 panel->Close();
388 }
365 }; 389 };
366 390
367 // Panel is not supported for Linux view yet. 391 // Panel is not supported for Linux view yet.
368 #if !defined(OS_LINUX) || !defined(TOOLKIT_VIEWS) 392 #if !defined(OS_LINUX) || !defined(TOOLKIT_VIEWS)
369 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, CreatePanel) { 393 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, CreatePanel) {
370 PanelBrowserView* browser_view = CreatePanelBrowserView("PanelTest", 394 Panel* panel = CreatePanel("PanelTest");
371 SHOW_AS_ACTIVE); 395 PanelBrowserView* browser_view = GetBrowserView(panel);
372 PanelBrowserFrameView* frame_view = browser_view->GetFrameView(); 396 PanelBrowserFrameView* frame_view = browser_view->GetFrameView();
373 397
374 // The bounds animation should not be triggered when the panel is up for the 398 // The bounds animation should not be triggered when the panel is up for the
375 // first time. 399 // first time.
376 EXPECT_FALSE(browser_view->bounds_animator_.get()); 400 EXPECT_FALSE(browser_view->bounds_animator_.get());
377 401
378 // We should have icon, text, settings button and close button. 402 // We should have icon, text, settings button and close button.
379 EXPECT_EQ(4, frame_view->child_count()); 403 EXPECT_EQ(4, frame_view->child_count());
380 EXPECT_TRUE(frame_view->Contains(frame_view->title_icon_)); 404 EXPECT_TRUE(frame_view->Contains(frame_view->title_icon_));
381 EXPECT_TRUE(frame_view->Contains(frame_view->title_label_)); 405 EXPECT_TRUE(frame_view->Contains(frame_view->title_label_));
(...skipping 29 matching lines...) Expand all
411 frame_view->close_button_->x()); 435 frame_view->close_button_->x());
412 436
413 // Validate that the controls should be updated when the activation state is 437 // Validate that the controls should be updated when the activation state is
414 // changed. 438 // changed.
415 frame_view->UpdateControlStyles(PanelBrowserFrameView::PAINT_AS_ACTIVE); 439 frame_view->UpdateControlStyles(PanelBrowserFrameView::PAINT_AS_ACTIVE);
416 SkColor title_label_color1 = frame_view->title_label_->GetColor(); 440 SkColor title_label_color1 = frame_view->title_label_->GetColor();
417 frame_view->UpdateControlStyles(PanelBrowserFrameView::PAINT_AS_INACTIVE); 441 frame_view->UpdateControlStyles(PanelBrowserFrameView::PAINT_AS_INACTIVE);
418 SkColor title_label_color2 = frame_view->title_label_->GetColor(); 442 SkColor title_label_color2 = frame_view->title_label_->GetColor();
419 EXPECT_NE(title_label_color1, title_label_color2); 443 EXPECT_NE(title_label_color1, title_label_color2);
420 444
421 browser_view->panel()->Close(); 445 panel->Close();
422 } 446 }
423 447
424 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, ShowPanelActiveOrInactive) { 448 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, ShowPanelActiveOrInactive) {
425 TestShowPanelActiveOrInactive(); 449 TestShowPanelActiveOrInactive();
426 } 450 }
427 451
428 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, ShowOrHideSettingsButton) { 452 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, ShowOrHideSettingsButton) {
429 PanelBrowserView* browser_view = CreatePanelBrowserView("PanelTest", 453 Panel* panel = CreatePanel("PanelTest");
430 SHOW_AS_ACTIVE); 454 PanelBrowserFrameView* frame_view = GetBrowserView(panel)->GetFrameView();
431 PanelBrowserFrameView* frame_view = browser_view->GetFrameView();
432 455
433 // Create and hook up the MockMouseWatcher so that we can simulate if the 456 // Create and hook up the MockMouseWatcher so that we can simulate if the
434 // mouse is over the panel. 457 // mouse is over the panel.
435 MockMouseWatcher* mouse_watcher = new MockMouseWatcher(frame_view); 458 MockMouseWatcher* mouse_watcher = new MockMouseWatcher(frame_view);
436 frame_view->set_mouse_watcher(mouse_watcher); 459 frame_view->set_mouse_watcher(mouse_watcher);
437 460
438 // When the panel is created, it is active. Since we cannot programatically 461 // When the panel is created, it is active. Since we cannot programatically
439 // bring the panel back to active state once it is deactivated, we have to 462 // bring the panel back to active state once it is deactivated, we have to
440 // test the cases that the panel is active first. 463 // test the cases that the panel is active first.
441 EXPECT_TRUE(browser_view->panel()->IsActive()); 464 EXPECT_TRUE(panel->IsActive());
442 465
443 // When the panel is active, the settings button should always be visible. 466 // When the panel is active, the settings button should always be visible.
444 mouse_watcher->MoveMouse(true); 467 mouse_watcher->MoveMouse(true);
445 EXPECT_TRUE(frame_view->settings_button_->IsVisible()); 468 EXPECT_TRUE(frame_view->settings_button_->IsVisible());
446 mouse_watcher->MoveMouse(false); 469 mouse_watcher->MoveMouse(false);
447 EXPECT_TRUE(frame_view->settings_button_->IsVisible()); 470 EXPECT_TRUE(frame_view->settings_button_->IsVisible());
448 471
449 // When the panel is inactive, the options button is active per the mouse over 472 // When the panel is inactive, the options button is active per the mouse over
450 // the panel or not. 473 // the panel or not.
451 browser_view->panel()->Deactivate(); 474 panel->Deactivate();
452 EXPECT_FALSE(browser_view->panel()->IsActive()); 475 EXPECT_FALSE(panel->IsActive());
453 476
454 mouse_watcher->MoveMouse(true); 477 mouse_watcher->MoveMouse(true);
455 EXPECT_TRUE(frame_view->settings_button_->IsVisible()); 478 EXPECT_TRUE(frame_view->settings_button_->IsVisible());
456 mouse_watcher->MoveMouse(false); 479 mouse_watcher->MoveMouse(false);
457 EXPECT_FALSE(frame_view->settings_button_->IsVisible()); 480 EXPECT_FALSE(frame_view->settings_button_->IsVisible());
458 } 481 }
459 482
460 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, SetBoundsAnimation) { 483 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, SetBoundsAnimation) {
461 PanelBrowserView* browser_view = CreatePanelBrowserView("PanelTest", 484 Panel* panel = CreatePanel("PanelTest");
462 SHOW_AS_ACTIVE); 485 PanelBrowserView* browser_view = GetBrowserView(panel);
463 486
464 // Validate that animation should be triggered when SetBounds is called. 487 // Validate that animation should be triggered when SetBounds is called.
465 gfx::Rect target_bounds(browser_view->GetBounds()); 488 gfx::Rect target_bounds(browser_view->GetBounds());
466 target_bounds.Offset(20, -30); 489 target_bounds.Offset(20, -30);
467 target_bounds.set_width(target_bounds.width() + 100); 490 target_bounds.set_width(target_bounds.width() + 100);
468 target_bounds.set_height(target_bounds.height() + 50); 491 target_bounds.set_height(target_bounds.height() + 50);
469 browser_view->SetBounds(target_bounds); 492 browser_view->SetBounds(target_bounds);
470 ASSERT_TRUE(browser_view->bounds_animator_.get()); 493 ASSERT_TRUE(browser_view->bounds_animator_.get());
471 EXPECT_TRUE(browser_view->bounds_animator_->is_animating()); 494 EXPECT_TRUE(browser_view->bounds_animator_->is_animating());
472 EXPECT_NE(browser_view->GetBounds(), target_bounds); 495 EXPECT_NE(browser_view->GetBounds(), target_bounds);
473 WaitTillBoundsAnimationFinished(browser_view); 496 WaitTillBoundsAnimationFinished(browser_view);
474 EXPECT_EQ(browser_view->GetBounds(), target_bounds); 497 EXPECT_EQ(browser_view->GetBounds(), target_bounds);
475 498
476 // Validates that no animation should be triggered for the panel currently 499 // Validates that no animation should be triggered for the panel currently
477 // being dragged. 500 // being dragged.
478 browser_view->OnTitlebarMousePressed(gfx::Point( 501 browser_view->OnTitlebarMousePressed(gfx::Point(
479 target_bounds.x(), target_bounds.y())); 502 target_bounds.x(), target_bounds.y()));
480 browser_view->OnTitlebarMouseDragged(gfx::Point( 503 browser_view->OnTitlebarMouseDragged(gfx::Point(
481 target_bounds.x() + 5, target_bounds.y() + 5)); 504 target_bounds.x() + 5, target_bounds.y() + 5));
482 EXPECT_FALSE(browser_view->bounds_animator_->is_animating()); 505 EXPECT_FALSE(browser_view->bounds_animator_->is_animating());
483 browser_view->OnTitlebarMouseCaptureLost(); 506 browser_view->OnTitlebarMouseCaptureLost();
484 507
485 browser_view->panel()->Close(); 508 panel->Close();
486 } 509 }
487 510
488 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, CreateSettingsMenu) { 511 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, CreateSettingsMenu) {
489 TestCreateSettingsMenuForExtension( 512 TestCreateSettingsMenuForExtension(
490 FILE_PATH_LITERAL("extension1"), Extension::EXTERNAL_POLICY_DOWNLOAD, 513 FILE_PATH_LITERAL("extension1"), Extension::EXTERNAL_POLICY_DOWNLOAD,
491 "", ""); 514 "", "");
492 TestCreateSettingsMenuForExtension( 515 TestCreateSettingsMenuForExtension(
493 FILE_PATH_LITERAL("extension2"), Extension::INVALID, 516 FILE_PATH_LITERAL("extension2"), Extension::INVALID,
494 "http://home", "options.html"); 517 "http://home", "options.html");
495 } 518 }
496 519
497 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, MinimizeAndRestore) { 520 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest,
498 TestMinimizeAndRestore(); 521 MinimizeAndRestoreOnNormalTaskBar) {
522 TestMinimizeAndRestore(false);
523 }
524
525 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest,
526 MinimizeAndRestoreOnAutoHideTaskBar) {
527 TestMinimizeAndRestore(true);
499 } 528 }
500 529
501 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, DrawAttention) { 530 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, DrawAttention) {
502 TestDrawAttention(); 531 TestDrawAttention();
503 } 532 }
533
534 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, ChangeAutoHideTaskBarThickness) {
535 TestChangeAutoHideTaskBarThickness();
536 }
504 #endif 537 #endif
OLDNEW
« no previous file with comments | « chrome/browser/ui/panels/panel_browser_view.cc ('k') | chrome/browser/ui/panels/panel_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698