| 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/launcher/launcher.h" | 8 #include "ash/launcher/launcher.h" |
| 9 #include "ash/launcher/launcher_model.h" | |
| 10 #include "ash/launcher/launcher_types.h" | 9 #include "ash/launcher/launcher_types.h" |
| 10 #include "ash/shelf/shelf_model.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.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 LauncherNavigatorTest : public testing::Test { | 19 class LauncherNavigatorTest : public testing::Test { |
| 20 public: | 20 public: |
| 21 LauncherNavigatorTest() {} | 21 LauncherNavigatorTest() {} |
| 22 | 22 |
| 23 protected: | 23 protected: |
| 24 virtual void SetUp() OVERRIDE { | 24 virtual void SetUp() OVERRIDE { |
| 25 model_.reset(new LauncherModel); | 25 model_.reset(new ShelfModel); |
| 26 | 26 |
| 27 // Add APP_LIST for test. | 27 // Add APP_LIST for test. |
| 28 LauncherItem app_list; | 28 LauncherItem 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 LauncherItem 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 SetupMockLauncherModel(LauncherItemType* types, | 43 void SetupMockShelfModel(LauncherItemType* 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 LauncherItem 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 LauncherItem 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 LauncherModel& model() { return *model_.get(); } | 64 const ShelfModel& model() { return *model_.get(); } |
| 65 | 65 |
| 66 private: | 66 private: |
| 67 scoped_ptr<LauncherModel> model_; | 67 scoped_ptr<ShelfModel> model_; |
| 68 | 68 |
| 69 DISALLOW_COPY_AND_ASSIGN(LauncherNavigatorTest); | 69 DISALLOW_COPY_AND_ASSIGN(LauncherNavigatorTest); |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 class LauncherNavigatorLegacyShelfLayoutTest : public LauncherNavigatorTest { | 72 class LauncherNavigatorLegacyShelfLayoutTest : public LauncherNavigatorTest { |
| 73 public: | 73 public: |
| 74 LauncherNavigatorLegacyShelfLayoutTest() : LauncherNavigatorTest() {} | 74 LauncherNavigatorLegacyShelfLayoutTest() : LauncherNavigatorTest() {} |
| 75 | 75 |
| 76 protected: | 76 protected: |
| 77 virtual void SetUp() OVERRIDE { | 77 virtual void SetUp() OVERRIDE { |
| 78 CommandLine::ForCurrentProcess()->AppendSwitch( | 78 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 79 ash::switches::kAshDisableAlternateShelfLayout); | 79 ash::switches::kAshDisableAlternateShelfLayout); |
| 80 LauncherNavigatorTest::SetUp(); | 80 LauncherNavigatorTest::SetUp(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 private: | 83 private: |
| 84 DISALLOW_COPY_AND_ASSIGN(LauncherNavigatorLegacyShelfLayoutTest); | 84 DISALLOW_COPY_AND_ASSIGN(LauncherNavigatorLegacyShelfLayoutTest); |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 } // namespace | 87 } // namespace |
| 88 | 88 |
| 89 TEST_F(LauncherNavigatorTest, BasicCycle) { | 89 TEST_F(LauncherNavigatorTest, BasicCycle) { |
| 90 // An app shortcut and three platform apps. | 90 // An app shortcut and three platform apps. |
| 91 LauncherItemType types[] = { | 91 LauncherItemType types[] = { |
| 92 TYPE_APP_SHORTCUT, TYPE_PLATFORM_APP, TYPE_PLATFORM_APP, TYPE_PLATFORM_APP, | 92 TYPE_APP_SHORTCUT, TYPE_PLATFORM_APP, TYPE_PLATFORM_APP, TYPE_PLATFORM_APP, |
| 93 }; | 93 }; |
| 94 // LauncherModel automatically adds BROWSER_SHORTCUT item at the | 94 // ShelfModel automatically adds BROWSER_SHORTCUT item at the |
| 95 // beginning, so '3' refers the first TYPE_PLATFORM_APP item. | 95 // beginning, so '3' refers the first TYPE_PLATFORM_APP item. |
| 96 SetupMockLauncherModel(types, arraysize(types), 3); | 96 SetupMockShelfModel(types, arraysize(types), 3); |
| 97 | 97 |
| 98 EXPECT_EQ(4, GetNextActivatedItemIndex(model(), CYCLE_FORWARD)); | 98 EXPECT_EQ(4, GetNextActivatedItemIndex(model(), CYCLE_FORWARD)); |
| 99 | 99 |
| 100 // Fourth one. It will skip the APP_SHORTCUT at the beginning of the list and | 100 // Fourth one. It will skip the APP_SHORTCUT at the beginning of the list and |
| 101 // the APP_LIST item which is automatically added at the end of items. | 101 // the APP_LIST item which is automatically added at the end of items. |
| 102 EXPECT_EQ(5, GetNextActivatedItemIndex(model(), CYCLE_BACKWARD)); | 102 EXPECT_EQ(5, GetNextActivatedItemIndex(model(), CYCLE_BACKWARD)); |
| 103 } | 103 } |
| 104 | 104 |
| 105 TEST_F(LauncherNavigatorLegacyShelfLayoutTest, BasicCycle) { | 105 TEST_F(LauncherNavigatorLegacyShelfLayoutTest, BasicCycle) { |
| 106 // An app shortcut and three platform apps. | 106 // An app shortcut and three platform apps. |
| 107 LauncherItemType types[] = { | 107 LauncherItemType types[] = { |
| 108 TYPE_APP_SHORTCUT, TYPE_PLATFORM_APP, TYPE_PLATFORM_APP, TYPE_PLATFORM_APP, | 108 TYPE_APP_SHORTCUT, TYPE_PLATFORM_APP, TYPE_PLATFORM_APP, TYPE_PLATFORM_APP, |
| 109 }; | 109 }; |
| 110 // LauncherModel automatically adds BROWSER_SHORTCUT item at the | 110 // ShelfModel automatically adds BROWSER_SHORTCUT item at the |
| 111 // beginning, so '2' refers the first TYPE_PLATFORM_APP item. | 111 // beginning, so '2' refers the first TYPE_PLATFORM_APP item. |
| 112 SetupMockLauncherModel(types, arraysize(types), 2); | 112 SetupMockShelfModel(types, arraysize(types), 2); |
| 113 | 113 |
| 114 EXPECT_EQ(3, GetNextActivatedItemIndex(model(), CYCLE_FORWARD)); | 114 EXPECT_EQ(3, GetNextActivatedItemIndex(model(), CYCLE_FORWARD)); |
| 115 | 115 |
| 116 // Fourth one. It will skip the APP_SHORTCUT at the beginning of the list and | 116 // Fourth one. It will skip the APP_SHORTCUT at the beginning of the list and |
| 117 // the APP_LIST item which is automatically added at the end of items. | 117 // the APP_LIST item which is automatically added at the end of items. |
| 118 EXPECT_EQ(4, GetNextActivatedItemIndex(model(), CYCLE_BACKWARD)); | 118 EXPECT_EQ(4, GetNextActivatedItemIndex(model(), CYCLE_BACKWARD)); |
| 119 } | 119 } |
| 120 | 120 |
| 121 TEST_F(LauncherNavigatorTest, WrapToBeginning) { | 121 TEST_F(LauncherNavigatorTest, WrapToBeginning) { |
| 122 LauncherItemType types[] = { | 122 LauncherItemType types[] = { |
| 123 TYPE_APP_SHORTCUT, TYPE_PLATFORM_APP, TYPE_PLATFORM_APP, TYPE_PLATFORM_APP, | 123 TYPE_APP_SHORTCUT, TYPE_PLATFORM_APP, TYPE_PLATFORM_APP, TYPE_PLATFORM_APP, |
| 124 }; | 124 }; |
| 125 SetupMockLauncherModel(types, arraysize(types), 5); | 125 SetupMockShelfModel(types, arraysize(types), 5); |
| 126 | 126 |
| 127 // Second one. It skips the APP_LIST item at the end of the list, | 127 // Second one. It skips the APP_LIST item at the end of the list, |
| 128 // wraps to the beginning, and skips BROWSER_SHORTCUT and APP_SHORTCUT | 128 // wraps to the beginning, and skips BROWSER_SHORTCUT and APP_SHORTCUT |
| 129 // at the beginning of the list. | 129 // at the beginning of the list. |
| 130 EXPECT_EQ(3, GetNextActivatedItemIndex(model(), CYCLE_FORWARD)); | 130 EXPECT_EQ(3, GetNextActivatedItemIndex(model(), CYCLE_FORWARD)); |
| 131 } | 131 } |
| 132 | 132 |
| 133 TEST_F(LauncherNavigatorLegacyShelfLayoutTest, WrapToBeginning) { | 133 TEST_F(LauncherNavigatorLegacyShelfLayoutTest, WrapToBeginning) { |
| 134 LauncherItemType types[] = { | 134 LauncherItemType types[] = { |
| 135 TYPE_APP_SHORTCUT, TYPE_PLATFORM_APP, TYPE_PLATFORM_APP, TYPE_PLATFORM_APP, | 135 TYPE_APP_SHORTCUT, TYPE_PLATFORM_APP, TYPE_PLATFORM_APP, TYPE_PLATFORM_APP, |
| 136 }; | 136 }; |
| 137 SetupMockLauncherModel(types, arraysize(types), 4); | 137 SetupMockShelfModel(types, arraysize(types), 4); |
| 138 | 138 |
| 139 // Second one. It skips the APP_LIST item at the end of the list, | 139 // Second one. It skips the APP_LIST item at the end of the list, |
| 140 // wraps to the beginning, and skips BROWSER_SHORTCUT and APP_SHORTCUT | 140 // wraps to the beginning, and skips BROWSER_SHORTCUT and APP_SHORTCUT |
| 141 // at the beginning of the list. | 141 // at the beginning of the list. |
| 142 EXPECT_EQ(2, GetNextActivatedItemIndex(model(), CYCLE_FORWARD)); | 142 EXPECT_EQ(2, GetNextActivatedItemIndex(model(), CYCLE_FORWARD)); |
| 143 } | 143 } |
| 144 | 144 |
| 145 TEST_F(LauncherNavigatorTest, Empty) { | 145 TEST_F(LauncherNavigatorTest, Empty) { |
| 146 SetupMockLauncherModel(NULL, 0, -1); | 146 SetupMockShelfModel(NULL, 0, -1); |
| 147 EXPECT_EQ(-1, GetNextActivatedItemIndex(model(), CYCLE_FORWARD)); | 147 EXPECT_EQ(-1, GetNextActivatedItemIndex(model(), CYCLE_FORWARD)); |
| 148 EXPECT_EQ(-1, GetNextActivatedItemIndex(model(), CYCLE_BACKWARD)); | 148 EXPECT_EQ(-1, GetNextActivatedItemIndex(model(), CYCLE_BACKWARD)); |
| 149 } | 149 } |
| 150 | 150 |
| 151 TEST_F(LauncherNavigatorTest, SingleEntry) { | 151 TEST_F(LauncherNavigatorTest, SingleEntry) { |
| 152 LauncherItemType type = TYPE_PLATFORM_APP; | 152 LauncherItemType type = TYPE_PLATFORM_APP; |
| 153 SetupMockLauncherModel(&type, 1, 2); | 153 SetupMockShelfModel(&type, 1, 2); |
| 154 | 154 |
| 155 // If there's only one item there and it is already active, there's no item | 155 // If there's only one item there and it is already active, there's no item |
| 156 // to be activated next. | 156 // to be activated next. |
| 157 EXPECT_EQ(-1, GetNextActivatedItemIndex(model(), CYCLE_FORWARD)); | 157 EXPECT_EQ(-1, GetNextActivatedItemIndex(model(), CYCLE_FORWARD)); |
| 158 EXPECT_EQ(-1, GetNextActivatedItemIndex(model(), CYCLE_BACKWARD)); | 158 EXPECT_EQ(-1, GetNextActivatedItemIndex(model(), CYCLE_BACKWARD)); |
| 159 } | 159 } |
| 160 | 160 |
| 161 TEST_F(LauncherNavigatorLegacyShelfLayoutTest, SingleEntry) { | 161 TEST_F(LauncherNavigatorLegacyShelfLayoutTest, SingleEntry) { |
| 162 LauncherItemType type = TYPE_PLATFORM_APP; | 162 LauncherItemType type = TYPE_PLATFORM_APP; |
| 163 SetupMockLauncherModel(&type, 1, 1); | 163 SetupMockShelfModel(&type, 1, 1); |
| 164 | 164 |
| 165 // If there's only one item there and it is already active, there's no item | 165 // If there's only one item there and it is already active, there's no item |
| 166 // to be activated next. | 166 // to be activated next. |
| 167 EXPECT_EQ(-1, GetNextActivatedItemIndex(model(), CYCLE_FORWARD)); | 167 EXPECT_EQ(-1, GetNextActivatedItemIndex(model(), CYCLE_FORWARD)); |
| 168 EXPECT_EQ(-1, GetNextActivatedItemIndex(model(), CYCLE_BACKWARD)); | 168 EXPECT_EQ(-1, GetNextActivatedItemIndex(model(), CYCLE_BACKWARD)); |
| 169 } | 169 } |
| 170 | 170 |
| 171 TEST_F(LauncherNavigatorTest, NoActive) { | 171 TEST_F(LauncherNavigatorTest, NoActive) { |
| 172 LauncherItemType types[] = { | 172 LauncherItemType types[] = { |
| 173 TYPE_PLATFORM_APP, TYPE_PLATFORM_APP, | 173 TYPE_PLATFORM_APP, TYPE_PLATFORM_APP, |
| 174 }; | 174 }; |
| 175 // Special case: no items are 'STATUS_ACTIVE'. | 175 // Special case: no items are 'STATUS_ACTIVE'. |
| 176 SetupMockLauncherModel(types, arraysize(types), -1); | 176 SetupMockShelfModel(types, arraysize(types), -1); |
| 177 | 177 |
| 178 // If there are no active status, pick the first running item as a fallback. | 178 // If there are no active status, pick the first running item as a fallback. |
| 179 EXPECT_EQ(2, GetNextActivatedItemIndex(model(), CYCLE_FORWARD)); | 179 EXPECT_EQ(2, GetNextActivatedItemIndex(model(), CYCLE_FORWARD)); |
| 180 EXPECT_EQ(2, GetNextActivatedItemIndex(model(), CYCLE_BACKWARD)); | 180 EXPECT_EQ(2, GetNextActivatedItemIndex(model(), CYCLE_BACKWARD)); |
| 181 } | 181 } |
| 182 | 182 |
| 183 TEST_F(LauncherNavigatorLegacyShelfLayoutTest, NoActive) { | 183 TEST_F(LauncherNavigatorLegacyShelfLayoutTest, NoActive) { |
| 184 LauncherItemType types[] = { | 184 LauncherItemType types[] = { |
| 185 TYPE_PLATFORM_APP, TYPE_PLATFORM_APP, | 185 TYPE_PLATFORM_APP, TYPE_PLATFORM_APP, |
| 186 }; | 186 }; |
| 187 // Special case: no items are 'STATUS_ACTIVE'. | 187 // Special case: no items are 'STATUS_ACTIVE'. |
| 188 SetupMockLauncherModel(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 |