Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ash / wm / panels / panel_window_resizer_unittest.cc
index 3fdddf1..73500b3 100644 (file)
 #include "ash/wm/drag_window_resizer.h"
 #include "ash/wm/panels/panel_layout_manager.h"
 #include "ash/wm/window_state.h"
+#include "ash/wm/wm_event.h"
 #include "base/win/windows_version.h"
 #include "ui/aura/client/aura_constants.h"
-#include "ui/aura/root_window.h"
+#include "ui/aura/window_event_dispatcher.h"
 #include "ui/base/hit_test.h"
 #include "ui/base/l10n/l10n_util.h"
 #include "ui/base/ui_base_types.h"
-#include "ui/views/corewm/window_util.h"
 #include "ui/views/widget/widget.h"
+#include "ui/wm/core/window_util.h"
 
 namespace ash {
-namespace internal {
 
 class PanelWindowResizerTest : public test::AshTestBase {
  public:
   PanelWindowResizerTest() {}
-  virtual ~PanelWindowResizerTest() {}
+  ~PanelWindowResizerTest() override {}
 
-  virtual void SetUp() OVERRIDE {
+  void SetUp() override {
     AshTestBase::SetUp();
     UpdateDisplay("600x400");
     test::ShellTestApi test_api(Shell::GetInstance());
@@ -45,9 +45,7 @@ class PanelWindowResizerTest : public test::AshTestBase {
     shelf_delegate_ = test::TestShelfDelegate::instance();
   }
 
-  virtual void TearDown() OVERRIDE {
-    AshTestBase::TearDown();
-  }
+  void TearDown() override { AshTestBase::TearDown(); }
 
  protected:
   gfx::Point CalculateDragPoint(const WindowResizer& resizer,
@@ -63,13 +61,7 @@ class PanelWindowResizerTest : public test::AshTestBase {
     gfx::Rect bounds(origin, gfx::Size(101, 101));
     aura::Window* window = CreateTestWindowInShellWithDelegateAndType(
         NULL, ui::wm::WINDOW_TYPE_PANEL, 0, bounds);
-    shelf_delegate_->AddLauncherItem(window);
-    PanelLayoutManager* manager =
-        static_cast<PanelLayoutManager*>(
-            Shell::GetContainer(window->GetRootWindow(),
-                                internal::kShellWindowId_PanelContainer)->
-                layout_manager());
-    manager->Relayout();
+    shelf_delegate_->AddShelfItem(window);
     return window;
   }
 
@@ -102,7 +94,7 @@ class PanelWindowResizerTest : public test::AshTestBase {
     wm::WindowState* window_state = wm::GetWindowState(window);
     EXPECT_TRUE(window_state->panel_attached());
     aura::Window* root_window = window->GetRootWindow();
-    EXPECT_EQ(internal::kShellWindowId_PanelContainer, window->parent()->id());
+    EXPECT_EQ(kShellWindowId_PanelContainer, window->parent()->id());
     DragStart(window);
     gfx::Rect initial_bounds = window->GetBoundsInScreen();
 
@@ -121,8 +113,7 @@ class PanelWindowResizerTest : public test::AshTestBase {
     DragEnd();
 
     EXPECT_FALSE(window_state->panel_attached());
-    EXPECT_EQ(internal::kShellWindowId_DefaultContainer,
-              window->parent()->id());
+    EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
     EXPECT_EQ(root_window, window->GetRootWindow());
 
     DragStart(window);
@@ -135,7 +126,7 @@ class PanelWindowResizerTest : public test::AshTestBase {
     EXPECT_TRUE(window_state->panel_attached());
     EXPECT_EQ(initial_bounds.x(), window->GetBoundsInScreen().x());
     EXPECT_EQ(initial_bounds.y(), window->GetBoundsInScreen().y());
-    EXPECT_EQ(internal::kShellWindowId_PanelContainer, window->parent()->id());
+    EXPECT_EQ(kShellWindowId_PanelContainer, window->parent()->id());
   }
 
   void TestWindowOrder(const std::vector<aura::Window*>& window_order) {
@@ -144,7 +135,7 @@ class PanelWindowResizerTest : public test::AshTestBase {
     for (std::vector<aura::Window*>::const_iterator iter =
          window_order.begin(); iter != window_order.end();
          ++iter, ++panel_index) {
-      LauncherID id = GetLauncherIDForWindow(*iter);
+      ShelfID id = GetShelfIDForWindow(*iter);
       EXPECT_EQ(id, model_->items()[panel_index].id);
     }
   }
@@ -184,7 +175,7 @@ class PanelWindowResizerTest : public test::AshTestBase {
 
  private:
   scoped_ptr<WindowResizer> resizer_;
-  internal::PanelLayoutManager* panel_layout_manager_;
+  PanelLayoutManager* panel_layout_manager_;
   ShelfModel* model_;
   test::TestShelfDelegate* shelf_delegate_;
 
@@ -198,7 +189,7 @@ class PanelWindowResizerTextDirectionTest
   PanelWindowResizerTextDirectionTest() : is_rtl_(GetParam()) {}
   virtual ~PanelWindowResizerTextDirectionTest() {}
 
-  virtual void SetUp() OVERRIDE {
+  void SetUp() override {
     original_locale = l10n_util::GetApplicationLocale(std::string());
     if (is_rtl_)
       base::i18n::SetICUDefaultLocale("he");
@@ -206,7 +197,7 @@ class PanelWindowResizerTextDirectionTest
     ASSERT_EQ(is_rtl_, base::i18n::IsRTL());
   }
 
-  virtual void TearDown() OVERRIDE {
+  void TearDown() override {
     if (is_rtl_)
       base::i18n::SetICUDefaultLocale(original_locale);
     PanelWindowResizerTest::TearDown();
@@ -280,6 +271,38 @@ TEST_F(PanelWindowResizerTest, PanelDetachReattachTop) {
   DetachReattachTest(window.get(), 0, 1);
 }
 
+// Tests that a drag continues when the shelf is hidden. This occurs as part of
+// the animation when switching profiles. http://crbug.com/393047.
+TEST_F(PanelWindowResizerTest, DetachThenHideShelf) {
+  if (!SupportsHostWindowResize())
+    return;
+  scoped_ptr<aura::Window> window(
+      CreatePanelWindow(gfx::Point(0, 0)));
+  wm::WindowState* state = wm::GetWindowState(window.get());
+  gfx::Rect expected_bounds = window->GetBoundsInScreen();
+  expected_bounds.set_y(expected_bounds.y() - 100);
+  DragStart(window.get());
+  DragMove(0, -100);
+  EXPECT_FALSE(state->IsMinimized());
+
+  // Hide the shelf. This minimizes all attached windows but should ignore
+  // the dragged window.
+  ShelfLayoutManager* shelf = RootWindowController::ForWindow(window.get())->
+      shelf()->shelf_layout_manager();
+  shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
+  shelf->UpdateVisibilityState();
+  RunAllPendingInMessageLoop();
+  EXPECT_FALSE(state->IsMinimized());
+  EXPECT_EQ(kShellWindowId_PanelContainer, window->parent()->id());
+  DragEnd();
+
+  // When the drag ends the window should be detached and placed where it was
+  // dragged to.
+  EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
+  EXPECT_FALSE(state->IsMinimized());
+  EXPECT_EQ(expected_bounds.ToString(), window->GetBoundsInScreen().ToString());
+}
+
 TEST_F(PanelWindowResizerTest, PanelDetachReattachMultipleDisplays) {
   if (!SupportsMultipleDisplays())
     return;
@@ -309,7 +332,7 @@ TEST_F(PanelWindowResizerTest, DetachThenDragAcrossDisplays) {
   EXPECT_EQ(initial_bounds.x(), window->GetBoundsInScreen().x());
   EXPECT_EQ(initial_bounds.y() - 100, window->GetBoundsInScreen().y());
   EXPECT_FALSE(wm::GetWindowState(window.get())->panel_attached());
-  EXPECT_EQ(internal::kShellWindowId_DefaultContainer, window->parent()->id());
+  EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
 
   DragStart(window.get());
   DragMove(500, 0);
@@ -318,7 +341,7 @@ TEST_F(PanelWindowResizerTest, DetachThenDragAcrossDisplays) {
   EXPECT_EQ(initial_bounds.x() + 500, window->GetBoundsInScreen().x());
   EXPECT_EQ(initial_bounds.y() - 100, window->GetBoundsInScreen().y());
   EXPECT_FALSE(wm::GetWindowState(window.get())->panel_attached());
-  EXPECT_EQ(internal::kShellWindowId_DefaultContainer, window->parent()->id());
+  EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
 }
 
 TEST_F(PanelWindowResizerTest, DetachAcrossDisplays) {
@@ -338,7 +361,7 @@ TEST_F(PanelWindowResizerTest, DetachAcrossDisplays) {
   EXPECT_EQ(initial_bounds.x() + 500, window->GetBoundsInScreen().x());
   EXPECT_EQ(initial_bounds.y() - 100, window->GetBoundsInScreen().y());
   EXPECT_FALSE(wm::GetWindowState(window.get())->panel_attached());
-  EXPECT_EQ(internal::kShellWindowId_DefaultContainer, window->parent()->id());
+  EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
 }
 
 TEST_F(PanelWindowResizerTest, DetachThenAttachToSecondDisplay) {
@@ -371,7 +394,7 @@ TEST_F(PanelWindowResizerTest, DetachThenAttachToSecondDisplay) {
   // When dropped should move to second display's panel container.
   EXPECT_EQ(root_windows[1], window->GetRootWindow());
   EXPECT_TRUE(wm::GetWindowState(window.get())->panel_attached());
-  EXPECT_EQ(internal::kShellWindowId_PanelContainer, window->parent()->id());
+  EXPECT_EQ(kShellWindowId_PanelContainer, window->parent()->id());
 }
 
 TEST_F(PanelWindowResizerTest, AttachToSecondDisplay) {
@@ -397,26 +420,62 @@ TEST_F(PanelWindowResizerTest, AttachToSecondDisplay) {
   // When dropped should move to second display's panel container.
   EXPECT_EQ(root_windows[1], window->GetRootWindow());
   EXPECT_TRUE(wm::GetWindowState(window.get())->panel_attached());
-  EXPECT_EQ(internal::kShellWindowId_PanelContainer, window->parent()->id());
+  EXPECT_EQ(kShellWindowId_PanelContainer, window->parent()->id());
+}
+
+TEST_F(PanelWindowResizerTest, AttachToSecondFullscreenDisplay) {
+  if (!SupportsMultipleDisplays())
+    return;
+
+  UpdateDisplay("600x400,600x600");
+  aura::Window::Windows root_windows = Shell::GetAllRootWindows();
+  scoped_ptr<aura::Window> window(
+      CreatePanelWindow(gfx::Point(0, 0)));
+  scoped_ptr<aura::Window> fullscreen(
+      CreateTestWindowInShellWithBounds(gfx::Rect(600, 0, 101, 101)));
+  wm::GetWindowState(fullscreen.get())->Activate();
+  const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
+  wm::GetWindowState(fullscreen.get())->OnWMEvent(&event);
+  EXPECT_TRUE(wm::GetWindowState(fullscreen.get())->IsFullscreen());
+
+  gfx::Rect initial_bounds = window->GetBoundsInScreen();
+  EXPECT_EQ(root_windows[0], window->GetRootWindow());
+
+  // Activate and drag the window to the other display's launcher.
+  wm::GetWindowState(window.get())->Activate();
+  DragStart(window.get());
+  DragMove(500, 250);
+  EXPECT_EQ(initial_bounds.x() + 500, window->GetBoundsInScreen().x());
+  EXPECT_GT(window->GetBoundsInScreen().y(),
+            initial_bounds.y() + 200);
+  DragEnd();
+
+  // When dropped should move to second display's panel container.
+  EXPECT_EQ(root_windows[1], window->GetRootWindow());
+  EXPECT_TRUE(wm::GetWindowState(window.get())->panel_attached());
+  EXPECT_EQ(kShellWindowId_PanelContainer, window->parent()->id());
+  EXPECT_TRUE(window->IsVisible());
+  EXPECT_TRUE(wm::GetWindowState(window.get())->IsActive());
+  EXPECT_EQ(initial_bounds.y() + 200, window->GetBoundsInScreen().y());
 }
 
 TEST_F(PanelWindowResizerTest, RevertDragRestoresAttachment) {
   scoped_ptr<aura::Window> window(
       CreatePanelWindow(gfx::Point(0, 0)));
   EXPECT_TRUE(wm::GetWindowState(window.get())->panel_attached());
-  EXPECT_EQ(internal::kShellWindowId_PanelContainer, window->parent()->id());
+  EXPECT_EQ(kShellWindowId_PanelContainer, window->parent()->id());
   DragStart(window.get());
   DragMove(0, -100);
   DragRevert();
   EXPECT_TRUE(wm::GetWindowState(window.get())->panel_attached());
-  EXPECT_EQ(internal::kShellWindowId_PanelContainer, window->parent()->id());
+  EXPECT_EQ(kShellWindowId_PanelContainer, window->parent()->id());
 
   // Detach panel.
   DragStart(window.get());
   DragMove(0, -100);
   DragEnd();
   EXPECT_FALSE(wm::GetWindowState(window.get())->panel_attached());
-  EXPECT_EQ(internal::kShellWindowId_DefaultContainer, window->parent()->id());
+  EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
 
   // Drag back to launcher.
   DragStart(window.get());
@@ -425,7 +484,7 @@ TEST_F(PanelWindowResizerTest, RevertDragRestoresAttachment) {
   // When the drag is reverted it should remain detached.
   DragRevert();
   EXPECT_FALSE(wm::GetWindowState(window.get())->panel_attached());
-  EXPECT_EQ(internal::kShellWindowId_DefaultContainer, window->parent()->id());
+  EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
 }
 
 TEST_F(PanelWindowResizerTest, DragMovesToPanelLayer) {
@@ -433,17 +492,16 @@ TEST_F(PanelWindowResizerTest, DragMovesToPanelLayer) {
   DragStart(window.get());
   DragMove(0, -100);
   DragEnd();
-  EXPECT_EQ(internal::kShellWindowId_DefaultContainer, window->parent()->id());
+  EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
 
   // While moving the panel window should be moved to the panel container.
   DragStart(window.get());
   DragMove(20, 0);
-  EXPECT_EQ(internal::kShellWindowId_PanelContainer, window->parent()->id());
+  EXPECT_EQ(kShellWindowId_PanelContainer, window->parent()->id());
   DragEnd();
 
   // When dropped it should return to the default container.
-  EXPECT_EQ(internal::kShellWindowId_DefaultContainer,
-            window->parent()->id());
+  EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
 }
 
 TEST_P(PanelWindowResizerTextDirectionTest, DragReordersPanelsHorizontal) {
@@ -471,10 +529,10 @@ TEST_P(PanelWindowResizerTransientTest, PanelWithTransientChild) {
   scoped_ptr<aura::Window> window(CreatePanelWindow(gfx::Point(0, 0)));
   scoped_ptr<aura::Window> child(CreateTestWindowInShellWithDelegateAndType(
       NULL, transient_window_type_, 0, gfx::Rect(20, 20, 150, 40)));
-  views::corewm::AddTransientChild(window.get(), child.get());
+  ::wm::AddTransientChild(window.get(), child.get());
   if (window->parent() != child->parent())
     window->parent()->AddChild(child.get());
-  EXPECT_EQ(window.get(), views::corewm::GetTransientParent(child.get()));
+  EXPECT_EQ(window.get(), ::wm::GetTransientParent(child.get()));
 
   // Drag the child to the shelf. Its new position should not be overridden.
   const gfx::Rect attached_bounds(window->GetBoundsInScreen());
@@ -483,7 +541,7 @@ TEST_P(PanelWindowResizerTransientTest, PanelWithTransientChild) {
   DragStart(child.get());
   DragMove(50, dy);
   // While moving the transient child window should be in the panel container.
-  EXPECT_EQ(internal::kShellWindowId_PanelContainer, child->parent()->id());
+  EXPECT_EQ(kShellWindowId_PanelContainer, child->parent()->id());
   DragEnd();
   // Child should move, |window| should not.
   EXPECT_EQ(gfx::Point(20 + 50, 20 + dy).ToString(),
@@ -495,7 +553,7 @@ TEST_P(PanelWindowResizerTransientTest, PanelWithTransientChild) {
   DragStart(child.get());
   DragMove(350, 0);
   // While moving the transient child window should be in the panel container.
-  EXPECT_EQ(internal::kShellWindowId_PanelContainer, child->parent()->id());
+  EXPECT_EQ(kShellWindowId_PanelContainer, child->parent()->id());
   DragEnd();
   // |child| should move, |window| should not.
   EXPECT_EQ(gfx::Point(20 + 50 + 350, 20 + dy).ToString(),
@@ -505,23 +563,23 @@ TEST_P(PanelWindowResizerTransientTest, PanelWithTransientChild) {
   DragStart(window.get());
   DragMove(0, -100);
   // While moving the windows should be in the panel container.
-  EXPECT_EQ(internal::kShellWindowId_PanelContainer, window->parent()->id());
-  EXPECT_EQ(internal::kShellWindowId_PanelContainer, child->parent()->id());
+  EXPECT_EQ(kShellWindowId_PanelContainer, window->parent()->id());
+  EXPECT_EQ(kShellWindowId_PanelContainer, child->parent()->id());
   DragEnd();
   // When dropped they should return to the default container.
-  EXPECT_EQ(internal::kShellWindowId_DefaultContainer, window->parent()->id());
-  EXPECT_EQ(internal::kShellWindowId_DefaultContainer, child->parent()->id());
+  EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
+  EXPECT_EQ(kShellWindowId_DefaultContainer, child->parent()->id());
 
   // While moving the window and child should be moved to the panel container.
   DragStart(window.get());
   DragMove(20, 0);
-  EXPECT_EQ(internal::kShellWindowId_PanelContainer, window->parent()->id());
-  EXPECT_EQ(internal::kShellWindowId_PanelContainer, child->parent()->id());
+  EXPECT_EQ(kShellWindowId_PanelContainer, window->parent()->id());
+  EXPECT_EQ(kShellWindowId_PanelContainer, child->parent()->id());
   DragEnd();
 
   // When dropped they should return to the default container.
-  EXPECT_EQ(internal::kShellWindowId_DefaultContainer, window->parent()->id());
-  EXPECT_EQ(internal::kShellWindowId_DefaultContainer, child->parent()->id());
+  EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
+  EXPECT_EQ(kShellWindowId_DefaultContainer, child->parent()->id());
 }
 
 INSTANTIATE_TEST_CASE_P(LtrRtl, PanelWindowResizerTextDirectionTest,
@@ -532,5 +590,4 @@ INSTANTIATE_TEST_CASE_P(NormalPanelPopup,
                                         ui::wm::WINDOW_TYPE_PANEL,
                                         ui::wm::WINDOW_TYPE_POPUP));
 
-}  // namespace internal
 }  // namespace ash