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