Commit c82aeb35 authored by Jiaquan He's avatar Jiaquan He Committed by Commit Bot

app_list:: reenables ClickingContextMenuDoesNotDismiss.

This commit reenables ClickingContextMenuDoesNotDismiss but moves it
into Ash.

Bug: 733662
Change-Id: If176458fd07d949c8d21082b40ed06f4f571b3d5
Reviewed-on: https://chromium-review.googlesource.com/1100675
Commit-Queue: Jiaquan He <hejq@google.com>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568200}
parent 29c98e7e
......@@ -6,14 +6,19 @@
#include <memory>
#include <utility>
#include <vector>
#include "ash/app_list/test/app_list_test_view_delegate.h"
#include "ash/app_list/views/app_list_item_view.h"
#include "ash/app_list/views/app_list_view.h"
#include "ash/app_list/views/apps_grid_view.h"
#include "base/memory/ptr_util.h"
#include "base/run_loop.h"
#include "ui/aura/client/focus_client.h"
#include "ui/aura/test/aura_test_base.h"
#include "ui/aura/test/test_screen.h"
#include "ui/aura/window.h"
#include "ui/events/test/event_generator.h"
#include "ui/views/test/test_views_delegate.h"
#include "ui/wm/core/default_activation_client.h"
#include "ui/wm/core/window_util.h"
......@@ -33,6 +38,10 @@ class AppListPresenterDelegateTest : public AppListPresenterDelegate {
bool on_shown_called() const { return on_shown_called_; }
bool on_dismissed_called() const { return on_dismissed_called_; }
AppListViewDelegate* GetAppListViewDelegate() override {
return &app_list_view_delegate_;
}
private:
// AppListPresenterDelegate:
void SetPresenter(AppListPresenterImpl* presenter) override {
......@@ -58,9 +67,6 @@ class AppListPresenterDelegateTest : public AppListPresenterDelegate {
return base::TimeDelta::FromMilliseconds(0);
}
bool IsHomeLauncherEnabledInTabletMode() override { return false; }
AppListViewDelegate* GetAppListViewDelegate() override {
return &app_list_view_delegate_;
}
bool GetOnScreenKeyboardShown() override { return false; }
aura::Window* GetRootWindowForDisplayId(int64_t display_id) override {
return nullptr;
......@@ -179,4 +185,48 @@ TEST_F(AppListPresenterImplTest, WidgetDestroyed) {
EXPECT_TRUE(delegate());
}
// Test that clicking on app list context menus doesn't close the app list.
TEST_F(AppListPresenterImplTest, ClickingContextMenuDoesNotDismiss) {
// Populate some apps since we will show the context menu over a view.
test::AppListTestViewDelegate* view_delegate =
static_cast<test::AppListTestViewDelegate*>(
delegate()->GetAppListViewDelegate());
view_delegate->GetTestModel()->PopulateApps(2);
// Show the app list on the primary display.
presenter()->Show(display::Screen::GetScreen()->GetPrimaryDisplay().id(),
base::TimeTicks());
aura::Window* window = presenter()->GetWindow();
ASSERT_TRUE(window);
// Show a context menu for the first app list item view.
app_list::AppListView::TestApi test_api(presenter()->GetView());
app_list::AppsGridView* grid_view = test_api.GetRootAppsGridView();
app_list::AppListItemView* item_view = grid_view->GetItemViewAt(0);
DCHECK(item_view);
item_view->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE);
// Find the context menu as a transient child of the app list.
aura::Window* transient_parent = window;
const std::vector<aura::Window*>& transient_children =
wm::GetTransientChildren(transient_parent);
ASSERT_EQ(1u, transient_children.size());
aura::Window* menu = transient_children[0];
// Press the left mouse button on the menu window, it should not close the
// app list nor the context menu on this pointer event.
ui::test::EventGenerator menu_event_generator(menu);
menu_event_generator.set_current_location(menu->GetBoundsInScreen().origin());
menu_event_generator.PressLeftButton();
// Check that the window and the app list are still open.
ASSERT_EQ(window, presenter()->GetWindow());
EXPECT_EQ(1u, wm::GetTransientChildren(transient_parent).size());
// Close app list so that views are destructed and unregistered from the
// model's observer list.
presenter()->Dismiss(base::TimeTicks());
base::RunLoop().RunUntilIdle();
}
} // namespace app_list
......@@ -229,6 +229,17 @@ class HideViewAnimationObserver : public ui::ImplicitAnimationObserver {
DISALLOW_COPY_AND_ASSIGN(HideViewAnimationObserver);
};
////////////////////////////////////////////////////////////////////////////////
// AppListView::TestApi
AppListView::TestApi::TestApi(AppListView* view) : view_(view) {}
AppListView::TestApi::~TestApi() = default;
AppsGridView* AppListView::TestApi::GetRootAppsGridView() {
return view_->GetRootAppsGridView();
}
////////////////////////////////////////////////////////////////////////////////
// AppListView:
......
......@@ -43,15 +43,23 @@ class PaginationModel;
class SearchBoxView;
class SearchModel;
namespace test {
class AppListViewTestApi;
}
// AppListView is the top-level view and controller of app list UI. It creates
// and hosts a AppsGridView and passes AppListModel to it for display.
class APP_LIST_EXPORT AppListView : public views::WidgetDelegateView,
public display::DisplayObserver {
public:
class TestApi {
public:
explicit TestApi(AppListView* view);
~TestApi();
AppsGridView* GetRootAppsGridView();
private:
AppListView* const view_;
DISALLOW_COPY_AND_ASSIGN(TestApi);
};
// Number of the size of shelf. Used to determine the opacity of items in the
// app list during dragging.
static constexpr float kNumOfShelfSize = 2.0;
......@@ -239,7 +247,6 @@ class APP_LIST_EXPORT AppListView : public views::WidgetDelegateView,
// TODO(newcomer): Merge this class into AppListView once the old app list
// view code is removed.
class FullscreenWidgetObserver;
friend class test::AppListViewTestApi;
void InitContents(int initial_apps_page);
......
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