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

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 2 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,
244 : test_context_(test_context) { 244 TesterContext* test_context,
245 InterfaceRequest<TestA> request)
246 : test_context_(test_context),
247 binding_(this, request.Pass()) {
245 connection->ConnectToApplication(kTestBURLString)->ConnectToService(&b_); 248 connection->ConnectToApplication(kTestBURLString)->ConnectToService(&b_);
246 } 249 }
247 ~TestAImpl() override { 250 ~TestAImpl() override {
248 test_context_->IncrementNumADeletes(); 251 test_context_->IncrementNumADeletes();
249 if (base::MessageLoop::current()->is_running()) 252 if (base::MessageLoop::current()->is_running())
250 Quit(); 253 Quit();
251 } 254 }
252 255
253 private: 256 private:
254 void CallB() override { 257 void CallB() override {
255 b_->B(base::Bind(&TestAImpl::Quit, base::Unretained(this))); 258 b_->B(base::Bind(&TestAImpl::Quit, base::Unretained(this)));
256 } 259 }
257 260
258 void CallCFromB() override { 261 void CallCFromB() override {
259 b_->CallC(base::Bind(&TestAImpl::Quit, base::Unretained(this))); 262 b_->CallC(base::Bind(&TestAImpl::Quit, base::Unretained(this)));
260 } 263 }
261 264
262 void Quit() { 265 void Quit() {
263 base::MessageLoop::current()->Quit(); 266 base::MessageLoop::current()->Quit();
264 test_context_->set_a_called_quit(); 267 test_context_->set_a_called_quit();
265 test_context_->QuitSoon(); 268 test_context_->QuitSoon();
266 } 269 }
267 270
268 TesterContext* test_context_; 271 TesterContext* test_context_;
269 TestBPtr b_; 272 TestBPtr b_;
273 Binding<TestA> binding_;
270 }; 274 };
271 275
272 class TestBImpl : public InterfaceImpl<TestB> { 276 class TestBImpl : public InterfaceImpl<TestB> {
273 public: 277 public:
274 TestBImpl(ApplicationConnection* connection, TesterContext* test_context) 278 TestBImpl(ApplicationConnection* connection, TesterContext* test_context)
275 : test_context_(test_context) { 279 : test_context_(test_context) {
276 connection->ConnectToService(&c_); 280 connection->ConnectToService(&c_);
277 } 281 }
278 282
279 ~TestBImpl() override { 283 ~TestBImpl() override {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 356
353 bool ConfigureOutgoingConnection(ApplicationConnection* connection) override { 357 bool ConfigureOutgoingConnection(ApplicationConnection* connection) override {
354 // If we're connecting to B, then add C. 358 // If we're connecting to B, then add C.
355 if (connection->GetRemoteApplicationURL() == kTestBURLString) 359 if (connection->GetRemoteApplicationURL() == kTestBURLString)
356 connection->AddService<TestC>(this); 360 connection->AddService<TestC>(this);
357 return true; 361 return true;
358 } 362 }
359 363
360 void Create(ApplicationConnection* connection, 364 void Create(ApplicationConnection* connection,
361 InterfaceRequest<TestA> request) override { 365 InterfaceRequest<TestA> request) override {
362 BindToRequest(new TestAImpl(connection, context_), &request); 366 a_bindings_.push_back(new TestAImpl(connection, context_, request.Pass()));
363 } 367 }
364 368
365 void Create(ApplicationConnection* connection, 369 void Create(ApplicationConnection* connection,
366 InterfaceRequest<TestB> request) override { 370 InterfaceRequest<TestB> request) override {
367 BindToRequest(new TestBImpl(connection, context_), &request); 371 BindToRequest(new TestBImpl(connection, context_), &request);
368 } 372 }
369 373
370 void Create(ApplicationConnection* connection, 374 void Create(ApplicationConnection* connection,
371 InterfaceRequest<TestC> request) override { 375 InterfaceRequest<TestC> request) override {
372 BindToRequest(new TestCImpl(connection, context_), &request); 376 BindToRequest(new TestCImpl(connection, context_), &request);
373 } 377 }
374 378
375 TesterContext* context_; 379 TesterContext* context_;
376 scoped_ptr<ApplicationImpl> app_; 380 scoped_ptr<ApplicationImpl> app_;
377 std::string requestor_url_; 381 std::string requestor_url_;
382 ScopedVector<TestAImpl> a_bindings_;
378 }; 383 };
379 384
380 class TestServiceInterceptor : public ApplicationManager::Interceptor { 385 class TestServiceInterceptor : public ApplicationManager::Interceptor {
381 public: 386 public:
382 TestServiceInterceptor() : call_count_(0) {} 387 TestServiceInterceptor() : call_count_(0) {}
383 388
384 ServiceProviderPtr OnConnectToClient( 389 ServiceProviderPtr OnConnectToClient(
385 const GURL& url, 390 const GURL& url,
386 ServiceProviderPtr service_provider) override { 391 ServiceProviderPtr service_provider) override {
387 ++call_count_; 392 ++call_count_;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 application_manager_->ConnectToService(GURL(kTestURLString), 448 application_manager_->ConnectToService(GURL(kTestURLString),
444 &service_proxy); 449 &service_proxy);
445 test_client_.reset(new TestClientImpl(service_proxy.Pass())); 450 test_client_.reset(new TestClientImpl(service_proxy.Pass()));
446 } 451 }
447 452
448 void TearDown() override { 453 void TearDown() override {
449 test_client_.reset(NULL); 454 test_client_.reset(NULL);
450 application_manager_.reset(NULL); 455 application_manager_.reset(NULL);
451 } 456 }
452 457
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) { 458 void AddLoaderForURL(const GURL& url, const std::string& requestor_url) {
465 application_manager_->SetLoaderForURL(MakeLoader(requestor_url), url); 459 application_manager_->SetLoaderForURL(
460 make_scoped_ptr(new Tester(&tester_context_, requestor_url)), url);
466 } 461 }
467 462
468 bool HasFactoryForTestURL() { 463 bool HasFactoryForTestURL() {
469 ApplicationManager::TestAPI manager_test_api(application_manager_.get()); 464 ApplicationManager::TestAPI manager_test_api(application_manager_.get());
470 return manager_test_api.HasFactoryForURL(GURL(kTestURLString)); 465 return manager_test_api.HasFactoryForURL(GURL(kTestURLString));
471 } 466 }
472 467
473 protected: 468 protected:
474 base::ShadowingAtExitManager at_exit_; 469 base::ShadowingAtExitManager at_exit_;
475 TestDelegate test_delegate_; 470 TestDelegate test_delegate_;
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 TestServicePtr test_service2; 706 TestServicePtr test_service2;
712 application_manager_->ConnectToService(GURL("foo:foo2"), &test_service2); 707 application_manager_->ConnectToService(GURL("foo:foo2"), &test_service2);
713 EXPECT_EQ(2, test_loader_->num_loads()); 708 EXPECT_EQ(2, test_loader_->num_loads());
714 709
715 TestServicePtr test_service3; 710 TestServicePtr test_service3;
716 application_manager_->ConnectToService(GURL("bar:bar"), &test_service2); 711 application_manager_->ConnectToService(GURL("bar:bar"), &test_service2);
717 EXPECT_EQ(3, test_loader_->num_loads()); 712 EXPECT_EQ(3, test_loader_->num_loads());
718 } 713 }
719 714
720 } // namespace mojo 715 } // 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