Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / ash / wm / workspace_controller_unittest.cc
index af81e7d..7621b28 100644 (file)
@@ -42,7 +42,6 @@
 using aura::Window;
 
 namespace ash {
-namespace internal {
 
 // Returns a string containing the names of all the children of |window| (in
 // order). Each entry is separated by a space.
@@ -129,11 +128,9 @@ class WorkspaceControllerTest : public test::AshTestBase {
     test::TestShelfDelegate* shelf_delegate =
         test::TestShelfDelegate::instance();
     shelf_delegate->AddShelfItem(window);
-    PanelLayoutManager* manager =
-        static_cast<PanelLayoutManager*>(
-            Shell::GetContainer(window->GetRootWindow(),
-                                internal::kShellWindowId_PanelContainer)->
-                                layout_manager());
+    PanelLayoutManager* manager = static_cast<PanelLayoutManager*>(
+        Shell::GetContainer(window->GetRootWindow(),
+                            kShellWindowId_PanelContainer)->layout_manager());
     manager->Relayout();
     return window;
   }
@@ -776,6 +773,54 @@ TEST_F(WorkspaceControllerTest, BasicAutoPlacingOnCreate) {
   }
 }
 
+// Test that adding a second window shifts both the first window and its
+// transient child.
+TEST_F(WorkspaceControllerTest, AutoPlacingMovesTransientChild) {
+  // Create an auto-positioned window.
+  scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(0));
+  gfx::Rect desktop_area = window1->parent()->bounds();
+  wm::GetWindowState(window1.get())->set_window_position_managed(true);
+  // Hide and then show |window1| to trigger auto-positioning logic.
+  window1->Hide();
+  window1->SetBounds(gfx::Rect(16, 32, 300, 300));
+  window1->Show();
+
+  // |window1| should be horizontally centered.
+  int x_window1 = (desktop_area.width() - 300) / 2;
+  EXPECT_EQ(base::IntToString(x_window1) + ",32 300x300",
+            window1->bounds().ToString());
+
+  // Create a |child| window and make it a transient child of |window1|.
+  scoped_ptr<Window> child(CreateTestWindowUnparented());
+  ::wm::AddTransientChild(window1.get(), child.get());
+  const int x_child = x_window1 + 50;
+  child->SetBounds(gfx::Rect(x_child, 20, 200, 200));
+  ParentWindowInPrimaryRootWindow(child.get());
+  child->Show();
+  wm::ActivateWindow(child.get());
+
+  // The |child| should be where it was created.
+  EXPECT_EQ(base::IntToString(x_child) + ",20 200x200",
+            child->bounds().ToString());
+
+  // Create and show a second window forcing the first window and its child to
+  // move.
+  scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(1));
+  wm::GetWindowState(window2.get())->set_window_position_managed(true);
+  // Hide and then show |window2| to trigger auto-positioning logic.
+  window2->Hide();
+  window2->SetBounds(gfx::Rect(32, 48, 250, 250));
+  window2->Show();
+
+  // Check that both |window1| and |child| have moved left.
+  EXPECT_EQ("0,32 300x300", window1->bounds().ToString());
+  int x = x_child - x_window1;
+  EXPECT_EQ(base::IntToString(x) + ",20 200x200", child->bounds().ToString());
+  // Check that |window2| has moved right.
+  x = desktop_area.width() - window2->bounds().width();
+  EXPECT_EQ(base::IntToString(x) + ",48 250x250", window2->bounds().ToString());
+}
+
 // Test the basic auto placement of one and or two windows in a "simulated
 // session" of sequential window operations.
 TEST_F(WorkspaceControllerTest, BasicAutoPlacingOnShowHide) {
@@ -1470,8 +1515,8 @@ TEST_F(WorkspaceControllerTest, WindowEdgeHitTest) {
   }
 }
 
-// Verifies events targeting just outside the window edges for panels.
-TEST_F(WorkspaceControllerTest, WindowEdgeHitTestPanel) {
+// Verifies mouse event targeting just outside the window edges for panels.
+TEST_F(WorkspaceControllerTest, WindowEdgeMouseHitTestPanel) {
   aura::test::TestWindowDelegate delegate;
   scoped_ptr<Window> window(CreateTestPanel(&delegate,
                                            gfx::Rect(20, 10, 100, 50)));
@@ -1500,10 +1545,38 @@ TEST_F(WorkspaceControllerTest, WindowEdgeHitTestPanel) {
       EXPECT_EQ(window.get(), target);
     else
       EXPECT_NE(window.get(), target);
+  }
+}
 
+// Verifies touch event targeting just outside the window edges for panels.
+// The shelf is aligned to the bottom by default, and so touches just below
+// the bottom edge of the panel should not target the panel itself because
+// an AttachedPanelWindowTargeter is installed on the panel container.
+TEST_F(WorkspaceControllerTest, WindowEdgeTouchHitTestPanel) {
+  aura::test::TestWindowDelegate delegate;
+  scoped_ptr<Window> window(CreateTestPanel(&delegate,
+                                            gfx::Rect(20, 10, 100, 50)));
+  ui::EventTarget* root = window->GetRootWindow();
+  ui::EventTargeter* targeter = root->GetEventTargeter();
+  const gfx::Rect bounds = window->bounds();
+  const int kNumPoints = 5;
+  struct {
+    const char* direction;
+    gfx::Point location;
+    bool is_target_hit;
+  } points[kNumPoints] = {
+    { "left", gfx::Point(bounds.x() - 2, bounds.y() + 10), true },
+    { "top", gfx::Point(bounds.x() + 10, bounds.y() - 2), true },
+    { "right", gfx::Point(bounds.right() + 2, bounds.y() + 10), true },
+    { "bottom", gfx::Point(bounds.x() + 10, bounds.bottom() + 2), false },
+    { "outside", gfx::Point(bounds.x() + 10, bounds.y() - 31), false },
+  };
+  for (int i = 0; i < kNumPoints; ++i) {
+    SCOPED_TRACE(points[i].direction);
+    const gfx::Point& location = points[i].location;
     ui::TouchEvent touch(ui::ET_TOUCH_PRESSED, location, 0,
                          ui::EventTimeForNow());
-    target = targeter->FindTargetForEvent(root, &touch);
+    ui::EventTarget* target = targeter->FindTargetForEvent(root, &touch);
     if (points[i].is_target_hit)
       EXPECT_EQ(window.get(), target);
     else
@@ -1523,7 +1596,7 @@ TEST_F(WorkspaceControllerTest, WindowEdgeHitTestDocked) {
       123, gfx::Rect(20, 10, 100, 50), NULL));
   ParentWindowInPrimaryRootWindow(window.get());
   aura::Window* docked_container = Shell::GetContainer(
-      window->GetRootWindow(), internal::kShellWindowId_DockedContainer);
+      window->GetRootWindow(), kShellWindowId_DockedContainer);
   docked_container->AddChild(window.get());
   window->Show();
   ui::EventTarget* root = window->GetRootWindow();
@@ -1562,5 +1635,4 @@ TEST_F(WorkspaceControllerTest, WindowEdgeHitTestDocked) {
   }
 }
 
-}  // namespace internal
 }  // namespace ash