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

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

Issue 2169653002: mash: Move shelf_navigator.* to //ash/common/shelf (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 4 years, 5 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
« no previous file with comments | « ash/shelf/shelf_navigator.cc ('k') | ash/shelf/shelf_widget.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ash/shelf/shelf_navigator.h"
6
7 #include "ash/common/ash_switches.h"
8 #include "ash/common/shelf/shelf_item_types.h"
9 #include "ash/common/shelf/shelf_model.h"
10 #include "ash/shelf/shelf.h"
11 #include "base/command_line.h"
12 #include "base/macros.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace ash {
16
17 namespace {
18
19 class ShelfNavigatorTest : public testing::Test {
20 public:
21 ShelfNavigatorTest() {}
22
23 protected:
24 void SetUp() override {
25 model_.reset(new ShelfModel);
26
27 // Add APP_LIST for test.
28 ShelfItem app_list;
29 app_list.type = TYPE_APP_LIST;
30 model_->Add(app_list);
31
32 // Initially, applist launcher item is only created.
33 int total_num = model_->item_count();
34 EXPECT_EQ(1, total_num);
35 EXPECT_TRUE(model_->items()[0].type == TYPE_APP_LIST);
36
37 // Add BROWSER_SHORTCUT for test.
38 ShelfItem browser_shortcut;
39 browser_shortcut.type = TYPE_BROWSER_SHORTCUT;
40 model_->Add(browser_shortcut);
41 }
42
43 void SetupMockShelfModel(ShelfItemType* types,
44 int types_length,
45 int focused_index) {
46 for (int i = 0; i < types_length; ++i) {
47 ShelfItem new_item;
48 new_item.type = types[i];
49 new_item.status =
50 (types[i] == TYPE_PLATFORM_APP) ? STATUS_RUNNING : STATUS_CLOSED;
51 model_->Add(new_item);
52 }
53
54 // Set the focused item.
55 if (focused_index >= 0) {
56 ShelfItem focused_item = model_->items()[focused_index];
57 if (focused_item.type == TYPE_PLATFORM_APP) {
58 focused_item.status = STATUS_ACTIVE;
59 model_->Set(focused_index, focused_item);
60 }
61 }
62 }
63
64 const ShelfModel& model() { return *model_.get(); }
65
66 private:
67 std::unique_ptr<ShelfModel> model_;
68
69 DISALLOW_COPY_AND_ASSIGN(ShelfNavigatorTest);
70 };
71
72 } // namespace
73
74 TEST_F(ShelfNavigatorTest, BasicCycle) {
75 // An app shortcut and three platform apps.
76 ShelfItemType types[] = {
77 TYPE_APP_SHORTCUT, TYPE_PLATFORM_APP, TYPE_PLATFORM_APP,
78 TYPE_PLATFORM_APP,
79 };
80 // ShelfModel automatically adds BROWSER_SHORTCUT item at the
81 // beginning, so '3' refers the first TYPE_PLATFORM_APP item.
82 SetupMockShelfModel(types, arraysize(types), 3);
83
84 EXPECT_EQ(4, GetNextActivatedItemIndex(model(), CYCLE_FORWARD));
85
86 // Fourth one. It will skip the APP_SHORTCUT at the beginning of the list and
87 // the APP_LIST item which is automatically added at the end of items.
88 EXPECT_EQ(5, GetNextActivatedItemIndex(model(), CYCLE_BACKWARD));
89 }
90
91 TEST_F(ShelfNavigatorTest, WrapToBeginning) {
92 ShelfItemType types[] = {
93 TYPE_APP_SHORTCUT, TYPE_PLATFORM_APP, TYPE_PLATFORM_APP,
94 TYPE_PLATFORM_APP,
95 };
96 SetupMockShelfModel(types, arraysize(types), 5);
97
98 // Second one. It skips the APP_LIST item at the end of the list,
99 // wraps to the beginning, and skips BROWSER_SHORTCUT and APP_SHORTCUT
100 // at the beginning of the list.
101 EXPECT_EQ(3, GetNextActivatedItemIndex(model(), CYCLE_FORWARD));
102 }
103
104 TEST_F(ShelfNavigatorTest, Empty) {
105 SetupMockShelfModel(NULL, 0, -1);
106 EXPECT_EQ(-1, GetNextActivatedItemIndex(model(), CYCLE_FORWARD));
107 EXPECT_EQ(-1, GetNextActivatedItemIndex(model(), CYCLE_BACKWARD));
108 }
109
110 TEST_F(ShelfNavigatorTest, SingleEntry) {
111 ShelfItemType type = TYPE_PLATFORM_APP;
112 SetupMockShelfModel(&type, 1, 2);
113
114 // If there's only one item there and it is already active, there's no item
115 // to be activated next.
116 EXPECT_EQ(-1, GetNextActivatedItemIndex(model(), CYCLE_FORWARD));
117 EXPECT_EQ(-1, GetNextActivatedItemIndex(model(), CYCLE_BACKWARD));
118 }
119
120 TEST_F(ShelfNavigatorTest, NoActive) {
121 ShelfItemType types[] = {
122 TYPE_PLATFORM_APP, TYPE_PLATFORM_APP,
123 };
124 // Special case: no items are 'STATUS_ACTIVE'.
125 SetupMockShelfModel(types, arraysize(types), -1);
126
127 // If there are no active status, pick the first running item as a fallback.
128 EXPECT_EQ(2, GetNextActivatedItemIndex(model(), CYCLE_FORWARD));
129 EXPECT_EQ(2, GetNextActivatedItemIndex(model(), CYCLE_BACKWARD));
130 }
131
132 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_navigator.cc ('k') | ash/shelf/shelf_widget.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698