diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-19 09:43:08 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-19 09:43:08 +0000 |
commit | 052313bd2f8ef1f994d65be5a5615bb2e9aa19f9 (patch) | |
tree | 883e79cee1112b90bd82890f6bffaf84688bb15f /chrome/common/important_file_writer_unittest.cc | |
parent | f98f581eb3999563a71e8cf35c68420951c9f4e1 (diff) | |
download | chromium_src-052313bd2f8ef1f994d65be5a5615bb2e9aa19f9.zip chromium_src-052313bd2f8ef1f994d65be5a5615bb2e9aa19f9.tar.gz chromium_src-052313bd2f8ef1f994d65be5a5615bb2e9aa19f9.tar.bz2 |
Move pref_{member,service} and important_file_writer from chrome/common
to chrome/browser.
This is a part of an effort to remove bad dependency of chrome/common
on chrome/browser.
TEST=unit_tests and ui_tests, just moving code
BUG=none
Review URL: http://codereview.chromium.org/621004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39428 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/important_file_writer_unittest.cc')
-rw-r--r-- | chrome/common/important_file_writer_unittest.cc | 113 |
1 files changed, 0 insertions, 113 deletions
diff --git a/chrome/common/important_file_writer_unittest.cc b/chrome/common/important_file_writer_unittest.cc deleted file mode 100644 index b3fee0d..0000000 --- a/chrome/common/important_file_writer_unittest.cc +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright (c) 2009 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/thread.h" -#include "base/time.h" -#include "chrome/browser/chrome_thread.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() : file_thread_(ChromeThread::FILE, &loop_) { } - virtual void SetUp() { - ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); - file_ = temp_dir_.path().AppendASCII("test-file"); - } - - protected: - FilePath file_; - MessageLoop loop_; - - private: - ChromeThread file_thread_; - ScopedTempDir temp_dir_; -}; - -TEST_F(ImportantFileWriterTest, Basic) { - ImportantFileWriter writer(file_); - 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_); - 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, - new MessageLoop::QuitTask(), 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_); - EXPECT_FALSE(writer.HasPendingWrite()); - DataSerializer serializer("foo"); - writer.ScheduleWrite(&serializer); - EXPECT_TRUE(writer.HasPendingWrite()); - writer.DoScheduledWrite(); - MessageLoop::current()->PostDelayedTask(FROM_HERE, - new MessageLoop::QuitTask(), 100); - MessageLoop::current()->Run(); - EXPECT_FALSE(writer.HasPendingWrite()); - ASSERT_TRUE(file_util::PathExists(writer.path())); - EXPECT_EQ("foo", GetFileContent(writer.path())); -} - -TEST_F(ImportantFileWriterTest, BatchingWrites) { - ImportantFileWriter writer(file_); - 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, - new MessageLoop::QuitTask(), 100); - MessageLoop::current()->Run(); - ASSERT_TRUE(file_util::PathExists(writer.path())); - EXPECT_EQ("baz", GetFileContent(writer.path())); -} |