| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h" | 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "ash/common/ash_switches.h" | 9 #include "ash/common/ash_switches.h" |
| 10 #include "ash/common/shelf/app_list_button.h" | 10 #include "ash/common/shelf/app_list_button.h" |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 // This triggers an internal cancel. Using VKEY_ESCAPE was too unreliable. | 367 // This triggers an internal cancel. Using VKEY_ESCAPE was too unreliable. |
| 368 button->OnMouseCaptureLost(); | 368 button->OnMouseCaptureLost(); |
| 369 } | 369 } |
| 370 if (command != RIP_OFF_ITEM_AND_DONT_RELEASE_MOUSE) { | 370 if (command != RIP_OFF_ITEM_AND_DONT_RELEASE_MOUSE) { |
| 371 generator->ReleaseLeftButton(); | 371 generator->ReleaseLeftButton(); |
| 372 base::RunLoop().RunUntilIdle(); | 372 base::RunLoop().RunUntilIdle(); |
| 373 test->RunMessageLoopUntilAnimationsDone(); | 373 test->RunMessageLoopUntilAnimationsDone(); |
| 374 } | 374 } |
| 375 } | 375 } |
| 376 | 376 |
| 377 std::unique_ptr<LauncherContextMenu> CreateLauncherContextMenu( | 377 // Creates a context menu for the existing browser shortcut item. |
| 378 ash::ShelfItemType shelf_item_type) { | 378 std::unique_ptr<LauncherContextMenu> CreateBrowserItemContextMenu() { |
| 379 ash::ShelfItem item; | 379 int index = model_->GetItemIndexForType(ash::TYPE_BROWSER_SHORTCUT); |
| 380 item.id = 1; // dummy id | 380 DCHECK_GE(index, 0); |
| 381 item.type = shelf_item_type; | 381 ash::ShelfItem item = model_->items()[index]; |
| 382 ash::Shelf* shelf = ash::Shelf::ForWindow(CurrentContext()); | 382 ash::Shelf* shelf = ash::Shelf::ForWindow(CurrentContext()); |
| 383 std::unique_ptr<LauncherContextMenu> menu(LauncherContextMenu::Create( | 383 std::unique_ptr<LauncherContextMenu> menu(LauncherContextMenu::Create( |
| 384 controller_, &item, ash::test::ShelfTestAPI(shelf).wm_shelf())); | 384 controller_, &item, ash::test::ShelfTestAPI(shelf).wm_shelf())); |
| 385 return menu; | 385 return menu; |
| 386 } | 386 } |
| 387 | 387 |
| 388 aura::Window* CurrentContext() { | 388 aura::Window* CurrentContext() { |
| 389 aura::Window* root_window = ash::Shell::GetTargetRootWindow(); | 389 aura::Window* root_window = ash::Shell::GetTargetRootWindow(); |
| 390 DCHECK(root_window); | 390 DCHECK(root_window); |
| 391 return root_window; | 391 return root_window; |
| (...skipping 1996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2388 // The apps should now be running, with the last opened app active. | 2388 // The apps should now be running, with the last opened app active. |
| 2389 EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(hosted_app_shelf_id)->status); | 2389 EXPECT_EQ(ash::STATUS_RUNNING, model_->ItemByID(hosted_app_shelf_id)->status); |
| 2390 EXPECT_EQ(ash::STATUS_ACTIVE, | 2390 EXPECT_EQ(ash::STATUS_ACTIVE, |
| 2391 model_->ItemByID(bookmark_app_shelf_id)->status); | 2391 model_->ItemByID(bookmark_app_shelf_id)->status); |
| 2392 } | 2392 } |
| 2393 | 2393 |
| 2394 // Test that "Close" is shown in the context menu when there are opened browsers | 2394 // Test that "Close" is shown in the context menu when there are opened browsers |
| 2395 // windows. | 2395 // windows. |
| 2396 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, | 2396 IN_PROC_BROWSER_TEST_F(ShelfAppBrowserTest, |
| 2397 LauncherContextMenuVerifyCloseItemAppearance) { | 2397 LauncherContextMenuVerifyCloseItemAppearance) { |
| 2398 // Open a new window. | 2398 // Open a context menu for the existing browser window. |
| 2399 aura::Window* window1 = browser()->window()->GetNativeWindow(); | 2399 std::unique_ptr<LauncherContextMenu> menu1 = CreateBrowserItemContextMenu(); |
| 2400 ash::wm::WindowState* window1_state = ash::wm::GetWindowState(window1); | |
| 2401 window1->Show(); | |
| 2402 window1_state->Activate(); | |
| 2403 std::unique_ptr<LauncherContextMenu> menu1 = | |
| 2404 CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT); | |
| 2405 // Check if "Close" is added to in the context menu. | 2400 // Check if "Close" is added to in the context menu. |
| 2406 ASSERT_TRUE( | 2401 ASSERT_TRUE( |
| 2407 IsItemPresentInMenu(menu1.get(), LauncherContextMenu::MENU_CLOSE)); | 2402 IsItemPresentInMenu(menu1.get(), LauncherContextMenu::MENU_CLOSE)); |
| 2408 | 2403 |
| 2409 // Close all windows. | 2404 // Close all windows via the menu item. |
| 2410 CloseBrowserWindow(browser(), menu1.get(), LauncherContextMenu::MENU_CLOSE); | 2405 CloseBrowserWindow(browser(), menu1.get(), LauncherContextMenu::MENU_CLOSE); |
| 2411 EXPECT_EQ(0u, BrowserList::GetInstance()->size()); | 2406 EXPECT_EQ(0u, BrowserList::GetInstance()->size()); |
| 2412 | 2407 |
| 2413 // Check if "Close" is removed from the context menu. | 2408 // Check if "Close" is removed from the context menu. |
| 2414 std::unique_ptr<LauncherContextMenu> menu2 = | 2409 std::unique_ptr<LauncherContextMenu> menu2 = CreateBrowserItemContextMenu(); |
| 2415 CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT); | |
| 2416 ASSERT_FALSE( | 2410 ASSERT_FALSE( |
| 2417 IsItemPresentInMenu(menu2.get(), LauncherContextMenu::MENU_CLOSE)); | 2411 IsItemPresentInMenu(menu2.get(), LauncherContextMenu::MENU_CLOSE)); |
| 2418 } | 2412 } |
| OLD | NEW |