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