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