| OLD | NEW |
| 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/workspace/workspace.h" |
| 5 #include "ui/aura_shell/workspace/workspace_manager.h" | 6 #include "ui/aura_shell/workspace/workspace_manager.h" |
| 6 #include "ui/aura_shell/workspace/workspace.h" | 7 #include "ui/aura/desktop.h" |
| 7 | 8 #include "ui/aura/screen_aura.h" |
| 8 #include "ui/aura/test/aura_test_base.h" | 9 #include "ui/aura/test/aura_test_base.h" |
| 9 #include "ui/aura/test/test_desktop_delegate.h" | 10 #include "ui/aura/test/test_desktop_delegate.h" |
| 10 #include "ui/aura/desktop.h" | |
| 11 #include "ui/aura/screen_aura.h" | |
| 12 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
| 13 | 12 |
| 14 namespace { | 13 using aura::Window; |
| 14 |
| 15 namespace aura_shell { |
| 16 namespace internal { |
| 15 | 17 |
| 16 class WorkspaceManagerTestBase : public aura::test::AuraTestBase { | 18 class WorkspaceManagerTestBase : public aura::test::AuraTestBase { |
| 17 public: | 19 public: |
| 18 WorkspaceManagerTestBase() {} | 20 WorkspaceManagerTestBase() {} |
| 19 virtual ~WorkspaceManagerTestBase() {} | 21 virtual ~WorkspaceManagerTestBase() {} |
| 20 | 22 |
| 21 virtual void SetUp() OVERRIDE { | 23 virtual void SetUp() OVERRIDE { |
| 22 aura::test::AuraTestBase::SetUp(); | 24 aura::test::AuraTestBase::SetUp(); |
| 23 manager_.reset(new aura_shell::WorkspaceManager(viewport())); | 25 manager_.reset(new WorkspaceManager(viewport())); |
| 24 } | 26 } |
| 25 | 27 |
| 26 virtual void TearDown() OVERRIDE { | 28 virtual void TearDown() OVERRIDE { |
| 27 manager_.reset(); | 29 manager_.reset(); |
| 28 aura::test::AuraTestBase::TearDown(); | 30 aura::test::AuraTestBase::TearDown(); |
| 29 } | 31 } |
| 30 | 32 |
| 31 aura::Window* CreateTestWindow() { | 33 aura::Window* CreateTestWindow() { |
| 32 aura::Window* window = new aura::Window(NULL); | 34 aura::Window* window = new aura::Window(NULL); |
| 33 window->Init(ui::Layer::LAYER_HAS_NO_TEXTURE); | 35 window->Init(ui::Layer::LAYER_HAS_NO_TEXTURE); |
| 34 return window; | 36 return window; |
| 35 } | 37 } |
| 36 | 38 |
| 37 aura::Window* viewport() { | 39 aura::Window* viewport() { |
| 38 return GetTestDesktopDelegate()->default_container(); | 40 return GetTestDesktopDelegate()->default_container(); |
| 39 } | 41 } |
| 40 scoped_ptr<aura_shell::WorkspaceManager> manager_; | 42 scoped_ptr<WorkspaceManager> manager_; |
| 41 | 43 |
| 42 private: | 44 private: |
| 43 DISALLOW_COPY_AND_ASSIGN(WorkspaceManagerTestBase); | 45 DISALLOW_COPY_AND_ASSIGN(WorkspaceManagerTestBase); |
| 44 }; | 46 }; |
| 45 | 47 |
| 46 } // namespace | |
| 47 | |
| 48 namespace aura_shell { | |
| 49 | |
| 50 using aura::Window; | |
| 51 using aura_shell::Workspace; | |
| 52 using aura_shell::WorkspaceManager; | |
| 53 | |
| 54 class WorkspaceManagerTest : public WorkspaceManagerTestBase { | 48 class WorkspaceManagerTest : public WorkspaceManagerTestBase { |
| 55 }; | 49 }; |
| 56 | 50 |
| 57 TEST_F(WorkspaceManagerTest, WorkspaceManagerCreateAddFind) { | 51 TEST_F(WorkspaceManagerTest, WorkspaceManagerCreateAddFind) { |
| 58 scoped_ptr<Window> w1(CreateTestWindow()); | 52 scoped_ptr<Window> w1(CreateTestWindow()); |
| 59 scoped_ptr<Window> w2(CreateTestWindow()); | 53 scoped_ptr<Window> w2(CreateTestWindow()); |
| 60 | 54 |
| 61 Workspace* ws1 = manager_->CreateWorkspace(); | 55 Workspace* ws1 = manager_->CreateWorkspace(); |
| 62 ws1->AddWindowAfter(w1.get(), NULL); | 56 ws1->AddWindowAfter(w1.get(), NULL); |
| 63 // w2 is not a part of any workspace yet. | 57 // w2 is not a part of any workspace yet. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 75 // once workspace is gone, w2 shouldn't match | 69 // once workspace is gone, w2 shouldn't match |
| 76 // any workspace. | 70 // any workspace. |
| 77 delete ws2; | 71 delete ws2; |
| 78 EXPECT_EQ(NULL, manager_->FindBy(w2.get())); | 72 EXPECT_EQ(NULL, manager_->FindBy(w2.get())); |
| 79 | 73 |
| 80 // Reset now before windows are destroyed. | 74 // Reset now before windows are destroyed. |
| 81 manager_.reset(); | 75 manager_.reset(); |
| 82 } | 76 } |
| 83 | 77 |
| 84 TEST_F(WorkspaceManagerTest, LayoutWorkspaces) { | 78 TEST_F(WorkspaceManagerTest, LayoutWorkspaces) { |
| 85 manager_->workspace_size_ = gfx::Size(100, 100); | 79 manager_->SetWorkspaceSize(gfx::Size(100, 100)); |
| 86 manager_->LayoutWorkspaces(); | |
| 87 EXPECT_EQ("0,0 100x100", viewport()->bounds().ToString()); | 80 EXPECT_EQ("0,0 100x100", viewport()->bounds().ToString()); |
| 88 | 81 |
| 89 Workspace* ws1 = manager_->CreateWorkspace(); | 82 Workspace* ws1 = manager_->CreateWorkspace(); |
| 90 manager_->LayoutWorkspaces(); | 83 manager_->LayoutWorkspaces(); |
| 91 | 84 |
| 92 // ws1 is laied out in left most position. | 85 // ws1 is laied out in left most position. |
| 93 EXPECT_EQ(100, viewport()->bounds().width()); | 86 EXPECT_EQ(100, viewport()->bounds().width()); |
| 94 EXPECT_EQ("0,0 100x100", ws1->bounds().ToString()); | 87 EXPECT_EQ("0,0 100x100", ws1->bounds().ToString()); |
| 95 | 88 |
| 96 // ws2 is laied out next to ws1, with 50 margin. | 89 // ws2 is laied out next to ws1, with 50 margin. |
| 97 Workspace* ws2 = manager_->CreateWorkspace(); | 90 Workspace* ws2 = manager_->CreateWorkspace(); |
| 98 manager_->LayoutWorkspaces(); | 91 manager_->LayoutWorkspaces(); |
| 99 | 92 |
| 100 EXPECT_EQ(250, viewport()->bounds().width()); | 93 EXPECT_EQ(250, viewport()->bounds().width()); |
| 101 EXPECT_EQ("0,0 100x100", ws1->bounds().ToString()); | 94 EXPECT_EQ("0,0 100x100", ws1->bounds().ToString()); |
| 102 EXPECT_EQ("150,0 100x100", ws2->bounds().ToString()); | 95 EXPECT_EQ("150,0 100x100", ws2->bounds().ToString()); |
| 103 } | 96 } |
| 104 | 97 |
| 98 // Makes sure the bounds of window are resized if the workspace size shrinks. |
| 99 TEST_F(WorkspaceManagerTest, ResizeDuringLayout) { |
| 100 manager_->SetWorkspaceSize(gfx::Size(100, 100)); |
| 101 EXPECT_EQ("0,0 100x100", viewport()->bounds().ToString()); |
| 102 |
| 103 Workspace* ws1 = manager_->CreateWorkspace(); |
| 104 scoped_ptr<Window> w1(CreateTestWindow()); |
| 105 w1->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 106 viewport()->AddChild(w1.get()); |
| 107 EXPECT_TRUE(ws1->AddWindowAfter(w1.get(), NULL)); |
| 108 manager_->SetWorkspaceSize(gfx::Size(50, 50)); |
| 109 |
| 110 // ws1 is laied out in left most position. |
| 111 EXPECT_EQ("0,0 50x50", ws1->bounds().ToString()); |
| 112 EXPECT_EQ("0,0 50x50", w1->layer()->GetTargetBounds().ToString()); |
| 113 } |
| 114 |
| 105 TEST_F(WorkspaceManagerTest, WorkspaceManagerDragArea) { | 115 TEST_F(WorkspaceManagerTest, WorkspaceManagerDragArea) { |
| 106 aura::Desktop::GetInstance()->screen()->set_work_area_insets( | 116 aura::Desktop::GetInstance()->screen()->set_work_area_insets( |
| 107 gfx::Insets(10, 10, 10, 10)); | 117 gfx::Insets(10, 10, 10, 10)); |
| 108 viewport()->SetBounds(gfx::Rect(0, 0, 200, 200)); | 118 viewport()->SetBounds(gfx::Rect(0, 0, 200, 200)); |
| 109 EXPECT_EQ("10,10 180x180", manager_->GetDragAreaBounds().ToString()); | 119 EXPECT_EQ("10,10 180x180", manager_->GetDragAreaBounds().ToString()); |
| 110 } | 120 } |
| 111 | 121 |
| 112 TEST_F(WorkspaceManagerTest, Overview) { | 122 // TODO(sky): move this into a test for WorkspaceController. |
| 113 manager_->workspace_size_ = gfx::Size(500, 300); | 123 TEST_F(WorkspaceManagerTest, DISABLED_Overview) { |
| 124 manager_->SetWorkspaceSize(gfx::Size(500, 300)); |
| 114 | 125 |
| 115 // Creating two workspaces, ws1 which contains window w1, | 126 // Creating two workspaces, ws1 which contains window w1, |
| 116 // and ws2 which contains window w2. | 127 // and ws2 which contains window w2. |
| 117 Workspace* ws1 = manager_->CreateWorkspace(); | 128 Workspace* ws1 = manager_->CreateWorkspace(); |
| 118 scoped_ptr<Window> w1(CreateTestWindow()); | 129 scoped_ptr<Window> w1(CreateTestWindow()); |
| 119 viewport()->AddChild(w1.get()); | 130 viewport()->AddChild(w1.get()); |
| 120 EXPECT_TRUE(ws1->AddWindowAfter(w1.get(), NULL)); | 131 EXPECT_TRUE(ws1->AddWindowAfter(w1.get(), NULL)); |
| 121 | 132 |
| 122 Workspace* ws2 = manager_->CreateWorkspace(); | 133 Workspace* ws2 = manager_->CreateWorkspace(); |
| 123 scoped_ptr<Window> w2(CreateTestWindow()); | 134 scoped_ptr<Window> w2(CreateTestWindow()); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 ws2->Activate(); | 183 ws2->Activate(); |
| 173 EXPECT_EQ(ws2, manager_->GetActiveWorkspace()); | 184 EXPECT_EQ(ws2, manager_->GetActiveWorkspace()); |
| 174 | 185 |
| 175 // Deleting active workspace sets active workspace to NULL. | 186 // Deleting active workspace sets active workspace to NULL. |
| 176 delete ws2; | 187 delete ws2; |
| 177 EXPECT_EQ(NULL, manager_->GetActiveWorkspace()); | 188 EXPECT_EQ(NULL, manager_->GetActiveWorkspace()); |
| 178 manager_.reset(); | 189 manager_.reset(); |
| 179 } | 190 } |
| 180 | 191 |
| 181 TEST_F(WorkspaceManagerTest, FindRotateWindow) { | 192 TEST_F(WorkspaceManagerTest, FindRotateWindow) { |
| 182 manager_->workspace_size_ = gfx::Size(500, 300); | 193 manager_->SetWorkspaceSize(gfx::Size(500, 300)); |
| 183 | 194 |
| 184 Workspace* ws1 = manager_->CreateWorkspace(); | 195 Workspace* ws1 = manager_->CreateWorkspace(); |
| 185 scoped_ptr<Window> w11(CreateTestWindow()); | 196 scoped_ptr<Window> w11(CreateTestWindow()); |
| 186 w11->SetBounds(gfx::Rect(0, 0, 100, 100)); | 197 w11->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 187 ws1->AddWindowAfter(w11.get(), NULL); | 198 ws1->AddWindowAfter(w11.get(), NULL); |
| 188 | 199 |
| 189 scoped_ptr<Window> w12(CreateTestWindow()); | 200 scoped_ptr<Window> w12(CreateTestWindow()); |
| 190 w12->SetBounds(gfx::Rect(0, 0, 100, 100)); | 201 w12->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 191 ws1->AddWindowAfter(w12.get(), NULL); | 202 ws1->AddWindowAfter(w12.get(), NULL); |
| 192 manager_->LayoutWorkspaces(); | 203 manager_->LayoutWorkspaces(); |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 Workspace::SHIFT_TO_LEFT); | 493 Workspace::SHIFT_TO_LEFT); |
| 483 EXPECT_EQ(w2.get(), overflow); | 494 EXPECT_EQ(w2.get(), overflow); |
| 484 EXPECT_EQ(-1, ws->GetIndexOf(w2.get())); | 495 EXPECT_EQ(-1, ws->GetIndexOf(w2.get())); |
| 485 EXPECT_EQ(0, ws->GetIndexOf(w1.get())); | 496 EXPECT_EQ(0, ws->GetIndexOf(w1.get())); |
| 486 EXPECT_EQ(1, ws->GetIndexOf(w3.get())); | 497 EXPECT_EQ(1, ws->GetIndexOf(w3.get())); |
| 487 | 498 |
| 488 // Reset now before windows are destroyed. | 499 // Reset now before windows are destroyed. |
| 489 manager_.reset(); | 500 manager_.reset(); |
| 490 } | 501 } |
| 491 | 502 |
| 503 } // namespace internal |
| 492 } // namespace aura_shell | 504 } // namespace aura_shell |
| OLD | NEW |