summaryrefslogtreecommitdiffstats
path: root/chromium/ash/launcher/launcher_unittest.cc
blob: 24eca334999436674a46a0f61da57aa1d1a65891 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/launcher/launcher.h"
#include "ash/shelf/shelf_button.h"
#include "ash/shelf/shelf_item_delegate_manager.h"
#include "ash/shelf/shelf_model.h"
#include "ash/shelf/shelf_view.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/launcher_test_api.h"
#include "ash/test/shelf_view_test_api.h"
#include "ash/test/test_shelf_item_delegate.h"
#include "ash/wm/window_util.h"
#include "ui/aura/root_window.h"
#include "ui/gfx/display.h"
#include "ui/gfx/screen.h"
#include "ui/views/corewm/corewm_switches.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"

#if defined(OS_WIN)
#include "base/win/windows_version.h"
#endif

typedef ash::test::AshTestBase LauncherTest;
using ash::internal::ShelfView;
using ash::internal::ShelfButton;

namespace ash {

class LauncherTest : public ash::test::AshTestBase {
 public:
  LauncherTest() : launcher_(NULL),
                   shelf_view_(NULL),
                   shelf_model_(NULL),
                   item_delegate_manager_(NULL) {
  }

  virtual ~LauncherTest() {}

  virtual void SetUp() {
    test::AshTestBase::SetUp();

    launcher_ = Launcher::ForPrimaryDisplay();
    ASSERT_TRUE(launcher_);

    ash::test::LauncherTestAPI test(launcher_);
    shelf_view_ = test.shelf_view();
    shelf_model_ = shelf_view_->model();
    item_delegate_manager_ =
        Shell::GetInstance()->shelf_item_delegate_manager();

    test_.reset(new ash::test::ShelfViewTestAPI(shelf_view_));
  }

  virtual void TearDown() OVERRIDE {
    test::AshTestBase::TearDown();
  }

  Launcher* launcher() {
    return launcher_;
  }

  ShelfView* shelf_view() {
    return shelf_view_;
  }

  ShelfModel* shelf_model() {
    return shelf_model_;
  }

  ShelfItemDelegateManager* item_manager() {
    return item_delegate_manager_;
  }

  ash::test::ShelfViewTestAPI* test_api() {
    return test_.get();
  }

 private:
  Launcher* launcher_;
  ShelfView* shelf_view_;
  ShelfModel* shelf_model_;
  ShelfItemDelegateManager* item_delegate_manager_;
  scoped_ptr<test::ShelfViewTestAPI> test_;

  DISALLOW_COPY_AND_ASSIGN(LauncherTest);
};

// Confirms that LauncherItem reflects the appropriated state.
TEST_F(LauncherTest, StatusReflection) {
  // Initially we have the app list.
  int button_count = test_api()->GetButtonCount();

  // Add running platform app.
  LauncherItem item;
  item.type = TYPE_PLATFORM_APP;
  item.status = STATUS_RUNNING;
  int index = shelf_model()->Add(item);
  ASSERT_EQ(++button_count, test_api()->GetButtonCount());
  ShelfButton* button = test_api()->GetButton(index);
  EXPECT_EQ(ShelfButton::STATE_RUNNING, button->state());

  // Remove it.
  shelf_model()->RemoveItemAt(index);
  ASSERT_EQ(--button_count, test_api()->GetButtonCount());
}

// Confirm that using the menu will clear the hover attribute. To avoid another
// browser test we check this here.
TEST_F(LauncherTest, checkHoverAfterMenu) {
  // Initially we have the app list.
  int button_count = test_api()->GetButtonCount();

  // Add running platform app.
  LauncherItem item;
  item.type = TYPE_PLATFORM_APP;
  item.status = STATUS_RUNNING;
  int index = shelf_model()->Add(item);

  scoped_ptr<ShelfItemDelegate> delegate(
      new test::TestShelfItemDelegate(NULL));
  item_manager()->SetShelfItemDelegate(shelf_model()->items()[index].id,
                                       delegate.Pass());

  ASSERT_EQ(++button_count, test_api()->GetButtonCount());
  ShelfButton* button = test_api()->GetButton(index);
  button->AddState(ShelfButton::STATE_HOVERED);
  button->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE);
  EXPECT_FALSE(button->state() & ShelfButton::STATE_HOVERED);

  // Remove it.
  shelf_model()->RemoveItemAt(index);
}

TEST_F(LauncherTest, ShowOverflowBubble) {
  LauncherID first_item_id = shelf_model()->next_id();

  // Add platform app button until overflow.
  int items_added = 0;
  while (!test_api()->IsOverflowButtonVisible()) {
    LauncherItem item;
    item.type = TYPE_PLATFORM_APP;
    item.status = STATUS_RUNNING;
    shelf_model()->Add(item);

    ++items_added;
    ASSERT_LT(items_added, 10000);
  }

  // Shows overflow bubble.
  test_api()->ShowOverflowBubble();
  EXPECT_TRUE(launcher()->IsShowingOverflowBubble());

  // Removes the first item in main shelf view.
  shelf_model()->RemoveItemAt(shelf_model()->ItemIndexByID(first_item_id));

  // Waits for all transitions to finish and there should be no crash.
  test_api()->RunMessageLoopUntilAnimationsDone();
  EXPECT_FALSE(launcher()->IsShowingOverflowBubble());
}

}  // namespace ash