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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « shell/command_line_util.cc ('k') | shell/desktop/mojo_main.cc » ('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 "shell/command_line_util.h"
6
7 #include "base/logging.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace mojo {
11 namespace shell {
12 namespace {
13
14 TEST(CommandLineUtil, ParseArgsFor) {
15 static const struct Expectation {
16 const char* args;
17 const char* value;
18 } EXPECTATIONS[] = {
19 {"", nullptr},
20 {"hello", nullptr},
21 {"args-for=mojo:app1", nullptr},
22 {"--args-for", nullptr},
23 {"--args-for=", ""},
24 {"--args-for=mojo:app1", "mojo:app1"},
25 {"--args-for=mojo:app1 hello world", "mojo:app1 hello world"},
26 {"-args-for", nullptr},
27 {"-args-for=", ""},
28 {"-args-for=mojo:app1", "mojo:app1"},
29 {"-args-for=mojo:app1 hello world", "mojo:app1 hello world"}};
30 for (auto& expectation : EXPECTATIONS) {
31 std::string value;
32 bool result = ParseArgsFor(expectation.args, &value);
33 EXPECT_EQ(bool(expectation.value), result);
34 if (expectation.value && result)
35 EXPECT_EQ(value, expectation.value);
36 }
37 }
38
39 TEST(CommandLineUtil, GetAppURLAndArgs) {
40 const char* NO_ARGUMENTS[] = {nullptr};
41 const char* ONE_ARGUMENTS[] = {"1", nullptr};
42 const char* TWO_ARGUMENTS[] = {"1", "two", nullptr};
43 static const struct Expectation {
44 const char* args;
45 const char* url;
46 const char** values;
47 } EXPECTATIONS[] = {
48 {"", nullptr, nullptr},
49 {"foo", nullptr, nullptr},
50 {"http://example.com", "http://example.com", NO_ARGUMENTS},
51 {"http://example.com 1", "http://example.com", ONE_ARGUMENTS},
52 {"http://example.com 1 ", "http://example.com", ONE_ARGUMENTS},
53 {"http://example.com 1 ", "http://example.com", ONE_ARGUMENTS},
54 {"http://example.com 1 two", "http://example.com", TWO_ARGUMENTS},
55 {" http://example.com 1 two ",
56 "http://example.com",
57 TWO_ARGUMENTS}};
58 for (auto& expectation : EXPECTATIONS) {
59 std::vector<std::string> args;
60 GURL result(GetAppURLAndArgs(expectation.args, &args));
61 EXPECT_EQ(bool(expectation.url), result.is_valid());
62 if (expectation.url && result.is_valid()) {
63 EXPECT_EQ(GURL(expectation.url), result);
64 std::vector<std::string> expected_args;
65 if (expectation.values) {
66 if (*expectation.values)
67 expected_args.push_back(expectation.url);
68 for (const char** value = expectation.values; *value; ++value)
69 expected_args.push_back(*value);
70 }
71 EXPECT_EQ(expected_args, args);
72 }
73 }
74 }
75
76 } // namespace
77 } // namespace shell
78 } // namespace mojo
OLDNEW
« 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