| 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_manager.h" | 5 #include "ui/aura_shell/workspace/workspace_manager.h" |
| 6 #include "ui/aura_shell/workspace/workspace.h" | 6 #include "ui/aura_shell/workspace/workspace.h" |
| 7 | 7 |
| 8 #include "ui/aura/test/aura_test_base.h" | 8 #include "ui/aura/test/aura_test_base.h" |
| 9 #include "ui/aura/window.h" | 9 #include "ui/aura/window.h" |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 namespace aura_shell { | 24 namespace aura_shell { |
| 25 | 25 |
| 26 using aura::Window; | 26 using aura::Window; |
| 27 using aura_shell::Workspace; | 27 using aura_shell::Workspace; |
| 28 | 28 |
| 29 class WorkspaceManagerTest : public WorkspaceManagerTestBase { | 29 class WorkspaceManagerTest : public WorkspaceManagerTestBase { |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 TEST_F(WorkspaceManagerTest, WorkspaceManagerBaic) { | 32 TEST_F(WorkspaceManagerTest, WorkspaceManagerBaic) { |
| 33 WorkspaceManager manager; | 33 scoped_ptr<aura::Window> viewport(CreateTestWindow()); |
| 34 WorkspaceManager manager(viewport.get()); |
| 34 scoped_ptr<Window> w1(CreateTestWindow()); | 35 scoped_ptr<Window> w1(CreateTestWindow()); |
| 35 scoped_ptr<Window> w2(CreateTestWindow()); | 36 scoped_ptr<Window> w2(CreateTestWindow()); |
| 36 | 37 |
| 37 Workspace* ws1 = manager.CreateWorkspace(); | 38 Workspace* ws1 = manager.CreateWorkspace(); |
| 38 ws1->AddWindowAfter(w1.get(), NULL); | 39 ws1->AddWindowAfter(w1.get(), NULL); |
| 39 // w2 is not a part of any workspace yet. | 40 // w2 is not a part of any workspace yet. |
| 40 EXPECT_EQ(NULL, manager.FindBy(w2.get())); | 41 EXPECT_EQ(NULL, manager.FindBy(w2.get())); |
| 41 | 42 |
| 42 // w2 is in ws2 workspace. | 43 // w2 is in ws2 workspace. |
| 43 Workspace* ws2 = manager.CreateWorkspace(); | 44 Workspace* ws2 = manager.CreateWorkspace(); |
| 44 ws2->AddWindowAfter(w2.get(), NULL); | 45 ws2->AddWindowAfter(w2.get(), NULL); |
| 45 EXPECT_EQ(ws2, manager.FindBy(w2.get())); | 46 EXPECT_EQ(ws2, manager.FindBy(w2.get())); |
| 46 | 47 |
| 47 // Make sure |FindBy(w1.get())| still returns | 48 // Make sure |FindBy(w1.get())| still returns |
| 48 // correct workspace. | 49 // correct workspace. |
| 49 EXPECT_EQ(ws1, manager.FindBy(w1.get())); | 50 EXPECT_EQ(ws1, manager.FindBy(w1.get())); |
| 50 | 51 |
| 51 // once workspace is gone, w2 shouldn't match | 52 // once workspace is gone, w2 shouldn't match |
| 52 // any workspace. | 53 // any workspace. |
| 53 delete ws2; | 54 delete ws2; |
| 54 EXPECT_EQ(NULL, manager.FindBy(w2.get())); | 55 EXPECT_EQ(NULL, manager.FindBy(w2.get())); |
| 55 } | 56 } |
| 56 | 57 |
| 57 TEST_F(WorkspaceManagerTest, WorkspaceManagerLayout) { | 58 TEST_F(WorkspaceManagerTest, WorkspaceManagerLayout) { |
| 58 WorkspaceManager manager; | 59 scoped_ptr<aura::Window> viewport(CreateTestWindow()); |
| 60 WorkspaceManager manager(viewport.get()); |
| 59 manager.set_workspace_size(gfx::Size(100, 100)); | 61 manager.set_workspace_size(gfx::Size(100, 100)); |
| 60 EXPECT_EQ(0, manager.GetTotalWidth()); | 62 EXPECT_EQ(0, manager.GetTotalWidth()); |
| 61 | 63 |
| 62 Workspace* ws1 = manager.CreateWorkspace(); | 64 Workspace* ws1 = manager.CreateWorkspace(); |
| 63 manager.Layout(); | 65 manager.Layout(); |
| 66 |
| 64 // ws1 is laied out in left most position. | 67 // ws1 is laied out in left most position. |
| 65 EXPECT_EQ(100, manager.GetTotalWidth()); | 68 EXPECT_EQ(100, manager.GetTotalWidth()); |
| 66 EXPECT_EQ("0,0 100x100", ws1->bounds().ToString()); | 69 EXPECT_EQ("0,0 100x100", ws1->bounds().ToString()); |
| 67 | 70 |
| 68 // ws2 is laied out next to ws1, with 50 margin. | 71 // ws2 is laied out next to ws1, with 50 margin. |
| 69 Workspace* ws2 = manager.CreateWorkspace(); | 72 Workspace* ws2 = manager.CreateWorkspace(); |
| 70 manager.Layout(); | 73 manager.Layout(); |
| 74 |
| 71 EXPECT_EQ(250, manager.GetTotalWidth()); | 75 EXPECT_EQ(250, manager.GetTotalWidth()); |
| 72 EXPECT_EQ("0,0 100x100", ws1->bounds().ToString()); | 76 EXPECT_EQ("0,0 100x100", ws1->bounds().ToString()); |
| 73 EXPECT_EQ("150,0 100x100", ws2->bounds().ToString()); | 77 EXPECT_EQ("150,0 100x100", ws2->bounds().ToString()); |
| 74 } | 78 } |
| 75 | 79 |
| 76 TEST_F(WorkspaceManagerTest, WorkspaceManagerActivate) { | 80 TEST_F(WorkspaceManagerTest, WorkspaceManagerActivate) { |
| 77 WorkspaceManager manager; | 81 WorkspaceManager manager; |
| 78 Workspace* ws1 = manager.CreateWorkspace(); | 82 Workspace* ws1 = manager.CreateWorkspace(); |
| 79 Workspace* ws2 = manager.CreateWorkspace(); | 83 Workspace* ws2 = manager.CreateWorkspace(); |
| 80 EXPECT_EQ(NULL, manager.GetActiveWorkspace()); | 84 EXPECT_EQ(NULL, manager.GetActiveWorkspace()); |
| 81 | 85 |
| 82 // Activate ws1. | 86 // Activate ws1. |
| 83 ws1->Activate(); | 87 ws1->Activate(); |
| 84 EXPECT_EQ(ws1, manager.GetActiveWorkspace()); | 88 EXPECT_EQ(ws1, manager.GetActiveWorkspace()); |
| 85 | 89 |
| 86 // Activate ws2. | 90 // Activate ws2. |
| 87 ws2->Activate(); | 91 ws2->Activate(); |
| 88 EXPECT_EQ(ws2, manager.GetActiveWorkspace()); | 92 EXPECT_EQ(ws2, manager.GetActiveWorkspace()); |
| 89 | 93 |
| 90 // Deleting active workspace sets active workspace to NULL. | 94 // Deleting active workspace sets active workspace to NULL. |
| 91 delete ws2; | 95 delete ws2; |
| 92 EXPECT_EQ(NULL, manager.GetActiveWorkspace()); | 96 EXPECT_EQ(NULL, manager.GetActiveWorkspace()); |
| 93 } | 97 } |
| 94 | 98 |
| 95 class WorkspaceTest : public WorkspaceManagerTestBase { | 99 class WorkspaceTest : public WorkspaceManagerTestBase { |
| 96 }; | 100 }; |
| 97 | 101 |
| 98 TEST_F(WorkspaceTest, WorkspaceBasic) { | 102 TEST_F(WorkspaceTest, WorkspaceBasic) { |
| 99 WorkspaceManager manager; | 103 scoped_ptr<aura::Window> viewport(CreateTestWindow()); |
| 104 WorkspaceManager manager(viewport.get()); |
| 100 | 105 |
| 101 Workspace* ws = manager.CreateWorkspace(); | 106 Workspace* ws = manager.CreateWorkspace(); |
| 102 // Sanity check | 107 // Sanity check |
| 103 EXPECT_TRUE(ws->is_empty()); | 108 EXPECT_TRUE(ws->is_empty()); |
| 104 | 109 |
| 105 scoped_ptr<Window> w1(CreateTestWindow()); | 110 scoped_ptr<Window> w1(CreateTestWindow()); |
| 106 scoped_ptr<Window> w2(CreateTestWindow()); | 111 scoped_ptr<Window> w2(CreateTestWindow()); |
| 107 scoped_ptr<Window> w3(CreateTestWindow()); | 112 scoped_ptr<Window> w3(CreateTestWindow()); |
| 108 w1->Init(); | 113 w1->Init(); |
| 109 w2->Init(); | 114 w2->Init(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 137 EXPECT_EQ(0, ws->GetIndexOf(w2.get())); | 142 EXPECT_EQ(0, ws->GetIndexOf(w2.get())); |
| 138 EXPECT_FALSE(ws->Contains(w1.get())); | 143 EXPECT_FALSE(ws->Contains(w1.get())); |
| 139 | 144 |
| 140 // Add w1 back. w1 now has index = 1. | 145 // Add w1 back. w1 now has index = 1. |
| 141 EXPECT_TRUE(ws->AddWindowAfter(w1.get(), w2.get())); | 146 EXPECT_TRUE(ws->AddWindowAfter(w1.get(), w2.get())); |
| 142 EXPECT_EQ(0, ws->GetIndexOf(w2.get())); | 147 EXPECT_EQ(0, ws->GetIndexOf(w2.get())); |
| 143 EXPECT_EQ(1, ws->GetIndexOf(w1.get())); | 148 EXPECT_EQ(1, ws->GetIndexOf(w1.get())); |
| 144 } | 149 } |
| 145 | 150 |
| 146 } // namespace aura_shell | 151 } // namespace aura_shell |
| OLD | NEW |