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

Side by Side Diff: mojo/services/catalog/builder_unittest.cc

Issue 1775113003: Morph CapabilityFilter into caps::Capabilities, which supports capability classes (yet unimplemente… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@44cattests
Patch Set: . Created 4 years, 9 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 | « mojo/services/catalog/builder.cc ('k') | mojo/services/catalog/catalog.cc » ('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 "mojo/services/catalog/builder.h" 5 #include "mojo/services/catalog/builder.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/json/json_file_value_serializer.h" 8 #include "base/json/json_file_value_serializer.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "mojo/shell/public/cpp/capabilities.h"
12 #include "mojo/shell/public/cpp/names.h" 13 #include "mojo/shell/public/cpp/names.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
16 namespace catalog {
17
15 class BuilderTest : public testing::Test { 18 class BuilderTest : public testing::Test {
16 public: 19 public:
17 BuilderTest() {} 20 BuilderTest() {}
18 ~BuilderTest() override {} 21 ~BuilderTest() override {}
19 22
20 protected: 23 protected:
24 scoped_ptr<base::Value> ReadEntry(const std::string& manifest, Entry* entry) {
25 DCHECK(entry);
26 scoped_ptr<base::Value> value = ReadManifest(manifest);
27 base::DictionaryValue* dictionary = nullptr;
28 CHECK(value->GetAsDictionary(&dictionary));
29 *entry = BuildEntry(*dictionary);
30 return value;
31 }
32
21 scoped_ptr<base::Value> ReadManifest(const std::string& manifest) { 33 scoped_ptr<base::Value> ReadManifest(const std::string& manifest) {
22 base::FilePath manifest_path; 34 base::FilePath manifest_path;
23 PathService::Get(base::DIR_SOURCE_ROOT, &manifest_path); 35 PathService::Get(base::DIR_SOURCE_ROOT, &manifest_path);
24 manifest_path = manifest_path.AppendASCII( 36 manifest_path = manifest_path.AppendASCII(
25 "mojo/services/catalog/data/" + manifest); 37 "mojo/services/catalog/data/" + manifest);
26 38
27 JSONFileValueDeserializer deserializer(manifest_path); 39 JSONFileValueDeserializer deserializer(manifest_path);
28 int error = 0; 40 int error = 0;
29 std::string message; 41 std::string message;
30 // TODO(beng): probably want to do more detailed error checking. This should 42 // TODO(beng): probably want to do more detailed error checking. This should
31 // be done when figuring out if to unblock connection 43 // be done when figuring out if to unblock connection
32 // completion. 44 // completion.
33 return deserializer.Deserialize(&error, &message); 45 return deserializer.Deserialize(&error, &message);
34 } 46 }
35 47
36 private: 48 private:
37 void SetUp() override {} 49 void SetUp() override {}
38 void TearDown() override {} 50 void TearDown() override {}
39 51
40 DISALLOW_COPY_AND_ASSIGN(BuilderTest); 52 DISALLOW_COPY_AND_ASSIGN(BuilderTest);
41 }; 53 };
42 54
43 namespace catalog {
44
45 TEST_F(BuilderTest, Simple) { 55 TEST_F(BuilderTest, Simple) {
46 scoped_ptr<base::Value> value = ReadManifest("simple"); 56 Entry entry;
47 base::DictionaryValue* dictionary = nullptr; 57 ReadEntry("simple", &entry);
48 CHECK(value->GetAsDictionary(&dictionary));
49 Entry entry = BuildEntry(*dictionary);
50 58
51 EXPECT_EQ("mojo:foo", entry.name); 59 EXPECT_EQ("mojo:foo", entry.name);
52 EXPECT_EQ(mojo::GetNamePath(entry.name), entry.qualifier); 60 EXPECT_EQ(mojo::GetNamePath(entry.name), entry.qualifier);
53 EXPECT_EQ("Foo", entry.display_name); 61 EXPECT_EQ("Foo", entry.display_name);
54 } 62 }
55 63
56 TEST_F(BuilderTest, Instance) { 64 TEST_F(BuilderTest, Instance) {
57 scoped_ptr<base::Value> value = ReadManifest("instance"); 65 Entry entry;
58 base::DictionaryValue* dictionary = nullptr; 66 ReadEntry("instance", &entry);
59 CHECK(value->GetAsDictionary(&dictionary));
60 Entry entry = BuildEntry(*dictionary);
61 67
62 EXPECT_EQ("mojo:foo", entry.name); 68 EXPECT_EQ("mojo:foo", entry.name);
63 EXPECT_EQ("bar", entry.qualifier); 69 EXPECT_EQ("bar", entry.qualifier);
64 EXPECT_EQ("Foo", entry.display_name); 70 EXPECT_EQ("Foo", entry.display_name);
65 } 71 }
66 72
67 TEST_F(BuilderTest, Capabilities) { 73 TEST_F(BuilderTest, Capabilities) {
68 scoped_ptr<base::Value> value = ReadManifest("capabilities"); 74 Entry entry;
69 base::DictionaryValue* dictionary = nullptr; 75 ReadEntry("capabilities", &entry);
70 CHECK(value->GetAsDictionary(&dictionary));
71 Entry entry = BuildEntry(*dictionary);
72 76
73 EXPECT_EQ("mojo:foo", entry.name); 77 EXPECT_EQ("mojo:foo", entry.name);
74 EXPECT_EQ("bar", entry.qualifier); 78 EXPECT_EQ("bar", entry.qualifier);
75 EXPECT_EQ("Foo", entry.display_name); 79 EXPECT_EQ("Foo", entry.display_name);
76 CapabilityFilter filter; 80 mojo::CapabilitySpec spec;
77 AllowedInterfaces interfaces; 81 mojo::CapabilityRequest request;
78 interfaces.insert("mojo::Bar"); 82 request.interfaces.insert("mojo::Bar");
79 filter["mojo:bar"] = interfaces; 83 spec.required["mojo:bar"] = request;
80 EXPECT_EQ(filter, entry.capabilities); 84 EXPECT_EQ(spec, entry.capabilities);
85 }
86
87 TEST_F(BuilderTest, Serialization) {
88 Entry entry;
89 scoped_ptr<base::Value> value = ReadEntry("serialization", &entry);
90
91 scoped_ptr<base::DictionaryValue> serialized(SerializeEntry(entry));
92
93 // We can't just compare values, since during deserialization some of the
94 // lists get converted to std::sets, which are sorted, so Value::Equals will
95 // fail.
96 Entry reconstituted = BuildEntry(*serialized.get());
97 EXPECT_EQ(entry, reconstituted);
81 } 98 }
82 99
83 TEST_F(BuilderTest, Malformed) { 100 TEST_F(BuilderTest, Malformed) {
84 scoped_ptr<base::Value> value = ReadManifest("malformed"); 101 scoped_ptr<base::Value> value = ReadManifest("malformed");
85 EXPECT_FALSE(value.get()); 102 EXPECT_FALSE(value.get());
86 } 103 }
87 104
88 105
89 } // namespace catalog 106 } // namespace catalog
OLDNEW
« no previous file with comments | « mojo/services/catalog/builder.cc ('k') | mojo/services/catalog/catalog.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698