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

Side by Side Diff: ash/shelf/shelf_window_watcher_unittest.cc

Issue 152223002: Renames LauncherID, LauncherItem and LauncherItems... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: OWNERS Created 6 years, 10 months 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
« no previous file with comments | « ash/shelf/shelf_window_watcher_item_delegate.cc ('k') | ash/shell.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "ash/shelf/shelf_window_watcher.h" 5 #include "ash/shelf/shelf_window_watcher.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/launcher/launcher_types.h" 8 #include "ash/shelf/shelf_item_types.h"
9 #include "ash/shelf/shelf_model.h" 9 #include "ash/shelf/shelf_model.h"
10 #include "ash/shelf/shelf_util.h" 10 #include "ash/shelf/shelf_util.h"
11 #include "ash/shell.h" 11 #include "ash/shell.h"
12 #include "ash/shell_window_ids.h" 12 #include "ash/shell_window_ids.h"
13 #include "ash/test/ash_test_base.h" 13 #include "ash/test/ash_test_base.h"
14 #include "ash/test/shell_test_api.h" 14 #include "ash/test/shell_test_api.h"
15 #include "ash/wm/window_resizer.h" 15 #include "ash/wm/window_resizer.h"
16 #include "ash/wm/window_state.h" 16 #include "ash/wm/window_state.h"
17 #include "ash/wm/window_util.h" 17 #include "ash/wm/window_util.h"
18 #include "base/command_line.h" 18 #include "base/command_line.h"
(...skipping 12 matching lines...) Expand all
31 virtual void SetUp() OVERRIDE { 31 virtual void SetUp() OVERRIDE {
32 test::AshTestBase::SetUp(); 32 test::AshTestBase::SetUp();
33 model_ = test::ShellTestApi(Shell::GetInstance()).shelf_model(); 33 model_ = test::ShellTestApi(Shell::GetInstance()).shelf_model();
34 } 34 }
35 35
36 virtual void TearDown() OVERRIDE { 36 virtual void TearDown() OVERRIDE {
37 model_ = NULL; 37 model_ = NULL;
38 test::AshTestBase::TearDown(); 38 test::AshTestBase::TearDown();
39 } 39 }
40 40
41 LauncherID CreateShelfItem(aura::Window* window) { 41 ShelfID CreateShelfItem(aura::Window* window) {
42 LauncherID id = model_->next_id(); 42 ShelfID id = model_->next_id();
43 ShelfItemDetails item_details; 43 ShelfItemDetails item_details;
44 item_details.type = TYPE_PLATFORM_APP; 44 item_details.type = TYPE_PLATFORM_APP;
45 SetShelfItemDetailsForWindow(window, item_details); 45 SetShelfItemDetailsForWindow(window, item_details);
46 return id; 46 return id;
47 } 47 }
48 48
49 protected: 49 protected:
50 ShelfModel* model_; 50 ShelfModel* model_;
51 51
52 private: 52 private:
53 DISALLOW_COPY_AND_ASSIGN(ShelfWindowWatcherTest); 53 DISALLOW_COPY_AND_ASSIGN(ShelfWindowWatcherTest);
54 }; 54 };
55 55
56 TEST_F(ShelfWindowWatcherTest, CreateAndRemoveLauncherItem) { 56 TEST_F(ShelfWindowWatcherTest, CreateAndRemoveShelfItem) {
57 // ShelfModel only has an APP_LIST item. 57 // ShelfModel only has an APP_LIST item.
58 EXPECT_EQ(1, model_->item_count()); 58 EXPECT_EQ(1, model_->item_count());
59 59
60 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithId(0)); 60 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithId(0));
61 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithId(0)); 61 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithId(0));
62 62
63 // Create a LauncherItem for w1. 63 // Create a ShelfItem for w1.
64 LauncherID id_w1 = CreateShelfItem(w1.get()); 64 ShelfID id_w1 = CreateShelfItem(w1.get());
65 EXPECT_EQ(2, model_->item_count()); 65 EXPECT_EQ(2, model_->item_count());
66 66
67 int index_w1 = model_->ItemIndexByID(id_w1); 67 int index_w1 = model_->ItemIndexByID(id_w1);
68 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status); 68 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status);
69 69
70 // Create a LauncherItem for w2. 70 // Create a ShelfItem for w2.
71 LauncherID id_w2 = CreateShelfItem(w2.get()); 71 ShelfID id_w2 = CreateShelfItem(w2.get());
72 EXPECT_EQ(3, model_->item_count()); 72 EXPECT_EQ(3, model_->item_count());
73 73
74 int index_w2 = model_->ItemIndexByID(id_w2); 74 int index_w2 = model_->ItemIndexByID(id_w2);
75 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w2].status); 75 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w2].status);
76 76
77 // LauncherItem is removed when assoicated window is destroyed. 77 // ShelfItem is removed when assoicated window is destroyed.
78 ClearShelfItemDetailsForWindow(w1.get()); 78 ClearShelfItemDetailsForWindow(w1.get());
79 EXPECT_EQ(2, model_->item_count()); 79 EXPECT_EQ(2, model_->item_count());
80 ClearShelfItemDetailsForWindow(w2.get()); 80 ClearShelfItemDetailsForWindow(w2.get());
81 EXPECT_EQ(1, model_->item_count()); 81 EXPECT_EQ(1, model_->item_count());
82 // Clears twice doesn't do anything. 82 // Clears twice doesn't do anything.
83 ClearShelfItemDetailsForWindow(w2.get()); 83 ClearShelfItemDetailsForWindow(w2.get());
84 EXPECT_EQ(1, model_->item_count()); 84 EXPECT_EQ(1, model_->item_count());
85 85
86 } 86 }
87 87
88 TEST_F(ShelfWindowWatcherTest, ActivateWindow) { 88 TEST_F(ShelfWindowWatcherTest, ActivateWindow) {
89 // ShelfModel only have APP_LIST item. 89 // ShelfModel only have APP_LIST item.
90 EXPECT_EQ(1, model_->item_count()); 90 EXPECT_EQ(1, model_->item_count());
91 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithId(0)); 91 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithId(0));
92 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithId(0)); 92 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithId(0));
93 93
94 // Create a LauncherItem for w1. 94 // Create a ShelfItem for w1.
95 LauncherID id_w1 = CreateShelfItem(w1.get()); 95 ShelfID id_w1 = CreateShelfItem(w1.get());
96 EXPECT_EQ(2, model_->item_count()); 96 EXPECT_EQ(2, model_->item_count());
97 int index_w1 = model_->ItemIndexByID(id_w1); 97 int index_w1 = model_->ItemIndexByID(id_w1);
98 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status); 98 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status);
99 99
100 // Create a LauncherItem for w2. 100 // Create a ShelfItem for w2.
101 LauncherID id_w2 = CreateShelfItem(w2.get()); 101 ShelfID id_w2 = CreateShelfItem(w2.get());
102 EXPECT_EQ(3, model_->item_count()); 102 EXPECT_EQ(3, model_->item_count());
103 int index_w2 = model_->ItemIndexByID(id_w2); 103 int index_w2 = model_->ItemIndexByID(id_w2);
104 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status); 104 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status);
105 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w2].status); 105 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w2].status);
106 106
107 // LauncherItem for w1 is active when w1 is activated. 107 // ShelfItem for w1 is active when w1 is activated.
108 wm::ActivateWindow(w1.get()); 108 wm::ActivateWindow(w1.get());
109 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index_w1].status); 109 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index_w1].status);
110 110
111 // LauncherItem for w2 is active state when w2 is activated. 111 // ShelfItem for w2 is active state when w2 is activated.
112 wm::ActivateWindow(w2.get()); 112 wm::ActivateWindow(w2.get());
113 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status); 113 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status);
114 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index_w2].status); 114 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index_w2].status);
115 } 115 }
116 116
117 TEST_F(ShelfWindowWatcherTest, UpdateWindowProperty) { 117 TEST_F(ShelfWindowWatcherTest, UpdateWindowProperty) {
118 // ShelfModel only has an APP_LIST item. 118 // ShelfModel only has an APP_LIST item.
119 EXPECT_EQ(1, model_->item_count()); 119 EXPECT_EQ(1, model_->item_count());
120 120
121 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); 121 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
122 122
123 // Create a LauncherItem for |window|. 123 // Create a ShelfItem for |window|.
124 LauncherID id = CreateShelfItem(window.get()); 124 ShelfID id = CreateShelfItem(window.get());
125 EXPECT_EQ(2, model_->item_count()); 125 EXPECT_EQ(2, model_->item_count());
126 126
127 int index = model_->ItemIndexByID(id); 127 int index = model_->ItemIndexByID(id);
128 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status); 128 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status);
129 129
130 // Update LauncherItem for |window|. 130 // Update ShelfItem for |window|.
131 ShelfItemDetails details; 131 ShelfItemDetails details;
132 details.type = TYPE_PLATFORM_APP; 132 details.type = TYPE_PLATFORM_APP;
133 133
134 SetShelfItemDetailsForWindow(window.get(), details); 134 SetShelfItemDetailsForWindow(window.get(), details);
135 // No new item is created after updating a launcher item. 135 // No new item is created after updating a launcher item.
136 EXPECT_EQ(2, model_->item_count()); 136 EXPECT_EQ(2, model_->item_count());
137 // index and id are not changed after updating a launcher item. 137 // index and id are not changed after updating a launcher item.
138 EXPECT_EQ(index, model_->ItemIndexByID(id)); 138 EXPECT_EQ(index, model_->ItemIndexByID(id));
139 EXPECT_EQ(id, model_->items()[index].id); 139 EXPECT_EQ(id, model_->items()[index].id);
140 } 140 }
141 141
142 TEST_F(ShelfWindowWatcherTest, MaximizeAndRestoreWindow) { 142 TEST_F(ShelfWindowWatcherTest, MaximizeAndRestoreWindow) {
143 // ShelfModel only has an APP_LIST item. 143 // ShelfModel only has an APP_LIST item.
144 EXPECT_EQ(1, model_->item_count()); 144 EXPECT_EQ(1, model_->item_count());
145 145
146 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); 146 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
147 wm::WindowState* window_state = wm::GetWindowState(window.get()); 147 wm::WindowState* window_state = wm::GetWindowState(window.get());
148 148
149 // Create a LauncherItem for |window|. 149 // Create a ShelfItem for |window|.
150 LauncherID id = CreateShelfItem(window.get()); 150 ShelfID id = CreateShelfItem(window.get());
151 EXPECT_EQ(2, model_->item_count()); 151 EXPECT_EQ(2, model_->item_count());
152 152
153 int index = model_->ItemIndexByID(id); 153 int index = model_->ItemIndexByID(id);
154 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status); 154 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status);
155 155
156 // Maximize window |window|. 156 // Maximize window |window|.
157 EXPECT_FALSE(window_state->IsMaximized()); 157 EXPECT_FALSE(window_state->IsMaximized());
158 window_state->Maximize(); 158 window_state->Maximize();
159 EXPECT_TRUE(window_state->IsMaximized()); 159 EXPECT_TRUE(window_state->IsMaximized());
160 // No new item is created after maximizing a window |window|. 160 // No new item is created after maximizing a window |window|.
(...skipping 13 matching lines...) Expand all
174 } 174 }
175 175
176 // Check that an item is removed when its associated Window is re-parented. 176 // Check that an item is removed when its associated Window is re-parented.
177 TEST_F(ShelfWindowWatcherTest, ReparentWindow) { 177 TEST_F(ShelfWindowWatcherTest, ReparentWindow) {
178 // ShelfModel only has an APP_LIST item. 178 // ShelfModel only has an APP_LIST item.
179 EXPECT_EQ(1, model_->item_count()); 179 EXPECT_EQ(1, model_->item_count());
180 180
181 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); 181 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
182 window->set_owned_by_parent(false); 182 window->set_owned_by_parent(false);
183 183
184 // Create a LauncherItem for |window|. 184 // Create a ShelfItem for |window|.
185 LauncherID id = CreateShelfItem(window.get()); 185 ShelfID id = CreateShelfItem(window.get());
186 EXPECT_EQ(2, model_->item_count()); 186 EXPECT_EQ(2, model_->item_count());
187 187
188 int index = model_->ItemIndexByID(id); 188 int index = model_->ItemIndexByID(id);
189 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status); 189 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status);
190 190
191 aura::Window* root_window = window->GetRootWindow(); 191 aura::Window* root_window = window->GetRootWindow();
192 aura::Window* default_container = Shell::GetContainer( 192 aura::Window* default_container = Shell::GetContainer(
193 root_window, 193 root_window,
194 kShellWindowId_DefaultContainer); 194 kShellWindowId_DefaultContainer);
195 EXPECT_EQ(default_container, window->parent()); 195 EXPECT_EQ(default_container, window->parent());
(...skipping 14 matching lines...) Expand all
210 } 210 }
211 211
212 // Check |window|'s item is not changed during the dragging. 212 // Check |window|'s item is not changed during the dragging.
213 // TODO(simonhong): Add a test for removing a Window during the dragging. 213 // TODO(simonhong): Add a test for removing a Window during the dragging.
214 TEST_F(ShelfWindowWatcherTest, DragWindow) { 214 TEST_F(ShelfWindowWatcherTest, DragWindow) {
215 // ShelfModel only has an APP_LIST item. 215 // ShelfModel only has an APP_LIST item.
216 EXPECT_EQ(1, model_->item_count()); 216 EXPECT_EQ(1, model_->item_count());
217 217
218 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); 218 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
219 219
220 // Create a LauncherItem for |window|. 220 // Create a ShelfItem for |window|.
221 LauncherID id = CreateShelfItem(window.get()); 221 ShelfID id = CreateShelfItem(window.get());
222 EXPECT_EQ(2, model_->item_count()); 222 EXPECT_EQ(2, model_->item_count());
223 223
224 int index = model_->ItemIndexByID(id); 224 int index = model_->ItemIndexByID(id);
225 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status); 225 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status);
226 226
227 // Simulate dragging of |window| and check its item is not changed. 227 // Simulate dragging of |window| and check its item is not changed.
228 scoped_ptr<WindowResizer> resizer( 228 scoped_ptr<WindowResizer> resizer(
229 CreateWindowResizer(window.get(), 229 CreateWindowResizer(window.get(),
230 gfx::Point(), 230 gfx::Point(),
231 HTCAPTION, 231 HTCAPTION,
232 aura::client::WINDOW_MOVE_SOURCE_MOUSE)); 232 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
233 ASSERT_TRUE(resizer.get()); 233 ASSERT_TRUE(resizer.get());
234 resizer->Drag(gfx::Point(50, 50), 0); 234 resizer->Drag(gfx::Point(50, 50), 0);
235 resizer->CompleteDrag(); 235 resizer->CompleteDrag();
236 236
237 //Index and id are not changed after dragging a |window|. 237 //Index and id are not changed after dragging a |window|.
238 EXPECT_EQ(index, model_->ItemIndexByID(id)); 238 EXPECT_EQ(index, model_->ItemIndexByID(id));
239 EXPECT_EQ(id, model_->items()[index].id); 239 EXPECT_EQ(id, model_->items()[index].id);
240 } 240 }
241 241
242 // Check |window|'s item is removed when it is re-parented not to default 242 // Check |window|'s item is removed when it is re-parented not to default
243 // container during the dragging. 243 // container during the dragging.
244 TEST_F(ShelfWindowWatcherTest, ReparentWindowDuringTheDragging) { 244 TEST_F(ShelfWindowWatcherTest, ReparentWindowDuringTheDragging) {
245 // ShelfModel only has an APP_LIST item. 245 // ShelfModel only has an APP_LIST item.
246 EXPECT_EQ(1, model_->item_count()); 246 EXPECT_EQ(1, model_->item_count());
247 247
248 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); 248 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
249 window->set_owned_by_parent(false); 249 window->set_owned_by_parent(false);
250 250
251 // Create a LauncherItem for |window|. 251 // Create a ShelfItem for |window|.
252 LauncherID id = CreateShelfItem(window.get()); 252 ShelfID id = CreateShelfItem(window.get());
253 EXPECT_EQ(2, model_->item_count()); 253 EXPECT_EQ(2, model_->item_count());
254 int index = model_->ItemIndexByID(id); 254 int index = model_->ItemIndexByID(id);
255 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status); 255 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status);
256 256
257 aura::Window* root_window = window->GetRootWindow(); 257 aura::Window* root_window = window->GetRootWindow();
258 aura::Window* default_container = Shell::GetContainer( 258 aura::Window* default_container = Shell::GetContainer(
259 root_window, 259 root_window,
260 kShellWindowId_DefaultContainer); 260 kShellWindowId_DefaultContainer);
261 EXPECT_EQ(default_container, window->parent()); 261 EXPECT_EQ(default_container, window->parent());
262 262
(...skipping 18 matching lines...) Expand all
281 EXPECT_TRUE(wm::GetWindowState(window.get())->is_dragged()); 281 EXPECT_TRUE(wm::GetWindowState(window.get())->is_dragged());
282 new_parent->AddChild(window.get()); 282 new_parent->AddChild(window.get());
283 EXPECT_EQ(1, model_->item_count()); 283 EXPECT_EQ(1, model_->item_count());
284 } 284 }
285 EXPECT_FALSE(wm::GetWindowState(window.get())->is_dragged()); 285 EXPECT_FALSE(wm::GetWindowState(window.get())->is_dragged());
286 EXPECT_EQ(1, model_->item_count()); 286 EXPECT_EQ(1, model_->item_count());
287 } 287 }
288 288
289 } // namespace internal 289 } // namespace internal
290 } // namespace ash 290 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_window_watcher_item_delegate.cc ('k') | ash/shell.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698