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

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

Issue 1538823002: Convert Pass()→std::move() in mojo/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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/application/public/cpp/application_test_base.h" 5 #include <utility>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "mojo/application/public/cpp/application_impl.h" 9 #include "mojo/application/public/cpp/application_impl.h"
10 #include "mojo/application/public/cpp/application_test_base.h"
10 #include "mojo/application/public/interfaces/application.mojom.h" 11 #include "mojo/application/public/interfaces/application.mojom.h"
11 #include "mojo/public/cpp/bindings/binding.h" 12 #include "mojo/public/cpp/bindings/binding.h"
12 #include "mojo/public/cpp/environment/environment.h" 13 #include "mojo/public/cpp/environment/environment.h"
13 #include "mojo/public/cpp/system/message_pipe.h" 14 #include "mojo/public/cpp/system/message_pipe.h"
14 15
15 namespace mojo { 16 namespace mojo {
16 namespace test { 17 namespace test {
17 18
18 namespace { 19 namespace {
19 // Share the application URL with multiple application tests. 20 // Share the application URL with multiple application tests.
20 String g_url; 21 String g_url;
21 22
22 // Application request handle passed from the shell in MojoMain, stored in 23 // Application request handle passed from the shell in MojoMain, stored in
23 // between SetUp()/TearDown() so we can (re-)intialize new ApplicationImpls. 24 // between SetUp()/TearDown() so we can (re-)intialize new ApplicationImpls.
24 InterfaceRequest<Application> g_application_request; 25 InterfaceRequest<Application> g_application_request;
25 26
26 // Shell pointer passed in the initial mojo.Application.Initialize() call, 27 // Shell pointer passed in the initial mojo.Application.Initialize() call,
27 // stored in between initial setup and the first test and between SetUp/TearDown 28 // stored in between initial setup and the first test and between SetUp/TearDown
28 // calls so we can (re-)initialize new ApplicationImpls. 29 // calls so we can (re-)initialize new ApplicationImpls.
29 ShellPtr g_shell; 30 ShellPtr g_shell;
30 31
31 class ShellGrabber : public Application { 32 class ShellGrabber : public Application {
32 public: 33 public:
33 explicit ShellGrabber(InterfaceRequest<Application> application_request) 34 explicit ShellGrabber(InterfaceRequest<Application> application_request)
34 : binding_(this, application_request.Pass()) {} 35 : binding_(this, std::move(application_request)) {}
35 36
36 void WaitForInitialize() { 37 void WaitForInitialize() {
37 // Initialize is always the first call made on Application. 38 // Initialize is always the first call made on Application.
38 MOJO_CHECK(binding_.WaitForIncomingMethodCall()); 39 MOJO_CHECK(binding_.WaitForIncomingMethodCall());
39 } 40 }
40 41
41 private: 42 private:
42 // Application implementation. 43 // Application implementation.
43 void Initialize(ShellPtr shell, const mojo::String& url) override { 44 void Initialize(ShellPtr shell, const mojo::String& url) override {
44 g_url = url; 45 g_url = url;
45 g_application_request = binding_.Unbind(); 46 g_application_request = binding_.Unbind();
46 g_shell = shell.Pass(); 47 g_shell = std::move(shell);
47 } 48 }
48 49
49 void AcceptConnection(const String& requestor_url, 50 void AcceptConnection(const String& requestor_url,
50 InterfaceRequest<ServiceProvider> services, 51 InterfaceRequest<ServiceProvider> services,
51 ServiceProviderPtr exposed_services, 52 ServiceProviderPtr exposed_services,
52 Array<String> allowed_interfaces, 53 Array<String> allowed_interfaces,
53 const String& url) override { 54 const String& url) override {
54 MOJO_CHECK(false); 55 MOJO_CHECK(false);
55 } 56 }
56 57
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 // A run loop is recommended for ApplicationImpl initialization and 121 // A run loop is recommended for ApplicationImpl initialization and
121 // communication. 122 // communication.
122 if (ShouldCreateDefaultRunLoop()) 123 if (ShouldCreateDefaultRunLoop())
123 Environment::InstantiateDefaultRunLoop(); 124 Environment::InstantiateDefaultRunLoop();
124 125
125 MOJO_CHECK(g_application_request.is_pending()); 126 MOJO_CHECK(g_application_request.is_pending());
126 MOJO_CHECK(g_shell); 127 MOJO_CHECK(g_shell);
127 128
128 // New applications are constructed for each test to avoid persisting state. 129 // New applications are constructed for each test to avoid persisting state.
129 application_impl_ = new ApplicationImpl(GetApplicationDelegate(), 130 application_impl_ = new ApplicationImpl(GetApplicationDelegate(),
130 g_application_request.Pass()); 131 std::move(g_application_request));
131 132
132 // Fake application initialization. 133 // Fake application initialization.
133 Application* application = application_impl_; 134 Application* application = application_impl_;
134 application->Initialize(g_shell.Pass(), g_url); 135 application->Initialize(std::move(g_shell), g_url);
135 } 136 }
136 137
137 void ApplicationTestBase::TearDown() { 138 void ApplicationTestBase::TearDown() {
138 MOJO_CHECK(!g_application_request.is_pending()); 139 MOJO_CHECK(!g_application_request.is_pending());
139 MOJO_CHECK(!g_shell); 140 MOJO_CHECK(!g_shell);
140 141
141 // TODO: commented out until http://crbug.com/533107 is solved. 142 // TODO: commented out until http://crbug.com/533107 is solved.
142 // { 143 // {
143 // ApplicationImpl::TestApi test_api(application_impl_); 144 // ApplicationImpl::TestApi test_api(application_impl_);
144 // test_api.UnbindConnections(&g_application_request, &g_shell); 145 // test_api.UnbindConnections(&g_application_request, &g_shell);
145 // } 146 // }
146 delete application_impl_; 147 delete application_impl_;
147 if (ShouldCreateDefaultRunLoop()) 148 if (ShouldCreateDefaultRunLoop())
148 Environment::DestroyDefaultRunLoop(); 149 Environment::DestroyDefaultRunLoop();
149 } 150 }
150 151
151 bool ApplicationTestBase::ShouldCreateDefaultRunLoop() { 152 bool ApplicationTestBase::ShouldCreateDefaultRunLoop() {
152 return true; 153 return true;
153 } 154 }
154 155
155 156
156 } // namespace test 157 } // namespace test
157 } // namespace mojo 158 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/application/public/cpp/lib/application_impl.cc ('k') | mojo/application/public/cpp/lib/content_handler_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698