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

Side by Side Diff: ios/chrome/common/x_callback_url_unittest.cc

Issue 2485573003: Functions to create and manipulate x-callback-url URLs. (Closed)
Patch Set: Address comments Created 4 years, 1 month 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 | « ios/chrome/common/x_callback_url.cc ('k') | no next file » | 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 2016 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 "ios/chrome/common/x_callback_url.h"
6
7 #include "base/strings/stringprintf.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace {
11
12 struct XCallbackURLEncodeTestCase {
13 const char* scheme;
14 const char* action;
15 GURL success_url;
16 GURL error_url;
17 GURL cancel_url;
18 std::map<std::string, std::string> parameters;
19
20 const char* expected;
21 };
22
23 TEST(XCallbackURLTest, IsXCallbackURL) {
24 EXPECT_TRUE(IsXCallbackURL(GURL("chrome://x-callback-url")));
25 EXPECT_TRUE(IsXCallbackURL(GURL("https://x-callback-url")));
26 EXPECT_TRUE(IsXCallbackURL(GURL("exotic-scheme://x-callback-url")));
27
28 EXPECT_TRUE(IsXCallbackURL(GURL("chrome://x-callback-url/action")));
29 EXPECT_TRUE(IsXCallbackURL(GURL("https://x-callback-url/action")));
30 EXPECT_TRUE(IsXCallbackURL(GURL("exotic-scheme://x-callback-url/action")));
31
32 EXPECT_FALSE(IsXCallbackURL(GURL()));
33 EXPECT_FALSE(IsXCallbackURL(GURL("chrome://version")));
34 EXPECT_FALSE(IsXCallbackURL(GURL("https://www.google.com")));
35 }
36
37 TEST(XCallbackURLTest, URLWithScheme) {
38 const XCallbackURLEncodeTestCase test_cases[] = {
39 {
40 "chrome",
41 nullptr,
42 GURL(),
43 GURL(),
44 GURL(),
45 {},
46
47 "chrome://x-callback-url/",
48 },
49 {
50 "chrome",
51 "command",
52 GURL(),
53 GURL(),
54 GURL(),
55 {},
56
57 "chrome://x-callback-url/command",
58 },
59 {
60 "chrome",
61 "command",
62 GURL("chrome://callback/?success=1"),
63 GURL("chrome://callback/?success=0"),
64 GURL("chrome://callback/?cancelled=1"),
65 {},
66
67 "chrome://x-callback-url/"
68 "command?x-success=chrome%3A%2F%2Fcallback%2F"
69 "%3Fsuccess%3D1&x-error=chrome%3A%2F%2Fcallback%2F"
70 "%3Fsuccess%3D0&x-cancel=chrome%3A%2F%2Fcallback%2F"
71 "%3Fcancelled%3D1",
72 },
73 {
74 "chrome",
75 "command",
76 GURL(),
77 GURL(),
78 GURL(),
79 {{"foo", "bar baz"}, {"qux", ""}},
80
81 "chrome://x-callback-url/command?foo=bar+baz&qux=",
82 },
83 {
84 "chrome",
85 "command",
86 GURL("chrome://callback/?success=1"),
87 GURL("chrome://callback/?success=0"),
88 GURL("chrome://callback/?cancelled=1"),
89 {{"foo", "bar baz"}, {"qux", ""}},
90
91 "chrome://x-callback-url/"
92 "command?x-success=chrome%3A%2F%2Fcallback%2F%3Fsuccess%3D1"
93 "&x-error=chrome%3A%2F%2Fcallback%2F%3Fsuccess%3D0&x-cancel=chrome"
94 "%3A%2F%2Fcallback%2F%3Fcancelled%3D1&foo=bar+baz&qux=",
95 },
96 {
97 "chrome",
98 "command",
99 GURL("chrome://path/with%20spaces"),
100 GURL(),
101 GURL(),
102 {},
103
104 "chrome://x-callback-url/command?x-success="
105 "chrome%3A%2F%2Fpath%2Fwith%2520spaces",
106 },
107 };
108
109 for (size_t i = 0; i < arraysize(test_cases); ++i) {
110 const XCallbackURLEncodeTestCase& test_case = test_cases[i];
111 const GURL x_callback_url = CreateXCallbackURLWithParameters(
112 test_case.scheme, test_case.action, test_case.success_url,
113 test_case.error_url, test_case.cancel_url, test_case.parameters);
114 EXPECT_EQ(test_case.expected, x_callback_url.spec());
115 }
116 }
117
118 struct XCallbackURLDecodeTestCase {
119 GURL x_callback_url;
120
121 std::map<std::string, std::string> expected;
122 };
123
124 TEST(XCallbackURLTest, QueryParameters) {
125 const XCallbackURLDecodeTestCase test_cases[] = {
126 {
127 GURL("chrome://x-callback-url/"),
128
129 {},
130 },
131 {
132 GURL("chrome://x-callback-url/command"),
133
134 {},
135 },
136 {
137 GURL("chrome://x-callback-url/"
138 "command?x-success=chrome%3A%2F%2Fcallback%2F%3Fsuccess%3D1"
139 "&x-error=chrome%3A%2F%2Fcallback%2F%3Fsuccess%3D0&x-cancel="
140 "chrome%3A%2F%2Fcallback%2F%3Fcancelled%3D1"),
141
142 {{"x-success", "chrome://callback/?success=1"},
143 {"x-error", "chrome://callback/?success=0"},
144 {"x-cancel", "chrome://callback/?cancelled=1"}},
145 },
146 {
147 GURL("chrome://x-callback-url/command?foo=bar+baz&qux="),
148
149 {{"foo", "bar baz"}, {"qux", ""}},
150 },
151 {
152 GURL("chrome://x-callback-url/"
153 "command?x-success=chrome%3A%2F%2Fcallback%2F%3Fsuccess%3D1"
154 "&x-error=chrome%3A%2F%2Fcallback%2F%3Fsuccess%3D0&x-cancel="
155 "chrome%3A%2F%2Fcallback%2F%3Fcancelled%3D1&foo=bar+baz&qux="),
156
157 {{"x-success", "chrome://callback/?success=1"},
158 {"x-error", "chrome://callback/?success=0"},
159 {"x-cancel", "chrome://callback/?cancelled=1"},
160 {"foo", "bar baz"},
161 {"qux", ""}},
162 },
163 {
164 GURL("chrome://x-callback-url/command?x-success="
165 "chrome%3A%2F%2Fpath%2Fwith%2520spaces"),
166
167 {{"x-success", "chrome://path/with%20spaces"}},
168 },
169 };
170
171 for (size_t i = 0; i < arraysize(test_cases); ++i) {
172 const XCallbackURLDecodeTestCase& test_case = test_cases[i];
173 const std::map<std::string, std::string> parameters =
174 ExtractQueryParametersFromXCallbackURL(test_case.x_callback_url);
175 EXPECT_EQ(test_case.expected, parameters);
176 }
177 }
178
179 } // namespace
OLDNEW
« no previous file with comments | « ios/chrome/common/x_callback_url.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698