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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/chrome/common/x_callback_url.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/common/x_callback_url_unittest.cc
diff --git a/ios/chrome/common/x_callback_url_unittest.cc b/ios/chrome/common/x_callback_url_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f4452886f15de36766a8d80da32a00af5edd4adc
--- /dev/null
+++ b/ios/chrome/common/x_callback_url_unittest.cc
@@ -0,0 +1,179 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ios/chrome/common/x_callback_url.h"
+
+#include "base/strings/stringprintf.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+struct XCallbackURLEncodeTestCase {
+ const char* scheme;
+ const char* action;
+ GURL success_url;
+ GURL error_url;
+ GURL cancel_url;
+ std::map<std::string, std::string> parameters;
+
+ const char* expected;
+};
+
+TEST(XCallbackURLTest, IsXCallbackURL) {
+ EXPECT_TRUE(IsXCallbackURL(GURL("chrome://x-callback-url")));
+ EXPECT_TRUE(IsXCallbackURL(GURL("https://x-callback-url")));
+ EXPECT_TRUE(IsXCallbackURL(GURL("exotic-scheme://x-callback-url")));
+
+ EXPECT_TRUE(IsXCallbackURL(GURL("chrome://x-callback-url/action")));
+ EXPECT_TRUE(IsXCallbackURL(GURL("https://x-callback-url/action")));
+ EXPECT_TRUE(IsXCallbackURL(GURL("exotic-scheme://x-callback-url/action")));
+
+ EXPECT_FALSE(IsXCallbackURL(GURL()));
+ EXPECT_FALSE(IsXCallbackURL(GURL("chrome://version")));
+ EXPECT_FALSE(IsXCallbackURL(GURL("https://www.google.com")));
+}
+
+TEST(XCallbackURLTest, URLWithScheme) {
+ const XCallbackURLEncodeTestCase test_cases[] = {
+ {
+ "chrome",
+ nullptr,
+ GURL(),
+ GURL(),
+ GURL(),
+ {},
+
+ "chrome://x-callback-url/",
+ },
+ {
+ "chrome",
+ "command",
+ GURL(),
+ GURL(),
+ GURL(),
+ {},
+
+ "chrome://x-callback-url/command",
+ },
+ {
+ "chrome",
+ "command",
+ GURL("chrome://callback/?success=1"),
+ GURL("chrome://callback/?success=0"),
+ GURL("chrome://callback/?cancelled=1"),
+ {},
+
+ "chrome://x-callback-url/"
+ "command?x-success=chrome%3A%2F%2Fcallback%2F"
+ "%3Fsuccess%3D1&x-error=chrome%3A%2F%2Fcallback%2F"
+ "%3Fsuccess%3D0&x-cancel=chrome%3A%2F%2Fcallback%2F"
+ "%3Fcancelled%3D1",
+ },
+ {
+ "chrome",
+ "command",
+ GURL(),
+ GURL(),
+ GURL(),
+ {{"foo", "bar baz"}, {"qux", ""}},
+
+ "chrome://x-callback-url/command?foo=bar+baz&qux=",
+ },
+ {
+ "chrome",
+ "command",
+ GURL("chrome://callback/?success=1"),
+ GURL("chrome://callback/?success=0"),
+ GURL("chrome://callback/?cancelled=1"),
+ {{"foo", "bar baz"}, {"qux", ""}},
+
+ "chrome://x-callback-url/"
+ "command?x-success=chrome%3A%2F%2Fcallback%2F%3Fsuccess%3D1"
+ "&x-error=chrome%3A%2F%2Fcallback%2F%3Fsuccess%3D0&x-cancel=chrome"
+ "%3A%2F%2Fcallback%2F%3Fcancelled%3D1&foo=bar+baz&qux=",
+ },
+ {
+ "chrome",
+ "command",
+ GURL("chrome://path/with%20spaces"),
+ GURL(),
+ GURL(),
+ {},
+
+ "chrome://x-callback-url/command?x-success="
+ "chrome%3A%2F%2Fpath%2Fwith%2520spaces",
+ },
+ };
+
+ for (size_t i = 0; i < arraysize(test_cases); ++i) {
+ const XCallbackURLEncodeTestCase& test_case = test_cases[i];
+ const GURL x_callback_url = CreateXCallbackURLWithParameters(
+ test_case.scheme, test_case.action, test_case.success_url,
+ test_case.error_url, test_case.cancel_url, test_case.parameters);
+ EXPECT_EQ(test_case.expected, x_callback_url.spec());
+ }
+}
+
+struct XCallbackURLDecodeTestCase {
+ GURL x_callback_url;
+
+ std::map<std::string, std::string> expected;
+};
+
+TEST(XCallbackURLTest, QueryParameters) {
+ const XCallbackURLDecodeTestCase test_cases[] = {
+ {
+ GURL("chrome://x-callback-url/"),
+
+ {},
+ },
+ {
+ GURL("chrome://x-callback-url/command"),
+
+ {},
+ },
+ {
+ GURL("chrome://x-callback-url/"
+ "command?x-success=chrome%3A%2F%2Fcallback%2F%3Fsuccess%3D1"
+ "&x-error=chrome%3A%2F%2Fcallback%2F%3Fsuccess%3D0&x-cancel="
+ "chrome%3A%2F%2Fcallback%2F%3Fcancelled%3D1"),
+
+ {{"x-success", "chrome://callback/?success=1"},
+ {"x-error", "chrome://callback/?success=0"},
+ {"x-cancel", "chrome://callback/?cancelled=1"}},
+ },
+ {
+ GURL("chrome://x-callback-url/command?foo=bar+baz&qux="),
+
+ {{"foo", "bar baz"}, {"qux", ""}},
+ },
+ {
+ GURL("chrome://x-callback-url/"
+ "command?x-success=chrome%3A%2F%2Fcallback%2F%3Fsuccess%3D1"
+ "&x-error=chrome%3A%2F%2Fcallback%2F%3Fsuccess%3D0&x-cancel="
+ "chrome%3A%2F%2Fcallback%2F%3Fcancelled%3D1&foo=bar+baz&qux="),
+
+ {{"x-success", "chrome://callback/?success=1"},
+ {"x-error", "chrome://callback/?success=0"},
+ {"x-cancel", "chrome://callback/?cancelled=1"},
+ {"foo", "bar baz"},
+ {"qux", ""}},
+ },
+ {
+ GURL("chrome://x-callback-url/command?x-success="
+ "chrome%3A%2F%2Fpath%2Fwith%2520spaces"),
+
+ {{"x-success", "chrome://path/with%20spaces"}},
+ },
+ };
+
+ for (size_t i = 0; i < arraysize(test_cases); ++i) {
+ const XCallbackURLDecodeTestCase& test_case = test_cases[i];
+ const std::map<std::string, std::string> parameters =
+ ExtractQueryParametersFromXCallbackURL(test_case.x_callback_url);
+ EXPECT_EQ(test_case.expected, parameters);
+ }
+}
+
+} // namespace
« 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