Fix incorrect handling of accelerators on constrained web dailogs.
[chromium-blink-merge.git] / ash / launcher / launcher_navigator_unittest.cc
blob6c91717a3d9d5d63257e3168262289ae19bf9986
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
3 // found in the LICENSE file.
5 #include "ash/launcher/launcher_navigator.h"
7 #include "ash/launcher/launcher.h"
8 #include "ash/launcher/launcher_model.h"
9 #include "ash/launcher/launcher_types.h"
10 #include "base/compiler_specific.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 namespace ash {
15 namespace {
17 class LauncherNavigatorTest : public testing::Test {
18 public:
19 LauncherNavigatorTest() {}
21 protected:
22 virtual void SetUp() OVERRIDE {
23 model_.reset(new LauncherModel);
26 void SetupMockLauncherModel(LauncherItemType* types,
27 int types_length,
28 int focused_index) {
29 for (int i = 0; i < types_length; ++i) {
30 LauncherItem new_item;
31 new_item.type = types[i];
32 new_item.status =
33 (types[i] == TYPE_TABBED) ? STATUS_RUNNING : STATUS_CLOSED;
34 model_->Add(new_item);
37 // Set the focused item.
38 if (focused_index >= 0) {
39 LauncherItem focused_item =model_->items()[focused_index];
40 if (focused_item.type == TYPE_TABBED) {
41 focused_item.status = STATUS_ACTIVE;
42 model_->Set(focused_index, focused_item);
47 const LauncherModel& model() { return *model_.get(); }
49 private:
50 scoped_ptr<LauncherModel> model_;
52 DISALLOW_COPY_AND_ASSIGN(LauncherNavigatorTest);
55 } // namespace
57 TEST_F(LauncherNavigatorTest, BasicCycle) {
58 // An app shortcut and three windows
59 LauncherItemType types[] = {
60 TYPE_APP_SHORTCUT, TYPE_TABBED, TYPE_TABBED, TYPE_TABBED,
62 // LauncherModel automatically adds BROWSER_SHORTCUT item at the
63 // beginning, so '2' refers the first TYPE_TABBED item.
64 SetupMockLauncherModel(types, arraysize(types), 2);
66 EXPECT_EQ(3, GetNextActivatedItemIndex(model(), CYCLE_FORWARD));
68 // Fourth one. It will skip the APP_SHORTCUT at the beginning of the list and
69 // the APP_LIST item which is automatically added at the end of items.
70 EXPECT_EQ(4, GetNextActivatedItemIndex(model(), CYCLE_BACKWARD));
73 TEST_F(LauncherNavigatorTest, WrapToBeginning) {
74 LauncherItemType types[] = {
75 TYPE_APP_SHORTCUT, TYPE_TABBED, TYPE_TABBED, TYPE_TABBED,
77 SetupMockLauncherModel(types, arraysize(types), 4);
79 // Second one. It skips the APP_LIST item at the end of the list,
80 // wraps to the beginning, and skips BROWSER_SHORTCUT and APP_SHORTCUT
81 // at the beginning of the list.
82 EXPECT_EQ(2, GetNextActivatedItemIndex(model(), CYCLE_FORWARD));
85 TEST_F(LauncherNavigatorTest, Empty) {
86 SetupMockLauncherModel(NULL, 0, -1);
87 EXPECT_EQ(-1, GetNextActivatedItemIndex(model(), CYCLE_FORWARD));
88 EXPECT_EQ(-1, GetNextActivatedItemIndex(model(), CYCLE_BACKWARD));
91 TEST_F(LauncherNavigatorTest, SingleEntry) {
92 LauncherItemType type = TYPE_TABBED;
93 SetupMockLauncherModel(&type, 1, 1);
95 // If there's only one item there and it is already active, there's no item
96 // to be activated next.
97 EXPECT_EQ(-1, GetNextActivatedItemIndex(model(), CYCLE_FORWARD));
98 EXPECT_EQ(-1, GetNextActivatedItemIndex(model(), CYCLE_BACKWARD));
101 TEST_F(LauncherNavigatorTest, NoActive) {
102 LauncherItemType types[] = {
103 TYPE_TABBED, TYPE_TABBED,
105 // Special case: no items are 'STATUS_ACTIVE'.
106 SetupMockLauncherModel(types, arraysize(types), -1);
108 // If there are no active status, pick the first running item as a fallback.
109 EXPECT_EQ(1, GetNextActivatedItemIndex(model(), CYCLE_FORWARD));
110 EXPECT_EQ(1, GetNextActivatedItemIndex(model(), CYCLE_BACKWARD));
113 } // namespace ash