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. 4 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" 9 10 #include "ash/shelf/shelf_widget.h" 11 #include "ash/shell.h" 12 #include "ash/test/ash_test_base.h" 13 #include "ash/test/launcher_view_test_api.h" 14 #include "ash/wm/window_util.h" 15 #include "ui/aura/root_window.h" 16 #include "ui/gfx/display.h" 17 #include "ui/gfx/screen.h" 18 #include "ui/views/corewm/corewm_switches.h" 19 #include "ui/views/view.h" 20 #include "ui/views/widget/widget.h" 21 22 #if defined(OS_WIN) 23 #include "base/win/windows_version.h" 24 #endif 25 26 typedef ash::test::AshTestBase LauncherTest; 27 using ash::internal::LauncherView; 28 using ash::internal::LauncherButton; 29 30 namespace ash { 31 32 // Confirm that launching a browser gets the appropriate state reflected in 33 // its button. 34 TEST_F(LauncherTest, OpenBrowser) { 35 Launcher* launcher = Launcher::ForPrimaryDisplay(); 36 ASSERT_TRUE(launcher); 37 LauncherView* launcher_view = launcher->GetLauncherViewForTest(); 38 test::LauncherViewTestAPI test(launcher_view); 39 LauncherModel* model = launcher_view->model(); 40 41 // Initially we have the app list and chrome icon. 42 int button_count = test.GetButtonCount(); 43 44 // Add running tab. 45 LauncherItem item; 46 item.type = TYPE_TABBED; 47 item.status = STATUS_RUNNING; 48 int index = model->Add(item); 49 ASSERT_EQ(++button_count, test.GetButtonCount()); 50 LauncherButton* button = test.GetButton(index); 51 EXPECT_EQ(LauncherButton::STATE_RUNNING, button->state()); 52 53 // Remove it. 54 model->RemoveItemAt(index); 55 ASSERT_EQ(--button_count, test.GetButtonCount()); 56 } 57 58 // Confirm that using the menu will clear the hover attribute. To avoid another 59 // browser test we check this here. 60 TEST_F(LauncherTest, checkHoverAfterMenu) { 61 Launcher* launcher = Launcher::ForPrimaryDisplay(); 62 ASSERT_TRUE(launcher); 63 LauncherView* launcher_view = launcher->GetLauncherViewForTest(); 64 test::LauncherViewTestAPI test(launcher_view); 65 LauncherModel* model = launcher_view->model(); 66 67 // Initially we have the app list and chrome icon. 68 int button_count = test.GetButtonCount(); 69 70 // Add running tab. 71 LauncherItem item; 72 item.type = TYPE_TABBED; 73 item.status = STATUS_RUNNING; 74 int index = model->Add(item); 75 ASSERT_EQ(++button_count, test.GetButtonCount()); 76 LauncherButton* button = test.GetButton(index); 77 button->AddState(LauncherButton::STATE_HOVERED); 78 button->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); 79 EXPECT_FALSE(button->state() & LauncherButton::STATE_HOVERED); 80 81 // Remove it. 82 model->RemoveItemAt(index); 83 } 84 85 TEST_F(LauncherTest, ShowOverflowBubble) { 86 Launcher* launcher = Launcher::ForPrimaryDisplay(); 87 ASSERT_TRUE(launcher); 88 89 LauncherView* launcher_view = launcher->GetLauncherViewForTest(); 90 test::LauncherViewTestAPI test(launcher_view); 91 92 LauncherModel* model = launcher_view->model(); 93 LauncherID first_item_id = model->next_id(); 94 95 // Add tabbed browser until overflow. 96 int items_added = 0; 97 while (!test.IsOverflowButtonVisible()) { 98 LauncherItem item; 99 item.type = TYPE_TABBED; 100 item.status = STATUS_RUNNING; 101 model->Add(item); 102 103 ++items_added; 104 ASSERT_LT(items_added, 10000); 105 } 106 107 // Shows overflow bubble. 108 test.ShowOverflowBubble(); 109 EXPECT_TRUE(launcher->IsShowingOverflowBubble()); 110 111 // Removes the first item in main launcher view. 112 model->RemoveItemAt(model->ItemIndexByID(first_item_id)); 113 114 // Waits for all transitions to finish and there should be no crash. 115 test.RunMessageLoopUntilAnimationsDone(); 116 EXPECT_FALSE(launcher->IsShowingOverflowBubble()); 117 } 118 119 } // namespace ash 120