Index: mojo/runner/url_resolver_unittest.cc |
diff --git a/mojo/runner/url_resolver_unittest.cc b/mojo/runner/url_resolver_unittest.cc |
index 5862b51c46466c32053a73601b35d1d1e30c8457..26a67f210402a27a7f2f9cd5cca3661e1e108e0e 100644 |
--- a/mojo/runner/url_resolver_unittest.cc |
+++ b/mojo/runner/url_resolver_unittest.cc |
@@ -4,7 +4,10 @@ |
#include "mojo/runner/url_resolver.h" |
+#include "base/files/file_util.h" |
+#include "base/files/scoped_temp_dir.h" |
#include "base/logging.h" |
+#include "mojo/util/filename_util.h" |
#include "testing/gtest/include/gtest/gtest.h" |
namespace mojo { |
@@ -144,6 +147,27 @@ TEST_F(URLResolverTest, TestQueryForBaseURL) { |
EXPECT_EQ("file:///base/foo.mojo?a=b", mapped_url.spec()); |
} |
+// Verifies that ResolveMojoURL prefers the directory with the name of the host |
+// over the raw file. |
+TEST_F(URLResolverTest, PreferDirectory) { |
+ base::ScopedTempDir tmp_dir; |
+ ASSERT_TRUE(tmp_dir.CreateUniqueTempDir()); |
+ URLResolver resolver; |
+ // With no directory |mojo:foo| maps to path/foo.mojo. |
+ resolver.SetMojoBaseURL(util::FilePathToFileURL(tmp_dir.path())); |
+ const GURL mapped_url = resolver.ResolveMojoURL(GURL("mojo:foo")); |
+ EXPECT_EQ(util::FilePathToFileURL(tmp_dir.path()).spec() + "/foo.mojo", |
+ mapped_url.spec()); |
+ |
+ // With a directory |mojo:foo| maps to path/foo/foo.mojo. |
+ const base::FilePath foo_file_path( |
+ tmp_dir.path().Append(FILE_PATH_LITERAL("foo"))); |
+ ASSERT_TRUE(base::CreateDirectory(foo_file_path)); |
+ const GURL mapped_url_with_dir = resolver.ResolveMojoURL(GURL("mojo:foo")); |
+ EXPECT_EQ(util::FilePathToFileURL(tmp_dir.path()).spec() + "/foo/foo.mojo", |
+ mapped_url_with_dir.spec()); |
+} |
+ |
} // namespace |
} // namespace test |
} // namespace shell |