| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/mus/public/cpp/tests/view_manager_test_base.h" | 5 #include "components/mus/public/cpp/tests/mandoline_ui_services_test_base.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
| 11 #include "components/mus/public/cpp/view.h" | 11 #include "components/mus/public/cpp/view.h" |
| 12 #include "components/mus/public/cpp/view_tree_connection.h" | 12 #include "components/mus/public/cpp/view_tree_connection.h" |
| 13 #include "components/mus/public/cpp/view_tree_host_factory.h" | 13 #include "components/mus/public/cpp/view_tree_host_factory.h" |
| 14 #include "mojo/application/public/cpp/application_impl.h" | 14 #include "mojo/application/public/cpp/application_impl.h" |
| 15 | 15 |
| 16 namespace mojo { | 16 namespace mus { |
| 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 base::RunLoop* current_run_loop = nullptr; | 20 base::RunLoop* current_run_loop = nullptr; |
| 20 | 21 |
| 21 void TimeoutRunLoop(const base::Closure& timeout_task, bool* timeout) { | 22 void TimeoutRunLoop(const base::Closure& timeout_task, bool* timeout) { |
| 22 CHECK(current_run_loop); | 23 CHECK(current_run_loop); |
| 23 *timeout = true; | 24 *timeout = true; |
| 24 timeout_task.Run(); | 25 timeout_task.Run(); |
| 25 } | 26 } |
| 26 | 27 |
| 27 } // namespace | 28 } // namespace |
| 28 | 29 |
| 29 ViewManagerTestBase::ViewManagerTestBase() | 30 MandolineUIServicesTestBase::MandolineUIServicesTestBase() |
| 30 : most_recent_connection_(nullptr), | 31 : most_recent_connection_(nullptr), |
| 31 window_manager_(nullptr), | 32 window_manager_(nullptr), |
| 32 view_tree_connection_destroyed_(false) {} | 33 view_tree_connection_destroyed_(false) {} |
| 33 | 34 |
| 34 ViewManagerTestBase::~ViewManagerTestBase() {} | 35 MandolineUIServicesTestBase::~MandolineUIServicesTestBase() {} |
| 35 | 36 |
| 36 // static | 37 // static |
| 37 bool ViewManagerTestBase::DoRunLoopWithTimeout() { | 38 bool MandolineUIServicesTestBase::DoRunLoopWithTimeout() { |
| 38 if (current_run_loop != nullptr) | 39 if (current_run_loop != nullptr) |
| 39 return false; | 40 return false; |
| 40 | 41 |
| 41 bool timeout = false; | 42 bool timeout = false; |
| 42 base::RunLoop run_loop; | 43 base::RunLoop run_loop; |
| 43 base::MessageLoop::current()->PostDelayedTask( | 44 base::MessageLoop::current()->PostDelayedTask( |
| 44 FROM_HERE, base::Bind(&TimeoutRunLoop, run_loop.QuitClosure(), &timeout), | 45 FROM_HERE, base::Bind(&TimeoutRunLoop, run_loop.QuitClosure(), &timeout), |
| 45 TestTimeouts::action_timeout()); | 46 TestTimeouts::action_timeout()); |
| 46 | 47 |
| 47 current_run_loop = &run_loop; | 48 current_run_loop = &run_loop; |
| 48 current_run_loop->Run(); | 49 current_run_loop->Run(); |
| 49 current_run_loop = nullptr; | 50 current_run_loop = nullptr; |
| 50 return !timeout; | 51 return !timeout; |
| 51 } | 52 } |
| 52 | 53 |
| 53 // static | 54 // static |
| 54 bool ViewManagerTestBase::QuitRunLoop() { | 55 bool MandolineUIServicesTestBase::QuitRunLoop() { |
| 55 if (!current_run_loop) | 56 if (!current_run_loop) |
| 56 return false; | 57 return false; |
| 57 | 58 |
| 58 current_run_loop->Quit(); | 59 current_run_loop->Quit(); |
| 59 current_run_loop = nullptr; | 60 current_run_loop = nullptr; |
| 60 return true; | 61 return true; |
| 61 } | 62 } |
| 62 | 63 |
| 63 void ViewManagerTestBase::SetUp() { | 64 void MandolineUIServicesTestBase::SetUp() { |
| 64 ApplicationTestBase::SetUp(); | 65 ApplicationTestBase::SetUp(); |
| 65 | 66 |
| 66 CreateSingleViewTreeHost(application_impl(), this, &host_); | 67 CreateSingleViewTreeHost(application_impl(), this, &host_); |
| 67 | 68 |
| 68 ASSERT_TRUE(DoRunLoopWithTimeout()); // RunLoop should be quit by OnEmbed(). | 69 ASSERT_TRUE(DoRunLoopWithTimeout()); // RunLoop should be quit by OnEmbed(). |
| 69 std::swap(window_manager_, most_recent_connection_); | 70 std::swap(window_manager_, most_recent_connection_); |
| 70 } | 71 } |
| 71 | 72 |
| 72 void ViewManagerTestBase::TearDown() { | 73 void MandolineUIServicesTestBase::TearDown() { |
| 73 ApplicationTestBase::TearDown(); | 74 ApplicationTestBase::TearDown(); |
| 74 } | 75 } |
| 75 | 76 |
| 76 ApplicationDelegate* ViewManagerTestBase::GetApplicationDelegate() { | 77 mojo::ApplicationDelegate* |
| 78 MandolineUIServicesTestBase::GetApplicationDelegate() { |
| 77 return this; | 79 return this; |
| 78 } | 80 } |
| 79 | 81 |
| 80 bool ViewManagerTestBase::ConfigureIncomingConnection( | 82 bool MandolineUIServicesTestBase::ConfigureIncomingConnection( |
| 81 ApplicationConnection* connection) { | 83 mojo::ApplicationConnection* connection) { |
| 82 connection->AddService<ViewTreeClient>(this); | 84 connection->AddService<mojo::ViewTreeClient>(this); |
| 83 return true; | 85 return true; |
| 84 } | 86 } |
| 85 | 87 |
| 86 void ViewManagerTestBase::OnEmbed(View* root) { | 88 void MandolineUIServicesTestBase::OnEmbed(View* root) { |
| 87 most_recent_connection_ = root->connection(); | 89 most_recent_connection_ = root->connection(); |
| 88 EXPECT_TRUE(QuitRunLoop()); | 90 EXPECT_TRUE(QuitRunLoop()); |
| 89 } | 91 } |
| 90 | 92 |
| 91 void ViewManagerTestBase::OnConnectionLost(ViewTreeConnection* connection) { | 93 void MandolineUIServicesTestBase::OnConnectionLost( |
| 94 ViewTreeConnection* connection) { |
| 92 view_tree_connection_destroyed_ = true; | 95 view_tree_connection_destroyed_ = true; |
| 93 } | 96 } |
| 94 | 97 |
| 95 void ViewManagerTestBase::Create(ApplicationConnection* connection, | 98 void MandolineUIServicesTestBase::Create( |
| 96 InterfaceRequest<ViewTreeClient> request) { | 99 mojo::ApplicationConnection* connection, |
| 100 mojo::InterfaceRequest<mojo::ViewTreeClient> request) { |
| 97 ViewTreeConnection::Create(this, request.Pass()); | 101 ViewTreeConnection::Create(this, request.Pass()); |
| 98 } | 102 } |
| 99 | 103 |
| 100 } // namespace mojo | 104 } // namespace mus |
| OLD | NEW |