| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/command_line.h" | 5 #include "chrome/browser/ui/panels/base_panel_browser_test.h" |
| 6 #include "chrome/browser/extensions/extension_service.h" | 6 |
| 7 #include "chrome/browser/prefs/pref_service.h" | 7 #include "chrome/browser/prefs/pref_service.h" |
| 8 #include "chrome/browser/profiles/profile.h" | |
| 9 #include "chrome/browser/ui/browser.h" | |
| 10 #include "chrome/browser/ui/browser_list.h" | 8 #include "chrome/browser/ui/browser_list.h" |
| 11 #include "chrome/browser/ui/browser_window.h" | 9 #include "chrome/browser/ui/browser_window.h" |
| 12 #include "chrome/browser/ui/find_bar/find_bar.h" | 10 #include "chrome/browser/ui/find_bar/find_bar.h" |
| 13 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 11 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
| 14 #include "chrome/browser/ui/panels/native_panel.h" | 12 #include "chrome/browser/ui/panels/native_panel.h" |
| 15 #include "chrome/browser/ui/panels/panel.h" | 13 #include "chrome/browser/ui/panels/panel.h" |
| 16 #include "chrome/browser/ui/panels/panel_manager.h" | 14 #include "chrome/browser/ui/panels/panel_manager.h" |
| 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | |
| 18 #include "chrome/browser/web_applications/web_app.h" | 15 #include "chrome/browser/web_applications/web_app.h" |
| 19 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
| 20 #include "chrome/common/chrome_switches.h" | |
| 21 #include "chrome/common/extensions/extension.h" | |
| 22 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 23 #include "chrome/test/base/in_process_browser_test.h" | |
| 24 #include "chrome/test/base/ui_test_utils.h" | 18 #include "chrome/test/base/ui_test_utils.h" |
| 25 #include "content/browser/download/download_manager.h" | 19 #include "content/browser/download/download_manager.h" |
| 26 #include "content/browser/net/url_request_mock_http_job.h" | 20 #include "content/browser/net/url_request_mock_http_job.h" |
| 27 #include "content/browser/tab_contents/test_tab_contents.h" | |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 29 | 22 |
| 30 #if defined(OS_MACOSX) | 23 class PanelBrowserTest : public BasePanelBrowserTest { |
| 31 #include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" | |
| 32 #endif | |
| 33 | |
| 34 class PanelBrowserTest : public InProcessBrowserTest { | |
| 35 public: | 24 public: |
| 36 PanelBrowserTest() : InProcessBrowserTest() { | 25 PanelBrowserTest() : BasePanelBrowserTest() { |
| 37 #if defined(OS_MACOSX) | |
| 38 FindBarBridge::disable_animations_during_testing_ = true; | |
| 39 #endif | |
| 40 } | |
| 41 | |
| 42 virtual void SetUpCommandLine(CommandLine* command_line) { | |
| 43 command_line->AppendSwitch(switches::kEnablePanels); | |
| 44 } | 26 } |
| 45 | 27 |
| 46 protected: | 28 protected: |
| 47 Panel* CreatePanel(const std::string& name, const gfx::Rect& bounds) { | |
| 48 Browser* panel_browser = Browser::CreateForApp(Browser::TYPE_PANEL, | |
| 49 name, | |
| 50 bounds, | |
| 51 browser()->profile()); | |
| 52 EXPECT_TRUE(panel_browser->is_type_panel()); | |
| 53 | |
| 54 TabContentsWrapper* tab_contents = | |
| 55 new TabContentsWrapper(new TestTabContents(browser()->profile(), NULL)); | |
| 56 panel_browser->AddTab(tab_contents, PageTransition::LINK); | |
| 57 | |
| 58 Panel* panel = static_cast<Panel*>(panel_browser->window()); | |
| 59 panel->Show(); | |
| 60 MessageLoopForUI::current()->RunAllPending(); | |
| 61 | |
| 62 return panel; | |
| 63 } | |
| 64 | |
| 65 // Creates a testing extension. | |
| 66 scoped_refptr<Extension> CreateExtension(const FilePath::StringType& path) { | |
| 67 #if defined(OS_WIN) | |
| 68 FilePath full_path(FILE_PATH_LITERAL("c:\\")); | |
| 69 #else | |
| 70 FilePath full_path(FILE_PATH_LITERAL("/")); | |
| 71 #endif | |
| 72 full_path = full_path.Append(path); | |
| 73 DictionaryValue input_value; | |
| 74 input_value.SetString(extension_manifest_keys::kVersion, "1.0.0.0"); | |
| 75 input_value.SetString(extension_manifest_keys::kName, "Sample Extension"); | |
| 76 std::string error; | |
| 77 scoped_refptr<Extension> extension = Extension::Create( | |
| 78 full_path, Extension::INVALID, input_value, | |
| 79 Extension::STRICT_ERROR_CHECKS, &error); | |
| 80 EXPECT_TRUE(extension.get()); | |
| 81 EXPECT_STREQ("", error.c_str()); | |
| 82 browser()->GetProfile()->GetExtensionService()->OnLoadSingleExtension( | |
| 83 extension.get(), false); | |
| 84 return extension; | |
| 85 } | |
| 86 | |
| 87 void TestCreatePanelOnOverflow() { | 29 void TestCreatePanelOnOverflow() { |
| 88 PanelManager* panel_manager = PanelManager::GetInstance(); | 30 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 89 EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially. | 31 EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially. |
| 90 | 32 |
| 91 // Specify the work area for testing purpose. | |
| 92 panel_manager->SetWorkArea(gfx::Rect(0, 0, 800, 600)); | |
| 93 | |
| 94 // Create testing extensions. | 33 // Create testing extensions. |
| 95 scoped_refptr<Extension> extension1 = | 34 scoped_refptr<Extension> extension1 = |
| 96 CreateExtension(FILE_PATH_LITERAL("extension1")); | 35 CreateExtension(FILE_PATH_LITERAL("extension1"), |
| 36 Extension::INVALID, DictionaryValue()); |
| 97 scoped_refptr<Extension> extension2 = | 37 scoped_refptr<Extension> extension2 = |
| 98 CreateExtension(FILE_PATH_LITERAL("extension2")); | 38 CreateExtension(FILE_PATH_LITERAL("extension2"), |
| 39 Extension::INVALID, DictionaryValue()); |
| 99 scoped_refptr<Extension> extension3 = | 40 scoped_refptr<Extension> extension3 = |
| 100 CreateExtension(FILE_PATH_LITERAL("extension3")); | 41 CreateExtension(FILE_PATH_LITERAL("extension3"), |
| 42 Extension::INVALID, DictionaryValue()); |
| 101 | 43 |
| 102 // First, create 3 panels. | 44 // First, create 3 panels. |
| 103 Panel* panel1 = CreatePanel( | 45 Panel* panel1 = CreatePanel( |
| 104 web_app::GenerateApplicationNameFromExtensionId(extension1->id()), | 46 web_app::GenerateApplicationNameFromExtensionId(extension1->id()), |
| 105 gfx::Rect(0, 0, 250, 200)); | 47 gfx::Rect(0, 0, 250, 200), SHOW_AS_ACTIVE); |
| 106 Panel* panel2 = CreatePanel( | 48 Panel* panel2 = CreatePanel( |
| 107 web_app::GenerateApplicationNameFromExtensionId(extension2->id()), | 49 web_app::GenerateApplicationNameFromExtensionId(extension2->id()), |
| 108 gfx::Rect(0, 0, 300, 200)); | 50 gfx::Rect(0, 0, 300, 200), SHOW_AS_ACTIVE); |
| 109 Panel* panel3 = CreatePanel( | 51 Panel* panel3 = CreatePanel( |
| 110 web_app::GenerateApplicationNameFromExtensionId(extension1->id()), | 52 web_app::GenerateApplicationNameFromExtensionId(extension1->id()), |
| 111 gfx::Rect(0, 0, 200, 200)); | 53 gfx::Rect(0, 0, 200, 200), SHOW_AS_ACTIVE); |
| 112 ASSERT_EQ(3, panel_manager->num_panels()); | 54 ASSERT_EQ(3, panel_manager->num_panels()); |
| 113 | 55 |
| 114 // Test closing the left-most panel that is from same extension. | 56 // Test closing the left-most panel that is from same extension. |
| 115 ui_test_utils::WindowedNotificationObserver signal( | 57 ui_test_utils::WindowedNotificationObserver signal( |
| 116 chrome::NOTIFICATION_BROWSER_CLOSED, | 58 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 117 Source<Browser>(panel2->browser())); | 59 Source<Browser>(panel2->browser())); |
| 118 Panel* panel4 = CreatePanel( | 60 Panel* panel4 = CreatePanel( |
| 119 web_app::GenerateApplicationNameFromExtensionId(extension2->id()), | 61 web_app::GenerateApplicationNameFromExtensionId(extension2->id()), |
| 120 gfx::Rect(0, 0, 280, 200)); | 62 gfx::Rect(0, 0, 280, 200), SHOW_AS_ACTIVE); |
| 121 signal.Wait(); | 63 signal.Wait(); |
| 122 ASSERT_EQ(3, panel_manager->num_panels()); | 64 ASSERT_EQ(3, panel_manager->num_panels()); |
| 123 EXPECT_LT(panel4->GetBounds().right(), panel3->GetBounds().x()); | 65 EXPECT_LT(panel4->GetBounds().right(), panel3->GetBounds().x()); |
| 124 EXPECT_LT(panel3->GetBounds().right(), panel1->GetBounds().x()); | 66 EXPECT_LT(panel3->GetBounds().right(), panel1->GetBounds().x()); |
| 125 | 67 |
| 126 // Test closing the left-most panel. | 68 // Test closing the left-most panel. |
| 127 ui_test_utils::WindowedNotificationObserver signal2( | 69 ui_test_utils::WindowedNotificationObserver signal2( |
| 128 chrome::NOTIFICATION_BROWSER_CLOSED, | 70 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 129 Source<Browser>(panel4->browser())); | 71 Source<Browser>(panel4->browser())); |
| 130 Panel* panel5 = CreatePanel( | 72 Panel* panel5 = CreatePanel( |
| 131 web_app::GenerateApplicationNameFromExtensionId(extension3->id()), | 73 web_app::GenerateApplicationNameFromExtensionId(extension3->id()), |
| 132 gfx::Rect(0, 0, 300, 200)); | 74 gfx::Rect(0, 0, 300, 200), SHOW_AS_ACTIVE); |
| 133 signal2.Wait(); | 75 signal2.Wait(); |
| 134 ASSERT_EQ(3, panel_manager->num_panels()); | 76 ASSERT_EQ(3, panel_manager->num_panels()); |
| 135 EXPECT_LT(panel5->GetBounds().right(), panel3->GetBounds().x()); | 77 EXPECT_LT(panel5->GetBounds().right(), panel3->GetBounds().x()); |
| 136 EXPECT_LT(panel3->GetBounds().right(), panel1->GetBounds().x()); | 78 EXPECT_LT(panel3->GetBounds().right(), panel1->GetBounds().x()); |
| 137 | 79 |
| 138 // Test closing 2 left-most panels. | 80 // Test closing 2 left-most panels. |
| 139 ui_test_utils::WindowedNotificationObserver signal3( | 81 ui_test_utils::WindowedNotificationObserver signal3( |
| 140 chrome::NOTIFICATION_BROWSER_CLOSED, | 82 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 141 Source<Browser>(panel3->browser())); | 83 Source<Browser>(panel3->browser())); |
| 142 ui_test_utils::WindowedNotificationObserver signal4( | 84 ui_test_utils::WindowedNotificationObserver signal4( |
| 143 chrome::NOTIFICATION_BROWSER_CLOSED, | 85 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 144 Source<Browser>(panel5->browser())); | 86 Source<Browser>(panel5->browser())); |
| 145 Panel* panel6 = CreatePanel( | 87 Panel* panel6 = CreatePanel( |
| 146 web_app::GenerateApplicationNameFromExtensionId(extension3->id()), | 88 web_app::GenerateApplicationNameFromExtensionId(extension3->id()), |
| 147 gfx::Rect(0, 0, 500, 200)); | 89 gfx::Rect(0, 0, 500, 200), SHOW_AS_ACTIVE); |
| 148 signal3.Wait(); | 90 signal3.Wait(); |
| 149 signal4.Wait(); | 91 signal4.Wait(); |
| 150 ASSERT_EQ(2, panel_manager->num_panels()); | 92 ASSERT_EQ(2, panel_manager->num_panels()); |
| 151 EXPECT_LT(panel6->GetBounds().right(), panel1->GetBounds().x()); | 93 EXPECT_LT(panel6->GetBounds().right(), panel1->GetBounds().x()); |
| 152 | 94 |
| 153 panel1->Close(); | 95 panel1->Close(); |
| 154 panel6->Close(); | 96 panel6->Close(); |
| 155 } | 97 } |
| 156 | 98 |
| 157 struct DragTestData { | 99 struct DragTestData { |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 expected_bounds.Offset(expected_delta_x_after_finish[i], 0); | 207 expected_bounds.Offset(expected_delta_x_after_finish[i], 0); |
| 266 EXPECT_EQ(expected_bounds, panels[i]->GetRestoredBounds()); | 208 EXPECT_EQ(expected_bounds, panels[i]->GetRestoredBounds()); |
| 267 } | 209 } |
| 268 } | 210 } |
| 269 }; | 211 }; |
| 270 | 212 |
| 271 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreatePanel) { | 213 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreatePanel) { |
| 272 PanelManager* panel_manager = PanelManager::GetInstance(); | 214 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 273 EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially. | 215 EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially. |
| 274 | 216 |
| 275 Panel* panel = CreatePanel("PanelTest", gfx::Rect()); | 217 Panel* panel = CreatePanel("PanelTest", gfx::Rect(), SHOW_AS_ACTIVE); |
| 276 EXPECT_EQ(1, panel_manager->num_panels()); | 218 EXPECT_EQ(1, panel_manager->num_panels()); |
| 277 | 219 |
| 278 gfx::Rect bounds = panel->GetBounds(); | 220 gfx::Rect bounds = panel->GetBounds(); |
| 279 EXPECT_GT(bounds.x(), 0); | 221 EXPECT_GT(bounds.x(), 0); |
| 280 EXPECT_GT(bounds.y(), 0); | 222 EXPECT_GT(bounds.y(), 0); |
| 281 EXPECT_GT(bounds.width(), 0); | 223 EXPECT_GT(bounds.width(), 0); |
| 282 EXPECT_GT(bounds.height(), 0); | 224 EXPECT_GT(bounds.height(), 0); |
| 283 | 225 |
| 284 panel->Close(); | 226 panel->Close(); |
| 285 EXPECT_EQ(0, panel_manager->num_panels()); | 227 EXPECT_EQ(0, panel_manager->num_panels()); |
| 286 } | 228 } |
| 287 | 229 |
| 288 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, FindBar) { | 230 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, FindBar) { |
| 289 Panel* panel = CreatePanel("PanelTest", gfx::Rect(0, 0, 400, 400)); | 231 Panel* panel = CreatePanel("PanelTest", |
| 232 gfx::Rect(0, 0, 400, 400), |
| 233 SHOW_AS_ACTIVE); |
| 290 Browser* browser = panel->browser(); | 234 Browser* browser = panel->browser(); |
| 291 browser->ShowFindBar(); | 235 browser->ShowFindBar(); |
| 292 ASSERT_TRUE(browser->GetFindBarController()->find_bar()->IsFindBarVisible()); | 236 ASSERT_TRUE(browser->GetFindBarController()->find_bar()->IsFindBarVisible()); |
| 293 panel->Close(); | 237 panel->Close(); |
| 294 } | 238 } |
| 295 | 239 |
| 296 // TODO(jianli): Investigate and enable it for Mac. | 240 // TODO(jianli): Investigate and enable it for Mac. |
| 297 #ifdef OS_MACOSX | 241 #ifdef OS_MACOSX |
| 298 #define MAYBE_CreatePanelOnOverflow DISABLED_CreatePanelOnOverflow | 242 #define MAYBE_CreatePanelOnOverflow DISABLED_CreatePanelOnOverflow |
| 299 #else | 243 #else |
| 300 #define MAYBE_CreatePanelOnOverflow CreatePanelOnOverflow | 244 #define MAYBE_CreatePanelOnOverflow CreatePanelOnOverflow |
| 301 #endif | 245 #endif |
| 302 | 246 |
| 303 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_CreatePanelOnOverflow) { | 247 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_CreatePanelOnOverflow) { |
| 304 TestCreatePanelOnOverflow(); | 248 TestCreatePanelOnOverflow(); |
| 305 } | 249 } |
| 306 | 250 |
| 307 #if defined(TOOLKIT_GTK) || defined(OS_WIN) | 251 #if defined(TOOLKIT_GTK) || defined(OS_WIN) |
| 308 #define MAYBE_DragPanels DragPanels | 252 #define MAYBE_DragPanels DragPanels |
| 309 #else | 253 #else |
| 310 #define MAYBE_DragPanels DISABLED_DragPanels | 254 #define MAYBE_DragPanels DISABLED_DragPanels |
| 311 #endif | 255 #endif |
| 312 | 256 |
| 313 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_DragPanels) { | 257 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_DragPanels) { |
| 314 std::vector<Panel*> panels; | 258 std::vector<Panel*> panels; |
| 315 panels.push_back(CreatePanel("PanelTest0", gfx::Rect())); | 259 panels.push_back(CreatePanel("PanelTest0", gfx::Rect(), SHOW_AS_ACTIVE)); |
| 316 | 260 |
| 317 int small_delta = 5; | 261 int small_delta = 5; |
| 318 int big_delta = panels[0]->GetRestoredBounds().width() * 0.5 + 5; | 262 int big_delta = panels[0]->GetRestoredBounds().width() * 0.5 + 5; |
| 319 | 263 |
| 320 // Setup test data. | 264 // Setup test data. |
| 321 // Template - DragTestData(delta_x, delta_y, is_big_delta, should_cancel_drag) | 265 // Template - DragTestData(delta_x, delta_y, is_big_delta, should_cancel_drag) |
| 322 std::vector<DragTestData> drag_test_data; | 266 std::vector<DragTestData> drag_test_data; |
| 323 drag_test_data.push_back(DragTestData( | 267 drag_test_data.push_back(DragTestData( |
| 324 small_delta, small_delta, false, false)); | 268 small_delta, small_delta, false, false)); |
| 325 drag_test_data.push_back(DragTestData( | 269 drag_test_data.push_back(DragTestData( |
| 326 -small_delta, -small_delta, false, false)); | 270 -small_delta, -small_delta, false, false)); |
| 327 drag_test_data.push_back(DragTestData(big_delta, big_delta, true, false)); | 271 drag_test_data.push_back(DragTestData(big_delta, big_delta, true, false)); |
| 328 drag_test_data.push_back(DragTestData(big_delta, small_delta, true, false)); | 272 drag_test_data.push_back(DragTestData(big_delta, small_delta, true, false)); |
| 329 drag_test_data.push_back(DragTestData(-big_delta, -big_delta, true, false)); | 273 drag_test_data.push_back(DragTestData(-big_delta, -big_delta, true, false)); |
| 330 drag_test_data.push_back(DragTestData(-big_delta, 0, true, false)); | 274 drag_test_data.push_back(DragTestData(-big_delta, 0, true, false)); |
| 331 drag_test_data.push_back(DragTestData(big_delta, big_delta, true, true)); | 275 drag_test_data.push_back(DragTestData(big_delta, big_delta, true, true)); |
| 332 drag_test_data.push_back(DragTestData(-big_delta, -big_delta, true, true)); | 276 drag_test_data.push_back(DragTestData(-big_delta, -big_delta, true, true)); |
| 333 | 277 |
| 334 for (int num_panels = 1; num_panels <= 3; ++num_panels) { | 278 for (int num_panels = 1; num_panels <= 3; ++num_panels) { |
| 335 if (num_panels > 1) | 279 if (num_panels > 1) |
| 336 panels.push_back(CreatePanel("PanelTest", gfx::Rect())); | 280 panels.push_back(CreatePanel("PanelTest", gfx::Rect(), SHOW_AS_ACTIVE)); |
| 337 for (size_t j = 0; j < drag_test_data.size(); ++j) { | 281 for (size_t j = 0; j < drag_test_data.size(); ++j) { |
| 338 // Test for each combination of drag test data and number of panels. | 282 // Test for each combination of drag test data and number of panels. |
| 339 TestDragging(&panels, drag_test_data[j]); | 283 TestDragging(&panels, drag_test_data[j]); |
| 340 } | 284 } |
| 341 } | 285 } |
| 342 | 286 |
| 343 for (size_t i = 0; i < panels.size(); ++i) | 287 for (size_t i = 0; i < panels.size(); ++i) |
| 344 panels[i]->Close(); | 288 panels[i]->Close(); |
| 345 } | 289 } |
| 346 | 290 |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 EXPECT_EQ(1, tabbed_browser->tab_count()); | 445 EXPECT_EQ(1, tabbed_browser->tab_count()); |
| 502 ASSERT_TRUE(tabbed_browser->window()->IsDownloadShelfVisible()); | 446 ASSERT_TRUE(tabbed_browser->window()->IsDownloadShelfVisible()); |
| 503 tabbed_browser->CloseWindow(); | 447 tabbed_browser->CloseWindow(); |
| 504 #endif | 448 #endif |
| 505 | 449 |
| 506 EXPECT_EQ(1, panel_browser->tab_count()); | 450 EXPECT_EQ(1, panel_browser->tab_count()); |
| 507 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible()); | 451 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible()); |
| 508 | 452 |
| 509 panel_browser->CloseWindow(); | 453 panel_browser->CloseWindow(); |
| 510 } | 454 } |
| OLD | NEW |