| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/pickle.h" | 5 #include "base/pickle.h" |
| 6 #include "components/nacl/browser/nacl_validation_cache.h" | 6 #include "components/nacl/browser/nacl_validation_cache.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 8 |
| 9 namespace nacl { | 9 namespace nacl { |
| 10 | 10 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 cache2.QueryKnownToValidate(sig2, false); | 137 cache2.QueryKnownToValidate(sig2, false); |
| 138 ASSERT_FALSE(IsIdentical(cache1, cache2)); | 138 ASSERT_FALSE(IsIdentical(cache1, cache2)); |
| 139 } | 139 } |
| 140 | 140 |
| 141 TEST_F(NaClValidationCacheTest, SerializeDeserialize) { | 141 TEST_F(NaClValidationCacheTest, SerializeDeserialize) { |
| 142 std::string key(key2); | 142 std::string key(key2); |
| 143 cache1.SetValidationCacheKey(key); | 143 cache1.SetValidationCacheKey(key); |
| 144 cache1.SetKnownToValidate(sig1); | 144 cache1.SetKnownToValidate(sig1); |
| 145 cache1.SetKnownToValidate(sig2); | 145 cache1.SetKnownToValidate(sig2); |
| 146 | 146 |
| 147 Pickle pickle; | 147 base::Pickle pickle; |
| 148 cache1.Serialize(&pickle); | 148 cache1.Serialize(&pickle); |
| 149 ASSERT_TRUE(cache2.Deserialize(&pickle)); | 149 ASSERT_TRUE(cache2.Deserialize(&pickle)); |
| 150 ASSERT_EQ(2, (int) cache2.size()); | 150 ASSERT_EQ(2, (int) cache2.size()); |
| 151 ASSERT_TRUE(IsIdentical(cache1, cache2)); | 151 ASSERT_TRUE(IsIdentical(cache1, cache2)); |
| 152 } | 152 } |
| 153 | 153 |
| 154 TEST_F(NaClValidationCacheTest, SerializeDeserializeTruncated) { | 154 TEST_F(NaClValidationCacheTest, SerializeDeserializeTruncated) { |
| 155 std::string key(key2); | 155 std::string key(key2); |
| 156 cache1.SetValidationCacheKey(key); | 156 cache1.SetValidationCacheKey(key); |
| 157 cache1.SetKnownToValidate(sig1); | 157 cache1.SetKnownToValidate(sig1); |
| 158 cache1.SetKnownToValidate(sig2); | 158 cache1.SetKnownToValidate(sig2); |
| 159 | 159 |
| 160 Pickle pickle; | 160 base::Pickle pickle; |
| 161 cache1.Serialize(&pickle); | 161 cache1.Serialize(&pickle); |
| 162 Pickle truncated(static_cast<const char*>(pickle.data()), pickle.size()-20); | 162 base::Pickle truncated(static_cast<const char*>(pickle.data()), |
| 163 pickle.size() - 20); |
| 163 ASSERT_FALSE(cache2.Deserialize(&truncated)); | 164 ASSERT_FALSE(cache2.Deserialize(&truncated)); |
| 164 ASSERT_EQ(0, (int) cache2.size()); | 165 ASSERT_EQ(0, (int) cache2.size()); |
| 165 } | 166 } |
| 166 | 167 |
| 167 TEST_F(NaClValidationCacheTest, DeserializeBadKey) { | 168 TEST_F(NaClValidationCacheTest, DeserializeBadKey) { |
| 168 std::string key(sig1); // Too short, will cause the deserialization to error. | 169 std::string key(sig1); // Too short, will cause the deserialization to error. |
| 169 cache1.SetValidationCacheKey(key); | 170 cache1.SetValidationCacheKey(key); |
| 170 cache1.SetKnownToValidate(sig1); | 171 cache1.SetKnownToValidate(sig1); |
| 171 cache1.SetKnownToValidate(sig2); | 172 cache1.SetKnownToValidate(sig2); |
| 172 | 173 |
| 173 Pickle pickle; | 174 base::Pickle pickle; |
| 174 cache1.Serialize(&pickle); | 175 cache1.Serialize(&pickle); |
| 175 ASSERT_FALSE(cache2.Deserialize(&pickle)); | 176 ASSERT_FALSE(cache2.Deserialize(&pickle)); |
| 176 ASSERT_EQ(0, (int) cache2.size()); | 177 ASSERT_EQ(0, (int) cache2.size()); |
| 177 } | 178 } |
| 178 | 179 |
| 179 TEST_F(NaClValidationCacheTest, DeserializeNothing) { | 180 TEST_F(NaClValidationCacheTest, DeserializeNothing) { |
| 180 cache1.SetKnownToValidate(sig1); | 181 cache1.SetKnownToValidate(sig1); |
| 181 Pickle pickle("", 0); | 182 base::Pickle pickle("", 0); |
| 182 ASSERT_FALSE(cache1.Deserialize(&pickle)); | 183 ASSERT_FALSE(cache1.Deserialize(&pickle)); |
| 183 ASSERT_EQ(0, (int) cache1.size()); | 184 ASSERT_EQ(0, (int) cache1.size()); |
| 184 } | 185 } |
| 185 | 186 |
| 186 TEST_F(NaClValidationCacheTest, DeserializeJunk) { | 187 TEST_F(NaClValidationCacheTest, DeserializeJunk) { |
| 187 cache1.SetKnownToValidate(sig1); | 188 cache1.SetKnownToValidate(sig1); |
| 188 Pickle pickle(key1, strlen(key1)); | 189 base::Pickle pickle(key1, strlen(key1)); |
| 189 ASSERT_FALSE(cache1.Deserialize(&pickle)); | 190 ASSERT_FALSE(cache1.Deserialize(&pickle)); |
| 190 ASSERT_EQ(0, (int) cache1.size()); | 191 ASSERT_EQ(0, (int) cache1.size()); |
| 191 } | 192 } |
| 192 | 193 |
| 193 } | 194 } |
| OLD | NEW |