| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/launcher_context_menu.h" | 5 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" |
| 6 | 6 |
| 7 #include "ash/shelf/shelf.h" | 7 #include "ash/shelf/shelf.h" |
| 8 #include "ash/shelf/shelf_item_types.h" | 8 #include "ash/shelf/shelf_item_types.h" |
| 9 #include "ash/shelf/shelf_model.h" | 9 #include "ash/shelf/shelf_model.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 11 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "chrome/app/chrome_command_ids.h" | 13 #include "chrome/app/chrome_command_ids.h" |
| 14 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 14 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/ui/ash/launcher/arc_launcher_context_menu.h" |
| 16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 17 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 18 #include "chrome/browser/ui/ash/launcher/desktop_shell_launcher_context_menu.h" |
| 19 #include "chrome/browser/ui/ash/launcher/extension_launcher_context_menu.h" |
| 17 #include "chrome/test/base/testing_profile.h" | 20 #include "chrome/test/base/testing_profile.h" |
| 18 #include "components/prefs/pref_service.h" | 21 #include "components/prefs/pref_service.h" |
| 19 #include "ui/aura/window_event_dispatcher.h" | 22 #include "ui/aura/window_event_dispatcher.h" |
| 20 | 23 |
| 21 class LauncherContextMenuTest : public ash::test::AshTestBase { | 24 class LauncherContextMenuTest : public ash::test::AshTestBase { |
| 22 protected: | 25 protected: |
| 23 static bool IsItemPresentInMenu(LauncherContextMenu* menu, int command_id) { | 26 static bool IsItemPresentInMenu(LauncherContextMenu* menu, int command_id) { |
| 24 return menu->GetIndexOfCommandId(command_id) != -1; | 27 return menu->GetIndexOfCommandId(command_id) != -1; |
| 25 } | 28 } |
| 26 | 29 |
| 27 LauncherContextMenuTest() : profile_(new TestingProfile()) {} | 30 LauncherContextMenuTest() : profile_(new TestingProfile()) {} |
| 28 | 31 |
| 29 void SetUp() override { | 32 void SetUp() override { |
| 30 ash::test::AshTestBase::SetUp(); | 33 ash::test::AshTestBase::SetUp(); |
| 31 controller_.reset(new ChromeLauncherController(profile(), &shelf_model_)); | 34 controller_.reset(new ChromeLauncherController(profile(), &shelf_model_)); |
| 32 } | 35 } |
| 33 | 36 |
| 34 void TearDown() override { | 37 void TearDown() override { |
| 35 controller_.reset(nullptr); | 38 controller_.reset(nullptr); |
| 36 ash::test::AshTestBase::TearDown(); | 39 ash::test::AshTestBase::TearDown(); |
| 37 } | 40 } |
| 38 | 41 |
| 39 LauncherContextMenu* CreateLauncherContextMenu( | 42 LauncherContextMenu* CreateLauncherContextMenu( |
| 40 ash::ShelfItemType shelf_item_type) { | 43 ash::ShelfItemType shelf_item_type) { |
| 41 ash::ShelfItem item; | 44 ash::ShelfItem item; |
| 42 item.id = 1; // dummy id | 45 item.id = 1; // dummy id |
| 43 item.type = shelf_item_type; | 46 item.type = shelf_item_type; |
| 44 ash::Shelf* shelf = ash::Shelf::ForWindow(CurrentContext()); | 47 ash::Shelf* shelf = ash::Shelf::ForWindow(CurrentContext()); |
| 45 return new LauncherContextMenu(controller_.get(), &item, shelf); | 48 return LauncherContextMenu::CreateLauncherContextMenu(controller_.get(), |
| 49 &item, shelf); |
| 46 } | 50 } |
| 47 | 51 |
| 52 LauncherContextMenu* CreateLauncherContextMenuForDesktopShell() { |
| 53 ash::ShelfItem* item = nullptr; |
| 54 ash::Shelf* shelf = ash::Shelf::ForWindow(CurrentContext()); |
| 55 return LauncherContextMenu::CreateLauncherContextMenu(controller_.get(), |
| 56 item, shelf); |
| 57 } |
| 58 |
| 59 LauncherContextMenu* CreateLauncherContextMenuForArcApp() { |
| 60 ash::ShelfItem item; |
| 61 item.id = 1; |
| 62 ash::Shelf* shelf = ash::Shelf::ForWindow(CurrentContext()); |
| 63 return new ArcLauncherContextMenu(controller_.get(), &item, shelf); |
| 64 } |
| 48 Profile* profile() { return profile_.get(); } | 65 Profile* profile() { return profile_.get(); } |
| 49 | 66 |
| 50 private: | 67 private: |
| 51 scoped_ptr<TestingProfile> profile_; | 68 scoped_ptr<TestingProfile> profile_; |
| 52 ash::ShelfModel shelf_model_; | 69 ash::ShelfModel shelf_model_; |
| 53 scoped_ptr<ChromeLauncherController> controller_; | 70 scoped_ptr<ChromeLauncherController> controller_; |
| 54 | 71 |
| 55 DISALLOW_COPY_AND_ASSIGN(LauncherContextMenuTest); | 72 DISALLOW_COPY_AND_ASSIGN(LauncherContextMenuTest); |
| 56 }; | 73 }; |
| 57 | 74 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 EXPECT_TRUE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_NEW_WINDOW)); | 107 EXPECT_TRUE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_NEW_WINDOW)); |
| 91 | 108 |
| 92 // Disable Incognito mode. | 109 // Disable Incognito mode. |
| 93 IncognitoModePrefs::SetAvailability(profile()->GetPrefs(), | 110 IncognitoModePrefs::SetAvailability(profile()->GetPrefs(), |
| 94 IncognitoModePrefs::FORCED); | 111 IncognitoModePrefs::FORCED); |
| 95 menu.reset(CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT)); | 112 menu.reset(CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT)); |
| 96 ASSERT_TRUE(IsItemPresentInMenu( | 113 ASSERT_TRUE(IsItemPresentInMenu( |
| 97 menu.get(), LauncherContextMenu::MENU_NEW_WINDOW)); | 114 menu.get(), LauncherContextMenu::MENU_NEW_WINDOW)); |
| 98 EXPECT_FALSE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_NEW_WINDOW)); | 115 EXPECT_FALSE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_NEW_WINDOW)); |
| 99 } | 116 } |
| 117 |
| 118 // Verifies status of contextmenu items for desktop shell. |
| 119 TEST_F(LauncherContextMenuTest, DesktopShellLauncherContextMenuItemCheck) { |
| 120 scoped_ptr<LauncherContextMenu> menu( |
| 121 CreateLauncherContextMenuForDesktopShell()); |
| 122 EXPECT_FALSE( |
| 123 IsItemPresentInMenu(menu.get(), LauncherContextMenu::MENU_OPEN_NEW)); |
| 124 EXPECT_FALSE(IsItemPresentInMenu(menu.get(), LauncherContextMenu::MENU_PIN)); |
| 125 EXPECT_TRUE( |
| 126 IsItemPresentInMenu(menu.get(), LauncherContextMenu::MENU_AUTO_HIDE)); |
| 127 EXPECT_TRUE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_AUTO_HIDE)); |
| 128 EXPECT_TRUE(IsItemPresentInMenu(menu.get(), |
| 129 LauncherContextMenu::MENU_ALIGNMENT_MENU)); |
| 130 EXPECT_TRUE( |
| 131 menu->IsCommandIdEnabled(LauncherContextMenu::MENU_ALIGNMENT_MENU)); |
| 132 #if defined(OS_CHROMEOS) |
| 133 // By default, screen is not locked and ChangeWallPaper item is added in |
| 134 // menu. ChangeWallPaper item is not enabled in default mode. |
| 135 EXPECT_TRUE(IsItemPresentInMenu(menu.get(), |
| 136 LauncherContextMenu::MENU_CHANGE_WALLPAPER)); |
| 137 EXPECT_FALSE( |
| 138 menu->IsCommandIdEnabled(LauncherContextMenu::MENU_CHANGE_WALLPAPER)); |
| 139 #endif |
| 140 } |
| 141 |
| 142 // Verifies contextmenu items for Arc app |
| 143 TEST_F(LauncherContextMenuTest, ArcLauncherContextMenuItemCheck) { |
| 144 #if defined(OS_CHROMEOS) |
| 145 scoped_ptr<LauncherContextMenu> menu(CreateLauncherContextMenuForArcApp()); |
| 146 EXPECT_TRUE( |
| 147 IsItemPresentInMenu(menu.get(), LauncherContextMenu::MENU_OPEN_NEW)); |
| 148 EXPECT_TRUE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_OPEN_NEW)); |
| 149 EXPECT_TRUE( |
| 150 IsItemPresentInMenu(menu.get(), LauncherContextMenu::MENU_AUTO_HIDE)); |
| 151 EXPECT_TRUE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_AUTO_HIDE)); |
| 152 EXPECT_TRUE(IsItemPresentInMenu(menu.get(), |
| 153 LauncherContextMenu::MENU_ALIGNMENT_MENU)); |
| 154 EXPECT_TRUE( |
| 155 menu->IsCommandIdEnabled(LauncherContextMenu::MENU_ALIGNMENT_MENU)); |
| 156 // By default, screen is not locked and ChangeWallPaper item is added in |
| 157 // menu. ChangeWallPaper item is not enabled in default mode. |
| 158 EXPECT_TRUE(IsItemPresentInMenu(menu.get(), |
| 159 LauncherContextMenu::MENU_CHANGE_WALLPAPER)); |
| 160 EXPECT_FALSE( |
| 161 menu->IsCommandIdEnabled(LauncherContextMenu::MENU_CHANGE_WALLPAPER)); |
| 162 #endif |
| 163 } |
| OLD | NEW |