Commit 7df0afaf authored by khmel's avatar khmel Committed by Commit Bot

arc: Restore deferred controller item menu.

This fixes regression when ARC deferred launch controller does not have
a menu and user cannot closes launch request and pin/unpin item.

Test: Manually on device. Unit test added
Bug: 775744
Change-Id: I85d902a77a251d2958f9cd2a42dd7c10a393d6c0
Reviewed-on: https://chromium-review.googlesource.com/724460
Commit-Queue: Yury Khmel <khmel@google.com>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#509686}
parent 4c8f4342
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "chrome/browser/ui/ash/launcher/arc_app_deferred_launcher_controller.h" #include "chrome/browser/ui/ash/launcher/arc_app_deferred_launcher_controller.h"
#include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h" #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
#include "chrome/browser/ui/ash/launcher/launcher_context_menu.h"
ArcAppDeferredLauncherItemController::ArcAppDeferredLauncherItemController( ArcAppDeferredLauncherItemController::ArcAppDeferredLauncherItemController(
const std::string& arc_app_id, const std::string& arc_app_id,
...@@ -47,10 +48,19 @@ void ArcAppDeferredLauncherItemController::ExecuteCommand( ...@@ -47,10 +48,19 @@ void ArcAppDeferredLauncherItemController::ExecuteCommand(
int64_t command_id, int64_t command_id,
int32_t event_flags, int32_t event_flags,
int64_t display_id) { int64_t display_id) {
// This delegate does not show custom context or application menu items. if (from_context_menu && ExecuteContextMenuCommand(command_id, event_flags))
return;
NOTIMPLEMENTED(); NOTIMPLEMENTED();
} }
std::unique_ptr<ui::MenuModel>
ArcAppDeferredLauncherItemController::GetContextMenu(int64_t display_id) {
ChromeLauncherController* controller = ChromeLauncherController::instance();
const ash::ShelfItem* item = controller->GetItem(shelf_id());
return LauncherContextMenu::Create(controller, item, display_id);
}
void ArcAppDeferredLauncherItemController::Close() { void ArcAppDeferredLauncherItemController::Close() {
if (host_) if (host_)
host_->Close(app_id()); host_->Close(app_id());
......
...@@ -43,6 +43,7 @@ class ArcAppDeferredLauncherItemController : public ash::ShelfItemDelegate { ...@@ -43,6 +43,7 @@ class ArcAppDeferredLauncherItemController : public ash::ShelfItemDelegate {
int64_t command_id, int64_t command_id,
int32_t event_flags, int32_t event_flags,
int64_t display_id) override; int64_t display_id) override;
std::unique_ptr<ui::MenuModel> GetContextMenu(int64_t display_id) override;
void Close() override; void Close() override;
private: private:
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "chrome/browser/prefs/incognito_mode_prefs.h" #include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_list/arc/arc_app_test.h" #include "chrome/browser/ui/app_list/arc/arc_app_test.h"
#include "chrome/browser/ui/app_list/arc/arc_app_utils.h"
#include "chrome/browser/ui/ash/fake_tablet_mode_controller.h" #include "chrome/browser/ui/ash/fake_tablet_mode_controller.h"
#include "chrome/browser/ui/ash/launcher/arc_app_shelf_id.h" #include "chrome/browser/ui/ash/launcher/arc_app_shelf_id.h"
#include "chrome/browser/ui/ash/launcher/arc_launcher_context_menu.h" #include "chrome/browser/ui/ash/launcher/arc_launcher_context_menu.h"
...@@ -32,11 +33,15 @@ ...@@ -32,11 +33,15 @@
namespace { namespace {
bool IsItemPresentInMenu(ui::MenuModel* menu, int command_id) {
ui::MenuModel* model = menu;
int index = 0;
return ui::MenuModel::GetModelAndIndexForCommandId(command_id, &model,
&index);
}
class LauncherContextMenuTest : public ash::AshTestBase { class LauncherContextMenuTest : public ash::AshTestBase {
protected: protected:
static bool IsItemPresentInMenu(LauncherContextMenu* menu, int command_id) {
return menu->GetIndexOfCommandId(command_id) != -1;
}
LauncherContextMenuTest() {} LauncherContextMenuTest() {}
...@@ -85,6 +90,8 @@ class LauncherContextMenuTest : public ash::AshTestBase { ...@@ -85,6 +90,8 @@ class LauncherContextMenuTest : public ash::AshTestBase {
ChromeLauncherController* controller() { return launcher_controller_.get(); } ChromeLauncherController* controller() { return launcher_controller_.get(); }
ash::ShelfModel* model() { return model_.get(); }
private: private:
TestingProfile profile_; TestingProfile profile_;
ArcAppTest arc_test_; ArcAppTest arc_test_;
...@@ -237,4 +244,51 @@ TEST_F(LauncherContextMenuTest, ArcLauncherContextMenuItemCheck) { ...@@ -237,4 +244,51 @@ TEST_F(LauncherContextMenuTest, ArcLauncherContextMenuItemCheck) {
EXPECT_TRUE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_CLOSE)); EXPECT_TRUE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_CLOSE));
} }
TEST_F(LauncherContextMenuTest, ArcDeferredLauncherContextMenuItemCheck) {
arc_test().app_instance()->RefreshAppList();
arc_test().app_instance()->SendRefreshAppList(
std::vector<arc::mojom::AppInfo>(arc_test().fake_apps().begin(),
arc_test().fake_apps().begin() + 2));
const std::string app_id1 = ArcAppTest::GetAppId(arc_test().fake_apps()[0]);
const std::string app_id2 = ArcAppTest::GetAppId(arc_test().fake_apps()[1]);
controller()->PinAppWithID(app_id1);
arc_test().StopArcInstance();
const ash::ShelfID shelf_id1(app_id1);
const ash::ShelfID shelf_id2(app_id2);
EXPECT_TRUE(controller()->GetItem(shelf_id1));
EXPECT_FALSE(controller()->GetItem(shelf_id2));
arc::LaunchApp(profile(), app_id1, ui::EF_LEFT_MOUSE_BUTTON);
arc::LaunchApp(profile(), app_id2, ui::EF_LEFT_MOUSE_BUTTON);
EXPECT_TRUE(controller()->GetItem(shelf_id1));
EXPECT_TRUE(controller()->GetItem(shelf_id2));
ash::ShelfItemDelegate* item_delegate =
model()->GetShelfItemDelegate(shelf_id1);
ASSERT_TRUE(item_delegate);
std::unique_ptr<ui::MenuModel> menu =
item_delegate->GetContextMenu(0 /* display_id */);
ASSERT_TRUE(menu);
EXPECT_FALSE(
IsItemPresentInMenu(menu.get(), LauncherContextMenu::MENU_OPEN_NEW));
EXPECT_TRUE(IsItemPresentInMenu(menu.get(), LauncherContextMenu::MENU_PIN));
EXPECT_TRUE(IsItemPresentInMenu(menu.get(), LauncherContextMenu::MENU_CLOSE));
item_delegate = model()->GetShelfItemDelegate(shelf_id2);
ASSERT_TRUE(item_delegate);
menu = item_delegate->GetContextMenu(0 /* display_id */);
ASSERT_TRUE(menu);
EXPECT_FALSE(
IsItemPresentInMenu(menu.get(), LauncherContextMenu::MENU_OPEN_NEW));
EXPECT_TRUE(IsItemPresentInMenu(menu.get(), LauncherContextMenu::MENU_PIN));
EXPECT_TRUE(IsItemPresentInMenu(menu.get(), LauncherContextMenu::MENU_CLOSE));
}
} // namespace } // namespace
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment