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

Unified Diff: base/files/important_file_writer_unittest.cc

Issue 2920223002: Add additional histograms with suffixes to ImportantFileWriter. (Closed)
Patch Set: Minor fix of std::string::append. Created 3 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 | « base/files/important_file_writer.cc ('k') | components/bookmarks/browser/bookmark_storage.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/files/important_file_writer_unittest.cc
diff --git a/base/files/important_file_writer_unittest.cc b/base/files/important_file_writer_unittest.cc
index 511f5fbf5f408b038aa27687281fd7b695886cbb..e5afedbcd3487691a40bd9b95ed0ea3455f71372 100644
--- a/base/files/important_file_writer_unittest.cc
+++ b/base/files/important_file_writer_unittest.cc
@@ -15,6 +15,7 @@
#include "base/memory/ptr_util.h"
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
+#include "base/test/histogram_tester.h"
#include "base/threading/thread.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
@@ -325,4 +326,25 @@ TEST_F(ImportantFileWriterTest, DoScheduledWrite_FailToSerialize) {
EXPECT_FALSE(PathExists(writer.path()));
}
+TEST_F(ImportantFileWriterTest, WriteFileAtomicallyHistogramSuffixTest) {
+ base::HistogramTester histogram_tester;
+ EXPECT_FALSE(PathExists(file_));
+ EXPECT_TRUE(ImportantFileWriter::WriteFileAtomically(file_, "baz", "test"));
+ EXPECT_TRUE(PathExists(file_));
+ EXPECT_EQ("baz", GetFileContent(file_));
+ histogram_tester.ExpectTotalCount("ImportantFile.FileCreateError", 0);
+ histogram_tester.ExpectTotalCount("ImportantFile.FileCreateError.test", 0);
+
+ FilePath invalid_file_ = FilePath().AppendASCII("bad/../path");
+ EXPECT_FALSE(PathExists(invalid_file_));
+ EXPECT_FALSE(
+ ImportantFileWriter::WriteFileAtomically(invalid_file_, nullptr));
+ histogram_tester.ExpectTotalCount("ImportantFile.FileCreateError", 1);
+ histogram_tester.ExpectTotalCount("ImportantFile.FileCreateError.test", 0);
+ EXPECT_FALSE(
+ ImportantFileWriter::WriteFileAtomically(invalid_file_, nullptr, "test"));
+ histogram_tester.ExpectTotalCount("ImportantFile.FileCreateError", 1);
+ histogram_tester.ExpectTotalCount("ImportantFile.FileCreateError.test", 1);
+}
+
} // namespace base
« no previous file with comments | « base/files/important_file_writer.cc ('k') | components/bookmarks/browser/bookmark_storage.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698