| OLD | NEW |
| 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 "services/catalog/entry.h" | 5 #include "services/catalog/entry.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 "services/shell/public/cpp/capabilities.h" | 12 #include "services/shell/public/cpp/capabilities.h" |
| 13 #include "services/shell/public/cpp/names.h" | 13 #include "services/shell/public/cpp/names.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 namespace catalog { | 16 namespace catalog { |
| 17 | 17 |
| 18 class EntryTest : public testing::Test { | 18 class EntryTest : public testing::Test { |
| 19 public: | 19 public: |
| 20 EntryTest() {} | 20 EntryTest() {} |
| 21 ~EntryTest() override {} | 21 ~EntryTest() override {} |
| 22 | 22 |
| 23 protected: | 23 protected: |
| 24 scoped_ptr<Entry> ReadEntry(const std::string& manifest, | 24 std::unique_ptr<Entry> ReadEntry(const std::string& manifest, |
| 25 scoped_ptr<base::Value>* out_value) { | 25 std::unique_ptr<base::Value>* out_value) { |
| 26 scoped_ptr<base::Value> value = ReadManifest(manifest); | 26 std::unique_ptr<base::Value> value = ReadManifest(manifest); |
| 27 base::DictionaryValue* dictionary = nullptr; | 27 base::DictionaryValue* dictionary = nullptr; |
| 28 CHECK(value->GetAsDictionary(&dictionary)); | 28 CHECK(value->GetAsDictionary(&dictionary)); |
| 29 if (out_value) | 29 if (out_value) |
| 30 *out_value = std::move(value); | 30 *out_value = std::move(value); |
| 31 return Entry::Deserialize(*dictionary); | 31 return Entry::Deserialize(*dictionary); |
| 32 } | 32 } |
| 33 | 33 |
| 34 scoped_ptr<base::Value> ReadManifest(const std::string& manifest) { | 34 std::unique_ptr<base::Value> ReadManifest(const std::string& manifest) { |
| 35 base::FilePath manifest_path; | 35 base::FilePath manifest_path; |
| 36 PathService::Get(base::DIR_SOURCE_ROOT, &manifest_path); | 36 PathService::Get(base::DIR_SOURCE_ROOT, &manifest_path); |
| 37 manifest_path = manifest_path.AppendASCII( | 37 manifest_path = manifest_path.AppendASCII( |
| 38 "services/catalog/data/" + manifest); | 38 "services/catalog/data/" + manifest); |
| 39 | 39 |
| 40 JSONFileValueDeserializer deserializer(manifest_path); | 40 JSONFileValueDeserializer deserializer(manifest_path); |
| 41 int error = 0; | 41 int error = 0; |
| 42 std::string message; | 42 std::string message; |
| 43 // TODO(beng): probably want to do more detailed error checking. This should | 43 // TODO(beng): probably want to do more detailed error checking. This should |
| 44 // be done when figuring out if to unblock connection | 44 // be done when figuring out if to unblock connection |
| 45 // completion. | 45 // completion. |
| 46 return deserializer.Deserialize(&error, &message); | 46 return deserializer.Deserialize(&error, &message); |
| 47 } | 47 } |
| 48 | 48 |
| 49 private: | 49 private: |
| 50 void SetUp() override {} | 50 void SetUp() override {} |
| 51 void TearDown() override {} | 51 void TearDown() override {} |
| 52 | 52 |
| 53 DISALLOW_COPY_AND_ASSIGN(EntryTest); | 53 DISALLOW_COPY_AND_ASSIGN(EntryTest); |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 TEST_F(EntryTest, Simple) { | 56 TEST_F(EntryTest, Simple) { |
| 57 scoped_ptr<Entry> entry = ReadEntry("simple", nullptr); | 57 std::unique_ptr<Entry> entry = ReadEntry("simple", nullptr); |
| 58 EXPECT_EQ("mojo:foo", entry->name()); | 58 EXPECT_EQ("mojo:foo", entry->name()); |
| 59 EXPECT_EQ(shell::GetNamePath(entry->name()), entry->qualifier()); | 59 EXPECT_EQ(shell::GetNamePath(entry->name()), entry->qualifier()); |
| 60 EXPECT_EQ("Foo", entry->display_name()); | 60 EXPECT_EQ("Foo", entry->display_name()); |
| 61 } | 61 } |
| 62 | 62 |
| 63 TEST_F(EntryTest, Instance) { | 63 TEST_F(EntryTest, Instance) { |
| 64 scoped_ptr<Entry> entry = ReadEntry("instance", nullptr); | 64 std::unique_ptr<Entry> entry = ReadEntry("instance", nullptr); |
| 65 EXPECT_EQ("mojo:foo", entry->name()); | 65 EXPECT_EQ("mojo:foo", entry->name()); |
| 66 EXPECT_EQ("bar", entry->qualifier()); | 66 EXPECT_EQ("bar", entry->qualifier()); |
| 67 EXPECT_EQ("Foo", entry->display_name()); | 67 EXPECT_EQ("Foo", entry->display_name()); |
| 68 } | 68 } |
| 69 | 69 |
| 70 TEST_F(EntryTest, Capabilities) { | 70 TEST_F(EntryTest, Capabilities) { |
| 71 scoped_ptr<Entry> entry = ReadEntry("capabilities", nullptr); | 71 std::unique_ptr<Entry> entry = ReadEntry("capabilities", nullptr); |
| 72 | 72 |
| 73 EXPECT_EQ("mojo:foo", entry->name()); | 73 EXPECT_EQ("mojo:foo", entry->name()); |
| 74 EXPECT_EQ("bar", entry->qualifier()); | 74 EXPECT_EQ("bar", entry->qualifier()); |
| 75 EXPECT_EQ("Foo", entry->display_name()); | 75 EXPECT_EQ("Foo", entry->display_name()); |
| 76 shell::CapabilitySpec spec; | 76 shell::CapabilitySpec spec; |
| 77 shell::CapabilityRequest request; | 77 shell::CapabilityRequest request; |
| 78 request.interfaces.insert("mojo::Bar"); | 78 request.interfaces.insert("mojo::Bar"); |
| 79 spec.required["mojo:bar"] = request; | 79 spec.required["mojo:bar"] = request; |
| 80 EXPECT_EQ(spec, entry->capabilities()); | 80 EXPECT_EQ(spec, entry->capabilities()); |
| 81 } | 81 } |
| 82 | 82 |
| 83 TEST_F(EntryTest, Serialization) { | 83 TEST_F(EntryTest, Serialization) { |
| 84 scoped_ptr<base::Value> value; | 84 std::unique_ptr<base::Value> value; |
| 85 scoped_ptr<Entry> entry = ReadEntry("serialization", &value); | 85 std::unique_ptr<Entry> entry = ReadEntry("serialization", &value); |
| 86 | 86 |
| 87 scoped_ptr<base::DictionaryValue> serialized(entry->Serialize()); | 87 std::unique_ptr<base::DictionaryValue> serialized(entry->Serialize()); |
| 88 | 88 |
| 89 // We can't just compare values, since during deserialization some of the | 89 // We can't just compare values, since during deserialization some of the |
| 90 // lists get converted to std::sets, which are sorted, so Value::Equals will | 90 // lists get converted to std::sets, which are sorted, so Value::Equals will |
| 91 // fail. | 91 // fail. |
| 92 scoped_ptr<Entry> reconstituted = Entry::Deserialize(*serialized.get()); | 92 std::unique_ptr<Entry> reconstituted = Entry::Deserialize(*serialized.get()); |
| 93 EXPECT_EQ(*entry, *reconstituted); | 93 EXPECT_EQ(*entry, *reconstituted); |
| 94 } | 94 } |
| 95 | 95 |
| 96 TEST_F(EntryTest, Malformed) { | 96 TEST_F(EntryTest, Malformed) { |
| 97 scoped_ptr<base::Value> value = ReadManifest("malformed"); | 97 std::unique_ptr<base::Value> value = ReadManifest("malformed"); |
| 98 EXPECT_FALSE(value.get()); | 98 EXPECT_FALSE(value.get()); |
| 99 } | 99 } |
| 100 | 100 |
| 101 | 101 |
| 102 } // namespace catalog | 102 } // namespace catalog |
| OLD | NEW |