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

Side by Side Diff: mojo/shell/command_line_util_unittest.cc

Issue 1049993002: Get mojo_shell building inside chromium checkout. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix presubmit Created 5 years, 8 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/shell/command_line_util.cc ('k') | mojo/shell/context.h » ('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/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", "file:///root/foo", NO_ARGUMENTS},
50 {"/foo", "file:///foo", NO_ARGUMENTS},
51 {"file:foo", "file:///root/foo", NO_ARGUMENTS},
52 {"file:///foo", "file:///foo", NO_ARGUMENTS},
53 {"http://example.com", "http://example.com", NO_ARGUMENTS},
54 {"http://example.com 1", "http://example.com", ONE_ARGUMENTS},
55 {"http://example.com 1 ", "http://example.com", ONE_ARGUMENTS},
56 {"http://example.com 1 ", "http://example.com", ONE_ARGUMENTS},
57 {"http://example.com 1 two", "http://example.com", TWO_ARGUMENTS},
58 {" http://example.com 1 two ",
59 "http://example.com",
60 TWO_ARGUMENTS}};
61 Context context;
62 context.SetCommandLineCWD(base::FilePath(FILE_PATH_LITERAL("/root")));
63 for (auto& expectation : EXPECTATIONS) {
64 std::vector<std::string> args;
65 GURL result(GetAppURLAndArgs(&context, expectation.args, &args));
66 EXPECT_EQ(bool(expectation.url), result.is_valid());
67 if (expectation.url && result.is_valid()) {
68 EXPECT_EQ(GURL(expectation.url), result);
69 std::vector<std::string> expected_args;
70 if (expectation.values) {
71 if (*expectation.values)
72 expected_args.push_back(expectation.url);
73 for (const char** value = expectation.values; *value; ++value)
74 expected_args.push_back(*value);
75 }
76 EXPECT_EQ(expected_args, args);
77 }
78 }
79 }
80
81 } // namespace
82 } // namespace shell
83 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/command_line_util.cc ('k') | mojo/shell/context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698