OLD | NEW |
---|---|
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" |
jennb
2011/08/26 20:41:57
Should this be placed in alpha ordering?
jianli
2011/08/26 22:18:52
Done.
| |
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 Loading... | |
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 Loading... | |
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_hiding) { |
204 PanelBrowserView* browser_view1 = CreatePanelBrowserView("PanelTest1", | 175 PanelManager* panel_manager = PanelManager::GetInstance(); |
205 SHOW_AS_ACTIVE); | 176 int expected_bottom_on_minimized = testing_work_area().height(); |
206 Panel* panel1 = browser_view1->panel_.get(); | 177 int expected_bottom_on_unminimized = expected_bottom_on_minimized; |
178 | |
179 // Turn on auto-hiding if requested. | |
180 static const int bottom_thickness = 40; | |
181 mock_auto_hiding_desktop_bar()->EnableAutoHiding( | |
182 AutoHidingDesktopBar::ALIGN_BOTTOM, | |
183 enable_auto_hiding, | |
184 bottom_thickness); | |
185 if (enable_auto_hiding) | |
186 expected_bottom_on_unminimized -= bottom_thickness; | |
187 | |
188 // Create and test one panel first. | |
189 Panel* panel1 = CreatePanel("PanelTest1"); | |
190 PanelBrowserView* browser_view1 = GetBrowserView(panel1); | |
207 PanelBrowserFrameView* frame_view1 = browser_view1->GetFrameView(); | 191 PanelBrowserFrameView* frame_view1 = browser_view1->GetFrameView(); |
208 | 192 |
209 // Test minimizing/restoring an individual panel. | 193 // Test minimizing/restoring an individual panel. |
210 EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state()); | 194 EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state()); |
211 int initial_height = panel1->GetBounds().height(); | 195 int initial_height = panel1->GetBounds().height(); |
212 int titlebar_height = | 196 int titlebar_height = frame_view1->NonClientTopBorderHeight(); |
213 browser_view1->GetFrameView()->NonClientTopBorderHeight(); | |
214 | 197 |
215 panel1->SetExpansionState(Panel::MINIMIZED); | 198 panel1->SetExpansionState(Panel::MINIMIZED); |
216 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); | 199 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); |
217 EXPECT_LT(panel1->GetBounds().height(), titlebar_height); | 200 EXPECT_LT(panel1->GetBounds().height(), titlebar_height); |
218 EXPECT_GT(panel1->GetBounds().height(), 0); | 201 EXPECT_GT(panel1->GetBounds().height(), 0); |
202 EXPECT_EQ(expected_bottom_on_minimized, panel1->GetBounds().bottom()); | |
219 EXPECT_TRUE(IsMouseWatcherStarted()); | 203 EXPECT_TRUE(IsMouseWatcherStarted()); |
220 EXPECT_FALSE(panel1->IsActive()); | 204 EXPECT_FALSE(panel1->IsActive()); |
221 WaitTillBoundsAnimationFinished(browser_view1); | 205 WaitTillBoundsAnimationFinished(browser_view1); |
222 | 206 |
223 panel1->SetExpansionState(Panel::TITLE_ONLY); | 207 panel1->SetExpansionState(Panel::TITLE_ONLY); |
224 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); | 208 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); |
225 EXPECT_EQ(titlebar_height, panel1->GetBounds().height()); | 209 EXPECT_EQ(titlebar_height, panel1->GetBounds().height()); |
210 EXPECT_EQ(expected_bottom_on_unminimized, panel1->GetBounds().bottom()); | |
226 WaitTillBoundsAnimationFinished(browser_view1); | 211 WaitTillBoundsAnimationFinished(browser_view1); |
227 EXPECT_TRUE(frame_view1->close_button_->IsVisible()); | 212 EXPECT_TRUE(frame_view1->close_button_->IsVisible()); |
228 EXPECT_TRUE(frame_view1->title_icon_->IsVisible()); | 213 EXPECT_TRUE(frame_view1->title_icon_->IsVisible()); |
229 EXPECT_TRUE(frame_view1->title_label_->IsVisible()); | 214 EXPECT_TRUE(frame_view1->title_label_->IsVisible()); |
230 | 215 |
231 panel1->SetExpansionState(Panel::EXPANDED); | 216 panel1->SetExpansionState(Panel::EXPANDED); |
232 EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state()); | 217 EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state()); |
233 EXPECT_EQ(initial_height, panel1->GetBounds().height()); | 218 EXPECT_EQ(initial_height, panel1->GetBounds().height()); |
219 EXPECT_EQ(expected_bottom_on_unminimized, panel1->GetBounds().bottom()); | |
234 WaitTillBoundsAnimationFinished(browser_view1); | 220 WaitTillBoundsAnimationFinished(browser_view1); |
235 EXPECT_TRUE(frame_view1->close_button_->IsVisible()); | 221 EXPECT_TRUE(frame_view1->close_button_->IsVisible()); |
236 EXPECT_TRUE(frame_view1->title_icon_->IsVisible()); | 222 EXPECT_TRUE(frame_view1->title_icon_->IsVisible()); |
237 EXPECT_TRUE(frame_view1->title_label_->IsVisible()); | 223 EXPECT_TRUE(frame_view1->title_label_->IsVisible()); |
238 | 224 |
239 panel1->SetExpansionState(Panel::TITLE_ONLY); | 225 panel1->SetExpansionState(Panel::TITLE_ONLY); |
240 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); | 226 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); |
241 EXPECT_EQ(titlebar_height, panel1->GetBounds().height()); | 227 EXPECT_EQ(titlebar_height, panel1->GetBounds().height()); |
228 EXPECT_EQ(expected_bottom_on_unminimized, panel1->GetBounds().bottom()); | |
242 | 229 |
243 panel1->SetExpansionState(Panel::MINIMIZED); | 230 panel1->SetExpansionState(Panel::MINIMIZED); |
244 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); | 231 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); |
245 EXPECT_LT(panel1->GetBounds().height(), titlebar_height); | 232 EXPECT_LT(panel1->GetBounds().height(), titlebar_height); |
246 EXPECT_GT(panel1->GetBounds().height(), 0); | 233 EXPECT_GT(panel1->GetBounds().height(), 0); |
234 EXPECT_EQ(expected_bottom_on_minimized, panel1->GetBounds().bottom()); | |
247 | 235 |
248 // Create 2 more panels for more testing. | 236 // Create 2 more panels for more testing. |
249 PanelBrowserView* browser_view2 = CreatePanelBrowserView("PanelTest2", | 237 Panel* panel2 = CreatePanel("PanelTest2"); |
250 SHOW_AS_ACTIVE); | 238 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 | 239 |
257 // Test bringing up or down the title-bar of all minimized panels. | 240 // Test bringing up or down the title-bar of all minimized panels. |
258 EXPECT_EQ(Panel::EXPANDED, panel2->expansion_state()); | 241 EXPECT_EQ(Panel::EXPANDED, panel2->expansion_state()); |
259 panel3->SetExpansionState(Panel::MINIMIZED); | 242 panel3->SetExpansionState(Panel::MINIMIZED); |
260 EXPECT_EQ(Panel::MINIMIZED, panel3->expansion_state()); | 243 EXPECT_EQ(Panel::MINIMIZED, panel3->expansion_state()); |
261 | 244 |
262 PanelManager* panel_manager = PanelManager::GetInstance(); | 245 mock_auto_hiding_desktop_bar()->SetVisibility( |
263 | 246 AutoHidingDesktopBar::ALIGN_BOTTOM, AutoHidingDesktopBar::VISIBLE); |
264 panel_manager->BringUpOrDownTitlebarForAllMinimizedPanels(true); | 247 panel_manager->BringUpOrDownTitlebars(true); |
248 MessageLoop::current()->RunAllPending(); | |
265 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); | 249 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); |
266 EXPECT_EQ(Panel::EXPANDED, panel2->expansion_state()); | 250 EXPECT_EQ(Panel::EXPANDED, panel2->expansion_state()); |
267 EXPECT_EQ(Panel::TITLE_ONLY, panel3->expansion_state()); | 251 EXPECT_EQ(Panel::TITLE_ONLY, panel3->expansion_state()); |
268 | 252 |
269 panel_manager->BringUpOrDownTitlebarForAllMinimizedPanels(false); | 253 mock_auto_hiding_desktop_bar()->SetVisibility( |
254 AutoHidingDesktopBar::ALIGN_BOTTOM, AutoHidingDesktopBar::HIDDEN); | |
255 panel_manager->BringUpOrDownTitlebars(false); | |
256 MessageLoop::current()->RunAllPending(); | |
270 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); | 257 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); |
271 EXPECT_EQ(Panel::EXPANDED, panel2->expansion_state()); | 258 EXPECT_EQ(Panel::EXPANDED, panel2->expansion_state()); |
272 EXPECT_EQ(Panel::MINIMIZED, panel3->expansion_state()); | 259 EXPECT_EQ(Panel::MINIMIZED, panel3->expansion_state()); |
273 | 260 |
274 // Test if it is OK to bring up title-bar given the mouse position. | 261 // Test if it is OK to bring up title-bar given the mouse position. |
275 EXPECT_TRUE(panel_manager->ShouldBringUpTitlebarForAllMinimizedPanels( | 262 EXPECT_TRUE(panel_manager->ShouldBringUpTitlebars( |
276 panel1->GetBounds().x(), panel1->GetBounds().y())); | 263 panel1->GetBounds().x(), panel1->GetBounds().y())); |
277 EXPECT_FALSE(panel_manager->ShouldBringUpTitlebarForAllMinimizedPanels( | 264 EXPECT_FALSE(panel_manager->ShouldBringUpTitlebars( |
278 panel2->GetBounds().x(), panel2->GetBounds().y())); | 265 panel2->GetBounds().x(), panel2->GetBounds().y())); |
279 EXPECT_TRUE(panel_manager->ShouldBringUpTitlebarForAllMinimizedPanels( | 266 EXPECT_TRUE(panel_manager->ShouldBringUpTitlebars( |
280 panel3->GetBounds().right() - 1, panel3->GetBounds().bottom() - 1)); | 267 panel3->GetBounds().right() - 1, panel3->GetBounds().bottom() - 1)); |
281 EXPECT_TRUE(panel_manager->ShouldBringUpTitlebarForAllMinimizedPanels( | 268 EXPECT_TRUE(panel_manager->ShouldBringUpTitlebars( |
282 panel3->GetBounds().right() - 1, panel3->GetBounds().bottom() + 10)); | 269 panel3->GetBounds().right() - 1, panel3->GetBounds().bottom() + 10)); |
283 EXPECT_FALSE(panel_manager->ShouldBringUpTitlebarForAllMinimizedPanels( | 270 EXPECT_FALSE(panel_manager->ShouldBringUpTitlebars( |
284 0, 0)); | 271 0, 0)); |
285 | 272 |
286 // Test that the panel in title-only state should not be minimized | 273 // 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. | 274 // regardless of the current mouse position when the panel is being dragged. |
288 panel1->SetExpansionState(Panel::TITLE_ONLY); | 275 panel1->SetExpansionState(Panel::TITLE_ONLY); |
289 EXPECT_FALSE(panel_manager->ShouldBringUpTitlebarForAllMinimizedPanels( | 276 EXPECT_FALSE(panel_manager->ShouldBringUpTitlebars( |
290 0, 0)); | 277 0, 0)); |
291 browser_view1->OnTitlebarMousePressed(panel1->GetBounds().origin()); | 278 browser_view1->OnTitlebarMousePressed(panel1->GetBounds().origin()); |
292 browser_view1->OnTitlebarMouseDragged( | 279 browser_view1->OnTitlebarMouseDragged( |
293 panel1->GetBounds().origin().Subtract(gfx::Point(5, 5))); | 280 panel1->GetBounds().origin().Subtract(gfx::Point(5, 5))); |
294 EXPECT_TRUE(panel_manager->ShouldBringUpTitlebarForAllMinimizedPanels( | 281 EXPECT_TRUE(panel_manager->ShouldBringUpTitlebars( |
295 0, 0)); | 282 0, 0)); |
296 browser_view1->OnTitlebarMouseReleased(); | 283 browser_view1->OnTitlebarMouseReleased(); |
297 | 284 |
298 panel1->Close(); | 285 panel1->Close(); |
299 EXPECT_TRUE(IsMouseWatcherStarted()); | 286 EXPECT_TRUE(IsMouseWatcherStarted()); |
300 panel2->Close(); | 287 panel2->Close(); |
301 EXPECT_TRUE(IsMouseWatcherStarted()); | 288 EXPECT_TRUE(IsMouseWatcherStarted()); |
302 panel3->Close(); | 289 panel3->Close(); |
303 EXPECT_FALSE(IsMouseWatcherStarted()); | 290 EXPECT_FALSE(IsMouseWatcherStarted()); |
304 } | 291 } |
305 | 292 |
306 void TestDrawAttention() { | 293 void TestDrawAttention() { |
307 PanelBrowserView* browser_view = CreatePanelBrowserView("PanelTest", | 294 Panel* panel = CreatePanel("PanelTest"); |
308 SHOW_AS_ACTIVE); | 295 PanelBrowserView* browser_view = GetBrowserView(panel); |
309 PanelBrowserFrameView* frame_view = browser_view->GetFrameView(); | 296 PanelBrowserFrameView* frame_view = browser_view->GetFrameView(); |
310 Panel* panel = browser_view->panel_.get(); | |
311 SkColor attention_color = frame_view->GetTitleColor( | 297 SkColor attention_color = frame_view->GetTitleColor( |
312 PanelBrowserFrameView::PAINT_FOR_ATTENTION); | 298 PanelBrowserFrameView::PAINT_FOR_ATTENTION); |
313 | 299 |
314 // Test that the attention should not be drawn if the expanded panel is in | 300 // Test that the attention should not be drawn if the expanded panel is in |
315 // focus. | 301 // focus. |
316 browser_view->DrawAttention(); | 302 browser_view->DrawAttention(); |
317 EXPECT_FALSE(browser_view->IsDrawingAttention()); | 303 EXPECT_FALSE(browser_view->IsDrawingAttention()); |
318 MessageLoop::current()->RunAllPending(); | 304 MessageLoop::current()->RunAllPending(); |
319 EXPECT_NE(attention_color, frame_view->title_label_->GetColor()); | 305 EXPECT_NE(attention_color, frame_view->title_label_->GetColor()); |
320 | 306 |
(...skipping 17 matching lines...) Expand all Loading... | |
338 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state()); | 324 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state()); |
339 browser_view->DrawAttention(); | 325 browser_view->DrawAttention(); |
340 EXPECT_TRUE(browser_view->IsDrawingAttention()); | 326 EXPECT_TRUE(browser_view->IsDrawingAttention()); |
341 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); | 327 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); |
342 MessageLoop::current()->RunAllPending(); | 328 MessageLoop::current()->RunAllPending(); |
343 EXPECT_EQ(attention_color, frame_view->title_label_->GetColor()); | 329 EXPECT_EQ(attention_color, frame_view->title_label_->GetColor()); |
344 | 330 |
345 // Test that we cannot bring up other minimized panel if the mouse is over | 331 // Test that we cannot bring up other minimized panel if the mouse is over |
346 // the panel that draws attension. | 332 // the panel that draws attension. |
347 EXPECT_FALSE(PanelManager::GetInstance()-> | 333 EXPECT_FALSE(PanelManager::GetInstance()-> |
348 ShouldBringUpTitlebarForAllMinimizedPanels( | 334 ShouldBringUpTitlebars(panel->GetBounds().x(), panel->GetBounds().y())); |
349 panel->GetBounds().x(), panel->GetBounds().y())); | |
350 | 335 |
351 // Test that we cannot bring down the panel that is drawing the attention. | 336 // Test that we cannot bring down the panel that is drawing the attention. |
352 PanelManager::GetInstance()->BringUpOrDownTitlebarForAllMinimizedPanels( | 337 PanelManager::GetInstance()->BringUpOrDownTitlebars(false); |
353 false); | |
354 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); | 338 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); |
355 | 339 |
356 // Test that the attention is cleared. | 340 // Test that the attention is cleared. |
357 browser_view->StopDrawingAttention(); | 341 browser_view->StopDrawingAttention(); |
358 EXPECT_FALSE(browser_view->IsDrawingAttention()); | 342 EXPECT_FALSE(browser_view->IsDrawingAttention()); |
359 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state()); | 343 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state()); |
360 MessageLoop::current()->RunAllPending(); | 344 MessageLoop::current()->RunAllPending(); |
361 EXPECT_NE(attention_color, frame_view->title_label_->GetColor()); | 345 EXPECT_NE(attention_color, frame_view->title_label_->GetColor()); |
362 | 346 |
363 panel->Close(); | 347 panel->Close(); |
364 } | 348 } |
349 | |
350 void TestChangeAutoHideTaskBarThickness() { | |
351 int bottom_bar_thickness = 20; | |
352 int right_bar_thickness = 30; | |
353 mock_auto_hiding_desktop_bar()->EnableAutoHiding( | |
354 AutoHidingDesktopBar::ALIGN_BOTTOM, true, bottom_bar_thickness); | |
355 mock_auto_hiding_desktop_bar()->EnableAutoHiding( | |
356 AutoHidingDesktopBar::ALIGN_RIGHT, true, right_bar_thickness); | |
357 | |
358 Panel* panel = CreatePanel("PanelTest"); | |
359 EXPECT_EQ(testing_work_area().height() - bottom_bar_thickness, | |
360 panel->GetBounds().bottom()); | |
361 EXPECT_EQ(testing_work_area().right() - right_bar_thickness, | |
362 panel->GetBounds().right()); | |
363 | |
364 bottom_bar_thickness += 10; | |
365 right_bar_thickness += 15; | |
366 mock_auto_hiding_desktop_bar()->SetThickness( | |
367 AutoHidingDesktopBar::ALIGN_BOTTOM, bottom_bar_thickness); | |
368 mock_auto_hiding_desktop_bar()->SetThickness( | |
369 AutoHidingDesktopBar::ALIGN_RIGHT, right_bar_thickness); | |
370 MessageLoop::current()->RunAllPending(); | |
371 EXPECT_EQ(testing_work_area().height() - bottom_bar_thickness, | |
372 panel->GetBounds().bottom()); | |
373 EXPECT_EQ(testing_work_area().right() - right_bar_thickness, | |
374 panel->GetBounds().right()); | |
375 | |
376 bottom_bar_thickness -= 20; | |
377 right_bar_thickness -= 10; | |
378 mock_auto_hiding_desktop_bar()->SetThickness( | |
379 AutoHidingDesktopBar::ALIGN_BOTTOM, bottom_bar_thickness); | |
380 mock_auto_hiding_desktop_bar()->SetThickness( | |
381 AutoHidingDesktopBar::ALIGN_RIGHT, right_bar_thickness); | |
382 MessageLoop::current()->RunAllPending(); | |
383 EXPECT_EQ(testing_work_area().height() - bottom_bar_thickness, | |
384 panel->GetBounds().bottom()); | |
385 EXPECT_EQ(testing_work_area().right() - right_bar_thickness, | |
386 panel->GetBounds().right()); | |
387 | |
388 panel->Close(); | |
389 } | |
365 }; | 390 }; |
366 | 391 |
367 // Panel is not supported for Linux view yet. | 392 // Panel is not supported for Linux view yet. |
368 #if !defined(OS_LINUX) || !defined(TOOLKIT_VIEWS) | 393 #if !defined(OS_LINUX) || !defined(TOOLKIT_VIEWS) |
369 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, CreatePanel) { | 394 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, CreatePanel) { |
370 PanelBrowserView* browser_view = CreatePanelBrowserView("PanelTest", | 395 Panel* panel = CreatePanel("PanelTest"); |
371 SHOW_AS_ACTIVE); | 396 PanelBrowserView* browser_view = GetBrowserView(panel); |
372 PanelBrowserFrameView* frame_view = browser_view->GetFrameView(); | 397 PanelBrowserFrameView* frame_view = browser_view->GetFrameView(); |
373 | 398 |
374 // The bounds animation should not be triggered when the panel is up for the | 399 // The bounds animation should not be triggered when the panel is up for the |
375 // first time. | 400 // first time. |
376 EXPECT_FALSE(browser_view->bounds_animator_.get()); | 401 EXPECT_FALSE(browser_view->bounds_animator_.get()); |
377 | 402 |
378 // We should have icon, text, settings button and close button. | 403 // We should have icon, text, settings button and close button. |
379 EXPECT_EQ(4, frame_view->child_count()); | 404 EXPECT_EQ(4, frame_view->child_count()); |
380 EXPECT_TRUE(frame_view->Contains(frame_view->title_icon_)); | 405 EXPECT_TRUE(frame_view->Contains(frame_view->title_icon_)); |
381 EXPECT_TRUE(frame_view->Contains(frame_view->title_label_)); | 406 EXPECT_TRUE(frame_view->Contains(frame_view->title_label_)); |
(...skipping 29 matching lines...) Expand all Loading... | |
411 frame_view->close_button_->x()); | 436 frame_view->close_button_->x()); |
412 | 437 |
413 // Validate that the controls should be updated when the activation state is | 438 // Validate that the controls should be updated when the activation state is |
414 // changed. | 439 // changed. |
415 frame_view->UpdateControlStyles(PanelBrowserFrameView::PAINT_AS_ACTIVE); | 440 frame_view->UpdateControlStyles(PanelBrowserFrameView::PAINT_AS_ACTIVE); |
416 SkColor title_label_color1 = frame_view->title_label_->GetColor(); | 441 SkColor title_label_color1 = frame_view->title_label_->GetColor(); |
417 frame_view->UpdateControlStyles(PanelBrowserFrameView::PAINT_AS_INACTIVE); | 442 frame_view->UpdateControlStyles(PanelBrowserFrameView::PAINT_AS_INACTIVE); |
418 SkColor title_label_color2 = frame_view->title_label_->GetColor(); | 443 SkColor title_label_color2 = frame_view->title_label_->GetColor(); |
419 EXPECT_NE(title_label_color1, title_label_color2); | 444 EXPECT_NE(title_label_color1, title_label_color2); |
420 | 445 |
421 browser_view->panel()->Close(); | 446 panel->Close(); |
422 } | 447 } |
423 | 448 |
424 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, ShowPanelActiveOrInactive) { | 449 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, ShowPanelActiveOrInactive) { |
425 TestShowPanelActiveOrInactive(); | 450 TestShowPanelActiveOrInactive(); |
426 } | 451 } |
427 | 452 |
428 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, ShowOrHideSettingsButton) { | 453 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, ShowOrHideSettingsButton) { |
429 PanelBrowserView* browser_view = CreatePanelBrowserView("PanelTest", | 454 Panel* panel = CreatePanel("PanelTest"); |
430 SHOW_AS_ACTIVE); | 455 PanelBrowserFrameView* frame_view = GetBrowserView(panel)->GetFrameView(); |
431 PanelBrowserFrameView* frame_view = browser_view->GetFrameView(); | |
432 | 456 |
433 // Create and hook up the MockMouseWatcher so that we can simulate if the | 457 // Create and hook up the MockMouseWatcher so that we can simulate if the |
434 // mouse is over the panel. | 458 // mouse is over the panel. |
435 MockMouseWatcher* mouse_watcher = new MockMouseWatcher(frame_view); | 459 MockMouseWatcher* mouse_watcher = new MockMouseWatcher(frame_view); |
436 frame_view->set_mouse_watcher(mouse_watcher); | 460 frame_view->set_mouse_watcher(mouse_watcher); |
437 | 461 |
438 // When the panel is created, it is active. Since we cannot programatically | 462 // 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 | 463 // bring the panel back to active state once it is deactivated, we have to |
440 // test the cases that the panel is active first. | 464 // test the cases that the panel is active first. |
441 EXPECT_TRUE(browser_view->panel()->IsActive()); | 465 EXPECT_TRUE(panel->IsActive()); |
442 | 466 |
443 // When the panel is active, the settings button should always be visible. | 467 // When the panel is active, the settings button should always be visible. |
444 mouse_watcher->MoveMouse(true); | 468 mouse_watcher->MoveMouse(true); |
445 EXPECT_TRUE(frame_view->settings_button_->IsVisible()); | 469 EXPECT_TRUE(frame_view->settings_button_->IsVisible()); |
446 mouse_watcher->MoveMouse(false); | 470 mouse_watcher->MoveMouse(false); |
447 EXPECT_TRUE(frame_view->settings_button_->IsVisible()); | 471 EXPECT_TRUE(frame_view->settings_button_->IsVisible()); |
448 | 472 |
449 // When the panel is inactive, the options button is active per the mouse over | 473 // When the panel is inactive, the options button is active per the mouse over |
450 // the panel or not. | 474 // the panel or not. |
451 browser_view->panel()->Deactivate(); | 475 panel->Deactivate(); |
452 EXPECT_FALSE(browser_view->panel()->IsActive()); | 476 EXPECT_FALSE(panel->IsActive()); |
453 | 477 |
454 mouse_watcher->MoveMouse(true); | 478 mouse_watcher->MoveMouse(true); |
455 EXPECT_TRUE(frame_view->settings_button_->IsVisible()); | 479 EXPECT_TRUE(frame_view->settings_button_->IsVisible()); |
456 mouse_watcher->MoveMouse(false); | 480 mouse_watcher->MoveMouse(false); |
457 EXPECT_FALSE(frame_view->settings_button_->IsVisible()); | 481 EXPECT_FALSE(frame_view->settings_button_->IsVisible()); |
458 } | 482 } |
459 | 483 |
460 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, SetBoundsAnimation) { | 484 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, SetBoundsAnimation) { |
461 PanelBrowserView* browser_view = CreatePanelBrowserView("PanelTest", | 485 Panel* panel = CreatePanel("PanelTest"); |
462 SHOW_AS_ACTIVE); | 486 PanelBrowserView* browser_view = GetBrowserView(panel); |
463 | 487 |
464 // Validate that animation should be triggered when SetBounds is called. | 488 // Validate that animation should be triggered when SetBounds is called. |
465 gfx::Rect target_bounds(browser_view->GetBounds()); | 489 gfx::Rect target_bounds(browser_view->GetBounds()); |
466 target_bounds.Offset(20, -30); | 490 target_bounds.Offset(20, -30); |
467 target_bounds.set_width(target_bounds.width() + 100); | 491 target_bounds.set_width(target_bounds.width() + 100); |
468 target_bounds.set_height(target_bounds.height() + 50); | 492 target_bounds.set_height(target_bounds.height() + 50); |
469 browser_view->SetBounds(target_bounds); | 493 browser_view->SetBounds(target_bounds); |
470 ASSERT_TRUE(browser_view->bounds_animator_.get()); | 494 ASSERT_TRUE(browser_view->bounds_animator_.get()); |
471 EXPECT_TRUE(browser_view->bounds_animator_->is_animating()); | 495 EXPECT_TRUE(browser_view->bounds_animator_->is_animating()); |
472 EXPECT_NE(browser_view->GetBounds(), target_bounds); | 496 EXPECT_NE(browser_view->GetBounds(), target_bounds); |
473 WaitTillBoundsAnimationFinished(browser_view); | 497 WaitTillBoundsAnimationFinished(browser_view); |
474 EXPECT_EQ(browser_view->GetBounds(), target_bounds); | 498 EXPECT_EQ(browser_view->GetBounds(), target_bounds); |
475 | 499 |
476 // Validates that no animation should be triggered for the panel currently | 500 // Validates that no animation should be triggered for the panel currently |
477 // being dragged. | 501 // being dragged. |
478 browser_view->OnTitlebarMousePressed(gfx::Point( | 502 browser_view->OnTitlebarMousePressed(gfx::Point( |
479 target_bounds.x(), target_bounds.y())); | 503 target_bounds.x(), target_bounds.y())); |
480 browser_view->OnTitlebarMouseDragged(gfx::Point( | 504 browser_view->OnTitlebarMouseDragged(gfx::Point( |
481 target_bounds.x() + 5, target_bounds.y() + 5)); | 505 target_bounds.x() + 5, target_bounds.y() + 5)); |
482 EXPECT_FALSE(browser_view->bounds_animator_->is_animating()); | 506 EXPECT_FALSE(browser_view->bounds_animator_->is_animating()); |
483 browser_view->OnTitlebarMouseCaptureLost(); | 507 browser_view->OnTitlebarMouseCaptureLost(); |
484 | 508 |
485 browser_view->panel()->Close(); | 509 panel->Close(); |
486 } | 510 } |
487 | 511 |
488 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, CreateSettingsMenu) { | 512 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, CreateSettingsMenu) { |
489 TestCreateSettingsMenuForExtension( | 513 TestCreateSettingsMenuForExtension( |
490 FILE_PATH_LITERAL("extension1"), Extension::EXTERNAL_POLICY_DOWNLOAD, | 514 FILE_PATH_LITERAL("extension1"), Extension::EXTERNAL_POLICY_DOWNLOAD, |
491 "", ""); | 515 "", ""); |
492 TestCreateSettingsMenuForExtension( | 516 TestCreateSettingsMenuForExtension( |
493 FILE_PATH_LITERAL("extension2"), Extension::INVALID, | 517 FILE_PATH_LITERAL("extension2"), Extension::INVALID, |
494 "http://home", "options.html"); | 518 "http://home", "options.html"); |
495 } | 519 } |
496 | 520 |
497 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, MinimizeAndRestore) { | 521 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, |
498 TestMinimizeAndRestore(); | 522 MinimizeAndRestoreOnNormalTaskBar) { |
523 TestMinimizeAndRestore(false); | |
524 } | |
525 | |
526 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, | |
527 MinimizeAndRestoreOnAutoHideTaskBar) { | |
528 TestMinimizeAndRestore(true); | |
499 } | 529 } |
500 | 530 |
501 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, DrawAttention) { | 531 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, DrawAttention) { |
502 TestDrawAttention(); | 532 TestDrawAttention(); |
503 } | 533 } |
534 | |
535 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, ChangeAutoHideTaskBarThickness) { | |
536 TestChangeAutoHideTaskBarThickness(); | |
537 } | |
504 #endif | 538 #endif |
OLD | NEW |