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

Side by Side Diff: extensions/browser/content_hash_tree_unittest.cc

Issue 1909773002: Convert //extensions/browser from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 8 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 | « extensions/browser/content_hash_tree.cc ('k') | extensions/browser/content_verifier.h » ('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 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 "base/memory/scoped_ptr.h" 5 #include "extensions/browser/content_hash_tree.h"
6
7 #include <memory>
8
6 #include "base/stl_util.h" 9 #include "base/stl_util.h"
7 #include "crypto/secure_hash.h" 10 #include "crypto/secure_hash.h"
8 #include "crypto/sha2.h" 11 #include "crypto/sha2.h"
9 #include "extensions/browser/content_hash_tree.h"
10 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
11 13
12 using crypto::kSHA256Length; 14 using crypto::kSHA256Length;
13 using crypto::SecureHash; 15 using crypto::SecureHash;
14 16
15 // Helper to return a fake sha256 signature based on a seed. 17 // Helper to return a fake sha256 signature based on a seed.
16 static std::string FakeSignatureWithSeed(int seed) { 18 static std::string FakeSignatureWithSeed(int seed) {
17 std::string input; 19 std::string input;
18 for (int i = 0; i < seed * 3; i++) { 20 for (int i = 0; i < seed * 3; i++) {
19 input.push_back(static_cast<char>(((i + 19) * seed) % 256)); 21 input.push_back(static_cast<char>(((i + 19) * seed) % 256));
(...skipping 11 matching lines...) Expand all
31 // One node. 33 // One node.
32 std::string node1 = FakeSignatureWithSeed(1); 34 std::string node1 = FakeSignatureWithSeed(1);
33 nodes.push_back(node1); 35 nodes.push_back(node1);
34 EXPECT_EQ(node1, ComputeTreeHashRoot(nodes, 16)); 36 EXPECT_EQ(node1, ComputeTreeHashRoot(nodes, 16));
35 37
36 // Two nodes. 38 // Two nodes.
37 std::string node2 = FakeSignatureWithSeed(2); 39 std::string node2 = FakeSignatureWithSeed(2);
38 nodes.push_back(node2); 40 nodes.push_back(node2);
39 41
40 std::string expected(kSHA256Length, 0); 42 std::string expected(kSHA256Length, 0);
41 scoped_ptr<SecureHash> hash(SecureHash::Create(SecureHash::SHA256)); 43 std::unique_ptr<SecureHash> hash(SecureHash::Create(SecureHash::SHA256));
42 hash->Update(node1.data(), node1.size()); 44 hash->Update(node1.data(), node1.size());
43 hash->Update(node2.data(), node2.size()); 45 hash->Update(node2.data(), node2.size());
44 hash->Finish(string_as_array(&expected), expected.size()); 46 hash->Finish(string_as_array(&expected), expected.size());
45 EXPECT_EQ(expected, ComputeTreeHashRoot(nodes, 16)); 47 EXPECT_EQ(expected, ComputeTreeHashRoot(nodes, 16));
46 } 48 }
47 49
48 TEST(ContentHashTreeTest, HashTreeMultipleLevels) { 50 TEST(ContentHashTreeTest, HashTreeMultipleLevels) {
49 std::vector<std::string> nodes; 51 std::vector<std::string> nodes;
50 for (int i = 0; i < 3; i++) { 52 for (int i = 0; i < 3; i++) {
51 std::string node; 53 std::string node;
(...skipping 16 matching lines...) Expand all
68 // 1 2 3 70 // 1 2 3
69 // 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
70 // hash of 4 and 5. 72 // hash of 4 and 5.
71 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]);
72 std::string hash_of_third = crypto::SHA256HashString(nodes[2]); 74 std::string hash_of_third = crypto::SHA256HashString(nodes[2]);
73 expected = crypto::SHA256HashString(hash_of_first_2 + hash_of_third); 75 expected = crypto::SHA256HashString(hash_of_first_2 + hash_of_third);
74 EXPECT_EQ(expected, ComputeTreeHashRoot(nodes, 2)); 76 EXPECT_EQ(expected, ComputeTreeHashRoot(nodes, 2));
75 } 77 }
76 78
77 } // namespace extensions 79 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/content_hash_tree.cc ('k') | extensions/browser/content_verifier.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698