OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/bind.h" |
| 6 #include "base/utf_string_conversions.h" |
| 7 #include "chrome/browser/download/download_service.h" |
| 8 #include "chrome/browser/download/download_service_factory.h" |
| 9 #include "chrome/browser/net/url_request_mock_util.h" |
| 10 #include "chrome/browser/prefs/browser_prefs.h" |
| 11 #include "chrome/browser/prefs/pref_service.h" |
| 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h" |
| 14 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h" |
| 15 #include "chrome/browser/ui/browser_finder.h" |
| 16 #include "chrome/browser/ui/browser_list.h" |
| 17 #include "chrome/browser/ui/browser_window.h" |
| 18 #include "chrome/browser/ui/find_bar/find_bar.h" |
| 19 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
| 20 #include "chrome/browser/ui/panels/base_panel_browser_test.h" |
| 21 #include "chrome/browser/ui/panels/docked_panel_strip.h" |
| 22 #include "chrome/browser/ui/panels/native_panel.h" |
| 23 #include "chrome/browser/ui/panels/panel.h" |
| 24 #include "chrome/browser/ui/panels/panel_manager.h" |
| 25 #include "chrome/browser/ui/panels/test_panel_mouse_watcher.h" |
| 26 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 27 #include "chrome/browser/web_applications/web_app.h" |
| 28 #include "chrome/common/chrome_notification_types.h" |
| 29 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 30 #include "chrome/common/pref_names.h" |
| 31 #include "chrome/common/url_constants.h" |
| 32 #include "chrome/test/base/ui_test_utils.h" |
| 33 #include "content/public/browser/download_manager.h" |
| 34 #include "content/public/browser/notification_service.h" |
| 35 #include "content/public/browser/web_contents.h" |
| 36 #include "content/public/common/url_constants.h" |
| 37 #include "content/test/net/url_request_mock_http_job.h" |
| 38 #include "net/base/net_util.h" |
| 39 #include "testing/gtest/include/gtest/gtest.h" |
| 40 #include "ui/gfx/screen.h" |
| 41 |
| 42 using content::BrowserContext; |
| 43 using content::BrowserThread; |
| 44 using content::DownloadItem; |
| 45 using content::DownloadManager; |
| 46 using content::WebContents; |
| 47 using extensions::Extension; |
| 48 |
| 49 class PanelBrowserTest : public BasePanelBrowserTest { |
| 50 public: |
| 51 PanelBrowserTest() : BasePanelBrowserTest() { |
| 52 } |
| 53 |
| 54 protected: |
| 55 // Helper function for debugging. |
| 56 void PrintAllPanelBounds() { |
| 57 const std::vector<Panel*>& panels = PanelManager::GetInstance()->panels(); |
| 58 DLOG(WARNING) << "PanelBounds:"; |
| 59 for (size_t i = 0; i < panels.size(); ++i) { |
| 60 DLOG(WARNING) << "#=" << i |
| 61 << ", ptr=" << panels[i] |
| 62 << ", x=" << panels[i]->GetBounds().x() |
| 63 << ", y=" << panels[i]->GetBounds().y() |
| 64 << ", width=" << panels[i]->GetBounds().width() |
| 65 << ", height" << panels[i]->GetBounds().height(); |
| 66 } |
| 67 } |
| 68 |
| 69 std::vector<gfx::Rect> GetAllPanelBounds() { |
| 70 std::vector<Panel*> panels = PanelManager::GetInstance()->panels(); |
| 71 std::vector<gfx::Rect> bounds; |
| 72 for (size_t i = 0; i < panels.size(); i++) |
| 73 bounds.push_back(panels[i]->GetBounds()); |
| 74 return bounds; |
| 75 } |
| 76 |
| 77 std::vector<gfx::Rect> AddXDeltaToBounds(const std::vector<gfx::Rect>& bounds, |
| 78 const std::vector<int>& delta_x) { |
| 79 std::vector<gfx::Rect> new_bounds = bounds; |
| 80 for (size_t i = 0; i < bounds.size(); ++i) |
| 81 new_bounds[i].Offset(delta_x[i], 0); |
| 82 return new_bounds; |
| 83 } |
| 84 |
| 85 std::vector<Panel::ExpansionState> GetAllPanelExpansionStates() { |
| 86 std::vector<Panel*> panels = PanelManager::GetInstance()->panels(); |
| 87 std::vector<Panel::ExpansionState> expansion_states; |
| 88 for (size_t i = 0; i < panels.size(); i++) |
| 89 expansion_states.push_back(panels[i]->expansion_state()); |
| 90 return expansion_states; |
| 91 } |
| 92 |
| 93 std::vector<bool> GetAllPanelActiveStates() { |
| 94 std::vector<Panel*> panels = PanelManager::GetInstance()->panels(); |
| 95 std::vector<bool> active_states; |
| 96 for (size_t i = 0; i < panels.size(); i++) |
| 97 active_states.push_back(panels[i]->IsActive()); |
| 98 return active_states; |
| 99 } |
| 100 |
| 101 std::vector<bool> ProduceExpectedActiveStates( |
| 102 int expected_active_panel_index) { |
| 103 std::vector<Panel*> panels = PanelManager::GetInstance()->panels(); |
| 104 std::vector<bool> active_states; |
| 105 for (int i = 0; i < static_cast<int>(panels.size()); i++) |
| 106 active_states.push_back(i == expected_active_panel_index); |
| 107 return active_states; |
| 108 } |
| 109 |
| 110 void WaitForPanelActiveStates(const std::vector<bool>& old_states, |
| 111 const std::vector<bool>& new_states) { |
| 112 DCHECK(old_states.size() == new_states.size()); |
| 113 std::vector<Panel*> panels = PanelManager::GetInstance()->panels(); |
| 114 for (size_t i = 0; i < old_states.size(); i++) { |
| 115 if (old_states[i] != new_states[i]){ |
| 116 WaitForPanelActiveState( |
| 117 panels[i], new_states[i] ? SHOW_AS_ACTIVE : SHOW_AS_INACTIVE); |
| 118 } |
| 119 } |
| 120 } |
| 121 |
| 122 void TestMinimizeRestore() { |
| 123 // This constant is used to generate a point 'sufficiently higher then |
| 124 // top edge of the panel'. On some platforms (Mac) we extend hover area |
| 125 // a bit above the minimized panel as well, so it takes significant |
| 126 // distance to 'move mouse out' of the hover-sensitive area. |
| 127 const int kFarEnoughFromHoverArea = 153; |
| 128 |
| 129 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 130 std::vector<Panel*> panels = panel_manager->panels(); |
| 131 std::vector<gfx::Rect> test_begin_bounds = GetAllPanelBounds(); |
| 132 std::vector<gfx::Rect> expected_bounds = test_begin_bounds; |
| 133 std::vector<Panel::ExpansionState> expected_expansion_states( |
| 134 panels.size(), Panel::EXPANDED); |
| 135 std::vector<NativePanelTesting*> native_panels_testing(panels.size()); |
| 136 for (size_t i = 0; i < panels.size(); ++i) { |
| 137 native_panels_testing[i] = |
| 138 NativePanelTesting::Create(panels[i]->native_panel()); |
| 139 } |
| 140 |
| 141 // Verify titlebar click does not minimize. |
| 142 for (size_t index = 0; index < panels.size(); ++index) { |
| 143 // Press left mouse button. Verify nothing changed. |
| 144 native_panels_testing[index]->PressLeftMouseButtonTitlebar( |
| 145 panels[index]->GetBounds().origin()); |
| 146 EXPECT_EQ(expected_bounds, GetAllPanelBounds()); |
| 147 EXPECT_EQ(expected_expansion_states, GetAllPanelExpansionStates()); |
| 148 |
| 149 // Release mouse button. Verify nothing changed. |
| 150 native_panels_testing[index]->ReleaseMouseButtonTitlebar(); |
| 151 EXPECT_EQ(expected_bounds, GetAllPanelBounds()); |
| 152 EXPECT_EQ(expected_expansion_states, GetAllPanelExpansionStates()); |
| 153 } |
| 154 |
| 155 // Minimize all panels for next stage in test. |
| 156 for (size_t index = 0; index < panels.size(); ++index) { |
| 157 panels[index]->Minimize(); |
| 158 expected_bounds[index].set_height(panel::kMinimizedPanelHeight); |
| 159 expected_bounds[index].set_y( |
| 160 test_begin_bounds[index].y() + |
| 161 test_begin_bounds[index].height() - panel::kMinimizedPanelHeight); |
| 162 expected_expansion_states[index] = Panel::MINIMIZED; |
| 163 EXPECT_EQ(expected_bounds, GetAllPanelBounds()); |
| 164 EXPECT_EQ(expected_expansion_states, GetAllPanelExpansionStates()); |
| 165 } |
| 166 |
| 167 // Setup bounds and expansion states for minimized and titlebar-only |
| 168 // states. |
| 169 std::vector<Panel::ExpansionState> titlebar_exposed_states( |
| 170 panels.size(), Panel::TITLE_ONLY); |
| 171 std::vector<gfx::Rect> minimized_bounds = expected_bounds; |
| 172 std::vector<Panel::ExpansionState> minimized_states( |
| 173 panels.size(), Panel::MINIMIZED); |
| 174 std::vector<gfx::Rect> titlebar_exposed_bounds = test_begin_bounds; |
| 175 for (size_t index = 0; index < panels.size(); ++index) { |
| 176 titlebar_exposed_bounds[index].set_height( |
| 177 panels[index]->native_panel()->TitleOnlyHeight()); |
| 178 titlebar_exposed_bounds[index].set_y( |
| 179 test_begin_bounds[index].y() + |
| 180 test_begin_bounds[index].height() - |
| 181 panels[index]->native_panel()->TitleOnlyHeight()); |
| 182 } |
| 183 |
| 184 // Test hover. All panels are currently in minimized state. |
| 185 EXPECT_EQ(minimized_states, GetAllPanelExpansionStates()); |
| 186 for (size_t index = 0; index < panels.size(); ++index) { |
| 187 // Hover mouse on minimized panel. |
| 188 // Verify titlebar is exposed on all panels. |
| 189 gfx::Point hover_point(panels[index]->GetBounds().origin()); |
| 190 MoveMouseAndWaitForExpansionStateChange(panels[index], hover_point); |
| 191 EXPECT_EQ(titlebar_exposed_bounds, GetAllPanelBounds()); |
| 192 EXPECT_EQ(titlebar_exposed_states, GetAllPanelExpansionStates()); |
| 193 |
| 194 // Hover mouse above the panel. Verify all panels are minimized. |
| 195 hover_point.set_y( |
| 196 panels[index]->GetBounds().y() - kFarEnoughFromHoverArea); |
| 197 MoveMouseAndWaitForExpansionStateChange(panels[index], hover_point); |
| 198 EXPECT_EQ(minimized_bounds, GetAllPanelBounds()); |
| 199 EXPECT_EQ(minimized_states, GetAllPanelExpansionStates()); |
| 200 |
| 201 // Hover mouse below minimized panel. |
| 202 // Verify titlebar is exposed on all panels. |
| 203 hover_point.set_y(panels[index]->GetBounds().y() + |
| 204 panels[index]->GetBounds().height() + 5); |
| 205 MoveMouseAndWaitForExpansionStateChange(panels[index], hover_point); |
| 206 EXPECT_EQ(titlebar_exposed_bounds, GetAllPanelBounds()); |
| 207 EXPECT_EQ(titlebar_exposed_states, GetAllPanelExpansionStates()); |
| 208 |
| 209 // Hover below titlebar exposed panel. Verify nothing changed. |
| 210 hover_point.set_y(panels[index]->GetBounds().y() + |
| 211 panels[index]->GetBounds().height() + 6); |
| 212 MoveMouse(hover_point); |
| 213 EXPECT_EQ(titlebar_exposed_bounds, GetAllPanelBounds()); |
| 214 EXPECT_EQ(titlebar_exposed_states, GetAllPanelExpansionStates()); |
| 215 |
| 216 // Hover mouse above panel. Verify all panels are minimized. |
| 217 hover_point.set_y( |
| 218 panels[index]->GetBounds().y() - kFarEnoughFromHoverArea); |
| 219 MoveMouseAndWaitForExpansionStateChange(panels[index], hover_point); |
| 220 EXPECT_EQ(minimized_bounds, GetAllPanelBounds()); |
| 221 EXPECT_EQ(minimized_states, GetAllPanelExpansionStates()); |
| 222 } |
| 223 |
| 224 // Test restore. All panels are currently in minimized state. |
| 225 for (size_t index = 0; index < panels.size(); ++index) { |
| 226 // Hover on the last panel. This is to test the case of clicking on the |
| 227 // panel when it's in titlebar exposed state. |
| 228 if (index == panels.size() - 1) |
| 229 MoveMouse(minimized_bounds[index].origin()); |
| 230 |
| 231 // Click minimized or title bar exposed panel as the case may be. |
| 232 // Verify panel is restored to its original size. |
| 233 native_panels_testing[index]->PressLeftMouseButtonTitlebar( |
| 234 panels[index]->GetBounds().origin()); |
| 235 native_panels_testing[index]->ReleaseMouseButtonTitlebar(); |
| 236 expected_bounds[index].set_height( |
| 237 test_begin_bounds[index].height()); |
| 238 expected_bounds[index].set_y(test_begin_bounds[index].y()); |
| 239 expected_expansion_states[index] = Panel::EXPANDED; |
| 240 EXPECT_EQ(expected_bounds, GetAllPanelBounds()); |
| 241 EXPECT_EQ(expected_expansion_states, GetAllPanelExpansionStates()); |
| 242 |
| 243 // Hover again on the last panel which is now restored, to reset the |
| 244 // titlebar exposed state. |
| 245 if (index == panels.size() - 1) |
| 246 MoveMouse(minimized_bounds[index].origin()); |
| 247 } |
| 248 |
| 249 // The below could be separate tests, just adding a TODO here for tracking. |
| 250 // TODO(prasadt): Add test for dragging when in titlebar exposed state. |
| 251 // TODO(prasadt): Add test in presence of auto hiding task bar. |
| 252 |
| 253 for (size_t i = 0; i < panels.size(); ++i) |
| 254 delete native_panels_testing[i]; |
| 255 } |
| 256 }; |
| 257 |
| 258 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CheckDockedPanelProperties) { |
| 259 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 260 DockedPanelStrip* docked_strip = panel_manager->docked_strip(); |
| 261 |
| 262 // Create 3 docked panels that are in expanded, title-only or minimized states |
| 263 // respectively. |
| 264 Panel* panel1 = CreatePanelWithBounds("1", gfx::Rect(0, 0, 100, 100)); |
| 265 Panel* panel2 = CreatePanelWithBounds("2", gfx::Rect(0, 0, 100, 100)); |
| 266 panel2->SetExpansionState(Panel::TITLE_ONLY); |
| 267 WaitForExpansionStateChanged(panel2, Panel::TITLE_ONLY); |
| 268 Panel* panel3 = CreatePanelWithBounds("3", gfx::Rect(0, 0, 100, 100)); |
| 269 panel3->SetExpansionState(Panel::MINIMIZED); |
| 270 WaitForExpansionStateChanged(panel3, Panel::MINIMIZED); |
| 271 scoped_ptr<NativePanelTesting> panel1_testing( |
| 272 NativePanelTesting::Create(panel1->native_panel())); |
| 273 scoped_ptr<NativePanelTesting> panel2_testing( |
| 274 NativePanelTesting::Create(panel2->native_panel())); |
| 275 scoped_ptr<NativePanelTesting> panel3_testing( |
| 276 NativePanelTesting::Create(panel3->native_panel())); |
| 277 |
| 278 // Ensure that the layout message can get a chance to be processed so that |
| 279 // the button visibility can be updated. |
| 280 MessageLoop::current()->RunAllPending(); |
| 281 |
| 282 EXPECT_EQ(3, panel_manager->num_panels()); |
| 283 EXPECT_TRUE(docked_strip->HasPanel(panel1)); |
| 284 EXPECT_TRUE(docked_strip->HasPanel(panel2)); |
| 285 EXPECT_TRUE(docked_strip->HasPanel(panel3)); |
| 286 |
| 287 EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state()); |
| 288 EXPECT_EQ(Panel::TITLE_ONLY, panel2->expansion_state()); |
| 289 EXPECT_EQ(Panel::MINIMIZED, panel3->expansion_state()); |
| 290 |
| 291 EXPECT_TRUE(panel1->always_on_top()); |
| 292 EXPECT_TRUE(panel2->always_on_top()); |
| 293 EXPECT_TRUE(panel3->always_on_top()); |
| 294 |
| 295 EXPECT_TRUE(panel1_testing->IsButtonVisible(panel::CLOSE_BUTTON)); |
| 296 EXPECT_TRUE(panel2_testing->IsButtonVisible(panel::CLOSE_BUTTON)); |
| 297 EXPECT_TRUE(panel3_testing->IsButtonVisible(panel::CLOSE_BUTTON)); |
| 298 |
| 299 EXPECT_TRUE(panel1_testing->IsButtonVisible(panel::MINIMIZE_BUTTON)); |
| 300 EXPECT_FALSE(panel2_testing->IsButtonVisible(panel::MINIMIZE_BUTTON)); |
| 301 EXPECT_FALSE(panel3_testing->IsButtonVisible(panel::MINIMIZE_BUTTON)); |
| 302 |
| 303 EXPECT_FALSE(panel1_testing->IsButtonVisible(panel::RESTORE_BUTTON)); |
| 304 EXPECT_TRUE(panel2_testing->IsButtonVisible(panel::RESTORE_BUTTON)); |
| 305 EXPECT_TRUE(panel3_testing->IsButtonVisible(panel::RESTORE_BUTTON)); |
| 306 |
| 307 EXPECT_EQ(panel::RESIZABLE_ALL_SIDES_EXCEPT_BOTTOM, |
| 308 panel1->CanResizeByMouse()); |
| 309 EXPECT_EQ(panel::NOT_RESIZABLE, panel2->CanResizeByMouse()); |
| 310 EXPECT_EQ(panel::NOT_RESIZABLE, panel3->CanResizeByMouse()); |
| 311 |
| 312 EXPECT_EQ(Panel::USE_PANEL_ATTENTION, panel1->attention_mode()); |
| 313 EXPECT_EQ(Panel::USE_PANEL_ATTENTION, panel2->attention_mode()); |
| 314 EXPECT_EQ(Panel::USE_PANEL_ATTENTION, panel3->attention_mode()); |
| 315 |
| 316 panel_manager->CloseAll(); |
| 317 } |
| 318 |
| 319 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreatePanel) { |
| 320 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 321 EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially. |
| 322 |
| 323 Panel* panel = CreatePanel("PanelTest"); |
| 324 EXPECT_EQ(1, panel_manager->num_panels()); |
| 325 |
| 326 gfx::Rect bounds = panel->GetBounds(); |
| 327 EXPECT_GT(bounds.x(), 0); |
| 328 EXPECT_GT(bounds.y(), 0); |
| 329 EXPECT_GT(bounds.width(), 0); |
| 330 EXPECT_GT(bounds.height(), 0); |
| 331 |
| 332 EXPECT_EQ(bounds.right(), |
| 333 panel_manager->docked_strip()->StartingRightPosition()); |
| 334 |
| 335 CloseWindowAndWait(panel); |
| 336 |
| 337 EXPECT_EQ(0, panel_manager->num_panels()); |
| 338 } |
| 339 |
| 340 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreateBigPanel) { |
| 341 gfx::Rect work_area = PanelManager::GetInstance()-> |
| 342 display_settings_provider()->GetDisplayArea(); |
| 343 Panel* panel = CreatePanelWithBounds("BigPanel", work_area); |
| 344 gfx::Rect bounds = panel->GetBounds(); |
| 345 EXPECT_EQ(panel->max_size().width(), bounds.width()); |
| 346 EXPECT_LT(bounds.width(), work_area.width()); |
| 347 EXPECT_EQ(panel->max_size().height(), bounds.height()); |
| 348 EXPECT_LT(bounds.height(), work_area.height()); |
| 349 panel->Close(); |
| 350 } |
| 351 |
| 352 // Flaky: http://crbug.com/105445 |
| 353 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DISABLED_AutoResize) { |
| 354 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 355 panel_manager->enable_auto_sizing(true); |
| 356 // Bigger space is needed by this test. |
| 357 SetTestingAreas(gfx::Rect(0, 0, 1200, 900), gfx::Rect()); |
| 358 |
| 359 // Create a test panel with tab contents loaded. |
| 360 CreatePanelParams params("PanelTest1", gfx::Rect(), SHOW_AS_ACTIVE); |
| 361 GURL url(ui_test_utils::GetTestUrl( |
| 362 FilePath(kTestDir), |
| 363 FilePath(FILE_PATH_LITERAL("update-preferred-size.html")))); |
| 364 params.url = url; |
| 365 Panel* panel = CreatePanelWithParams(params); |
| 366 |
| 367 // Expand the test page. |
| 368 gfx::Rect initial_bounds = panel->GetBounds(); |
| 369 ui_test_utils::WindowedNotificationObserver enlarge( |
| 370 chrome::NOTIFICATION_PANEL_BOUNDS_ANIMATIONS_FINISHED, |
| 371 content::Source<Panel>(panel)); |
| 372 EXPECT_TRUE(ui_test_utils::ExecuteJavaScript( |
| 373 panel->WebContents()->GetRenderViewHost(), |
| 374 std::wstring(), |
| 375 L"changeSize(50);")); |
| 376 enlarge.Wait(); |
| 377 gfx::Rect bounds_on_grow = panel->GetBounds(); |
| 378 EXPECT_GT(bounds_on_grow.width(), initial_bounds.width()); |
| 379 EXPECT_EQ(bounds_on_grow.height(), initial_bounds.height()); |
| 380 |
| 381 // Shrink the test page. |
| 382 ui_test_utils::WindowedNotificationObserver shrink( |
| 383 chrome::NOTIFICATION_PANEL_BOUNDS_ANIMATIONS_FINISHED, |
| 384 content::Source<Panel>(panel)); |
| 385 EXPECT_TRUE(ui_test_utils::ExecuteJavaScript( |
| 386 panel->WebContents()->GetRenderViewHost(), |
| 387 std::wstring(), |
| 388 L"changeSize(-30);")); |
| 389 shrink.Wait(); |
| 390 gfx::Rect bounds_on_shrink = panel->GetBounds(); |
| 391 EXPECT_LT(bounds_on_shrink.width(), bounds_on_grow.width()); |
| 392 EXPECT_GT(bounds_on_shrink.width(), initial_bounds.width()); |
| 393 EXPECT_EQ(bounds_on_shrink.height(), initial_bounds.height()); |
| 394 |
| 395 // Verify resizing turns off auto-resizing and that it works. |
| 396 gfx::Rect previous_bounds = panel->GetBounds(); |
| 397 // These should be identical because the panel is expanded. |
| 398 EXPECT_EQ(previous_bounds.size(), panel->GetRestoredBounds().size()); |
| 399 gfx::Size new_size(previous_bounds.size()); |
| 400 new_size.Enlarge(5, 5); |
| 401 gfx::Rect new_bounds(previous_bounds.origin(), new_size); |
| 402 panel->SetBounds(new_bounds); |
| 403 EXPECT_FALSE(panel->auto_resizable()); |
| 404 EXPECT_EQ(new_bounds.size(), panel->GetBounds().size()); |
| 405 EXPECT_EQ(new_bounds.size(), panel->GetRestoredBounds().size()); |
| 406 |
| 407 // Turn back on auto-resize and verify that it works. |
| 408 ui_test_utils::WindowedNotificationObserver auto_resize_enabled( |
| 409 chrome::NOTIFICATION_PANEL_BOUNDS_ANIMATIONS_FINISHED, |
| 410 content::Source<Panel>(panel)); |
| 411 panel->SetAutoResizable(true); |
| 412 auto_resize_enabled.Wait(); |
| 413 gfx::Rect bounds_auto_resize_enabled = panel->GetBounds(); |
| 414 EXPECT_EQ(bounds_on_shrink.width(), bounds_auto_resize_enabled.width()); |
| 415 EXPECT_EQ(bounds_on_shrink.height(), bounds_auto_resize_enabled.height()); |
| 416 |
| 417 panel->Close(); |
| 418 } |
| 419 |
| 420 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, ResizePanel) { |
| 421 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 422 panel_manager->enable_auto_sizing(true); |
| 423 |
| 424 Panel* panel = CreatePanel("TestPanel"); |
| 425 EXPECT_TRUE(panel->auto_resizable()); |
| 426 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state()); |
| 427 |
| 428 // Verify resizing turns off auto-resizing and that it works. |
| 429 gfx::Rect original_bounds = panel->GetBounds(); |
| 430 // These should be identical because the panel is expanded. |
| 431 EXPECT_EQ(original_bounds.size(), panel->GetRestoredBounds().size()); |
| 432 gfx::Size new_size(original_bounds.size()); |
| 433 new_size.Enlarge(5, 5); |
| 434 gfx::Rect new_bounds(original_bounds.origin(), new_size); |
| 435 panel->SetBounds(new_bounds); |
| 436 EXPECT_FALSE(panel->auto_resizable()); |
| 437 EXPECT_EQ(new_bounds.size(), panel->GetBounds().size()); |
| 438 EXPECT_EQ(new_bounds.size(), panel->GetRestoredBounds().size()); |
| 439 |
| 440 // Verify current height unaffected when panel is not expanded. |
| 441 panel->SetExpansionState(Panel::MINIMIZED); |
| 442 int original_height = panel->GetBounds().height(); |
| 443 new_size.Enlarge(5, 5); |
| 444 new_bounds.set_size(new_size); |
| 445 panel->SetBounds(new_bounds); |
| 446 EXPECT_EQ(new_bounds.size().width(), panel->GetBounds().width()); |
| 447 EXPECT_EQ(original_height, panel->GetBounds().height()); |
| 448 EXPECT_EQ(new_bounds.size(), panel->GetRestoredBounds().size()); |
| 449 |
| 450 panel->Close(); |
| 451 } |
| 452 |
| 453 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, AnimateBounds) { |
| 454 Panel* panel = CreatePanelWithBounds("PanelTest", gfx::Rect(0, 0, 100, 100)); |
| 455 scoped_ptr<NativePanelTesting> panel_testing( |
| 456 NativePanelTesting::Create(panel->native_panel())); |
| 457 |
| 458 // Set bounds with animation. |
| 459 gfx::Rect bounds = gfx::Rect(10, 20, 150, 160); |
| 460 panel->SetPanelBounds(bounds); |
| 461 EXPECT_TRUE(panel_testing->IsAnimatingBounds()); |
| 462 WaitForBoundsAnimationFinished(panel); |
| 463 EXPECT_FALSE(panel_testing->IsAnimatingBounds()); |
| 464 EXPECT_EQ(bounds, panel->GetBounds()); |
| 465 |
| 466 // Set bounds without animation. |
| 467 bounds = gfx::Rect(30, 40, 200, 220); |
| 468 panel->SetPanelBoundsInstantly(bounds); |
| 469 EXPECT_FALSE(panel_testing->IsAnimatingBounds()); |
| 470 EXPECT_EQ(bounds, panel->GetBounds()); |
| 471 |
| 472 panel->Close(); |
| 473 } |
| 474 |
| 475 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, RestoredBounds) { |
| 476 // Disable mouse watcher. We don't care about mouse movements in this test. |
| 477 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 478 PanelMouseWatcher* mouse_watcher = new TestPanelMouseWatcher(); |
| 479 panel_manager->SetMouseWatcherForTesting(mouse_watcher); |
| 480 Panel* panel = CreatePanelWithBounds("PanelTest", gfx::Rect(0, 0, 100, 100)); |
| 481 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state()); |
| 482 EXPECT_EQ(panel->GetBounds(), panel->GetRestoredBounds()); |
| 483 |
| 484 panel->SetExpansionState(Panel::MINIMIZED); |
| 485 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state()); |
| 486 gfx::Rect bounds = panel->GetBounds(); |
| 487 gfx::Rect restored = panel->GetRestoredBounds(); |
| 488 EXPECT_EQ(bounds.x(), restored.x()); |
| 489 EXPECT_GT(bounds.y(), restored.y()); |
| 490 EXPECT_EQ(bounds.width(), restored.width()); |
| 491 EXPECT_LT(bounds.height(), restored.height()); |
| 492 |
| 493 panel->SetExpansionState(Panel::TITLE_ONLY); |
| 494 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); |
| 495 bounds = panel->GetBounds(); |
| 496 restored = panel->GetRestoredBounds(); |
| 497 EXPECT_EQ(bounds.x(), restored.x()); |
| 498 EXPECT_GT(bounds.y(), restored.y()); |
| 499 EXPECT_EQ(bounds.width(), restored.width()); |
| 500 EXPECT_LT(bounds.height(), restored.height()); |
| 501 |
| 502 panel->SetExpansionState(Panel::MINIMIZED); |
| 503 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state()); |
| 504 bounds = panel->GetBounds(); |
| 505 restored = panel->GetRestoredBounds(); |
| 506 EXPECT_EQ(bounds.x(), restored.x()); |
| 507 EXPECT_GT(bounds.y(), restored.y()); |
| 508 EXPECT_EQ(bounds.width(), restored.width()); |
| 509 EXPECT_LT(bounds.height(), restored.height()); |
| 510 |
| 511 panel->SetExpansionState(Panel::EXPANDED); |
| 512 EXPECT_EQ(panel->GetBounds(), panel->GetRestoredBounds()); |
| 513 |
| 514 // Verify that changing the panel bounds does not affect the restored height. |
| 515 int saved_restored_height = restored.height(); |
| 516 panel->SetExpansionState(Panel::MINIMIZED); |
| 517 bounds = gfx::Rect(10, 20, 300, 400); |
| 518 panel->SetPanelBounds(bounds); |
| 519 EXPECT_EQ(saved_restored_height, panel->GetRestoredBounds().height()); |
| 520 |
| 521 panel->SetExpansionState(Panel::TITLE_ONLY); |
| 522 bounds = gfx::Rect(20, 30, 100, 200); |
| 523 panel->SetPanelBounds(bounds); |
| 524 EXPECT_EQ(saved_restored_height, panel->GetRestoredBounds().height()); |
| 525 |
| 526 panel->SetExpansionState(Panel::EXPANDED); |
| 527 bounds = gfx::Rect(40, 60, 300, 400); |
| 528 panel->SetPanelBounds(bounds); |
| 529 EXPECT_EQ(saved_restored_height, panel->GetRestoredBounds().height()); |
| 530 panel->set_full_size(bounds.size()); |
| 531 EXPECT_NE(saved_restored_height, panel->GetRestoredBounds().height()); |
| 532 |
| 533 panel->Close(); |
| 534 } |
| 535 |
| 536 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MinimizeRestore) { |
| 537 // We'll simulate mouse movements for test. |
| 538 PanelMouseWatcher* mouse_watcher = new TestPanelMouseWatcher(); |
| 539 PanelManager::GetInstance()->SetMouseWatcherForTesting(mouse_watcher); |
| 540 |
| 541 // Test with one panel. |
| 542 CreatePanelWithBounds("PanelTest1", gfx::Rect(0, 0, 100, 100)); |
| 543 TestMinimizeRestore(); |
| 544 |
| 545 PanelManager::GetInstance()->CloseAll(); |
| 546 } |
| 547 |
| 548 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MinimizeRestoreTwoPanels) { |
| 549 // We'll simulate mouse movements for test. |
| 550 PanelMouseWatcher* mouse_watcher = new TestPanelMouseWatcher(); |
| 551 PanelManager::GetInstance()->SetMouseWatcherForTesting(mouse_watcher); |
| 552 |
| 553 // Test with two panels. |
| 554 CreatePanelWithBounds("PanelTest1", gfx::Rect(0, 0, 100, 100)); |
| 555 CreatePanelWithBounds("PanelTest2", gfx::Rect(0, 0, 110, 110)); |
| 556 TestMinimizeRestore(); |
| 557 |
| 558 PanelManager::GetInstance()->CloseAll(); |
| 559 } |
| 560 |
| 561 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MinimizeRestoreThreePanels) { |
| 562 // We'll simulate mouse movements for test. |
| 563 PanelMouseWatcher* mouse_watcher = new TestPanelMouseWatcher(); |
| 564 PanelManager::GetInstance()->SetMouseWatcherForTesting(mouse_watcher); |
| 565 |
| 566 // Test with three panels. |
| 567 CreatePanelWithBounds("PanelTest1", gfx::Rect(0, 0, 100, 100)); |
| 568 CreatePanelWithBounds("PanelTest2", gfx::Rect(0, 0, 110, 110)); |
| 569 CreatePanelWithBounds("PanelTest3", gfx::Rect(0, 0, 120, 120)); |
| 570 TestMinimizeRestore(); |
| 571 |
| 572 PanelManager::GetInstance()->CloseAll(); |
| 573 } |
| 574 |
| 575 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MinimizeRestoreButtonClick) { |
| 576 // Test with three panels. |
| 577 Panel* panel1 = CreatePanel("PanelTest1"); |
| 578 Panel* panel2 = CreatePanel("PanelTest2"); |
| 579 Panel* panel3 = CreatePanel("PanelTest3"); |
| 580 EXPECT_FALSE(panel1->IsMinimized()); |
| 581 EXPECT_FALSE(panel2->IsMinimized()); |
| 582 EXPECT_FALSE(panel3->IsMinimized()); |
| 583 |
| 584 // Click restore button on an expanded panel. Expect no change. |
| 585 panel1->OnRestoreButtonClicked(panel::NO_MODIFIER); |
| 586 EXPECT_FALSE(panel1->IsMinimized()); |
| 587 EXPECT_FALSE(panel2->IsMinimized()); |
| 588 EXPECT_FALSE(panel3->IsMinimized()); |
| 589 |
| 590 // Click minimize button on an expanded panel. Only that panel will minimize. |
| 591 panel1->OnMinimizeButtonClicked(panel::NO_MODIFIER); |
| 592 EXPECT_TRUE(panel1->IsMinimized()); |
| 593 EXPECT_FALSE(panel2->IsMinimized()); |
| 594 EXPECT_FALSE(panel3->IsMinimized()); |
| 595 |
| 596 // Click minimize button on a minimized panel. Expect no change. |
| 597 panel1->OnMinimizeButtonClicked(panel::NO_MODIFIER); |
| 598 EXPECT_TRUE(panel1->IsMinimized()); |
| 599 EXPECT_FALSE(panel2->IsMinimized()); |
| 600 EXPECT_FALSE(panel3->IsMinimized()); |
| 601 |
| 602 // Minimize all panels by clicking minimize button on an expanded panel |
| 603 // with the apply-all modifier. |
| 604 panel2->OnMinimizeButtonClicked(panel::APPLY_TO_ALL); |
| 605 EXPECT_TRUE(panel1->IsMinimized()); |
| 606 EXPECT_TRUE(panel2->IsMinimized()); |
| 607 EXPECT_TRUE(panel3->IsMinimized()); |
| 608 |
| 609 // Click restore button on a minimized panel. Only that panel will restore. |
| 610 panel2->OnRestoreButtonClicked(panel::NO_MODIFIER); |
| 611 EXPECT_TRUE(panel1->IsMinimized()); |
| 612 EXPECT_FALSE(panel2->IsMinimized()); |
| 613 EXPECT_TRUE(panel3->IsMinimized()); |
| 614 |
| 615 // Restore all panels by clicking restore button on a minimized panel. |
| 616 panel3->OnRestoreButtonClicked(panel::APPLY_TO_ALL); |
| 617 EXPECT_FALSE(panel1->IsMinimized()); |
| 618 EXPECT_FALSE(panel2->IsMinimized()); |
| 619 EXPECT_FALSE(panel3->IsMinimized()); |
| 620 } |
| 621 |
| 622 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, RestoreAllWithTitlebarClick) { |
| 623 // We'll simulate mouse movements for test. |
| 624 PanelMouseWatcher* mouse_watcher = new TestPanelMouseWatcher(); |
| 625 PanelManager::GetInstance()->SetMouseWatcherForTesting(mouse_watcher); |
| 626 |
| 627 // Test with three panels. |
| 628 Panel* panel1 = CreatePanel("PanelTest1"); |
| 629 Panel* panel2 = CreatePanel("PanelTest2"); |
| 630 Panel* panel3 = CreatePanel("PanelTest3"); |
| 631 EXPECT_FALSE(panel1->IsMinimized()); |
| 632 EXPECT_FALSE(panel2->IsMinimized()); |
| 633 EXPECT_FALSE(panel3->IsMinimized()); |
| 634 |
| 635 scoped_ptr<NativePanelTesting> test_panel1( |
| 636 NativePanelTesting::Create(panel1->native_panel())); |
| 637 scoped_ptr<NativePanelTesting> test_panel2( |
| 638 NativePanelTesting::Create(panel2->native_panel())); |
| 639 scoped_ptr<NativePanelTesting> test_panel3( |
| 640 NativePanelTesting::Create(panel3->native_panel())); |
| 641 |
| 642 // Click on an expanded panel's titlebar using the apply-all modifier. |
| 643 // Verify expansion state is unchanged. |
| 644 test_panel2->PressLeftMouseButtonTitlebar(panel2->GetBounds().origin(), |
| 645 panel::APPLY_TO_ALL); |
| 646 test_panel2->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL); |
| 647 EXPECT_FALSE(panel1->IsMinimized()); |
| 648 EXPECT_FALSE(panel2->IsMinimized()); |
| 649 EXPECT_FALSE(panel3->IsMinimized()); |
| 650 |
| 651 // Click on a minimized panel's titlebar using the apply-all modifier. |
| 652 panel1->Minimize(); |
| 653 panel2->Minimize(); |
| 654 panel3->Minimize(); |
| 655 EXPECT_TRUE(panel1->IsMinimized()); |
| 656 EXPECT_TRUE(panel2->IsMinimized()); |
| 657 EXPECT_TRUE(panel3->IsMinimized()); |
| 658 |
| 659 // Nothing changes until mouse is released. |
| 660 test_panel1->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin(), |
| 661 panel::APPLY_TO_ALL); |
| 662 EXPECT_TRUE(panel1->IsMinimized()); |
| 663 EXPECT_TRUE(panel2->IsMinimized()); |
| 664 EXPECT_TRUE(panel3->IsMinimized()); |
| 665 // Verify all panels restored when mouse is released. |
| 666 test_panel1->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL); |
| 667 EXPECT_FALSE(panel1->IsMinimized()); |
| 668 EXPECT_FALSE(panel2->IsMinimized()); |
| 669 EXPECT_FALSE(panel3->IsMinimized()); |
| 670 |
| 671 // Minimize a single panel. Then click on expanded panel with apply-all |
| 672 // modifier. Verify nothing changes. |
| 673 panel1->Minimize(); |
| 674 EXPECT_TRUE(panel1->IsMinimized()); |
| 675 EXPECT_FALSE(panel2->IsMinimized()); |
| 676 EXPECT_FALSE(panel3->IsMinimized()); |
| 677 |
| 678 test_panel2->PressLeftMouseButtonTitlebar(panel2->GetBounds().origin(), |
| 679 panel::APPLY_TO_ALL); |
| 680 test_panel2->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL); |
| 681 EXPECT_TRUE(panel1->IsMinimized()); |
| 682 EXPECT_FALSE(panel2->IsMinimized()); |
| 683 EXPECT_FALSE(panel3->IsMinimized()); |
| 684 |
| 685 // Minimize another panel. Then click on a minimized panel with apply-all |
| 686 // modifier to restore all panels. |
| 687 panel2->Minimize(); |
| 688 EXPECT_TRUE(panel1->IsMinimized()); |
| 689 EXPECT_TRUE(panel2->IsMinimized()); |
| 690 EXPECT_FALSE(panel3->IsMinimized()); |
| 691 |
| 692 test_panel2->PressLeftMouseButtonTitlebar(panel2->GetBounds().origin(), |
| 693 panel::APPLY_TO_ALL); |
| 694 test_panel2->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL); |
| 695 EXPECT_FALSE(panel1->IsMinimized()); |
| 696 EXPECT_FALSE(panel2->IsMinimized()); |
| 697 EXPECT_FALSE(panel3->IsMinimized()); |
| 698 |
| 699 // Click on the single minimized panel. Verify all are restored. |
| 700 panel1->Minimize(); |
| 701 EXPECT_TRUE(panel1->IsMinimized()); |
| 702 EXPECT_FALSE(panel2->IsMinimized()); |
| 703 EXPECT_FALSE(panel3->IsMinimized()); |
| 704 |
| 705 test_panel1->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin(), |
| 706 panel::APPLY_TO_ALL); |
| 707 test_panel1->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL); |
| 708 EXPECT_FALSE(panel1->IsMinimized()); |
| 709 EXPECT_FALSE(panel2->IsMinimized()); |
| 710 EXPECT_FALSE(panel3->IsMinimized()); |
| 711 |
| 712 // Click on the single expanded panel. Verify nothing changes. |
| 713 panel1->Minimize(); |
| 714 panel3->Minimize(); |
| 715 EXPECT_TRUE(panel1->IsMinimized()); |
| 716 EXPECT_FALSE(panel2->IsMinimized()); |
| 717 EXPECT_TRUE(panel3->IsMinimized()); |
| 718 |
| 719 test_panel2->PressLeftMouseButtonTitlebar(panel2->GetBounds().origin(), |
| 720 panel::APPLY_TO_ALL); |
| 721 test_panel2->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL); |
| 722 EXPECT_TRUE(panel1->IsMinimized()); |
| 723 EXPECT_FALSE(panel2->IsMinimized()); |
| 724 EXPECT_TRUE(panel3->IsMinimized()); |
| 725 |
| 726 // Hover over a minimized panel and click on the titlebar while it is in |
| 727 // title-only mode. Should restore all panels. |
| 728 panel2->Minimize(); |
| 729 EXPECT_TRUE(panel1->IsMinimized()); |
| 730 EXPECT_TRUE(panel2->IsMinimized()); |
| 731 EXPECT_TRUE(panel3->IsMinimized()); |
| 732 |
| 733 MoveMouseAndWaitForExpansionStateChange(panel2, panel2->GetBounds().origin()); |
| 734 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); |
| 735 EXPECT_EQ(Panel::TITLE_ONLY, panel2->expansion_state()); |
| 736 EXPECT_EQ(Panel::TITLE_ONLY, panel3->expansion_state()); |
| 737 |
| 738 test_panel3->PressLeftMouseButtonTitlebar(panel3->GetBounds().origin(), |
| 739 panel::APPLY_TO_ALL); |
| 740 test_panel3->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL); |
| 741 EXPECT_FALSE(panel1->IsMinimized()); |
| 742 EXPECT_FALSE(panel2->IsMinimized()); |
| 743 EXPECT_FALSE(panel3->IsMinimized()); |
| 744 |
| 745 // Draw attention to a minimized panel. Click on a minimized panel that is |
| 746 // not drawing attention. Verify restore all applies without affecting |
| 747 // draw attention. |
| 748 panel1->Minimize(); |
| 749 panel2->Minimize(); |
| 750 panel3->Minimize(); |
| 751 EXPECT_TRUE(panel1->IsMinimized()); |
| 752 EXPECT_TRUE(panel2->IsMinimized()); |
| 753 EXPECT_TRUE(panel3->IsMinimized()); |
| 754 |
| 755 panel1->FlashFrame(true); |
| 756 EXPECT_TRUE(panel1->IsDrawingAttention()); |
| 757 |
| 758 test_panel2->PressLeftMouseButtonTitlebar(panel3->GetBounds().origin(), |
| 759 panel::APPLY_TO_ALL); |
| 760 test_panel2->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL); |
| 761 EXPECT_FALSE(panel1->IsMinimized()); |
| 762 EXPECT_FALSE(panel2->IsMinimized()); |
| 763 EXPECT_FALSE(panel3->IsMinimized()); |
| 764 EXPECT_TRUE(panel1->IsDrawingAttention()); |
| 765 |
| 766 // Restore all panels by clicking on the minimized panel that is drawing |
| 767 // attention. Verify restore all applies and clears draw attention. |
| 768 panel1->Minimize(); |
| 769 panel2->Minimize(); |
| 770 panel3->Minimize(); |
| 771 EXPECT_TRUE(panel1->IsMinimized()); |
| 772 EXPECT_TRUE(panel2->IsMinimized()); |
| 773 EXPECT_TRUE(panel3->IsMinimized()); |
| 774 |
| 775 test_panel1->PressLeftMouseButtonTitlebar(panel1->GetBounds().origin(), |
| 776 panel::APPLY_TO_ALL); |
| 777 test_panel1->ReleaseMouseButtonTitlebar(panel::APPLY_TO_ALL); |
| 778 EXPECT_FALSE(panel1->IsMinimized()); |
| 779 EXPECT_FALSE(panel2->IsMinimized()); |
| 780 EXPECT_FALSE(panel3->IsMinimized()); |
| 781 EXPECT_FALSE(panel1->IsDrawingAttention()); |
| 782 |
| 783 PanelManager::GetInstance()->CloseAll(); |
| 784 } |
| 785 |
| 786 #if defined(OS_MACOSX) |
| 787 // This test doesn't pass on Snow Leopard (10.6), although it works just |
| 788 // fine on Lion (10.7). The problem is not having a real run loop around |
| 789 // the window close is at fault, given how window controllers in Chrome |
| 790 // autorelease themselves on a -performSelector:withObject:afterDelay: |
| 791 #define MAYBE_ActivatePanelOrTabbedWindow DISABLED_ActivatePanelOrTabbedWindow |
| 792 #else |
| 793 #define MAYBE_ActivatePanelOrTabbedWindow ActivatePanelOrTabbedWindow |
| 794 #endif |
| 795 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_ActivatePanelOrTabbedWindow) { |
| 796 CreatePanelParams params1("Panel1", gfx::Rect(), SHOW_AS_ACTIVE); |
| 797 Panel* panel1 = CreatePanelWithParams(params1); |
| 798 CreatePanelParams params2("Panel2", gfx::Rect(), SHOW_AS_ACTIVE); |
| 799 Panel* panel2 = CreatePanelWithParams(params2); |
| 800 |
| 801 // Need tab contents in order to trigger deactivation upon close. |
| 802 CreateTestTabContents(panel2->browser()); |
| 803 |
| 804 ASSERT_FALSE(panel1->IsActive()); |
| 805 ASSERT_TRUE(panel2->IsActive()); |
| 806 // Activate main tabbed window. |
| 807 browser()->window()->Activate(); |
| 808 WaitForPanelActiveState(panel2, SHOW_AS_INACTIVE); |
| 809 |
| 810 // Activate a panel. |
| 811 panel2->Activate(); |
| 812 WaitForPanelActiveState(panel2, SHOW_AS_ACTIVE); |
| 813 |
| 814 // Activate the main tabbed window back. |
| 815 browser()->window()->Activate(); |
| 816 WaitForPanelActiveState(panel2, SHOW_AS_INACTIVE); |
| 817 // Close the main tabbed window. That should move focus back to panel. |
| 818 browser()->CloseWindow(); |
| 819 WaitForPanelActiveState(panel2, SHOW_AS_ACTIVE); |
| 820 |
| 821 // Activate another panel. |
| 822 panel1->Activate(); |
| 823 WaitForPanelActiveState(panel1, SHOW_AS_ACTIVE); |
| 824 WaitForPanelActiveState(panel2, SHOW_AS_INACTIVE); |
| 825 |
| 826 // Switch focus between panels. |
| 827 panel2->Activate(); |
| 828 WaitForPanelActiveState(panel2, SHOW_AS_ACTIVE); |
| 829 WaitForPanelActiveState(panel1, SHOW_AS_INACTIVE); |
| 830 |
| 831 // Close active panel, focus should move to the remaining one. |
| 832 CloseWindowAndWait(panel2); |
| 833 WaitForPanelActiveState(panel1, SHOW_AS_ACTIVE); |
| 834 panel1->Close(); |
| 835 } |
| 836 |
| 837 // TODO(jianli): To be enabled for other platforms. |
| 838 #if defined(OS_WIN) |
| 839 #define MAYBE_ActivateDeactivateBasic ActivateDeactivateBasic |
| 840 #else |
| 841 #define MAYBE_ActivateDeactivateBasic DISABLED_ActivateDeactivateBasic |
| 842 #endif |
| 843 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_ActivateDeactivateBasic) { |
| 844 // Create an active panel. |
| 845 Panel* panel = CreatePanel("PanelTest"); |
| 846 scoped_ptr<NativePanelTesting> native_panel_testing( |
| 847 NativePanelTesting::Create(panel->native_panel())); |
| 848 EXPECT_TRUE(panel->IsActive()); |
| 849 EXPECT_TRUE(native_panel_testing->VerifyActiveState(true)); |
| 850 |
| 851 // Deactivate the panel. |
| 852 panel->Deactivate(); |
| 853 WaitForPanelActiveState(panel, SHOW_AS_INACTIVE); |
| 854 EXPECT_FALSE(panel->IsActive()); |
| 855 EXPECT_TRUE(native_panel_testing->VerifyActiveState(false)); |
| 856 |
| 857 // Reactivate the panel. |
| 858 panel->Activate(); |
| 859 WaitForPanelActiveState(panel, SHOW_AS_ACTIVE); |
| 860 EXPECT_TRUE(panel->IsActive()); |
| 861 EXPECT_TRUE(native_panel_testing->VerifyActiveState(true)); |
| 862 } |
| 863 // TODO(jianli): To be enabled for other platforms. |
| 864 #if defined(OS_WIN) |
| 865 #define MAYBE_ActivateDeactivateMultiple ActivateDeactivateMultiple |
| 866 #else |
| 867 #define MAYBE_ActivateDeactivateMultiple DISABLED_ActivateDeactivateMultiple |
| 868 #endif |
| 869 |
| 870 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_ActivateDeactivateMultiple) { |
| 871 BrowserWindow* tabbed_window = browser()->window(); |
| 872 |
| 873 // Create 4 panels in the following screen layout: |
| 874 // P3 P2 P1 P0 |
| 875 const int kNumPanels = 4; |
| 876 for (int i = 0; i < kNumPanels; ++i) |
| 877 CreatePanelWithBounds(MakePanelName(i), gfx::Rect(0, 0, 100, 100)); |
| 878 const std::vector<Panel*>& panels = PanelManager::GetInstance()->panels(); |
| 879 |
| 880 std::vector<bool> expected_active_states; |
| 881 std::vector<bool> last_active_states; |
| 882 |
| 883 // The last created panel, P3, should be active. |
| 884 expected_active_states = ProduceExpectedActiveStates(3); |
| 885 EXPECT_EQ(expected_active_states, GetAllPanelActiveStates()); |
| 886 EXPECT_FALSE(tabbed_window->IsActive()); |
| 887 |
| 888 // Activating P1 should cause P3 to lose focus. |
| 889 panels[1]->Activate(); |
| 890 last_active_states = expected_active_states; |
| 891 expected_active_states = ProduceExpectedActiveStates(1); |
| 892 WaitForPanelActiveStates(last_active_states, expected_active_states); |
| 893 EXPECT_EQ(expected_active_states, GetAllPanelActiveStates()); |
| 894 |
| 895 // Minimizing inactive panel P2 should not affect other panels' active states. |
| 896 panels[2]->SetExpansionState(Panel::MINIMIZED); |
| 897 EXPECT_EQ(expected_active_states, GetAllPanelActiveStates()); |
| 898 EXPECT_FALSE(tabbed_window->IsActive()); |
| 899 |
| 900 // Minimizing active panel P1 should activate last active panel P3. |
| 901 panels[1]->SetExpansionState(Panel::MINIMIZED); |
| 902 last_active_states = expected_active_states; |
| 903 expected_active_states = ProduceExpectedActiveStates(3); |
| 904 WaitForPanelActiveStates(last_active_states, expected_active_states); |
| 905 EXPECT_EQ(expected_active_states, GetAllPanelActiveStates()); |
| 906 EXPECT_FALSE(tabbed_window->IsActive()); |
| 907 |
| 908 // Minimizing active panel P3 should activate last active panel P0. |
| 909 panels[3]->SetExpansionState(Panel::MINIMIZED); |
| 910 last_active_states = expected_active_states; |
| 911 expected_active_states = ProduceExpectedActiveStates(0); |
| 912 WaitForPanelActiveStates(last_active_states, expected_active_states); |
| 913 EXPECT_EQ(expected_active_states, GetAllPanelActiveStates()); |
| 914 EXPECT_FALSE(tabbed_window->IsActive()); |
| 915 |
| 916 // Minimizing active panel P0 should activate last active tabbed window. |
| 917 panels[0]->SetExpansionState(Panel::MINIMIZED); |
| 918 last_active_states = expected_active_states; |
| 919 expected_active_states = ProduceExpectedActiveStates(-1); // -1 means none. |
| 920 WaitForPanelActiveStates(last_active_states, expected_active_states); |
| 921 EXPECT_EQ(expected_active_states, GetAllPanelActiveStates()); |
| 922 EXPECT_TRUE(tabbed_window->IsActive()); |
| 923 } |
| 924 |
| 925 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionBasic) { |
| 926 CreatePanelParams params("Initially Inactive", gfx::Rect(), SHOW_AS_INACTIVE); |
| 927 Panel* panel = CreatePanelWithParams(params); |
| 928 scoped_ptr<NativePanelTesting> native_panel_testing( |
| 929 NativePanelTesting::Create(panel->native_panel())); |
| 930 |
| 931 // Test that the attention is drawn when the expanded panel is not in focus. |
| 932 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state()); |
| 933 EXPECT_FALSE(panel->IsActive()); |
| 934 EXPECT_FALSE(panel->IsDrawingAttention()); |
| 935 panel->FlashFrame(true); |
| 936 EXPECT_TRUE(panel->IsDrawingAttention()); |
| 937 MessageLoop::current()->RunAllPending(); |
| 938 EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention()); |
| 939 |
| 940 // Stop drawing attention. |
| 941 panel->FlashFrame(false); |
| 942 EXPECT_FALSE(panel->IsDrawingAttention()); |
| 943 MessageLoop::current()->RunAllPending(); |
| 944 EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention()); |
| 945 |
| 946 // Draw attention, then minimize. Titlebar should remain visible. |
| 947 panel->FlashFrame(true); |
| 948 EXPECT_TRUE(panel->IsDrawingAttention()); |
| 949 |
| 950 panel->Minimize(); |
| 951 EXPECT_TRUE(panel->IsDrawingAttention()); |
| 952 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); |
| 953 |
| 954 // Stop drawing attention. Titlebar should no longer be visible. |
| 955 panel->FlashFrame(false); |
| 956 EXPECT_FALSE(panel->IsDrawingAttention()); |
| 957 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state()); |
| 958 |
| 959 panel->Close(); |
| 960 } |
| 961 |
| 962 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionWhileMinimized) { |
| 963 // We'll simulate mouse movements for test. |
| 964 PanelMouseWatcher* mouse_watcher = new TestPanelMouseWatcher(); |
| 965 PanelManager::GetInstance()->SetMouseWatcherForTesting(mouse_watcher); |
| 966 |
| 967 // Create 2 panels so we end up with an inactive panel that can |
| 968 // be made to draw attention. |
| 969 Panel* panel = CreatePanel("test panel1"); |
| 970 Panel* panel2 = CreatePanel("test panel2"); |
| 971 Panel* panel3 = CreatePanel("test panel2"); |
| 972 |
| 973 scoped_ptr<NativePanelTesting> native_panel_testing( |
| 974 NativePanelTesting::Create(panel->native_panel())); |
| 975 |
| 976 // Test that the attention is drawn and the title-bar is brought up when the |
| 977 // minimized panel is drawing attention. |
| 978 panel->Minimize(); |
| 979 WaitForExpansionStateChanged(panel, Panel::MINIMIZED); |
| 980 panel->FlashFrame(true); |
| 981 EXPECT_TRUE(panel->IsDrawingAttention()); |
| 982 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); |
| 983 MessageLoop::current()->RunAllPending(); |
| 984 EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention()); |
| 985 |
| 986 // Test that we cannot bring up other minimized panel if the mouse is over |
| 987 // the panel that draws attension. |
| 988 panel2->Minimize(); |
| 989 gfx::Point hover_point(panel->GetBounds().origin()); |
| 990 MoveMouse(hover_point); |
| 991 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); |
| 992 EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state()); |
| 993 |
| 994 // Test that we cannot bring down the panel that is drawing the attention. |
| 995 hover_point.set_y(hover_point.y() - 200); |
| 996 MoveMouse(hover_point); |
| 997 EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); |
| 998 |
| 999 // Test that the attention is cleared when activated. |
| 1000 panel->Activate(); |
| 1001 MessageLoop::current()->RunAllPending(); |
| 1002 WaitForPanelActiveState(panel, SHOW_AS_ACTIVE); |
| 1003 EXPECT_FALSE(panel->IsDrawingAttention()); |
| 1004 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state()); |
| 1005 EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention()); |
| 1006 |
| 1007 panel->Close(); |
| 1008 panel2->Close(); |
| 1009 panel3->Close(); |
| 1010 } |
| 1011 |
| 1012 // Verify that minimized state of a panel is correct after draw attention |
| 1013 // is stopped when there are other minimized panels. |
| 1014 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, StopDrawingAttentionWhileMinimized) { |
| 1015 // We'll simulate mouse movements for test. |
| 1016 PanelMouseWatcher* mouse_watcher = new TestPanelMouseWatcher(); |
| 1017 PanelManager::GetInstance()->SetMouseWatcherForTesting(mouse_watcher); |
| 1018 |
| 1019 Panel* panel1 = CreatePanel("panel1"); |
| 1020 Panel* panel2 = CreatePanel("panel2"); |
| 1021 |
| 1022 panel1->Minimize(); |
| 1023 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); |
| 1024 panel2->Minimize(); |
| 1025 EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state()); |
| 1026 |
| 1027 // Verify panel returns to minimized state when no longer drawing attention. |
| 1028 panel1->FlashFrame(true); |
| 1029 EXPECT_TRUE(panel1->IsDrawingAttention()); |
| 1030 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); |
| 1031 |
| 1032 panel1->FlashFrame(false); |
| 1033 EXPECT_FALSE(panel1->IsDrawingAttention()); |
| 1034 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); |
| 1035 |
| 1036 // Hover over other minimized panel to bring up titlebars. |
| 1037 gfx::Point hover_point(panel2->GetBounds().origin()); |
| 1038 MoveMouseAndWaitForExpansionStateChange(panel1, hover_point); |
| 1039 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); |
| 1040 EXPECT_EQ(Panel::TITLE_ONLY, panel2->expansion_state()); |
| 1041 |
| 1042 // Verify panel keeps titlebar visible when no longer drawing attention |
| 1043 // if titlebars are up. |
| 1044 panel1->FlashFrame(true); |
| 1045 EXPECT_TRUE(panel1->IsDrawingAttention()); |
| 1046 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); |
| 1047 |
| 1048 panel1->FlashFrame(false); |
| 1049 EXPECT_FALSE(panel1->IsDrawingAttention()); |
| 1050 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); |
| 1051 |
| 1052 // Move mouse away. All panels should return to minimized state. |
| 1053 hover_point.set_y(hover_point.y() - 200); |
| 1054 MoveMouseAndWaitForExpansionStateChange(panel1, hover_point); |
| 1055 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); |
| 1056 EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state()); |
| 1057 |
| 1058 // Verify minimized panel that is drawing attention stays in title-only mode |
| 1059 // after attention is cleared if mouse is in the titlebar area. |
| 1060 panel1->FlashFrame(true); |
| 1061 EXPECT_TRUE(panel1->IsDrawingAttention()); |
| 1062 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); |
| 1063 |
| 1064 gfx::Point hover_point_in_panel(panel1->GetBounds().origin()); |
| 1065 MoveMouse(hover_point_in_panel); |
| 1066 |
| 1067 panel1->FlashFrame(false); |
| 1068 EXPECT_FALSE(panel1->IsDrawingAttention()); |
| 1069 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); |
| 1070 EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state()); |
| 1071 |
| 1072 // Move mouse away and panel should go back to fully minimized state. |
| 1073 MoveMouseAndWaitForExpansionStateChange(panel1, hover_point); |
| 1074 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); |
| 1075 EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state()); |
| 1076 |
| 1077 panel1->Close(); |
| 1078 panel2->Close(); |
| 1079 } |
| 1080 |
| 1081 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionWhenActive) { |
| 1082 CreatePanelParams params("Initially Active", gfx::Rect(), SHOW_AS_ACTIVE); |
| 1083 Panel* panel = CreatePanelWithParams(params); |
| 1084 scoped_ptr<NativePanelTesting> native_panel_testing( |
| 1085 NativePanelTesting::Create(panel->native_panel())); |
| 1086 |
| 1087 // Test that the attention should not be drawn if the expanded panel is in |
| 1088 // focus. |
| 1089 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state()); |
| 1090 EXPECT_TRUE(panel->IsActive()); |
| 1091 EXPECT_FALSE(panel->IsDrawingAttention()); |
| 1092 panel->FlashFrame(true); |
| 1093 EXPECT_FALSE(panel->IsDrawingAttention()); |
| 1094 MessageLoop::current()->RunAllPending(); |
| 1095 EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention()); |
| 1096 |
| 1097 panel->Close(); |
| 1098 } |
| 1099 |
| 1100 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionResetOnActivate) { |
| 1101 // Create 2 panels so we end up with an inactive panel that can |
| 1102 // be made to draw attention. |
| 1103 Panel* panel = CreatePanel("test panel1"); |
| 1104 Panel* panel2 = CreatePanel("test panel2"); |
| 1105 |
| 1106 scoped_ptr<NativePanelTesting> native_panel_testing( |
| 1107 NativePanelTesting::Create(panel->native_panel())); |
| 1108 |
| 1109 panel->FlashFrame(true); |
| 1110 EXPECT_TRUE(panel->IsDrawingAttention()); |
| 1111 MessageLoop::current()->RunAllPending(); |
| 1112 EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention()); |
| 1113 |
| 1114 // Test that the attention is cleared when panel gets focus. |
| 1115 panel->Activate(); |
| 1116 MessageLoop::current()->RunAllPending(); |
| 1117 WaitForPanelActiveState(panel, SHOW_AS_ACTIVE); |
| 1118 EXPECT_FALSE(panel->IsDrawingAttention()); |
| 1119 EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention()); |
| 1120 |
| 1121 panel->Close(); |
| 1122 panel2->Close(); |
| 1123 } |
| 1124 |
| 1125 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, |
| 1126 DrawAttentionMinimizedNotResetOnActivate) { |
| 1127 // Create 2 panels so we end up with an inactive panel that can |
| 1128 // be made to draw attention. |
| 1129 Panel* panel1 = CreatePanel("test panel1"); |
| 1130 Panel* panel2 = CreatePanel("test panel2"); |
| 1131 |
| 1132 panel1->Minimize(); |
| 1133 EXPECT_TRUE(panel1->IsMinimized()); |
| 1134 panel1->FlashFrame(true); |
| 1135 EXPECT_TRUE(panel1->IsDrawingAttention()); |
| 1136 |
| 1137 // Simulate panel being activated while minimized. Cannot call |
| 1138 // Activate() as that expands the panel. |
| 1139 panel1->OnActiveStateChanged(true); |
| 1140 EXPECT_TRUE(panel1->IsDrawingAttention()); // Unchanged. |
| 1141 |
| 1142 // Unminimize panel to show that attention would have been cleared |
| 1143 // if panel had not been minimized. |
| 1144 panel1->Restore(); |
| 1145 EXPECT_FALSE(panel1->IsMinimized()); |
| 1146 EXPECT_TRUE(panel1->IsDrawingAttention()); // Unchanged. |
| 1147 |
| 1148 panel1->OnActiveStateChanged(true); |
| 1149 EXPECT_FALSE(panel1->IsDrawingAttention()); // Attention cleared. |
| 1150 |
| 1151 panel1->Close(); |
| 1152 panel2->Close(); |
| 1153 } |
| 1154 |
| 1155 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DrawAttentionResetOnClick) { |
| 1156 CreatePanelParams params("Initially Inactive", gfx::Rect(), SHOW_AS_INACTIVE); |
| 1157 Panel* panel = CreatePanelWithParams(params); |
| 1158 scoped_ptr<NativePanelTesting> native_panel_testing( |
| 1159 NativePanelTesting::Create(panel->native_panel())); |
| 1160 |
| 1161 panel->FlashFrame(true); |
| 1162 EXPECT_TRUE(panel->IsDrawingAttention()); |
| 1163 MessageLoop::current()->RunAllPending(); |
| 1164 EXPECT_TRUE(native_panel_testing->VerifyDrawingAttention()); |
| 1165 |
| 1166 // Test that the attention is cleared when panel gets focus. |
| 1167 native_panel_testing->PressLeftMouseButtonTitlebar( |
| 1168 panel->GetBounds().origin()); |
| 1169 native_panel_testing->ReleaseMouseButtonTitlebar(); |
| 1170 |
| 1171 MessageLoop::current()->RunAllPending(); |
| 1172 WaitForPanelActiveState(panel, SHOW_AS_ACTIVE); |
| 1173 EXPECT_FALSE(panel->IsDrawingAttention()); |
| 1174 EXPECT_FALSE(native_panel_testing->VerifyDrawingAttention()); |
| 1175 |
| 1176 panel->Close(); |
| 1177 } |
| 1178 |
| 1179 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, |
| 1180 MinimizeImmediatelyAfterRestore) { |
| 1181 CreatePanelParams params("Panel Test", gfx::Rect(), SHOW_AS_ACTIVE); |
| 1182 Panel* panel = CreatePanelWithParams(params); |
| 1183 scoped_ptr<NativePanelTesting> native_panel_testing( |
| 1184 NativePanelTesting::Create(panel->native_panel())); |
| 1185 |
| 1186 panel->Minimize(); // this should deactivate. |
| 1187 MessageLoop::current()->RunAllPending(); |
| 1188 WaitForPanelActiveState(panel, SHOW_AS_INACTIVE); |
| 1189 EXPECT_EQ(Panel::MINIMIZED, panel->expansion_state()); |
| 1190 |
| 1191 panel->Restore(); |
| 1192 MessageLoop::current()->RunAllPending(); |
| 1193 WaitForExpansionStateChanged(panel, Panel::EXPANDED); |
| 1194 |
| 1195 // Verify that minimizing a panel right after expansion works. |
| 1196 panel->Minimize(); |
| 1197 MessageLoop::current()->RunAllPending(); |
| 1198 WaitForExpansionStateChanged(panel, Panel::MINIMIZED); |
| 1199 |
| 1200 panel->Close(); |
| 1201 } |
| 1202 |
| 1203 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, FocusLostOnMinimize) { |
| 1204 CreatePanelParams params("Initially Active", gfx::Rect(), SHOW_AS_ACTIVE); |
| 1205 Panel* panel = CreatePanelWithParams(params); |
| 1206 EXPECT_EQ(Panel::EXPANDED, panel->expansion_state()); |
| 1207 |
| 1208 panel->SetExpansionState(Panel::MINIMIZED); |
| 1209 MessageLoop::current()->RunAllPending(); |
| 1210 WaitForPanelActiveState(panel, SHOW_AS_INACTIVE); |
| 1211 panel->Close(); |
| 1212 } |
| 1213 |
| 1214 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreateInactiveSwitchToActive) { |
| 1215 // Compiz will not activate initially inactive window. |
| 1216 if (SkipTestIfCompizWM()) |
| 1217 return; |
| 1218 |
| 1219 CreatePanelParams params("Initially Inactive", gfx::Rect(), SHOW_AS_INACTIVE); |
| 1220 Panel* panel = CreatePanelWithParams(params); |
| 1221 |
| 1222 panel->Activate(); |
| 1223 WaitForPanelActiveState(panel, SHOW_AS_ACTIVE); |
| 1224 |
| 1225 panel->Close(); |
| 1226 } |
| 1227 |
| 1228 // TODO(dimich): try/enable on other platforms. See bug 103253 for details on |
| 1229 // why this is disabled on windows. |
| 1230 #if defined(OS_MACOSX) |
| 1231 #define MAYBE_MinimizeTwoPanelsWithoutTabbedWindow \ |
| 1232 MinimizeTwoPanelsWithoutTabbedWindow |
| 1233 #else |
| 1234 #define MAYBE_MinimizeTwoPanelsWithoutTabbedWindow \ |
| 1235 DISABLED_MinimizeTwoPanelsWithoutTabbedWindow |
| 1236 #endif |
| 1237 |
| 1238 // When there are 2 panels and no chrome window, minimizing one panel does |
| 1239 // not expand/focuses another. |
| 1240 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, |
| 1241 MAYBE_MinimizeTwoPanelsWithoutTabbedWindow) { |
| 1242 CreatePanelParams params("Initially Inactive", gfx::Rect(), SHOW_AS_INACTIVE); |
| 1243 Panel* panel1 = CreatePanelWithParams(params); |
| 1244 Panel* panel2 = CreatePanelWithParams(params); |
| 1245 |
| 1246 // Close main tabbed window. |
| 1247 ui_test_utils::WindowedNotificationObserver signal( |
| 1248 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 1249 content::Source<Browser>(browser())); |
| 1250 browser()->CloseWindow(); |
| 1251 signal.Wait(); |
| 1252 |
| 1253 EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state()); |
| 1254 EXPECT_EQ(Panel::EXPANDED, panel2->expansion_state()); |
| 1255 panel1->Activate(); |
| 1256 WaitForPanelActiveState(panel1, SHOW_AS_ACTIVE); |
| 1257 |
| 1258 panel1->SetExpansionState(Panel::MINIMIZED); |
| 1259 MessageLoop::current()->RunAllPending(); |
| 1260 WaitForPanelActiveState(panel1, SHOW_AS_INACTIVE); |
| 1261 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); |
| 1262 |
| 1263 panel2->SetExpansionState(Panel::MINIMIZED); |
| 1264 MessageLoop::current()->RunAllPending(); |
| 1265 WaitForPanelActiveState(panel2, SHOW_AS_INACTIVE); |
| 1266 EXPECT_EQ(Panel::MINIMIZED, panel2->expansion_state()); |
| 1267 |
| 1268 // Verify that panel1 is still minimized and not active. |
| 1269 WaitForPanelActiveState(panel1, SHOW_AS_INACTIVE); |
| 1270 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); |
| 1271 |
| 1272 // Another check for the same. |
| 1273 EXPECT_FALSE(panel1->IsActive()); |
| 1274 EXPECT_FALSE(panel2->IsActive()); |
| 1275 |
| 1276 panel1->Close(); |
| 1277 panel2->Close(); |
| 1278 } |
| 1279 |
| 1280 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, |
| 1281 NonExtensionDomainPanelsCloseOnUninstall) { |
| 1282 // Create a test extension. |
| 1283 DictionaryValue empty_value; |
| 1284 scoped_refptr<Extension> extension = |
| 1285 CreateExtension(FILE_PATH_LITERAL("TestExtension"), |
| 1286 Extension::INVALID, empty_value); |
| 1287 std::string extension_app_name = |
| 1288 web_app::GenerateApplicationNameFromExtensionId(extension->id()); |
| 1289 |
| 1290 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 1291 EXPECT_EQ(0, panel_manager->num_panels()); |
| 1292 |
| 1293 // Create a panel with the extension as host. |
| 1294 CreatePanelParams params(extension_app_name, gfx::Rect(), SHOW_AS_INACTIVE); |
| 1295 std::string extension_domain_url(chrome::kExtensionScheme); |
| 1296 extension_domain_url += "://"; |
| 1297 extension_domain_url += extension->id(); |
| 1298 extension_domain_url += "/hello.html"; |
| 1299 params.url = GURL(extension_domain_url); |
| 1300 Panel* panel = CreatePanelWithParams(params); |
| 1301 EXPECT_EQ(1, panel_manager->num_panels()); |
| 1302 |
| 1303 // Create a panel with a non-extension host. |
| 1304 CreatePanelParams params1(extension_app_name, gfx::Rect(), SHOW_AS_INACTIVE); |
| 1305 params1.url = GURL(chrome::kAboutBlankURL); |
| 1306 Panel* panel1 = CreatePanelWithParams(params1); |
| 1307 EXPECT_EQ(2, panel_manager->num_panels()); |
| 1308 |
| 1309 // Create another extension and a panel from that extension. |
| 1310 scoped_refptr<Extension> extension_other = |
| 1311 CreateExtension(FILE_PATH_LITERAL("TestExtensionOther"), |
| 1312 Extension::INVALID, empty_value); |
| 1313 std::string extension_app_name_other = |
| 1314 web_app::GenerateApplicationNameFromExtensionId(extension_other->id()); |
| 1315 Panel* panel_other = CreatePanel(extension_app_name_other); |
| 1316 |
| 1317 ui_test_utils::WindowedNotificationObserver signal( |
| 1318 chrome::NOTIFICATION_PANEL_CLOSED, |
| 1319 content::Source<Panel>(panel)); |
| 1320 ui_test_utils::WindowedNotificationObserver signal1( |
| 1321 chrome::NOTIFICATION_PANEL_CLOSED, |
| 1322 content::Source<Panel>(panel1)); |
| 1323 |
| 1324 // Send unload notification on the first extension. |
| 1325 extensions::UnloadedExtensionInfo details(extension, |
| 1326 extension_misc::UNLOAD_REASON_UNINSTALL); |
| 1327 content::NotificationService::current()->Notify( |
| 1328 chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 1329 content::Source<Profile>(browser()->profile()), |
| 1330 content::Details<extensions::UnloadedExtensionInfo>(&details)); |
| 1331 |
| 1332 // Wait for the panels opened by the first extension to close. |
| 1333 signal.Wait(); |
| 1334 signal1.Wait(); |
| 1335 |
| 1336 // Verify that the panel that's left is the panel from the second extension. |
| 1337 EXPECT_EQ(panel_other, panel_manager->panels()[0]); |
| 1338 panel_other->Close(); |
| 1339 } |
| 1340 |
| 1341 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, OnBeforeUnloadOnClose) { |
| 1342 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 1343 EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially. |
| 1344 |
| 1345 const string16 title_first_close = UTF8ToUTF16("TitleFirstClose"); |
| 1346 const string16 title_second_close = UTF8ToUTF16("TitleSecondClose"); |
| 1347 |
| 1348 // Create a test panel with tab contents loaded. |
| 1349 CreatePanelParams params("PanelTest1", gfx::Rect(0, 0, 300, 300), |
| 1350 SHOW_AS_ACTIVE); |
| 1351 params.url = ui_test_utils::GetTestUrl( |
| 1352 FilePath(kTestDir), |
| 1353 FilePath(FILE_PATH_LITERAL("onbeforeunload.html"))); |
| 1354 Panel* panel = CreatePanelWithParams(params); |
| 1355 EXPECT_EQ(1, panel_manager->num_panels()); |
| 1356 WebContents* web_contents = panel->WebContents(); |
| 1357 |
| 1358 // Close panel and respond to the onbeforeunload dialog with cancel. This is |
| 1359 // equivalent to clicking "Stay on this page" |
| 1360 scoped_ptr<ui_test_utils::TitleWatcher> title_watcher( |
| 1361 new ui_test_utils::TitleWatcher(web_contents, title_first_close)); |
| 1362 panel->Close(); |
| 1363 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); |
| 1364 alert->native_dialog()->CancelAppModalDialog(); |
| 1365 EXPECT_EQ(title_first_close, title_watcher->WaitAndGetTitle()); |
| 1366 EXPECT_EQ(1, panel_manager->num_panels()); |
| 1367 |
| 1368 // Close panel and respond to the onbeforeunload dialog with close. This is |
| 1369 // equivalent to clicking the OS close button on the dialog. |
| 1370 title_watcher.reset( |
| 1371 new ui_test_utils::TitleWatcher(web_contents, title_second_close)); |
| 1372 panel->Close(); |
| 1373 alert = ui_test_utils::WaitForAppModalDialog(); |
| 1374 alert->native_dialog()->CloseAppModalDialog(); |
| 1375 EXPECT_EQ(title_second_close, title_watcher->WaitAndGetTitle()); |
| 1376 EXPECT_EQ(1, panel_manager->num_panels()); |
| 1377 |
| 1378 // Close panel and respond to the onbeforeunload dialog with accept. This is |
| 1379 // equivalent to clicking "Leave this page". |
| 1380 ui_test_utils::WindowedNotificationObserver signal( |
| 1381 chrome::NOTIFICATION_PANEL_CLOSED, |
| 1382 content::Source<Panel>(panel)); |
| 1383 panel->Close(); |
| 1384 alert = ui_test_utils::WaitForAppModalDialog(); |
| 1385 alert->native_dialog()->AcceptAppModalDialog(); |
| 1386 signal.Wait(); |
| 1387 EXPECT_EQ(0, panel_manager->num_panels()); |
| 1388 } |
| 1389 |
| 1390 // http://crbug.com/126381 - should find a better notification to wait |
| 1391 // for resize completion. Bounds animation could happen for all sorts of |
| 1392 // reasons. |
| 1393 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DISABLED_CreateWithExistingContents) { |
| 1394 PanelManager::GetInstance()->enable_auto_sizing(true); |
| 1395 |
| 1396 // Load contents into regular tabbed browser. |
| 1397 GURL url(ui_test_utils::GetTestUrl( |
| 1398 FilePath(kTestDir), |
| 1399 FilePath(FILE_PATH_LITERAL("update-preferred-size.html")))); |
| 1400 ui_test_utils::NavigateToURL(browser(), url); |
| 1401 EXPECT_EQ(1, browser()->tab_count()); |
| 1402 |
| 1403 Profile* profile = browser()->profile(); |
| 1404 CreatePanelParams params("PanelTest1", gfx::Rect(), SHOW_AS_ACTIVE); |
| 1405 Panel* panel = CreatePanelWithParams(params); |
| 1406 Browser* panel_browser = panel->browser(); |
| 1407 EXPECT_EQ(2U, BrowserList::size()); |
| 1408 |
| 1409 // Swap tab contents over to the panel from the tabbed browser. |
| 1410 TabContentsWrapper* contents = |
| 1411 browser()->tab_strip_model()->DetachTabContentsAt(0); |
| 1412 panel_browser->tab_strip_model()->InsertTabContentsAt( |
| 1413 0, contents, TabStripModel::ADD_NONE); |
| 1414 panel_browser->SelectNumberedTab(0); |
| 1415 EXPECT_EQ(contents, panel_browser->GetSelectedTabContentsWrapper()); |
| 1416 EXPECT_EQ(1, PanelManager::GetInstance()->num_panels()); |
| 1417 |
| 1418 // Ensure that the tab contents were noticed by the panel by |
| 1419 // verifying that the panel auto resizes correctly. (Panel |
| 1420 // enables auto resizing when tab contents are detected.) |
| 1421 int initial_width = panel->GetBounds().width(); |
| 1422 ui_test_utils::WindowedNotificationObserver enlarge( |
| 1423 chrome::NOTIFICATION_PANEL_BOUNDS_ANIMATIONS_FINISHED, |
| 1424 content::Source<Panel>(panel)); |
| 1425 EXPECT_TRUE(ui_test_utils::ExecuteJavaScript( |
| 1426 panel_browser->GetSelectedWebContents()->GetRenderViewHost(), |
| 1427 std::wstring(), |
| 1428 L"changeSize(50);")); |
| 1429 enlarge.Wait(); |
| 1430 EXPECT_GT(panel->GetBounds().width(), initial_width); |
| 1431 |
| 1432 // Swapping tab contents back to the browser should close the panel. |
| 1433 ui_test_utils::WindowedNotificationObserver signal( |
| 1434 chrome::NOTIFICATION_PANEL_CLOSED, |
| 1435 content::Source<Panel>(panel)); |
| 1436 panel_browser->ConvertPopupToTabbedBrowser(); |
| 1437 signal.Wait(); |
| 1438 EXPECT_EQ(0, PanelManager::GetInstance()->num_panels()); |
| 1439 |
| 1440 Browser* tabbed_browser = browser::FindTabbedBrowser(profile, false); |
| 1441 EXPECT_EQ(contents, tabbed_browser->GetSelectedTabContentsWrapper()); |
| 1442 tabbed_browser->window()->Close(); |
| 1443 } |
| 1444 |
| 1445 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, SizeClamping) { |
| 1446 // Using '0' sizes is equivalent of not providing sizes in API and causes |
| 1447 // minimum sizes to be applied to facilitate auto-sizing. |
| 1448 CreatePanelParams params("Panel", gfx::Rect(), SHOW_AS_ACTIVE); |
| 1449 Panel* panel = CreatePanelWithParams(params); |
| 1450 EXPECT_EQ(panel->min_size().width(), panel->GetBounds().width()); |
| 1451 EXPECT_EQ(panel->min_size().height(), panel->GetBounds().height()); |
| 1452 int reasonable_width = panel->min_size().width() + 10; |
| 1453 int reasonable_height = panel->min_size().height() + 20; |
| 1454 |
| 1455 panel->Close(); |
| 1456 |
| 1457 // Using reasonable actual sizes should avoid clamping. |
| 1458 CreatePanelParams params1("Panel1", |
| 1459 gfx::Rect(0, 0, |
| 1460 reasonable_width, reasonable_height), |
| 1461 SHOW_AS_ACTIVE); |
| 1462 panel = CreatePanelWithParams(params1); |
| 1463 EXPECT_EQ(reasonable_width, panel->GetBounds().width()); |
| 1464 EXPECT_EQ(reasonable_height, panel->GetBounds().height()); |
| 1465 panel->Close(); |
| 1466 |
| 1467 // Using just one size should auto-compute some reasonable other size. |
| 1468 int given_height = 200; |
| 1469 CreatePanelParams params2("Panel2", gfx::Rect(0, 0, 0, given_height), |
| 1470 SHOW_AS_ACTIVE); |
| 1471 panel = CreatePanelWithParams(params2); |
| 1472 EXPECT_GT(panel->GetBounds().width(), 0); |
| 1473 EXPECT_EQ(given_height, panel->GetBounds().height()); |
| 1474 panel->Close(); |
| 1475 } |
| 1476 |
| 1477 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, TightAutosizeAroundSingleLine) { |
| 1478 PanelManager::GetInstance()->enable_auto_sizing(true); |
| 1479 // Using 0 sizes triggers auto-sizing. |
| 1480 CreatePanelParams params("Panel", gfx::Rect(), SHOW_AS_ACTIVE); |
| 1481 params.url = GURL("data:text/html;charset=utf-8,<!doctype html><body>"); |
| 1482 Panel* panel = CreatePanelWithParams(params); |
| 1483 |
| 1484 int initial_width = panel->GetBounds().width(); |
| 1485 int initial_height = panel->GetBounds().height(); |
| 1486 |
| 1487 // Inject some HTML content into the panel. |
| 1488 ui_test_utils::WindowedNotificationObserver enlarge( |
| 1489 chrome::NOTIFICATION_PANEL_BOUNDS_ANIMATIONS_FINISHED, |
| 1490 content::Source<Panel>(panel)); |
| 1491 EXPECT_TRUE(ui_test_utils::ExecuteJavaScript( |
| 1492 panel->WebContents()->GetRenderViewHost(), |
| 1493 std::wstring(), |
| 1494 L"document.body.innerHTML =" |
| 1495 L"'<nobr>line of text and a <button>Button</button>';")); |
| 1496 enlarge.Wait(); |
| 1497 |
| 1498 // The panel should have become larger in both dimensions (the minimums |
| 1499 // has to be set to be smaller then a simple 1-line content, so the autosize |
| 1500 // can work correctly. |
| 1501 EXPECT_GT(panel->GetBounds().width(), initial_width); |
| 1502 EXPECT_GT(panel->GetBounds().height(), initial_height); |
| 1503 |
| 1504 panel->Close(); |
| 1505 } |
| 1506 |
| 1507 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, |
| 1508 DefaultMaxSizeOnDisplaySettingsChange) { |
| 1509 Panel* panel = CreatePanelWithBounds("1", gfx::Rect(0, 0, 240, 220)); |
| 1510 |
| 1511 gfx::Size old_max_size = panel->max_size(); |
| 1512 gfx::Size old_full_size = panel->full_size(); |
| 1513 |
| 1514 // Shrink the work area. Expect max size and full size become smaller. |
| 1515 gfx::Size smaller_work_area_size = gfx::Size(500, 300); |
| 1516 SetTestingAreas(gfx::Rect(gfx::Point(0, 0), smaller_work_area_size), |
| 1517 gfx::Rect()); |
| 1518 EXPECT_GT(old_max_size.width(), panel->max_size().width()); |
| 1519 EXPECT_GT(old_max_size.height(), panel->max_size().height()); |
| 1520 EXPECT_GT(smaller_work_area_size.width(), panel->max_size().width()); |
| 1521 EXPECT_GT(smaller_work_area_size.height(), panel->max_size().height()); |
| 1522 EXPECT_GT(old_full_size.width(), panel->full_size().width()); |
| 1523 EXPECT_GT(old_full_size.height(), panel->full_size().height()); |
| 1524 EXPECT_GE(panel->max_size().width(), panel->full_size().width()); |
| 1525 EXPECT_GE(panel->max_size().height(), panel->full_size().height()); |
| 1526 |
| 1527 panel->Close(); |
| 1528 } |
| 1529 |
| 1530 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, |
| 1531 CustomMaxSizeOnDisplaySettingsChange) { |
| 1532 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 1533 Panel* panel = CreatePanelWithBounds("1", gfx::Rect(0, 0, 240, 220)); |
| 1534 |
| 1535 // Trigger custom max size by user resizing. |
| 1536 gfx::Size bigger_size = gfx::Size(550, 400); |
| 1537 gfx::Point mouse_location = panel->GetBounds().origin(); |
| 1538 panel_manager->StartResizingByMouse(panel, |
| 1539 mouse_location, |
| 1540 panel::RESIZE_TOP_LEFT); |
| 1541 mouse_location.Offset(panel->GetBounds().width() - bigger_size.width(), |
| 1542 panel->GetBounds().height() - bigger_size.height()); |
| 1543 panel_manager->ResizeByMouse(mouse_location); |
| 1544 panel_manager->EndResizingByMouse(false); |
| 1545 |
| 1546 gfx::Size old_max_size = panel->max_size(); |
| 1547 EXPECT_EQ(bigger_size, old_max_size); |
| 1548 gfx::Size old_full_size = panel->full_size(); |
| 1549 EXPECT_EQ(bigger_size, old_full_size); |
| 1550 |
| 1551 // Shrink the work area. Expect max size and full size become smaller. |
| 1552 gfx::Size smaller_work_area_size = gfx::Size(500, 300); |
| 1553 SetTestingAreas(gfx::Rect(gfx::Point(0, 0), smaller_work_area_size), |
| 1554 gfx::Rect()); |
| 1555 EXPECT_GT(old_max_size.width(), panel->max_size().width()); |
| 1556 EXPECT_GT(old_max_size.height(), panel->max_size().height()); |
| 1557 EXPECT_GE(smaller_work_area_size.width(), panel->max_size().width()); |
| 1558 EXPECT_EQ(smaller_work_area_size.height(), panel->max_size().height()); |
| 1559 EXPECT_GT(old_full_size.width(), panel->full_size().width()); |
| 1560 EXPECT_GT(old_full_size.height(), panel->full_size().height()); |
| 1561 EXPECT_GE(panel->max_size().width(), panel->full_size().width()); |
| 1562 EXPECT_GE(panel->max_size().height(), panel->full_size().height()); |
| 1563 EXPECT_EQ(smaller_work_area_size.height(), panel->full_size().height()); |
| 1564 |
| 1565 panel->Close(); |
| 1566 } |
| 1567 |
| 1568 class PanelDownloadTest : public PanelBrowserTest { |
| 1569 public: |
| 1570 PanelDownloadTest() : PanelBrowserTest() { } |
| 1571 |
| 1572 // Creates a temporary directory for downloads that is auto-deleted |
| 1573 // on destruction. |
| 1574 bool CreateDownloadDirectory(Profile* profile) { |
| 1575 bool created = downloads_directory_.CreateUniqueTempDir(); |
| 1576 if (!created) |
| 1577 return false; |
| 1578 profile->GetPrefs()->SetFilePath( |
| 1579 prefs::kDownloadDefaultDirectory, |
| 1580 downloads_directory_.path()); |
| 1581 return true; |
| 1582 } |
| 1583 |
| 1584 protected: |
| 1585 void SetUpOnMainThread() OVERRIDE { |
| 1586 PanelBrowserTest::SetUpOnMainThread(); |
| 1587 |
| 1588 BrowserThread::PostTask( |
| 1589 BrowserThread::IO, FROM_HERE, |
| 1590 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); |
| 1591 } |
| 1592 |
| 1593 private: |
| 1594 // Location of the downloads directory for download tests. |
| 1595 ScopedTempDir downloads_directory_; |
| 1596 }; |
| 1597 |
| 1598 class DownloadObserver : public content::DownloadManager::Observer { |
| 1599 public: |
| 1600 explicit DownloadObserver(Profile* profile) |
| 1601 : download_manager_( |
| 1602 BrowserContext::GetDownloadManager(profile)), |
| 1603 saw_download_(false), |
| 1604 waiting_(false) { |
| 1605 download_manager_->AddObserver(this); |
| 1606 } |
| 1607 |
| 1608 ~DownloadObserver() { |
| 1609 download_manager_->RemoveObserver(this); |
| 1610 } |
| 1611 |
| 1612 void WaitForDownload() { |
| 1613 if (!saw_download_) { |
| 1614 waiting_ = true; |
| 1615 ui_test_utils::RunMessageLoop(); |
| 1616 EXPECT_TRUE(saw_download_); |
| 1617 waiting_ = false; |
| 1618 } |
| 1619 } |
| 1620 |
| 1621 // DownloadManager::Observer |
| 1622 virtual void ModelChanged(DownloadManager* manager) { |
| 1623 DCHECK_EQ(download_manager_, manager); |
| 1624 |
| 1625 std::vector<DownloadItem*> downloads; |
| 1626 download_manager_->SearchDownloads(string16(), &downloads); |
| 1627 if (downloads.empty()) |
| 1628 return; |
| 1629 |
| 1630 EXPECT_EQ(1U, downloads.size()); |
| 1631 downloads.front()->Cancel(false); // Don't actually need to download it. |
| 1632 |
| 1633 saw_download_ = true; |
| 1634 EXPECT_TRUE(waiting_); |
| 1635 MessageLoopForUI::current()->Quit(); |
| 1636 } |
| 1637 |
| 1638 private: |
| 1639 DownloadManager* download_manager_; |
| 1640 bool saw_download_; |
| 1641 bool waiting_; |
| 1642 }; |
| 1643 |
| 1644 // Verify that the download shelf is opened in the existing tabbed browser |
| 1645 // when a download is started in a Panel. |
| 1646 IN_PROC_BROWSER_TEST_F(PanelDownloadTest, Download) { |
| 1647 Profile* profile = browser()->profile(); |
| 1648 ASSERT_TRUE(CreateDownloadDirectory(profile)); |
| 1649 Browser* panel_browser = Browser::CreateWithParams( |
| 1650 Browser::CreateParams::CreateForApp( |
| 1651 Browser::TYPE_PANEL, "PanelTest", gfx::Rect(), profile)); |
| 1652 EXPECT_EQ(2U, BrowserList::size()); |
| 1653 ASSERT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 1654 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible()); |
| 1655 |
| 1656 scoped_ptr<DownloadObserver> observer(new DownloadObserver(profile)); |
| 1657 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1658 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1659 ui_test_utils::NavigateToURLWithDisposition( |
| 1660 panel_browser, |
| 1661 download_url, |
| 1662 CURRENT_TAB, |
| 1663 ui_test_utils::BROWSER_TEST_NONE); |
| 1664 observer->WaitForDownload(); |
| 1665 |
| 1666 #if defined(OS_CHROMEOS) |
| 1667 // ChromeOS uses a download panel instead of a download shelf. |
| 1668 EXPECT_EQ(3U, BrowserList::size()); |
| 1669 ASSERT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 1670 |
| 1671 std::set<Browser*> original_browsers; |
| 1672 original_browsers.insert(browser()); |
| 1673 original_browsers.insert(panel_browser); |
| 1674 Browser* added = ui_test_utils::GetBrowserNotInSet(original_browsers); |
| 1675 ASSERT_TRUE(added->is_type_panel()); |
| 1676 ASSERT_FALSE(added->window()->IsDownloadShelfVisible()); |
| 1677 #else |
| 1678 EXPECT_EQ(2U, BrowserList::size()); |
| 1679 ASSERT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 1680 #endif |
| 1681 |
| 1682 EXPECT_EQ(1, browser()->tab_count()); |
| 1683 EXPECT_EQ(1, panel_browser->tab_count()); |
| 1684 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible()); |
| 1685 |
| 1686 panel_browser->CloseWindow(); |
| 1687 browser()->CloseWindow(); |
| 1688 } |
| 1689 |
| 1690 // See crbug 113779. |
| 1691 #if defined(OS_MACOSX) |
| 1692 #define MAYBE_DownloadNoTabbedBrowser DISABLED_DownloadNoTabbedBrowser |
| 1693 #else |
| 1694 #define MAYBE_DownloadNoTabbedBrowser DownloadNoTabbedBrowser |
| 1695 #endif |
| 1696 // Verify that a new tabbed browser is created to display a download |
| 1697 // shelf when a download is started in a Panel and there is no existing |
| 1698 // tabbed browser. |
| 1699 IN_PROC_BROWSER_TEST_F(PanelDownloadTest, MAYBE_DownloadNoTabbedBrowser) { |
| 1700 Profile* profile = browser()->profile(); |
| 1701 ASSERT_TRUE(CreateDownloadDirectory(profile)); |
| 1702 Browser* panel_browser = Browser::CreateWithParams( |
| 1703 Browser::CreateParams::CreateForApp( |
| 1704 Browser::TYPE_PANEL, "PanelTest", gfx::Rect(), profile)); |
| 1705 EXPECT_EQ(2U, BrowserList::size()); |
| 1706 ASSERT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 1707 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible()); |
| 1708 |
| 1709 ui_test_utils::WindowedNotificationObserver signal( |
| 1710 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 1711 content::Source<Browser>(browser())); |
| 1712 browser()->CloseWindow(); |
| 1713 signal.Wait(); |
| 1714 ASSERT_EQ(1U, BrowserList::size()); |
| 1715 ASSERT_EQ(NULL, browser::FindTabbedBrowser(profile, false)); |
| 1716 |
| 1717 scoped_ptr<DownloadObserver> observer(new DownloadObserver(profile)); |
| 1718 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1719 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1720 ui_test_utils::NavigateToURLWithDisposition( |
| 1721 panel_browser, |
| 1722 download_url, |
| 1723 CURRENT_TAB, |
| 1724 ui_test_utils::BROWSER_TEST_NONE); |
| 1725 observer->WaitForDownload(); |
| 1726 |
| 1727 EXPECT_EQ(2U, BrowserList::size()); |
| 1728 |
| 1729 Browser* tabbed_browser = browser::FindTabbedBrowser(profile, false); |
| 1730 EXPECT_EQ(1, tabbed_browser->tab_count()); |
| 1731 ASSERT_TRUE(tabbed_browser->window()->IsDownloadShelfVisible()); |
| 1732 tabbed_browser->CloseWindow(); |
| 1733 |
| 1734 EXPECT_EQ(1, panel_browser->tab_count()); |
| 1735 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible()); |
| 1736 |
| 1737 panel_browser->CloseWindow(); |
| 1738 } |
OLD | NEW |