Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(860)

Side by Side Diff: chrome/browser/ui/panels/panel_drag_browsertest.cc

Issue 12764018: Improve panel related tests to make them more reliable (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Patch Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/panels/panel_collection.h ('k') | chrome/browser/ui/panels/panel_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/message_loop.h" 5 #include "base/message_loop.h"
6 #include "chrome/browser/ui/panels/base_panel_browser_test.h" 6 #include "chrome/browser/ui/panels/base_panel_browser_test.h"
7 #include "chrome/browser/ui/panels/detached_panel_collection.h" 7 #include "chrome/browser/ui/panels/detached_panel_collection.h"
8 #include "chrome/browser/ui/panels/docked_panel_collection.h" 8 #include "chrome/browser/ui/panels/docked_panel_collection.h"
9 #include "chrome/browser/ui/panels/native_panel.h" 9 #include "chrome/browser/ui/panels/native_panel.h"
10 #include "chrome/browser/ui/panels/panel.h" 10 #include "chrome/browser/ui/panels/panel.h"
11 #include "chrome/browser/ui/panels/panel_drag_controller.h" 11 #include "chrome/browser/ui/panels/panel_drag_controller.h"
12 #include "chrome/browser/ui/panels/panel_manager.h" 12 #include "chrome/browser/ui/panels/panel_manager.h"
13 #include "chrome/browser/ui/panels/stacked_panel_collection.h" 13 #include "chrome/browser/ui/panels/stacked_panel_collection.h"
14 #include "chrome/browser/ui/panels/test_panel_collection_squeeze_observer.h"
15 #include "chrome/common/chrome_notification_types.h" 14 #include "chrome/common/chrome_notification_types.h"
16 #include "content/public/browser/notification_service.h" 15 #include "content/public/browser/notification_service.h"
17 #include "content/public/test/test_utils.h" 16 #include "content/public/test/test_utils.h"
18 17
19 class PanelDragBrowserTest : public BasePanelBrowserTest { 18 class PanelDragBrowserTest : public BasePanelBrowserTest {
20 public: 19 public:
21 PanelDragBrowserTest() : BasePanelBrowserTest() { 20 PanelDragBrowserTest() : BasePanelBrowserTest() {
22 } 21 }
23 22
24 virtual ~PanelDragBrowserTest() { 23 virtual ~PanelDragBrowserTest() {
(...skipping 1260 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 #define MAYBE_DetachWithSqueeze DetachWithSqueeze 1284 #define MAYBE_DetachWithSqueeze DetachWithSqueeze
1286 #endif 1285 #endif
1287 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, MAYBE_DetachWithSqueeze) { 1286 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, MAYBE_DetachWithSqueeze) {
1288 PanelManager* panel_manager = PanelManager::GetInstance(); 1287 PanelManager* panel_manager = PanelManager::GetInstance();
1289 DockedPanelCollection* docked_collection = panel_manager->docked_collection(); 1288 DockedPanelCollection* docked_collection = panel_manager->docked_collection();
1290 DetachedPanelCollection* detached_collection = 1289 DetachedPanelCollection* detached_collection =
1291 panel_manager->detached_collection(); 1290 panel_manager->detached_collection();
1292 1291
1293 gfx::Vector2d drag_delta_to_detach = GetDragDeltaToDetach(); 1292 gfx::Vector2d drag_delta_to_detach = GetDragDeltaToDetach();
1294 1293
1294 int full_width = 200;
1295 gfx::Rect initial_bounds = gfx::Rect(0, 0, full_width, 100);
1296
1295 // Create some docked panels. 1297 // Create some docked panels.
1296 // docked: P1 P2 P3 P4 P5 1298 // docked: P1 P2 P3 P4 P5
1297 Panel* panel1 = CreateDockedPanel("1", gfx::Rect(0, 0, 200, 100)); 1299 Panel* panel1 = CreateDockedPanel("1", initial_bounds);
1298 Panel* panel2 = CreateDockedPanel("2", gfx::Rect(0, 0, 200, 100)); 1300 Panel* panel2 = CreateDockedPanel("2", initial_bounds);
1299 Panel* panel3 = CreateDockedPanel("3", gfx::Rect(0, 0, 200, 100)); 1301 Panel* panel3 = CreateDockedPanel("3", initial_bounds);
1300 Panel* panel4 = CreateDockedPanel("4", gfx::Rect(0, 0, 200, 100)); 1302 Panel* panel4 = CreateDockedPanel("4", initial_bounds);
1301 Panel* panel5 = CreateDockedPanel("5", gfx::Rect(0, 0, 200, 100)); 1303 Panel* panel5 = CreateDockedPanel("5", initial_bounds);
1302 ASSERT_EQ(0, detached_collection->num_panels()); 1304 ASSERT_EQ(0, detached_collection->num_panels());
1303 ASSERT_EQ(5, docked_collection->num_panels()); 1305 ASSERT_EQ(5, docked_collection->num_panels());
1304 1306
1307 EXPECT_GT(full_width, panel1->GetBounds().width());
1308 EXPECT_GT(full_width, panel2->GetBounds().width());
1309 EXPECT_GT(full_width, panel3->GetBounds().width());
1310 EXPECT_GT(full_width, panel4->GetBounds().width());
1311 EXPECT_EQ(full_width, panel5->GetBounds().width());
1312
1305 // Drag to detach the middle docked panel. 1313 // Drag to detach the middle docked panel.
1306 // Expect to have: 1314 // Expect to have:
1307 // detached: P2 1315 // detached: P2
1308 // docked: P1 P3 P4 P5 1316 // docked: P1 P3 P4 P5
1309 gfx::Point panel2_docked_position = panel2->GetBounds().origin();
1310 DragPanelByDelta(panel2, drag_delta_to_detach); 1317 DragPanelByDelta(panel2, drag_delta_to_detach);
1311 ASSERT_EQ(1, detached_collection->num_panels()); 1318 ASSERT_EQ(1, detached_collection->num_panels());
1312 ASSERT_EQ(4, docked_collection->num_panels()); 1319 ASSERT_EQ(4, docked_collection->num_panels());
1313 EXPECT_EQ(PanelCollection::DOCKED, panel1->collection()->type()); 1320 EXPECT_EQ(PanelCollection::DOCKED, panel1->collection()->type());
1314 EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type()); 1321 EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type());
1315 EXPECT_EQ(PanelCollection::DOCKED, panel3->collection()->type()); 1322 EXPECT_EQ(PanelCollection::DOCKED, panel3->collection()->type());
1316 EXPECT_EQ(PanelCollection::DOCKED, panel4->collection()->type()); 1323 EXPECT_EQ(PanelCollection::DOCKED, panel4->collection()->type());
1317 EXPECT_EQ(PanelCollection::DOCKED, panel5->collection()->type()); 1324 EXPECT_EQ(PanelCollection::DOCKED, panel5->collection()->type());
1318 gfx::Point panel2_new_position = 1325 // Expect that P2 should be restored with full width.1359
1319 panel2_docked_position + drag_delta_to_detach; 1326
1320 EXPECT_EQ(panel2_new_position, panel2->GetBounds().origin()); 1327 EXPECT_EQ(full_width, panel2->GetBounds().width());
1321 1328
1322 // Drag to detach the left-most docked panel. 1329 // Drag to detach the left-most docked panel.
1323 // Expect to have: 1330 // Expect to have:
1324 // detached: P2 P4 1331 // detached: P2 P5
1325 // docked: P1 P3 P5 1332 // docked: P1 P3 P4
1326 gfx::Point panel4_docked_position = panel4->GetBounds().origin(); 1333 // Note that the different delta y is used for dragging in order to avoid
1327 DragPanelByDelta(panel4, drag_delta_to_detach); 1334 // possible snapping of detached panels.
1335 drag_delta_to_detach.set_y(drag_delta_to_detach.y() - 50);
1336 DragPanelByDelta(panel5, drag_delta_to_detach);
1328 ASSERT_EQ(2, detached_collection->num_panels()); 1337 ASSERT_EQ(2, detached_collection->num_panels());
1329 ASSERT_EQ(3, docked_collection->num_panels()); 1338 ASSERT_EQ(3, docked_collection->num_panels());
1330 EXPECT_EQ(PanelCollection::DOCKED, panel1->collection()->type()); 1339 EXPECT_EQ(PanelCollection::DOCKED, panel1->collection()->type());
1331 EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type()); 1340 EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type());
1332 EXPECT_EQ(PanelCollection::DOCKED, panel3->collection()->type()); 1341 EXPECT_EQ(PanelCollection::DOCKED, panel3->collection()->type());
1333 EXPECT_EQ(PanelCollection::DETACHED, panel4->collection()->type()); 1342 EXPECT_EQ(PanelCollection::DOCKED, panel4->collection()->type());
1334 EXPECT_EQ(PanelCollection::DOCKED, panel5->collection()->type()); 1343 EXPECT_EQ(PanelCollection::DETACHED, panel5->collection()->type());
1335 EXPECT_EQ(panel2_new_position, panel2->GetBounds().origin()); 1344 // Expect that P5 should be restored with full width.
1336 gfx::Point panel4_new_position = 1345 EXPECT_EQ(full_width, panel5->GetBounds().width());
1337 panel4_docked_position + drag_delta_to_detach;
1338 EXPECT_EQ(panel4_new_position, panel4->GetBounds().origin());
1339 1346
1340 // Drag to detach the right-most docked panel. 1347 // Drag to detach the right-most docked panel.
1341 // Expect to have: 1348 // Expect to have:
1342 // detached: P1 P2 P4 1349 // detached: P1 P2 P5
1343 // docked: P3 P5 1350 // docked: P3 P4
1344 gfx::Point docked_position1 = panel1->GetBounds().origin(); 1351 // Note that the different delta y is used for dragging in order to avoid
1345 gfx::Point docked_position2 = panel3->GetBounds().origin(); 1352 // possible snapping of detached panels.
1346 1353 drag_delta_to_detach.set_y(drag_delta_to_detach.y() - 100);
1347 DragPanelByDelta(panel1, drag_delta_to_detach); 1354 DragPanelByDelta(panel1, drag_delta_to_detach);
1348 ASSERT_EQ(3, detached_collection->num_panels()); 1355 ASSERT_EQ(3, detached_collection->num_panels());
1349 ASSERT_EQ(2, docked_collection->num_panels()); 1356 ASSERT_EQ(2, docked_collection->num_panels());
1350 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type()); 1357 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
1351 EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type()); 1358 EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type());
1352 EXPECT_EQ(PanelCollection::DOCKED, panel3->collection()->type()); 1359 EXPECT_EQ(PanelCollection::DOCKED, panel3->collection()->type());
1353 EXPECT_EQ(PanelCollection::DETACHED, panel4->collection()->type()); 1360 EXPECT_EQ(PanelCollection::DOCKED, panel4->collection()->type());
1354 EXPECT_EQ(PanelCollection::DOCKED, panel5->collection()->type()); 1361 EXPECT_EQ(PanelCollection::DETACHED, panel5->collection()->type());
1355 gfx::Point panel1_new_position = docked_position1 + drag_delta_to_detach; 1362 // Expect that P1 should be restored with full width.
1356 EXPECT_EQ(panel1_new_position, panel1->GetBounds().origin()); 1363 EXPECT_EQ(full_width, panel1->GetBounds().width());
1357 EXPECT_EQ(panel2_new_position, panel2->GetBounds().origin());
1358 EXPECT_EQ(panel4_new_position, panel4->GetBounds().origin());
1359 1364
1360 // No more squeeze, docked panels should stay put. 1365 // No more squeeze, docked panels should stay put.
1361 EXPECT_EQ(docked_position1, panel3->GetBounds().origin()); 1366 EXPECT_EQ(full_width, panel1->GetBounds().width());
1362 EXPECT_EQ(panel1->GetBounds().width(), panel1->GetRestoredBounds().width()); 1367 EXPECT_EQ(full_width, panel2->GetBounds().width());
1363 EXPECT_EQ(docked_position2, panel5->GetBounds().origin());
1364 EXPECT_EQ(panel2->GetBounds().width(), panel2->GetRestoredBounds().width());
1365 1368
1366 panel_manager->CloseAll(); 1369 panel_manager->CloseAll();
1367 } 1370 }
1368 1371
1369 // http://crbug.com/143247, http://crbug.com/175760 1372 // http://crbug.com/143247, http://crbug.com/175760
1370 #if defined(OS_LINUX) || defined(OS_MACOSX) 1373 #if defined(OS_LINUX) || defined(OS_MACOSX)
1371 #define MAYBE_AttachWithSqueeze DISABLED_AttachWithSqueeze 1374 #define MAYBE_AttachWithSqueeze DISABLED_AttachWithSqueeze
1372 #else 1375 #else
1373 #define MAYBE_AttachWithSqueeze AttachWithSqueeze 1376 #define MAYBE_AttachWithSqueeze AttachWithSqueeze
1374 #endif 1377 #endif
1375 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, MAYBE_AttachWithSqueeze) { 1378 IN_PROC_BROWSER_TEST_F(PanelDragBrowserTest, MAYBE_AttachWithSqueeze) {
1376 PanelManager* panel_manager = PanelManager::GetInstance(); 1379 PanelManager* panel_manager = PanelManager::GetInstance();
1377 DockedPanelCollection* docked_collection = panel_manager->docked_collection(); 1380 DockedPanelCollection* docked_collection = panel_manager->docked_collection();
1378 DetachedPanelCollection* detached_collection = 1381 DetachedPanelCollection* detached_collection =
1379 panel_manager->detached_collection(); 1382 panel_manager->detached_collection();
1380 1383
1381 // Create some detached, docked panels. 1384 // Create some detached, docked panels.
1382 // detached: P1 P2 P3 1385 // detached: P1 P2 P3
1383 // docked: P4 P5 P6 P7 1386 // docked: P4 P5 P6 P7
1384 Panel* panel1 = CreateDetachedPanel("1", gfx::Rect(100, 300, 200, 100)); 1387 Panel* panel1 = CreateDetachedPanel("1", gfx::Rect(100, 300, 200, 100));
1385 Panel* panel2 = CreateDetachedPanel("2", gfx::Rect(200, 300, 200, 100)); 1388 Panel* panel2 = CreateDetachedPanel("2", gfx::Rect(200, 300, 200, 100));
1386 Panel* panel3 = CreateDetachedPanel("3", gfx::Rect(400, 300, 200, 100)); 1389 Panel* panel3 = CreateDetachedPanel("3", gfx::Rect(400, 300, 200, 100));
1387 Panel* panel4 = CreateDockedPanel("4", gfx::Rect(0, 0, 200, 100)); 1390 Panel* panel4 = CreateDockedPanel("4", gfx::Rect(0, 0, 200, 100));
1388 Panel* panel5 = CreateDockedPanel("5", gfx::Rect(0, 0, 200, 100)); 1391 Panel* panel5 = CreateDockedPanel("5", gfx::Rect(0, 0, 200, 100));
1389 Panel* panel6 = CreateDockedPanel("6", gfx::Rect(0, 0, 200, 100)); 1392 Panel* panel6 = CreateDockedPanel("6", gfx::Rect(0, 0, 200, 100));
1390 Panel* panel7 = CreateDockedPanel("7", gfx::Rect(0, 0, 200, 100)); 1393 Panel* panel7 = CreateDockedPanel("7", gfx::Rect(0, 0, 200, 100));
1391 ASSERT_EQ(3, detached_collection->num_panels()); 1394 ASSERT_EQ(3, detached_collection->num_panels());
1392 ASSERT_EQ(4, docked_collection->num_panels()); 1395 ASSERT_EQ(4, docked_collection->num_panels());
1393 1396
1394 // Wait for active states to settle.
1395 PanelCollectionSqueezeObserver panel7_settled(docked_collection, panel7);
1396 panel7_settled.Wait();
1397
1398 gfx::Point detached_position1 = panel1->GetBounds().origin(); 1397 gfx::Point detached_position1 = panel1->GetBounds().origin();
1399 gfx::Point detached_position2 = panel2->GetBounds().origin(); 1398 gfx::Point detached_position2 = panel2->GetBounds().origin();
1400 gfx::Point detached_position3 = panel3->GetBounds().origin(); 1399 gfx::Point detached_position3 = panel3->GetBounds().origin();
1401 gfx::Point docked_position4 = panel4->GetBounds().origin(); 1400 gfx::Point docked_position4 = panel4->GetBounds().origin();
1402 gfx::Point docked_position5 = panel5->GetBounds().origin(); 1401 gfx::Point docked_position5 = panel5->GetBounds().origin();
1403 gfx::Point docked_position6 = panel6->GetBounds().origin(); 1402 gfx::Point docked_position6 = panel6->GetBounds().origin();
1404 gfx::Point docked_position7 = panel7->GetBounds().origin(); 1403 gfx::Point docked_position7 = panel7->GetBounds().origin();
1405 1404
1406 // Drag to attach a detached panel between 2 docked panels. 1405 // Drag to attach a detached panel between 2 docked panels.
1407 // Expect to have: 1406 // Expect to have:
1408 // detached: P1 P2 1407 // detached: P1 P2
1409 // docked: P4 P3 P5 P6 P7 1408 // docked: P4 P3 P5 P6 P7
1410 gfx::Point drag_to_location(panel5->GetBounds().x() + 10, 1409 gfx::Point drag_to_location(panel5->GetBounds().x() + 10,
1411 panel5->GetBounds().y()); 1410 panel5->GetBounds().y());
1412 DragPanelToMouseLocation(panel3, drag_to_location); 1411 DragPanelToMouseLocation(panel3, drag_to_location);
1413 ASSERT_EQ(2, detached_collection->num_panels()); 1412 ASSERT_EQ(2, detached_collection->num_panels());
1414 ASSERT_EQ(5, docked_collection->num_panels()); 1413 ASSERT_EQ(5, docked_collection->num_panels());
1415 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type()); 1414 EXPECT_EQ(PanelCollection::DETACHED, panel1->collection()->type());
1416 EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type()); 1415 EXPECT_EQ(PanelCollection::DETACHED, panel2->collection()->type());
1417 EXPECT_EQ(PanelCollection::DOCKED, panel3->collection()->type()); 1416 EXPECT_EQ(PanelCollection::DOCKED, panel3->collection()->type());
1418 EXPECT_EQ(PanelCollection::DOCKED, panel4->collection()->type()); 1417 EXPECT_EQ(PanelCollection::DOCKED, panel4->collection()->type());
1419 EXPECT_EQ(PanelCollection::DOCKED, panel5->collection()->type()); 1418 EXPECT_EQ(PanelCollection::DOCKED, panel5->collection()->type());
1420 EXPECT_EQ(PanelCollection::DOCKED, panel6->collection()->type()); 1419 EXPECT_EQ(PanelCollection::DOCKED, panel6->collection()->type());
1421 EXPECT_EQ(PanelCollection::DOCKED, panel7->collection()->type()); 1420 EXPECT_EQ(PanelCollection::DOCKED, panel7->collection()->type());
1422 EXPECT_EQ(detached_position1, panel1->GetBounds().origin()); 1421 EXPECT_EQ(detached_position1, panel1->GetBounds().origin());
1423 EXPECT_EQ(detached_position2, panel2->GetBounds().origin()); 1422 EXPECT_EQ(detached_position2, panel2->GetBounds().origin());
1424 1423
1425 // Wait for active states to settle.
1426 MessageLoopForUI::current()->RunUntilIdle();
1427
1428 // Panel positions should have shifted because of the "squeeze" mode. 1424 // Panel positions should have shifted because of the "squeeze" mode.
1429 EXPECT_NE(docked_position4, panel4->GetBounds().origin()); 1425 EXPECT_NE(docked_position4, panel4->GetBounds().origin());
1430 EXPECT_LT(panel4->GetBounds().width(), panel4->GetRestoredBounds().width()); 1426 EXPECT_LT(panel4->GetBounds().width(), panel4->GetRestoredBounds().width());
1431 EXPECT_NE(docked_position5, panel5->GetBounds().origin()); 1427 EXPECT_NE(docked_position5, panel5->GetBounds().origin());
1432 EXPECT_LT(panel5->GetBounds().width(), panel5->GetRestoredBounds().width()); 1428 EXPECT_LT(panel5->GetBounds().width(), panel5->GetRestoredBounds().width());
1433 1429
1434 #if defined(OS_WIN) 1430 #if defined(OS_WIN)
1435 // The panel we dragged becomes the active one. 1431 // The panel we dragged becomes the active one.
1436 EXPECT_EQ(true, panel3->IsActive()); 1432 EXPECT_EQ(true, panel3->IsActive());
1437 EXPECT_EQ(panel3->GetBounds().width(), panel3->GetRestoredBounds().width()); 1433 EXPECT_EQ(panel3->GetBounds().width(), panel3->GetRestoredBounds().width());
(...skipping 1689 matching lines...) Expand 10 before | Expand all | Expand 10 after
3127 panel1_expected_bounds.set_x(expected_x); 3123 panel1_expected_bounds.set_x(expected_x);
3128 panel1_expected_bounds.set_y(secondary_work_area.y()); 3124 panel1_expected_bounds.set_y(secondary_work_area.y());
3129 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds()); 3125 EXPECT_EQ(panel1_expected_bounds, panel1->GetBounds());
3130 panel2_expected_bounds.set_x(expected_x); 3126 panel2_expected_bounds.set_x(expected_x);
3131 panel2_expected_bounds.set_y(panel1_expected_bounds.bottom()); 3127 panel2_expected_bounds.set_y(panel1_expected_bounds.bottom());
3132 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds()); 3128 EXPECT_EQ(panel2_expected_bounds, panel2->GetBounds());
3133 3129
3134 panel_manager->CloseAll(); 3130 panel_manager->CloseAll();
3135 } 3131 }
3136 #endif 3132 #endif
OLDNEW
« no previous file with comments | « chrome/browser/ui/panels/panel_collection.h ('k') | chrome/browser/ui/panels/panel_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698