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

Unified Diff: shell/command_line_util_unittest.cc

Issue 816473002: Update mojo shell so that --args-for can be used on android (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Follow review Created 6 years 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 | « shell/command_line_util.cc ('k') | shell/desktop/mojo_main.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: shell/command_line_util_unittest.cc
diff --git a/shell/command_line_util_unittest.cc b/shell/command_line_util_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0c31eb8ec30f2d369f917ff82365d6a8989442cc
--- /dev/null
+++ b/shell/command_line_util_unittest.cc
@@ -0,0 +1,78 @@
+// Copyright 2014 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 "shell/command_line_util.h"
+
+#include "base/logging.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace mojo {
+namespace shell {
+namespace {
+
+TEST(CommandLineUtil, ParseArgsFor) {
+ static const struct Expectation {
+ const char* args;
+ const char* value;
+ } EXPECTATIONS[] = {
+ {"", nullptr},
+ {"hello", nullptr},
+ {"args-for=mojo:app1", nullptr},
+ {"--args-for", nullptr},
+ {"--args-for=", ""},
+ {"--args-for=mojo:app1", "mojo:app1"},
+ {"--args-for=mojo:app1 hello world", "mojo:app1 hello world"},
+ {"-args-for", nullptr},
+ {"-args-for=", ""},
+ {"-args-for=mojo:app1", "mojo:app1"},
+ {"-args-for=mojo:app1 hello world", "mojo:app1 hello world"}};
+ for (auto& expectation : EXPECTATIONS) {
+ std::string value;
+ bool result = ParseArgsFor(expectation.args, &value);
+ EXPECT_EQ(bool(expectation.value), result);
+ if (expectation.value && result)
+ EXPECT_EQ(value, expectation.value);
+ }
+}
+
+TEST(CommandLineUtil, GetAppURLAndArgs) {
+ const char* NO_ARGUMENTS[] = {nullptr};
+ const char* ONE_ARGUMENTS[] = {"1", nullptr};
+ const char* TWO_ARGUMENTS[] = {"1", "two", nullptr};
+ static const struct Expectation {
+ const char* args;
+ const char* url;
+ const char** values;
+ } EXPECTATIONS[] = {
+ {"", nullptr, nullptr},
+ {"foo", nullptr, nullptr},
+ {"http://example.com", "http://example.com", NO_ARGUMENTS},
+ {"http://example.com 1", "http://example.com", ONE_ARGUMENTS},
+ {"http://example.com 1 ", "http://example.com", ONE_ARGUMENTS},
+ {"http://example.com 1 ", "http://example.com", ONE_ARGUMENTS},
+ {"http://example.com 1 two", "http://example.com", TWO_ARGUMENTS},
+ {" http://example.com 1 two ",
+ "http://example.com",
+ TWO_ARGUMENTS}};
+ for (auto& expectation : EXPECTATIONS) {
+ std::vector<std::string> args;
+ GURL result(GetAppURLAndArgs(expectation.args, &args));
+ EXPECT_EQ(bool(expectation.url), result.is_valid());
+ if (expectation.url && result.is_valid()) {
+ EXPECT_EQ(GURL(expectation.url), result);
+ std::vector<std::string> expected_args;
+ if (expectation.values) {
+ if (*expectation.values)
+ expected_args.push_back(expectation.url);
+ for (const char** value = expectation.values; *value; ++value)
+ expected_args.push_back(*value);
+ }
+ EXPECT_EQ(expected_args, args);
+ }
+ }
+}
+
+} // namespace
+} // namespace shell
+} // namespace mojo
« no previous file with comments | « shell/command_line_util.cc ('k') | shell/desktop/mojo_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698