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

Side by Side Diff: mojo/runner/url_resolver_unittest.cc

Issue 1343823002: Revert of Move fetching logic out of ApplicationManager, eliminate url mappings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months 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 | « mojo/runner/url_resolver.cc ('k') | mojo/shell/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "mojo/runner/url_resolver.h"
6
7 #include "base/files/file_util.h"
8 #include "base/files/scoped_temp_dir.h"
9 #include "base/logging.h"
10 #include "mojo/util/filename_util.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace mojo {
14 namespace runner {
15 namespace test {
16 namespace {
17
18 typedef testing::Test URLResolverTest;
19
20 TEST_F(URLResolverTest, MojoURLsFallThrough) {
21 URLResolver resolver;
22 resolver.AddURLMapping(GURL("mojo:test"), GURL("mojo:foo"));
23 const GURL base_url("file:/base");
24 resolver.SetMojoBaseURL(base_url);
25 GURL mapped_url = resolver.ApplyMappings(GURL("mojo:test"));
26 std::string resolved(resolver.ResolveMojoURL(mapped_url).spec());
27 // Resolved must start with |base_url|.
28 EXPECT_EQ(base_url.spec(), resolved.substr(0, base_url.spec().size()));
29 // And must contain foo.
30 EXPECT_NE(std::string::npos, resolved.find("foo"));
31 }
32
33 TEST_F(URLResolverTest, MapURL) {
34 URLResolver resolver;
35 resolver.AddURLMapping(GURL("https://domokit.org/test.mojo"),
36 GURL("file:///mojo/src/out/Debug/test.mojo"));
37 GURL mapped_url =
38 resolver.ApplyMappings(GURL("https://domokit.org/test.mojo"));
39 EXPECT_EQ("file:///mojo/src/out/Debug/test.mojo", mapped_url.spec());
40 }
41
42 TEST_F(URLResolverTest, MultipleMapURL) {
43 URLResolver resolver;
44 resolver.AddURLMapping(GURL("https://a.org/foo"),
45 GURL("https://b.org/a/foo"));
46 resolver.AddURLMapping(GURL("https://b.org/a/foo"),
47 GURL("https://c.org/b/a/foo"));
48 GURL mapped_url = resolver.ApplyMappings(GURL("https://a.org/foo"));
49 EXPECT_EQ("https://c.org/b/a/foo", mapped_url.spec());
50 }
51
52 TEST_F(URLResolverTest, MapOrigin) {
53 URLResolver resolver;
54 resolver.AddOriginMapping(GURL("https://domokit.org"),
55 GURL("file:///mojo/src/out/Debug"));
56 GURL mapped_url =
57 resolver.ApplyMappings(GURL("https://domokit.org/test.mojo"));
58 EXPECT_EQ("file:///mojo/src/out/Debug/test.mojo", mapped_url.spec());
59 }
60
61 TEST_F(URLResolverTest, MultipleMapOrigin) {
62 URLResolver resolver;
63 resolver.AddOriginMapping(GURL("https://a.org"), GURL("https://b.org/a"));
64 resolver.AddOriginMapping(GURL("https://b.org"), GURL("https://c.org/b"));
65 GURL mapped_url = resolver.ApplyMappings(GURL("https://a.org/foo"));
66 EXPECT_EQ("https://c.org/b/a/foo", mapped_url.spec());
67 }
68
69 TEST_F(URLResolverTest, MapOriginThenURL) {
70 URLResolver resolver;
71 resolver.AddOriginMapping(GURL("https://a.org"), GURL("https://b.org/a"));
72 resolver.AddURLMapping(GURL("https://b.org/a/foo"),
73 GURL("https://c.org/b/a/foo"));
74 GURL mapped_url = resolver.ApplyMappings(GURL("https://a.org/foo"));
75 EXPECT_EQ("https://c.org/b/a/foo", mapped_url.spec());
76 }
77
78 TEST_F(URLResolverTest, MapURLThenOrigin) {
79 URLResolver resolver;
80 resolver.AddURLMapping(GURL("https://a.org/foo"),
81 GURL("https://b.org/a/foo"));
82 resolver.AddOriginMapping(GURL("https://b.org"), GURL("https://c.org/b"));
83 GURL mapped_url = resolver.ApplyMappings(GURL("https://a.org/foo"));
84 EXPECT_EQ("https://c.org/b/a/foo", mapped_url.spec());
85 }
86
87 #if defined(OS_POSIX)
88 #define ARG_LITERAL(x) x
89 #elif defined(OS_WIN)
90 #define ARG_LITERAL(x) L ## x
91 #endif
92
93 TEST_F(URLResolverTest, GetOriginMappings) {
94 base::CommandLine::StringVector args;
95 args.push_back(ARG_LITERAL("--map-origin=https://a.org=https://b.org/a"));
96 std::vector<URLResolver::OriginMapping> mappings =
97 URLResolver::GetOriginMappings(args);
98 ASSERT_EQ(1U, mappings.size());
99 EXPECT_EQ("https://a.org", mappings[0].origin);
100 EXPECT_EQ("https://b.org/a", mappings[0].base_url);
101
102 args.clear();
103 args.push_back(ARG_LITERAL("-map-origin=https://a.org=https://b.org/a"));
104 mappings = URLResolver::GetOriginMappings(args);
105 ASSERT_EQ(1U, mappings.size());
106 EXPECT_EQ("https://a.org", mappings[0].origin);
107 EXPECT_EQ("https://b.org/a", mappings[0].base_url);
108
109 args.clear();
110 args.push_back(ARG_LITERAL("--map-origin"));
111 mappings = URLResolver::GetOriginMappings(args);
112 EXPECT_EQ(0U, mappings.size());
113
114 args.clear();
115 args.push_back(ARG_LITERAL("--map-origin="));
116 mappings = URLResolver::GetOriginMappings(args);
117 EXPECT_EQ(0U, mappings.size());
118
119 args.clear();
120 args.push_back(ARG_LITERAL("mojo_shell"));
121 args.push_back(ARG_LITERAL("--map-origin=https://a.org=https://b.org/a"));
122 args.push_back(ARG_LITERAL("--map-origin=https://b.org=https://c.org/b"));
123 args.push_back(ARG_LITERAL("https://a.org/foo"));
124 mappings = URLResolver::GetOriginMappings(args);
125 ASSERT_EQ(2U, mappings.size());
126 EXPECT_EQ("https://a.org", mappings[0].origin);
127 EXPECT_EQ("https://b.org/a", mappings[0].base_url);
128 EXPECT_EQ("https://b.org", mappings[1].origin);
129 EXPECT_EQ("https://c.org/b", mappings[1].base_url);
130 }
131
132 TEST_F(URLResolverTest, TestQueryForURLMapping) {
133 URLResolver resolver;
134 resolver.SetMojoBaseURL(GURL("file:/base"));
135 resolver.AddURLMapping(GURL("https://a.org/foo"),
136 GURL("https://b.org/a/foo"));
137 resolver.AddURLMapping(GURL("https://b.org/a/foo"),
138 GURL("https://c.org/b/a/foo"));
139 GURL mapped_url = resolver.ApplyMappings(GURL("https://a.org/foo?a=b"));
140 EXPECT_EQ("https://c.org/b/a/foo?a=b", mapped_url.spec());
141 }
142
143 TEST_F(URLResolverTest, TestQueryForBaseFileURL) {
144 URLResolver resolver;
145 resolver.SetMojoBaseURL(GURL("file:///base"));
146 GURL mapped_url = resolver.ResolveMojoURL(GURL("mojo:foo?a=b"));
147 EXPECT_EQ("file:///base/foo/foo.mojo?a=b", mapped_url.spec());
148 }
149
150 TEST_F(URLResolverTest, TestQueryForBaseHttpURL) {
151 URLResolver resolver;
152 resolver.SetMojoBaseURL(GURL("http://127.0.0.1:1234"));
153 GURL mapped_url = resolver.ResolveMojoURL(GURL("mojo:foo?a=b"));
154 EXPECT_EQ("http://127.0.0.1:1234/foo/foo.mojo?a=b", mapped_url.spec());
155 }
156
157 } // namespace
158 } // namespace test
159 } // namespace runner
160 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/runner/url_resolver.cc ('k') | mojo/shell/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698