| 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::Create(controller_.get(), &item, shelf); |
| 46 } | 49 } |
| 47 | 50 |
| 51 LauncherContextMenu* CreateLauncherContextMenuForDesktopShell() { |
| 52 ash::ShelfItem* item = nullptr; |
| 53 ash::Shelf* shelf = ash::Shelf::ForWindow(CurrentContext()); |
| 54 return LauncherContextMenu::Create(controller_.get(), item, shelf); |
| 55 } |
| 56 |
| 57 #if defined(OS_CHROMEOS) |
| 58 LauncherContextMenu* CreateLauncherContextMenuForArcApp() { |
| 59 ash::ShelfItem item; |
| 60 item.id = 1; |
| 61 ash::Shelf* shelf = ash::Shelf::ForWindow(CurrentContext()); |
| 62 return new ArcLauncherContextMenu(controller_.get(), &item, shelf); |
| 63 } |
| 64 #endif |
| 65 |
| 48 Profile* profile() { return profile_.get(); } | 66 Profile* profile() { return profile_.get(); } |
| 49 | 67 |
| 50 private: | 68 private: |
| 51 scoped_ptr<TestingProfile> profile_; | 69 scoped_ptr<TestingProfile> profile_; |
| 52 ash::ShelfModel shelf_model_; | 70 ash::ShelfModel shelf_model_; |
| 53 scoped_ptr<ChromeLauncherController> controller_; | 71 scoped_ptr<ChromeLauncherController> controller_; |
| 54 | 72 |
| 55 DISALLOW_COPY_AND_ASSIGN(LauncherContextMenuTest); | 73 DISALLOW_COPY_AND_ASSIGN(LauncherContextMenuTest); |
| 56 }; | 74 }; |
| 57 | 75 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 EXPECT_TRUE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_NEW_WINDOW)); | 108 EXPECT_TRUE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_NEW_WINDOW)); |
| 91 | 109 |
| 92 // Disable Incognito mode. | 110 // Disable Incognito mode. |
| 93 IncognitoModePrefs::SetAvailability(profile()->GetPrefs(), | 111 IncognitoModePrefs::SetAvailability(profile()->GetPrefs(), |
| 94 IncognitoModePrefs::FORCED); | 112 IncognitoModePrefs::FORCED); |
| 95 menu.reset(CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT)); | 113 menu.reset(CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT)); |
| 96 ASSERT_TRUE(IsItemPresentInMenu( | 114 ASSERT_TRUE(IsItemPresentInMenu( |
| 97 menu.get(), LauncherContextMenu::MENU_NEW_WINDOW)); | 115 menu.get(), LauncherContextMenu::MENU_NEW_WINDOW)); |
| 98 EXPECT_FALSE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_NEW_WINDOW)); | 116 EXPECT_FALSE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_NEW_WINDOW)); |
| 99 } | 117 } |
| 118 |
| 119 // Verifies status of contextmenu items for desktop shell. |
| 120 TEST_F(LauncherContextMenuTest, DesktopShellLauncherContextMenuItemCheck) { |
| 121 scoped_ptr<LauncherContextMenu> menu( |
| 122 CreateLauncherContextMenuForDesktopShell()); |
| 123 EXPECT_FALSE( |
| 124 IsItemPresentInMenu(menu.get(), LauncherContextMenu::MENU_OPEN_NEW)); |
| 125 EXPECT_FALSE(IsItemPresentInMenu(menu.get(), LauncherContextMenu::MENU_PIN)); |
| 126 EXPECT_TRUE( |
| 127 IsItemPresentInMenu(menu.get(), LauncherContextMenu::MENU_AUTO_HIDE)); |
| 128 EXPECT_TRUE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_AUTO_HIDE)); |
| 129 EXPECT_TRUE(IsItemPresentInMenu(menu.get(), |
| 130 LauncherContextMenu::MENU_ALIGNMENT_MENU)); |
| 131 EXPECT_TRUE( |
| 132 menu->IsCommandIdEnabled(LauncherContextMenu::MENU_ALIGNMENT_MENU)); |
| 133 #if defined(OS_CHROMEOS) |
| 134 // By default, screen is not locked and ChangeWallPaper item is added in |
| 135 // menu. ChangeWallPaper item is not enabled in default mode. |
| 136 EXPECT_TRUE(IsItemPresentInMenu(menu.get(), |
| 137 LauncherContextMenu::MENU_CHANGE_WALLPAPER)); |
| 138 EXPECT_FALSE( |
| 139 menu->IsCommandIdEnabled(LauncherContextMenu::MENU_CHANGE_WALLPAPER)); |
| 140 #endif |
| 141 } |
| 142 |
| 143 // Verifies contextmenu items for Arc app |
| 144 #if defined(OS_CHROMEOS) |
| 145 TEST_F(LauncherContextMenuTest, ArcLauncherContextMenuItemCheck) { |
| 146 scoped_ptr<LauncherContextMenu> menu(CreateLauncherContextMenuForArcApp()); |
| 147 EXPECT_TRUE( |
| 148 IsItemPresentInMenu(menu.get(), LauncherContextMenu::MENU_OPEN_NEW)); |
| 149 EXPECT_TRUE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_OPEN_NEW)); |
| 150 EXPECT_TRUE( |
| 151 IsItemPresentInMenu(menu.get(), LauncherContextMenu::MENU_AUTO_HIDE)); |
| 152 EXPECT_TRUE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_AUTO_HIDE)); |
| 153 EXPECT_TRUE(IsItemPresentInMenu(menu.get(), |
| 154 LauncherContextMenu::MENU_ALIGNMENT_MENU)); |
| 155 EXPECT_TRUE( |
| 156 menu->IsCommandIdEnabled(LauncherContextMenu::MENU_ALIGNMENT_MENU)); |
| 157 // By default, screen is not locked and ChangeWallPaper item is added in |
| 158 // menu. ChangeWallPaper item is not enabled in default mode. |
| 159 EXPECT_TRUE(IsItemPresentInMenu(menu.get(), |
| 160 LauncherContextMenu::MENU_CHANGE_WALLPAPER)); |
| 161 EXPECT_FALSE( |
| 162 menu->IsCommandIdEnabled(LauncherContextMenu::MENU_CHANGE_WALLPAPER)); |
| 163 } |
| 164 #endif |
| OLD | NEW |