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

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

Powered by Google App Engine
This is Rietveld 408576698