Index: ui/wm/test/wm_test_helper.cc |
diff --git a/ui/wm/test/wm_test_helper.cc b/ui/wm/test/wm_test_helper.cc |
index 83166be9aad299bf55f6cd06a027acfae24242e0..68b57c09faa77bac2b971fe3c04fc33f24255cab 100644 |
--- a/ui/wm/test/wm_test_helper.cc |
+++ b/ui/wm/test/wm_test_helper.cc |
@@ -4,24 +4,81 @@ |
#include "ui/wm/test/wm_test_helper.h" |
+#include "base/run_loop.h" |
#include "ui/aura/client/default_capture_client.h" |
#include "ui/aura/env.h" |
-#include "ui/aura/test/test_focus_client.h" |
#include "ui/aura/window.h" |
#include "ui/wm/core/compound_event_filter.h" |
#include "ui/wm/core/default_activation_client.h" |
+#include "ui/wm/core/default_screen_position_client.h" |
+#include "ui/wm/public/dispatcher_client.h" |
+ |
+#if defined(OS_ANDROID) && defined(USE_AURA) |
+#include "ui/wm/android/android_focus_rules.h" |
+#include "ui/wm/core/base_focus_rules.h" |
+#include "ui/wm/core/focus_controller.h" |
+#else |
+#include "ui/aura/test/test_focus_client.h" |
+#endif |
namespace wm { |
+namespace { |
+class TestDispatcherClient : public aura::client::DispatcherClient { |
+ public: |
+ TestDispatcherClient() : dispatcher_(nullptr) {} |
+ ~TestDispatcherClient() override {} |
+ |
+ base::MessagePumpDispatcher* dispatcher() { |
+ return dispatcher_; |
+ } |
+ |
+ // aura::client::DispatcherClient: |
+ void PrepareNestedLoopClosures(base::MessagePumpDispatcher* dispatcher, |
+ base::Closure* run_closure, |
+ base::Closure* quit_closure) override { |
+ scoped_ptr<base::RunLoop> run_loop(new base::RunLoop()); |
+ *quit_closure = run_loop->QuitClosure(); |
+ *run_closure = base::Bind(&TestDispatcherClient::RunNestedDispatcher, |
+ base::Unretained(this), |
+ base::Passed(&run_loop), |
+ dispatcher); |
+ } |
+ |
+ private: |
+ void RunNestedDispatcher(scoped_ptr<base::RunLoop> run_loop, |
+ base::MessagePumpDispatcher* dispatcher) { |
+ base::AutoReset<base::MessagePumpDispatcher*> reset_dispatcher(&dispatcher_, |
+ dispatcher); |
+ base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); |
+ base::MessageLoop::ScopedNestableTaskAllower allow(loop); |
+ run_loop->Run(); |
+ } |
+ |
+ base::MessagePumpDispatcher* dispatcher_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(TestDispatcherClient); |
+}; |
+} // namespace |
+ |
WMTestHelper::WMTestHelper(const gfx::Size& default_window_size, |
ui::ContextFactory* context_factory) { |
aura::Env::CreateInstance(true); |
aura::Env::GetInstance()->set_context_factory(context_factory); |
+ LOG(ERROR) << "WMTestHelper ctor: context_factory=" |
+ << context_factory; |
+ |
host_.reset(aura::WindowTreeHost::Create(gfx::Rect(default_window_size))); |
host_->InitHost(); |
+ host_->Show(); |
aura::client::SetWindowTreeClient(host_->window(), this); |
+#if defined(OS_ANDROID) && defined(USE_AURA) |
+ AndroidFocusRules* focus_rules = new AndroidFocusRules(); |
+ focus_client_.reset(new FocusController(focus_rules)); |
+#else |
focus_client_.reset(new aura::test::TestFocusClient); |
+#endif |
aura::client::SetFocusClient(host_->window(), focus_client_.get()); |
root_window_event_filter_.reset(new wm::CompoundEventFilter); |
@@ -31,6 +88,13 @@ WMTestHelper::WMTestHelper(const gfx::Size& default_window_size, |
capture_client_.reset( |
new aura::client::DefaultCaptureClient(host_->window())); |
+ screen_position_client_.reset(new DefaultScreenPositionClient); |
+ aura::client::SetScreenPositionClient(host_->window(), |
+ screen_position_client_.get()); |
+ dispatcher_client_.reset(new TestDispatcherClient); |
+ aura::client::SetDispatcherClient(host_->window(), |
+ dispatcher_client_.get()); |
+ |
} |
WMTestHelper::~WMTestHelper() { |