Chromium Code Reviews| Index: chrome/test/webdriver/webdriver_capabilities_parser_unittest.cc |
| diff --git a/chrome/test/webdriver/webdriver_capabilities_parser_unittest.cc b/chrome/test/webdriver/webdriver_capabilities_parser_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a5e74ce14fef37b4e4e004ff7138606d2d1d1b44 |
| --- /dev/null |
| +++ b/chrome/test/webdriver/webdriver_capabilities_parser_unittest.cc |
| @@ -0,0 +1,85 @@ |
| +// Copyright (c) 2011 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 "base/file_path.h" |
| +#include "base/file_util.h" |
| +#include "base/scoped_temp_dir.h" |
| +#include "base/values.h" |
| +#include "chrome/test/webdriver/webdriver_capabilities_parser.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +using base::DictionaryValue; |
| +using base::ListValue; |
| +using base::Value; |
| + |
| +namespace webdriver { |
| + |
| +TEST(CapabilitiesParser, NoCaps) { |
| + Capabilities caps; |
| + DictionaryValue dict; |
| + CapabilitiesParser parser(&dict, FilePath(), &caps); |
| + ASSERT_FALSE(parser.Parse()); |
| +} |
| + |
| +TEST(CapabilitiesParser, AllCaps) { |
|
Huyen
2011/10/26 18:05:46
Did you forget to add profile/user-data-dir option
|
| + DictionaryValue dict; |
| + DictionaryValue* options = new DictionaryValue(); |
| + dict.Set("chromeOptions", options); |
| + |
| + ListValue* args = new ListValue(); |
| + args->Append(Value::CreateStringValue("arg1")); |
| + args->Append(Value::CreateStringValue("arg2=val")); |
| + args->Append(Value::CreateStringValue("arg3='a space'")); |
| + options->Set("args", args); |
| + options->SetString("binary", "binary"); |
| + options->SetString("channel", "channel"); |
| + options->SetBoolean("detach", true); |
| + ListValue* extensions = new ListValue(); |
| + extensions->Append(Value::CreateStringValue("TWFu")); |
| + extensions->Append(Value::CreateStringValue("TWFuTWFu")); |
| + options->Set("extensions", extensions); |
| + options->SetBoolean("loadAsync", true); |
| + options->SetBoolean("nativeEvents", true); |
| + options->SetBoolean("verbose", true); |
| + |
| + Capabilities caps; |
| + ScopedTempDir temp_dir; |
| + ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| + CapabilitiesParser parser(&dict, temp_dir.path(), &caps); |
| + ASSERT_FALSE(parser.Parse()); |
| + EXPECT_TRUE(caps.command.HasSwitch("arg1")); |
| + EXPECT_STREQ("val", caps.command.GetSwitchValueASCII("arg2").c_str()); |
| + EXPECT_STREQ("'a space'", caps.command.GetSwitchValueASCII("arg3").c_str()); |
| + EXPECT_EQ(FILE_PATH_LITERAL("binary"), caps.command.GetProgram().value()); |
| + EXPECT_STREQ("channel", caps.channel.c_str()); |
| + EXPECT_TRUE(caps.detach); |
| + ASSERT_EQ(2u, caps.extensions.size()); |
| + std::string contents; |
| + ASSERT_TRUE(file_util::ReadFileToString(caps.extensions[0], &contents)); |
| + EXPECT_STREQ("Man", contents.c_str()); |
| + contents.clear(); |
| + ASSERT_TRUE(file_util::ReadFileToString(caps.extensions[1], &contents)); |
| + EXPECT_STREQ("ManMan", contents.c_str()); |
| + EXPECT_TRUE(caps.load_async); |
| + EXPECT_TRUE(caps.native_events); |
| + EXPECT_TRUE(caps.verbose); |
| +} |
| + |
| +TEST(CapabilitiesParser, UnknownCap) { |
| + Capabilities caps; |
| + DictionaryValue dict; |
| + dict.SetString("chromeOptions.nosuchcap", "none"); |
| + CapabilitiesParser parser(&dict, FilePath(), &caps); |
| + ASSERT_FALSE(parser.Parse()); |
| +} |
| + |
| +TEST(CapabilitiesParser, BadInput) { |
| + Capabilities caps; |
| + DictionaryValue dict; |
| + dict.SetString("chromeOptions.verbose", "false"); |
| + CapabilitiesParser parser(&dict, FilePath(), &caps); |
| + ASSERT_TRUE(parser.Parse()); |
| +} |
| + |
| +} // namespace webdriver |