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

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

Issue 71653003: ash: Rename LauncherModel to ShelfModel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: chrome changes Created 7 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
« no previous file with comments | « ash/shelf/shelf_model_observer.h ('k') | ash/shelf/shelf_model_util.h » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/launcher/launcher_model.h" 5 #include "ash/shelf/shelf_model.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "ash/ash_switches.h" 10 #include "ash/ash_switches.h"
11 #include "ash/shelf/shelf_model_observer.h" 11 #include "ash/shelf/shelf_model_observer.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 int added_count_; 68 int added_count_;
69 int removed_count_; 69 int removed_count_;
70 int changed_count_; 70 int changed_count_;
71 int moved_count_; 71 int moved_count_;
72 72
73 DISALLOW_COPY_AND_ASSIGN(TestShelfModelObserver); 73 DISALLOW_COPY_AND_ASSIGN(TestShelfModelObserver);
74 }; 74 };
75 75
76 } // namespace 76 } // namespace
77 77
78 class LauncherModelTest : public testing::Test { 78 class ShelfModelTest : public testing::Test {
79 public: 79 public:
80 LauncherModelTest() {} 80 ShelfModelTest() {}
81 virtual ~LauncherModelTest() {} 81 virtual ~ShelfModelTest() {}
82 82
83 virtual void SetUp() { 83 virtual void SetUp() {
84 model_.reset(new LauncherModel); 84 model_.reset(new ShelfModel);
85 observer_.reset(new TestShelfModelObserver); 85 observer_.reset(new TestShelfModelObserver);
86 EXPECT_EQ(0, model_->item_count()); 86 EXPECT_EQ(0, model_->item_count());
87 87
88 LauncherItem item; 88 LauncherItem item;
89 item.type = TYPE_APP_LIST; 89 item.type = TYPE_APP_LIST;
90 model_->Add(item); 90 model_->Add(item);
91 EXPECT_EQ(1, model_->item_count()); 91 EXPECT_EQ(1, model_->item_count());
92 92
93 model_->AddObserver(observer_.get()); 93 model_->AddObserver(observer_.get());
94 } 94 }
95 95
96 virtual void TearDown() { 96 virtual void TearDown() {
97 observer_.reset(); 97 observer_.reset();
98 model_.reset(); 98 model_.reset();
99 } 99 }
100 100
101 scoped_ptr<LauncherModel> model_; 101 scoped_ptr<ShelfModel> model_;
102 scoped_ptr<TestShelfModelObserver> observer_; 102 scoped_ptr<TestShelfModelObserver> observer_;
103 103
104 private: 104 private:
105 DISALLOW_COPY_AND_ASSIGN(LauncherModelTest); 105 DISALLOW_COPY_AND_ASSIGN(ShelfModelTest);
106 }; 106 };
107 107
108 TEST_F(LauncherModelTest, BasicAssertions) { 108 TEST_F(ShelfModelTest, BasicAssertions) {
109 // Add an item. 109 // Add an item.
110 LauncherItem item; 110 LauncherItem item;
111 item.type = TYPE_APP_SHORTCUT; 111 item.type = TYPE_APP_SHORTCUT;
112 int index = model_->Add(item); 112 int index = model_->Add(item);
113 EXPECT_EQ(2, model_->item_count()); 113 EXPECT_EQ(2, model_->item_count());
114 EXPECT_EQ("added=1", observer_->StateStringAndClear()); 114 EXPECT_EQ("added=1", observer_->StateStringAndClear());
115 115
116 // Change to a platform app item. 116 // Change to a platform app item.
117 LauncherID original_id = model_->items()[index].id; 117 LauncherID original_id = model_->items()[index].id;
118 item.type = TYPE_PLATFORM_APP; 118 item.type = TYPE_PLATFORM_APP;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 EXPECT_EQ("moved=1", observer_->StateStringAndClear()); 150 EXPECT_EQ("moved=1", observer_->StateStringAndClear());
151 151
152 // Verifies all the items get unique ids. 152 // Verifies all the items get unique ids.
153 std::set<LauncherID> ids; 153 std::set<LauncherID> ids;
154 for (int i = 0; i < model_->item_count(); ++i) 154 for (int i = 0; i < model_->item_count(); ++i)
155 ids.insert(model_->items()[i].id); 155 ids.insert(model_->items()[i].id);
156 EXPECT_EQ(model_->item_count(), static_cast<int>(ids.size())); 156 EXPECT_EQ(model_->item_count(), static_cast<int>(ids.size()));
157 } 157 }
158 158
159 // Assertions around where items are added. 159 // Assertions around where items are added.
160 TEST_F(LauncherModelTest, AddIndices) { 160 TEST_F(ShelfModelTest, AddIndices) {
161 // Insert browser short cut at index 1. 161 // Insert browser short cut at index 1.
162 LauncherItem browser_shortcut; 162 LauncherItem browser_shortcut;
163 browser_shortcut.type = TYPE_BROWSER_SHORTCUT; 163 browser_shortcut.type = TYPE_BROWSER_SHORTCUT;
164 int browser_shortcut_index = model_->Add(browser_shortcut); 164 int browser_shortcut_index = model_->Add(browser_shortcut);
165 EXPECT_EQ(1, browser_shortcut_index); 165 EXPECT_EQ(1, browser_shortcut_index);
166 166
167 // platform app items should be after browser shortcut. 167 // platform app items should be after browser shortcut.
168 LauncherItem item; 168 LauncherItem item;
169 item.type = TYPE_PLATFORM_APP; 169 item.type = TYPE_PLATFORM_APP;
170 int platform_app_index1 = model_->Add(item); 170 int platform_app_index1 = model_->Add(item);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 EXPECT_EQ(13, app_panel_index3); 230 EXPECT_EQ(13, app_panel_index3);
231 231
232 // Right aligned index should be the first app panel index. 232 // Right aligned index should be the first app panel index.
233 EXPECT_EQ(12, model_->FirstPanelIndex()); 233 EXPECT_EQ(12, model_->FirstPanelIndex());
234 234
235 EXPECT_EQ(TYPE_BROWSER_SHORTCUT, model_->items()[2].type); 235 EXPECT_EQ(TYPE_BROWSER_SHORTCUT, model_->items()[2].type);
236 EXPECT_EQ(TYPE_APP_LIST, model_->items()[0].type); 236 EXPECT_EQ(TYPE_APP_LIST, model_->items()[0].type);
237 } 237 }
238 238
239 // Assertions around where items are added. 239 // Assertions around where items are added.
240 TEST_F(LauncherModelTest, AddIndicesForLegacyShelfLayout) { 240 TEST_F(ShelfModelTest, AddIndicesForLegacyShelfLayout) {
241 CommandLine::ForCurrentProcess()->AppendSwitch( 241 CommandLine::ForCurrentProcess()->AppendSwitch(
242 ash::switches::kAshDisableAlternateShelfLayout); 242 ash::switches::kAshDisableAlternateShelfLayout);
243 243
244 // Insert browser short cut at index 0. 244 // Insert browser short cut at index 0.
245 LauncherItem browser_shortcut; 245 LauncherItem browser_shortcut;
246 browser_shortcut.type = TYPE_BROWSER_SHORTCUT; 246 browser_shortcut.type = TYPE_BROWSER_SHORTCUT;
247 int browser_shortcut_index = model_->Add(browser_shortcut); 247 int browser_shortcut_index = model_->Add(browser_shortcut);
248 EXPECT_EQ(0, browser_shortcut_index); 248 EXPECT_EQ(0, browser_shortcut_index);
249 249
250 // platform app items should be after browser shortcut. 250 // platform app items should be after browser shortcut.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 EXPECT_EQ(13, app_panel_index3); 313 EXPECT_EQ(13, app_panel_index3);
314 314
315 // Right aligned index should be the first app panel index. 315 // Right aligned index should be the first app panel index.
316 EXPECT_EQ(12, model_->FirstPanelIndex()); 316 EXPECT_EQ(12, model_->FirstPanelIndex());
317 317
318 EXPECT_EQ(TYPE_BROWSER_SHORTCUT, model_->items()[1].type); 318 EXPECT_EQ(TYPE_BROWSER_SHORTCUT, model_->items()[1].type);
319 EXPECT_EQ(TYPE_APP_LIST, model_->items()[model_->FirstPanelIndex() - 1].type); 319 EXPECT_EQ(TYPE_APP_LIST, model_->items()[model_->FirstPanelIndex() - 1].type);
320 } 320 }
321 321
322 // Assertions around id generation and usage. 322 // Assertions around id generation and usage.
323 TEST_F(LauncherModelTest, LauncherIDTests) { 323 TEST_F(ShelfModelTest, LauncherIDTests) {
324 // Get the next to use ID counter. 324 // Get the next to use ID counter.
325 LauncherID id = model_->next_id(); 325 LauncherID id = model_->next_id();
326 326
327 // Calling this function multiple times does not change the returned ID. 327 // Calling this function multiple times does not change the returned ID.
328 EXPECT_EQ(model_->next_id(), id); 328 EXPECT_EQ(model_->next_id(), id);
329 329
330 // Check that when we reserve a value it will be the previously retrieved ID, 330 // Check that when we reserve a value it will be the previously retrieved ID,
331 // but it will not change the item count and retrieving the next ID should 331 // but it will not change the item count and retrieving the next ID should
332 // produce something new. 332 // produce something new.
333 EXPECT_EQ(model_->reserve_external_id(), id); 333 EXPECT_EQ(model_->reserve_external_id(), id);
334 EXPECT_EQ(1, model_->item_count()); 334 EXPECT_EQ(1, model_->item_count());
335 LauncherID id2 = model_->next_id(); 335 LauncherID id2 = model_->next_id();
336 EXPECT_NE(id2, id); 336 EXPECT_NE(id2, id);
337 337
338 // Adding another item to the list should also produce a new ID. 338 // Adding another item to the list should also produce a new ID.
339 LauncherItem item; 339 LauncherItem item;
340 item.type = TYPE_PLATFORM_APP; 340 item.type = TYPE_PLATFORM_APP;
341 model_->Add(item); 341 model_->Add(item);
342 EXPECT_NE(model_->next_id(), id2); 342 EXPECT_NE(model_->next_id(), id2);
343 } 343 }
344 344
345 // This verifies that converting an existing item into a lower weight category 345 // This verifies that converting an existing item into a lower weight category
346 // (e.g. shortcut to running but not pinned app) will move it to the proper 346 // (e.g. shortcut to running but not pinned app) will move it to the proper
347 // location. See crbug.com/248769. 347 // location. See crbug.com/248769.
348 TEST_F(LauncherModelTest, CorrectMoveItemsWhenStateChange) { 348 TEST_F(ShelfModelTest, CorrectMoveItemsWhenStateChange) {
349 // The first item is the app list and last item is the browser. 349 // The first item is the app list and last item is the browser.
350 LauncherItem browser_shortcut; 350 LauncherItem browser_shortcut;
351 browser_shortcut.type = TYPE_BROWSER_SHORTCUT; 351 browser_shortcut.type = TYPE_BROWSER_SHORTCUT;
352 int browser_shortcut_index = model_->Add(browser_shortcut); 352 int browser_shortcut_index = model_->Add(browser_shortcut);
353 EXPECT_EQ(TYPE_APP_LIST, model_->items()[0].type); 353 EXPECT_EQ(TYPE_APP_LIST, model_->items()[0].type);
354 EXPECT_EQ(1, browser_shortcut_index); 354 EXPECT_EQ(1, browser_shortcut_index);
355 355
356 // Add three shortcuts. They should all be moved between the two. 356 // Add three shortcuts. They should all be moved between the two.
357 LauncherItem item; 357 LauncherItem item;
358 item.type = TYPE_APP_SHORTCUT; 358 item.type = TYPE_APP_SHORTCUT;
359 int app1_index = model_->Add(item); 359 int app1_index = model_->Add(item);
360 EXPECT_EQ(2, app1_index); 360 EXPECT_EQ(2, app1_index);
361 int app2_index = model_->Add(item); 361 int app2_index = model_->Add(item);
362 EXPECT_EQ(3, app2_index); 362 EXPECT_EQ(3, app2_index);
363 int app3_index = model_->Add(item); 363 int app3_index = model_->Add(item);
364 EXPECT_EQ(4, app3_index); 364 EXPECT_EQ(4, app3_index);
365 365
366 // Now change the type of the second item and make sure that it is moving 366 // Now change the type of the second item and make sure that it is moving
367 // behind the shortcuts. 367 // behind the shortcuts.
368 item.type = TYPE_PLATFORM_APP; 368 item.type = TYPE_PLATFORM_APP;
369 model_->Set(app2_index, item); 369 model_->Set(app2_index, item);
370 370
371 // The item should have moved in front of the app launcher. 371 // The item should have moved in front of the app launcher.
372 EXPECT_EQ(TYPE_PLATFORM_APP, model_->items()[4].type); 372 EXPECT_EQ(TYPE_PLATFORM_APP, model_->items()[4].type);
373 } 373 }
374 374
375 TEST_F(LauncherModelTest, CorrectMoveItemsWhenStateChangeForLegacyShelfLayout) { 375 TEST_F(ShelfModelTest, CorrectMoveItemsWhenStateChangeForLegacyShelfLayout) {
376 CommandLine::ForCurrentProcess()->AppendSwitch( 376 CommandLine::ForCurrentProcess()->AppendSwitch(
377 ash::switches::kAshDisableAlternateShelfLayout); 377 ash::switches::kAshDisableAlternateShelfLayout);
378 378
379 // The first item is the browser and the second item is app list. 379 // The first item is the browser and the second item is app list.
380 LauncherItem browser_shortcut; 380 LauncherItem browser_shortcut;
381 browser_shortcut.type = TYPE_BROWSER_SHORTCUT; 381 browser_shortcut.type = TYPE_BROWSER_SHORTCUT;
382 int browser_shortcut_index = model_->Add(browser_shortcut); 382 int browser_shortcut_index = model_->Add(browser_shortcut);
383 EXPECT_EQ(0, browser_shortcut_index); 383 EXPECT_EQ(0, browser_shortcut_index);
384 EXPECT_EQ(TYPE_APP_LIST, model_->items()[1].type); 384 EXPECT_EQ(TYPE_APP_LIST, model_->items()[1].type);
385 385
(...skipping 10 matching lines...) Expand all
396 // Now change the type of the second item and make sure that it is moving 396 // Now change the type of the second item and make sure that it is moving
397 // behind the shortcuts. 397 // behind the shortcuts.
398 item.type = TYPE_PLATFORM_APP; 398 item.type = TYPE_PLATFORM_APP;
399 model_->Set(app2_index, item); 399 model_->Set(app2_index, item);
400 400
401 // The item should have moved in front of the app launcher. 401 // The item should have moved in front of the app launcher.
402 EXPECT_EQ(TYPE_PLATFORM_APP, model_->items()[3].type); 402 EXPECT_EQ(TYPE_PLATFORM_APP, model_->items()[3].type);
403 } 403 }
404 404
405 } // namespace ash 405 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_model_observer.h ('k') | ash/shelf/shelf_model_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698