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 is_cancel_drag) | |
162 : drag_delta_x_(drag_delta_x), drag_delta_y_(drag_delta_y), | |
163 is_big_delta_(is_big_delta), is_cancel_drag_(is_cancel_drag) {} | |
164 int drag_delta_x_; | |
jianli
2011/08/11 01:22:54
For struct members, we do not end with "_".
prasadt
2011/08/11 18:11:11
Done.
| |
165 int drag_delta_y_; | |
166 bool is_big_delta_; // Drag big enough to cause shuffling. | |
jianli
2011/08/11 01:22:54
Can we get rid of is_big_delta? I think we can get
prasadt
2011/08/11 18:11:11
I like being explicit about this at the outset. L
| |
167 bool is_cancel_drag_; | |
168 }; | |
169 | |
170 void TestDragging(std::vector<Panel*>& panels, | |
jianli
2011/08/11 01:22:54
We do not like to pass by reference.
prasadt
2011/08/11 18:11:11
Done.
| |
171 const struct DragTestData& drag_test_data) { | |
jianli
2011/08/11 01:22:54
struct is not needed.
prasadt
2011/08/11 18:11:11
Done.
| |
172 // Test dragging each panel in the list. | |
173 for (size_t drag_index = 0; drag_index < panels.size(); drag_index++) { | |
jianli
2011/08/11 01:22:54
We prefer to use ++drag_index with the iterator.
prasadt
2011/08/11 18:11:11
Done.
| |
174 std::vector<int> expected_delta_x_after_drag; | |
175 std::vector<int> expected_delta_x_after_finish; | |
176 | |
177 for (size_t j = 0; j < panels.size(); j++) { | |
178 expected_delta_x_after_drag.push_back(0); | |
179 expected_delta_x_after_finish.push_back(0); | |
180 } | |
181 | |
182 expected_delta_x_after_drag[drag_index] = drag_test_data.drag_delta_x_; | |
183 size_t swap_index = drag_index; | |
184 if (drag_test_data.is_big_delta_) { | |
185 if (drag_test_data.drag_delta_x_ > 0 && drag_index != 0) { | |
186 // Dragged to right. | |
187 swap_index = drag_index - 1; | |
188 } else if (drag_test_data.drag_delta_x_ < 0 && | |
189 drag_index != panels.size() - 1) { | |
190 // Dragged to left. | |
191 swap_index = drag_index + 1; | |
192 } | |
193 } | |
194 if (swap_index != drag_index) { | |
195 expected_delta_x_after_drag[swap_index] = | |
196 panels[drag_index]->GetRestoredBounds().x() - | |
197 panels[swap_index]->GetRestoredBounds().x(); | |
198 expected_delta_x_after_finish[swap_index] = | |
199 expected_delta_x_after_drag[swap_index]; | |
200 expected_delta_x_after_finish[drag_index] = | |
201 -expected_delta_x_after_drag[swap_index]; | |
202 } | |
203 ValidateDragging(panels, drag_index, drag_test_data.drag_delta_x_, | |
204 drag_test_data.drag_delta_y_, expected_delta_x_after_drag, | |
205 expected_delta_x_after_finish, drag_test_data.is_cancel_drag_); | |
206 | |
207 if (swap_index != drag_index && !drag_test_data.is_cancel_drag_) { | |
208 // Swap the panels in the vector so they reflect their true relative | |
209 // positions. | |
210 Panel* tmp_panel = panels[swap_index]; | |
211 panels[swap_index] = panels[drag_index]; | |
212 panels[drag_index] = tmp_panel; | |
213 } | |
214 } | |
215 } | |
216 | |
217 void ValidateDragging(const std::vector<Panel*>& panels, | |
218 int index_to_drag, | |
219 int delta_x, | |
220 int delta_y, | |
221 const std::vector<int>& expected_delta_x_after_drag, | |
222 const std::vector<int>& expected_delta_x_after_finish, | |
223 bool is_cancel_drag) { | |
jianli
2011/08/11 01:22:54
is_cancel_drag => should_cancel_drag
prasadt
2011/08/11 18:11:11
Done.
| |
224 // Keep track of the initial bounds for comparison. | |
225 std::vector<gfx::Rect> initial_bounds(panels.size()); | |
226 for (size_t i = 0; i < panels.size(); i++) | |
jianli
2011/08/11 01:22:54
ditto.
prasadt
2011/08/11 18:11:11
Done.
| |
227 initial_bounds[i] = panels[i]->GetRestoredBounds(); | |
228 | |
229 // Trigger the mouse-pressed event. | |
230 // All panels should remain in their original positions. | |
231 NativePanel* panel_to_drag = panels[index_to_drag]->native_panel(); | |
232 NativePanelTesting* panel_to_drag_testing = | |
jianli
2011/08/11 01:22:54
Memory leak here. Also, the name panel_to_drag_tes
prasadt
2011/08/11 18:11:11
Done.
| |
233 NativePanelTesting::Create(panel_to_drag); | |
234 gfx::Point button_press_point(initial_bounds[index_to_drag].x(), | |
235 initial_bounds[index_to_drag].y()); | |
236 panel_to_drag_testing->PressLeftMouseButtonTitlebar(button_press_point); | |
237 for (size_t i = 0; i < panels.size(); i++) | |
238 EXPECT_EQ(initial_bounds[i], panels[i]->GetRestoredBounds()); | |
239 | |
240 if (delta_x || delta_y) { | |
jianli
2011/08/11 01:22:54
Please add a comment:
// Trigger the drag.
prasadt
2011/08/11 18:11:11
Done.
| |
241 panel_to_drag_testing->DragTitlebar(delta_x, delta_y); | |
242 | |
243 for (size_t i = 0; i < panels.size(); i++) { | |
244 gfx::Rect expected_bounds = initial_bounds[i]; | |
245 expected_bounds.Offset(expected_delta_x_after_drag[i], 0); | |
246 EXPECT_EQ(expected_bounds, panels[i]->GetRestoredBounds()); | |
247 } | |
248 } | |
249 | |
250 // Cancel the dragging if asked. | |
251 // All panels should stay in their original positions. | |
252 if (is_cancel_drag) { | |
253 panel_to_drag_testing->CancelDragTitlebar(); | |
254 for (size_t i = 0; i < panels.size(); i++) | |
255 EXPECT_EQ(initial_bounds[i], panels[i]->GetRestoredBounds()); | |
256 return; | |
257 } | |
258 | |
259 // Otherwise finish the drag. | |
260 panel_to_drag_testing->FinishDragTitlebar(); | |
261 for (size_t i = 0; i < panels.size(); i++) { | |
262 gfx::Rect expected_bounds = initial_bounds[i]; | |
263 expected_bounds.Offset(expected_delta_x_after_finish[i], 0); | |
264 EXPECT_EQ(expected_bounds, panels[i]->GetRestoredBounds()); | |
265 } | |
266 } | |
153 }; | 267 }; |
154 | 268 |
155 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreatePanel) { | 269 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreatePanel) { |
156 PanelManager* panel_manager = PanelManager::GetInstance(); | 270 PanelManager* panel_manager = PanelManager::GetInstance(); |
157 EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially. | 271 EXPECT_EQ(0, panel_manager->num_panels()); // No panels initially. |
158 | 272 |
159 Panel* panel = CreatePanel("PanelTest", gfx::Rect()); | 273 Panel* panel = CreatePanel("PanelTest", gfx::Rect()); |
160 EXPECT_EQ(1, panel_manager->num_panels()); | 274 EXPECT_EQ(1, panel_manager->num_panels()); |
161 | 275 |
162 gfx::Rect bounds = panel->GetBounds(); | 276 gfx::Rect bounds = panel->GetBounds(); |
(...skipping 18 matching lines...) Expand all Loading... | |
181 #ifdef OS_MACOSX | 295 #ifdef OS_MACOSX |
182 #define MAYBE_CreatePanelOnOverflow DISABLED_CreatePanelOnOverflow | 296 #define MAYBE_CreatePanelOnOverflow DISABLED_CreatePanelOnOverflow |
183 #else | 297 #else |
184 #define MAYBE_CreatePanelOnOverflow CreatePanelOnOverflow | 298 #define MAYBE_CreatePanelOnOverflow CreatePanelOnOverflow |
185 #endif | 299 #endif |
186 | 300 |
187 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_CreatePanelOnOverflow) { | 301 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_CreatePanelOnOverflow) { |
188 TestCreatePanelOnOverflow(); | 302 TestCreatePanelOnOverflow(); |
189 } | 303 } |
190 | 304 |
305 #ifdef OS_MACOSX | |
306 #define MAYBE_DragPanels DISABLED_DragPanels | |
307 #else | |
308 #define MAYBE_DragPanels DragPanels | |
309 #endif | |
310 | |
311 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_DragPanels) { | |
312 std::vector<Panel*> panels; | |
313 panels.push_back(CreatePanel("PanelTest0", gfx::Rect())); | |
jianli
2011/08/11 01:22:54
The creation of 1st panel can be moved into for lo
prasadt
2011/08/11 18:11:11
I would rather just use the default size than to t
jianli
2011/08/11 20:52:09
It would be better to pass fixed size to CreatePan
prasadt
2011/08/11 21:07:56
Will look at doing this in my next patch.
| |
314 | |
315 int small_delta = 5; | |
316 int big_delta = panels[0]->GetRestoredBounds().width() * 0.5 + 5; | |
317 | |
318 // Setup test data. | |
319 // Template - DragTestData(delta_x, delta_y, is_big_delta, is_cancel_drag) | |
320 std::vector<DragTestData> drag_test_data; | |
321 drag_test_data.push_back(DragTestData( | |
322 small_delta, small_delta, false, false)); | |
323 drag_test_data.push_back(DragTestData( | |
324 -small_delta, -small_delta, false, false)); | |
325 drag_test_data.push_back(DragTestData(big_delta, big_delta, true, false)); | |
326 drag_test_data.push_back(DragTestData(big_delta, small_delta, true, false)); | |
327 drag_test_data.push_back(DragTestData(-big_delta, -big_delta, true, false)); | |
328 drag_test_data.push_back(DragTestData(-big_delta, 0, true, false)); | |
329 drag_test_data.push_back(DragTestData(big_delta, big_delta, true, true)); | |
330 drag_test_data.push_back(DragTestData(-big_delta, -big_delta, true, true)); | |
331 | |
332 for (int num_panels = 1; num_panels <= 3; num_panels++) { | |
333 if (num_panels > 1) | |
334 panels.push_back(CreatePanel("PanelTest", gfx::Rect())); | |
335 for (size_t j = 0; j < drag_test_data.size(); j++) { | |
336 // Test for each combination of drag test data and number of panels. | |
337 TestDragging(panels, drag_test_data[j]); | |
338 } | |
339 } | |
340 | |
341 for (size_t i = 0; i < panels.size(); i++) | |
342 panels[i]->Close(); | |
343 } | |
344 | |
191 class PanelDownloadTest : public PanelBrowserTest { | 345 class PanelDownloadTest : public PanelBrowserTest { |
192 public: | 346 public: |
193 PanelDownloadTest() : PanelBrowserTest() { } | 347 PanelDownloadTest() : PanelBrowserTest() { } |
194 | 348 |
195 // Creates a temporary directory for downloads that is auto-deleted | 349 // Creates a temporary directory for downloads that is auto-deleted |
196 // on destruction. | 350 // on destruction. |
197 bool CreateDownloadDirectory(Profile* profile) { | 351 bool CreateDownloadDirectory(Profile* profile) { |
198 bool created = downloads_directory_.CreateUniqueTempDir(); | 352 bool created = downloads_directory_.CreateUniqueTempDir(); |
199 if (!created) | 353 if (!created) |
200 return false; | 354 return false; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
345 EXPECT_EQ(1, tabbed_browser->tab_count()); | 499 EXPECT_EQ(1, tabbed_browser->tab_count()); |
346 ASSERT_TRUE(tabbed_browser->window()->IsDownloadShelfVisible()); | 500 ASSERT_TRUE(tabbed_browser->window()->IsDownloadShelfVisible()); |
347 tabbed_browser->CloseWindow(); | 501 tabbed_browser->CloseWindow(); |
348 #endif | 502 #endif |
349 | 503 |
350 EXPECT_EQ(1, panel_browser->tab_count()); | 504 EXPECT_EQ(1, panel_browser->tab_count()); |
351 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible()); | 505 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible()); |
352 | 506 |
353 panel_browser->CloseWindow(); | 507 panel_browser->CloseWindow(); |
354 } | 508 } |
OLD | NEW |