diff --git a/cobalt/webdriver/BUILD.gn b/cobalt/webdriver/BUILD.gn index bce97f01e7b9..518f94061f17 100644 --- a/cobalt/webdriver/BUILD.gn +++ b/cobalt/webdriver/BUILD.gn @@ -131,6 +131,7 @@ target(gtest_target_type, "webdriver_test") { testonly = true sources = [ + "dispatcher_test.cc", "execute_test.cc", "get_element_text_test.cc", "is_displayed_test.cc", @@ -150,6 +151,7 @@ target(gtest_target_type, "webdriver_test") { "//testing/gmock", "//testing/gtest", "//third_party/devtools:devtools_all_files", + "//url", ] data_deps = [ diff --git a/cobalt/webdriver/dispatcher_test.cc b/cobalt/webdriver/dispatcher_test.cc new file mode 100644 index 000000000000..6812858029a4 --- /dev/null +++ b/cobalt/webdriver/dispatcher_test.cc @@ -0,0 +1,61 @@ +// Copyright 2024 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "cobalt/webdriver/dispatcher.h" + +#include + +#include "base/optional.h" +#include "base/values.h" +#include "cobalt/webdriver/protocol/log_type.h" +#include "cobalt/webdriver/protocol/window_id.h" +#include "cobalt/webdriver/session_driver.h" +#include "cobalt/webdriver/util/command_result.h" +#include "cobalt/webdriver/util/dispatch_command_factory.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "url/gurl.h" + +namespace cobalt { +namespace webdriver { + +TEST(FromValueTest, WindowID) { + base::DictionaryValue dict; + dict.SetString("name", "foo"); + base::Value value(std::move(dict)); + auto result = util::internal::FromValue(&value); + EXPECT_EQ(result->id(), "foo"); +} + +TEST(FromValueTest, WindowID_Fail) { + base::Value empty; + auto result = util::internal::FromValue(&empty); + EXPECT_EQ(result, base::nullopt); +} + +TEST(FromValueTest, LogType) { + base::DictionaryValue dict; + dict.SetString("type", "foo"); + base::Value value(std::move(dict)); + auto result = util::internal::FromValue(&value); + EXPECT_EQ(result->type(), "foo"); +} + +TEST(FromValueTest, LogType_Fail) { + base::Value empty; + auto result = util::internal::FromValue(&empty); + EXPECT_EQ(result, base::nullopt); +} + +} // namespace webdriver +} // namespace cobalt diff --git a/cobalt/webdriver/util/dispatch_command_factory.h b/cobalt/webdriver/util/dispatch_command_factory.h index 35afd3ee9ebb..2a5e21d7e5e2 100644 --- a/cobalt/webdriver/util/dispatch_command_factory.h +++ b/cobalt/webdriver/util/dispatch_command_factory.h @@ -85,13 +85,13 @@ std::unique_ptr ToValue(const base::Optional& value) { // Template specialization for std::string. template <> -std::unique_ptr ToValue(const std::string& value) { +inline std::unique_ptr ToValue(const std::string& value) { return std::unique_ptr(new base::Value(value)); } // Template specialization for bool. template <> -std::unique_ptr ToValue(const bool& value) { +inline std::unique_ptr ToValue(const bool& value) { return std::unique_ptr(new base::Value(value)); } @@ -101,7 +101,7 @@ std::unique_ptr ToValue(const CommandResult& command_result) { } template <> -std::unique_ptr ToValue( +inline std::unique_ptr ToValue( const CommandResult& command_result) { return std::make_unique(); } @@ -114,7 +114,7 @@ base::Optional FromValue(const base::Value* value) { } template <> -base::Optional FromValue(const base::Value* value) { +inline base::Optional FromValue(const base::Value* value) { const char kUrlKey[] = "url"; std::string url; const base::DictionaryValue* dictionary_value;