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

Side by Side Diff: mojo/package_manager/content_handler_unittest.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 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 <utility>
6
5 #include "base/at_exit.h" 7 #include "base/at_exit.h"
6 #include "base/bind.h" 8 #include "base/bind.h"
7 #include "base/macros.h" 9 #include "base/macros.h"
8 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
9 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
10 #include "base/path_service.h" 12 #include "base/path_service.h"
11 #include "base/run_loop.h" 13 #include "base/run_loop.h"
12 #include "mojo/application/public/cpp/application_connection.h" 14 #include "mojo/application/public/cpp/application_connection.h"
13 #include "mojo/application/public/cpp/application_delegate.h" 15 #include "mojo/application/public/cpp/application_delegate.h"
14 #include "mojo/application/public/cpp/application_impl.h" 16 #include "mojo/application/public/cpp/application_impl.h"
(...skipping 25 matching lines...) Expand all
40 loader_callback_.Run(make_scoped_ptr(this)); 42 loader_callback_.Run(make_scoped_ptr(this));
41 } 43 }
42 ~TestFetcher() override {} 44 ~TestFetcher() override {}
43 45
44 // Fetcher: 46 // Fetcher:
45 const GURL& GetURL() const override { return url_; } 47 const GURL& GetURL() const override { return url_; }
46 GURL GetRedirectURL() const override { return GURL("yyy"); } 48 GURL GetRedirectURL() const override { return GURL("yyy"); }
47 GURL GetRedirectReferer() const override { return GURL(); } 49 GURL GetRedirectReferer() const override { return GURL(); }
48 URLResponsePtr AsURLResponse(base::TaskRunner* task_runner, 50 URLResponsePtr AsURLResponse(base::TaskRunner* task_runner,
49 uint32_t skip) override { 51 uint32_t skip) override {
50 return URLResponse::New().Pass(); 52 return URLResponse::New();
51 } 53 }
52 void AsPath( 54 void AsPath(
53 base::TaskRunner* task_runner, 55 base::TaskRunner* task_runner,
54 base::Callback<void(const base::FilePath&, bool)> callback) override {} 56 base::Callback<void(const base::FilePath&, bool)> callback) override {}
55 std::string MimeType() override { return mime_type_; } 57 std::string MimeType() override { return mime_type_; }
56 bool HasMojoMagic() override { return false; } 58 bool HasMojoMagic() override { return false; }
57 bool PeekFirstLine(std::string* line) override { return false; } 59 bool PeekFirstLine(std::string* line) override { return false; }
58 60
59 private: 61 private:
60 const GURL url_; 62 const GURL url_;
61 const std::string mime_type_; 63 const std::string mime_type_;
62 64
63 DISALLOW_COPY_AND_ASSIGN(TestFetcher); 65 DISALLOW_COPY_AND_ASSIGN(TestFetcher);
64 }; 66 };
65 67
66 void QuitClosure(bool* value) { 68 void QuitClosure(bool* value) {
67 *value = true; 69 *value = true;
68 base::MessageLoop::current()->QuitWhenIdle(); 70 base::MessageLoop::current()->QuitWhenIdle();
69 } 71 }
70 72
71 class TestContentHandler : public ContentHandler, public ApplicationDelegate { 73 class TestContentHandler : public ContentHandler, public ApplicationDelegate {
72 public: 74 public:
73 TestContentHandler(ApplicationConnection* connection, 75 TestContentHandler(ApplicationConnection* connection,
74 InterfaceRequest<ContentHandler> request) 76 InterfaceRequest<ContentHandler> request)
75 : binding_(this, request.Pass()) {} 77 : binding_(this, std::move(request)) {}
76 78
77 // ContentHandler: 79 // ContentHandler:
78 void StartApplication( 80 void StartApplication(
79 InterfaceRequest<Application> application_request, 81 InterfaceRequest<Application> application_request,
80 URLResponsePtr response, 82 URLResponsePtr response,
81 const Callback<void()>& destruct_callback) override { 83 const Callback<void()>& destruct_callback) override {
82 apps_.push_back(new ApplicationImpl(this, application_request.Pass())); 84 apps_.push_back(new ApplicationImpl(this, std::move(application_request)));
83 destruct_callback.Run(); 85 destruct_callback.Run();
84 } 86 }
85 87
86 private: 88 private:
87 StrongBinding<ContentHandler> binding_; 89 StrongBinding<ContentHandler> binding_;
88 ScopedVector<ApplicationImpl> apps_; 90 ScopedVector<ApplicationImpl> apps_;
89 91
90 DISALLOW_COPY_AND_ASSIGN(TestContentHandler); 92 DISALLOW_COPY_AND_ASSIGN(TestContentHandler);
91 }; 93 };
92 94
93 class TestApplicationLoader : public shell::ApplicationLoader, 95 class TestApplicationLoader : public shell::ApplicationLoader,
94 public ApplicationDelegate, 96 public ApplicationDelegate,
95 public InterfaceFactory<ContentHandler> { 97 public InterfaceFactory<ContentHandler> {
96 public: 98 public:
97 TestApplicationLoader() : num_loads_(0) {} 99 TestApplicationLoader() : num_loads_(0) {}
98 ~TestApplicationLoader() override {} 100 ~TestApplicationLoader() override {}
99 101
100 int num_loads() const { return num_loads_; } 102 int num_loads() const { return num_loads_; }
101 const GURL& last_requestor_url() const { return last_requestor_url_; } 103 const GURL& last_requestor_url() const { return last_requestor_url_; }
102 104
103 private: 105 private:
104 // ApplicationLoader implementation. 106 // ApplicationLoader implementation.
105 void Load(const GURL& url, 107 void Load(const GURL& url,
106 InterfaceRequest<Application> application_request) override { 108 InterfaceRequest<Application> application_request) override {
107 ++num_loads_; 109 ++num_loads_;
108 test_app_.reset(new ApplicationImpl(this, application_request.Pass())); 110 test_app_.reset(new ApplicationImpl(this, std::move(application_request)));
109 } 111 }
110 112
111 // ApplicationDelegate implementation. 113 // ApplicationDelegate implementation.
112 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { 114 bool ConfigureIncomingConnection(ApplicationConnection* connection) override {
113 connection->AddService<ContentHandler>(this); 115 connection->AddService<ContentHandler>(this);
114 last_requestor_url_ = GURL(connection->GetRemoteApplicationURL()); 116 last_requestor_url_ = GURL(connection->GetRemoteApplicationURL());
115 return true; 117 return true;
116 } 118 }
117 // InterfaceFactory<ContentHandler> implementation. 119 // InterfaceFactory<ContentHandler> implementation.
118 void Create(ApplicationConnection* connection, 120 void Create(ApplicationConnection* connection,
119 InterfaceRequest<ContentHandler> request) override { 121 InterfaceRequest<ContentHandler> request) override {
120 new TestContentHandler(connection, request.Pass()); 122 new TestContentHandler(connection, std::move(request));
121 } 123 }
122 124
123 scoped_ptr<ApplicationImpl> test_app_; 125 scoped_ptr<ApplicationImpl> test_app_;
124 int num_loads_; 126 int num_loads_;
125 GURL last_requestor_url_; 127 GURL last_requestor_url_;
126 128
127 DISALLOW_COPY_AND_ASSIGN(TestApplicationLoader); 129 DISALLOW_COPY_AND_ASSIGN(TestApplicationLoader);
128 }; 130 };
129 131
130 class TestPackageManager : public PackageManagerImpl { 132 class TestPackageManager : public PackageManagerImpl {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 scoped_ptr<shell::ApplicationLoader>(loader), 195 scoped_ptr<shell::ApplicationLoader>(loader),
194 content_handler_url_); 196 content_handler_url_);
195 197
196 bool called = false; 198 bool called = false;
197 scoped_ptr<shell::ConnectToApplicationParams> params( 199 scoped_ptr<shell::ConnectToApplicationParams> params(
198 new shell::ConnectToApplicationParams); 200 new shell::ConnectToApplicationParams);
199 params->set_source(shell::Identity(requestor_url_)); 201 params->set_source(shell::Identity(requestor_url_));
200 params->SetTargetURL(GURL("test:test")); 202 params->SetTargetURL(GURL("test:test"));
201 params->set_on_application_end( 203 params->set_on_application_end(
202 base::Bind(&QuitClosure, base::Unretained(&called))); 204 base::Bind(&QuitClosure, base::Unretained(&called)));
203 application_manager_->ConnectToApplication(params.Pass()); 205 application_manager_->ConnectToApplication(std::move(params));
204 loop_.Run(); 206 loop_.Run();
205 EXPECT_TRUE(called); 207 EXPECT_TRUE(called);
206 208
207 ASSERT_EQ(1, loader->num_loads()); 209 ASSERT_EQ(1, loader->num_loads());
208 EXPECT_EQ(requestor_url_, loader->last_requestor_url()); 210 EXPECT_EQ(requestor_url_, loader->last_requestor_url());
209 } 211 }
210 212
211 TEST_F(ContentHandlerTest, 213 TEST_F(ContentHandlerTest,
212 MultipleConnectionsToContentHandlerGetSameContentHandlerId) { 214 MultipleConnectionsToContentHandlerGetSameContentHandlerId) {
213 TestApplicationLoader* content_handler_loader = new TestApplicationLoader; 215 TestApplicationLoader* content_handler_loader = new TestApplicationLoader;
214 application_manager_->SetLoaderForURL( 216 application_manager_->SetLoaderForURL(
215 scoped_ptr<shell::ApplicationLoader>(content_handler_loader), 217 scoped_ptr<shell::ApplicationLoader>(content_handler_loader),
216 content_handler_url_); 218 content_handler_url_);
217 219
218 uint32_t content_handler_id; 220 uint32_t content_handler_id;
219 { 221 {
220 base::RunLoop run_loop; 222 base::RunLoop run_loop;
221 scoped_ptr<shell::ConnectToApplicationParams> params( 223 scoped_ptr<shell::ConnectToApplicationParams> params(
222 new shell::ConnectToApplicationParams); 224 new shell::ConnectToApplicationParams);
223 params->set_source(shell::Identity(requestor_url_)); 225 params->set_source(shell::Identity(requestor_url_));
224 params->SetTargetURL(GURL("test:test")); 226 params->SetTargetURL(GURL("test:test"));
225 params->set_connect_callback([&content_handler_id, &run_loop](uint32_t t) { 227 params->set_connect_callback([&content_handler_id, &run_loop](uint32_t t) {
226 content_handler_id = t; 228 content_handler_id = t;
227 run_loop.Quit(); 229 run_loop.Quit();
228 }); 230 });
229 application_manager_->ConnectToApplication(params.Pass()); 231 application_manager_->ConnectToApplication(std::move(params));
230 run_loop.Run(); 232 run_loop.Run();
231 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id); 233 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id);
232 } 234 }
233 235
234 uint32_t content_handler_id2; 236 uint32_t content_handler_id2;
235 { 237 {
236 base::RunLoop run_loop; 238 base::RunLoop run_loop;
237 scoped_ptr<shell::ConnectToApplicationParams> params( 239 scoped_ptr<shell::ConnectToApplicationParams> params(
238 new shell::ConnectToApplicationParams); 240 new shell::ConnectToApplicationParams);
239 params->set_source(shell::Identity(requestor_url_)); 241 params->set_source(shell::Identity(requestor_url_));
240 params->SetTargetURL(GURL("test:test")); 242 params->SetTargetURL(GURL("test:test"));
241 params->set_connect_callback([&content_handler_id2, &run_loop](uint32_t t) { 243 params->set_connect_callback([&content_handler_id2, &run_loop](uint32_t t) {
242 content_handler_id2 = t; 244 content_handler_id2 = t;
243 run_loop.Quit(); 245 run_loop.Quit();
244 }); 246 });
245 application_manager_->ConnectToApplication(params.Pass()); 247 application_manager_->ConnectToApplication(std::move(params));
246 run_loop.Run(); 248 run_loop.Run();
247 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id2); 249 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id2);
248 } 250 }
249 EXPECT_EQ(content_handler_id, content_handler_id2); 251 EXPECT_EQ(content_handler_id, content_handler_id2);
250 } 252 }
251 253
252 TEST_F(ContentHandlerTest, DifferedContentHandlersGetDifferentIDs) { 254 TEST_F(ContentHandlerTest, DifferedContentHandlersGetDifferentIDs) {
253 TestApplicationLoader* content_handler_loader = new TestApplicationLoader; 255 TestApplicationLoader* content_handler_loader = new TestApplicationLoader;
254 application_manager_->SetLoaderForURL( 256 application_manager_->SetLoaderForURL(
255 scoped_ptr<shell::ApplicationLoader>(content_handler_loader), 257 scoped_ptr<shell::ApplicationLoader>(content_handler_loader),
256 content_handler_url_); 258 content_handler_url_);
257 259
258 uint32_t content_handler_id; 260 uint32_t content_handler_id;
259 { 261 {
260 base::RunLoop run_loop; 262 base::RunLoop run_loop;
261 scoped_ptr<shell::ConnectToApplicationParams> params( 263 scoped_ptr<shell::ConnectToApplicationParams> params(
262 new shell::ConnectToApplicationParams); 264 new shell::ConnectToApplicationParams);
263 params->set_source(shell::Identity(requestor_url_)); 265 params->set_source(shell::Identity(requestor_url_));
264 params->SetTargetURL(GURL("test:test")); 266 params->SetTargetURL(GURL("test:test"));
265 params->set_connect_callback([&content_handler_id, &run_loop](uint32_t t) { 267 params->set_connect_callback([&content_handler_id, &run_loop](uint32_t t) {
266 content_handler_id = t; 268 content_handler_id = t;
267 run_loop.Quit(); 269 run_loop.Quit();
268 }); 270 });
269 application_manager_->ConnectToApplication(params.Pass()); 271 application_manager_->ConnectToApplication(std::move(params));
270 run_loop.Run(); 272 run_loop.Run();
271 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id); 273 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id);
272 } 274 }
273 275
274 const std::string mime_type2 = "test/mime-type2"; 276 const std::string mime_type2 = "test/mime-type2";
275 const GURL content_handler_url2("http://test.content.handler2"); 277 const GURL content_handler_url2("http://test.content.handler2");
276 test_package_manager_->set_mime_type(mime_type2); 278 test_package_manager_->set_mime_type(mime_type2);
277 test_package_manager_->RegisterContentHandler(mime_type2, 279 test_package_manager_->RegisterContentHandler(mime_type2,
278 content_handler_url2); 280 content_handler_url2);
279 281
280 TestApplicationLoader* content_handler_loader2 = new TestApplicationLoader; 282 TestApplicationLoader* content_handler_loader2 = new TestApplicationLoader;
281 application_manager_->SetLoaderForURL( 283 application_manager_->SetLoaderForURL(
282 scoped_ptr<shell::ApplicationLoader>(content_handler_loader2), 284 scoped_ptr<shell::ApplicationLoader>(content_handler_loader2),
283 content_handler_url2); 285 content_handler_url2);
284 286
285 uint32_t content_handler_id2; 287 uint32_t content_handler_id2;
286 { 288 {
287 base::RunLoop run_loop; 289 base::RunLoop run_loop;
288 scoped_ptr<shell::ConnectToApplicationParams> params( 290 scoped_ptr<shell::ConnectToApplicationParams> params(
289 new shell::ConnectToApplicationParams); 291 new shell::ConnectToApplicationParams);
290 params->set_source(shell::Identity(requestor_url_)); 292 params->set_source(shell::Identity(requestor_url_));
291 params->SetTargetURL(GURL("test2:test2")); 293 params->SetTargetURL(GURL("test2:test2"));
292 params->set_connect_callback([&content_handler_id2, &run_loop](uint32_t t) { 294 params->set_connect_callback([&content_handler_id2, &run_loop](uint32_t t) {
293 content_handler_id2 = t; 295 content_handler_id2 = t;
294 run_loop.Quit(); 296 run_loop.Quit();
295 }); 297 });
296 application_manager_->ConnectToApplication(params.Pass()); 298 application_manager_->ConnectToApplication(std::move(params));
297 run_loop.Run(); 299 run_loop.Run();
298 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id2); 300 EXPECT_NE(Shell::kInvalidContentHandlerID, content_handler_id2);
299 } 301 }
300 EXPECT_NE(content_handler_id, content_handler_id2); 302 EXPECT_NE(content_handler_id, content_handler_id2);
301 } 303 }
302 304
303 TEST_F(ContentHandlerTest, 305 TEST_F(ContentHandlerTest,
304 ConnectWithNoContentHandlerGetsInvalidContentHandlerId) { 306 ConnectWithNoContentHandlerGetsInvalidContentHandlerId) {
305 application_manager_->SetLoaderForURL( 307 application_manager_->SetLoaderForURL(
306 scoped_ptr<shell::ApplicationLoader>(new TestApplicationLoader), 308 scoped_ptr<shell::ApplicationLoader>(new TestApplicationLoader),
307 GURL("test:test")); 309 GURL("test:test"));
308 310
309 uint32_t content_handler_id = 1u; 311 uint32_t content_handler_id = 1u;
310 scoped_ptr<shell::ConnectToApplicationParams> params( 312 scoped_ptr<shell::ConnectToApplicationParams> params(
311 new shell::ConnectToApplicationParams); 313 new shell::ConnectToApplicationParams);
312 params->SetTargetURL(GURL("test:test")); 314 params->SetTargetURL(GURL("test:test"));
313 params->set_connect_callback( 315 params->set_connect_callback(
314 [&content_handler_id](uint32_t t) { content_handler_id = t; }); 316 [&content_handler_id](uint32_t t) { content_handler_id = t; });
315 application_manager_->ConnectToApplication(params.Pass()); 317 application_manager_->ConnectToApplication(std::move(params));
316 EXPECT_EQ(0u, content_handler_id); 318 EXPECT_EQ(0u, content_handler_id);
317 } 319 }
318 320
319 } // namespace test 321 } // namespace test
320 } // namespace package_manager 322 } // namespace package_manager
321 } // namespace mojo 323 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/package_manager/content_handler_connection.cc ('k') | mojo/package_manager/package_manager_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698