Chromium Code Reviews| Index: chrome/browser/ui/ash/app_list/app_list_presenter_delegate_mus_unittest.cc |
| diff --git a/chrome/browser/ui/ash/app_list/app_list_presenter_delegate_mus_unittest.cc b/chrome/browser/ui/ash/app_list/app_list_presenter_delegate_mus_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c537ffc8bba62cd0b3b0b50dfb621baf0d56733e |
| --- /dev/null |
| +++ b/chrome/browser/ui/ash/app_list/app_list_presenter_delegate_mus_unittest.cc |
| @@ -0,0 +1,242 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/ash/app_list/app_list_presenter_delegate_mus.h" |
| + |
| +#include <memory> |
| +#include <string> |
| + |
| +#include "base/command_line.h" |
| +#include "base/files/file_path.h" |
| +#include "base/memory/ptr_util.h" |
| +#include "base/message_loop/message_loop.h" |
| +#include "base/run_loop.h" |
| +#include "base/synchronization/waitable_event.h" |
| +#include "base/threading/simple_thread.h" |
| +#include "base/threading/thread.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/ui/app_list/app_list_service_impl.h" |
| +#include "chrome/browser/ui/ash/app_list/app_list_presenter_delegate_mus.h" |
| +#include "services/shell/background/background_shell.h" |
| +#include "services/shell/public/cpp/connector.h" |
| +#include "services/shell/public/cpp/service.h" |
| +#include "services/shell/public/cpp/service_context.h" |
| + |
| +#include "services/ui/public/cpp/tests/window_tree_client_private.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "ui/app_list/app_list_switches.h" |
| +#include "ui/app_list/presenter/app_list_presenter_delegate_factory.h" |
| +#include "ui/app_list/presenter/app_list_presenter_impl.h" |
| +#include "ui/app_list/presenter/app_list_view_delegate_factory.h" |
| +#include "ui/app_list/presenter/test/app_list_presenter_impl_test_api.h" |
| +#include "ui/app_list/test/app_list_test_view_delegate.h" |
| +#include "ui/app_list/views/app_list_main_view.h" |
| +#include "ui/app_list/views/app_list_view.h" |
| +#include "ui/app_list/views/contents_view.h" |
| +#include "ui/events/event.h" |
| +#include "ui/events/test/test_event_handler.h" |
| +#include "ui/views/controls/native/native_view_host.h" |
| +#include "ui/views/mus/native_widget_mus.h" |
| +#include "ui/views/mus/views_mus_test_suite.h" |
| +#include "ui/views/mus/window_manager_connection.h" |
| +#include "ui/views/pointer_watcher.h" |
| +#include "ui/views/test/focus_manager_test.h" |
| +#include "ui/views/test/platform_test_helper.h" |
| +#include "ui/views/test/scoped_views_test_helper.h" |
| +#include "ui/views/test/views_test_base.h" |
| +#include "ui/views/views_delegate.h" |
| +#include "ui/views/views_test_suite.h" |
| +#include "ui/views/widget/widget.h" |
| +#include "ui/views/widget/widget_delegate.h" |
| +#include "ui/views/widget/widget_observer.h" |
| +#include "ui/wm/core/default_activation_client.h" |
| +#include "ui/wm/core/window_util.h" |
| + |
| +#include "ui/views/views_delegate.h" |
| +#include "ui/views/test/test_views_delegate.h" |
| + |
| +namespace views { |
| + |
| +class AppListTestViewDelegateFactory |
| + : public app_list::AppListViewDelegateFactory { |
| + public: |
| + AppListTestViewDelegateFactory() { |
| + app_list_view_delegate_.reset( |
| + new app_list::test::AppListTestViewDelegate()); |
| + } |
| + ~AppListTestViewDelegateFactory() override {} |
| + |
| + // app_list::AppListViewDelegateFactory: |
| + app_list::AppListViewDelegate* GetDelegate() override { |
| + return app_list_view_delegate_.get(); |
| + } |
| + |
| + private: |
| + std::unique_ptr<app_list::AppListViewDelegate> app_list_view_delegate_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(AppListTestViewDelegateFactory); |
| +}; |
| + |
| +class AppListPresenterDelegateFactoryMus |
| + : public app_list::AppListPresenterDelegateFactory { |
| + public: |
| + AppListPresenterDelegateFactoryMus() {} |
| + |
| + ~AppListPresenterDelegateFactoryMus() override {} |
| + |
| + std::unique_ptr<app_list::AppListPresenterDelegate> GetDelegate( |
| + app_list::AppListPresenter* presenter) override { |
| + return base::MakeUnique<AppListPresenterDelegateMus>( |
| + presenter, view_delegate_factory_); |
| + } |
| + |
| + app_list::AppListViewDelegateFactory* view_delegate_factory_; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(AppListPresenterDelegateFactoryMus); |
| +}; |
| + |
| +// class AppListPresenterDelegateMusTest : public ViewsTestBase { |
| +class AppListPresenterDelegateMusTest : public testing::Test { |
| + public: |
| + AppListPresenterDelegateMusTest() { |
| + app_list_presenter_delegate_factory_mus_ = |
| + new AppListPresenterDelegateFactoryMus(); |
| + |
| + app_list_presenter_delegate_factory_mus_->view_delegate_factory_ = |
| + new AppListTestViewDelegateFactory; |
| + |
| + app_list_presenter_ = new app_list::AppListPresenterImpl( |
| + app_list_presenter_delegate_factory_mus_); |
| + } |
| + |
| + void SetUp() override { |
| + LOG(ERROR) << "\n\n\n Create SetUp AppListPresenterDelegateMusTest \n\n\n"; |
| + testing::Test::SetUp(); |
| + LOG(ERROR) << "\n\n\n End SetUp AppListPresenterDelegateMusTest \n\n\n"; |
| + } |
| + |
| + void TearDown() override { |
| + LOG(ERROR) |
| + << "\n\n\n Create TearDown AppListPresenterDelegateMusTest \n\n\n"; |
| + testing::Test::TearDown(); |
| + LOG(ERROR) |
| + << "\n\n\n End TearDown AppListPresenterDelegateMusTest SetUp \n\n\n"; |
| + } |
| + ~AppListPresenterDelegateMusTest() override {} |
| + |
| + // Creates a test widget. Takes ownership of |delegate|. |
| + // std::unique_ptr<Widget> CreateWidget(WidgetDelegate* delegate) { |
| + // std::unique_ptr<Widget> widget(new Widget()); |
| + // Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); |
| + // params.delegate = delegate; |
| + // params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| + // params.bounds = initial_bounds(); |
| + // widget->Init(params); |
| + // return widget; |
| + // } |
| + |
| + int ack_callback_count() { return ack_callback_count_; } |
| + |
| + // Returns a mouse pressed event inside the widget. Tests that place views |
| + // within the widget that respond to the event must be constructed within the |
| + // widget coordinate space such that they respond correctly. |
| + std::unique_ptr<ui::MouseEvent> CreateMouseEvent() { |
| + return base::MakeUnique<ui::MouseEvent>( |
| + ui::ET_MOUSE_PRESSED, gfx::Point(50, 50), gfx::Point(50, 50), |
| + base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| + } |
| + |
| + protected: |
| + gfx::Rect initial_bounds() { return gfx::Rect(0, 0, 100, 100); } |
| + AppListPresenterDelegateFactoryMus* app_list_presenter_delegate_factory_mus_; |
| + app_list::AppListPresenterImpl* app_list_presenter_; |
| + |
| + |
| + private: |
| + int ack_callback_count_ = 0; |
| + DISALLOW_COPY_AND_ASSIGN(AppListPresenterDelegateMusTest); |
| +}; |
| + |
| +// A view that reports any mouse press as handled. |
| +class HandleMousePressView : public View { |
| + public: |
| + HandleMousePressView() {} |
| + ~HandleMousePressView() override {} |
| + |
| + // View: |
| + bool OnMousePressed(const ui::MouseEvent& event) override { return true; } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(HandleMousePressView); |
| +}; |
| + |
| +TEST_F(AppListPresenterDelegateMusTest, HideOnFocusOut) { |
| + |
| + // PlatformTestHelper* platform_test_helper = new PlatformTestHelper(); |
| + |
| + // platform_test_helper->SetIsMus(); |
| + |
| + // PlatformTestHelper::SetIsMus(); |
| + // Let other mojo apps know that we're running in tests. Do this with a |
| + // command line flag to avoid making blocking calls to other processes for |
| + // setup for tests (e.g. to unlock the screen in the window manager). |
| + // EnsureCommandLineSwitch(ui::switches::kUseTestConfig); |
| + |
| + |
| + |
| + base::MessageLoop message_loop(base::MessageLoop::TYPE_UI); |
| + |
| + // LOG(ERROR) << "About to create ScopedViewsTestHelper which should call CreatePlatformTestHelper"; |
| + |
| + // ViewsMusTestSuite *views_mus_test_suite_ = new ViewsMusTestSuite(0,0); |
| + |
| + // TestViewsDelegate test_views_delegate_; |
| + // shell_connections_ = base::MakeUnique<ShellConnection>(); |
| + ScopedViewsTestHelper test_helper_; |
| + |
| + |
| + // LOG(ERROR) << "End create ScopedViewsTestHelper which should call CreatePlatformTestHelper"; |
| + // AppListPresenterDelegateMus *app_list_presenter_delegate_mus_ = |
| + // new AppListPresenterDelegateMus(app_list_presenter_, |
| + // app_list_presenter_delegate_factory_mus_->view_delegate_factory_); |
| + |
| + // app_list::AppListView* app_list_view_ = app_list_presenter_->GetView(); |
| + |
| + // app_list_view_ = nullptr; |
| + // app_list_presenter_delegate_mus_ = nullptr; |
| + // app_list_presenter_delegate_mus_->Init(app_list_view_, 0, 0); |
| + |
| + // app_list_presenter_delegate_mus_.Init(content, ) |
| + |
| + // std::unique_ptr<Widget> widget(CreateWidget(nullptr)); |
| + // widget->Show(); |
| + |
| + // View* content = new HandleMousePressView; |
| + // content->SetBounds(0, 0, 100, 100); |
| + // widget->GetContentsView()->AddChildView(content); |
| + |
| + // ui::test::TestEventHandler handler; |
| + // content->AddPreTargetHandler(&handler); |
| + |
| + // std::unique_ptr<ui::MouseEvent> mouse = CreateMouseEvent(); |
| + // NativeWidgetMus* native_widget = |
| + // static_cast<NativeWidgetMus*>(widget->native_widget_private()); |
| + // ui::WindowTreeClientPrivate test_api(native_widget->window()); |
| + // test_api.CallOnWindowInputEvent(native_widget->window(), |
| + // std::move(mouse)); |
| + // EXPECT_EQ(1, handler.num_mouse_events()); |
| + |
| + // widget->Show(); |
| + |
| + // Deactivate the Widget, which deactivates the NativeWidgetMus. |
| + // widget->Deactivate(); |
| + |
| + // Re-activate the Widget, which actives the NativeWidgetMus. |
| + // widget->Activate(); |
| + |
| + // ASSERTION STILL BREAKS HERE -> Test fails |
| + ASSERT_TRUE(WindowManagerConnection::Exists()); |
|
mfomitchev
2016/10/18 23:50:42
Can you put a LOG before this so that we can tell
thanhph
2016/10/19 00:02:06
I just did. Binary unit_tests ran through this lin
|
| +} |
| +} |