Aggregate parameters through mappings.

This will allow to do something like:
- Pass generic parameters to mojo:window_manager
- Pass specific parameters to the final implementation

It will also ensure that when mappings are present, the arguments an
application receive do not depend on the URL used to connect to it the first
time.

This is a reland of https://codereview.chromium.org/1025603004 fixing the
android tests. The arguments were not taken into account because settings
arguments must happen after the context is initialized.

TBR=davemoore@chromium.org

Review URL: https://codereview.chromium.org/1026293002
diff --git a/shell/application_manager/application_manager_unittest.cc b/shell/application_manager/application_manager_unittest.cc
index 1683ab8..19edcff 100644
--- a/shell/application_manager/application_manager_unittest.cc
+++ b/shell/application_manager/application_manager_unittest.cc
@@ -527,6 +527,53 @@
   EXPECT_EQ(args[1], app_args[1]);
 }
 
+// Confirm that arguments are aggregated through mappings.
+TEST_F(ApplicationManagerTest, ArgsAndMapping) {
+  ApplicationManager am(&test_delegate_);
+  GURL test_url("test:test");
+  GURL test_url2("test:test2");
+  test_delegate_.AddMapping(test_url, test_url2);
+  std::vector<std::string> args;
+  args.push_back("test_arg1");
+  args.push_back("test_arg2");
+  am.SetArgsForURL(args, test_url);
+  std::vector<std::string> args2;
+  args2.push_back("test_arg3");
+  args2.push_back("test_arg4");
+  am.SetArgsForURL(args2, test_url2);
+  TestApplicationLoader* loader = new TestApplicationLoader;
+  loader->set_context(&context_);
+  am.SetLoaderForURL(scoped_ptr<ApplicationLoader>(loader), test_url2);
+  {
+    // Connext to the mapped url
+    TestServicePtr test_service;
+    am.ConnectToService(test_url, &test_service);
+    TestClient test_client(test_service.Pass());
+    test_client.Test("test");
+    loop_.Run();
+    std::vector<std::string> app_args = loader->GetArgs();
+    ASSERT_EQ(args.size() + args2.size(), app_args.size());
+    EXPECT_EQ(args[0], app_args[0]);
+    EXPECT_EQ(args[1], app_args[1]);
+    EXPECT_EQ(args2[0], app_args[2]);
+    EXPECT_EQ(args2[1], app_args[3]);
+  }
+  {
+    // Connext to the target url
+    TestServicePtr test_service;
+    am.ConnectToService(test_url2, &test_service);
+    TestClient test_client(test_service.Pass());
+    test_client.Test("test");
+    loop_.Run();
+    std::vector<std::string> app_args = loader->GetArgs();
+    ASSERT_EQ(args.size() + args2.size(), app_args.size());
+    EXPECT_EQ(args[0], app_args[0]);
+    EXPECT_EQ(args[1], app_args[1]);
+    EXPECT_EQ(args2[0], app_args[2]);
+    EXPECT_EQ(args2[1], app_args[3]);
+  }
+}
+
 TEST_F(ApplicationManagerTest, ClientError) {
   test_client_->Test("test");
   EXPECT_TRUE(HasFactoryForTestURL());