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

Side by Side Diff: ui/aura_shell/default_container_layout_manager_unittest.cc

Issue 8381015: Add workspace to desktop (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: temporarily exlucde tests failing on win Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/aura_shell/default_container_layout_manager.h" 5 #include "ui/aura_shell/default_container_layout_manager.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "ui/aura/test/aura_test_base.h" 10 #include "ui/aura/test/aura_test_base.h"
11 #include "ui/aura/desktop.h" 11 #include "ui/aura/desktop.h"
12 #include "ui/aura/screen_aura.h" 12 #include "ui/aura/screen_aura.h"
13 #include "ui/aura/window.h" 13 #include "ui/aura/window.h"
14 #include "ui/aura_shell/workspace/workspace_manager.h"
14 #include "ui/base/view_prop.h" 15 #include "ui/base/view_prop.h"
15 #include "views/widget/native_widget_aura.h" 16 #include "views/widget/native_widget_aura.h"
16 17
17 namespace aura_shell { 18 namespace aura_shell {
18 namespace test { 19 namespace test {
19 20
20 namespace { 21 namespace {
21 22
22 using views::Widget; 23 using views::Widget;
24 using aura_shell::internal::DefaultContainerLayoutManager;
23 25
24 class DefaultContainerLayoutManagerTest : public aura::test::AuraTestBase { 26 class DefaultContainerLayoutManagerTest : public aura::test::AuraTestBase {
25 public: 27 public:
26 DefaultContainerLayoutManagerTest() {} 28 DefaultContainerLayoutManagerTest() {}
27 virtual ~DefaultContainerLayoutManagerTest() {} 29 virtual ~DefaultContainerLayoutManagerTest() {}
28 30
29 virtual void SetUp() OVERRIDE { 31 virtual void SetUp() OVERRIDE {
30 aura::test::AuraTestBase::SetUp(); 32 aura::test::AuraTestBase::SetUp();
31 aura::Desktop* desktop = aura::Desktop::GetInstance(); 33 aura::Desktop* desktop = aura::Desktop::GetInstance();
32 container_.reset( 34 container_.reset(
33 CreateTestWindow(gfx::Rect(0, 0, 500, 400), desktop)); 35 CreateTestWindow(gfx::Rect(0, 0, 500, 400), desktop));
36 workspace_manager_.reset(new WorkspaceManager(container_.get()));
37
38 desktop->SetHostSize(gfx::Size(500, 400));
39 default_container_layout_manager_ = new DefaultContainerLayoutManager(
40 container_.get(), workspace_manager_.get());
34 // draggable area is 0,0 500x400. 41 // draggable area is 0,0 500x400.
35 container_->SetLayoutManager( 42 container_->SetLayoutManager(default_container_layout_manager_);
36 new aura_shell::internal::DefaultContainerLayoutManager(
37 container_.get()));
38 } 43 }
39 44
40 aura::Window* CreateTestWindowWithType(const gfx::Rect& bounds, 45 aura::Window* CreateTestWindowWithType(const gfx::Rect& bounds,
41 aura::Window* parent, 46 aura::Window* parent,
42 Widget::InitParams::Type type) { 47 Widget::InitParams::Type type) {
43 aura::Window* window = new aura::Window(NULL); 48 aura::Window* window = new aura::Window(NULL);
44 props_.push_back(new ui::ViewProp( 49 props_.push_back(new ui::ViewProp(
45 window, views::NativeWidgetAura::kWindowTypeKey, 50 window, views::NativeWidgetAura::kWindowTypeKey,
46 reinterpret_cast<void*>(type))); 51 reinterpret_cast<void*>(type)));
47 window->SetType(type); 52 window->SetType(type);
48 window->Init(); 53 window->Init();
49 window->SetBounds(bounds); 54 window->SetBounds(bounds);
50 window->Show(); 55 window->Show();
51 window->SetParent(parent); 56 window->SetParent(parent);
52 return window; 57 return window;
53 } 58 }
54 59
55 aura::Window* CreateTestWindow(const gfx::Rect& bounds, 60 aura::Window* CreateTestWindow(const gfx::Rect& bounds,
56 aura::Window* parent) { 61 aura::Window* parent) {
57 return CreateTestWindowWithType(bounds, 62 return CreateTestWindowWithType(bounds,
58 parent, 63 parent,
59 Widget::InitParams::TYPE_WINDOW); 64 Widget::InitParams::TYPE_WINDOW);
60 } 65 }
61 66
62 aura::Window* container() { return container_.get(); } 67 aura::Window* container() { return container_.get(); }
63 68
69 DefaultContainerLayoutManager* default_container_layout_manager() {
70 return default_container_layout_manager_;
71 }
72
73
64 private: 74 private:
65 scoped_ptr<aura::Window> container_; 75 scoped_ptr<aura::Window> container_;
66 ScopedVector<ui::ViewProp> props_; 76 ScopedVector<ui::ViewProp> props_;
77 scoped_ptr<aura_shell::WorkspaceManager> workspace_manager_;
78 DefaultContainerLayoutManager* default_container_layout_manager_;
67 79
68 DISALLOW_COPY_AND_ASSIGN(DefaultContainerLayoutManagerTest); 80 DISALLOW_COPY_AND_ASSIGN(DefaultContainerLayoutManagerTest);
69 }; 81 };
70 82
71 } // namespace 83 } // namespace
72 84
85 #if !defined(OS_WIN)
73 TEST_F(DefaultContainerLayoutManagerTest, SetBounds) { 86 TEST_F(DefaultContainerLayoutManagerTest, SetBounds) {
74 // Layout Manager moves the window to (0,0) to fit to draggable area. 87 // Layout Manager moves the window to (0,0) to fit to draggable area.
75 scoped_ptr<aura::Window> child( 88 scoped_ptr<aura::Window> child(
76 CreateTestWindow(gfx::Rect(0, -1000, 100, 100), container())); 89 CreateTestWindow(gfx::Rect(0, -1000, 100, 100), container()));
77 EXPECT_EQ("0,0 100x100", child->bounds().ToString()); 90 // Window is centered in workspace.
91 EXPECT_EQ("200,0 100x100", child->bounds().ToString());
78 92
79 // DCLM enforces the window height can't be taller than its owner's height. 93 // DCLM enforces the window height can't be taller than its owner's height.
80 child->SetBounds(gfx::Rect(0, 0, 100, 500)); 94 child->SetBounds(gfx::Rect(0, 0, 100, 500));
81 EXPECT_EQ("0,0 100x400", child->bounds().ToString()); 95 EXPECT_EQ("200,0 100x400", child->bounds().ToString());
82 96
83 // DCLM enforces the window width can't be wider than its owner's width. 97 // DCLM enforces the window width can't be wider than its owner's width.
84 child->SetBounds(gfx::Rect(0, 0, 900, 500)); 98 child->SetBounds(gfx::Rect(0, 0, 900, 500));
85 EXPECT_EQ("0,0 500x400", child->bounds().ToString()); 99 EXPECT_EQ("0,0 500x400", child->bounds().ToString());
86 100
87 // Y origin must always be the top of drag area. 101 // Y origin must always be the top of drag area.
88 child->SetBounds(gfx::Rect(0, 500, 900, 500)); 102 child->SetBounds(gfx::Rect(0, 500, 900, 500));
89 EXPECT_EQ("0,0 500x400", child->bounds().ToString()); 103 EXPECT_EQ("0,0 500x400", child->bounds().ToString());
90 child->SetBounds(gfx::Rect(0, -500, 900, 500)); 104 child->SetBounds(gfx::Rect(0, -500, 900, 500));
91 EXPECT_EQ("0,0 500x400", child->bounds().ToString()); 105 EXPECT_EQ("0,0 500x400", child->bounds().ToString());
106 }
107 #endif
92 108
93 // X origin can be anywhere. 109 #if !defined(OS_WIN)
94 child->SetBounds(gfx::Rect(-100, 500, 900, 500)); 110 TEST_F(DefaultContainerLayoutManagerTest, DragWindow) {
95 EXPECT_EQ("-100,0 500x400", child->bounds().ToString()); 111 scoped_ptr<aura::Window> child(
96 child->SetBounds(gfx::Rect(1000, 500, 900, 500)); 112 CreateTestWindow(gfx::Rect(0, -1000, 50, 50), container()));
97 EXPECT_EQ("1000,0 500x400", child->bounds().ToString()); 113 gfx::Rect original_bounds = child->bounds();
114
115 default_container_layout_manager()->PrepareForMoveOrResize(
116 child.get(), NULL);
117 // X origin must fit within viewport.
118 child->SetBounds(gfx::Rect(-100, 500, 50, 50));
119 EXPECT_EQ("0,0 50x50", child->GetTargetBounds().ToString());
120 child->SetBounds(gfx::Rect(1000, 500, 50, 50));
121 EXPECT_EQ("450,0 50x50", child->GetTargetBounds().ToString());
122 default_container_layout_manager()->EndMove(child.get(), NULL);
123 EXPECT_EQ(original_bounds.ToString(), child->GetTargetBounds().ToString());
98 } 124 }
125 #endif
99 126
100 TEST_F(DefaultContainerLayoutManagerTest, Popup) { 127 TEST_F(DefaultContainerLayoutManagerTest, Popup) {
101 scoped_ptr<aura::Window> popup( 128 scoped_ptr<aura::Window> popup(
102 CreateTestWindowWithType(gfx::Rect(0, -1000, 100, 100), 129 CreateTestWindowWithType(gfx::Rect(0, -1000, 100, 100),
103 container(), 130 container(),
104 Widget::InitParams::TYPE_POPUP)); 131 Widget::InitParams::TYPE_POPUP));
105 // A popup window can be placed outside of draggable area. 132 // A popup window can be placed outside of draggable area.
106 EXPECT_EQ("0,-1000 100x100", popup->bounds().ToString()); 133 EXPECT_EQ("0,-1000 100x100", popup->bounds().ToString());
107 134
108 // A popup window can be moved to outside of draggable area. 135 // A popup window can be moved to outside of draggable area.
109 popup->SetBounds(gfx::Rect(-100, 0, 100, 100)); 136 popup->SetBounds(gfx::Rect(-100, 0, 100, 100));
110 EXPECT_EQ("-100,0 100x100", popup->bounds().ToString()); 137 EXPECT_EQ("-100,0 100x100", popup->bounds().ToString());
111 138
112 // A popup window can be resized to the size bigger than draggable area. 139 // A popup window can be resized to the size bigger than draggable area.
113 popup->SetBounds(gfx::Rect(0, 0, 1000, 1000)); 140 popup->SetBounds(gfx::Rect(0, 0, 1000, 1000));
114 EXPECT_EQ("0,0 1000x1000", popup->bounds().ToString()); 141 EXPECT_EQ("0,0 1000x1000", popup->bounds().ToString());
115 } 142 }
116 143
117 } // namespace test 144 } // namespace test
118 } // namespace aura_shell 145 } // namespace aura_shell
OLDNEW
« no previous file with comments | « ui/aura_shell/default_container_layout_manager.cc ('k') | ui/aura_shell/desktop_background_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698