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

Unified Diff: win8/delegate_execute/delegate_execute_util_unittest.cc

Issue 10962023: Prefix Chrome switches with the switch prefix. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: win8/delegate_execute/delegate_execute_util_unittest.cc
diff --git a/win8/delegate_execute/delegate_execute_util_unittest.cc b/win8/delegate_execute/delegate_execute_util_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..360d8e7785ccd7bc6fbe9215dac452f39452cbcd
--- /dev/null
+++ b/win8/delegate_execute/delegate_execute_util_unittest.cc
@@ -0,0 +1,79 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "win8/delegate_execute/delegate_execute_util.h"
+
+#include <algorithm>
+
+#include "base/command_line.h"
+#include "base/file_path.h"
+#include "base/stringprintf.h"
+#include "base/utf_string_conversions.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+static const char kSomeSwitch[] = "some-switch";
+
+} // namespace
+
+TEST(DelegateExecuteUtil, CommandLineFromParametersTest) {
+ CommandLine cl(CommandLine::NO_PROGRAM);
+
+ // Empty parameters means empty command-line string.
+ cl = delegate_execute::CommandLineFromParameters(NULL);
+ EXPECT_EQ(std::wstring(), cl.GetProgram().value());
+ EXPECT_EQ(CommandLine::StringType(), cl.GetCommandLineString());
+
+ // Parameters with a switch are parsed properly.
+ cl = delegate_execute::CommandLineFromParameters(
+ base::StringPrintf(L"--%ls", ASCIIToWide(kSomeSwitch).c_str()).c_str());
+ EXPECT_EQ(std::wstring(), cl.GetProgram().value());
+ EXPECT_TRUE(cl.HasSwitch(kSomeSwitch));
+}
+
+TEST(DelegateExecuteUtil, MakeChromeCommandLineTest) {
+ static const wchar_t kSomeArgument[] = L"http://some.url/";
+ static const wchar_t kOtherArgument[] = L"http://some.other.url/";
+ const FilePath this_exe(CommandLine::ForCurrentProcess()->GetProgram());
+
+ CommandLine cl(CommandLine::NO_PROGRAM);
+
+ // Empty params and argument contains only the exe.
+ cl = delegate_execute::MakeChromeCommandLine(
+ this_exe, delegate_execute::CommandLineFromParameters(NULL), string16());
+ EXPECT_EQ(1, cl.argv().size());
+ EXPECT_EQ(this_exe.value(), cl.GetProgram().value());
+
+ // Empty params with arg contains the arg.
+ cl = delegate_execute::MakeChromeCommandLine(
+ this_exe, delegate_execute::CommandLineFromParameters(NULL),
+ string16(kSomeArgument));
+ EXPECT_EQ(2, cl.argv().size());
+ EXPECT_EQ(this_exe.value(), cl.GetProgram().value());
+ EXPECT_EQ(1, cl.GetArgs().size());
+ EXPECT_EQ(string16(kSomeArgument), cl.GetArgs()[0]);
+
+ // Params with switchs and args plus arg contains the arg.
+ cl = delegate_execute::MakeChromeCommandLine(
+ this_exe, delegate_execute::CommandLineFromParameters(
+ base::StringPrintf(L"--%ls -- %ls", ASCIIToWide(kSomeSwitch).c_str(),
+ kOtherArgument).c_str()),
+ string16(kSomeArgument));
+ EXPECT_EQ(5, cl.argv().size());
+ EXPECT_EQ(this_exe.value(), cl.GetProgram().value());
+ EXPECT_TRUE(cl.HasSwitch(kSomeSwitch));
+ CommandLine::StringVector args(cl.GetArgs());
+ EXPECT_EQ(2, args.size());
+ EXPECT_NE(args.end(),
+ std::find(args.begin(), args.end(), string16(kOtherArgument)));
+ EXPECT_NE(args.end(),
+ std::find(args.begin(), args.end(), string16(kSomeArgument)));
+}
+
+TEST(DelegateExecuteUtil, ParametersFromSwitchTest) {
+ EXPECT_EQ(string16(), delegate_execute::ParametersFromSwitch(NULL));
+ EXPECT_EQ(string16(L"--some-switch"),
+ delegate_execute::ParametersFromSwitch(kSomeSwitch));
+}

Powered by Google App Engine
This is Rietveld 408576698