Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Side by Side Diff: components/mus/public/cpp/tests/view_manager_test_base.cc

Issue 1340983002: Mandoline UI Process: Update namespaces and file names (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated all the namespaces in mus Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/mus/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/mus/public/cpp/view.h"
12 #include "components/mus/public/cpp/view_tree_connection.h"
13 #include "components/mus/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 ViewManagerTestBase::~ViewManagerTestBase() {}
35
36 // static
37 bool ViewManagerTestBase::DoRunLoopWithTimeout() {
38 if (current_run_loop != nullptr)
39 return false;
40
41 bool timeout = false;
42 base::RunLoop run_loop;
43 base::MessageLoop::current()->PostDelayedTask(
44 FROM_HERE, base::Bind(&TimeoutRunLoop, run_loop.QuitClosure(), &timeout),
45 TestTimeouts::action_timeout());
46
47 current_run_loop = &run_loop;
48 current_run_loop->Run();
49 current_run_loop = nullptr;
50 return !timeout;
51 }
52
53 // static
54 bool ViewManagerTestBase::QuitRunLoop() {
55 if (!current_run_loop)
56 return false;
57
58 current_run_loop->Quit();
59 current_run_loop = nullptr;
60 return true;
61 }
62
63 void ViewManagerTestBase::SetUp() {
64 ApplicationTestBase::SetUp();
65
66 CreateSingleViewTreeHost(application_impl(), this, &host_);
67
68 ASSERT_TRUE(DoRunLoopWithTimeout()); // RunLoop should be quit by OnEmbed().
69 std::swap(window_manager_, most_recent_connection_);
70 }
71
72 void ViewManagerTestBase::TearDown() {
73 ApplicationTestBase::TearDown();
74 }
75
76 ApplicationDelegate* ViewManagerTestBase::GetApplicationDelegate() {
77 return this;
78 }
79
80 bool ViewManagerTestBase::ConfigureIncomingConnection(
81 ApplicationConnection* connection) {
82 connection->AddService<ViewTreeClient>(this);
83 return true;
84 }
85
86 void ViewManagerTestBase::OnEmbed(View* root) {
87 most_recent_connection_ = root->connection();
88 EXPECT_TRUE(QuitRunLoop());
89 }
90
91 void ViewManagerTestBase::OnConnectionLost(ViewTreeConnection* connection) {
92 view_tree_connection_destroyed_ = true;
93 }
94
95 void ViewManagerTestBase::Create(ApplicationConnection* connection,
96 InterfaceRequest<ViewTreeClient> request) {
97 ViewTreeConnection::Create(this, request.Pass());
98 }
99
100 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698