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 mojo { | 10 namespace mojo { |
(...skipping 28 matching lines...) Expand all Loading... |
39 TEST(CommandLineUtil, GetAppURLAndArgs) { | 39 TEST(CommandLineUtil, GetAppURLAndArgs) { |
40 const char* NO_ARGUMENTS[] = {nullptr}; | 40 const char* NO_ARGUMENTS[] = {nullptr}; |
41 const char* ONE_ARGUMENTS[] = {"1", nullptr}; | 41 const char* ONE_ARGUMENTS[] = {"1", nullptr}; |
42 const char* TWO_ARGUMENTS[] = {"1", "two", nullptr}; | 42 const char* TWO_ARGUMENTS[] = {"1", "two", nullptr}; |
43 static const struct Expectation { | 43 static const struct Expectation { |
44 const char* args; | 44 const char* args; |
45 const char* url; | 45 const char* url; |
46 const char** values; | 46 const char** values; |
47 } EXPECTATIONS[] = { | 47 } EXPECTATIONS[] = { |
48 {"", nullptr, nullptr}, | 48 {"", nullptr, nullptr}, |
49 {"foo", 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}, |
50 {"http://example.com", "http://example.com", NO_ARGUMENTS}, | 53 {"http://example.com", "http://example.com", NO_ARGUMENTS}, |
51 {"http://example.com 1", "http://example.com", ONE_ARGUMENTS}, | 54 {"http://example.com 1", "http://example.com", ONE_ARGUMENTS}, |
52 {"http://example.com 1 ", "http://example.com", ONE_ARGUMENTS}, | 55 {"http://example.com 1 ", "http://example.com", ONE_ARGUMENTS}, |
53 {"http://example.com 1 ", "http://example.com", ONE_ARGUMENTS}, | 56 {"http://example.com 1 ", "http://example.com", ONE_ARGUMENTS}, |
54 {"http://example.com 1 two", "http://example.com", TWO_ARGUMENTS}, | 57 {"http://example.com 1 two", "http://example.com", TWO_ARGUMENTS}, |
55 {" http://example.com 1 two ", | 58 {" http://example.com 1 two ", |
56 "http://example.com", | 59 "http://example.com", |
57 TWO_ARGUMENTS}}; | 60 TWO_ARGUMENTS}}; |
| 61 Context context; |
| 62 context.SetCommandLineCWD(base::FilePath("/root")); |
58 for (auto& expectation : EXPECTATIONS) { | 63 for (auto& expectation : EXPECTATIONS) { |
59 std::vector<std::string> args; | 64 std::vector<std::string> args; |
60 GURL result(GetAppURLAndArgs(expectation.args, &args)); | 65 GURL result(GetAppURLAndArgs(&context, expectation.args, &args)); |
61 EXPECT_EQ(bool(expectation.url), result.is_valid()); | 66 EXPECT_EQ(bool(expectation.url), result.is_valid()); |
62 if (expectation.url && result.is_valid()) { | 67 if (expectation.url && result.is_valid()) { |
63 EXPECT_EQ(GURL(expectation.url), result); | 68 EXPECT_EQ(GURL(expectation.url), result); |
64 std::vector<std::string> expected_args; | 69 std::vector<std::string> expected_args; |
65 if (expectation.values) { | 70 if (expectation.values) { |
66 if (*expectation.values) | 71 if (*expectation.values) |
67 expected_args.push_back(expectation.url); | 72 expected_args.push_back(expectation.url); |
68 for (const char** value = expectation.values; *value; ++value) | 73 for (const char** value = expectation.values; *value; ++value) |
69 expected_args.push_back(*value); | 74 expected_args.push_back(*value); |
70 } | 75 } |
71 EXPECT_EQ(expected_args, args); | 76 EXPECT_EQ(expected_args, args); |
72 } | 77 } |
73 } | 78 } |
74 } | 79 } |
75 | 80 |
76 } // namespace | 81 } // namespace |
77 } // namespace shell | 82 } // namespace shell |
78 } // namespace mojo | 83 } // namespace mojo |
OLD | NEW |