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.h"
6 #include "ash/launcher/launcher_button.h"
7 #include "ash/launcher/launcher_model.h"
8 #include "ash/launcher/launcher_view.h"
10 #include "ash/shell.h"
11 #include "ash/test/ash_test_base.h"
12 #include "ash/test/launcher_view_test_api.h"
13 #include "ash/wm/window_util.h"
14 #include "ui/views/view.h"
15 #include "ui/views/widget/widget.h"
17 typedef ash::test::AshTestBase LauncherTest
;
18 using ash::internal::LauncherView
;
19 using ash::internal::LauncherButton
;
23 // Makes sure invoking SetStatusSize on the launcher changes the size of the
25 TEST_F(LauncherTest
, SetStatusSize
) {
26 Launcher
* launcher
= Launcher::ForPrimaryDisplay();
27 LauncherView
* launcher_view
= launcher
->GetLauncherViewForTest();
29 gfx::Size launcher_size
=
30 launcher
->widget()->GetWindowBoundsInScreen().size();
31 int total_width
= launcher_size
.width();
32 ASSERT_GT(total_width
, 0);
33 launcher
->SetStatusSize(gfx::Size(total_width
/ 2, launcher_size
.height()));
34 EXPECT_EQ(total_width
- total_width
/ 2, launcher_view
->width());
37 // Tests that the dimmer widget resizes itself as appropriate.
38 TEST_F(LauncherTest
, DimmerSize
) {
39 Launcher
* launcher
= Launcher::ForPrimaryDisplay();
40 launcher
->SetDimsShelf(true);
42 gfx::Size launcher_size
=
43 launcher
->widget()->GetWindowBoundsInScreen().size();
45 launcher
->widget()->GetWindowBoundsInScreen().ToString(),
46 launcher
->GetDimmerWidgetForTest()->GetWindowBoundsInScreen().ToString());
48 launcher
->widget()->SetSize(
49 gfx::Size(launcher_size
.width() / 2, launcher_size
.height() + 10));
51 launcher
->widget()->GetWindowBoundsInScreen().ToString(),
52 launcher
->GetDimmerWidgetForTest()->GetWindowBoundsInScreen().ToString());
55 // Confirm that launching a browser gets the appropriate state reflected in
57 TEST_F(LauncherTest
, OpenBrowser
) {
58 Launcher
* launcher
= Launcher::ForPrimaryDisplay();
59 ASSERT_TRUE(launcher
);
60 LauncherView
* launcher_view
= launcher
->GetLauncherViewForTest();
61 test::LauncherViewTestAPI
test(launcher_view
);
62 LauncherModel
* model
= launcher_view
->model();
64 // Initially we have the app list and chrome icon.
65 int button_count
= test
.GetButtonCount();
69 item
.type
= TYPE_TABBED
;
70 item
.status
= STATUS_RUNNING
;
71 int index
= model
->Add(item
);
72 ASSERT_EQ(++button_count
, test
.GetButtonCount());
73 LauncherButton
* button
= test
.GetButton(index
);
74 EXPECT_EQ(LauncherButton::STATE_RUNNING
, button
->state());
77 model
->RemoveItemAt(index
);
78 ASSERT_EQ(--button_count
, test
.GetButtonCount());
81 TEST_F(LauncherTest
, ShowOverflowBubble
) {
82 Launcher
* launcher
= Launcher::ForPrimaryDisplay();
83 ASSERT_TRUE(launcher
);
85 LauncherView
* launcher_view
= launcher
->GetLauncherViewForTest();
86 test::LauncherViewTestAPI
test(launcher_view
);
87 test
.SetAnimationDuration(1); // Speeds up animation for test.
89 LauncherModel
* model
= launcher_view
->model();
91 // Add tabbed browser until overflow.
93 while (!test
.IsOverflowButtonVisible()) {
95 item
.type
= TYPE_TABBED
;
96 item
.status
= STATUS_RUNNING
;
100 ASSERT_LT(items_added
, 10000);
103 // Shows overflow bubble.
104 test
.ShowOverflowBubble();
105 EXPECT_TRUE(launcher
->IsShowingOverflowBubble());
108 // Launcher can't be activated on mouse click, but it is activable from
109 // the focus cycler or as fallback.
110 TEST_F(LauncherTest
, ActivateAsFallback
) {
111 Launcher
* launcher
= Launcher::ForPrimaryDisplay();
112 views::Widget
* launcher_widget
= launcher
->widget();
113 EXPECT_FALSE(launcher_widget
->CanActivate());
115 launcher
->WillActivateAsFallback();
116 EXPECT_TRUE(launcher_widget
->CanActivate());
118 wm::ActivateWindow(launcher_widget
->GetNativeWindow());
119 EXPECT_FALSE(launcher_widget
->CanActivate());