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

Side by Side Diff: mojo/application_manager/application_manager_unittest.cc

Issue 812083002: Removes BackgroundShellApplicationLoader from application_manager tests (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: merge to trunk Created 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/at_exit.h" 5 #include "base/at_exit.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/scoped_vector.h"
8 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
9 #include "mojo/application_manager/application_loader.h" 10 #include "mojo/application_manager/application_loader.h"
10 #include "mojo/application_manager/application_manager.h" 11 #include "mojo/application_manager/application_manager.h"
11 #include "mojo/application_manager/background_shell_application_loader.h"
12 #include "mojo/application_manager/test.mojom.h" 12 #include "mojo/application_manager/test.mojom.h"
13 #include "mojo/public/cpp/application/application_connection.h" 13 #include "mojo/public/cpp/application/application_connection.h"
14 #include "mojo/public/cpp/application/application_delegate.h" 14 #include "mojo/public/cpp/application/application_delegate.h"
15 #include "mojo/public/cpp/application/application_impl.h" 15 #include "mojo/public/cpp/application/application_impl.h"
16 #include "mojo/public/cpp/application/interface_factory.h" 16 #include "mojo/public/cpp/application/interface_factory.h"
17 #include "mojo/public/interfaces/application/service_provider.mojom.h" 17 #include "mojo/public/interfaces/application/service_provider.mojom.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 19
20 namespace mojo { 20 namespace mojo {
21 namespace { 21 namespace {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 service_.set_client(this); 77 service_.set_client(this);
78 } 78 }
79 79
80 ~TestClientImpl() override { service_.reset(); } 80 ~TestClientImpl() override { service_.reset(); }
81 81
82 void AckTest() override { 82 void AckTest() override {
83 if (quit_after_ack_) 83 if (quit_after_ack_)
84 base::MessageLoop::current()->Quit(); 84 base::MessageLoop::current()->Quit();
85 } 85 }
86 86
87 void Test(std::string test_string) { 87 void Test(const std::string& test_string) {
88 quit_after_ack_ = true; 88 quit_after_ack_ = true;
89 service_->Test(test_string); 89 service_->Test(test_string);
90 } 90 }
91 91
92 private: 92 private:
93 TestServicePtr service_; 93 TestServicePtr service_;
94 bool quit_after_ack_; 94 bool quit_after_ack_;
95 DISALLOW_COPY_AND_ASSIGN(TestClientImpl); 95 DISALLOW_COPY_AND_ASSIGN(TestClientImpl);
96 }; 96 };
97 97
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 int num_a_deletes_; 231 int num_a_deletes_;
232 int num_b_deletes_; 232 int num_b_deletes_;
233 int num_c_deletes_; 233 int num_c_deletes_;
234 bool tester_called_quit_; 234 bool tester_called_quit_;
235 bool a_called_quit_; 235 bool a_called_quit_;
236 236
237 base::MessageLoop* loop_; 237 base::MessageLoop* loop_;
238 }; 238 };
239 239
240 // Used to test that the requestor url will be correctly passed. 240 // Used to test that the requestor url will be correctly passed.
241 class TestAImpl : public InterfaceImpl<TestA> { 241 class TestAImpl : public TestA {
242 public: 242 public:
243 TestAImpl(ApplicationConnection* connection, TesterContext* test_context) 243 TestAImpl(ApplicationConnection* connection, TesterContext* test_context)
244 : test_context_(test_context) { 244 : test_context_(test_context) {
245 connection->ConnectToApplication(kTestBURLString)->ConnectToService(&b_); 245 connection->ConnectToApplication(kTestBURLString)->ConnectToService(&b_);
246 } 246 }
247 ~TestAImpl() override { 247 ~TestAImpl() override {
248 test_context_->IncrementNumADeletes(); 248 test_context_->IncrementNumADeletes();
249 if (base::MessageLoop::current()->is_running()) 249 if (base::MessageLoop::current()->is_running())
250 Quit(); 250 Quit();
251 } 251 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 public ApplicationLoader, 317 public ApplicationLoader,
318 public InterfaceFactory<TestA>, 318 public InterfaceFactory<TestA>,
319 public InterfaceFactory<TestB>, 319 public InterfaceFactory<TestB>,
320 public InterfaceFactory<TestC> { 320 public InterfaceFactory<TestC> {
321 public: 321 public:
322 Tester(TesterContext* context, const std::string& requestor_url) 322 Tester(TesterContext* context, const std::string& requestor_url)
323 : context_(context), requestor_url_(requestor_url) {} 323 : context_(context), requestor_url_(requestor_url) {}
324 ~Tester() override {} 324 ~Tester() override {}
325 325
326 private: 326 private:
327 struct TestABinding {
qsr 2014/12/18 08:58:34 I'm perfectly fine with this, but you could have o
sky 2014/12/18 16:46:55 Good point. I went with your second suggestion.
328 scoped_ptr<TestAImpl> a;
329 scoped_ptr<Binding<TestA>> binding;
330 };
331
327 void Load(ApplicationManager* manager, 332 void Load(ApplicationManager* manager,
328 const GURL& url, 333 const GURL& url,
329 ScopedMessagePipeHandle shell_handle, 334 ScopedMessagePipeHandle shell_handle,
330 LoadCallback callback) override { 335 LoadCallback callback) override {
331 app_.reset(new ApplicationImpl(this, shell_handle.Pass())); 336 app_.reset(new ApplicationImpl(this, shell_handle.Pass()));
332 } 337 }
333 338
334 void OnApplicationError(ApplicationManager* manager, 339 void OnApplicationError(ApplicationManager* manager,
335 const GURL& url) override {} 340 const GURL& url) override {}
336 341
(...skipping 15 matching lines...) Expand all
352 357
353 bool ConfigureOutgoingConnection(ApplicationConnection* connection) override { 358 bool ConfigureOutgoingConnection(ApplicationConnection* connection) override {
354 // If we're connecting to B, then add C. 359 // If we're connecting to B, then add C.
355 if (connection->GetRemoteApplicationURL() == kTestBURLString) 360 if (connection->GetRemoteApplicationURL() == kTestBURLString)
356 connection->AddService<TestC>(this); 361 connection->AddService<TestC>(this);
357 return true; 362 return true;
358 } 363 }
359 364
360 void Create(ApplicationConnection* connection, 365 void Create(ApplicationConnection* connection,
361 InterfaceRequest<TestA> request) override { 366 InterfaceRequest<TestA> request) override {
362 BindToRequest(new TestAImpl(connection, context_), &request); 367 scoped_ptr<TestABinding> binding(new TestABinding);
368 binding->a.reset(new TestAImpl(connection, context_));
369 binding->binding.reset(new Binding<TestA>(binding->a.get(),
370 request.Pass()));
371 a_bindings_.push_back(binding.release());
363 } 372 }
364 373
365 void Create(ApplicationConnection* connection, 374 void Create(ApplicationConnection* connection,
366 InterfaceRequest<TestB> request) override { 375 InterfaceRequest<TestB> request) override {
367 BindToRequest(new TestBImpl(connection, context_), &request); 376 BindToRequest(new TestBImpl(connection, context_), &request);
368 } 377 }
369 378
370 void Create(ApplicationConnection* connection, 379 void Create(ApplicationConnection* connection,
371 InterfaceRequest<TestC> request) override { 380 InterfaceRequest<TestC> request) override {
372 BindToRequest(new TestCImpl(connection, context_), &request); 381 BindToRequest(new TestCImpl(connection, context_), &request);
373 } 382 }
374 383
375 TesterContext* context_; 384 TesterContext* context_;
376 scoped_ptr<ApplicationImpl> app_; 385 scoped_ptr<ApplicationImpl> app_;
377 std::string requestor_url_; 386 std::string requestor_url_;
387 ScopedVector<TestABinding> a_bindings_;
378 }; 388 };
379 389
380 class TestServiceInterceptor : public ApplicationManager::Interceptor { 390 class TestServiceInterceptor : public ApplicationManager::Interceptor {
381 public: 391 public:
382 TestServiceInterceptor() : call_count_(0) {} 392 TestServiceInterceptor() : call_count_(0) {}
383 393
384 ServiceProviderPtr OnConnectToClient( 394 ServiceProviderPtr OnConnectToClient(
385 const GURL& url, 395 const GURL& url,
386 ServiceProviderPtr service_provider) override { 396 ServiceProviderPtr service_provider) override {
387 ++call_count_; 397 ++call_count_;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 application_manager_->ConnectToService(GURL(kTestURLString), 453 application_manager_->ConnectToService(GURL(kTestURLString),
444 &service_proxy); 454 &service_proxy);
445 test_client_.reset(new TestClientImpl(service_proxy.Pass())); 455 test_client_.reset(new TestClientImpl(service_proxy.Pass()));
446 } 456 }
447 457
448 void TearDown() override { 458 void TearDown() override {
449 test_client_.reset(NULL); 459 test_client_.reset(NULL);
450 application_manager_.reset(NULL); 460 application_manager_.reset(NULL);
451 } 461 }
452 462
453 scoped_ptr<BackgroundShellApplicationLoader> MakeLoader(
454 const std::string& requestor_url) {
455 scoped_ptr<ApplicationLoader> real_loader(
456 new Tester(&tester_context_, requestor_url));
457 scoped_ptr<BackgroundShellApplicationLoader> loader(
458 new BackgroundShellApplicationLoader(real_loader.Pass(),
459 std::string(),
460 base::MessageLoop::TYPE_DEFAULT));
461 return loader.Pass();
462 }
463
464 void AddLoaderForURL(const GURL& url, const std::string& requestor_url) { 463 void AddLoaderForURL(const GURL& url, const std::string& requestor_url) {
465 application_manager_->SetLoaderForURL(MakeLoader(requestor_url), url); 464 application_manager_->SetLoaderForURL(
465 make_scoped_ptr(new Tester(&tester_context_, requestor_url)), url);
466 } 466 }
467 467
468 bool HasFactoryForTestURL() { 468 bool HasFactoryForTestURL() {
469 ApplicationManager::TestAPI manager_test_api(application_manager_.get()); 469 ApplicationManager::TestAPI manager_test_api(application_manager_.get());
470 return manager_test_api.HasFactoryForURL(GURL(kTestURLString)); 470 return manager_test_api.HasFactoryForURL(GURL(kTestURLString));
471 } 471 }
472 472
473 protected: 473 protected:
474 base::ShadowingAtExitManager at_exit_; 474 base::ShadowingAtExitManager at_exit_;
475 TestDelegate test_delegate_; 475 TestDelegate test_delegate_;
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 TestServicePtr test_service2; 711 TestServicePtr test_service2;
712 application_manager_->ConnectToService(GURL("foo:foo2"), &test_service2); 712 application_manager_->ConnectToService(GURL("foo:foo2"), &test_service2);
713 EXPECT_EQ(2, test_loader_->num_loads()); 713 EXPECT_EQ(2, test_loader_->num_loads());
714 714
715 TestServicePtr test_service3; 715 TestServicePtr test_service3;
716 application_manager_->ConnectToService(GURL("bar:bar"), &test_service2); 716 application_manager_->ConnectToService(GURL("bar:bar"), &test_service2);
717 EXPECT_EQ(3, test_loader_->num_loads()); 717 EXPECT_EQ(3, test_loader_->num_loads());
718 } 718 }
719 719
720 } // namespace mojo 720 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698