summaryrefslogtreecommitdiffstats
path: root/mojo
diff options
context:
space:
mode:
authormsw <msw@chromium.org>2015-04-21 17:50:02 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-22 00:51:07 +0000
commit9c69b8b227e605832c50911e01d1613ee6e37335 (patch)
treeefab14790a11cbf128aef0af95024733cda51f3a /mojo
parentf0b36803fc0c9789bec4b1ff0a4b242d84e39f06 (diff)
downloadchromium_src-9c69b8b227e605832c50911e01d1613ee6e37335.zip
chromium_src-9c69b8b227e605832c50911e01d1613ee6e37335.tar.gz
chromium_src-9c69b8b227e605832c50911e01d1613ee6e37335.tar.bz2
Restore --url-mappings switch for Mojo apptests.
Revert a portion of https://codereview.chromium.org/1057603003 This is needed to mock out dependencies for apptests. (blocking view_manager_apptests from passing) We are unable to specify mappings in code for now. (would need a Shell interface function or similar) TODO: Add a minimal test of --url-mappings behavior. BUG=NONE TEST=mojo_shell respects the --url-mappings switch. R=jam@chromium.org TBR=sky@chromium.org Review URL: https://codereview.chromium.org/1099923003 Cr-Commit-Position: refs/heads/master@{#326198}
Diffstat (limited to 'mojo')
-rw-r--r--mojo/shell/application_manager/application_manager_unittest.cc27
-rw-r--r--mojo/shell/context.cc17
-rw-r--r--mojo/shell/switches.cc6
-rw-r--r--mojo/shell/switches.h1
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