| 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/common/shelf/shelf_item_types.h" | 7 #include "ash/common/shelf/shelf_item_types.h" |
| 8 #include "ash/common/wm_root_window_controller.h" | 8 #include "ash/common/wm_root_window_controller.h" |
| 9 #include "ash/common/wm_shell.h" | 9 #include "ash/common/wm_shell.h" |
| 10 #include "ash/common/wm_window.h" | 10 #include "ash/common/wm_window.h" |
| 11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "ash/test/ash_test_base.h" | 12 #include "ash/test/ash_test_base.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "chrome/app/chrome_command_ids.h" | 14 #include "chrome/app/chrome_command_ids.h" |
| 15 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 15 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/ui/app_list/arc/arc_app_test.h" | 17 #include "chrome/browser/ui/app_list/arc/arc_app_test.h" |
| 18 #include "chrome/browser/ui/ash/launcher/arc_launcher_context_menu.h" | 18 #include "chrome/browser/ui/ash/launcher/arc_launcher_context_menu.h" |
| 19 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll
er.h" | 19 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll
er.h" |
| 20 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h" | 20 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h" |
| 21 #include "chrome/browser/ui/ash/launcher/desktop_shell_launcher_context_menu.h" | 21 #include "chrome/browser/ui/ash/launcher/desktop_shell_launcher_context_menu.h" |
| 22 #include "chrome/browser/ui/ash/launcher/extension_launcher_context_menu.h" | 22 #include "chrome/browser/ui/ash/launcher/extension_launcher_context_menu.h" |
| 23 #include "chrome/test/base/testing_profile.h" | 23 #include "chrome/test/base/testing_profile.h" |
| 24 #include "components/arc/test/fake_app_instance.h" | 24 #include "components/arc/test/fake_app_instance.h" |
| 25 #include "components/exo/shell_surface.h" | |
| 26 #include "components/prefs/pref_service.h" | 25 #include "components/prefs/pref_service.h" |
| 27 #include "ui/aura/window_event_dispatcher.h" | 26 #include "ui/aura/window_event_dispatcher.h" |
| 28 #include "ui/views/widget/widget.h" | |
| 29 | 27 |
| 30 class LauncherContextMenuTest : public ash::test::AshTestBase { | 28 class LauncherContextMenuTest : public ash::test::AshTestBase { |
| 31 protected: | 29 protected: |
| 32 static bool IsItemPresentInMenu(LauncherContextMenu* menu, int command_id) { | 30 static bool IsItemPresentInMenu(LauncherContextMenu* menu, int command_id) { |
| 33 return menu->GetIndexOfCommandId(command_id) != -1; | 31 return menu->GetIndexOfCommandId(command_id) != -1; |
| 34 } | 32 } |
| 35 | 33 |
| 36 LauncherContextMenuTest() : profile_(new TestingProfile()) {} | 34 LauncherContextMenuTest() : profile_(new TestingProfile()) {} |
| 37 | 35 |
| 38 void SetUp() override { | 36 void SetUp() override { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 61 item.id = 1; // dummy id | 59 item.id = 1; // dummy id |
| 62 item.type = shelf_item_type; | 60 item.type = shelf_item_type; |
| 63 return LauncherContextMenu::Create(controller_.get(), &item, GetWmShelf()); | 61 return LauncherContextMenu::Create(controller_.get(), &item, GetWmShelf()); |
| 64 } | 62 } |
| 65 | 63 |
| 66 LauncherContextMenu* CreateLauncherContextMenuForDesktopShell() { | 64 LauncherContextMenu* CreateLauncherContextMenuForDesktopShell() { |
| 67 ash::ShelfItem* item = nullptr; | 65 ash::ShelfItem* item = nullptr; |
| 68 return LauncherContextMenu::Create(controller_.get(), item, GetWmShelf()); | 66 return LauncherContextMenu::Create(controller_.get(), item, GetWmShelf()); |
| 69 } | 67 } |
| 70 | 68 |
| 71 // Creates app window and set optional Arc application id. | |
| 72 views::Widget* CreateArcWindow(std::string& window_app_id) { | |
| 73 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | |
| 74 views::Widget* widget = new views::Widget(); | |
| 75 widget->Init(params); | |
| 76 widget->Show(); | |
| 77 widget->Activate(); | |
| 78 exo::ShellSurface::SetApplicationId(widget->GetNativeWindow(), | |
| 79 &window_app_id); | |
| 80 return widget; | |
| 81 } | |
| 82 | |
| 83 ArcAppTest& arc_test() { return arc_test_; } | 69 ArcAppTest& arc_test() { return arc_test_; } |
| 84 | 70 |
| 85 Profile* profile() { return profile_.get(); } | 71 Profile* profile() { return profile_.get(); } |
| 86 | 72 |
| 87 ChromeLauncherControllerImpl* controller() { return controller_.get(); } | 73 ChromeLauncherControllerImpl* controller() { return controller_.get(); } |
| 88 | 74 |
| 89 private: | 75 private: |
| 90 std::unique_ptr<TestingProfile> profile_; | 76 std::unique_ptr<TestingProfile> profile_; |
| 91 std::unique_ptr<ChromeLauncherControllerImpl> controller_; | 77 std::unique_ptr<ChromeLauncherControllerImpl> controller_; |
| 92 ArcAppTest arc_test_; | 78 ArcAppTest arc_test_; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 EXPECT_TRUE( | 187 EXPECT_TRUE( |
| 202 menu->IsCommandIdEnabled(LauncherContextMenu::MENU_ALIGNMENT_MENU)); | 188 menu->IsCommandIdEnabled(LauncherContextMenu::MENU_ALIGNMENT_MENU)); |
| 203 // By default, screen is not locked and ChangeWallPaper item is added in | 189 // By default, screen is not locked and ChangeWallPaper item is added in |
| 204 // menu. ChangeWallPaper item is not enabled in default mode. | 190 // menu. ChangeWallPaper item is not enabled in default mode. |
| 205 EXPECT_TRUE(IsItemPresentInMenu(menu.get(), | 191 EXPECT_TRUE(IsItemPresentInMenu(menu.get(), |
| 206 LauncherContextMenu::MENU_CHANGE_WALLPAPER)); | 192 LauncherContextMenu::MENU_CHANGE_WALLPAPER)); |
| 207 EXPECT_FALSE( | 193 EXPECT_FALSE( |
| 208 menu->IsCommandIdEnabled(LauncherContextMenu::MENU_CHANGE_WALLPAPER)); | 194 menu->IsCommandIdEnabled(LauncherContextMenu::MENU_CHANGE_WALLPAPER)); |
| 209 | 195 |
| 210 // Arc app is running. | 196 // Arc app is running. |
| 211 std::string window_app_id1("org.chromium.arc.1"); | |
| 212 CreateArcWindow(window_app_id1); | |
| 213 arc_test().app_instance()->SendTaskCreated(1, arc_test().fake_apps()[0]); | 197 arc_test().app_instance()->SendTaskCreated(1, arc_test().fake_apps()[0]); |
| 214 menu.reset(new ArcLauncherContextMenu(controller(), &item, wm_shelf)); | 198 menu.reset(new ArcLauncherContextMenu(controller(), &item, wm_shelf)); |
| 215 | 199 |
| 216 EXPECT_FALSE( | 200 EXPECT_FALSE( |
| 217 IsItemPresentInMenu(menu.get(), LauncherContextMenu::MENU_OPEN_NEW)); | 201 IsItemPresentInMenu(menu.get(), LauncherContextMenu::MENU_OPEN_NEW)); |
| 218 EXPECT_TRUE(IsItemPresentInMenu(menu.get(), LauncherContextMenu::MENU_PIN)); | 202 EXPECT_TRUE(IsItemPresentInMenu(menu.get(), LauncherContextMenu::MENU_PIN)); |
| 219 EXPECT_TRUE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_PIN)); | 203 EXPECT_TRUE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_PIN)); |
| 220 EXPECT_TRUE(IsItemPresentInMenu(menu.get(), LauncherContextMenu::MENU_CLOSE)); | 204 EXPECT_TRUE(IsItemPresentInMenu(menu.get(), LauncherContextMenu::MENU_CLOSE)); |
| 221 EXPECT_TRUE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_CLOSE)); | 205 EXPECT_TRUE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_CLOSE)); |
| 222 | |
| 223 // Arc non-launchable app is running. | |
| 224 const std::string app_id2 = ArcAppTest::GetAppId(arc_test().fake_apps()[1]); | |
| 225 std::string window_app_id2("org.chromium.arc.2"); | |
| 226 CreateArcWindow(window_app_id2); | |
| 227 arc_test().app_instance()->SendTaskCreated(2, arc_test().fake_apps()[1]); | |
| 228 item.id = controller()->GetShelfIDForAppID(app_id2); | |
| 229 ASSERT_TRUE(item.id); | |
| 230 menu.reset(new ArcLauncherContextMenu(controller(), &item, wm_shelf)); | |
| 231 | |
| 232 EXPECT_FALSE( | |
| 233 IsItemPresentInMenu(menu.get(), LauncherContextMenu::MENU_OPEN_NEW)); | |
| 234 EXPECT_FALSE(IsItemPresentInMenu(menu.get(), LauncherContextMenu::MENU_PIN)); | |
| 235 EXPECT_TRUE(IsItemPresentInMenu(menu.get(), LauncherContextMenu::MENU_CLOSE)); | |
| 236 EXPECT_TRUE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_CLOSE)); | |
| 237 } | 206 } |
| OLD | NEW |