| 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 "extensions/browser/content_hash_tree.h" | 5 #include "extensions/browser/content_hash_tree.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "crypto/secure_hash.h" | 10 #include "crypto/secure_hash.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 EXPECT_EQ(node1, ComputeTreeHashRoot(nodes, 16)); | 36 EXPECT_EQ(node1, ComputeTreeHashRoot(nodes, 16)); |
| 37 | 37 |
| 38 // Two nodes. | 38 // Two nodes. |
| 39 std::string node2 = FakeSignatureWithSeed(2); | 39 std::string node2 = FakeSignatureWithSeed(2); |
| 40 nodes.push_back(node2); | 40 nodes.push_back(node2); |
| 41 | 41 |
| 42 std::string expected(kSHA256Length, 0); | 42 std::string expected(kSHA256Length, 0); |
| 43 std::unique_ptr<SecureHash> hash(SecureHash::Create(SecureHash::SHA256)); | 43 std::unique_ptr<SecureHash> hash(SecureHash::Create(SecureHash::SHA256)); |
| 44 hash->Update(node1.data(), node1.size()); | 44 hash->Update(node1.data(), node1.size()); |
| 45 hash->Update(node2.data(), node2.size()); | 45 hash->Update(node2.data(), node2.size()); |
| 46 hash->Finish(string_as_array(&expected), expected.size()); | 46 hash->Finish(base::string_as_array(&expected), expected.size()); |
| 47 EXPECT_EQ(expected, ComputeTreeHashRoot(nodes, 16)); | 47 EXPECT_EQ(expected, ComputeTreeHashRoot(nodes, 16)); |
| 48 } | 48 } |
| 49 | 49 |
| 50 TEST(ContentHashTreeTest, HashTreeMultipleLevels) { | 50 TEST(ContentHashTreeTest, HashTreeMultipleLevels) { |
| 51 std::vector<std::string> nodes; | 51 std::vector<std::string> nodes; |
| 52 for (int i = 0; i < 3; i++) { | 52 for (int i = 0; i < 3; i++) { |
| 53 std::string node; | 53 std::string node; |
| 54 nodes.push_back(FakeSignatureWithSeed(i)); | 54 nodes.push_back(FakeSignatureWithSeed(i)); |
| 55 } | 55 } |
| 56 | 56 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 70 // 1 2 3 | 70 // 1 2 3 |
| 71 // where 4 is the hash of 1 and 2, 5 is the hash of 3, and 6 is the | 71 // where 4 is the hash of 1 and 2, 5 is the hash of 3, and 6 is the |
| 72 // hash of 4 and 5. | 72 // hash of 4 and 5. |
| 73 std::string hash_of_first_2 = crypto::SHA256HashString(nodes[0] + nodes[1]); | 73 std::string hash_of_first_2 = crypto::SHA256HashString(nodes[0] + nodes[1]); |
| 74 std::string hash_of_third = crypto::SHA256HashString(nodes[2]); | 74 std::string hash_of_third = crypto::SHA256HashString(nodes[2]); |
| 75 expected = crypto::SHA256HashString(hash_of_first_2 + hash_of_third); | 75 expected = crypto::SHA256HashString(hash_of_first_2 + hash_of_third); |
| 76 EXPECT_EQ(expected, ComputeTreeHashRoot(nodes, 2)); | 76 EXPECT_EQ(expected, ComputeTreeHashRoot(nodes, 2)); |
| 77 } | 77 } |
| 78 | 78 |
| 79 } // namespace extensions | 79 } // namespace extensions |
| OLD | NEW |