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

Unified Diff: chrome/test/chromedriver/capabilities_unittest.cc

Issue 23643005: [chromedriver] Load the automation extension as a component extension. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 7 years, 4 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: chrome/test/chromedriver/capabilities_unittest.cc
diff --git a/chrome/test/chromedriver/capabilities_unittest.cc b/chrome/test/chromedriver/capabilities_unittest.cc
index 6d70f854a2f7a9234403f08d3ca1d6740e155ab1..6686620a744634de8750b275c38763f39edff54b 100644
--- a/chrome/test/chromedriver/capabilities_unittest.cc
+++ b/chrome/test/chromedriver/capabilities_unittest.cc
@@ -9,6 +9,68 @@
#include "chrome/test/chromedriver/chrome/status.h"
#include "testing/gtest/include/gtest/gtest.h"
+TEST(Switches, Empty) {
+ Switches switches;
+ CommandLine cmd(CommandLine::NO_PROGRAM);
+ switches.AppendToCommandLine(&cmd);
+ ASSERT_EQ(0u, cmd.GetSwitches().size());
+ ASSERT_EQ("", switches.ToString());
+}
+
+TEST(Switches, NoValue) {
+ Switches switches;
+ switches.SetSwitch("hello");
+
+ CommandLine cmd(CommandLine::NO_PROGRAM);
+ switches.AppendToCommandLine(&cmd);
+ ASSERT_TRUE(cmd.HasSwitch("hello"));
+ ASSERT_EQ(FILE_PATH_LITERAL(""), cmd.GetSwitchValueNative("hello"));
+ ASSERT_EQ("--hello", switches.ToString());
+}
+
+TEST(Switches, Value) {
+ Switches switches;
+ switches.SetSwitch("hello", "there");
+
+ CommandLine cmd(CommandLine::NO_PROGRAM);
+ switches.AppendToCommandLine(&cmd);
+ ASSERT_TRUE(cmd.HasSwitch("hello"));
+ ASSERT_EQ(FILE_PATH_LITERAL("there"), cmd.GetSwitchValueNative("hello"));
+ ASSERT_EQ("--hello=there", switches.ToString());
+}
+
+TEST(Switches, Quoting) {
+ Switches switches;
+ switches.SetSwitch("hello", "a b");
+ switches.SetSwitch("hello2", " '\" ");
+
+ ASSERT_EQ("--hello=\"a b\" --hello2=\" '\\\" \"", switches.ToString());
+}
+
+TEST(Switches, Multiple) {
+ Switches switches;
+ switches.SetSwitch("switch");
+ switches.SetSwitch("hello", "there");
+
+ CommandLine cmd(CommandLine::NO_PROGRAM);
+ switches.AppendToCommandLine(&cmd);
+ ASSERT_TRUE(cmd.HasSwitch("switch"));
+ ASSERT_TRUE(cmd.HasSwitch("hello"));
+ ASSERT_EQ(FILE_PATH_LITERAL("there"), cmd.GetSwitchValueNative("hello"));
+ ASSERT_EQ("--hello=there --switch", switches.ToString());
+}
+
+TEST(Switches, Unparsed) {
+ Switches switches;
+ switches.SetUnparsedSwitch("a");
+ switches.SetUnparsedSwitch("--b");
+ switches.SetUnparsedSwitch("--c=1");
+ switches.SetUnparsedSwitch("d=1");
+ switches.SetUnparsedSwitch("-e=--1=1");
+
+ ASSERT_EQ("---e=--1=1 --a --b --c=1 --d=1", switches.ToString());
+}
+
TEST(ParseCapabilities, WithAndroidPackage) {
Capabilities capabilities;
base::DictionaryValue caps;
@@ -48,70 +110,6 @@ TEST(ParseCapabilities, LogPath) {
ASSERT_STREQ("path/to/logfile", capabilities.log_path.c_str());
}
-TEST(ParseCapabilities, NoArgs) {
- Capabilities capabilities;
- base::ListValue args;
- ASSERT_TRUE(args.empty());
- base::DictionaryValue caps;
- caps.Set("chromeOptions.args", args.DeepCopy());
- Logger log(Log::kError);
- Status status = capabilities.Parse(caps, &log);
- ASSERT_TRUE(status.IsOk());
- ASSERT_TRUE(capabilities.command.GetSwitches().empty());
-}
-
-TEST(ParseCapabilities, SingleArgWithoutValue) {
- Capabilities capabilities;
- base::ListValue args;
- args.AppendString("enable-nacl");
- ASSERT_EQ(1u, args.GetSize());
- base::DictionaryValue caps;
- caps.Set("chromeOptions.args", args.DeepCopy());
- Logger log(Log::kError);
- Status status = capabilities.Parse(caps, &log);
- ASSERT_TRUE(status.IsOk());
- ASSERT_EQ(1u, capabilities.command.GetSwitches().size());
- ASSERT_TRUE(capabilities.command.HasSwitch("enable-nacl"));
-}
-
-TEST(ParseCapabilities, SingleArgWithValue) {
- Capabilities capabilities;
- base::ListValue args;
- args.AppendString("load-extension=/test/extension");
- ASSERT_EQ(1u, args.GetSize());
- base::DictionaryValue caps;
- caps.Set("chromeOptions.args", args.DeepCopy());
- Logger log(Log::kError);
- Status status = capabilities.Parse(caps, &log);
- ASSERT_TRUE(status.IsOk());
- ASSERT_EQ(1u, capabilities.command.GetSwitches().size());
- ASSERT_TRUE(capabilities.command.HasSwitch("load-extension"));
- ASSERT_STREQ(
- "/test/extension",
- capabilities.command.GetSwitchValueASCII("load-extension").c_str());
-}
-
-TEST(ParseCapabilities, MultipleArgs) {
- Capabilities capabilities;
- base::ListValue args;
- args.AppendString("arg1");
- args.AppendString("arg2=val");
- args.AppendString("arg3='a space'");
- ASSERT_EQ(3u, args.GetSize());
- base::DictionaryValue caps;
- caps.Set("chromeOptions.args", args.DeepCopy());
- Logger log(Log::kError);
- Status status = capabilities.Parse(caps, &log);
- ASSERT_TRUE(status.IsOk());
- ASSERT_EQ(3u, capabilities.command.GetSwitches().size());
- ASSERT_TRUE(capabilities.command.HasSwitch("arg1"));
- ASSERT_TRUE(capabilities.command.HasSwitch("arg2"));
- ASSERT_STREQ("val", capabilities.command.GetSwitchValueASCII("arg2").c_str());
- ASSERT_TRUE(capabilities.command.HasSwitch("arg3"));
- ASSERT_STREQ("'a space'",
- capabilities.command.GetSwitchValueASCII("arg3").c_str());
-}
-
TEST(ParseCapabilities, Prefs) {
Capabilities capabilities;
base::DictionaryValue prefs;
@@ -184,8 +182,8 @@ TEST(ParseCapabilities, DirectProxy) {
Logger log(Log::kError);
Status status = capabilities.Parse(caps, &log);
ASSERT_TRUE(status.IsOk());
- ASSERT_EQ(1u, capabilities.command.GetSwitches().size());
- ASSERT_TRUE(capabilities.command.HasSwitch("no-proxy-server"));
+ ASSERT_EQ(1u, capabilities.switches.GetSize());
+ ASSERT_TRUE(capabilities.switches.HasSwitch("no-proxy-server"));
}
TEST(ParseCapabilities, SystemProxy) {
@@ -197,7 +195,7 @@ TEST(ParseCapabilities, SystemProxy) {
Logger log(Log::kError);
Status status = capabilities.Parse(caps, &log);
ASSERT_TRUE(status.IsOk());
- ASSERT_TRUE(capabilities.command.GetSwitches().empty());
+ ASSERT_EQ(0u, capabilities.switches.GetSize());
}
TEST(ParseCapabilities, PacProxy) {
@@ -210,10 +208,8 @@ TEST(ParseCapabilities, PacProxy) {
Logger log(Log::kError);
Status status = capabilities.Parse(caps, &log);
ASSERT_TRUE(status.IsOk());
- ASSERT_EQ(1u, capabilities.command.GetSwitches().size());
- ASSERT_STREQ(
- "test.wpad",
- capabilities.command.GetSwitchValueASCII("proxy-pac-url").c_str());
+ ASSERT_EQ(1u, capabilities.switches.GetSize());
+ ASSERT_EQ("test.wpad", capabilities.switches.GetSwitchValue("proxy-pac-url"));
}
TEST(ParseCapabilities, MissingProxyAutoconfigUrl) {
@@ -237,8 +233,8 @@ TEST(ParseCapabilities, AutodetectProxy) {
Logger log(Log::kError);
Status status = capabilities.Parse(caps, &log);
ASSERT_TRUE(status.IsOk());
- ASSERT_EQ(1u, capabilities.command.GetSwitches().size());
- ASSERT_TRUE(capabilities.command.HasSwitch("proxy-auto-detect"));
+ ASSERT_EQ(1u, capabilities.switches.GetSize());
+ ASSERT_TRUE(capabilities.switches.HasSwitch("proxy-auto-detect"));
}
TEST(ParseCapabilities, ManualProxy) {
@@ -254,13 +250,13 @@ TEST(ParseCapabilities, ManualProxy) {
Logger log(Log::kError);
Status status = capabilities.Parse(caps, &log);
ASSERT_TRUE(status.IsOk());
- ASSERT_EQ(2u, capabilities.command.GetSwitches().size());
- ASSERT_STREQ(
+ ASSERT_EQ(2u, capabilities.switches.GetSize());
+ ASSERT_EQ(
"ftp=localhost:9001;http=localhost:8001;https=localhost:10001",
- capabilities.command.GetSwitchValueASCII("proxy-server").c_str());
- ASSERT_STREQ(
+ capabilities.switches.GetSwitchValue("proxy-server"));
+ ASSERT_EQ(
"google.com, youtube.com",
- capabilities.command.GetSwitchValueASCII("proxy-bypass-list").c_str());
+ capabilities.switches.GetSwitchValue("proxy-bypass-list"));
}
TEST(ParseCapabilities, MissingSettingForManualProxy) {
@@ -286,11 +282,11 @@ TEST(ParseCapabilities, IgnoreNullValueForManualProxy) {
Logger log(Log::kError);
Status status = capabilities.Parse(caps, &log);
ASSERT_TRUE(status.IsOk());
- ASSERT_EQ(1u, capabilities.command.GetSwitches().size());
- ASSERT_TRUE(capabilities.command.HasSwitch("proxy-server"));
- ASSERT_STREQ(
+ ASSERT_EQ(1u, capabilities.switches.GetSize());
+ ASSERT_TRUE(capabilities.switches.HasSwitch("proxy-server"));
+ ASSERT_EQ(
"ftp=localhost:9001",
- capabilities.command.GetSwitchValueASCII("proxy-server").c_str());
+ capabilities.switches.GetSwitchValue("proxy-server"));
}
TEST(ParseCapabilities, LoggingPrefsOk) {

Powered by Google App Engine
This is Rietveld 408576698