| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "sync/test/fake_server/fake_server_verifier.h" | 5 #include "components/sync/test/fake_server/fake_server_verifier.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <set> | 11 #include <set> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "sync/internal_api/public/base/model_type.h" | 16 #include "components/sync/base/model_type.h" |
| 17 #include "sync/test/fake_server/fake_server.h" | 17 #include "components/sync/test/fake_server/fake_server.h" |
| 18 #include "sync/test/fake_server/sessions_hierarchy.h" | 18 #include "components/sync/test/fake_server/sessions_hierarchy.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 20 |
| 21 using base::JSONWriter; | 21 using base::JSONWriter; |
| 22 using std::string; | 22 using std::string; |
| 23 using testing::AssertionFailure; | 23 using testing::AssertionFailure; |
| 24 using testing::AssertionResult; | 24 using testing::AssertionResult; |
| 25 using testing::AssertionSuccess; | 25 using testing::AssertionSuccess; |
| 26 | 26 |
| 27 namespace fake_server { | 27 namespace fake_server { |
| 28 | 28 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 if (!JSONWriter::WriteWithOptions(entities, JSONWriter::OPTIONS_PRETTY_PRINT, | 62 if (!JSONWriter::WriteWithOptions(entities, JSONWriter::OPTIONS_PRETTY_PRINT, |
| 63 &entities_str)) { | 63 &entities_str)) { |
| 64 entities_str = "Could not convert FakeServer contents to string."; | 64 entities_str = "Could not convert FakeServer contents to string."; |
| 65 } | 65 } |
| 66 return "FakeServer contents:\n" + entities_str; | 66 return "FakeServer contents:\n" + entities_str; |
| 67 } | 67 } |
| 68 | 68 |
| 69 } // namespace | 69 } // namespace |
| 70 | 70 |
| 71 FakeServerVerifier::FakeServerVerifier(FakeServer* fake_server) | 71 FakeServerVerifier::FakeServerVerifier(FakeServer* fake_server) |
| 72 : fake_server_(fake_server) { } | 72 : fake_server_(fake_server) {} |
| 73 | 73 |
| 74 FakeServerVerifier::~FakeServerVerifier() {} | 74 FakeServerVerifier::~FakeServerVerifier() {} |
| 75 | 75 |
| 76 AssertionResult FakeServerVerifier::VerifyEntityCountByType( | 76 AssertionResult FakeServerVerifier::VerifyEntityCountByType( |
| 77 size_t expected_count, | 77 size_t expected_count, |
| 78 syncer::ModelType model_type) const { | 78 syncer::ModelType model_type) const { |
| 79 std::unique_ptr<base::DictionaryValue> entities = | 79 std::unique_ptr<base::DictionaryValue> entities = |
| 80 fake_server_->GetEntitiesAsDictionaryValue(); | 80 fake_server_->GetEntitiesAsDictionaryValue(); |
| 81 if (!entities.get()) { | 81 if (!entities.get()) { |
| 82 return DictionaryCreationAssertionFailure(); | 82 return DictionaryCreationAssertionFailure(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 string model_type_string = ModelTypeToString(model_type); | 85 string model_type_string = ModelTypeToString(model_type); |
| 86 base::ListValue* entity_list = NULL; | 86 base::ListValue* entity_list = NULL; |
| 87 if (!entities->GetList(model_type_string, &entity_list)) { | 87 if (!entities->GetList(model_type_string, &entity_list)) { |
| 88 return UnknownTypeAssertionFailure(model_type_string); | 88 return UnknownTypeAssertionFailure(model_type_string); |
| 89 } else if (expected_count != entity_list->GetSize()) { | 89 } else if (expected_count != entity_list->GetSize()) { |
| 90 return VerificationCountAssertionFailure(entity_list->GetSize(), | 90 return VerificationCountAssertionFailure(entity_list->GetSize(), |
| 91 expected_count) | 91 expected_count) |
| 92 << "\n\n" | 92 << "\n\n" |
| 93 << ConvertFakeServerContentsToString(*entities); | 93 << ConvertFakeServerContentsToString(*entities); |
| 94 } | 94 } |
| 95 | 95 |
| 96 return AssertionSuccess(); | 96 return AssertionSuccess(); |
| 97 } | 97 } |
| 98 | 98 |
| 99 AssertionResult FakeServerVerifier::VerifyEntityCountByTypeAndName( | 99 AssertionResult FakeServerVerifier::VerifyEntityCountByTypeAndName( |
| 100 size_t expected_count, | 100 size_t expected_count, |
| 101 syncer::ModelType model_type, | 101 syncer::ModelType model_type, |
| 102 const string& name) const { | 102 const string& name) const { |
| 103 std::unique_ptr<base::DictionaryValue> entities = | 103 std::unique_ptr<base::DictionaryValue> entities = |
| (...skipping 10 matching lines...) Expand all Loading... |
| 114 for (const auto& entity : *entity_list) { | 114 for (const auto& entity : *entity_list) { |
| 115 if (name_value.Equals(entity.get())) | 115 if (name_value.Equals(entity.get())) |
| 116 actual_count++; | 116 actual_count++; |
| 117 } | 117 } |
| 118 } | 118 } |
| 119 | 119 |
| 120 if (!entity_list) { | 120 if (!entity_list) { |
| 121 return UnknownTypeAssertionFailure(model_type_string); | 121 return UnknownTypeAssertionFailure(model_type_string); |
| 122 } else if (actual_count != expected_count) { | 122 } else if (actual_count != expected_count) { |
| 123 return VerificationCountAssertionFailure(actual_count, expected_count) | 123 return VerificationCountAssertionFailure(actual_count, expected_count) |
| 124 << "; Name: " | 124 << "; Name: " << name << "\n\n" |
| 125 << name | 125 << ConvertFakeServerContentsToString(*entities); |
| 126 << "\n\n" | |
| 127 << ConvertFakeServerContentsToString(*entities); | |
| 128 } | 126 } |
| 129 | 127 |
| 130 return AssertionSuccess(); | 128 return AssertionSuccess(); |
| 131 } | 129 } |
| 132 | 130 |
| 133 AssertionResult FakeServerVerifier::VerifySessions( | 131 AssertionResult FakeServerVerifier::VerifySessions( |
| 134 const SessionsHierarchy& expected_sessions) { | 132 const SessionsHierarchy& expected_sessions) { |
| 135 std::vector<sync_pb::SyncEntity> sessions = | 133 std::vector<sync_pb::SyncEntity> sessions = |
| 136 fake_server_->GetSyncEntitiesByModelType(syncer::SESSIONS); | 134 fake_server_->GetSyncEntitiesByModelType(syncer::SESSIONS); |
| 137 // Look for the sessions entity containing a SessionHeader and cache all tab | 135 // Look for the sessions entity containing a SessionHeader and cache all tab |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 return AssertionFailure() << "Malformed data: Tab entity not found."; | 178 return AssertionFailure() << "Malformed data: Tab entity not found."; |
| 181 } | 179 } |
| 182 tab_urls.insert(tab_ids_to_urls[tab_id]); | 180 tab_urls.insert(tab_ids_to_urls[tab_id]); |
| 183 } | 181 } |
| 184 actual_sessions.AddWindow(tab_urls); | 182 actual_sessions.AddWindow(tab_urls); |
| 185 } | 183 } |
| 186 return VerifySessionsHierarchyEquality(expected_sessions, actual_sessions); | 184 return VerifySessionsHierarchyEquality(expected_sessions, actual_sessions); |
| 187 } | 185 } |
| 188 | 186 |
| 189 } // namespace fake_server | 187 } // namespace fake_server |
| OLD | NEW |