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

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

Issue 1467263002: Fix URL duplication when SetArgsForURL is called mutliple times. (Closed) Base URL: https://github.com/domokit/mojo.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
« no previous file with comments | « shell/application_manager/application_manager.cc ('k') | shell/command_line_util.cc » ('j') | 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/memory/scoped_vector.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "mojo/public/cpp/application/application_connection.h" 10 #include "mojo/public/cpp/application/application_connection.h"
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 am.SetArgsForURL(args, test_url); 515 am.SetArgsForURL(args, test_url);
516 TestApplicationLoader* loader = new TestApplicationLoader; 516 TestApplicationLoader* loader = new TestApplicationLoader;
517 loader->set_context(&context_); 517 loader->set_context(&context_);
518 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(loader), test_url); 518 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(loader), test_url);
519 TestServicePtr test_service; 519 TestServicePtr test_service;
520 am.ConnectToService(test_url, &test_service); 520 am.ConnectToService(test_url, &test_service);
521 TestClient test_client(test_service.Pass()); 521 TestClient test_client(test_service.Pass());
522 test_client.Test("test"); 522 test_client.Test("test");
523 loop_.Run(); 523 loop_.Run();
524 std::vector<std::string> app_args = loader->GetArgs(); 524 std::vector<std::string> app_args = loader->GetArgs();
525 ASSERT_EQ(args.size(), app_args.size()); 525 ASSERT_EQ(args.size() + 1, app_args.size());
526 EXPECT_EQ(args[0], app_args[0]); 526 EXPECT_EQ(args[0], app_args[1]);
527 EXPECT_EQ(args[1], app_args[1]); 527 EXPECT_EQ(args[1], app_args[2]);
528 } 528 }
529 529
530 // Confirm that arguments are sent to an application in the presence of query 530 // Confirm that arguments are sent to an application in the presence of query
531 // parameters. 531 // parameters.
532 TEST_F(ApplicationManagerTest, ArgsWithQuery) { 532 TEST_F(ApplicationManagerTest, ArgsWithQuery) {
533 ApplicationManager am(ApplicationManager::Options(), &test_delegate_); 533 ApplicationManager am(ApplicationManager::Options(), &test_delegate_);
534 GURL test_url("test:test"); 534 GURL test_url("test:test");
535 GURL test_url_with_query("test:test?foo=bar"); 535 GURL test_url_with_query("test:test?foo=bar");
536 std::vector<std::string> args; 536 std::vector<std::string> args;
537 args.push_back("test_arg1"); 537 args.push_back("test_arg1");
538 am.SetArgsForURL(args, test_url); 538 am.SetArgsForURL(args, test_url);
539 TestApplicationLoader* loader = new TestApplicationLoader; 539 TestApplicationLoader* loader = new TestApplicationLoader;
540 loader->set_context(&context_); 540 loader->set_context(&context_);
541 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(loader), test_url); 541 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(loader), test_url);
542 TestServicePtr test_service; 542 TestServicePtr test_service;
543 am.ConnectToService(test_url_with_query, &test_service); 543 am.ConnectToService(test_url_with_query, &test_service);
544 TestClient test_client(test_service.Pass()); 544 TestClient test_client(test_service.Pass());
545 test_client.Test("test"); 545 test_client.Test("test");
546 loop_.Run(); 546 loop_.Run();
547 std::vector<std::string> app_args = loader->GetArgs(); 547 std::vector<std::string> app_args = loader->GetArgs();
548 ASSERT_EQ(args.size(), app_args.size()); 548 ASSERT_EQ(args.size() + 1, app_args.size());
549 EXPECT_EQ(args[0], app_args[0]); 549 EXPECT_EQ(args[0], app_args[1]);
550 }
551
552 // Confirm that the URL is not duplicated when arguments are added in multiple
553 // phase.
ppi 2015/11/23 15:02:44 phases
qsr 2015/11/23 17:18:00 Done.
554 TEST_F(ApplicationManagerTest, ArgsMultipleCalls) {
555 ApplicationManager am(ApplicationManager::Options(), &test_delegate_);
556 GURL test_url("test:test");
557 std::vector<std::string> args1;
558 args1.push_back("test_arg1");
559 am.SetArgsForURL(args1, test_url);
560 std::vector<std::string> args2;
561 args2.push_back("test_arg2");
562 am.SetArgsForURL(args2, test_url);
563 TestApplicationLoader* loader = new TestApplicationLoader;
564 loader->set_context(&context_);
565 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(loader), test_url);
566 TestServicePtr test_service;
567 am.ConnectToService(test_url, &test_service);
568 TestClient test_client(test_service.Pass());
569 test_client.Test("test");
570 loop_.Run();
571 std::vector<std::string> app_args = loader->GetArgs();
572 ASSERT_EQ(args1.size() + args2.size() + 1, app_args.size());
573 EXPECT_EQ(args1[0], app_args[1]);
574 EXPECT_EQ(args2[0], app_args[2]);
550 } 575 }
551 576
552 // Confirm that arguments are aggregated through mappings. 577 // Confirm that arguments are aggregated through mappings.
553 TEST_F(ApplicationManagerTest, ArgsAndMapping) { 578 TEST_F(ApplicationManagerTest, ArgsAndMapping) {
554 ApplicationManager am(ApplicationManager::Options(), &test_delegate_); 579 ApplicationManager am(ApplicationManager::Options(), &test_delegate_);
555 GURL test_url("test:test"); 580 GURL test_url("test:test");
556 GURL test_url2("test:test2"); 581 GURL test_url2("test:test2");
557 test_delegate_.AddMapping(test_url, test_url2); 582 test_delegate_.AddMapping(test_url, test_url2);
558 std::vector<std::string> args; 583 std::vector<std::string> args;
559 args.push_back("test_arg1"); 584 args.push_back("test_arg1");
560 args.push_back("test_arg2"); 585 args.push_back("test_arg2");
561 am.SetArgsForURL(args, test_url); 586 am.SetArgsForURL(args, test_url);
562 std::vector<std::string> args2; 587 std::vector<std::string> args2;
563 args2.push_back("test_arg3"); 588 args2.push_back("test_arg3");
564 args2.push_back("test_arg4"); 589 args2.push_back("test_arg4");
565 am.SetArgsForURL(args2, test_url2); 590 am.SetArgsForURL(args2, test_url2);
566 TestApplicationLoader* loader = new TestApplicationLoader; 591 TestApplicationLoader* loader = new TestApplicationLoader;
567 loader->set_context(&context_); 592 loader->set_context(&context_);
568 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(loader), test_url2); 593 am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(loader), test_url2);
569 { 594 {
570 // Connext to the mapped url 595 // Connext to the mapped url
571 TestServicePtr test_service; 596 TestServicePtr test_service;
572 am.ConnectToService(test_url, &test_service); 597 am.ConnectToService(test_url, &test_service);
573 TestClient test_client(test_service.Pass()); 598 TestClient test_client(test_service.Pass());
574 test_client.Test("test"); 599 test_client.Test("test");
575 loop_.Run(); 600 loop_.Run();
576 std::vector<std::string> app_args = loader->GetArgs(); 601 std::vector<std::string> app_args = loader->GetArgs();
577 ASSERT_EQ(args.size() + args2.size(), app_args.size()); 602 ASSERT_EQ(args.size() + args2.size() + 1, app_args.size());
578 EXPECT_EQ(args[0], app_args[0]); 603 EXPECT_EQ(args[0], app_args[1]);
579 EXPECT_EQ(args[1], app_args[1]); 604 EXPECT_EQ(args[1], app_args[2]);
580 EXPECT_EQ(args2[0], app_args[2]); 605 EXPECT_EQ(args2[0], app_args[3]);
581 EXPECT_EQ(args2[1], app_args[3]); 606 EXPECT_EQ(args2[1], app_args[4]);
582 } 607 }
583 { 608 {
584 // Connext to the target url 609 // Connext to the target url
585 TestServicePtr test_service; 610 TestServicePtr test_service;
586 am.ConnectToService(test_url2, &test_service); 611 am.ConnectToService(test_url2, &test_service);
587 TestClient test_client(test_service.Pass()); 612 TestClient test_client(test_service.Pass());
588 test_client.Test("test"); 613 test_client.Test("test");
589 loop_.Run(); 614 loop_.Run();
590 std::vector<std::string> app_args = loader->GetArgs(); 615 std::vector<std::string> app_args = loader->GetArgs();
591 ASSERT_EQ(args.size() + args2.size(), app_args.size()); 616 ASSERT_EQ(args.size() + args2.size() + 1, app_args.size());
592 EXPECT_EQ(args[0], app_args[0]); 617 EXPECT_EQ(args[0], app_args[1]);
593 EXPECT_EQ(args[1], app_args[1]); 618 EXPECT_EQ(args[1], app_args[2]);
594 EXPECT_EQ(args2[0], app_args[2]); 619 EXPECT_EQ(args2[0], app_args[3]);
595 EXPECT_EQ(args2[1], app_args[3]); 620 EXPECT_EQ(args2[1], app_args[4]);
596 } 621 }
597 } 622 }
598 623
599 TEST_F(ApplicationManagerTest, ClientError) { 624 TEST_F(ApplicationManagerTest, ClientError) {
600 test_client_->Test("test"); 625 test_client_->Test("test");
601 EXPECT_TRUE(HasFactoryForTestURL()); 626 EXPECT_TRUE(HasFactoryForTestURL());
602 loop_.Run(); 627 loop_.Run();
603 EXPECT_EQ(1, context_.num_impls); 628 EXPECT_EQ(1, context_.num_impls);
604 test_client_.reset(); 629 test_client_.reset();
605 loop_.Run(); 630 loop_.Run();
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 bool called = false; 840 bool called = false;
816 application_manager_->ConnectToApplication( 841 application_manager_->ConnectToApplication(
817 GURL("test:test"), GURL(), nullptr, nullptr, 842 GURL("test:test"), GURL(), nullptr, nullptr,
818 base::Bind(&QuitClosure, base::Unretained(&called))); 843 base::Bind(&QuitClosure, base::Unretained(&called)));
819 loop_.Run(); 844 loop_.Run();
820 EXPECT_TRUE(called); 845 EXPECT_TRUE(called);
821 } 846 }
822 847
823 } // namespace 848 } // namespace
824 } // namespace shell 849 } // namespace shell
OLDNEW
« no previous file with comments | « shell/application_manager/application_manager.cc ('k') | shell/command_line_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698