diff options
author | fsamuel <fsamuel@chromium.org> | 2015-10-15 17:12:45 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-10-16 00:13:20 +0000 |
commit | 68afcf453d29c8f311b34a0aa210e042d4adc132 (patch) | |
tree | 5d7e25e02abe745aec485ecb4450f37d24b080c8 /components/mus/public/cpp/tests/window_server_test_base.cc | |
parent | da33ab883a2046613836487d852d5fd36f1dc4c3 (diff) | |
download | chromium_src-68afcf453d29c8f311b34a0aa210e042d4adc132.zip chromium_src-68afcf453d29c8f311b34a0aa210e042d4adc132.tar.gz chromium_src-68afcf453d29c8f311b34a0aa210e042d4adc132.tar.bz2 |
View => Window in components/mus/public/cpp
This CL updates the client lib to refer to mus::Windows and
mus::WindowServer instead of View and View Manager.
I hope I caught everything. I'll clean things up in
subsequent CLs, and start renaming the interfaces and
implementation.
BUG=542848
Review URL: https://codereview.chromium.org/1402223003
Cr-Commit-Position: refs/heads/master@{#354411}
Diffstat (limited to 'components/mus/public/cpp/tests/window_server_test_base.cc')
-rw-r--r-- | components/mus/public/cpp/tests/window_server_test_base.cc | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/components/mus/public/cpp/tests/window_server_test_base.cc b/components/mus/public/cpp/tests/window_server_test_base.cc new file mode 100644 index 0000000..649fc24 --- /dev/null +++ b/components/mus/public/cpp/tests/window_server_test_base.cc @@ -0,0 +1,103 @@ +// Copyright 2015 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 "components/mus/public/cpp/tests/window_server_test_base.h" + +#include "base/bind.h" +#include "base/message_loop/message_loop.h" +#include "base/run_loop.h" +#include "base/test/test_timeouts.h" +#include "components/mus/public/cpp/window.h" +#include "components/mus/public/cpp/window_tree_connection.h" +#include "components/mus/public/cpp/window_tree_host_factory.h" +#include "mojo/application/public/cpp/application_impl.h" + +namespace mus { +namespace { + +base::RunLoop* current_run_loop = nullptr; + +void TimeoutRunLoop(const base::Closure& timeout_task, bool* timeout) { + CHECK(current_run_loop); + *timeout = true; + timeout_task.Run(); +} + +} // namespace + +WindowServerTestBase::WindowServerTestBase() + : most_recent_connection_(nullptr), + window_manager_(nullptr), + window_tree_connection_destroyed_(false) {} + +WindowServerTestBase::~WindowServerTestBase() {} + +// static +bool WindowServerTestBase::DoRunLoopWithTimeout() { + if (current_run_loop != nullptr) + return false; + + bool timeout = false; + base::RunLoop run_loop; + base::MessageLoop::current()->PostDelayedTask( + FROM_HERE, base::Bind(&TimeoutRunLoop, run_loop.QuitClosure(), &timeout), + TestTimeouts::action_timeout()); + + current_run_loop = &run_loop; + current_run_loop->Run(); + current_run_loop = nullptr; + return !timeout; +} + +// static +bool WindowServerTestBase::QuitRunLoop() { + if (!current_run_loop) + return false; + + current_run_loop->Quit(); + current_run_loop = nullptr; + return true; +} + +void WindowServerTestBase::SetUp() { + ApplicationTestBase::SetUp(); + + CreateSingleWindowTreeHost(application_impl(), this, &host_); + + ASSERT_TRUE(DoRunLoopWithTimeout()); // RunLoop should be quit by OnEmbed(). + std::swap(window_manager_, most_recent_connection_); +} + +void WindowServerTestBase::TearDown() { + ApplicationTestBase::TearDown(); +} + +mojo::ApplicationDelegate* WindowServerTestBase::GetApplicationDelegate() { + return this; +} + +bool WindowServerTestBase::ConfigureIncomingConnection( + mojo::ApplicationConnection* connection) { + connection->AddService<mojo::ViewTreeClient>(this); + return true; +} + +void WindowServerTestBase::OnEmbed(Window* root) { + most_recent_connection_ = root->connection(); + EXPECT_TRUE(QuitRunLoop()); +} + +void WindowServerTestBase::OnConnectionLost(WindowTreeConnection* connection) { + window_tree_connection_destroyed_ = true; +} + +void WindowServerTestBase::Create( + mojo::ApplicationConnection* connection, + mojo::InterfaceRequest<mojo::ViewTreeClient> request) { + WindowTreeConnection::Create( + this, request.Pass(), + WindowTreeConnection::CreateType::DONT_WAIT_FOR_EMBED); +} + +} // namespace mus |