OLD | NEW |
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 Loading... |
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()); |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1587 ui::TouchEvent touch(ui::ET_TOUCH_PRESSED, location, 0, | 1551 ui::TouchEvent touch(ui::ET_TOUCH_PRESSED, location, 0, |
1588 ui::EventTimeForNow()); | 1552 ui::EventTimeForNow()); |
1589 ui::EventTarget* target = targeter->FindTargetForEvent(root, &touch); | 1553 ui::EventTarget* target = targeter->FindTargetForEvent(root, &touch); |
1590 if (points[i].is_target_hit) | 1554 if (points[i].is_target_hit) |
1591 EXPECT_EQ(window.get(), target); | 1555 EXPECT_EQ(window.get(), target); |
1592 else | 1556 else |
1593 EXPECT_NE(window.get(), target); | 1557 EXPECT_NE(window.get(), target); |
1594 } | 1558 } |
1595 } | 1559 } |
1596 | 1560 |
1597 // Verifies events targeting just outside the window edges for docked windows. | |
1598 TEST_F(WorkspaceControllerTest, WindowEdgeHitTestDocked) { | |
1599 aura::test::TestWindowDelegate delegate; | |
1600 // Make window smaller than the minimum docked area so that the window edges | |
1601 // are exposed. | |
1602 delegate.set_maximum_size(gfx::Size(180, 200)); | |
1603 std::unique_ptr<Window> window(aura::test::CreateTestWindowWithDelegate( | |
1604 &delegate, 123, gfx::Rect(20, 10, 100, 50), NULL)); | |
1605 ParentWindowInPrimaryRootWindow(window.get()); | |
1606 aura::Window* docked_container = Shell::GetContainer( | |
1607 window->GetRootWindow(), kShellWindowId_DockedContainer); | |
1608 docked_container->AddChild(window.get()); | |
1609 window->Show(); | |
1610 ui::EventTarget* root = window->GetRootWindow(); | |
1611 ui::EventTargeter* targeter = root->GetEventTargeter(); | |
1612 const gfx::Rect bounds = window->bounds(); | |
1613 const int kNumPoints = 5; | |
1614 struct { | |
1615 const char* direction; | |
1616 gfx::Point location; | |
1617 bool is_target_hit; | |
1618 } points[kNumPoints] = { | |
1619 {"left", gfx::Point(bounds.x() - 2, bounds.y() + 10), true}, | |
1620 {"top", gfx::Point(bounds.x() + 10, bounds.y() - 2), true}, | |
1621 {"right", gfx::Point(bounds.right() + 2, bounds.y() + 10), true}, | |
1622 {"bottom", gfx::Point(bounds.x() + 10, bounds.bottom() + 2), true}, | |
1623 {"outside", gfx::Point(bounds.x() + 10, bounds.y() - 31), false}, | |
1624 }; | |
1625 for (int i = 0; i < kNumPoints; ++i) { | |
1626 SCOPED_TRACE(points[i].direction); | |
1627 const gfx::Point& location = points[i].location; | |
1628 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, location, location, | |
1629 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | |
1630 ui::EventTarget* target = targeter->FindTargetForEvent(root, &mouse); | |
1631 if (points[i].is_target_hit) | |
1632 EXPECT_EQ(window.get(), target); | |
1633 else | |
1634 EXPECT_NE(window.get(), target); | |
1635 | |
1636 ui::TouchEvent touch(ui::ET_TOUCH_PRESSED, location, 0, | |
1637 ui::EventTimeForNow()); | |
1638 target = targeter->FindTargetForEvent(root, &touch); | |
1639 if (points[i].is_target_hit) | |
1640 EXPECT_EQ(window.get(), target); | |
1641 else | |
1642 EXPECT_NE(window.get(), target); | |
1643 } | |
1644 } | |
1645 | |
1646 } // namespace ash | 1561 } // namespace ash |
OLD | NEW |