Fix incorrect handling of accelerators on constrained web dailogs.
[chromium-blink-merge.git] / ash / launcher / launcher_unittest.cc
blobd5759092c0acb45de39541f4332ebedf675e632c
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;
21 namespace ash {
23 // Makes sure invoking SetStatusSize on the launcher changes the size of the
24 // LauncherView.
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();
44 EXPECT_EQ(
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));
50 EXPECT_EQ(
51 launcher->widget()->GetWindowBoundsInScreen().ToString(),
52 launcher->GetDimmerWidgetForTest()->GetWindowBoundsInScreen().ToString());
55 // Confirm that launching a browser gets the appropriate state reflected in
56 // its button.
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();
67 // Add running tab.
68 LauncherItem item;
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());
76 // Remove it.
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.
92 int items_added = 0;
93 while (!test.IsOverflowButtonVisible()) {
94 LauncherItem item;
95 item.type = TYPE_TABBED;
96 item.status = STATUS_RUNNING;
97 model->Add(item);
99 ++items_added;
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());
122 } // namespace ash