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 "base/command_line.h" |
6 #include "chrome/browser/download/download_manager.h" | 6 #include "chrome/browser/download/download_manager.h" |
7 #include "chrome/browser/extensions/extension_service.h" | 7 #include "chrome/browser/extensions/extension_service.h" |
8 #include "chrome/browser/prefs/pref_service.h" | 8 #include "chrome/browser/prefs/pref_service.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/browser_list.h" | 11 #include "chrome/browser/ui/browser_list.h" |
12 #include "chrome/browser/ui/browser_window.h" | 12 #include "chrome/browser/ui/browser_window.h" |
13 #include "chrome/browser/ui/find_bar/find_bar.h" | 13 #include "chrome/browser/ui/find_bar/find_bar.h" |
14 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 14 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
| 15 #include "chrome/browser/ui/panels/native_panel.h" |
15 #include "chrome/browser/ui/panels/panel.h" | 16 #include "chrome/browser/ui/panels/panel.h" |
16 #include "chrome/browser/ui/panels/panel_manager.h" | 17 #include "chrome/browser/ui/panels/panel_manager.h" |
17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
18 #include "chrome/browser/web_applications/web_app.h" | 19 #include "chrome/browser/web_applications/web_app.h" |
19 #include "chrome/common/chrome_notification_types.h" | 20 #include "chrome/common/chrome_notification_types.h" |
20 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
21 #include "chrome/common/extensions/extension.h" | 22 #include "chrome/common/extensions/extension.h" |
22 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
23 #include "chrome/test/base/in_process_browser_test.h" | 24 #include "chrome/test/base/in_process_browser_test.h" |
24 #include "chrome/test/base/ui_test_utils.h" | 25 #include "chrome/test/base/ui_test_utils.h" |
(...skipping 24 matching lines...) Expand all Loading... |
49 bounds, | 50 bounds, |
50 browser()->profile()); | 51 browser()->profile()); |
51 EXPECT_TRUE(panel_browser->is_type_panel()); | 52 EXPECT_TRUE(panel_browser->is_type_panel()); |
52 | 53 |
53 TabContentsWrapper* tab_contents = | 54 TabContentsWrapper* tab_contents = |
54 new TabContentsWrapper(new TestTabContents(browser()->profile(), NULL)); | 55 new TabContentsWrapper(new TestTabContents(browser()->profile(), NULL)); |
55 panel_browser->AddTab(tab_contents, PageTransition::LINK); | 56 panel_browser->AddTab(tab_contents, PageTransition::LINK); |
56 | 57 |
57 Panel* panel = static_cast<Panel*>(panel_browser->window()); | 58 Panel* panel = static_cast<Panel*>(panel_browser->window()); |
58 panel->Show(); | 59 panel->Show(); |
| 60 MessageLoopForUI::current()->RunAllPending(); |
| 61 |
59 return panel; | 62 return panel; |
60 } | 63 } |
61 | 64 |
62 // Creates a testing extension. | 65 // Creates a testing extension. |
63 scoped_refptr<Extension> CreateExtension(const FilePath::StringType& path) { | 66 scoped_refptr<Extension> CreateExtension(const FilePath::StringType& path) { |
64 #if defined(OS_WIN) | 67 #if defined(OS_WIN) |
65 FilePath full_path(FILE_PATH_LITERAL("c:\\")); | 68 FilePath full_path(FILE_PATH_LITERAL("c:\\")); |
66 #else | 69 #else |
67 FilePath full_path(FILE_PATH_LITERAL("/")); | 70 FilePath full_path(FILE_PATH_LITERAL("/")); |
68 #endif | 71 #endif |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 web_app::GenerateApplicationNameFromExtensionId(extension3->id()), | 146 web_app::GenerateApplicationNameFromExtensionId(extension3->id()), |
144 gfx::Rect(0, 0, 500, 200)); | 147 gfx::Rect(0, 0, 500, 200)); |
145 signal3.Wait(); | 148 signal3.Wait(); |
146 signal4.Wait(); | 149 signal4.Wait(); |
147 ASSERT_EQ(2, panel_manager->num_panels()); | 150 ASSERT_EQ(2, panel_manager->num_panels()); |
148 EXPECT_LT(panel6->GetBounds().right(), panel1->GetBounds().x()); | 151 EXPECT_LT(panel6->GetBounds().right(), panel1->GetBounds().x()); |
149 | 152 |
150 panel1->Close(); | 153 panel1->Close(); |
151 panel6->Close(); | 154 panel6->Close(); |
152 } | 155 } |
| 156 |
| 157 struct DragTestData { |
| 158 DragTestData(int drag_delta_x, |
| 159 int drag_delta_y, |
| 160 bool is_big_delta, |
| 161 bool should_cancel_drag) |
| 162 : drag_delta_x(drag_delta_x), drag_delta_y(drag_delta_y), |
| 163 is_big_delta(is_big_delta), should_cancel_drag(should_cancel_drag) {} |
| 164 int drag_delta_x; |
| 165 int drag_delta_y; |
| 166 bool is_big_delta; // Drag big enough to cause shuffling. |
| 167 bool should_cancel_drag; |
| 168 }; |
| 169 |
| 170 void TestDragging(std::vector<Panel*>* panels, |
| 171 const DragTestData& drag_test_data) { |
| 172 size_t num_panels = panels->size(); |
| 173 |
| 174 // Test dragging each panel in the list. |
| 175 for (size_t drag_index = 0; drag_index < num_panels; ++drag_index) { |
| 176 std::vector<int> expected_delta_x_after_drag(num_panels, 0); |
| 177 std::vector<int> expected_delta_x_after_finish(num_panels, 0); |
| 178 |
| 179 for (size_t j = 0; j < num_panels; ++j) { |
| 180 expected_delta_x_after_drag.push_back(0); |
| 181 expected_delta_x_after_finish.push_back(0); |
| 182 } |
| 183 |
| 184 expected_delta_x_after_drag[drag_index] = drag_test_data.drag_delta_x; |
| 185 size_t swap_index = drag_index; |
| 186 if (drag_test_data.is_big_delta) { |
| 187 if (drag_test_data.drag_delta_x > 0 && drag_index != 0) { |
| 188 // Dragged to right. |
| 189 swap_index = drag_index - 1; |
| 190 } else if (drag_test_data.drag_delta_x < 0 && |
| 191 drag_index != num_panels - 1) { |
| 192 // Dragged to left. |
| 193 swap_index = drag_index + 1; |
| 194 } |
| 195 } |
| 196 if (swap_index != drag_index) { |
| 197 expected_delta_x_after_drag[swap_index] = |
| 198 (*panels)[drag_index]->GetRestoredBounds().x() - |
| 199 (*panels)[swap_index]->GetRestoredBounds().x(); |
| 200 expected_delta_x_after_finish[swap_index] = |
| 201 expected_delta_x_after_drag[swap_index]; |
| 202 expected_delta_x_after_finish[drag_index] = |
| 203 -expected_delta_x_after_drag[swap_index]; |
| 204 } |
| 205 ValidateDragging(*panels, drag_index, drag_test_data.drag_delta_x, |
| 206 drag_test_data.drag_delta_y, expected_delta_x_after_drag, |
| 207 expected_delta_x_after_finish, drag_test_data.should_cancel_drag); |
| 208 |
| 209 if (swap_index != drag_index && !drag_test_data.should_cancel_drag) { |
| 210 // Swap the panels in the vector so they reflect their true relative |
| 211 // positions. |
| 212 Panel* tmp_panel = (*panels)[swap_index]; |
| 213 (*panels)[swap_index] = (*panels)[drag_index]; |
| 214 (*panels)[drag_index] = tmp_panel; |
| 215 } |
| 216 } |
| 217 } |
| 218 |
| 219 void ValidateDragging(const std::vector<Panel*>& panels, |
| 220 int index_to_drag, |
| 221 int delta_x, |
| 222 int delta_y, |
| 223 const std::vector<int>& expected_delta_x_after_drag, |
| 224 const std::vector<int>& expected_delta_x_after_finish, |
| 225 bool should_cancel_drag) { |
| 226 // Keep track of the initial bounds for comparison. |
| 227 std::vector<gfx::Rect> initial_bounds(panels.size()); |
| 228 for (size_t i = 0; i < panels.size(); ++i) |
| 229 initial_bounds[i] = panels[i]->GetRestoredBounds(); |
| 230 |
| 231 // Trigger the mouse-pressed event. |
| 232 // All panels should remain in their original positions. |
| 233 NativePanel* panel_to_drag = panels[index_to_drag]->native_panel(); |
| 234 scoped_ptr<NativePanelTesting> panel_testing_to_drag( |
| 235 NativePanelTesting::Create(panel_to_drag)); |
| 236 |
| 237 gfx::Point button_press_point(initial_bounds[index_to_drag].x(), |
| 238 initial_bounds[index_to_drag].y()); |
| 239 panel_testing_to_drag->PressLeftMouseButtonTitlebar(button_press_point); |
| 240 for (size_t i = 0; i < panels.size(); ++i) |
| 241 EXPECT_EQ(initial_bounds[i], panels[i]->GetRestoredBounds()); |
| 242 |
| 243 // Trigger the drag. |
| 244 panel_testing_to_drag->DragTitlebar(delta_x, delta_y); |
| 245 |
| 246 for (size_t i = 0; i < panels.size(); ++i) { |
| 247 gfx::Rect expected_bounds = initial_bounds[i]; |
| 248 expected_bounds.Offset(expected_delta_x_after_drag[i], 0); |
| 249 EXPECT_EQ(expected_bounds, panels[i]->GetRestoredBounds()); |
| 250 } |
| 251 |
| 252 // Cancel drag if asked. |
| 253 // All panels should stay in their original positions. |
| 254 if (should_cancel_drag) { |
| 255 panel_testing_to_drag->CancelDragTitlebar(); |
| 256 for (size_t i = 0; i < panels.size(); ++i) |
| 257 EXPECT_EQ(initial_bounds[i], panels[i]->GetRestoredBounds()); |
| 258 return; |
| 259 } |
| 260 |
| 261 // Otherwise finish the drag. |
| 262 panel_testing_to_drag->FinishDragTitlebar(); |
| 263 for (size_t i = 0; i < panels.size(); ++i) { |
| 264 gfx::Rect expected_bounds = initial_bounds[i]; |
| 265 expected_bounds.Offset(expected_delta_x_after_finish[i], 0); |
| 266 EXPECT_EQ(expected_bounds, panels[i]->GetRestoredBounds()); |
| 267 } |
| 268 } |
153 }; | 269 }; |
154 | 270 |
155 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreatePanel) { | 271 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreatePanel) { |
156 PanelManager* panel_manager = PanelManager::GetInstance(); | 272 PanelManager* panel_manager = PanelManager::GetInstance(); |
157 EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially. | 273 EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially. |
158 | 274 |
159 Panel* panel = CreatePanel("PanelTest", gfx::Rect()); | 275 Panel* panel = CreatePanel("PanelTest", gfx::Rect()); |
160 EXPECT_EQ(1, panel_manager->num_panels()); | 276 EXPECT_EQ(1, panel_manager->num_panels()); |
161 | 277 |
162 gfx::Rect bounds = panel->GetBounds(); | 278 gfx::Rect bounds = panel->GetBounds(); |
(...skipping 18 matching lines...) Expand all Loading... |
181 #ifdef OS_MACOSX | 297 #ifdef OS_MACOSX |
182 #define MAYBE_CreatePanelOnOverflow DISABLED_CreatePanelOnOverflow | 298 #define MAYBE_CreatePanelOnOverflow DISABLED_CreatePanelOnOverflow |
183 #else | 299 #else |
184 #define MAYBE_CreatePanelOnOverflow CreatePanelOnOverflow | 300 #define MAYBE_CreatePanelOnOverflow CreatePanelOnOverflow |
185 #endif | 301 #endif |
186 | 302 |
187 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_CreatePanelOnOverflow) { | 303 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_CreatePanelOnOverflow) { |
188 TestCreatePanelOnOverflow(); | 304 TestCreatePanelOnOverflow(); |
189 } | 305 } |
190 | 306 |
| 307 #ifdef OS_MACOSX |
| 308 #define MAYBE_DragPanels DISABLED_DragPanels |
| 309 #else |
| 310 #define MAYBE_DragPanels DragPanels |
| 311 #endif |
| 312 |
| 313 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_DragPanels) { |
| 314 std::vector<Panel*> panels; |
| 315 panels.push_back(CreatePanel("PanelTest0", gfx::Rect())); |
| 316 |
| 317 int small_delta = 5; |
| 318 int big_delta = panels[0]->GetRestoredBounds().width() * 0.5 + 5; |
| 319 |
| 320 // Setup test data. |
| 321 // Template - DragTestData(delta_x, delta_y, is_big_delta, should_cancel_drag) |
| 322 std::vector<DragTestData> drag_test_data; |
| 323 drag_test_data.push_back(DragTestData( |
| 324 small_delta, small_delta, false, false)); |
| 325 drag_test_data.push_back(DragTestData( |
| 326 -small_delta, -small_delta, false, false)); |
| 327 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)); |
| 329 drag_test_data.push_back(DragTestData(-big_delta, -big_delta, true, false)); |
| 330 drag_test_data.push_back(DragTestData(-big_delta, 0, true, false)); |
| 331 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)); |
| 333 |
| 334 for (int num_panels = 1; num_panels <= 3; ++num_panels) { |
| 335 if (num_panels > 1) |
| 336 panels.push_back(CreatePanel("PanelTest", gfx::Rect())); |
| 337 for (size_t j = 0; j < drag_test_data.size(); ++j) { |
| 338 // Test for each combination of drag test data and number of panels. |
| 339 TestDragging(&panels, drag_test_data[j]); |
| 340 } |
| 341 } |
| 342 |
| 343 for (size_t i = 0; i < panels.size(); ++i) |
| 344 panels[i]->Close(); |
| 345 } |
| 346 |
191 class PanelDownloadTest : public PanelBrowserTest { | 347 class PanelDownloadTest : public PanelBrowserTest { |
192 public: | 348 public: |
193 PanelDownloadTest() : PanelBrowserTest() { } | 349 PanelDownloadTest() : PanelBrowserTest() { } |
194 | 350 |
195 // Creates a temporary directory for downloads that is auto-deleted | 351 // Creates a temporary directory for downloads that is auto-deleted |
196 // on destruction. | 352 // on destruction. |
197 bool CreateDownloadDirectory(Profile* profile) { | 353 bool CreateDownloadDirectory(Profile* profile) { |
198 bool created = downloads_directory_.CreateUniqueTempDir(); | 354 bool created = downloads_directory_.CreateUniqueTempDir(); |
199 if (!created) | 355 if (!created) |
200 return false; | 356 return false; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 EXPECT_EQ(1, tabbed_browser->tab_count()); | 501 EXPECT_EQ(1, tabbed_browser->tab_count()); |
346 ASSERT_TRUE(tabbed_browser->window()->IsDownloadShelfVisible()); | 502 ASSERT_TRUE(tabbed_browser->window()->IsDownloadShelfVisible()); |
347 tabbed_browser->CloseWindow(); | 503 tabbed_browser->CloseWindow(); |
348 #endif | 504 #endif |
349 | 505 |
350 EXPECT_EQ(1, panel_browser->tab_count()); | 506 EXPECT_EQ(1, panel_browser->tab_count()); |
351 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible()); | 507 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible()); |
352 | 508 |
353 panel_browser->CloseWindow(); | 509 panel_browser->CloseWindow(); |
354 } | 510 } |
OLD | NEW |