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/shell/tests/application_manager_unittest.cc

Issue 1743473002: Change Mojo URLs to structured names (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@18collapse
Patch Set: . Created 4 years, 9 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/shell/application_manager.h" 5 #include "mojo/shell/application_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/at_exit.h" 9 #include "base/at_exit.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 public: 102 public:
103 explicit TestApplicationLoader(TestContext* context) 103 explicit TestApplicationLoader(TestContext* context)
104 : context_(context), num_loads_(0) {} 104 : context_(context), num_loads_(0) {}
105 105
106 ~TestApplicationLoader() override { 106 ~TestApplicationLoader() override {
107 ++context_->num_loader_deletes; 107 ++context_->num_loader_deletes;
108 shell_connection_.reset(); 108 shell_connection_.reset();
109 } 109 }
110 110
111 int num_loads() const { return num_loads_; } 111 int num_loads() const { return num_loads_; }
112 const GURL& last_requestor_url() const { return last_requestor_url_; } 112 std::string last_requestor_name() const { return last_requestor_name_; }
sky 2016/02/26 18:37:27 const std::string&
113 113
114 private: 114 private:
115 // ApplicationLoader implementation. 115 // ApplicationLoader implementation.
116 void Load(const GURL& url, 116 void Load(const std::string& name,
117 InterfaceRequest<mojom::ShellClient> request) override { 117 InterfaceRequest<mojom::ShellClient> request) override {
118 ++num_loads_; 118 ++num_loads_;
119 shell_connection_.reset(new ShellConnection(this, std::move(request))); 119 shell_connection_.reset(new ShellConnection(this, std::move(request)));
120 } 120 }
121 121
122 // mojo::ShellClient implementation. 122 // mojo::ShellClient implementation.
123 bool AcceptConnection(Connection* connection) override { 123 bool AcceptConnection(Connection* connection) override {
124 connection->AddInterface<TestService>(this); 124 connection->AddInterface<TestService>(this);
125 last_requestor_url_ = GURL(connection->GetRemoteApplicationURL()); 125 last_requestor_name_ = connection->GetRemoteApplicationName();
126 return true; 126 return true;
127 } 127 }
128 128
129 // InterfaceFactory<TestService> implementation. 129 // InterfaceFactory<TestService> implementation.
130 void Create(Connection* connection, 130 void Create(Connection* connection,
131 InterfaceRequest<TestService> request) override { 131 InterfaceRequest<TestService> request) override {
132 new TestServiceImpl(context_, std::move(request)); 132 new TestServiceImpl(context_, std::move(request));
133 } 133 }
134 134
135 scoped_ptr<ShellConnection> shell_connection_; 135 scoped_ptr<ShellConnection> shell_connection_;
136 TestContext* context_; 136 TestContext* context_;
137 int num_loads_; 137 int num_loads_;
138 GURL last_requestor_url_; 138 std::string last_requestor_name_;
139 139
140 DISALLOW_COPY_AND_ASSIGN(TestApplicationLoader); 140 DISALLOW_COPY_AND_ASSIGN(TestApplicationLoader);
141 }; 141 };
142 142
143 class ClosingApplicationLoader : public ApplicationLoader { 143 class ClosingApplicationLoader : public ApplicationLoader {
144 private: 144 private:
145 // ApplicationLoader implementation. 145 // ApplicationLoader implementation.
146 void Load(const GURL& url, 146 void Load(const std::string& name,
147 InterfaceRequest<mojom::ShellClient> request) override { 147 InterfaceRequest<mojom::ShellClient> request) override {
148 } 148 }
149 }; 149 };
150 150
151 class TesterContext { 151 class TesterContext {
152 public: 152 public:
153 explicit TesterContext(base::MessageLoop* loop) 153 explicit TesterContext(base::MessageLoop* loop)
154 : num_b_calls_(0), 154 : num_b_calls_(0),
155 num_c_calls_(0), 155 num_c_calls_(0),
156 num_a_deletes_(0), 156 num_a_deletes_(0),
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 int num_c_calls_; 236 int num_c_calls_;
237 int num_a_deletes_; 237 int num_a_deletes_;
238 int num_b_deletes_; 238 int num_b_deletes_;
239 int num_c_deletes_; 239 int num_c_deletes_;
240 bool tester_called_quit_; 240 bool tester_called_quit_;
241 bool a_called_quit_; 241 bool a_called_quit_;
242 242
243 base::MessageLoop* loop_; 243 base::MessageLoop* loop_;
244 }; 244 };
245 245
246 // Used to test that the requestor url will be correctly passed. 246 // Used to test that the requestor name will be correctly passed.
247 class TestAImpl : public TestA { 247 class TestAImpl : public TestA {
248 public: 248 public:
249 TestAImpl(Connector* connector, 249 TestAImpl(Connector* connector,
250 TesterContext* test_context, 250 TesterContext* test_context,
251 InterfaceRequest<TestA> request, 251 InterfaceRequest<TestA> request,
252 InterfaceFactory<TestC>* factory) 252 InterfaceFactory<TestC>* factory)
253 : test_context_(test_context), binding_(this, std::move(request)) { 253 : test_context_(test_context), binding_(this, std::move(request)) {
254 connection_ = connector->Connect(kTestBURLString); 254 connection_ = connector->Connect(kTestBURLString);
255 connection_->AddInterface<TestC>(factory); 255 connection_->AddInterface<TestC>(factory);
256 connection_->GetInterface(&b_); 256 connection_->GetInterface(&b_);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 TesterContext* test_context_; 333 TesterContext* test_context_;
334 StrongBinding<TestC> binding_; 334 StrongBinding<TestC> binding_;
335 }; 335 };
336 336
337 class Tester : public ShellClient, 337 class Tester : public ShellClient,
338 public ApplicationLoader, 338 public ApplicationLoader,
339 public InterfaceFactory<TestA>, 339 public InterfaceFactory<TestA>,
340 public InterfaceFactory<TestB>, 340 public InterfaceFactory<TestB>,
341 public InterfaceFactory<TestC> { 341 public InterfaceFactory<TestC> {
342 public: 342 public:
343 Tester(TesterContext* context, const std::string& requestor_url) 343 Tester(TesterContext* context, const std::string& requestor_name)
344 : context_(context), requestor_url_(requestor_url) {} 344 : context_(context), requestor_name_(requestor_name) {}
345 ~Tester() override {} 345 ~Tester() override {}
346 346
347 private: 347 private:
348 void Load(const GURL& url, 348 void Load(const std::string& name,
349 InterfaceRequest<mojom::ShellClient> request) override { 349 InterfaceRequest<mojom::ShellClient> request) override {
350 app_.reset(new ShellConnection(this, std::move(request))); 350 app_.reset(new ShellConnection(this, std::move(request)));
351 } 351 }
352 352
353 bool AcceptConnection(Connection* connection) override { 353 bool AcceptConnection(Connection* connection) override {
354 if (!requestor_url_.empty() && 354 if (!requestor_name_.empty() &&
355 requestor_url_ != connection->GetRemoteApplicationURL()) { 355 requestor_name_ != connection->GetRemoteApplicationName()) {
356 context_->set_tester_called_quit(); 356 context_->set_tester_called_quit();
357 context_->QuitSoon(); 357 context_->QuitSoon();
358 base::MessageLoop::current()->QuitWhenIdle(); 358 base::MessageLoop::current()->QuitWhenIdle();
359 return false; 359 return false;
360 } 360 }
361 // If we're coming from A, then add B, otherwise A. 361 // If we're coming from A, then add B, otherwise A.
362 if (connection->GetRemoteApplicationURL() == kTestAURLString) 362 if (connection->GetRemoteApplicationName() == kTestAURLString)
363 connection->AddInterface<TestB>(this); 363 connection->AddInterface<TestB>(this);
364 else 364 else
365 connection->AddInterface<TestA>(this); 365 connection->AddInterface<TestA>(this);
366 return true; 366 return true;
367 } 367 }
368 368
369 void Create(Connection* connection, 369 void Create(Connection* connection,
370 InterfaceRequest<TestA> request) override { 370 InterfaceRequest<TestA> request) override {
371 a_bindings_.push_back( 371 a_bindings_.push_back(
372 new TestAImpl(app_->connector(), context_, std::move(request), this)); 372 new TestAImpl(app_->connector(), context_, std::move(request), this));
373 } 373 }
374 374
375 void Create(Connection* connection, 375 void Create(Connection* connection,
376 InterfaceRequest<TestB> request) override { 376 InterfaceRequest<TestB> request) override {
377 new TestBImpl(connection, context_, std::move(request)); 377 new TestBImpl(connection, context_, std::move(request));
378 } 378 }
379 379
380 void Create(Connection* connection, 380 void Create(Connection* connection,
381 InterfaceRequest<TestC> request) override { 381 InterfaceRequest<TestC> request) override {
382 new TestCImpl(connection, context_, std::move(request)); 382 new TestCImpl(connection, context_, std::move(request));
383 } 383 }
384 384
385 TesterContext* context_; 385 TesterContext* context_;
386 scoped_ptr<ShellConnection> app_; 386 scoped_ptr<ShellConnection> app_;
387 std::string requestor_url_; 387 std::string requestor_name_;
388 ScopedVector<TestAImpl> a_bindings_; 388 ScopedVector<TestAImpl> a_bindings_;
389 }; 389 };
390 390
391 void OnConnect(base::RunLoop* loop, uint32_t instance_id) { 391 void OnConnect(base::RunLoop* loop, uint32_t instance_id) {
392 loop->Quit(); 392 loop->Quit();
393 } 393 }
394 394
395 class ApplicationManagerTest : public testing::Test { 395 class ApplicationManagerTest : public testing::Test {
396 public: 396 public:
397 ApplicationManagerTest() : tester_context_(&loop_) {} 397 ApplicationManagerTest() : tester_context_(&loop_) {}
398 398
399 ~ApplicationManagerTest() override {} 399 ~ApplicationManagerTest() override {}
400 400
401 void SetUp() override { 401 void SetUp() override {
402 application_manager_.reset( 402 application_manager_.reset(
403 new ApplicationManager(nullptr, nullptr, true, nullptr)); 403 new ApplicationManager(nullptr, nullptr, nullptr));
404 test_loader_ = new TestApplicationLoader(&context_); 404 test_loader_ = new TestApplicationLoader(&context_);
405 application_manager_->set_default_loader( 405 application_manager_->set_default_loader(
406 scoped_ptr<ApplicationLoader>(test_loader_)); 406 scoped_ptr<ApplicationLoader>(test_loader_));
407 407
408 TestServicePtr service_proxy; 408 TestServicePtr service_proxy;
409 ConnectToInterface(GURL(kTestURLString), &service_proxy); 409 ConnectToInterface(kTestURLString, &service_proxy);
410 test_client_.reset(new TestClient(std::move(service_proxy))); 410 test_client_.reset(new TestClient(std::move(service_proxy)));
411 } 411 }
412 412
413 void TearDown() override { 413 void TearDown() override {
414 test_client_.reset(); 414 test_client_.reset();
415 application_manager_.reset(); 415 application_manager_.reset();
416 } 416 }
417 417
418 void AddLoaderForURL(const GURL& url, const std::string& requestor_url) { 418 void AddLoaderForName(const std::string& name,
419 application_manager_->SetLoaderForURL( 419 const std::string& requestor_name) {
420 make_scoped_ptr(new Tester(&tester_context_, requestor_url)), url); 420 application_manager_->SetLoaderForName(
421 make_scoped_ptr(new Tester(&tester_context_, requestor_name)), name);
421 } 422 }
422 423
423 bool HasRunningInstanceForURL(const GURL& url) { 424 bool HasRunningInstanceForName(const std::string& name) {
424 ApplicationManager::TestAPI manager_test_api(application_manager_.get()); 425 ApplicationManager::TestAPI manager_test_api(application_manager_.get());
425 return manager_test_api.HasRunningInstanceForURL(url); 426 return manager_test_api.HasRunningInstanceForName(name);
426 } 427 }
427 428
428 protected: 429 protected:
429 template <typename Interface> 430 template <typename Interface>
430 void ConnectToInterface(const GURL& url, InterfacePtr<Interface>* ptr) { 431 void ConnectToInterface(const std::string& name,
432 InterfacePtr<Interface>* ptr) {
431 base::RunLoop loop; 433 base::RunLoop loop;
432 mojom::InterfaceProviderPtr remote_interfaces; 434 mojom::InterfaceProviderPtr remote_interfaces;
433 scoped_ptr<ConnectParams> params(new ConnectParams); 435 scoped_ptr<ConnectParams> params(new ConnectParams);
434 params->set_source(CreateShellIdentity()); 436 params->set_source(CreateShellIdentity());
435 params->set_target(Identity(url)); 437 params->set_target(Identity(name));
436 params->set_remote_interfaces(GetProxy(&remote_interfaces)); 438 params->set_remote_interfaces(GetProxy(&remote_interfaces));
437 params->set_connect_callback( 439 params->set_connect_callback(
438 base::Bind(&OnConnect, base::Unretained(&loop))); 440 base::Bind(&OnConnect, base::Unretained(&loop)));
439 application_manager_->Connect(std::move(params)); 441 application_manager_->Connect(std::move(params));
440 loop.Run(); 442 loop.Run();
441 443
442 mojo::GetInterface(remote_interfaces.get(), ptr); 444 mojo::GetInterface(remote_interfaces.get(), ptr);
443 } 445 }
444 446
445 base::ShadowingAtExitManager at_exit_; 447 base::ShadowingAtExitManager at_exit_;
446 TestApplicationLoader* test_loader_; 448 TestApplicationLoader* test_loader_;
447 TesterContext tester_context_; 449 TesterContext tester_context_;
448 TestContext context_; 450 TestContext context_;
449 base::MessageLoop loop_; 451 base::MessageLoop loop_;
450 scoped_ptr<TestClient> test_client_; 452 scoped_ptr<TestClient> test_client_;
451 scoped_ptr<ApplicationManager> application_manager_; 453 scoped_ptr<ApplicationManager> application_manager_;
452 DISALLOW_COPY_AND_ASSIGN(ApplicationManagerTest); 454 DISALLOW_COPY_AND_ASSIGN(ApplicationManagerTest);
453 }; 455 };
454 456
455 TEST_F(ApplicationManagerTest, Basic) { 457 TEST_F(ApplicationManagerTest, Basic) {
456 test_client_->Test("test"); 458 test_client_->Test("test");
457 loop_.Run(); 459 loop_.Run();
458 EXPECT_EQ(std::string("test"), context_.last_test_string); 460 EXPECT_EQ(std::string("test"), context_.last_test_string);
459 } 461 }
460 462
461 TEST_F(ApplicationManagerTest, ClientError) { 463 TEST_F(ApplicationManagerTest, ClientError) {
462 test_client_->Test("test"); 464 test_client_->Test("test");
463 EXPECT_TRUE(HasRunningInstanceForURL(GURL(kTestURLString))); 465 EXPECT_TRUE(HasRunningInstanceForName(kTestURLString));
464 loop_.Run(); 466 loop_.Run();
465 EXPECT_EQ(1, context_.num_impls); 467 EXPECT_EQ(1, context_.num_impls);
466 test_client_.reset(); 468 test_client_.reset();
467 loop_.Run(); 469 loop_.Run();
468 EXPECT_EQ(0, context_.num_impls); 470 EXPECT_EQ(0, context_.num_impls);
469 EXPECT_TRUE(HasRunningInstanceForURL(GURL(kTestURLString))); 471 EXPECT_TRUE(HasRunningInstanceForName(kTestURLString));
470 } 472 }
471 473
472 TEST_F(ApplicationManagerTest, Deletes) { 474 TEST_F(ApplicationManagerTest, Deletes) {
473 { 475 {
474 ApplicationManager am(nullptr, nullptr, true, nullptr); 476 ApplicationManager am(nullptr, nullptr, nullptr);
475 TestApplicationLoader* default_loader = 477 TestApplicationLoader* default_loader =
476 new TestApplicationLoader(&context_); 478 new TestApplicationLoader(&context_);
477 TestApplicationLoader* url_loader1 = new TestApplicationLoader(&context_); 479 TestApplicationLoader* name_loader1 = new TestApplicationLoader(&context_);
478 TestApplicationLoader* url_loader2 = new TestApplicationLoader(&context_); 480 TestApplicationLoader* name_loader2 = new TestApplicationLoader(&context_);
479 am.set_default_loader(scoped_ptr<ApplicationLoader>(default_loader)); 481 am.set_default_loader(scoped_ptr<ApplicationLoader>(default_loader));
480 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(url_loader1), 482 am.SetLoaderForName(scoped_ptr<ApplicationLoader>(name_loader1),
481 GURL("test:test1")); 483 "test:test1");
482 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(url_loader2), 484 am.SetLoaderForName(scoped_ptr<ApplicationLoader>(name_loader2),
483 GURL("test:test1")); 485 "test:test1");
484 } 486 }
485 EXPECT_EQ(3, context_.num_loader_deletes); 487 EXPECT_EQ(3, context_.num_loader_deletes);
486 } 488 }
487 489
488 // Test for SetLoaderForURL() & set_default_loader(). 490 // Test for SetLoaderForName() & set_default_loader().
489 TEST_F(ApplicationManagerTest, SetLoaders) { 491 TEST_F(ApplicationManagerTest, SetLoaders) {
490 TestApplicationLoader* default_loader = new TestApplicationLoader(&context_); 492 TestApplicationLoader* default_loader = new TestApplicationLoader(&context_);
491 TestApplicationLoader* url_loader = new TestApplicationLoader(&context_); 493 TestApplicationLoader* name_loader = new TestApplicationLoader(&context_);
492 application_manager_->set_default_loader( 494 application_manager_->set_default_loader(
493 scoped_ptr<ApplicationLoader>(default_loader)); 495 scoped_ptr<ApplicationLoader>(default_loader));
494 application_manager_->SetLoaderForURL( 496 application_manager_->SetLoaderForName(
495 scoped_ptr<ApplicationLoader>(url_loader), GURL("test:test1")); 497 scoped_ptr<ApplicationLoader>(name_loader), "test:test1");
496 498
497 // test::test1 should go to url_loader. 499 // test::test1 should go to name_loader.
498 TestServicePtr test_service; 500 TestServicePtr test_service;
499 ConnectToInterface(GURL("test:test1"), &test_service); 501 ConnectToInterface("test:test1", &test_service);
500 EXPECT_EQ(1, url_loader->num_loads()); 502 EXPECT_EQ(1, name_loader->num_loads());
501 EXPECT_EQ(0, default_loader->num_loads()); 503 EXPECT_EQ(0, default_loader->num_loads());
502 504
503 // http::test1 should go to default loader. 505 // http::test1 should go to default loader.
504 ConnectToInterface(GURL("http:test1"), &test_service); 506 ConnectToInterface("http:test1", &test_service);
505 EXPECT_EQ(1, url_loader->num_loads()); 507 EXPECT_EQ(1, name_loader->num_loads());
506 EXPECT_EQ(1, default_loader->num_loads()); 508 EXPECT_EQ(1, default_loader->num_loads());
507 } 509 }
508 510
509 // Confirm that the url of a service is correctly passed to another service that 511 // Confirm that the name of a service is correctly passed to another service
510 // it loads. 512 // that it loads.
511 // TODO(beng): these tests are disabled due to the new async connect flow. 513 // TODO(beng): these tests are disabled due to the new async connect flow.
512 // they should be re-written as shell apptests. 514 // they should be re-written as shell apptests.
513 TEST_F(ApplicationManagerTest, DISABLED_ACallB) { 515 TEST_F(ApplicationManagerTest, DISABLED_ACallB) {
514 // Any url can load a. 516 // Any name can load a.
515 AddLoaderForURL(GURL(kTestAURLString), std::string()); 517 AddLoaderForName(kTestAURLString, std::string());
516 518
517 // Only a can load b. 519 // Only a can load b.
518 AddLoaderForURL(GURL(kTestBURLString), kTestAURLString); 520 AddLoaderForName(kTestBURLString, kTestAURLString);
519 521
520 TestAPtr a; 522 TestAPtr a;
521 ConnectToInterface(GURL(kTestAURLString), &a); 523 ConnectToInterface(kTestAURLString, &a);
522 a->CallB(); 524 a->CallB();
523 loop_.Run(); 525 loop_.Run();
524 EXPECT_EQ(1, tester_context_.num_b_calls()); 526 EXPECT_EQ(1, tester_context_.num_b_calls());
525 EXPECT_TRUE(tester_context_.a_called_quit()); 527 EXPECT_TRUE(tester_context_.a_called_quit());
526 } 528 }
527 529
528 // A calls B which calls C. 530 // A calls B which calls C.
529 TEST_F(ApplicationManagerTest, DISABLED_BCallC) { 531 TEST_F(ApplicationManagerTest, DISABLED_BCallC) {
530 // Any url can load a. 532 // Any name can load a.
531 AddLoaderForURL(GURL(kTestAURLString), std::string()); 533 AddLoaderForName(kTestAURLString, std::string());
532 534
533 // Only a can load b. 535 // Only a can load b.
534 AddLoaderForURL(GURL(kTestBURLString), kTestAURLString); 536 AddLoaderForName(kTestBURLString, kTestAURLString);
535 537
536 TestAPtr a; 538 TestAPtr a;
537 ConnectToInterface(GURL(kTestAURLString), &a); 539 ConnectToInterface(kTestAURLString, &a);
538 a->CallCFromB(); 540 a->CallCFromB();
539 loop_.Run(); 541 loop_.Run();
540 542
541 EXPECT_EQ(1, tester_context_.num_b_calls()); 543 EXPECT_EQ(1, tester_context_.num_b_calls());
542 EXPECT_EQ(1, tester_context_.num_c_calls()); 544 EXPECT_EQ(1, tester_context_.num_c_calls());
543 EXPECT_TRUE(tester_context_.a_called_quit()); 545 EXPECT_TRUE(tester_context_.a_called_quit());
544 } 546 }
545 547
546 // Confirm that a service impl will be deleted if the app that connected to 548 // Confirm that a service impl will be deleted if the app that connected to
547 // it goes away. 549 // it goes away.
548 TEST_F(ApplicationManagerTest, DISABLED_BDeleted) { 550 TEST_F(ApplicationManagerTest, DISABLED_BDeleted) {
549 AddLoaderForURL(GURL(kTestAURLString), std::string()); 551 AddLoaderForName(kTestAURLString, std::string());
550 AddLoaderForURL(GURL(kTestBURLString), std::string()); 552 AddLoaderForName(kTestBURLString, std::string());
551 553
552 TestAPtr a; 554 TestAPtr a;
553 ConnectToInterface(GURL(kTestAURLString), &a); 555 ConnectToInterface(kTestAURLString, &a);
554 556
555 a->CallB(); 557 a->CallB();
556 loop_.Run(); 558 loop_.Run();
557 559
558 // Kills the a app. 560 // Kills the a app.
559 application_manager_->SetLoaderForURL(scoped_ptr<ApplicationLoader>(), 561 application_manager_->SetLoaderForName(scoped_ptr<ApplicationLoader>(),
560 GURL(kTestAURLString)); 562 kTestAURLString);
561 loop_.Run(); 563 loop_.Run();
562 564
563 EXPECT_EQ(1, tester_context_.num_b_deletes()); 565 EXPECT_EQ(1, tester_context_.num_b_deletes());
564 } 566 }
565 567
566 // Confirm that the url of a service is correctly passed to another service that 568 // Confirm that the name of a service is correctly passed to another service
567 // it loads, and that it can be rejected. 569 // that it loads, and that it can be rejected.
568 TEST_F(ApplicationManagerTest, DISABLED_ANoLoadB) { 570 TEST_F(ApplicationManagerTest, DISABLED_ANoLoadB) {
569 // Any url can load a. 571 // Any name can load a.
570 AddLoaderForURL(GURL(kTestAURLString), std::string()); 572 AddLoaderForName(kTestAURLString, std::string());
571 573
572 // Only c can load b, so this will fail. 574 // Only c can load b, so this will fail.
573 AddLoaderForURL(GURL(kTestBURLString), "test:TestC"); 575 AddLoaderForName(kTestBURLString, "test:TestC");
574 576
575 TestAPtr a; 577 TestAPtr a;
576 ConnectToInterface(GURL(kTestAURLString), &a); 578 ConnectToInterface(kTestAURLString, &a);
577 a->CallB(); 579 a->CallB();
578 loop_.Run(); 580 loop_.Run();
579 EXPECT_EQ(0, tester_context_.num_b_calls()); 581 EXPECT_EQ(0, tester_context_.num_b_calls());
580 582
581 EXPECT_FALSE(tester_context_.a_called_quit()); 583 EXPECT_FALSE(tester_context_.a_called_quit());
582 EXPECT_TRUE(tester_context_.tester_called_quit()); 584 EXPECT_TRUE(tester_context_.tester_called_quit());
583 } 585 }
584 586
585 TEST_F(ApplicationManagerTest, NoServiceNoLoad) { 587 TEST_F(ApplicationManagerTest, NoServiceNoLoad) {
586 AddLoaderForURL(GURL(kTestAURLString), std::string()); 588 AddLoaderForName(kTestAURLString, std::string());
587 589
588 // There is no TestC service implementation registered with 590 // There is no TestC service implementation registered with
589 // ApplicationManager, so this cannot succeed (but also shouldn't crash). 591 // ApplicationManager, so this cannot succeed (but also shouldn't crash).
590 TestCPtr c; 592 TestCPtr c;
591 ConnectToInterface(GURL(kTestAURLString), &c); 593 ConnectToInterface(kTestAURLString, &c);
592 c.set_connection_error_handler( 594 c.set_connection_error_handler(
593 []() { base::MessageLoop::current()->QuitWhenIdle(); }); 595 []() { base::MessageLoop::current()->QuitWhenIdle(); });
594 596
595 loop_.Run(); 597 loop_.Run();
596 EXPECT_TRUE(c.encountered_error()); 598 EXPECT_TRUE(c.encountered_error());
597 } 599 }
598 600
599 TEST_F(ApplicationManagerTest, TestEndApplicationClosure) { 601 TEST_F(ApplicationManagerTest, TestEndApplicationClosure) {
600 ClosingApplicationLoader* loader = new ClosingApplicationLoader(); 602 ClosingApplicationLoader* loader = new ClosingApplicationLoader();
601 application_manager_->SetLoaderForURL( 603 application_manager_->SetLoaderForName(
602 scoped_ptr<ApplicationLoader>(loader), GURL("test:test")); 604 scoped_ptr<ApplicationLoader>(loader), "test:test");
603 605
604 bool called = false; 606 bool called = false;
605 scoped_ptr<ConnectParams> params(new ConnectParams); 607 scoped_ptr<ConnectParams> params(new ConnectParams);
606 params->set_source(CreateShellIdentity()); 608 params->set_source(CreateShellIdentity());
607 params->set_target( 609 params->set_target(Identity("test:test", "", mojom::Connector::kUserRoot));
608 Identity(GURL("test:test"), "", mojom::Connector::kUserRoot));
609 application_manager_->SetInstanceQuitCallback( 610 application_manager_->SetInstanceQuitCallback(
610 base::Bind(&QuitClosure, params->target(), &called)); 611 base::Bind(&QuitClosure, params->target(), &called));
611 application_manager_->Connect(std::move(params)); 612 application_manager_->Connect(std::move(params));
612 loop_.Run(); 613 loop_.Run();
613 EXPECT_TRUE(called); 614 EXPECT_TRUE(called);
614 } 615 }
615 616
616 TEST_F(ApplicationManagerTest, SameIdentityShouldNotCauseDuplicateLoad) { 617 TEST_F(ApplicationManagerTest, SameIdentityShouldNotCauseDuplicateLoad) {
617 // 1 because ApplicationManagerTest connects once at startup. 618 // 1 because ApplicationManagerTest connects once at startup.
618 EXPECT_EQ(1, test_loader_->num_loads()); 619 EXPECT_EQ(1, test_loader_->num_loads());
619 620
620 TestServicePtr test_service; 621 TestServicePtr test_service;
621 ConnectToInterface(GURL("test:foo"), &test_service); 622 ConnectToInterface("test:foo", &test_service);
622 EXPECT_EQ(2, test_loader_->num_loads()); 623 EXPECT_EQ(2, test_loader_->num_loads());
623 624
624 // Exactly the same URL as above. 625 // Exactly the same name as above.
625 ConnectToInterface(GURL("test:foo"), &test_service); 626 ConnectToInterface("test:foo", &test_service);
626 EXPECT_EQ(2, test_loader_->num_loads()); 627 EXPECT_EQ(2, test_loader_->num_loads());
627 628
628 // A different identity because the domain is different. 629 // A different identity because the domain is different.
629 ConnectToInterface(GURL("test:bar"), &test_service); 630 ConnectToInterface("test:bar", &test_service);
630 EXPECT_EQ(3, test_loader_->num_loads()); 631 EXPECT_EQ(3, test_loader_->num_loads());
631 } 632 }
632 633
633 } // namespace test 634 } // namespace test
634 } // namespace shell 635 } // namespace shell
635 } // namespace mojo 636 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698