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

Side by Side Diff: content/browser/mojo/merge_dictionary_unittest.cc

Issue 2335423002: Revert of Enforce capability spec renderer <--> browser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 3 months 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 | « content/browser/mojo/merge_dictionary.cc ('k') | content/browser/mojo/mojo_shell_context.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/memory/ptr_util.h"
6 #include "content/browser/mojo/merge_dictionary.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace content {
10
11 using MergeDictionaryTest = testing::Test;
12
13 TEST(MergeDictionaryTest, Merge) {
14 // |source| & |target| have three properties, "string", "list" and
15 // "dictionary", which are then merged.
16 base::DictionaryValue target;
17 target.SetString("string", "Hello, ");
18 std::unique_ptr<base::DictionaryValue> dict_value_original(
19 base::MakeUnique<base::DictionaryValue>());
20 dict_value_original->SetString("key1", "original");
21 dict_value_original->SetString("key3", "original");
22 target.Set("dictionary", std::move(dict_value_original));
23 std::unique_ptr<base::ListValue> list(base::MakeUnique<base::ListValue>());
24 list->AppendString("A");
25 list->AppendString("B");
26 target.Set("list", std::move(list));
27
28 base::DictionaryValue source;
29 source.SetString("string", "World!");
30 std::unique_ptr<base::DictionaryValue> dict_value_replacement(
31 base::MakeUnique<base::DictionaryValue>());
32 dict_value_replacement->SetString("key1", "new");
33 dict_value_replacement->SetString("key2", "new");
34 source.Set("dictionary", std::move(dict_value_replacement));
35 list = base::MakeUnique<base::ListValue>();
36 list->AppendString("C");
37 source.Set("list", std::move(list));
38
39 MergeDictionary(&target, &source);
40
41 // Simple string value should have been clobbered.
42 std::string out_string;
43 EXPECT_TRUE(target.GetString("string", &out_string));
44 EXPECT_EQ(out_string, "World!");
45
46 // Dictionary should have been merged, with key1 being clobbered, key2 added
47 // and key3 preserved.
48 base::DictionaryValue* out_dictionary = nullptr;
49 EXPECT_TRUE(target.GetDictionary("dictionary", &out_dictionary));
50 EXPECT_EQ(3u, out_dictionary->size());
51 std::string value1, value2, value3;
52 EXPECT_TRUE(out_dictionary->GetString("key1", &value1));
53 EXPECT_TRUE(out_dictionary->GetString("key2", &value2));
54 EXPECT_TRUE(out_dictionary->GetString("key3", &value3));
55 EXPECT_EQ(value1, "new");
56 EXPECT_EQ(value2, "new");
57 EXPECT_EQ(value3, "original");
58
59 // List should have been merged, with the items from source appended to the
60 // items from target.
61 base::ListValue* out_list = nullptr;
62 EXPECT_TRUE(target.GetList("list", &out_list));
63 EXPECT_EQ(3u, out_list->GetSize());
64 std::string a, b, c;
65 EXPECT_TRUE(out_list->GetString(0, &a));
66 EXPECT_TRUE(out_list->GetString(1, &b));
67 EXPECT_TRUE(out_list->GetString(2, &c));
68 EXPECT_EQ("A", a);
69 EXPECT_EQ("B", b);
70 EXPECT_EQ("C", c);
71 }
72
73 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/mojo/merge_dictionary.cc ('k') | content/browser/mojo/mojo_shell_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698