1ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch// Copyright (c) 2013 The Chromium Authors. All rights reserved.
27d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
37d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// found in the LICENSE file.
47d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
57d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ash/wm/dock/docked_window_resizer.h"
67d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
77d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ash/ash_switches.h"
87d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ash/root_window_controller.h"
95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/screen_util.h"
105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/shelf/shelf.h"
117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ash/shelf/shelf_layout_manager.h"
12f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ash/shelf/shelf_model.h"
137d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ash/shelf/shelf_types.h"
147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ash/shelf/shelf_widget.h"
157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ash/shell.h"
167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ash/shell_window_ids.h"
177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ash/test/ash_test_base.h"
187d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ash/test/cursor_manager_test_api.h"
197d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ash/test/shell_test_api.h"
20a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "ash/test/test_shelf_delegate.h"
217d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ash/wm/dock/docked_window_layout_manager.h"
227d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ash/wm/drag_window_resizer.h"
237d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ash/wm/panels/panel_layout_manager.h"
2468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include "ash/wm/window_state.h"
25ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include "ash/wm/window_util.h"
26a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ash/wm/wm_event.h"
277d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/command_line.h"
287d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ui/aura/client/aura_constants.h"
29a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "ui/aura/client/window_tree_client.h"
30ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include "ui/aura/test/test_window_delegate.h"
31a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/aura/window_event_dispatcher.h"
327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ui/base/hit_test.h"
337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ui/base/ui_base_types.h"
345f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "ui/events/test/event_generator.h"
357d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ui/views/widget/widget.h"
366e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "ui/wm/core/coordinate_conversion.h"
37a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/wm/core/window_util.h"
387d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
397d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)namespace ash {
407d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
417d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)class DockedWindowResizerTest
427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    : public test::AshTestBase,
435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      public testing::WithParamInterface<ui::wm::WindowType> {
447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) public:
457d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  DockedWindowResizerTest() : model_(NULL), window_type_(GetParam()) {}
467d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  virtual ~DockedWindowResizerTest() {}
477d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
487d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  virtual void SetUp() OVERRIDE {
497d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    AshTestBase::SetUp();
507d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    UpdateDisplay("600x400");
517d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    test::ShellTestApi test_api(Shell::GetInstance());
52f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    model_ = test_api.shelf_model();
537d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  }
547d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
557d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  virtual void TearDown() OVERRIDE {
567d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    AshTestBase::TearDown();
577d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  }
587d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
597d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) protected:
607d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  enum DockedEdge {
617d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    DOCKED_EDGE_NONE,
627d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    DOCKED_EDGE_LEFT,
637d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    DOCKED_EDGE_RIGHT,
647d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  };
657d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
668bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  int ideal_width() const { return DockedWindowLayoutManager::kIdealWidth; }
678bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  int min_dock_gap() const { return DockedWindowLayoutManager::kMinDockGap; }
688bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  int max_width() const { return DockedWindowLayoutManager::kMaxDockWidth; }
698bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  int docked_width(const DockedWindowLayoutManager* layout_manager) const {
708bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    return layout_manager->docked_width_;
718bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  }
728bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  int docked_alignment(const DockedWindowLayoutManager* layout_manager) const {
738bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    return layout_manager->alignment_;
748bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  }
757d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  aura::Window* CreateTestWindow(const gfx::Rect& bounds) {
767d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    aura::Window* window = CreateTestWindowInShellWithDelegateAndType(
77ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch        &delegate_,
787d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        window_type_,
797d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        0,
807d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        bounds);
815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    if (window_type_ == ui::wm::WINDOW_TYPE_PANEL) {
82a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      test::TestShelfDelegate* shelf_delegate =
83a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)          test::TestShelfDelegate::instance();
845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      shelf_delegate->AddShelfItem(window);
85c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      PanelLayoutManager* manager = static_cast<PanelLayoutManager*>(
86c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch          Shell::GetContainer(window->GetRootWindow(),
87c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch                              kShellWindowId_PanelContainer)->layout_manager());
887d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      manager->Relayout();
897d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    }
907d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    return window;
917d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  }
927d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
93a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  aura::Window* CreateModalWindow(const gfx::Rect& bounds) {
94a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    aura::Window* window = new aura::Window(&delegate_);
95a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM);
965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    window->SetType(ui::wm::WINDOW_TYPE_NORMAL);
975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    window->Init(aura::WINDOW_LAYER_TEXTURED);
98a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    window->Show();
99a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
100a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    if (bounds.IsEmpty()) {
101a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      ParentWindowInPrimaryRootWindow(window);
102a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    } else {
103a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      gfx::Display display =
104a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)          Shell::GetScreen()->GetDisplayMatching(bounds);
105a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      aura::Window* root = ash::Shell::GetInstance()->display_controller()->
106a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)          GetRootWindowForDisplayId(display.id());
107a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      gfx::Point origin = bounds.origin();
1086e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      ::wm::ConvertPointFromScreen(root, &origin);
109a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      window->SetBounds(gfx::Rect(origin, bounds.size()));
110a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      aura::client::ParentWindowWithContext(window, root, bounds);
111a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    }
112a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return window;
113a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
114a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
1157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  static WindowResizer* CreateSomeWindowResizer(
1167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      aura::Window* window,
1177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      const gfx::Point& point_in_parent,
1187d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      int window_component) {
1197d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    return CreateWindowResizer(
1207d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        window,
1217d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        point_in_parent,
1227d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        window_component,
1237d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        aura::client::WINDOW_MOVE_SOURCE_MOUSE).release();
1247d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  }
1257d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
1267d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  void DragStart(aura::Window* window) {
127f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    DragStartAtOffsetFromWindowOrigin(window, 0, 0);
1287d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  }
1297d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
130f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  void DragStartAtOffsetFromWindowOrigin(aura::Window* window,
131d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                                         int dx, int dy) {
1327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    initial_location_in_parent_ =
1337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        window->bounds().origin() + gfx::Vector2d(dx, dy);
1347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    resizer_.reset(CreateSomeWindowResizer(window,
1357d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                                           initial_location_in_parent_,
1367d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                                           HTCAPTION));
1377d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    ASSERT_TRUE(resizer_.get());
1387d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  }
1397d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
140f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  void ResizeStartAtOffsetFromWindowOrigin(aura::Window* window,
141d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                                           int dx, int dy,
142ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                                           int window_component) {
143ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    initial_location_in_parent_ =
144ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch        window->bounds().origin() + gfx::Vector2d(dx, dy);
145ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    resizer_.reset(CreateSomeWindowResizer(window,
146ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                                           initial_location_in_parent_,
147ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                                           window_component));
148ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    ASSERT_TRUE(resizer_.get());
149ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  }
150ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
1517d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  void DragMove(int dx, int dy) {
1527d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    resizer_->Drag(initial_location_in_parent_ + gfx::Vector2d(dx, dy), 0);
1537d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  }
1547d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
1557d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  void DragEnd() {
1565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    resizer_->CompleteDrag();
1577d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    resizer_.reset();
1587d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  }
1597d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
1607d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  void DragRevert() {
1617d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    resizer_->RevertDrag();
1627d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    resizer_.reset();
1637d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  }
1647d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
1657d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Panels are parented by panel container during drags.
1663551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // All other windows that are tested here are parented by dock container
1673551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // during drags.
1683551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  int CorrectContainerIdDuringDrag() {
1695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    if (window_type_ == ui::wm::WINDOW_TYPE_PANEL)
170c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      return kShellWindowId_PanelContainer;
171c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    return kShellWindowId_DockedContainer;
1727d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  }
1737d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
1747d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Test dragging the window vertically (to detach if it is a panel) and then
1757d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // horizontally to the edge with an added offset from the edge of |dx|.
1767d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  void DragRelativeToEdge(DockedEdge edge,
1777d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                          aura::Window* window,
1787d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                          int dx) {
1797d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    DragVerticallyAndRelativeToEdge(
1807d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        edge,
1817d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        window,
1825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        dx,
1835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        window_type_ == ui::wm::WINDOW_TYPE_PANEL ? -100 : 20,
1845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        25,
1855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        5);
1867d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  }
1877d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
188ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  void DragToVerticalPositionAndToEdge(DockedEdge edge,
189ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                                       aura::Window* window,
190ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                                       int y) {
191ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    DragToVerticalPositionRelativeToEdge(edge, window, 0, y);
192ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  }
193ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
194ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  void DragToVerticalPositionRelativeToEdge(DockedEdge edge,
195ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                                            aura::Window* window,
196ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                                            int dx,
197ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                                            int y) {
1987d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    gfx::Rect initial_bounds = window->GetBoundsInScreen();
199d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    DragVerticallyAndRelativeToEdge(edge,
200d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                                    window,
201d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                                    dx, y - initial_bounds.y(),
202d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                                    25, 5);
2037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  }
2047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
2057d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Detach if our window is a panel, then drag it vertically by |dy| and
2067d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // horizontally to the edge with an added offset from the edge of |dx|.
2077d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  void DragVerticallyAndRelativeToEdge(DockedEdge edge,
2087d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                                       aura::Window* window,
209d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                                       int dx, int dy,
210d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                                       int grab_x, int grab_y) {
2117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    gfx::Rect initial_bounds = window->GetBoundsInScreen();
2127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // avoid snap by clicking away from the border
213f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(window,
214d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                                                              grab_x, grab_y));
2157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
216d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    gfx::Rect work_area =
217d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)        Shell::GetScreen()->GetDisplayNearestWindow(window).work_area();
218d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    gfx::Point initial_location_in_screen = initial_location_in_parent_;
2196e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    ::wm::ConvertPointToScreen(window->parent(), &initial_location_in_screen);
2207d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // Drag the window left or right to the edge (or almost to it).
2217d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    if (edge == DOCKED_EDGE_LEFT)
222d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      dx += work_area.x() - initial_location_in_screen.x();
2237d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    else if (edge == DOCKED_EDGE_RIGHT)
224d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      dx += work_area.right() - 1 - initial_location_in_screen.x();
225d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    DragMove(dx, dy);
2263551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id());
2277d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // Release the mouse and the panel should be attached to the dock.
2287d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    DragEnd();
2297d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
2307d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // x-coordinate can get adjusted by snapping or sticking.
231bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch    // y-coordinate could be changed by possible automatic layout if docked.
232c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    if (window->parent()->id() != kShellWindowId_DockedContainer &&
23368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)        !wm::GetWindowState(window)->HasRestoreBounds()) {
234bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch      EXPECT_EQ(initial_bounds.y() + dy, window->GetBoundsInScreen().y());
235d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    }
2367d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  }
2377d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
2385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool test_panels() const { return window_type_ == ui::wm::WINDOW_TYPE_PANEL; }
2395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  aura::test::TestWindowDelegate* delegate() {
2415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return &delegate_;
2427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  }
2437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
244f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  const gfx::Point& initial_location_in_parent() const {
245f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    return initial_location_in_parent_;
246f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
247f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
2487d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) private:
2497d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  scoped_ptr<WindowResizer> resizer_;
250f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ShelfModel* model_;
2515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ui::wm::WindowType window_type_;
252ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  aura::test::TestWindowDelegate delegate_;
2537d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
2547d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Location at start of the drag in |window->parent()|'s coordinates.
2557d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  gfx::Point initial_location_in_parent_;
2567d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
2577d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(DockedWindowResizerTest);
2587d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)};
2597d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
2607d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Verifies a window can be dragged and attached to the dock.
2617d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_P(DockedWindowResizerTest, AttachRightPrecise) {
262eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  if (!SupportsHostWindowResize())
263eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    return;
264eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
2657d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
2667d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0);
2677d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
268a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // The window should be docked at the right edge.
2695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
2707d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)            window->GetBoundsInScreen().right());
271c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
2727d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
2737d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
2747d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Verifies a window can be dragged and attached to the dock
275d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// even if pointer overshoots the screen edge by a few pixels (sticky edge)
2767d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_P(DockedWindowResizerTest, AttachRightOvershoot) {
277eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  if (!SupportsHostWindowResize())
278eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    return;
279eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
2807d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
2817d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), +4);
2827d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
283a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // The window should be docked at the right edge.
2845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
2857d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)            window->GetBoundsInScreen().right());
286c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
2877d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
2887d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
289d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// Verifies a window can be dragged and then if a pointer is not quite reaching
290d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// the screen edge the window does not get docked and stays in the desktop.
2917d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_P(DockedWindowResizerTest, AttachRightUndershoot) {
292eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  if (!SupportsHostWindowResize())
293eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    return;
294eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
2957d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
296d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Grabbing at 70px ensures that at least 30% of the window is in screen,
297d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // otherwise the window would be adjusted in
298d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // WorkspaceLayoutManager::AdjustWindowBoundsWhenAdded.
299d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  const int kGrabOffsetX = 70;
300d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  const int kUndershootBy = 1;
301d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  DragVerticallyAndRelativeToEdge(DOCKED_EDGE_RIGHT,
302d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                                  window.get(),
303d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                                  -kUndershootBy, test_panels() ? -100 : 20,
304d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                                  kGrabOffsetX, 5);
305d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
306d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // The window right should be past the screen edge but not docked.
307d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Initial touch point is 70px to the right which helps to find where the edge
308d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // should be.
3095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right() +
310d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)            window->bounds().width() - kGrabOffsetX - kUndershootBy - 1,
3117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)            window->GetBoundsInScreen().right());
312c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
3137d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
3147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
3157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Verifies a window can be dragged and attached to the dock.
3167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_P(DockedWindowResizerTest, AttachLeftPrecise) {
317eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  if (!SupportsHostWindowResize())
318eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    return;
319eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
3207d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
3217d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  DragRelativeToEdge(DOCKED_EDGE_LEFT, window.get(), 0);
3227d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
323a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // The window should be docked at the left edge.
3245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().x(),
3257d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)            window->GetBoundsInScreen().x());
326c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
3277d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
3287d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
3297d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Verifies a window can be dragged and attached to the dock
330d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// even if pointer overshoots the screen edge by a few pixels (sticky edge)
3317d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_P(DockedWindowResizerTest, AttachLeftOvershoot) {
332eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  if (!SupportsHostWindowResize())
333eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    return;
334eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
3357d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
3367d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  DragRelativeToEdge(DOCKED_EDGE_LEFT, window.get(), -4);
3377d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
338a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // The window should be docked at the left edge.
3395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().x(),
3407d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)            window->GetBoundsInScreen().x());
341c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
3427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
3437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
344d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// Verifies a window can be dragged and then if a pointer is not quite reaching
345d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// the screen edge the window does not get docked and stays in the desktop.
3467d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_P(DockedWindowResizerTest, AttachLeftUndershoot) {
347eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  if (!SupportsHostWindowResize())
348eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    return;
349eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
3507d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
351f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  gfx::Rect initial_bounds(window->bounds());
3527d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  DragRelativeToEdge(DOCKED_EDGE_LEFT, window.get(), 1);
3537d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
354f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // The window should be crossing the screen edge but not docked.
355f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  int expected_x = initial_bounds.x() - initial_location_in_parent().x() + 1;
356f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(expected_x, window->GetBoundsInScreen().x());
357c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
3587d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
3597d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
3607d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Dock on the right side, change shelf alignment, check that windows move to
3617d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// the opposite side.
3627d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_P(DockedWindowResizerTest, AttachRightChangeShelf) {
363eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  if (!SupportsHostWindowResize())
364eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    return;
365eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
3667d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
3677d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0);
3687d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
369a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // The window should be docked at the right edge.
3705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
3717d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)            window->GetBoundsInScreen().right());
372c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
3737d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
3747d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // set launcher shelf to be aligned on the right
3757d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  ash::Shell* shell = ash::Shell::GetInstance();
3767d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  shell->SetShelfAlignment(SHELF_ALIGNMENT_RIGHT,
3777d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                           shell->GetPrimaryRootWindow());
3787d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // The window should have moved and get attached to the left dock.
3795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().x(),
3807d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)            window->GetBoundsInScreen().x());
381c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
3827d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
3837d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // set launcher shelf to be aligned on the left
3847d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  shell->SetShelfAlignment(SHELF_ALIGNMENT_LEFT,
3857d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                           shell->GetPrimaryRootWindow());
3867d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // The window should have moved and get attached to the right edge.
3875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
3887d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)            window->GetBoundsInScreen().right());
389c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
3907d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
3917d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // set launcher shelf to be aligned at the bottom
3927d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  shell->SetShelfAlignment(SHELF_ALIGNMENT_BOTTOM,
3937d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                           shell->GetPrimaryRootWindow());
3947d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // The window should stay in the right edge.
3955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
3967d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)            window->GetBoundsInScreen().right());
397c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
3987d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
3997d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
4007d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Dock on the right side, try to undock, then drag more to really undock
4017d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_P(DockedWindowResizerTest, AttachTryDetach) {
402eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  if (!SupportsHostWindowResize())
403eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    return;
404eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
40568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  scoped_ptr<aura::Window> window(CreateTestWindow(
4068bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)      gfx::Rect(0, 0, ideal_width() + 10, 201)));
4077d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0);
4087d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
409a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // The window should be docked at the right edge.
41068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // Its width should shrink to ideal width.
4115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
4127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)            window->GetBoundsInScreen().right());
4138bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(ideal_width(), window->GetBoundsInScreen().width());
414c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
4157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
4163551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Try to detach by dragging left less than kSnapToDockDistance.
4173551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // The window should stay docked.
418f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(
41968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)      window.get(), 10, 0));
4203551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  DragMove(-4, -10);
4217d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Release the mouse and the window should be still attached to the dock.
4227d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  DragEnd();
4237d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
4247d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // The window should be still attached to the right edge.
4255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
4267d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)            window->GetBoundsInScreen().right());
427c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
4287d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
4293551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Try to detach by dragging left by kSnapToDockDistance or more.
4303551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // The window should get undocked.
43168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  const int left_edge = window->bounds().x();
4325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(
4335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      window.get(), 10, 0));
4345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DragMove(-32, -10);
4355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Release the mouse and the window should be no longer attached to the dock.
4365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DragEnd();
4375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
4385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // The window should be floating on the desktop again and moved to the left.
4395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(left_edge - 32, window->GetBoundsInScreen().x());
440c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
4415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
4425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
4435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Dock on the right side, and undock by dragging the right edge of the window
4445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// header. This test is useful because both the position of the dragged window
4455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// and the position of the mouse are used in determining whether a window should
4465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// be undocked.
4475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_P(DockedWindowResizerTest, AttachTryDetachDragRightEdgeOfHeader) {
4485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!SupportsHostWindowResize())
4495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
4505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
4515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  scoped_ptr<aura::Window> window(CreateTestWindow(
4525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      gfx::Rect(0, 0, ideal_width() + 10, 201)));
4535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0);
4545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
4555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // The window should be docked at the right edge.
4565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Its width should shrink to ideal width.
4575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
4585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            window->GetBoundsInScreen().right());
4595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(ideal_width(), window->GetBoundsInScreen().width());
460c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
4615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
4625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Try to detach by dragging left less than kSnapToDockDistance.
4635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // The window should stay docked.
4645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(
4655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      window.get(), ideal_width() - 10, 0));
4665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DragMove(-4, -10);
4675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Release the mouse and the window should be still attached to the dock.
4685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DragEnd();
4695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
4705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // The window should be still attached to the right edge.
4715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
4725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            window->GetBoundsInScreen().right());
473c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
4745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
4755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Try to detach by dragging left by kSnapToDockDistance or more.
4765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // The window should get undocked.
4775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const int left_edge = window->bounds().x();
4785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(
4795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      window.get(), ideal_width() - 10, 0));
4807d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  DragMove(-32, -10);
4817d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Release the mouse and the window should be no longer attached to the dock.
4827d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  DragEnd();
4837d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
48468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // The window should be floating on the desktop again and moved to the left.
48568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  EXPECT_EQ(left_edge - 32, window->GetBoundsInScreen().x());
486c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
4877d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
4887d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
4897d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Minimize a docked window, then restore it and check that it is still docked.
4907d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_P(DockedWindowResizerTest, AttachMinimizeRestore) {
491eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  if (!SupportsHostWindowResize())
492eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    return;
493eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
4947d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
4957d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0);
4967d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
497a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // The window should be docked at the right edge.
4985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
4997d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)            window->GetBoundsInScreen().right());
500c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
5017d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
5024e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  wm::WindowState* window_state = wm::GetWindowState(window.get());
5037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Minimize the window, it should be hidden.
5044e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  window_state->Minimize();
5057d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  RunAllPendingInMessageLoop();
5067d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  EXPECT_FALSE(window->IsVisible());
5074e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  EXPECT_TRUE(window_state->IsMinimized());
5087d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Restore the window; window should be visible.
5094e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  window_state->Restore();
5107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  RunAllPendingInMessageLoop();
5117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  EXPECT_TRUE(window->IsVisible());
512a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  EXPECT_TRUE(window_state->IsNormalStateType());
5134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
5144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
5154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Maximize a docked window and check that it is maximized and no longer docked.
5164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)TEST_P(DockedWindowResizerTest, AttachMaximize) {
5174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  if (!SupportsHostWindowResize())
5184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    return;
5194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
5204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
5214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0);
5224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
523a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // The window should be docked at the right edge.
5245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
5254e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)            window->GetBoundsInScreen().right());
526c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
5274e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
5284e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  wm::WindowState* window_state = wm::GetWindowState(window.get());
5294e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Maximize the window, it should get undocked and maximized in a desktop.
5304e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  window_state->Maximize();
5314e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  RunAllPendingInMessageLoop();
5324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  EXPECT_TRUE(window->IsVisible());
5334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  EXPECT_TRUE(window_state->IsMaximized());
534c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
5357d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
5367d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
5377d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Dock two windows, undock one, check that the other one is still docked.
5384e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)TEST_P(DockedWindowResizerTest, AttachTwoWindows) {
539ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  if (!SupportsHostWindowResize())
540ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    return;
541a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  UpdateDisplay("600x600");
542ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
5437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
5447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
545ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20);
546ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 50);
5477d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
548a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Docking second window should not minimize the first.
549a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  wm::WindowState* window_state1 = wm::GetWindowState(w1.get());
550a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  EXPECT_FALSE(window_state1->IsMinimized());
551a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
552a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Both windows should be docked at the right edge.
5535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
5547d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)            w1->GetBoundsInScreen().right());
555c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
5567d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
5575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(w2->GetRootWindow()->GetBoundsInScreen().right(),
5587d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)            w2->GetBoundsInScreen().right());
559c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w2->parent()->id());
5607d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
561bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch  // Detach by dragging left (should get undocked).
56268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  const int left_edge = w2->bounds().x();
5637d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(DragStart(w2.get()));
564bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch  // Drag up as well to avoid attaching panels to launcher shelf.
565bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch  DragMove(-32, -100);
5667d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Release the mouse and the window should be no longer attached to the edge.
5677d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  DragEnd();
5687d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
5697d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // The first window should be still docked.
570a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  EXPECT_FALSE(window_state1->IsMinimized());
5715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
5727d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)            w1->GetBoundsInScreen().right());
573c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
5747d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
57568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  // The window should be floating on the desktop again and moved to the left.
57668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  EXPECT_EQ(left_edge - 32, w2->GetBoundsInScreen().x());
577c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DefaultContainer, w2->parent()->id());
5787d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
5797d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
5804e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Create two windows, dock one and change shelf to auto-hide.
5814e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)TEST_P(DockedWindowResizerTest, AttachOneAutoHideShelf) {
5824e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  if (!SupportsHostWindowResize())
5834e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    return;
5844e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
5854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
5864e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20);
5874e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
588a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // w1 should be docked at the right edge.
5895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
5904e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)            w1->GetBoundsInScreen().right());
591c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
5924e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
5934e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegateAndType(
5945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      NULL, ui::wm::WINDOW_TYPE_NORMAL, 0, gfx::Rect(20, 20, 150, 20)));
5954e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  wm::GetWindowState(w2.get())->Maximize();
596c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DefaultContainer, w2->parent()->id());
5974e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  EXPECT_TRUE(wm::GetWindowState(w2.get())->IsMaximized());
5984e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
5994e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  gfx::Rect work_area =
6004e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      Shell::GetScreen()->GetDisplayNearestWindow(w1.get()).work_area();
6014e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  DockedWindowLayoutManager* manager =
6024e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager());
6034e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
6044e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Docked window should be centered vertically in the work area.
6054e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  EXPECT_EQ(work_area.CenterPoint().y(), w1->bounds().CenterPoint().y());
6064e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Docked background should extend to the bottom of work area.
6074e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  EXPECT_EQ(work_area.bottom(), manager->docked_bounds().bottom());
6084e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
6094e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // set launcher shelf to be aligned on the right
6104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  ash::Shell* shell = ash::Shell::GetInstance();
6114e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  shell->SetShelfAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS,
6124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)                                  shell->GetPrimaryRootWindow());
6134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  work_area =
6144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)        Shell::GetScreen()->GetDisplayNearestWindow(w1.get()).work_area();
6154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Docked window should be centered vertically in the work area.
6164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  EXPECT_EQ(work_area.CenterPoint().y(), w1->bounds().CenterPoint().y());
6174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Docked background should extend to the bottom of work area.
6184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  EXPECT_EQ(work_area.bottom(), manager->docked_bounds().bottom());
6194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
6204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
6217d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Dock one window, try to dock another window on the opposite side (should not
6227d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// dock).
6234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)TEST_P(DockedWindowResizerTest, AttachOnTwoSides) {
624ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  if (!SupportsHostWindowResize())
625ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    return;
626ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
6277d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
6287d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
629ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20);
630f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  gfx::Rect initial_bounds(w2->bounds());
631ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DragToVerticalPositionAndToEdge(DOCKED_EDGE_LEFT, w2.get(), 50);
6327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
633a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // The first window should be docked at the right edge.
6345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
6357d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)            w1->GetBoundsInScreen().right());
636c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
6377d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
6387d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // The second window should be near the left edge but not snapped.
639d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Normal window will get side-maximized while panels will not.
640f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  int expected_x = test_panels() ?
641f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      (initial_bounds.x() - initial_location_in_parent().x()) : 0;
642f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(expected_x, w2->GetBoundsInScreen().x());
643c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DefaultContainer, w2->parent()->id());
6447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
6457d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
646f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Tests that reverting a drag restores docked state if a window was docked.
6477d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_P(DockedWindowResizerTest, RevertDragRestoresAttachment) {
648eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  if (!SupportsHostWindowResize())
649eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    return;
650eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
6517d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
6527d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0);
6537d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
654a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // The window should be docked at the right edge.
6555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
6567d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)            window->GetBoundsInScreen().right());
657c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
6587d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
6597d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Drag the window out but revert the drag
6607d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(DragStart(window.get()));
6617d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  DragMove(-50, 0);
6627d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  DragRevert();
663c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
6647d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
6657d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Detach window.
6667d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(DragStart(window.get()));
6677d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  DragMove(-50, 0);
6687d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  DragEnd();
669c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
6707d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
6717d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
672f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Tests that reverting drag restores undocked state if a window was not docked.
673f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)TEST_P(DockedWindowResizerTest, RevertDockedDragRevertsAttachment) {
674f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  if (!SupportsHostWindowResize())
675f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    return;
676f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
6775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  aura::Window* dock_container = Shell::GetContainer(
6785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      window->GetRootWindow(),
6795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      kShellWindowId_DockedContainer);
6805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DockedWindowLayoutManager* manager =
6815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      static_cast<DockedWindowLayoutManager*>(dock_container->layout_manager());
682f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  int previous_container_id = window->parent()->id();
683f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Drag the window out but revert the drag
684f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(DragStart(window.get()));
685f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DragMove(-50 - window->bounds().x(), 50 - window->bounds().y());
686f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id());
687f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DragRevert();
688f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(previous_container_id, window->parent()->id());
6895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_NONE, docked_alignment(manager));
6905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
6915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Drag a window to the left so that it overlaps the screen edge.
6925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(
6935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      window.get(),
6945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      window->bounds().width()/2 + 10,
6955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      0));
6965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DragMove(-50 - window->bounds().x(), 50 - window->bounds().y());
6975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DragEnd();
6985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // The window now overlaps the left screen edge but is not docked.
6995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
7005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_NONE, docked_alignment(manager));
7015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_LT(window->bounds().x(), 0);
7025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_GT(window->bounds().right(), 0);
7035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Drag the window further left and revert the drag.
7055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(
7065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      window.get(),
7075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      window->bounds().width()/2 + 10,
7085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      0));
7095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DragMove(-10, 10);
7105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DragRevert();
7115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // The window should be in default container and not docked.
7125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
7135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Docked area alignment should be cleared.
7145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_NONE, docked_alignment(manager));
715f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
716f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
7177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Move a docked window to the second display
7187d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_P(DockedWindowResizerTest, DragAcrossDisplays) {
7197d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (!SupportsMultipleDisplays())
7207d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    return;
7217d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
7227d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  UpdateDisplay("800x800,800x800");
723f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  aura::Window::Windows root_windows = Shell::GetAllRootWindows();
724d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  EXPECT_EQ(2, static_cast<int>(root_windows.size()));
7257d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
7267d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  gfx::Rect initial_bounds = window->GetBoundsInScreen();
7277d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  EXPECT_EQ(root_windows[0], window->GetRootWindow());
7287d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
7297d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0);
730a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // The window should be docked at the right edge.
7315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
7327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)            window->GetBoundsInScreen().right());
733c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
7347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
735d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Try dragging to the right - enough to get it peeking at the other screen
736d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // but not enough to land in the other screen.
737d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // The window should stay on the left screen.
7387d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(DragStart(window.get()));
739d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  DragMove(100, 0);
7403551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id());
7417d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  DragEnd();
7425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
7437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)            window->GetBoundsInScreen().right());
744c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
7457d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  EXPECT_EQ(root_windows[0], window->GetRootWindow());
7467d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
7477d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Undock and move to the right - enough to get the mouse pointer past the
7487d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // edge of the screen and into the second screen. The window should now be
7497d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // in the second screen and not docked.
750f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(
7517d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      window.get(),
7527d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      window->bounds().width()/2 + 10,
7537d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      0));
7547d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  DragMove(window->bounds().width()/2 - 5, 0);
7553551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id());
7567d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  DragEnd();
7575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_NE(window->GetRootWindow()->GetBoundsInScreen().right(),
7587d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)            window->GetBoundsInScreen().right());
759c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
7607d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  EXPECT_EQ(root_windows[1], window->GetRootWindow());
7617d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
762d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Keep dragging it to the right until its left edge touches the screen edge.
763d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // The window should now be in the second screen and not docked.
764f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(
7657d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      window.get(),
7667d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      window->bounds().width()/2 + 10,
7677d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      0));
7687d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  DragMove(window->GetRootWindow()->GetBoundsInScreen().x() -
7697d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)           window->GetBoundsInScreen().x(),
7707d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)           0);
7713551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id());
7727d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  DragEnd();
7737d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().x(),
7747d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)            window->GetBoundsInScreen().x());
775c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
7767d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  EXPECT_EQ(root_windows[1], window->GetRootWindow());
7777d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
7787d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
779ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch// Dock two windows, undock one.
7802385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch// Test the docked windows area size and default container resizing.
7814e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)TEST_P(DockedWindowResizerTest, AttachTwoWindowsDetachOne) {
782ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  if (!SupportsHostWindowResize())
783ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    return;
7848bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  UpdateDisplay("600x600");
785ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
786ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
787ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 201)));
788ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Work area should cover the whole screen.
7895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w2.get()).width(),
7905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            ScreenUtil::GetDisplayWorkAreaBoundsInParent(w2.get()).width());
791ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
792ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20);
793a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // A window should be docked at the right edge.
7945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
795ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch            w1->GetBoundsInScreen().right());
796c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
797ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DockedWindowLayoutManager* manager =
798ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager());
7998bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
8008bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(w1->bounds().width(), docked_width(manager));
801ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
802f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 100);
803a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Both windows should now be docked at the right edge.
8045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(w2->GetRootWindow()->GetBoundsInScreen().right(),
805ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch            w2->GetBoundsInScreen().right());
806c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w2->parent()->id());
807ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Dock width should be set to a wider window.
8088bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
809ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  EXPECT_EQ(std::max(w1->bounds().width(), w2->bounds().width()),
8108bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)            docked_width(manager));
811ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
812ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Try to detach by dragging left a bit (should not get undocked).
813ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // This would normally detach a single docked window but since we have another
814ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // window and the mouse pointer does not leave the dock area the window
815ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // should stay docked.
816f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(w2.get(), 60, 0));
817558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  // Drag up as well as left to avoid attaching panels to launcher shelf.
818558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  DragMove(-40, -40);
819ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Release the mouse and the window should be still attached to the edge.
820ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DragEnd();
821ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
822ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // The first window should be still docked.
8235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
824ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch            w1->GetBoundsInScreen().right());
825c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
826ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
827ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // The second window should be still docked.
8285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(w2->GetRootWindow()->GetBoundsInScreen().right(),
829ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch            w2->GetBoundsInScreen().right());
830c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w2->parent()->id());
831ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
832ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Detach by dragging left more (should get undocked).
83368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  const int left_edge = w2->bounds().x();
834f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(
835ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      w2.get(),
836ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      w2->bounds().width()/2 + 10,
837ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      0));
838bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch  // Drag up as well to avoid attaching panels to launcher shelf.
83968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  const int drag_x = -(w2->bounds().width()/2 + 20);
84068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  DragMove(drag_x, -100);
841ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Release the mouse and the window should be no longer attached to the edge.
842ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DragEnd();
843ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
8442385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch  // The second window should be floating on the desktop again.
84568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  EXPECT_EQ(left_edge + drag_x, w2->bounds().x());
846c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DefaultContainer, w2->parent()->id());
847ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Dock width should be set to remaining single docked window.
848c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
8498bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
8508bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(w1->bounds().width(), docked_width(manager));
851ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch}
852ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
853d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// Dock one of the windows. Maximize other testing desktop resizing.
8544e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)TEST_P(DockedWindowResizerTest, AttachWindowMaximizeOther) {
855ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  if (!SupportsHostWindowResize())
856ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    return;
857ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
858ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
859ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 201)));
860ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Work area should cover the whole screen.
8615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w2.get()).width(),
8625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            ScreenUtil::GetDisplayWorkAreaBoundsInParent(w2.get()).width());
863ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
864ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20);
865a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // A window should be docked at the right edge.
8665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
867ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch            w1->GetBoundsInScreen().right());
868c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
869ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DockedWindowLayoutManager* manager =
870ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager());
8718bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
8728bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(w1->bounds().width(), docked_width(manager));
873ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
874f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(w2.get(), 25, 5));
8755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DragMove(w2->GetRootWindow()->bounds().width()
876d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)           -w2->bounds().width()
877d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)           -(w2->bounds().width()/2 + 20)
878d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)           -w2->bounds().x(),
879d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)           50 - w2->bounds().y());
880d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  DragEnd();
881ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // The first window should be still docked.
8825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
883ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch            w1->GetBoundsInScreen().right());
884c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
885ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
8862385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch  // The second window should be floating on the desktop.
8875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(w2->GetRootWindow()->GetBoundsInScreen().right() -
888ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch            (w2->bounds().width()/2 + 20),
889ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch            w2->GetBoundsInScreen().right());
890c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DefaultContainer, w2->parent()->id());
891ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Dock width should be set to remaining single docked window.
892c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
8938bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
8948bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(w1->bounds().width(), docked_width(manager));
8952385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch  // Desktop work area should now shrink.
8965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w2.get()).width() -
8978bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)            docked_width(manager) - min_dock_gap(),
8985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            ScreenUtil::GetDisplayWorkAreaBoundsInParent(w2.get()).width());
899ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
900ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Maximize the second window - Maximized area should be shrunk.
901ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  const gfx::Rect restored_bounds = w2->bounds();
90268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  wm::WindowState* w2_state = wm::GetWindowState(w2.get());
90368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  w2_state->Maximize();
9045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w2.get()).width() -
9058bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)            docked_width(manager) - min_dock_gap(),
906ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch            w2->bounds().width());
907ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
908ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Detach the first window (this should require very little drag).
909ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  ASSERT_NO_FATAL_FAILURE(DragStart(w1.get()));
9108bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
911ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DragMove(-35, 10);
9123551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Alignment is set to "NONE" when drag starts.
9138bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_NONE, docked_alignment(manager));
914ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Release the mouse and the window should be no longer attached to the edge.
915ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DragEnd();
9168bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_NONE, docked_alignment(manager));
9172385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch  // Dock should get shrunk and desktop should get expanded.
918c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DefaultContainer, w1->parent()->id());
919c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DefaultContainer, w2->parent()->id());
9208bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_NONE, docked_alignment(manager));
9218bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(0, docked_width(manager));
922ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // The second window should now get resized and take up the whole screen.
9235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w2.get()).width(),
924ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch            w2->bounds().width());
925ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
926ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Dock the first window to the left edge.
927ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Click at an offset from origin to prevent snapping.
928f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(w1.get(), 10, 0));
929d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Drag left to get pointer touching the screen edge.
930d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  DragMove(-w1->bounds().x() - 10, 0);
931ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Alignment set to "NONE" during the drag of the window when none are docked.
9328bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_NONE, docked_alignment(manager));
933ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Release the mouse and the window should be now attached to the edge.
934ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DragEnd();
9352385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch  // Dock should get expanded and desktop should get shrunk.
936c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
9378bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_LEFT, docked_alignment(manager));
9388bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(w1->bounds().width(), docked_width(manager));
9392385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch  // Second window should still be in the desktop.
940c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DefaultContainer, w2->parent()->id());
941ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Maximized window should be shrunk.
9425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w2.get()).width() -
9438bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)            docked_width(manager) - min_dock_gap(),
944ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch            w2->bounds().width());
945ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
946ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Unmaximize the second window.
94768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)  w2_state->Restore();
948ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Its bounds should get restored.
949ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  EXPECT_EQ(restored_bounds, w2->bounds());
950ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch}
951ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
9522385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch// Dock one window. Test the sticky behavior near screen or desktop edge.
9534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)TEST_P(DockedWindowResizerTest, AttachOneTestSticky) {
954ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  if (!SupportsHostWindowResize())
955ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    return;
956ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
957ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
958ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 201)));
959ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Work area should cover the whole screen.
9605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w2.get()).width(),
9615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            ScreenUtil::GetDisplayWorkAreaBoundsInParent(w2.get()).width());
962ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
963ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DragToVerticalPositionAndToEdge(DOCKED_EDGE_LEFT, w1.get(), 20);
964a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // A window should be docked at the left edge.
9655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().x(),
966ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch            w1->GetBoundsInScreen().x());
967c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
968ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DockedWindowLayoutManager* manager =
969ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager());
970ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // The first window should be docked.
9715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().x(),
972ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch            w1->GetBoundsInScreen().x());
973ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Dock width should be set to that of a single docked window.
974c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
9758bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_LEFT, docked_alignment(manager));
9768bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(w1->bounds().width(), docked_width(manager));
977ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
978d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Position second window in the desktop 20px to the right of the docked w1.
979ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DragToVerticalPositionRelativeToEdge(DOCKED_EDGE_LEFT,
980ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                                       w2.get(),
981d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                                       20 + 25 -
9828bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                                       min_dock_gap(),
983ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                                       50);
9842385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch  // The second window should be floating on the desktop.
9855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(w2->GetRootWindow()->GetBoundsInScreen().x() +
9865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                (w1->bounds().right() + 20),
987ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch            w2->GetBoundsInScreen().x());
988c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DefaultContainer, w2->parent()->id());
989ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Dock width should be set to that of a single docked window.
990c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
9918bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_LEFT, docked_alignment(manager));
9928bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(w1->bounds().width(), docked_width(manager));
993ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
994ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Drag w2 almost to the dock, the mouse pointer not quite reaching the dock.
995f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(w2.get(), 10, 0));
9968bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  DragMove(1 + docked_width(manager) - w2->bounds().x(), 0);
997ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Alignment set to "LEFT" during the drag because dock has a window in it.
9988bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_LEFT, docked_alignment(manager));
999ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Release the mouse and the window should not be attached to the edge.
1000ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DragEnd();
1001ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Dock should still have only one window in it.
10028bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_LEFT, docked_alignment(manager));
10038bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(w1->bounds().width(), docked_width(manager));
10042385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch  // The second window should still be in the desktop.
1005c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
1006c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DefaultContainer, w2->parent()->id());
1007ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
1008ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Drag w2 by a bit more - it should resist the drag (stuck edges)
1009ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  int start_x = w2->bounds().x();
1010f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(w2.get(), 100, 5));
1011ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DragMove(-2, 0);
1012ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Window should not actually move.
1013ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  EXPECT_EQ(start_x, w2->bounds().x());
1014ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Alignment set to "LEFT" during the drag because dock has a window in it.
10158bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_LEFT, docked_alignment(manager));
1016ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Release the mouse and the window should not be attached to the edge.
1017ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DragEnd();
1018ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Window should be still where it was before the last drag started.
1019ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  EXPECT_EQ(start_x, w2->bounds().x());
1020ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Dock should still have only one window in it
10218bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_LEFT, docked_alignment(manager));
10228bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(w1->bounds().width(), docked_width(manager));
10232385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch  // The second window should still be in the desktop
1024c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
1025c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DefaultContainer, w2->parent()->id());
1026ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
1027ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Drag w2 by more than the stuck threshold and drop it into the dock.
1028ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  ASSERT_NO_FATAL_FAILURE(DragStart(w2.get()));
1029ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DragMove(-100, 0);
1030ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Window should actually move.
1031ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  EXPECT_NE(start_x, w2->bounds().x());
1032ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Alignment set to "LEFT" during the drag because dock has a window in it.
10338bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_LEFT, docked_alignment(manager));
1034ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Release the mouse and the window should be attached to the edge.
1035ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DragEnd();
1036ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Both windows are docked now.
1037c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
1038c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w2->parent()->id());
10392385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch  // Dock should get expanded and desktop should get shrunk.
10408bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_LEFT, docked_alignment(manager));
1041ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  EXPECT_EQ(std::max(w1->bounds().width(), w2->bounds().width()),
10428bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)            docked_width(manager));
10432385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch  // Desktop work area should now shrink by dock width.
10445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w2.get()).width() -
10458bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)            docked_width(manager) - min_dock_gap(),
10465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            ScreenUtil::GetDisplayWorkAreaBoundsInParent(w2.get()).width());
1047ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch}
1048ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
1049f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Dock two windows, resize one.
10502385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch// Test the docked windows area size and remaining desktop resizing.
1051f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)TEST_P(DockedWindowResizerTest, ResizeOneOfTwoWindows) {
1052ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  if (!SupportsHostWindowResize())
1053ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    return;
1054ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
1055ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Wider display to start since panels are limited to half the display width.
10568bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  UpdateDisplay("1000x600");
1057ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
1058ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 201)));
1059ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Work area should cover the whole screen.
10605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w2.get()).width(),
10615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            ScreenUtil::GetDisplayWorkAreaBoundsInParent(w2.get()).width());
1062ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
1063ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20);
1064a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // A window should be docked at the right edge.
10655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
1066ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch            w1->GetBoundsInScreen().right());
1067c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
1068ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DockedWindowLayoutManager* manager =
1069ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager());
10708bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
10718bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(w1->bounds().width(), docked_width(manager));
1072ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
1073f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 100);
1074a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Both windows should now be docked at the right edge.
10755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(w2->GetRootWindow()->GetBoundsInScreen().right(),
1076ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch            w2->GetBoundsInScreen().right());
1077c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w2->parent()->id());
1078ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Dock width should be set to a wider window.
10798bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
1080ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  EXPECT_EQ(std::max(w1->bounds().width(), w2->bounds().width()),
10818bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)            docked_width(manager));
1082ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
1083ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Resize the first window left by a bit and test that the dock expands.
1084ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  int previous_width = w1->bounds().width();
1085ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  const int kResizeSpan1 = 30;
1086f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(ResizeStartAtOffsetFromWindowOrigin(w1.get(),
1087d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                                                              0, 20,
1088ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                                                              HTLEFT));
1089ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DragMove(-kResizeSpan1, 0);
1090ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Alignment set to "RIGHT" during the drag because dock has a window in it.
10918bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
1092ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Release the mouse and the window should be attached to the edge.
1093ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DragEnd();
1094ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Dock should still have both windows in it.
1095c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
1096c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w2->parent()->id());
10978bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
1098f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // w1 is now wider than before. The dock should expand and be as wide as w1.
1099ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  EXPECT_EQ(previous_width + kResizeSpan1, w1->bounds().width());
1100f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Both windows should get resized since they both don't have min/max size.
1101f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(w1->bounds().width(), w2->bounds().width());
11028bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(w1->bounds().width(), docked_width(manager));
11032385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch  // Desktop work area should shrink.
11045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w2.get()).width() -
11058bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)            docked_width(manager) - min_dock_gap(),
11065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            ScreenUtil::GetDisplayWorkAreaBoundsInParent(w2.get()).width());
1107ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
1108ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Resize the first window left by more than the dock maximum width.
1109d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // This should cause the window width to be restricted by maximum dock width.
1110ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  previous_width = w1->bounds().width();
1111ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  const int kResizeSpan2 = 250;
1112f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(ResizeStartAtOffsetFromWindowOrigin(w1.get(),
1113d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                                                              0, 20,
1114ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                                                              HTLEFT));
1115ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DragMove(-kResizeSpan2, 0);
1116ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Alignment set to "RIGHT" during the drag because dock has a window in it.
11178bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
1118ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Release the mouse and the window should be attached to the edge.
1119ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DragEnd();
1120ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Dock should still have both windows in it.
1121c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
1122c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w2->parent()->id());
11238bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
1124d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // w1 is now as wide as the maximum dock width and the dock should get
1125d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // resized to the maximum width.
11268bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(max_width(), w1->bounds().width());
1127f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Both windows should get resized since they both don't have min/max size.
1128f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(w1->bounds().width(), w2->bounds().width());
11298bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(w1->bounds().width(), docked_width(manager));
11302385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch  // Desktop work area should shrink.
11315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w2.get()).width() -
11328bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)            docked_width(manager) - min_dock_gap(),
11335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            ScreenUtil::GetDisplayWorkAreaBoundsInParent(w2.get()).width());
1134ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
1135ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Resize the first window right to get it completely inside the docked area.
1136ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  previous_width = w1->bounds().width();
1137ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  const int kResizeSpan3 = 100;
1138f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(ResizeStartAtOffsetFromWindowOrigin(w1.get(),
1139d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                                                              0, 20,
1140ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                                                              HTLEFT));
1141ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DragMove(kResizeSpan3, 0);
1142ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Alignment set to "RIGHT" during the drag because dock has a window in it.
11438bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
1144f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Release the mouse and the window should be docked.
1145ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DragEnd();
1146ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Dock should still have both windows in it.
1147c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
1148c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w2->parent()->id());
11498bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
1150f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // w1 should be narrower than before by the length of the drag.
1151ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  EXPECT_EQ(previous_width - kResizeSpan3, w1->bounds().width());
1152f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Both windows should get resized since they both don't have min/max size.
1153f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(w1->bounds().width(), w2->bounds().width());
1154f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // The dock should be as wide as w1 or w2.
11558bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(w1->bounds().width(), docked_width(manager));
11562385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch  // Desktop work area should shrink.
11575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w2.get()).width() -
11588bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)            docked_width(manager) - min_dock_gap(),
11595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            ScreenUtil::GetDisplayWorkAreaBoundsInParent(w2.get()).width());
1160ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
1161ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Resize the first window left to be overhang again.
1162ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  previous_width = w1->bounds().width();
1163f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(ResizeStartAtOffsetFromWindowOrigin(w1.get(),
1164d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)                                                              0, 20,
1165ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch                                                              HTLEFT));
1166ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DragMove(-kResizeSpan3, 0);
1167ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DragEnd();
1168ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  EXPECT_EQ(previous_width + kResizeSpan3, w1->bounds().width());
1169c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
1170d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // Docked area should be as wide as possible (maximum) and same as w1.
11718bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(max_width(), docked_width(manager));
11728bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(w1->bounds().width(), docked_width(manager));
1173ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
1174f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Undock the first window. Docked area should shrink to its ideal size.
1175f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(DragStart(w1.get()));
1176bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch  // Drag up as well to avoid attaching panels to launcher shelf.
1177f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DragMove(-(400 - 210), -100);
1178ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Alignment set to "RIGHT" since we have another window docked.
11798bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
1180ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Release the mouse and the window should be no longer attached to the edge.
1181ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DragEnd();
1182c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DefaultContainer, w1->parent()->id());
1183f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Dock should be as wide as w2 (and same as ideal width).
11848bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
1185f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(ideal_width(), docked_width(manager));
1186f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(w2->bounds().width(), docked_width(manager));
1187f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // The second window should be still docked.
1188c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w2->parent()->id());
11892385ea399aae016c0806a4f9ef3c9cfe3d2a39dfBen Murdoch  // Desktop work area should be inset.
11905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w1.get()).width() -
11918bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)            docked_width(manager) - min_dock_gap(),
11925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            ScreenUtil::GetDisplayWorkAreaBoundsInParent(w1.get()).width());
1193f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
1194f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1195f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Dock a window, resize it and test that undocking it preserves the width.
1196f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)TEST_P(DockedWindowResizerTest, ResizingKeepsWidth) {
1197f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  if (!SupportsHostWindowResize())
1198f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    return;
1199f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1200f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Wider display to start since panels are limited to half the display width.
1201f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  UpdateDisplay("1000x600");
1202f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
1203f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1204f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20);
12055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Window should be docked at the right edge.
1206f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
1207f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)            w1->GetBoundsInScreen().right());
1208c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
1209f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DockedWindowLayoutManager* manager =
1210f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager());
1211f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
1212f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(w1->bounds().width(), docked_width(manager));
1213f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1214f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Resize the window left by a bit and test that the dock expands.
1215f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  int previous_width = w1->bounds().width();
1216f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  const int kResizeSpan1 = 30;
1217f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(ResizeStartAtOffsetFromWindowOrigin(w1.get(),
1218f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                                                              0, 20,
1219f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                                                              HTLEFT));
1220f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DragMove(-kResizeSpan1, 0);
12215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Alignment stays "RIGHT" during the drag because the only docked window
12225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // is being resized.
12235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
1224f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Release the mouse and the window should be attached to the edge.
1225f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DragEnd();
12265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // The window should get docked.
1227c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
1228f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
1229f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // w1 is now wider and the dock should expand to be as wide as w1.
1230f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(previous_width + kResizeSpan1, w1->bounds().width());
1231f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(w1->bounds().width(), docked_width(manager));
1232f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1233f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Undock by dragging almost to the left edge.
1234f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DragToVerticalPositionRelativeToEdge(DOCKED_EDGE_LEFT, w1.get(), 100, 20);
1235f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Width should be preserved.
1236f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(previous_width + kResizeSpan1, w1->bounds().width());
1237f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Height should be restored to what it was originally.
1238f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(201, w1->bounds().height());
1239f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1240f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Dock again.
1241f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20);
1242f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Width should be reset to initial ideal width (25px).
1243f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(ideal_width(), w1->bounds().width());
1244f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1245f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Undock again by dragging left.
1246f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DragToVerticalPositionRelativeToEdge(DOCKED_EDGE_LEFT, w1.get(), 100, 20);
1247f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Width should be reset to what it was last time the window was not docked.
1248f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(previous_width + kResizeSpan1, w1->bounds().width());
1249f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Height should be restored to what it was originally.
1250f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(201, w1->bounds().height());
1251f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
1252f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
12535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Dock a window, resize it and test that it stays docked.
12545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_P(DockedWindowResizerTest, ResizingKeepsDockedState) {
12555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!SupportsHostWindowResize())
12565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
12575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
12585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Wider display to start since panels are limited to half the display width.
12595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UpdateDisplay("1000x600");
12605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
12615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
12625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20);
12635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Window should be docked at the right edge.
12645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
12655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            w1->GetBoundsInScreen().right());
1266c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
12675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DockedWindowLayoutManager* manager =
12685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager());
12695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
12705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(w1->bounds().width(), docked_width(manager));
12715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
12725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Resize the window left by a bit and test that the dock expands.
12735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  int previous_width = w1->bounds().width();
12745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const int kResizeSpan1 = 30;
12755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(ResizeStartAtOffsetFromWindowOrigin(
12765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      w1.get(), 0, 20, HTLEFT));
12775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DragMove(-kResizeSpan1, 0);
12785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Normally alignment would be reset to "NONE" during the drag when there is
12795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // only a single window docked and it is being dragged. However because that
12805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // window is being resized rather than moved the alignment is not changed.
12815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
12825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Release the mouse and the window should be attached to the edge.
12835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DragEnd();
12845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // The window should stay docked.
1285c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
12865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
12875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // w1 is now wider and the dock should expand to be as wide as w1.
12885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(previous_width + kResizeSpan1, w1->bounds().width());
12895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(w1->bounds().width(), docked_width(manager));
12905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
12915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Resize the window by dragging its right edge left a bit and test that the
12925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // window stays docked.
12935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  previous_width = w1->bounds().width();
12945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const int kResizeSpan2 = 15;
12955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(ResizeStartAtOffsetFromWindowOrigin(
12965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      w1.get(), w1->bounds().width(), 20, HTRIGHT));
12975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DragMove(-kResizeSpan2, 0);
12985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Alignment stays "RIGHT" during the drag because the window is being
12995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // resized rather than dragged.
13005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
13015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Release the mouse and the window should be attached to the edge.
13025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DragEnd();
13035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // The window should stay docked.
1304c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
13055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
13065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // The dock should stay as wide as w1 is now (a bit less than before).
13075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(previous_width - kResizeSpan2, w1->bounds().width());
13085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(w1->bounds().width(), docked_width(manager));
13095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
13105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1311f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Dock two windows, resize one. Test the docked windows area size.
1312f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)TEST_P(DockedWindowResizerTest, ResizeTwoWindows) {
1313f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  if (!SupportsHostWindowResize())
1314f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    return;
1315f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1316f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Wider display to start since panels are limited to half the display width.
1317f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  UpdateDisplay("1000x600");
1318f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
1319f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 201)));
1320f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1321f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20);
1322f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 100);
1323f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Both windows should now be docked at the right edge.
1324c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
1325c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w2->parent()->id());
1326f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Dock width should be set to ideal width.
1327f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DockedWindowLayoutManager* manager =
1328f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)      static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager());
1329f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
1330f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(ideal_width(), docked_width(manager));
1331f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1332f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Resize the first window left by a bit and test that the dock expands.
1333f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  int previous_width = w1->bounds().width();
1334f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  const int kResizeSpan1 = 30;
1335f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(ResizeStartAtOffsetFromWindowOrigin(w1.get(),
1336f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                                                              0, 20,
1337f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                                                              HTLEFT));
1338f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DragMove(-kResizeSpan1, 0);
1339f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DragEnd();
1340f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // w1 is now wider than before.
1341f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(previous_width + kResizeSpan1, w1->bounds().width());
1342f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Both windows should get resized since they both don't have min/max size.
1343f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(w1->bounds().width(), w2->bounds().width());
1344f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(w1->bounds().width(), docked_width(manager));
1345f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1346f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Resize the second window left by a bit more and test that the dock expands.
1347f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  previous_width = w2->bounds().width();
1348f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(ResizeStartAtOffsetFromWindowOrigin(w2.get(),
1349f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                                                              0, 20,
1350f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                                                              HTLEFT));
1351f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DragMove(-kResizeSpan1, 0);
1352f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DragEnd();
13535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // w2 should get wider since it was resized by a user.
1354f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(previous_width + kResizeSpan1, w2->bounds().width());
13555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // w1 should stay as wide as w2 since both were flush with the dock edge.
13565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(w2->bounds().width(), w1->bounds().width());
1357f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(w2->bounds().width(), docked_width(manager));
1358f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1359f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Undock w2 and then dock it back.
1360f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DragToVerticalPositionRelativeToEdge(DOCKED_EDGE_RIGHT, w2.get(), -400, 100);
1361c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DefaultContainer, w2->parent()->id());
1362f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 100);
1363c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w2->parent()->id());
1364f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // w2 should become same width as w1.
1365f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(w1->bounds().width(), w2->bounds().width());
1366f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(w1->bounds().width(), docked_width(manager));
1367f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1368f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Make w1 even wider.
1369f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(ResizeStartAtOffsetFromWindowOrigin(w1.get(),
1370f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                                                              0, 20,
1371f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                                                              HTLEFT));
1372f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DragMove(-kResizeSpan1, 0);
1373f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DragEnd();
1374f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Making w1 wider should make both windows wider since w2 no longer remembers
1375f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // user width.
1376f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(w1->bounds().width(), w2->bounds().width());
1377f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  EXPECT_EQ(w1->bounds().width(), docked_width(manager));
1378ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch}
1379ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
13804e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Tests that dragging a window down to shelf attaches a panel but does not
13814e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// attach a regular window.
13824e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)TEST_P(DockedWindowResizerTest, DragToShelf) {
1383ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  if (!SupportsHostWindowResize())
1384ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    return;
1385ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
1386ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
1387ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Work area should cover the whole screen.
13885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w1.get()).width(),
13895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            ScreenUtil::GetDisplayWorkAreaBoundsInParent(w1.get()).width());
1390ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
1391ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20);
1392a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // A window should be docked at the right edge.
13935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
1394ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch            w1->GetBoundsInScreen().right());
1395c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
1396ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DockedWindowLayoutManager* manager =
1397ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager());
13988bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
13998bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(w1->bounds().width(), docked_width(manager));
1400ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
1401ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Detach and drag down to shelf.
1402ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  ASSERT_NO_FATAL_FAILURE(DragStart(w1.get()));
1403ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DragMove(-40, 0);
14043551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Alignment is set to "NONE" when drag starts.
14058bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_NONE, docked_alignment(manager));
1406ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Release the mouse and the window should be no longer attached to the edge.
1407ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DragEnd();
14088bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_NONE, docked_alignment(manager));
1409ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
1410ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  // Drag down almost to shelf. A panel will snap, a regular window won't.
14115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShelfWidget* shelf = Shelf::ForPrimaryDisplay()->shelf_widget();
1412ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  const int shelf_y = shelf->GetWindowBoundsInScreen().y();
1413ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  const int kDistanceFromShelf = 10;
1414ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  ASSERT_NO_FATAL_FAILURE(DragStart(w1.get()));
1415ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DragMove(0, -kDistanceFromShelf + shelf_y - w1->bounds().bottom());
1416ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  DragEnd();
1417ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  if (test_panels()) {
1418ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    // The panel should be touching the shelf and attached.
1419ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    EXPECT_EQ(shelf_y, w1->bounds().bottom());
142068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)    EXPECT_TRUE(wm::GetWindowState(w1.get())->panel_attached());
1421ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  } else {
1422ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    // The window should not be touching the shelf.
1423ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    EXPECT_EQ(shelf_y - kDistanceFromShelf, w1->bounds().bottom());
1424ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  }
1425ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch}
1426ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
14274e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Tests that docking and undocking a |window| with a transient child properly
14284e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// maintains the parent of that transient child to be the same as the |window|.
14294e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)TEST_P(DockedWindowResizerTest, DragWindowWithTransientChild) {
14304e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  if (!SupportsHostWindowResize())
14314e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    return;
14324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
14334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Create a window with a transient child.
14344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
14354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  scoped_ptr<aura::Window> child(CreateTestWindowInShellWithDelegateAndType(
14365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      NULL, ui::wm::WINDOW_TYPE_NORMAL, 0, gfx::Rect(20, 20, 150, 20)));
1437a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  ::wm::AddTransientChild(window.get(), child.get());
14384e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  if (window->parent() != child->parent())
14394e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    window->parent()->AddChild(child.get());
1440a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  EXPECT_EQ(window.get(), ::wm::GetTransientParent(child.get()));
14414e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
14424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, window.get(), 20);
14434e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1444a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // A window should be docked at the right edge.
1445c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
1446c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, child->parent()->id());
14474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
14484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Drag the child - it should move freely and stay where it is dragged.
14494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(DragStart(child.get()));
14504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  DragMove(500, 20);
14514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  DragEnd();
14524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  EXPECT_EQ(gfx::Point(20 + 500, 20 + 20).ToString(),
14534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)            child->GetBoundsInScreen().origin().ToString());
14544e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
14554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Undock the window by dragging left.
14564e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(DragStart(window.get()));
14574e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  DragMove(-32, -10);
14584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  DragEnd();
14594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
14604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // The window should be undocked and the transient child should be reparented.
1461c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
1462c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DefaultContainer, child->parent()->id());
14634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // The child should not have moved.
14644e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  EXPECT_EQ(gfx::Point(20 + 500, 20 + 20).ToString(),
14654e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)            child->GetBoundsInScreen().origin().ToString());
14664e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
14674e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1468a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Tests that reparenting windows during the drag does not affect system modal
1469a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// windows that are transient children of the dragged windows.
1470a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)TEST_P(DockedWindowResizerTest, DragWindowWithModalTransientChild) {
1471a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (!SupportsHostWindowResize())
1472a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return;
1473a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
1474a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Create a window.
1475a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
1476a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  gfx::Rect bounds(window->bounds());
1477a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
1478a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Start dragging the window.
1479a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(DragStart(window.get()));
1480a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  gfx::Vector2d move_vector(40, test_panels() ? -60 : 60);
1481a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  DragMove(move_vector.x(), move_vector.y());
1482a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id());
1483a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
1484a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // While still dragging create a modal window and make it a transient child of
1485a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // the |window|.
1486a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  scoped_ptr<aura::Window> child(CreateModalWindow(gfx::Rect(20, 20, 150, 20)));
1487a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  ::wm::AddTransientChild(window.get(), child.get());
1488a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  EXPECT_EQ(window.get(), ::wm::GetTransientParent(child.get()));
1489c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_SystemModalContainer, child->parent()->id());
1490a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
1491a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // End the drag, the |window| should have moved (if it is a panel it will
1492a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // no longer be attached to the shelf since we dragged it above).
1493a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  DragEnd();
1494a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  bounds.Offset(move_vector);
1495a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_EQ(bounds.ToString(), window->GetBoundsInScreen().ToString());
1496a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
1497a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // The original |window| should be in the default container (not docked or
1498a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // attached).
1499c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
1500a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // The transient |child| should still be in system modal container.
1501c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_SystemModalContainer, child->parent()->id());
1502a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // The |child| should not have moved.
1503a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_EQ(gfx::Point(20, 20).ToString(),
1504a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)            child->GetBoundsInScreen().origin().ToString());
1505a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // The |child| should still be a transient child of |window|.
1506a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  EXPECT_EQ(window.get(), ::wm::GetTransientParent(child.get()));
1507a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
1508a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
1509a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Tests that side snapping a window undocks it, closes the dock and then snaps.
1510a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)TEST_P(DockedWindowResizerTest, SideSnapDocked) {
1511a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (!SupportsHostWindowResize() || test_panels())
1512a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return;
1513a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
1514a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
1515a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  wm::WindowState* window_state = wm::GetWindowState(w1.get());
1516a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20);
1517a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // A window should be docked at the right edge.
15185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
1519a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)            w1->GetBoundsInScreen().right());
1520c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
1521a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  DockedWindowLayoutManager* manager =
1522a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager());
1523a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
1524a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_EQ(w1->bounds().width(), docked_width(manager));
1525a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_TRUE(window_state->IsDocked());
1526a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_FALSE(window_state->IsSnapped());
1527a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
1528a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Side snap at right edge.
1529a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  const wm::WMEvent snap_right(wm::WM_EVENT_SNAP_RIGHT);
1530a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  window_state->OnWMEvent(&snap_right);
1531a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // The window should be snapped at the right edge and the dock should close.
15325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  gfx::Rect work_area(ScreenUtil::GetDisplayWorkAreaBoundsInParent(w1.get()));
1533a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_EQ(0, docked_width(manager));
1534a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_EQ(work_area.height(), w1->bounds().height());
1535a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_EQ(work_area.right(), w1->bounds().right());
1536c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DefaultContainer, w1->parent()->id());
1537a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_FALSE(window_state->IsDocked());
1538a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_TRUE(window_state->IsSnapped());
1539a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
1540a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Dock again.
1541a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20);
1542a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // A window should be docked at the right edge.
15435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
1544a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)            w1->GetBoundsInScreen().right());
1545c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
1546a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
1547a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_EQ(w1->bounds().width(), docked_width(manager));
1548a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_TRUE(window_state->IsDocked());
1549a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_FALSE(window_state->IsSnapped());
1550a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
1551a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Side snap at left edge.
1552a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  const wm::WMEvent snap_left(wm::WM_EVENT_SNAP_LEFT);
1553a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  window_state->OnWMEvent(&snap_left);
1554a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // The window should be snapped at the right edge and the dock should close.
1555a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_EQ(work_area.ToString(),
15565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            ScreenUtil::GetDisplayWorkAreaBoundsInParent(w1.get()).ToString());
1557a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_EQ(0, docked_width(manager));
1558a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_EQ(work_area.height(), w1->bounds().height());
1559a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_EQ(work_area.x(), w1->bounds().x());
1560c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DefaultContainer, w1->parent()->id());
1561a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_FALSE(window_state->IsDocked());
1562a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_TRUE(window_state->IsSnapped());
1563a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
1564a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
15655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Tests that a window is undocked if the window is maximized via a keyboard
15665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// accelerator during a drag.
15675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_P(DockedWindowResizerTest, MaximizedDuringDrag) {
15685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!SupportsHostWindowResize() || test_panels())
15695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
15705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
15715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  scoped_ptr<aura::Window> window(CreateTestWindow(
15725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      gfx::Rect(0, 0, ideal_width(), 201)));
15735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  wm::WindowState* window_state = wm::GetWindowState(window.get());
15745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
15755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Dock the window to the right edge.
15765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, window.get(), 20);
15775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
15785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            window->GetBoundsInScreen().right());
1579c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
15805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DockedWindowLayoutManager* manager =
15815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      static_cast<DockedWindowLayoutManager*>(
15825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          window->parent()->layout_manager());
15835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
15845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(window->bounds().width(), docked_width(manager));
15855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_TRUE(window_state->IsDocked());
15865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
15875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Maximize the window while in a real drag. In particular,
1588a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // ToplevelWindowEventHandler::ScopedWindowResizer::OnWindowStateTypeChanged()
15895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // must be called in order for the maximized window's size to be correct.
15905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  delegate()->set_window_component(HTCAPTION);
15915f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  ui::test::EventGenerator& generator = GetEventGenerator();
15925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  generator.MoveMouseTo(window->GetBoundsInScreen().origin());
15935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  generator.PressLeftButton();
15945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  generator.MoveMouseBy(10, 10);
15955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  window_state->Maximize();
15965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  generator.ReleaseLeftButton();
15975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
15985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // |window| should get undocked.
1599c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
16005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(0, docked_width(manager));
16015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_EQ(
16025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()).ToString(),
16035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      window->bounds().ToString());
16045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_TRUE(window_state->IsMaximized());
16055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
16065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
16077d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Tests run twice - on both panels and normal windows
16087d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)INSTANTIATE_TEST_CASE_P(NormalOrPanel,
16097d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                        DockedWindowResizerTest,
16105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                        testing::Values(ui::wm::WINDOW_TYPE_NORMAL,
16115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                        ui::wm::WINDOW_TYPE_PANEL));
1612c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
16137d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}  // namespace ash
1614