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

Side by Side Diff: ash/wm/workspace_controller_unittest.cc

Issue 2700523004: Remove docked windows entirely in M59. (Closed)
Patch Set: varkha's comments Created 3 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "ash/common/wm/workspace_controller.h" 5 #include "ash/common/wm/workspace_controller.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "ash/common/session/session_controller.h" 9 #include "ash/common/session/session_controller.h"
10 #include "ash/common/shelf/shelf_layout_manager.h" 10 #include "ash/common/shelf/shelf_layout_manager.h"
(...skipping 1325 matching lines...) Expand 10 before | Expand all | Expand 10 after
1336 EXPECT_EQ(snapped_bounds, window->bounds()); 1336 EXPECT_EQ(snapped_bounds, window->bounds());
1337 EXPECT_TRUE(window_state->bounds_changed_by_user()); 1337 EXPECT_TRUE(window_state->bounds_changed_by_user());
1338 1338
1339 // Minimize and Restore |window|, the restored bounds should be equal to the 1339 // Minimize and Restore |window|, the restored bounds should be equal to the
1340 // bounds of left snapped state. 1340 // bounds of left snapped state.
1341 window_state->Minimize(); 1341 window_state->Minimize();
1342 window_state->Restore(); 1342 window_state->Restore();
1343 EXPECT_EQ(snapped_bounds, window->bounds()); 1343 EXPECT_EQ(snapped_bounds, window->bounds());
1344 } 1344 }
1345 1345
1346 namespace {
1347
1348 // Used by DragMaximizedNonTrackedWindow to track how many times the window
1349 // hierarchy changes affecting the specified window.
1350 class DragMaximizedNonTrackedWindowObserver : public aura::WindowObserver {
1351 public:
1352 DragMaximizedNonTrackedWindowObserver(aura::Window* window)
1353 : change_count_(0), window_(window) {}
1354
1355 // Number of times OnWindowHierarchyChanged() has been received.
1356 void clear_change_count() { change_count_ = 0; }
1357 int change_count() const { return change_count_; }
1358
1359 // aura::WindowObserver overrides:
1360 // Counts number of times a window is reparented. Ignores reparenting into and
1361 // from a docked container which is expected when a tab is dragged.
1362 void OnWindowHierarchyChanged(const HierarchyChangeParams& params) override {
1363 if (params.target != window_ ||
1364 (params.old_parent->id() == kShellWindowId_DefaultContainer &&
1365 params.new_parent->id() == kShellWindowId_DockedContainer) ||
1366 (params.old_parent->id() == kShellWindowId_DockedContainer &&
1367 params.new_parent->id() == kShellWindowId_DefaultContainer)) {
1368 return;
1369 }
1370 change_count_++;
1371 }
1372
1373 private:
1374 int change_count_;
1375 aura::Window* window_;
1376
1377 DISALLOW_COPY_AND_ASSIGN(DragMaximizedNonTrackedWindowObserver);
1378 };
1379
1380 } // namespace
1381
1382 // Verifies that a new maximized window becomes visible after its activation 1346 // Verifies that a new maximized window becomes visible after its activation
1383 // is requested, even though it does not become activated because a system 1347 // is requested, even though it does not become activated because a system
1384 // modal window is active. 1348 // modal window is active.
1385 TEST_F(WorkspaceControllerTest, SwitchFromModal) { 1349 TEST_F(WorkspaceControllerTest, SwitchFromModal) {
1386 std::unique_ptr<Window> modal_window(CreateTestWindowUnparented()); 1350 std::unique_ptr<Window> modal_window(CreateTestWindowUnparented());
1387 modal_window->SetBounds(gfx::Rect(10, 11, 21, 22)); 1351 modal_window->SetBounds(gfx::Rect(10, 11, 21, 22));
1388 modal_window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM); 1352 modal_window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM);
1389 ParentWindowInPrimaryRootWindow(modal_window.get()); 1353 ParentWindowInPrimaryRootWindow(modal_window.get());
1390 modal_window->Show(); 1354 modal_window->Show();
1391 wm::ActivateWindow(modal_window.get()); 1355 wm::ActivateWindow(modal_window.get());
1392 1356
1393 std::unique_ptr<Window> maximized_window(CreateTestWindow()); 1357 std::unique_ptr<Window> maximized_window(CreateTestWindow());
1394 maximized_window->SetProperty(aura::client::kShowStateKey, 1358 maximized_window->SetProperty(aura::client::kShowStateKey,
1395 ui::SHOW_STATE_MAXIMIZED); 1359 ui::SHOW_STATE_MAXIMIZED);
1396 maximized_window->Show(); 1360 maximized_window->Show();
1397 wm::ActivateWindow(maximized_window.get()); 1361 wm::ActivateWindow(maximized_window.get());
1398 EXPECT_TRUE(maximized_window->IsVisible()); 1362 EXPECT_TRUE(maximized_window->IsVisible());
1399 } 1363 }
1400 1364
1401 namespace {
1402
1403 // Subclass of WorkspaceControllerTest that runs tests with docked windows
1404 // enabled and disabled.
1405 class WorkspaceControllerTestDragging : public WorkspaceControllerTest {
1406 public:
1407 WorkspaceControllerTestDragging() {}
1408 ~WorkspaceControllerTestDragging() override {}
1409
1410 private:
1411 DISALLOW_COPY_AND_ASSIGN(WorkspaceControllerTestDragging);
1412 };
1413
1414 } // namespace
1415
1416 // Verifies that when dragging a window over the shelf overlap is detected 1365 // Verifies that when dragging a window over the shelf overlap is detected
1417 // during and after the drag. 1366 // during and after the drag.
1418 TEST_F(WorkspaceControllerTestDragging, DragWindowOverlapShelf) { 1367 TEST_F(WorkspaceControllerTest, DragWindowOverlapShelf) {
1419 aura::test::TestWindowDelegate delegate; 1368 aura::test::TestWindowDelegate delegate;
1420 delegate.set_window_component(HTCAPTION); 1369 delegate.set_window_component(HTCAPTION);
1421 std::unique_ptr<Window> w1(aura::test::CreateTestWindowWithDelegate( 1370 std::unique_ptr<Window> w1(aura::test::CreateTestWindowWithDelegate(
1422 &delegate, ui::wm::WINDOW_TYPE_NORMAL, gfx::Rect(5, 5, 100, 50), NULL)); 1371 &delegate, ui::wm::WINDOW_TYPE_NORMAL, gfx::Rect(5, 5, 100, 50), NULL));
1423 ParentWindowInPrimaryRootWindow(w1.get()); 1372 ParentWindowInPrimaryRootWindow(w1.get());
1424 1373
1425 GetPrimaryShelf()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); 1374 GetPrimaryShelf()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
1426 1375
1427 // Drag near the shelf. 1376 // Drag near the shelf.
1428 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 1377 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1429 gfx::Point()); 1378 gfx::Point());
1430 generator.MoveMouseTo(10, 10); 1379 generator.MoveMouseTo(10, 10);
1431 generator.PressLeftButton(); 1380 generator.PressLeftButton();
1432 generator.MoveMouseTo(100, shelf_layout_manager()->GetIdealBounds().y() - 70); 1381 generator.MoveMouseTo(100, shelf_layout_manager()->GetIdealBounds().y() - 70);
1433 1382
1434 // Shelf should not be in overlapped state. 1383 // Shelf should not be in overlapped state.
1435 EXPECT_FALSE(GetWindowOverlapsShelf()); 1384 EXPECT_FALSE(GetWindowOverlapsShelf());
1436 1385
1437 generator.MoveMouseTo(100, shelf_layout_manager()->GetIdealBounds().y() - 20); 1386 generator.MoveMouseTo(100, shelf_layout_manager()->GetIdealBounds().y() - 20);
1438 1387
1439 // Shelf should detect overlap. Overlap state stays after mouse is released. 1388 // Shelf should detect overlap. Overlap state stays after mouse is released.
1440 EXPECT_TRUE(GetWindowOverlapsShelf()); 1389 EXPECT_TRUE(GetWindowOverlapsShelf());
1441 generator.ReleaseLeftButton(); 1390 generator.ReleaseLeftButton();
1442 EXPECT_TRUE(GetWindowOverlapsShelf()); 1391 EXPECT_TRUE(GetWindowOverlapsShelf());
1443 } 1392 }
1444 1393
1445 // Verifies that when dragging a window autohidden shelf stays hidden during 1394 // Verifies that when dragging a window autohidden shelf stays hidden during
1446 // and after the drag. 1395 // and after the drag.
1447 TEST_F(WorkspaceControllerTestDragging, DragWindowKeepsShelfAutohidden) { 1396 TEST_F(WorkspaceControllerTest, DragWindowKeepsShelfAutohidden) {
1448 aura::test::TestWindowDelegate delegate; 1397 aura::test::TestWindowDelegate delegate;
1449 delegate.set_window_component(HTCAPTION); 1398 delegate.set_window_component(HTCAPTION);
1450 std::unique_ptr<Window> w1(aura::test::CreateTestWindowWithDelegate( 1399 std::unique_ptr<Window> w1(aura::test::CreateTestWindowWithDelegate(
1451 &delegate, ui::wm::WINDOW_TYPE_NORMAL, gfx::Rect(5, 5, 100, 50), NULL)); 1400 &delegate, ui::wm::WINDOW_TYPE_NORMAL, gfx::Rect(5, 5, 100, 50), NULL));
1452 ParentWindowInPrimaryRootWindow(w1.get()); 1401 ParentWindowInPrimaryRootWindow(w1.get());
1453 1402
1454 WmShelf* shelf = GetPrimaryShelf(); 1403 WmShelf* shelf = GetPrimaryShelf();
1455 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 1404 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1456 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); 1405 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
1457 1406
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1590 ui::TouchEvent touch(ui::ET_TOUCH_PRESSED, location, 0, 1539 ui::TouchEvent touch(ui::ET_TOUCH_PRESSED, location, 0,
1591 ui::EventTimeForNow()); 1540 ui::EventTimeForNow());
1592 ui::EventTarget* target = targeter->FindTargetForEvent(root, &touch); 1541 ui::EventTarget* target = targeter->FindTargetForEvent(root, &touch);
1593 if (points[i].is_target_hit) 1542 if (points[i].is_target_hit)
1594 EXPECT_EQ(window.get(), target); 1543 EXPECT_EQ(window.get(), target);
1595 else 1544 else
1596 EXPECT_NE(window.get(), target); 1545 EXPECT_NE(window.get(), target);
1597 } 1546 }
1598 } 1547 }
1599 1548
1600 // Verifies events targeting just outside the window edges for docked windows.
1601 TEST_F(WorkspaceControllerTest, WindowEdgeHitTestDocked) {
1602 aura::test::TestWindowDelegate delegate;
1603 // Make window smaller than the minimum docked area so that the window edges
1604 // are exposed.
1605 delegate.set_maximum_size(gfx::Size(180, 200));
1606 std::unique_ptr<Window> window(aura::test::CreateTestWindowWithDelegate(
1607 &delegate, 123, gfx::Rect(20, 10, 100, 50), NULL));
1608 ParentWindowInPrimaryRootWindow(window.get());
1609 aura::Window* docked_container = Shell::GetContainer(
1610 window->GetRootWindow(), kShellWindowId_DockedContainer);
1611 docked_container->AddChild(window.get());
1612 window->Show();
1613 aura::Window* root = window->GetRootWindow();
1614 ui::EventTargeter* targeter =
1615 root->GetHost()->dispatcher()->GetDefaultEventTargeter();
1616 const gfx::Rect bounds = window->bounds();
1617 const int kNumPoints = 5;
1618 struct {
1619 const char* direction;
1620 gfx::Point location;
1621 bool is_target_hit;
1622 } points[kNumPoints] = {
1623 {"left", gfx::Point(bounds.x() - 2, bounds.y() + 10), true},
1624 {"top", gfx::Point(bounds.x() + 10, bounds.y() - 2), true},
1625 {"right", gfx::Point(bounds.right() + 2, bounds.y() + 10), true},
1626 {"bottom", gfx::Point(bounds.x() + 10, bounds.bottom() + 2), true},
1627 {"outside", gfx::Point(bounds.x() + 10, bounds.y() - 31), false},
1628 };
1629 for (int i = 0; i < kNumPoints; ++i) {
1630 SCOPED_TRACE(points[i].direction);
1631 const gfx::Point& location = points[i].location;
1632 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, location, location,
1633 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE);
1634 ui::EventTarget* target = targeter->FindTargetForEvent(root, &mouse);
1635 if (points[i].is_target_hit)
1636 EXPECT_EQ(window.get(), target);
1637 else
1638 EXPECT_NE(window.get(), target);
1639
1640 ui::TouchEvent touch(ui::ET_TOUCH_PRESSED, location, 0,
1641 ui::EventTimeForNow());
1642 target = targeter->FindTargetForEvent(root, &touch);
1643 if (points[i].is_target_hit)
1644 EXPECT_EQ(window.get(), target);
1645 else
1646 EXPECT_NE(window.get(), target);
1647 }
1648 }
1649
1650 } // namespace ash 1549 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698