diff options
-rw-r--r-- | mojo/shell/application_manager/application_manager_unittest.cc | 27 | ||||
-rw-r--r-- | mojo/shell/context.cc | 17 | ||||
-rw-r--r-- | mojo/shell/switches.cc | 6 | ||||
-rw-r--r-- | mojo/shell/switches.h | 1 |
4 files changed, 51 insertions, 0 deletions
diff --git a/mojo/shell/application_manager/application_manager_unittest.cc b/mojo/shell/application_manager/application_manager_unittest.cc index cc420a7..f801e36 100644 --- a/mojo/shell/application_manager/application_manager_unittest.cc +++ b/mojo/shell/application_manager/application_manager_unittest.cc @@ -487,6 +487,33 @@ TEST_F(ApplicationManagerTest, NoArgs) { EXPECT_EQ(0U, app_args.size()); } +// Confirm that url mappings are respected. +TEST_F(ApplicationManagerTest, URLMapping) { + ApplicationManager am(&test_delegate_); + GURL test_url("test:test"); + GURL test_url2("test:test2"); + test_delegate_.AddMapping(test_url, 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(); + } + { + // 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(); + } +} + TEST_F(ApplicationManagerTest, ClientError) { test_client_->Test("test"); EXPECT_TRUE(HasFactoryForTestURL()); diff --git a/mojo/shell/context.cc b/mojo/shell/context.cc index fc56476..0cc27d1 100644 --- a/mojo/shell/context.cc +++ b/mojo/shell/context.cc @@ -84,6 +84,23 @@ bool ConfigureURLMappings(const base::CommandLine& command_line, resolver->AddOriginMapping(GURL(origin_mapping.origin), GURL(origin_mapping.base_url)); + if (command_line.HasSwitch(switches::kURLMappings)) { + const std::string mappings = + command_line.GetSwitchValueASCII(switches::kURLMappings); + + base::StringPairs pairs; + if (!base::SplitStringIntoKeyValuePairs(mappings, '=', ',', &pairs)) + return false; + using StringPair = std::pair<std::string, std::string>; + for (const StringPair& pair : pairs) { + const GURL from(pair.first); + const GURL to = context->ResolveCommandLineURL(pair.second); + if (!from.is_valid() || !to.is_valid()) + return false; + resolver->AddURLMapping(from, to); + } + } + return true; } diff --git a/mojo/shell/switches.cc b/mojo/shell/switches.cc index 28e7d05..1fff40d 100644 --- a/mojo/shell/switches.cc +++ b/mojo/shell/switches.cc @@ -55,4 +55,10 @@ const char kPredictableAppFilenames[] = "predictable-app-filenames"; // seconds or when the shell exits. const char kTraceStartup[] = "trace-startup"; +// Specifies a set of mappings to apply when resolving urls. The value is a set +// of ',' separated mappings, where each mapping consists of a pair of urls +// giving the to/from url to map. For example, 'a=b,c=d' contains two mappings, +// the first maps 'a' to 'b' and the second 'c' to 'd'. +const char kURLMappings[] = "url-mappings"; + } // namespace switches diff --git a/mojo/shell/switches.h b/mojo/shell/switches.h index ff2eb6c..31cac8f 100644 --- a/mojo/shell/switches.h +++ b/mojo/shell/switches.h @@ -23,6 +23,7 @@ extern const char kMapOrigin[]; extern const char kOrigin[]; extern const char kPredictableAppFilenames[]; extern const char kTraceStartup[]; +extern const char kURLMappings[]; } // namespace switches |