OLD | NEW |
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 Loading... |
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 |
OLD | NEW |