Commit f02041b4 authored by John Chen's avatar John Chen Committed by Commit Bot

[ChromeDriver] Handle null capabilities

According to W3C spec, new session capabilities with null values should
be ignored, but they cause errors in ChromeDriver. This CL fixes it.

See https://www.w3.org/TR/webdriver/#dfn-validate-capabilities, step 3,
sub-steps 3 and 4.

Bug: chromedriver:1997
Change-Id: Ibee5e383c46139df1e5efc9f8a46872820c81046
Reviewed-on: https://chromium-review.googlesource.com/c/1340834
Commit-Queue: John Chen <johnchen@chromium.org>
Reviewed-by: default avatarCaleb Rouleau <crouleau@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609069}
parent 861186ea
......@@ -761,6 +761,8 @@ Status Capabilities::Parse(const base::DictionaryValue& desired_caps,
for (base::DictionaryValue::Iterator it(desired_caps); !it.IsAtEnd();
it.Advance()) {
if (it.value().is_none())
continue;
if (parser_map.find(it.key()) == parser_map.end()) {
// The specified capability is unrecognized. W3C spec requires us to
// return an error. In legacy mode, for backward compatibility reasons,
......
......@@ -330,15 +330,15 @@ bool MergeCapabilities(const base::DictionaryValue* always_match,
return true;
}
// Implementation of "matching capabilities", as defined in W3C spec at
// https://www.w3.org/TR/webdriver/#dfn-matching-capabilities.
// It checks some requested capabilities and make sure they are supported.
// Currently, we only check "browserName", but more can be added as necessary.
bool MatchCapabilities(const base::DictionaryValue* capabilities) {
// Attempt to match the capabilities requested to the actual capabilities.
// Reject if they don't match.
if (capabilities->HasKey("browserName")) {
std::string name;
capabilities->GetString("browserName", &name);
if (name != "chrome") {
const base::Value* name;
if (capabilities->Get("browserName", &name) && !name->is_none()) {
if (!(name->is_string() && name->GetString() == "chrome"))
return false;
}
}
return true;
}
......
......@@ -151,6 +151,12 @@ TEST(SessionCommandsTest, ProcessCapabilities_AlwaysMatch) {
std::string result_string;
ASSERT_TRUE(result.GetString("browserName", &result_string));
ASSERT_EQ(result_string, "chrome");
// Null "browserName" treated as not specifying "browserName"
params.SetPath({"capabilities", "alwaysMatch", "browserName"}, base::Value());
status = ProcessCapabilities(params, &result);
ASSERT_EQ(kOk, status.code()) << status.message();
ASSERT_FALSE(result.GetString("browserName", &result_string));
}
TEST(SessionCommandsTest, ProcessCapabilities_FirstMatch) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment