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

Side by Side Diff: shell/command_line_util_unittest.cc

Issue 1905353002: Use a tokenizer to parse the command line for applications. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 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 | « shell/command_line_util.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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "shell/command_line_util.h" 5 #include "shell/command_line_util.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace shell { 10 namespace shell {
(...skipping 21 matching lines...) Expand all
32 EXPECT_EQ(bool(expectation.value), result); 32 EXPECT_EQ(bool(expectation.value), result);
33 if (expectation.value && result) 33 if (expectation.value && result)
34 EXPECT_EQ(value, expectation.value); 34 EXPECT_EQ(value, expectation.value);
35 } 35 }
36 } 36 }
37 37
38 TEST(CommandLineUtil, GetAppURLAndArgs) { 38 TEST(CommandLineUtil, GetAppURLAndArgs) {
39 const char* NO_ARGUMENTS[] = {nullptr}; 39 const char* NO_ARGUMENTS[] = {nullptr};
40 const char* ONE_ARGUMENTS[] = {"1", nullptr}; 40 const char* ONE_ARGUMENTS[] = {"1", nullptr};
41 const char* TWO_ARGUMENTS[] = {"1", "two", nullptr}; 41 const char* TWO_ARGUMENTS[] = {"1", "two", nullptr};
42 const char* QUOTED_ARGUMENTS[] = {"'1 two'", nullptr};
42 static const struct Expectation { 43 static const struct Expectation {
43 const char* args; 44 const char* args;
44 const char* url; 45 const char* url;
45 const char** values; 46 const char** values;
46 } EXPECTATIONS[] = { 47 } EXPECTATIONS[] = {
47 {"", nullptr, nullptr}, 48 {"", nullptr, nullptr},
48 {"foo", "file:///root/foo", NO_ARGUMENTS}, 49 {"foo", "file:///root/foo", NO_ARGUMENTS},
49 {"/foo", "file:///foo", NO_ARGUMENTS}, 50 {"/foo", "file:///foo", NO_ARGUMENTS},
50 {"file:foo", "file:///root/foo", NO_ARGUMENTS}, 51 {"file:foo", "file:///root/foo", NO_ARGUMENTS},
51 {"file:///foo", "file:///foo", NO_ARGUMENTS}, 52 {"file:///foo", "file:///foo", NO_ARGUMENTS},
52 {"http://example.com", "http://example.com", NO_ARGUMENTS}, 53 {"http://example.com", "http://example.com", NO_ARGUMENTS},
53 {"http://example.com 1", "http://example.com", ONE_ARGUMENTS}, 54 {"http://example.com 1", "http://example.com", ONE_ARGUMENTS},
54 {"http://example.com 1 ", "http://example.com", ONE_ARGUMENTS}, 55 {"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},
56 {"http://example.com 1 two", "http://example.com", TWO_ARGUMENTS}, 57 {"http://example.com 1 two", "http://example.com", TWO_ARGUMENTS},
57 {" http://example.com 1 two ", 58 {" http://example.com 1 two ", "http://example.com", TWO_ARGUMENTS},
58 "http://example.com", 59 {"http://example.com '1 two' ", "http://example.com", QUOTED_ARGUMENTS},
59 TWO_ARGUMENTS}}; 60 };
60 Context context; 61 Context context;
61 context.SetCommandLineCWD(base::FilePath("/root")); 62 context.SetCommandLineCWD(base::FilePath("/root"));
62 for (auto& expectation : EXPECTATIONS) { 63 for (auto& expectation : EXPECTATIONS) {
63 std::vector<std::string> args; 64 std::vector<std::string> args;
64 GURL result(GetAppURLAndArgs(&context, expectation.args, &args)); 65 GURL result(GetAppURLAndArgs(&context, expectation.args, &args));
65 EXPECT_EQ(bool(expectation.url), result.is_valid()); 66 EXPECT_EQ(bool(expectation.url), result.is_valid());
66 if (expectation.url && result.is_valid()) { 67 if (expectation.url && result.is_valid()) {
67 EXPECT_EQ(GURL(expectation.url), result); 68 EXPECT_EQ(GURL(expectation.url), result);
68 std::vector<std::string> expected_args; 69 std::vector<std::string> expected_args;
69 if (expectation.values) { 70 if (expectation.values) {
70 for (const char** value = expectation.values; *value; ++value) 71 for (const char** value = expectation.values; *value; ++value)
71 expected_args.push_back(*value); 72 expected_args.push_back(*value);
72 } 73 }
73 EXPECT_EQ(expected_args, args); 74 EXPECT_EQ(expected_args, args);
74 } 75 }
75 } 76 }
76 } 77 }
77 78
78 } // namespace 79 } // namespace
79 } // namespace shell 80 } // namespace shell
OLDNEW
« no previous file with comments | « shell/command_line_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698