Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1956)

Side by Side Diff: headless/public/domains/types_unittest.cc

Issue 2533083003: Fix the serialization for values in std::unique_ptrs. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | headless/public/internal/value_conversions.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/json/json_reader.h" 5 #include "base/json/json_reader.h"
6 #include "base/json/json_string_value_serializer.h"
6 #include "headless/public/devtools/domains/accessibility.h" 7 #include "headless/public/devtools/domains/accessibility.h"
8 #include "headless/public/devtools/domains/dom.h"
7 #include "headless/public/devtools/domains/memory.h" 9 #include "headless/public/devtools/domains/memory.h"
8 #include "headless/public/devtools/domains/page.h" 10 #include "headless/public/devtools/domains/page.h"
9 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
10 12
11 namespace headless { 13 namespace headless {
12 14
13 TEST(TypesTest, IntegerProperty) { 15 TEST(TypesTest, IntegerProperty) {
14 std::unique_ptr<page::NavigateToHistoryEntryParams> object( 16 std::unique_ptr<page::NavigateToHistoryEntryParams> object(
15 page::NavigateToHistoryEntryParams::Builder().SetEntryId(123).Build()); 17 page::NavigateToHistoryEntryParams::Builder().SetEntryId(123).Build());
16 EXPECT_TRUE(object); 18 EXPECT_TRUE(object);
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 208
207 std::unique_ptr<accessibility::AXValue> clone(object->Clone()); 209 std::unique_ptr<accessibility::AXValue> clone(object->Clone());
208 EXPECT_TRUE(clone); 210 EXPECT_TRUE(clone);
209 EXPECT_EQ(base::Value::TYPE_INTEGER, clone->GetValue()->GetType()); 211 EXPECT_EQ(base::Value::TYPE_INTEGER, clone->GetValue()->GetType());
210 212
211 int clone_value; 213 int clone_value;
212 EXPECT_TRUE(clone->GetValue()->GetAsInteger(&clone_value)); 214 EXPECT_TRUE(clone->GetValue()->GetAsInteger(&clone_value));
213 EXPECT_EQ(123, clone_value); 215 EXPECT_EQ(123, clone_value);
214 } 216 }
215 217
218 TEST(TypesTest, ComplexObjectClone) {
219 std::vector<std::unique_ptr<dom::Node>> child_nodes;
220 child_nodes.emplace_back(dom::Node::Builder()
221 .SetNodeId(1)
222 .SetBackendNodeId(2)
223 .SetNodeType(3)
224 .SetNodeName("-blink-blink")
225 .SetLocalName("-blink-blink")
226 .SetNodeValue("-blink-blink")
227 .Build());
228 std::unique_ptr<dom::SetChildNodesParams> params =
229 dom::SetChildNodesParams::Builder()
230 .SetParentId(123)
231 .SetNodes(std::move(child_nodes))
232 .Build();
233 std::unique_ptr<dom::SetChildNodesParams> clone = params->Clone();
234 ASSERT_NE(nullptr, clone);
Sami 2016/11/29 10:32:21 Please use EXPECT_NE instead of ASSERT_NE so that
tmarek 2016/11/29 10:36:18 The test will crash with a SEGV (ptr is dereferenc
Sami 2016/11/29 10:48:04 Fair point. We generally avoid asserts in tests bu
235
236 std::string orig;
237 JSONStringValueSerializer(&orig).Serialize(*params->Serialize());
238 std::string clone_value;
239 JSONStringValueSerializer(&clone_value).Serialize(*clone->Serialize());
240 EXPECT_EQ(orig, clone_value);
241 }
242
216 } // namespace headless 243 } // namespace headless
OLDNEW
« no previous file with comments | « no previous file | headless/public/internal/value_conversions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698