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

Side by Side Diff: mojo/public/cpp/application/lib/application_test_base.cc

Issue 1990603002: Make ApplicationTestBase not use ApplicationImpl. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: delete ApplicationImpl::WaitForInitialize() Created 4 years, 7 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "mojo/public/cpp/application/application_test_base.h" 5 #include "mojo/public/cpp/application/application_test_base.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "mojo/public/cpp/application/application_impl.h"
10 #include "mojo/public/cpp/bindings/binding.h" 9 #include "mojo/public/cpp/bindings/binding.h"
11 #include "mojo/public/cpp/environment/environment.h" 10 #include "mojo/public/cpp/environment/environment.h"
12 #include "mojo/public/cpp/system/message_pipe.h" 11 #include "mojo/public/cpp/system/message_pipe.h"
13 #include "mojo/public/interfaces/application/application.mojom.h" 12 #include "mojo/public/interfaces/application/application.mojom.h"
14 13
15 namespace mojo { 14 namespace mojo {
16 namespace test { 15 namespace test {
17 16
18 namespace { 17 namespace {
19 18
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 } 69 }
71 70
72 void RequestQuit() override { MOJO_CHECK(false); } 71 void RequestQuit() override { MOJO_CHECK(false); }
73 72
74 Array<String>* args_; 73 Array<String>* args_;
75 Binding<Application> binding_; 74 Binding<Application> binding_;
76 }; 75 };
77 76
78 } // namespace 77 } // namespace
79 78
80 const Array<String>& Args() {
81 return g_args;
82 }
83
84 MojoResult RunAllTests(MojoHandle application_request_handle) { 79 MojoResult RunAllTests(MojoHandle application_request_handle) {
85 { 80 {
86 // This loop is used for init, and then destroyed before running tests. 81 // This loop is used for init, and then destroyed before running tests.
87 Environment::InstantiateDefaultRunLoop(); 82 Environment::InstantiateDefaultRunLoop();
88 83
89 // Grab the shell handle and GTEST commandline arguments. 84 // Grab the shell handle and GTEST commandline arguments.
90 // GTEST command line arguments are supported amid application arguments: 85 // GTEST command line arguments are supported amid application arguments:
91 // $ mojo_shell mojo:example_apptests 86 // $ mojo_shell mojo:example_apptests
92 // --args-for='mojo:example_apptests arg1 --gtest_filter=foo arg2' 87 // --args-for='mojo:example_apptests arg1 --gtest_filter=foo arg2'
93 Array<String> args; 88 Array<String> args;
(...skipping 23 matching lines...) Expand all
117 112
118 int result = RUN_ALL_TESTS(); 113 int result = RUN_ALL_TESTS();
119 114
120 // Shut down our message pipes before exiting. 115 // Shut down our message pipes before exiting.
121 (void)g_application_request.PassMessagePipe(); 116 (void)g_application_request.PassMessagePipe();
122 (void)g_shell.PassInterfaceHandle(); 117 (void)g_shell.PassInterfaceHandle();
123 118
124 return (result == 0) ? MOJO_RESULT_OK : MOJO_RESULT_UNKNOWN; 119 return (result == 0) ? MOJO_RESULT_OK : MOJO_RESULT_UNKNOWN;
125 } 120 }
126 121
127 ApplicationTestBase::ApplicationTestBase() : application_impl_(nullptr) { 122 ApplicationTestBase::ApplicationTestBase() {}
128 }
129 123
130 ApplicationTestBase::~ApplicationTestBase() { 124 ApplicationTestBase::~ApplicationTestBase() {}
131 }
132
133 ApplicationDelegate* ApplicationTestBase::GetApplicationDelegate() {
134 return &default_application_delegate_;
135 }
136 125
137 void ApplicationTestBase::SetUp() { 126 void ApplicationTestBase::SetUp() {
138 // A run loop is recommended for ApplicationImpl initialization and 127 // A run loop is recommended for ApplicationImpl initialization and
139 // communication. 128 // communication.
140 if (ShouldCreateDefaultRunLoop()) 129 if (ShouldCreateDefaultRunLoop())
141 Environment::InstantiateDefaultRunLoop(); 130 Environment::InstantiateDefaultRunLoop();
142 131
143 MOJO_CHECK(g_application_request.is_pending()); 132 MOJO_CHECK(g_application_request.is_pending());
144 MOJO_CHECK(g_shell); 133 MOJO_CHECK(g_shell);
134 MOJO_CHECK(args_.empty());
145 135
146 // New applications are constructed for each test to avoid persisting state. 136 shell_ = g_shell.Pass();
147 application_impl_ = new ApplicationImpl(GetApplicationDelegate(), 137 for (size_t i = 0; i < g_args.size(); i++)
148 g_application_request.Pass()); 138 args_.push_back(g_args[i]);
149
150 // Fake application initialization with the given command line arguments.
151 application_impl_->Initialize(g_shell.Pass(), g_args.Clone(), g_url);
152 } 139 }
153 140
154 void ApplicationTestBase::TearDown() { 141 void ApplicationTestBase::TearDown() {
155 MOJO_CHECK(!g_application_request.is_pending());
156 MOJO_CHECK(!g_shell); 142 MOJO_CHECK(!g_shell);
157 143
158 application_impl_->UnbindConnections(&g_application_request, &g_shell); 144 // TODO(vtl): The straightforward |g_shell = shell_.Pass();| causes tests to
159 delete application_impl_; 145 // hang. Presumably, it's because there are still requests to the shell
146 // pending. :-(
147 g_shell.Bind(shell_.PassInterfaceHandle());
148 args_.clear();
149
160 if (ShouldCreateDefaultRunLoop()) 150 if (ShouldCreateDefaultRunLoop())
161 Environment::DestroyDefaultRunLoop(); 151 Environment::DestroyDefaultRunLoop();
162 } 152 }
163 153
164 bool ApplicationTestBase::ShouldCreateDefaultRunLoop() { 154 bool ApplicationTestBase::ShouldCreateDefaultRunLoop() {
165 return true; 155 return true;
166 } 156 }
167 157
168 } // namespace test 158 } // namespace test
169 } // namespace mojo 159 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/application/lib/application_impl.cc ('k') | mojo/public/cpp/bindings/tests/versioning_apptest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698