Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 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 "base/file_path.h" | |
| 6 #include "base/file_util.h" | |
| 7 #include "base/scoped_temp_dir.h" | |
| 8 #include "base/values.h" | |
| 9 #include "chrome/test/webdriver/webdriver_capabilities_parser.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 | |
| 12 using base::DictionaryValue; | |
| 13 using base::ListValue; | |
| 14 using base::Value; | |
| 15 | |
| 16 namespace webdriver { | |
| 17 | |
| 18 TEST(CapabilitiesParser, NoCaps) { | |
| 19 Capabilities caps; | |
| 20 DictionaryValue dict; | |
| 21 CapabilitiesParser parser(&dict, FilePath(), &caps); | |
| 22 ASSERT_FALSE(parser.Parse()); | |
| 23 } | |
| 24 | |
| 25 TEST(CapabilitiesParser, AllCaps) { | |
|
Huyen
2011/10/26 18:05:46
Did you forget to add profile/user-data-dir option
| |
| 26 DictionaryValue dict; | |
| 27 DictionaryValue* options = new DictionaryValue(); | |
| 28 dict.Set("chromeOptions", options); | |
| 29 | |
| 30 ListValue* args = new ListValue(); | |
| 31 args->Append(Value::CreateStringValue("arg1")); | |
| 32 args->Append(Value::CreateStringValue("arg2=val")); | |
| 33 args->Append(Value::CreateStringValue("arg3='a space'")); | |
| 34 options->Set("args", args); | |
| 35 options->SetString("binary", "binary"); | |
| 36 options->SetString("channel", "channel"); | |
| 37 options->SetBoolean("detach", true); | |
| 38 ListValue* extensions = new ListValue(); | |
| 39 extensions->Append(Value::CreateStringValue("TWFu")); | |
| 40 extensions->Append(Value::CreateStringValue("TWFuTWFu")); | |
| 41 options->Set("extensions", extensions); | |
| 42 options->SetBoolean("loadAsync", true); | |
| 43 options->SetBoolean("nativeEvents", true); | |
| 44 options->SetBoolean("verbose", true); | |
| 45 | |
| 46 Capabilities caps; | |
| 47 ScopedTempDir temp_dir; | |
| 48 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | |
| 49 CapabilitiesParser parser(&dict, temp_dir.path(), &caps); | |
| 50 ASSERT_FALSE(parser.Parse()); | |
| 51 EXPECT_TRUE(caps.command.HasSwitch("arg1")); | |
| 52 EXPECT_STREQ("val", caps.command.GetSwitchValueASCII("arg2").c_str()); | |
| 53 EXPECT_STREQ("'a space'", caps.command.GetSwitchValueASCII("arg3").c_str()); | |
| 54 EXPECT_EQ(FILE_PATH_LITERAL("binary"), caps.command.GetProgram().value()); | |
| 55 EXPECT_STREQ("channel", caps.channel.c_str()); | |
| 56 EXPECT_TRUE(caps.detach); | |
| 57 ASSERT_EQ(2u, caps.extensions.size()); | |
| 58 std::string contents; | |
| 59 ASSERT_TRUE(file_util::ReadFileToString(caps.extensions[0], &contents)); | |
| 60 EXPECT_STREQ("Man", contents.c_str()); | |
| 61 contents.clear(); | |
| 62 ASSERT_TRUE(file_util::ReadFileToString(caps.extensions[1], &contents)); | |
| 63 EXPECT_STREQ("ManMan", contents.c_str()); | |
| 64 EXPECT_TRUE(caps.load_async); | |
| 65 EXPECT_TRUE(caps.native_events); | |
| 66 EXPECT_TRUE(caps.verbose); | |
| 67 } | |
| 68 | |
| 69 TEST(CapabilitiesParser, UnknownCap) { | |
| 70 Capabilities caps; | |
| 71 DictionaryValue dict; | |
| 72 dict.SetString("chromeOptions.nosuchcap", "none"); | |
| 73 CapabilitiesParser parser(&dict, FilePath(), &caps); | |
| 74 ASSERT_FALSE(parser.Parse()); | |
| 75 } | |
| 76 | |
| 77 TEST(CapabilitiesParser, BadInput) { | |
| 78 Capabilities caps; | |
| 79 DictionaryValue dict; | |
| 80 dict.SetString("chromeOptions.verbose", "false"); | |
| 81 CapabilitiesParser parser(&dict, FilePath(), &caps); | |
| 82 ASSERT_TRUE(parser.Parse()); | |
| 83 } | |
| 84 | |
| 85 } // namespace webdriver | |
| OLD | NEW |