Commit 64150c96 authored by tmarek's avatar tmarek Committed by Commit bot

Fix the serialization for values in std::unique_ptrs.

In the ToValueImpl specialization for std::unique_ptr<T>, call ToValue
with the dereferenced type. All specializations take const&, which would
previously result in a call to ToValue(const*&), resulting in a wrong
specialization to be selected.

BUG=546953

Review-Url: https://codereview.chromium.org/2533083003
Cr-Commit-Position: refs/heads/master@{#434955}
parent ffe8e7b5
......@@ -3,7 +3,9 @@
// found in the LICENSE file.
#include "base/json/json_reader.h"
#include "base/json/json_string_value_serializer.h"
#include "headless/public/devtools/domains/accessibility.h"
#include "headless/public/devtools/domains/dom.h"
#include "headless/public/devtools/domains/memory.h"
#include "headless/public/devtools/domains/page.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -213,4 +215,29 @@ TEST(TypesTest, AnyProperty) {
EXPECT_EQ(123, clone_value);
}
TEST(TypesTest, ComplexObjectClone) {
std::vector<std::unique_ptr<dom::Node>> child_nodes;
child_nodes.emplace_back(dom::Node::Builder()
.SetNodeId(1)
.SetBackendNodeId(2)
.SetNodeType(3)
.SetNodeName("-blink-blink")
.SetLocalName("-blink-blink")
.SetNodeValue("-blink-blink")
.Build());
std::unique_ptr<dom::SetChildNodesParams> params =
dom::SetChildNodesParams::Builder()
.SetParentId(123)
.SetNodes(std::move(child_nodes))
.Build();
std::unique_ptr<dom::SetChildNodesParams> clone = params->Clone();
ASSERT_NE(nullptr, clone);
std::string orig;
JSONStringValueSerializer(&orig).Serialize(*params->Serialize());
std::string clone_value;
JSONStringValueSerializer(&clone_value).Serialize(*clone->Serialize());
EXPECT_EQ(orig, clone_value);
}
} // namespace headless
......@@ -67,7 +67,7 @@ std::unique_ptr<base::Value> ToValueImpl(const std::vector<T>& vector,
template <typename T>
std::unique_ptr<base::Value> ToValueImpl(const std::unique_ptr<T>& value,
std::unique_ptr<T>*) {
return ToValue(value.get());
return ToValue(*value);
}
// FromValue specializations for basic types.
......
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