Chromium Code Reviews| 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/extensions/extension_service.h" | 6 #include "chrome/browser/extensions/extension_service.h" |
| 7 #include "chrome/browser/prefs/pref_service.h" | 7 #include "chrome/browser/prefs/pref_service.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_list.h" | 10 #include "chrome/browser/ui/browser_list.h" |
| 11 #include "chrome/browser/ui/browser_window.h" | 11 #include "chrome/browser/ui/browser_window.h" |
| 12 #include "chrome/browser/ui/find_bar/find_bar.h" | 12 #include "chrome/browser/ui/find_bar/find_bar.h" |
| 13 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 13 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
| 14 #include "chrome/browser/ui/panels/native_panel.h" | 14 #include "chrome/browser/ui/panels/native_panel.h" |
| 15 #include "chrome/browser/ui/panels/panel.h" | 15 #include "chrome/browser/ui/panels/panel.h" |
| 16 #include "chrome/browser/ui/panels/panel_manager.h" | 16 #include "chrome/browser/ui/panels/panel_manager.h" |
| 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 18 #include "chrome/browser/web_applications/web_app.h" | 18 #include "chrome/browser/web_applications/web_app.h" |
| 19 #include "chrome/common/chrome_notification_types.h" | 19 #include "chrome/common/chrome_notification_types.h" |
| 20 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
| 21 #include "chrome/common/extensions/extension.h" | 21 #include "chrome/common/extensions/extension.h" |
| 22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 23 #include "chrome/test/base/in_process_browser_test.h" | 23 #include "chrome/test/base/in_process_browser_test.h" |
| 24 #include "chrome/test/base/ui_test_utils.h" | 24 #include "chrome/test/base/ui_test_utils.h" |
| 25 #include "content/browser/download/download_manager.h" | 25 #include "content/browser/download/download_manager.h" |
| 26 #include "content/browser/net/url_request_mock_http_job.h" | 26 #include "content/browser/net/url_request_mock_http_job.h" |
| 27 #include "content/browser/tab_contents/test_tab_contents.h" | 27 #include "content/browser/tab_contents/test_tab_contents.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 29 | 29 |
| 30 using base::PlatformThread; | |
|
jianli
2011/08/23 17:27:12
Why is need needed?
prasadt
2011/08/23 18:05:10
Not needed. I was using it to get the Sleep metho
| |
| 31 | |
| 30 #if defined(OS_MACOSX) | 32 #if defined(OS_MACOSX) |
| 31 #include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" | 33 #include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" |
| 32 #endif | 34 #endif |
| 33 | 35 |
| 34 class PanelBrowserTest : public InProcessBrowserTest { | 36 class PanelBrowserTest : public InProcessBrowserTest { |
| 35 public: | 37 public: |
| 36 PanelBrowserTest() : InProcessBrowserTest() { | 38 PanelBrowserTest() : InProcessBrowserTest() { |
| 37 #if defined(OS_MACOSX) | 39 #if defined(OS_MACOSX) |
| 38 FindBarBridge::disable_animations_during_testing_ = true; | 40 FindBarBridge::disable_animations_during_testing_ = true; |
| 39 #endif | 41 #endif |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 gfx::Rect(0, 0, 500, 200)); | 149 gfx::Rect(0, 0, 500, 200)); |
| 148 signal3.Wait(); | 150 signal3.Wait(); |
| 149 signal4.Wait(); | 151 signal4.Wait(); |
| 150 ASSERT_EQ(2, panel_manager->num_panels()); | 152 ASSERT_EQ(2, panel_manager->num_panels()); |
| 151 EXPECT_LT(panel6->GetBounds().right(), panel1->GetBounds().x()); | 153 EXPECT_LT(panel6->GetBounds().right(), panel1->GetBounds().x()); |
| 152 | 154 |
| 153 panel1->Close(); | 155 panel1->Close(); |
| 154 panel6->Close(); | 156 panel6->Close(); |
| 155 } | 157 } |
| 156 | 158 |
| 157 struct DragTestData { | 159 void SetWorkArea(const gfx::Rect& work_area) { |
| 158 DragTestData(int drag_delta_x, | 160 PanelManager::GetInstance()->SetWorkArea(gfx::Rect(0, 0, 800, 600)); |
| 159 int drag_delta_y, | 161 } |
| 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 | 162 |
| 170 void TestDragging(std::vector<Panel*>* panels, | 163 void RestoreWorkArea() { |
| 171 const DragTestData& drag_test_data) { | 164 PanelManager::GetInstance()->OnDisplayChanged(); |
| 172 size_t num_panels = panels->size(); | 165 } |
| 173 | 166 |
| 174 // Test dragging each panel in the list. | 167 int horizontal_spacing() { |
| 175 for (size_t drag_index = 0; drag_index < num_panels; ++drag_index) { | 168 return PanelManager::horizontal_spacing(); |
| 176 std::vector<int> expected_delta_x_after_drag(num_panels, 0); | 169 } |
| 177 std::vector<int> expected_delta_x_after_finish(num_panels, 0); | |
| 178 | 170 |
| 179 for (size_t j = 0; j < num_panels; ++j) { | 171 void CloseAllPanels() { |
| 180 expected_delta_x_after_drag.push_back(0); | 172 const std::vector<Panel*>& panels = PanelManager::GetInstance()->panels_; |
| 181 expected_delta_x_after_finish.push_back(0); | 173 for (size_t i = 0; i < panels.size(); ++i) |
| 182 } | 174 panels[i]->Close(); |
|
jennb
2011/08/23 17:14:16
Is it safe to modify the vector as you're iteratin
prasadt
2011/08/23 18:05:10
We're not modifying the vector, rather the object
jennb
2011/08/23 18:09:31
Closing a panel could remove the panel from PanelM
prasadt
2011/08/23 18:26:25
Good point. Its probably not closing all the pane
| |
| 175 } | |
| 183 | 176 |
| 184 expected_delta_x_after_drag[drag_index] = drag_test_data.drag_delta_x; | 177 std::vector<gfx::Rect> GetAllPanelsBounds() { |
| 185 size_t swap_index = drag_index; | 178 std::vector<gfx::Rect> panels_bounds; |
| 186 if (drag_test_data.is_big_delta) { | 179 const std::vector<Panel*>& panels = PanelManager::GetInstance()->panels_; |
| 187 if (drag_test_data.drag_delta_x > 0 && drag_index != 0) { | 180 for (size_t i = 0; i < panels.size(); ++i) |
| 188 // Dragged to right. | 181 panels_bounds.push_back(panels[i]->GetRestoredBounds()); |
| 189 swap_index = drag_index - 1; | 182 return panels_bounds; |
| 190 } else if (drag_test_data.drag_delta_x < 0 && | 183 } |
| 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 | 184 |
| 209 if (swap_index != drag_index && !drag_test_data.should_cancel_drag) { | 185 // Helper function for debugging. |
| 210 // Swap the panels in the vector so they reflect their true relative | 186 void PrintPanelBounds() { |
| 211 // positions. | 187 const std::vector<Panel*>& panels = PanelManager::GetInstance()->panels_; |
| 212 Panel* tmp_panel = (*panels)[swap_index]; | 188 DLOG(WARNING) << "PanelBounds:"; |
| 213 (*panels)[swap_index] = (*panels)[drag_index]; | 189 for (size_t i = 0; i < panels.size(); ++i) { |
| 214 (*panels)[drag_index] = tmp_panel; | 190 DLOG(WARNING) << "#=" << i |
| 215 } | 191 << ", ptr=" << panels[i] |
| 192 << ", x=" << panels[i]->GetRestoredBounds().x() | |
| 193 << ", y=" << panels[i]->GetRestoredBounds().y() | |
| 194 << ", width=" << panels[i]->GetRestoredBounds().width() | |
| 195 << ", height" << panels[i]->GetRestoredBounds().height(); | |
| 216 } | 196 } |
| 217 } | 197 } |
| 218 | 198 |
| 219 void ValidateDragging(const std::vector<Panel*>& panels, | 199 // This is a set of flags that controls the specific drag actions to be |
| 220 int index_to_drag, | 200 // carried out by TestDragging function. |
| 221 int delta_x, | 201 enum HandleDrag { |
|
jennb
2011/08/23 17:14:16
Would DragAction be more descriptive?
prasadt
2011/08/23 18:05:10
Sounds good. Done.
| |
| 222 int delta_y, | 202 HANDLE_DRAG_BEGIN = 1, |
| 223 const std::vector<int>& expected_delta_x_after_drag, | 203 HANDLE_DRAG_FINISH = 2, |
| 224 const std::vector<int>& expected_delta_x_after_finish, | 204 HANDLE_DRAG_CANCEL = 4 |
| 225 bool should_cancel_drag) { | 205 }; |
| 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 | 206 |
| 231 // Trigger the mouse-pressed event. | 207 void TestDragging(int delta_x, |
| 232 // All panels should remain in their original positions. | 208 int delta_y, |
| 233 NativePanel* panel_to_drag = panels[index_to_drag]->native_panel(); | 209 size_t drag_index, |
| 210 std::vector<int>expected_delta_x_after_drag, | |
| 211 std::vector<int>expected_delta_x_after_finish, | |
| 212 std::vector<gfx::Rect> initial_bounds, | |
| 213 int handle_drag) { | |
| 214 std::vector<Panel*> panels = PanelManager::GetInstance()->panels_; | |
| 215 | |
| 216 // These are bounds at the beginning of this test. This would be different | |
|
jennb
2011/08/23 17:14:16
I'm still having trouble understanding how initial
prasadt
2011/08/23 18:05:10
Done.
I added an example, hope that helps.
| |
| 217 // from initial_bounds in the case where we're testing for the case of | |
| 218 // multiple drags before finishing the drag. | |
| 219 std::vector<gfx::Rect> test_begin_bounds = GetAllPanelsBounds(); | |
| 220 | |
| 221 NativePanel* panel_to_drag = panels[drag_index]->native_panel(); | |
| 234 scoped_ptr<NativePanelTesting> panel_testing_to_drag( | 222 scoped_ptr<NativePanelTesting> panel_testing_to_drag( |
| 235 NativePanelTesting::Create(panel_to_drag)); | 223 NativePanelTesting::Create(panel_to_drag)); |
| 236 | 224 |
| 237 gfx::Point button_press_point(initial_bounds[index_to_drag].x(), | 225 if (handle_drag & HANDLE_DRAG_BEGIN) { |
|
jennb
2011/08/23 17:14:16
Oh, it's a bitmask. Could you add a comment to the
prasadt
2011/08/23 18:05:10
Done.
There is a comment already that says its a s
| |
| 238 initial_bounds[index_to_drag].y()); | 226 // Trigger the mouse-pressed event. |
| 239 panel_testing_to_drag->PressLeftMouseButtonTitlebar(button_press_point); | 227 // All panels should remain in their original positions. |
| 240 for (size_t i = 0; i < panels.size(); ++i) | 228 gfx::Point button_press_point( |
| 241 EXPECT_EQ(initial_bounds[i], panels[i]->GetRestoredBounds()); | 229 panels[drag_index]->GetRestoredBounds().x(), |
| 230 panels[drag_index]->GetRestoredBounds().y()); | |
| 231 panel_testing_to_drag->PressLeftMouseButtonTitlebar(button_press_point); | |
| 232 for (size_t i = 0; i < panels.size(); ++i) | |
| 233 EXPECT_EQ(test_begin_bounds[i], panels[i]->GetRestoredBounds()); | |
| 234 } | |
| 242 | 235 |
| 243 // Trigger the drag. | 236 // Trigger the drag. |
| 237 // Compare against expected bounds. | |
| 244 panel_testing_to_drag->DragTitlebar(delta_x, delta_y); | 238 panel_testing_to_drag->DragTitlebar(delta_x, delta_y); |
| 245 | |
| 246 for (size_t i = 0; i < panels.size(); ++i) { | 239 for (size_t i = 0; i < panels.size(); ++i) { |
| 247 gfx::Rect expected_bounds = initial_bounds[i]; | 240 gfx::Rect expected_bounds = test_begin_bounds[i]; |
| 248 expected_bounds.Offset(expected_delta_x_after_drag[i], 0); | 241 expected_bounds.Offset(expected_delta_x_after_drag[i], 0); |
| 249 EXPECT_EQ(expected_bounds, panels[i]->GetRestoredBounds()); | 242 EXPECT_EQ(expected_bounds, panels[i]->GetRestoredBounds()); |
| 250 } | 243 } |
| 251 | 244 |
| 252 // Cancel drag if asked. | 245 if (handle_drag & HANDLE_DRAG_CANCEL) { |
| 253 // All panels should stay in their original positions. | 246 // Cancel the drag. |
| 254 if (should_cancel_drag) { | 247 // All panels should return to their initial positions. |
| 255 panel_testing_to_drag->CancelDragTitlebar(); | 248 panel_testing_to_drag->CancelDragTitlebar(); |
| 249 std::vector<gfx::Rect> current_bounds = GetAllPanelsBounds(); | |
| 256 for (size_t i = 0; i < panels.size(); ++i) | 250 for (size_t i = 0; i < panels.size(); ++i) |
| 257 EXPECT_EQ(initial_bounds[i], panels[i]->GetRestoredBounds()); | 251 EXPECT_EQ(initial_bounds[i], current_bounds[i]); |
| 258 return; | 252 } else if (handle_drag & HANDLE_DRAG_FINISH) { |
| 259 } | 253 // Finish the drag. |
| 260 | 254 // Compare against expected bounds. |
| 261 // Otherwise finish the drag. | 255 panel_testing_to_drag->FinishDragTitlebar(); |
| 262 panel_testing_to_drag->FinishDragTitlebar(); | 256 for (size_t i = 0; i < panels.size(); ++i) { |
| 263 for (size_t i = 0; i < panels.size(); ++i) { | 257 gfx::Rect expected_bounds = test_begin_bounds[i]; |
| 264 gfx::Rect expected_bounds = initial_bounds[i]; | 258 expected_bounds.Offset(expected_delta_x_after_finish[i], 0); |
| 265 expected_bounds.Offset(expected_delta_x_after_finish[i], 0); | 259 EXPECT_EQ(expected_bounds, panels[i]->GetRestoredBounds()); |
| 266 EXPECT_EQ(expected_bounds, panels[i]->GetRestoredBounds()); | 260 } |
| 267 } | 261 } |
| 268 } | 262 } |
| 269 }; | 263 }; |
| 270 | 264 |
| 271 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreatePanel) { | 265 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreatePanel) { |
| 272 PanelManager* panel_manager = PanelManager::GetInstance(); | 266 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 273 EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially. | 267 EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially. |
| 274 | 268 |
| 275 Panel* panel = CreatePanel("PanelTest", gfx::Rect()); | 269 Panel* panel = CreatePanel("PanelTest", gfx::Rect()); |
| 276 EXPECT_EQ(1, panel_manager->num_panels()); | 270 EXPECT_EQ(1, panel_manager->num_panels()); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 304 TestCreatePanelOnOverflow(); | 298 TestCreatePanelOnOverflow(); |
| 305 } | 299 } |
| 306 | 300 |
| 307 #if defined(TOOLKIT_GTK) || defined(OS_WIN) | 301 #if defined(TOOLKIT_GTK) || defined(OS_WIN) |
| 308 #define MAYBE_DragPanels DragPanels | 302 #define MAYBE_DragPanels DragPanels |
| 309 #else | 303 #else |
| 310 #define MAYBE_DragPanels DISABLED_DragPanels | 304 #define MAYBE_DragPanels DISABLED_DragPanels |
| 311 #endif | 305 #endif |
| 312 | 306 |
| 313 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_DragPanels) { | 307 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_DragPanels) { |
| 314 std::vector<Panel*> panels; | 308 // Set work area to make the test consistent on different monitor sizes. |
| 315 panels.push_back(CreatePanel("PanelTest0", gfx::Rect())); | 309 SetWorkArea(gfx::Rect(0, 0, 800, 600)); |
| 316 | 310 |
| 317 int small_delta = 5; | 311 int max_panels = 4; |
|
jianli
2011/08/23 17:27:12
You can add "static const" for this variable.
prasadt
2011/08/23 18:05:10
Done. Also changed the value to 3.
| |
| 318 int big_delta = panels[0]->GetRestoredBounds().width() * 0.5 + 5; | 312 int small_delta = 10; |
| 319 | 313 int big_delta = 60; |
| 320 // Setup test data. | 314 std::vector<int> zero_delta(max_panels, 0); |
| 321 // Template - DragTestData(delta_x, delta_y, is_big_delta, should_cancel_drag) | 315 std::vector<int> expected_delta_x_after_drag(max_panels, 0); |
| 322 std::vector<DragTestData> drag_test_data; | 316 std::vector<int> expected_delta_x_after_finish(max_panels, 0); |
| 323 drag_test_data.push_back(DragTestData( | 317 |
| 324 small_delta, small_delta, false, false)); | 318 // **** Tests with a single panel. |
|
jennb
2011/08/23 17:14:16
Not a big fan of extra **** or ==== in the comment
prasadt
2011/08/23 18:05:10
Sure. They make sense here though.
jennb
2011/08/23 18:09:31
What about subroutines then for testing one panel,
prasadt
2011/08/23 18:26:25
I don't see a net win. The variable declarations
prasadt
2011/08/23 20:15:10
Removed the special markers and replaced with scop
| |
| 325 drag_test_data.push_back(DragTestData( | 319 CreatePanel("PanelTest1", gfx::Rect(0, 0, 100, 100)); |
| 326 -small_delta, -small_delta, false, false)); | 320 |
| 327 drag_test_data.push_back(DragTestData(big_delta, big_delta, true, false)); | 321 // ==== Drag left. |
| 328 drag_test_data.push_back(DragTestData(big_delta, small_delta, true, false)); | 322 expected_delta_x_after_drag[0] = -big_delta; |
| 329 drag_test_data.push_back(DragTestData(-big_delta, -big_delta, true, false)); | 323 expected_delta_x_after_finish = zero_delta; |
| 330 drag_test_data.push_back(DragTestData(-big_delta, 0, true, false)); | 324 TestDragging(-big_delta, 0, 0, expected_delta_x_after_drag, |
| 331 drag_test_data.push_back(DragTestData(big_delta, big_delta, true, true)); | 325 zero_delta, GetAllPanelsBounds(), |
| 332 drag_test_data.push_back(DragTestData(-big_delta, -big_delta, true, true)); | 326 HANDLE_DRAG_BEGIN | HANDLE_DRAG_FINISH); |
| 333 | 327 |
| 334 for (int num_panels = 1; num_panels <= 3; ++num_panels) { | 328 // ==== Drag left and cancel. |
| 335 if (num_panels > 1) | 329 expected_delta_x_after_drag[0] = -big_delta; |
| 336 panels.push_back(CreatePanel("PanelTest", gfx::Rect())); | 330 expected_delta_x_after_finish = zero_delta; |
| 337 for (size_t j = 0; j < drag_test_data.size(); ++j) { | 331 TestDragging(-big_delta, 0, 0, expected_delta_x_after_drag, |
| 338 // Test for each combination of drag test data and number of panels. | 332 zero_delta, GetAllPanelsBounds(), |
| 339 TestDragging(&panels, drag_test_data[j]); | 333 HANDLE_DRAG_BEGIN | HANDLE_DRAG_CANCEL); |
| 340 } | 334 |
| 341 } | 335 // ==== Drag right. |
| 342 | 336 expected_delta_x_after_drag[0] = big_delta; |
| 343 for (size_t i = 0; i < panels.size(); ++i) | 337 TestDragging(big_delta, 0, 0, expected_delta_x_after_drag, |
| 344 panels[i]->Close(); | 338 zero_delta, GetAllPanelsBounds(), |
| 339 HANDLE_DRAG_BEGIN | HANDLE_DRAG_FINISH); | |
| 340 | |
| 341 // ==== Drag right and up. Expect no vertical movement. | |
| 342 TestDragging(big_delta, big_delta, 0, expected_delta_x_after_drag, | |
| 343 zero_delta, GetAllPanelsBounds(), | |
| 344 HANDLE_DRAG_BEGIN | HANDLE_DRAG_FINISH); | |
| 345 | |
| 346 // ==== Drag up. Expect no movement on drag. | |
| 347 TestDragging(0, -big_delta, 0, zero_delta, zero_delta, | |
| 348 GetAllPanelsBounds(), HANDLE_DRAG_BEGIN | HANDLE_DRAG_FINISH); | |
| 349 | |
| 350 // ==== Drag down. Expect no movement on drag. | |
| 351 TestDragging(0, big_delta, 0, zero_delta, zero_delta, | |
| 352 GetAllPanelsBounds(), HANDLE_DRAG_BEGIN | HANDLE_DRAG_FINISH); | |
| 353 | |
| 354 // **** Tests with two panels. | |
| 355 CreatePanel("PanelTest2", gfx::Rect(0, 0, 90, 90)); | |
|
jianli
2011/08/23 17:27:12
For now, do not create the panel with size smaller
prasadt
2011/08/23 18:05:10
Done. Made it bigger.
You're such a savior Jian!
| |
| 356 | |
| 357 // ==== Drag left, small delta, expect no shuffle. | |
| 358 expected_delta_x_after_drag = zero_delta; | |
| 359 expected_delta_x_after_drag[0] = -small_delta; | |
| 360 TestDragging(-small_delta, 1, 0, expected_delta_x_after_drag, zero_delta, | |
| 361 GetAllPanelsBounds(), HANDLE_DRAG_BEGIN | HANDLE_DRAG_FINISH); | |
| 362 | |
| 363 // Drag right panel i.e index 0, towards left, big delta, expect shuffle. | |
| 364 std::vector<gfx::Rect> initial_bounds = GetAllPanelsBounds(); | |
| 365 expected_delta_x_after_drag = zero_delta; | |
| 366 | |
| 367 // Deltas for panel being dragged. | |
| 368 expected_delta_x_after_drag[0] = -big_delta; | |
| 369 expected_delta_x_after_finish[0] = | |
| 370 -(initial_bounds[1].width() + horizontal_spacing()); | |
| 371 | |
| 372 // Deltas for panel being shuffled. | |
| 373 expected_delta_x_after_drag[1] = | |
| 374 initial_bounds[0].width() + horizontal_spacing(); | |
| 375 expected_delta_x_after_finish[1] = expected_delta_x_after_drag[1]; | |
| 376 | |
| 377 TestDragging(-big_delta, 0, 0, expected_delta_x_after_drag, | |
| 378 expected_delta_x_after_finish, initial_bounds, | |
| 379 HANDLE_DRAG_BEGIN | HANDLE_DRAG_FINISH); | |
| 380 | |
| 381 // ==== Drag left panel i.e index 1, towards right, big delta, expect shuffle. | |
| 382 initial_bounds = GetAllPanelsBounds(); | |
| 383 expected_delta_x_after_drag = zero_delta; | |
| 384 expected_delta_x_after_finish = zero_delta; | |
| 385 | |
| 386 // Deltas for panel being dragged. | |
| 387 expected_delta_x_after_drag[1] = big_delta; | |
| 388 expected_delta_x_after_finish[1] = | |
| 389 initial_bounds[0].width() + horizontal_spacing(); | |
| 390 | |
| 391 // Deltas for panel being shuffled. | |
| 392 expected_delta_x_after_drag[0] = | |
| 393 -(initial_bounds[1].width() + horizontal_spacing()); | |
| 394 expected_delta_x_after_finish[0] = expected_delta_x_after_drag[0]; | |
| 395 | |
| 396 TestDragging(big_delta, 0, 1, expected_delta_x_after_drag, | |
| 397 expected_delta_x_after_finish, initial_bounds, | |
| 398 HANDLE_DRAG_BEGIN | HANDLE_DRAG_FINISH); | |
| 399 | |
| 400 // ==== Drag left panel i.e index 1, towards right, big delta, expect shuffle. | |
| 401 // Cancel drag. | |
| 402 initial_bounds = GetAllPanelsBounds(); | |
| 403 expected_delta_x_after_drag = zero_delta; | |
| 404 | |
| 405 // Delta for panel being dragged. | |
| 406 expected_delta_x_after_drag[1] = big_delta; | |
| 407 | |
| 408 // Delta for panel being shuffled. | |
| 409 expected_delta_x_after_drag[0] = | |
| 410 -(initial_bounds[1].width() + horizontal_spacing()); | |
| 411 | |
| 412 // As the drag is being canceled, we don't need expected_delta_x_after_finish. | |
| 413 // Instead initial_bounds will be used. | |
| 414 TestDragging(big_delta, 0, 1, expected_delta_x_after_drag, | |
| 415 zero_delta, initial_bounds, | |
| 416 HANDLE_DRAG_BEGIN | HANDLE_DRAG_CANCEL); | |
| 417 | |
| 418 // **** Tests with three panels. | |
| 419 CreatePanel("PanelTest2", gfx::Rect(0, 0, 110, 110)); | |
|
jennb
2011/08/23 17:14:16
PanelTest3
prasadt
2011/08/23 18:05:10
Done.
| |
| 420 | |
| 421 // #### Drag left most panel to become right most with two shuffles. | |
| 422 // We test both shuffles. | |
| 423 | |
| 424 // ==== First drag and shuffle. | |
| 425 initial_bounds = GetAllPanelsBounds(); | |
| 426 expected_delta_x_after_drag = zero_delta; | |
| 427 | |
| 428 // Delta for panel being dragged. | |
| 429 expected_delta_x_after_drag[2] = big_delta; | |
| 430 | |
| 431 // Delta for panel being shuffled. | |
| 432 expected_delta_x_after_drag[1] = | |
| 433 -(initial_bounds[2].width() + horizontal_spacing()); | |
| 434 | |
| 435 // There is no delta after finish as drag is done yet. | |
| 436 TestDragging(big_delta, 0, 2, expected_delta_x_after_drag, | |
| 437 zero_delta, initial_bounds, HANDLE_DRAG_BEGIN); | |
| 438 | |
| 439 // ==== Second drag and shuffle. We finish the drag here. The drag index | |
| 440 // changes from 2 to 1 because of the first shuffle above. | |
| 441 std::vector<gfx::Rect> current_bounds = GetAllPanelsBounds(); | |
| 442 expected_delta_x_after_drag = zero_delta; | |
| 443 expected_delta_x_after_finish = zero_delta; | |
| 444 | |
| 445 // big_delta is not enough to cause the second shuffle as the panel being | |
| 446 // dragged is in the middle of a drag and big_delta won't go far enough. | |
| 447 int bigger_delta = 100; | |
| 448 | |
| 449 // Deltas for panel being dragged. | |
| 450 expected_delta_x_after_drag[1] = bigger_delta; | |
| 451 int x_after_finish = current_bounds[0].x() + | |
| 452 (current_bounds[0].width() - current_bounds[1].width()); | |
| 453 expected_delta_x_after_finish[1] = x_after_finish - current_bounds[1].x(); | |
| 454 | |
| 455 // Deltas for panel being shuffled. | |
| 456 expected_delta_x_after_drag[0] = | |
| 457 -(current_bounds[1].width() + horizontal_spacing()); | |
| 458 expected_delta_x_after_finish[0] = expected_delta_x_after_drag[0]; | |
| 459 | |
| 460 TestDragging(bigger_delta, 0, 1, expected_delta_x_after_drag, | |
| 461 expected_delta_x_after_finish, initial_bounds, | |
| 462 HANDLE_DRAG_FINISH); | |
| 463 | |
| 464 // #### Drag right most panel to become left most with two shuffles. | |
| 465 // And then cancel the drag. | |
| 466 | |
| 467 // ==== First drag and shuffle. | |
| 468 initial_bounds = GetAllPanelsBounds(); | |
| 469 expected_delta_x_after_drag = zero_delta; | |
| 470 | |
| 471 // Delta for panel being dragged. | |
| 472 expected_delta_x_after_drag[0] = -big_delta; | |
| 473 | |
| 474 // Delta for panel being shuffled. | |
| 475 expected_delta_x_after_drag[1] = | |
| 476 (initial_bounds[0].width() + horizontal_spacing()); | |
| 477 | |
| 478 // There is no delta after finish as drag is done yet. | |
| 479 TestDragging(-big_delta, 0, 0, expected_delta_x_after_drag, | |
| 480 zero_delta, initial_bounds, HANDLE_DRAG_BEGIN); | |
| 481 | |
| 482 // ==== Second drag and shuffle. We cancel the drag here. The drag index | |
| 483 // changes from 0 to 1 because of the first shuffle above. | |
| 484 current_bounds = GetAllPanelsBounds(); | |
| 485 expected_delta_x_after_drag = zero_delta; | |
| 486 | |
| 487 // Delta for panel being dragged. | |
| 488 expected_delta_x_after_drag[1] = -bigger_delta; | |
| 489 | |
| 490 // Deltas for panel being shuffled. | |
| 491 int x_after_shuffle = | |
| 492 current_bounds[0].x() - horizontal_spacing() - current_bounds[2].width(); | |
| 493 expected_delta_x_after_drag[2] = x_after_shuffle - current_bounds[2].x(); | |
| 494 | |
| 495 // There is no delta after finish as drag canceled. | |
| 496 TestDragging(-bigger_delta, 0, 1, expected_delta_x_after_drag, | |
| 497 zero_delta, initial_bounds, HANDLE_DRAG_CANCEL); | |
| 498 | |
| 499 // ==== Drag left most panel to become the right most in a single drag. This | |
| 500 // will shuffle middle panel to left most and right most to middle. | |
| 501 initial_bounds = GetAllPanelsBounds(); | |
| 502 expected_delta_x_after_drag = zero_delta; | |
| 503 expected_delta_x_after_finish = zero_delta; | |
| 504 int biggest_delta = 200; | |
| 505 | |
| 506 // Deltas for panel being dragged. | |
| 507 expected_delta_x_after_drag[2] = biggest_delta; | |
| 508 expected_delta_x_after_finish[2] = | |
| 509 initial_bounds[1].width() + horizontal_spacing() + | |
| 510 initial_bounds[0].width() + horizontal_spacing(); | |
| 511 | |
| 512 // Deltas for middle panels being shuffled. | |
| 513 expected_delta_x_after_drag[1] = | |
| 514 -(initial_bounds[2].width() + horizontal_spacing()); | |
| 515 expected_delta_x_after_finish[1] = expected_delta_x_after_drag[1]; | |
| 516 | |
| 517 expected_delta_x_after_drag[0] = expected_delta_x_after_drag[1]; | |
| 518 expected_delta_x_after_finish[0] = expected_delta_x_after_drag[0]; | |
| 519 | |
| 520 TestDragging(biggest_delta, 0, 2, expected_delta_x_after_drag, | |
| 521 expected_delta_x_after_finish, initial_bounds, | |
| 522 HANDLE_DRAG_BEGIN | HANDLE_DRAG_FINISH); | |
| 523 | |
| 524 // ==== Drag right most panel to become the left most in a single drag. This | |
| 525 // will shuffle middle panel to right most and left most to middle. | |
| 526 initial_bounds = GetAllPanelsBounds(); | |
| 527 expected_delta_x_after_drag = zero_delta; | |
| 528 expected_delta_x_after_finish = zero_delta; | |
| 529 | |
| 530 // Deltas for panel being dragged. | |
| 531 expected_delta_x_after_drag[0] = -biggest_delta; | |
| 532 expected_delta_x_after_finish[0] = | |
| 533 -(initial_bounds[1].width() + horizontal_spacing() + | |
| 534 initial_bounds[2].width() + horizontal_spacing()); | |
| 535 | |
| 536 // Deltas for panels being shuffled. | |
| 537 expected_delta_x_after_drag[1] = | |
| 538 initial_bounds[0].width() + horizontal_spacing(); | |
| 539 expected_delta_x_after_finish[1] = expected_delta_x_after_drag[1]; | |
| 540 | |
| 541 expected_delta_x_after_drag[2] = expected_delta_x_after_drag[1]; | |
| 542 expected_delta_x_after_finish[2] = expected_delta_x_after_drag[2]; | |
| 543 | |
| 544 TestDragging(-biggest_delta, 0, 0, expected_delta_x_after_drag, | |
| 545 expected_delta_x_after_finish, initial_bounds, | |
| 546 HANDLE_DRAG_BEGIN | HANDLE_DRAG_FINISH); | |
| 547 | |
| 548 // ==== Drag right most panel to become the left most in a single drag. Then | |
| 549 // cancel the drag. | |
| 550 initial_bounds = GetAllPanelsBounds(); | |
| 551 expected_delta_x_after_drag = zero_delta; | |
| 552 | |
| 553 // Deltas for panel being dragged. | |
| 554 expected_delta_x_after_drag[0] = -biggest_delta; | |
| 555 | |
| 556 // Deltas for panels being shuffled. | |
| 557 expected_delta_x_after_drag[1] = | |
| 558 initial_bounds[0].width() + horizontal_spacing(); | |
| 559 expected_delta_x_after_drag[2] = expected_delta_x_after_drag[1]; | |
| 560 | |
| 561 // No delta after finish as drag is canceled. | |
| 562 TestDragging(-biggest_delta, 0, 0, expected_delta_x_after_drag, | |
| 563 zero_delta, initial_bounds, | |
| 564 HANDLE_DRAG_BEGIN | HANDLE_DRAG_CANCEL); | |
| 565 | |
| 566 // Close panels and restore work area. | |
| 567 CloseAllPanels(); | |
| 568 RestoreWorkArea(); | |
|
jianli
2011/08/23 17:27:12
No need to restore work area.
prasadt
2011/08/23 18:05:10
Done.
| |
| 345 } | 569 } |
| 346 | 570 |
| 347 class PanelDownloadTest : public PanelBrowserTest { | 571 class PanelDownloadTest : public PanelBrowserTest { |
| 348 public: | 572 public: |
| 349 PanelDownloadTest() : PanelBrowserTest() { } | 573 PanelDownloadTest() : PanelBrowserTest() { } |
| 350 | 574 |
| 351 // Creates a temporary directory for downloads that is auto-deleted | 575 // Creates a temporary directory for downloads that is auto-deleted |
| 352 // on destruction. | 576 // on destruction. |
| 353 bool CreateDownloadDirectory(Profile* profile) { | 577 bool CreateDownloadDirectory(Profile* profile) { |
| 354 bool created = downloads_directory_.CreateUniqueTempDir(); | 578 bool created = downloads_directory_.CreateUniqueTempDir(); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 501 EXPECT_EQ(1, tabbed_browser->tab_count()); | 725 EXPECT_EQ(1, tabbed_browser->tab_count()); |
| 502 ASSERT_TRUE(tabbed_browser->window()->IsDownloadShelfVisible()); | 726 ASSERT_TRUE(tabbed_browser->window()->IsDownloadShelfVisible()); |
| 503 tabbed_browser->CloseWindow(); | 727 tabbed_browser->CloseWindow(); |
| 504 #endif | 728 #endif |
| 505 | 729 |
| 506 EXPECT_EQ(1, panel_browser->tab_count()); | 730 EXPECT_EQ(1, panel_browser->tab_count()); |
| 507 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible()); | 731 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible()); |
| 508 | 732 |
| 509 panel_browser->CloseWindow(); | 733 panel_browser->CloseWindow(); |
| 510 } | 734 } |
| OLD | NEW |