OLD | NEW |
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_navigator.h" | 5 #include "ash/shelf/shelf_navigator.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/shelf/shelf.h" | 8 #include "ash/shelf/shelf.h" |
9 #include "ash/shelf/shelf_item_types.h" | 9 #include "ash/shelf/shelf_item_types.h" |
10 #include "ash/shelf/shelf_model.h" | 10 #include "ash/shelf/shelf_model.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 namespace ash { | 15 namespace ash { |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 class ShelfNavigatorTest : public testing::Test { | 19 class ShelfNavigatorTest : public testing::Test { |
20 public: | 20 public: |
21 ShelfNavigatorTest() {} | 21 ShelfNavigatorTest() {} |
22 | 22 |
23 protected: | 23 protected: |
24 virtual void SetUp() OVERRIDE { | 24 virtual void SetUp() OVERRIDE { |
25 model_.reset(new ShelfModel); | 25 model_.reset(new ShelfModel); |
26 | 26 |
27 // Add APP_LIST for test. | 27 // Add APP_LIST for test. |
28 LauncherItem app_list; | 28 ShelfItem app_list; |
29 app_list.type = TYPE_APP_LIST; | 29 app_list.type = TYPE_APP_LIST; |
30 model_->Add(app_list); | 30 model_->Add(app_list); |
31 | 31 |
32 // Initially, applist launcher item is only created. | 32 // Initially, applist launcher item is only created. |
33 int total_num = model_->item_count(); | 33 int total_num = model_->item_count(); |
34 EXPECT_EQ(1, total_num); | 34 EXPECT_EQ(1, total_num); |
35 EXPECT_TRUE(model_->items()[0].type == TYPE_APP_LIST); | 35 EXPECT_TRUE(model_->items()[0].type == TYPE_APP_LIST); |
36 | 36 |
37 // Add BROWSER_SHORTCUT for test. | 37 // Add BROWSER_SHORTCUT for test. |
38 LauncherItem browser_shortcut; | 38 ShelfItem browser_shortcut; |
39 browser_shortcut.type = TYPE_BROWSER_SHORTCUT; | 39 browser_shortcut.type = TYPE_BROWSER_SHORTCUT; |
40 model_->Add(browser_shortcut); | 40 model_->Add(browser_shortcut); |
41 } | 41 } |
42 | 42 |
43 void SetupMockShelfModel(ShelfItemType* types, | 43 void SetupMockShelfModel(ShelfItemType* types, |
44 int types_length, | 44 int types_length, |
45 int focused_index) { | 45 int focused_index) { |
46 for (int i = 0; i < types_length; ++i) { | 46 for (int i = 0; i < types_length; ++i) { |
47 LauncherItem new_item; | 47 ShelfItem new_item; |
48 new_item.type = types[i]; | 48 new_item.type = types[i]; |
49 new_item.status = | 49 new_item.status = |
50 (types[i] == TYPE_PLATFORM_APP) ? STATUS_RUNNING : STATUS_CLOSED; | 50 (types[i] == TYPE_PLATFORM_APP) ? STATUS_RUNNING : STATUS_CLOSED; |
51 model_->Add(new_item); | 51 model_->Add(new_item); |
52 } | 52 } |
53 | 53 |
54 // Set the focused item. | 54 // Set the focused item. |
55 if (focused_index >= 0) { | 55 if (focused_index >= 0) { |
56 LauncherItem focused_item =model_->items()[focused_index]; | 56 ShelfItem focused_item =model_->items()[focused_index]; |
57 if (focused_item.type == TYPE_PLATFORM_APP) { | 57 if (focused_item.type == TYPE_PLATFORM_APP) { |
58 focused_item.status = STATUS_ACTIVE; | 58 focused_item.status = STATUS_ACTIVE; |
59 model_->Set(focused_index, focused_item); | 59 model_->Set(focused_index, focused_item); |
60 } | 60 } |
61 } | 61 } |
62 } | 62 } |
63 | 63 |
64 const ShelfModel& model() { return *model_.get(); } | 64 const ShelfModel& model() { return *model_.get(); } |
65 | 65 |
66 private: | 66 private: |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 }; | 186 }; |
187 // Special case: no items are 'STATUS_ACTIVE'. | 187 // Special case: no items are 'STATUS_ACTIVE'. |
188 SetupMockShelfModel(types, arraysize(types), -1); | 188 SetupMockShelfModel(types, arraysize(types), -1); |
189 | 189 |
190 // If there are no active status, pick the first running item as a fallback. | 190 // If there are no active status, pick the first running item as a fallback. |
191 EXPECT_EQ(1, GetNextActivatedItemIndex(model(), CYCLE_FORWARD)); | 191 EXPECT_EQ(1, GetNextActivatedItemIndex(model(), CYCLE_FORWARD)); |
192 EXPECT_EQ(1, GetNextActivatedItemIndex(model(), CYCLE_BACKWARD)); | 192 EXPECT_EQ(1, GetNextActivatedItemIndex(model(), CYCLE_BACKWARD)); |
193 } | 193 } |
194 | 194 |
195 } // namespace ash | 195 } // namespace ash |
OLD | NEW |