- add sources.
[platform/framework/web/crosswalk.git] / src / win8 / delegate_execute / delegate_execute_util_unittest.cc
1 // Copyright (c) 2012 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 "win8/delegate_execute/delegate_execute_util.h"
6
7 #include <algorithm>
8
9 #include "base/command_line.h"
10 #include "base/files/file_path.h"
11 #include "base/strings/stringprintf.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace {
16
17 static const char kSomeSwitch[] = "some-switch";
18
19 }  // namespace
20
21 TEST(DelegateExecuteUtil, CommandLineFromParametersTest) {
22   CommandLine cl(CommandLine::NO_PROGRAM);
23
24   // Empty parameters means empty command-line string.
25   cl = delegate_execute::CommandLineFromParameters(NULL);
26   EXPECT_EQ(std::wstring(), cl.GetProgram().value());
27   EXPECT_EQ(CommandLine::StringType(), cl.GetCommandLineString());
28
29   // Parameters with a switch are parsed properly.
30   cl = delegate_execute::CommandLineFromParameters(
31       base::StringPrintf(L"--%ls", ASCIIToWide(kSomeSwitch).c_str()).c_str());
32   EXPECT_EQ(std::wstring(), cl.GetProgram().value());
33   EXPECT_TRUE(cl.HasSwitch(kSomeSwitch));
34 }
35
36 TEST(DelegateExecuteUtil, MakeChromeCommandLineTest) {
37   static const wchar_t kSomeArgument[] = L"http://some.url/";
38   static const wchar_t kOtherArgument[] = L"http://some.other.url/";
39   const base::FilePath this_exe(CommandLine::ForCurrentProcess()->GetProgram());
40
41   CommandLine cl(CommandLine::NO_PROGRAM);
42
43   // Empty params and argument contains only the exe.
44   cl = delegate_execute::MakeChromeCommandLine(
45       this_exe, delegate_execute::CommandLineFromParameters(NULL), string16());
46   EXPECT_EQ(1, cl.argv().size());
47   EXPECT_EQ(this_exe.value(), cl.GetProgram().value());
48
49   // Empty params with arg contains the arg.
50   cl = delegate_execute::MakeChromeCommandLine(
51       this_exe, delegate_execute::CommandLineFromParameters(NULL),
52       string16(kSomeArgument));
53   EXPECT_EQ(2, cl.argv().size());
54   EXPECT_EQ(this_exe.value(), cl.GetProgram().value());
55   EXPECT_EQ(1, cl.GetArgs().size());
56   EXPECT_EQ(string16(kSomeArgument), cl.GetArgs()[0]);
57
58   // Params with switchs and args plus arg contains the arg.
59   cl = delegate_execute::MakeChromeCommandLine(
60       this_exe, delegate_execute::CommandLineFromParameters(
61           base::StringPrintf(L"--%ls -- %ls", ASCIIToWide(kSomeSwitch).c_str(),
62                              kOtherArgument).c_str()),
63       string16(kSomeArgument));
64   EXPECT_EQ(5, cl.argv().size());
65   EXPECT_EQ(this_exe.value(), cl.GetProgram().value());
66   EXPECT_TRUE(cl.HasSwitch(kSomeSwitch));
67   CommandLine::StringVector args(cl.GetArgs());
68   EXPECT_EQ(2, args.size());
69   EXPECT_NE(args.end(),
70             std::find(args.begin(), args.end(), string16(kOtherArgument)));
71   EXPECT_NE(args.end(),
72             std::find(args.begin(), args.end(), string16(kSomeArgument)));
73 }
74
75 TEST(DelegateExecuteUtil, ParametersFromSwitchTest) {
76   EXPECT_EQ(string16(), delegate_execute::ParametersFromSwitch(NULL));
77   EXPECT_EQ(string16(L"--some-switch"),
78             delegate_execute::ParametersFromSwitch(kSomeSwitch));
79 }