| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ui/views/mus/views_mus_test_suite.h" | 5 #include "ui/views/mus/views_mus_test_suite.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
| 15 #include "base/threading/simple_thread.h" | 15 #include "base/threading/simple_thread.h" |
| 16 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
| 17 #include "mojo/edk/embedder/embedder.h" | 17 #include "mojo/edk/embedder/embedder.h" |
| 18 #include "mojo/edk/embedder/scoped_ipc_support.h" | 18 #include "mojo/edk/embedder/scoped_ipc_support.h" |
| 19 #include "services/catalog/catalog.h" | 19 #include "services/catalog/catalog.h" |
| 20 #include "services/service_manager/background/background_service_manager.h" | 20 #include "services/service_manager/background/background_service_manager.h" |
| 21 #include "services/service_manager/public/cpp/connector.h" | 21 #include "services/service_manager/public/cpp/connector.h" |
| 22 #include "services/service_manager/public/cpp/service.h" | 22 #include "services/service_manager/public/cpp/service.h" |
| 23 #include "services/service_manager/public/cpp/service_context.h" | 23 #include "services/service_manager/public/cpp/service_context.h" |
| 24 #include "services/ui/common/switches.h" | 24 #include "services/ui/common/switches.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 26 #include "ui/aura/mus/window_tree_host_mus.h" | 26 #include "ui/aura/mus/window_tree_host_mus.h" |
| 27 #include "ui/aura/test/env_test_helper.h" | 27 #include "ui/aura/test/env_test_helper.h" |
| 28 #include "ui/aura/test/mus/input_method_mus_test_api.h" |
| 28 #include "ui/aura/window.h" | 29 #include "ui/aura/window.h" |
| 29 #include "ui/gl/gl_switches.h" | 30 #include "ui/gl/gl_switches.h" |
| 30 #include "ui/views/mus/desktop_window_tree_host_mus.h" | 31 #include "ui/views/mus/desktop_window_tree_host_mus.h" |
| 31 #include "ui/views/mus/mus_client.h" | 32 #include "ui/views/mus/mus_client.h" |
| 32 #include "ui/views/mus/test_utils.h" | 33 #include "ui/views/mus/test_utils.h" |
| 33 #include "ui/views/test/platform_test_helper.h" | 34 #include "ui/views/test/platform_test_helper.h" |
| 34 #include "ui/views/test/views_test_helper_aura.h" | 35 #include "ui/views/test/views_test_helper_aura.h" |
| 35 #include "ui/views/views_delegate.h" | 36 #include "ui/views/views_delegate.h" |
| 36 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 37 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
| 37 | 38 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 63 }; | 64 }; |
| 64 | 65 |
| 65 class PlatformTestHelperMus : public PlatformTestHelper { | 66 class PlatformTestHelperMus : public PlatformTestHelper { |
| 66 public: | 67 public: |
| 67 PlatformTestHelperMus(service_manager::Connector* connector, | 68 PlatformTestHelperMus(service_manager::Connector* connector, |
| 68 const service_manager::Identity& identity) { | 69 const service_manager::Identity& identity) { |
| 69 aura::test::EnvTestHelper().SetWindowTreeClient(nullptr); | 70 aura::test::EnvTestHelper().SetWindowTreeClient(nullptr); |
| 70 // It is necessary to recreate the MusClient for each test, | 71 // It is necessary to recreate the MusClient for each test, |
| 71 // since a new MessageLoop is created for each test. | 72 // since a new MessageLoop is created for each test. |
| 72 mus_client_ = test::MusClientTestApi::Create(connector, identity); | 73 mus_client_ = test::MusClientTestApi::Create(connector, identity); |
| 74 ViewsDelegate::GetInstance()->set_native_widget_factory(base::Bind( |
| 75 &PlatformTestHelperMus::CreateNativeWidget, base::Unretained(this))); |
| 73 } | 76 } |
| 74 ~PlatformTestHelperMus() override { | 77 ~PlatformTestHelperMus() override { |
| 75 aura::test::EnvTestHelper().SetWindowTreeClient(nullptr); | 78 aura::test::EnvTestHelper().SetWindowTreeClient(nullptr); |
| 76 } | 79 } |
| 77 | 80 |
| 78 // PlatformTestHelper: | 81 // PlatformTestHelper: |
| 79 void OnTestHelperCreated(ViewsTestHelper* helper) override { | 82 void OnTestHelperCreated(ViewsTestHelper* helper) override { |
| 80 static_cast<ViewsTestHelperAura*>(helper)->EnableMusWithWindowTreeClient( | 83 static_cast<ViewsTestHelperAura*>(helper)->EnableMusWithWindowTreeClient( |
| 81 mus_client_->window_tree_client()); | 84 mus_client_->window_tree_client()); |
| 82 } | 85 } |
| 83 void SimulateNativeDestroy(Widget* widget) override { | 86 void SimulateNativeDestroy(Widget* widget) override { |
| 84 aura::WindowTreeHostMus* window_tree_host = | 87 aura::WindowTreeHostMus* window_tree_host = |
| 85 static_cast<aura::WindowTreeHostMus*>( | 88 static_cast<aura::WindowTreeHostMus*>( |
| 86 widget->GetNativeView()->GetHost()); | 89 widget->GetNativeView()->GetHost()); |
| 87 static_cast<aura::WindowTreeClientDelegate*>(mus_client_.get()) | 90 static_cast<aura::WindowTreeClientDelegate*>(mus_client_.get()) |
| 88 ->OnEmbedRootDestroyed(window_tree_host); | 91 ->OnEmbedRootDestroyed(window_tree_host); |
| 89 } | 92 } |
| 90 | 93 |
| 91 private: | 94 private: |
| 95 NativeWidget* CreateNativeWidget(const Widget::InitParams& init_params, |
| 96 internal::NativeWidgetDelegate* delegate) { |
| 97 NativeWidget* native_widget = |
| 98 mus_client_->CreateNativeWidget(init_params, delegate); |
| 99 if (!native_widget) |
| 100 return nullptr; |
| 101 |
| 102 // Disable sending KeyEvents to IME as tests aren't set up to wait for an |
| 103 // ack (and tests run concurrently). |
| 104 aura::WindowTreeHostMus* window_tree_host_mus = |
| 105 static_cast<aura::WindowTreeHostMus*>( |
| 106 static_cast<DesktopNativeWidgetAura*>(native_widget)->host()); |
| 107 aura::InputMethodMusTestApi::Disable(window_tree_host_mus->input_method()); |
| 108 return native_widget; |
| 109 } |
| 110 |
| 92 std::unique_ptr<MusClient> mus_client_; | 111 std::unique_ptr<MusClient> mus_client_; |
| 93 | 112 |
| 94 DISALLOW_COPY_AND_ASSIGN(PlatformTestHelperMus); | 113 DISALLOW_COPY_AND_ASSIGN(PlatformTestHelperMus); |
| 95 }; | 114 }; |
| 96 | 115 |
| 97 std::unique_ptr<PlatformTestHelper> CreatePlatformTestHelper( | 116 std::unique_ptr<PlatformTestHelper> CreatePlatformTestHelper( |
| 98 const service_manager::Identity& identity, | 117 const service_manager::Identity& identity, |
| 99 const base::Callback<service_manager::Connector*(void)>& callback) { | 118 const base::Callback<service_manager::Connector*(void)>& callback) { |
| 100 return base::MakeUnique<PlatformTestHelperMus>(callback.Run(), identity); | 119 return base::MakeUnique<PlatformTestHelperMus>(callback.Run(), identity); |
| 101 } | 120 } |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 ViewsTestSuite::Initialize(); | 247 ViewsTestSuite::Initialize(); |
| 229 service_manager_connections_ = base::MakeUnique<ServiceManagerConnection>(); | 248 service_manager_connections_ = base::MakeUnique<ServiceManagerConnection>(); |
| 230 } | 249 } |
| 231 | 250 |
| 232 void ViewsMusTestSuite::Shutdown() { | 251 void ViewsMusTestSuite::Shutdown() { |
| 233 service_manager_connections_.reset(); | 252 service_manager_connections_.reset(); |
| 234 ViewsTestSuite::Shutdown(); | 253 ViewsTestSuite::Shutdown(); |
| 235 } | 254 } |
| 236 | 255 |
| 237 } // namespace views | 256 } // namespace views |
| OLD | NEW |