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

Unified Diff: chrome/common/important_file_writer_unittest.cc

Issue 11227026: Move ImportantFileWriter to base/. It now has two consumers, base/prefs and chrome/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Win build for real. Created 8 years, 2 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 | « chrome/common/important_file_writer.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/important_file_writer_unittest.cc
diff --git a/chrome/common/important_file_writer_unittest.cc b/chrome/common/important_file_writer_unittest.cc
deleted file mode 100644
index 35b2b44bc1be2b69cd43722303e0cc0ac6de3fe1..0000000000000000000000000000000000000000
--- a/chrome/common/important_file_writer_unittest.cc
+++ /dev/null
@@ -1,122 +0,0 @@
-// Copyright (c) 2012 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 "chrome/common/important_file_writer.h"
-
-#include "base/compiler_specific.h"
-#include "base/file_path.h"
-#include "base/file_util.h"
-#include "base/logging.h"
-#include "base/message_loop.h"
-#include "base/scoped_temp_dir.h"
-#include "base/threading/thread.h"
-#include "base/time.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace {
-
-std::string GetFileContent(const FilePath& path) {
- std::string content;
- if (!file_util::ReadFileToString(path, &content)) {
- NOTREACHED();
- }
- return content;
-}
-
-class DataSerializer : public ImportantFileWriter::DataSerializer {
- public:
- explicit DataSerializer(const std::string& data) : data_(data) {
- }
-
- virtual bool SerializeData(std::string* output) {
- output->assign(data_);
- return true;
- }
-
- private:
- const std::string data_;
-};
-
-} // namespace
-
-class ImportantFileWriterTest : public testing::Test {
- public:
- ImportantFileWriterTest() { }
- virtual void SetUp() {
- ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
- file_ = temp_dir_.path().AppendASCII("test-file");
- }
-
- protected:
- FilePath file_;
- MessageLoop loop_;
-
- private:
- ScopedTempDir temp_dir_;
-};
-
-TEST_F(ImportantFileWriterTest, Basic) {
- ImportantFileWriter writer(file_,
- base::MessageLoopProxy::current());
- EXPECT_FALSE(file_util::PathExists(writer.path()));
- writer.WriteNow("foo");
- loop_.RunAllPending();
-
- ASSERT_TRUE(file_util::PathExists(writer.path()));
- EXPECT_EQ("foo", GetFileContent(writer.path()));
-}
-
-TEST_F(ImportantFileWriterTest, ScheduleWrite) {
- ImportantFileWriter writer(file_,
- base::MessageLoopProxy::current());
- writer.set_commit_interval(base::TimeDelta::FromMilliseconds(25));
- EXPECT_FALSE(writer.HasPendingWrite());
- DataSerializer serializer("foo");
- writer.ScheduleWrite(&serializer);
- EXPECT_TRUE(writer.HasPendingWrite());
- MessageLoop::current()->PostDelayedTask(
- FROM_HERE,
- MessageLoop::QuitClosure(),
- base::TimeDelta::FromMilliseconds(100));
- MessageLoop::current()->Run();
- EXPECT_FALSE(writer.HasPendingWrite());
- ASSERT_TRUE(file_util::PathExists(writer.path()));
- EXPECT_EQ("foo", GetFileContent(writer.path()));
-}
-
-TEST_F(ImportantFileWriterTest, DoScheduledWrite) {
- ImportantFileWriter writer(file_,
- base::MessageLoopProxy::current());
- EXPECT_FALSE(writer.HasPendingWrite());
- DataSerializer serializer("foo");
- writer.ScheduleWrite(&serializer);
- EXPECT_TRUE(writer.HasPendingWrite());
- writer.DoScheduledWrite();
- MessageLoop::current()->PostDelayedTask(
- FROM_HERE,
- MessageLoop::QuitClosure(),
- base::TimeDelta::FromMilliseconds(100));
- MessageLoop::current()->Run();
- EXPECT_FALSE(writer.HasPendingWrite());
- ASSERT_TRUE(file_util::PathExists(writer.path()));
- EXPECT_EQ("foo", GetFileContent(writer.path()));
-}
-
-// Flaky - http://crbug.com/109292
-TEST_F(ImportantFileWriterTest, DISABLED_BatchingWrites) {
- ImportantFileWriter writer(file_,
- base::MessageLoopProxy::current());
- writer.set_commit_interval(base::TimeDelta::FromMilliseconds(25));
- DataSerializer foo("foo"), bar("bar"), baz("baz");
- writer.ScheduleWrite(&foo);
- writer.ScheduleWrite(&bar);
- writer.ScheduleWrite(&baz);
- MessageLoop::current()->PostDelayedTask(
- FROM_HERE,
- MessageLoop::QuitClosure(),
- base::TimeDelta::FromMilliseconds(100));
- MessageLoop::current()->Run();
- ASSERT_TRUE(file_util::PathExists(writer.path()));
- EXPECT_EQ("baz", GetFileContent(writer.path()));
-}
« no previous file with comments | « chrome/common/important_file_writer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698