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

Unified Diff: extensions/browser/computed_hashes_unittest.cc

Issue 361523002: Fix some more problems with windows paths in content verification (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « extensions/browser/computed_hashes.cc ('k') | extensions/browser/content_hash_fetcher.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/browser/computed_hashes_unittest.cc
diff --git a/extensions/browser/computed_hashes_unittest.cc b/extensions/browser/computed_hashes_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..da36a903e3d8795eb161b999a1d7562694f536ad
--- /dev/null
+++ b/extensions/browser/computed_hashes_unittest.cc
@@ -0,0 +1,62 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/files/file_path.h"
+#include "base/files/scoped_temp_dir.h"
+#include "crypto/sha2.h"
+#include "extensions/browser/computed_hashes.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace extensions {
+
+TEST(ComputedHashes, ComputedHashes) {
+ base::ScopedTempDir scoped_dir;
+ ASSERT_TRUE(scoped_dir.CreateUniqueTempDir());
+ base::FilePath computed_hashes =
+ scoped_dir.path().AppendASCII("computed_hashes.json");
+
+ // We'll add hashes for 2 files, one of which uses a subdirectory
+ // path. The first file will have a list of 1 block hash, and the
+ // second file will have 2 block hashes.
+ base::FilePath path1(FILE_PATH_LITERAL("foo.txt"));
+ base::FilePath path2 =
+ base::FilePath(FILE_PATH_LITERAL("foo")).AppendASCII("bar.txt");
+ std::vector<std::string> hashes1;
+ std::vector<std::string> hashes2;
+ hashes1.push_back(crypto::SHA256HashString("first"));
+ hashes2.push_back(crypto::SHA256HashString("second"));
+ hashes2.push_back(crypto::SHA256HashString("third"));
+
+ // Write them into the file.
+ ComputedHashes::Writer writer;
+ writer.AddHashes(path1, 4096, hashes1);
+ writer.AddHashes(path2, 2048, hashes2);
+ EXPECT_TRUE(writer.WriteToFile(computed_hashes));
+
+ // Now read them back again and assert that we got what we wrote.
+ ComputedHashes::Reader reader;
+ std::vector<std::string> read_hashes1;
+ std::vector<std::string> read_hashes2;
+ EXPECT_TRUE(reader.InitFromFile(computed_hashes));
+
+ int block_size = 0;
+ EXPECT_TRUE(reader.GetHashes(path1, &block_size, &read_hashes1));
+ EXPECT_EQ(block_size, 4096);
+ block_size = 0;
+ EXPECT_TRUE(reader.GetHashes(path2, &block_size, &read_hashes2));
+ EXPECT_EQ(block_size, 2048);
+
+ EXPECT_EQ(hashes1, read_hashes1);
+ EXPECT_EQ(hashes2, read_hashes2);
+
+ // Finally make sure that we can retrieve the hashes for the subdir
+ // path even when that path contains forward slashes (on windows).
+ base::FilePath path2_fwd_slashes =
+ base::FilePath::FromUTF8Unsafe("foo/bar.txt");
+ block_size = 0;
+ EXPECT_TRUE(reader.GetHashes(path2_fwd_slashes, &block_size, &read_hashes2));
+ EXPECT_EQ(hashes2, read_hashes2);
+}
+
+} // namespace extensions
« no previous file with comments | « extensions/browser/computed_hashes.cc ('k') | extensions/browser/content_hash_fetcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698