Index: trunk/src/base/files/important_file_writer_unittest.cc |
=================================================================== |
--- trunk/src/base/files/important_file_writer_unittest.cc (revision 269437) |
+++ trunk/src/base/files/important_file_writer_unittest.cc (working copy) |
@@ -4,7 +4,6 @@ |
#include "base/files/important_file_writer.h" |
-#include "base/bind.h" |
#include "base/compiler_specific.h" |
#include "base/file_util.h" |
#include "base/files/file_path.h" |
@@ -42,41 +41,6 @@ |
const std::string data_; |
}; |
-class SuccessfulWriteObserver { |
- public: |
- SuccessfulWriteObserver() : successful_write_observed_(false) {} |
- |
- // Register on_successful_write() to be called on the next successful write |
- // of |writer|. |
- void ObserveNextSuccessfulWrite(ImportantFileWriter* writer); |
- |
- // Returns true if a successful write was observed via on_successful_write() |
- // and resets the observation state to false regardless. |
- bool GetAndResetObservationState(); |
- |
- private: |
- void on_successful_write() { |
- EXPECT_FALSE(successful_write_observed_); |
- successful_write_observed_ = true; |
- } |
- |
- bool successful_write_observed_; |
- |
- DISALLOW_COPY_AND_ASSIGN(SuccessfulWriteObserver); |
-}; |
- |
-void SuccessfulWriteObserver::ObserveNextSuccessfulWrite( |
- ImportantFileWriter* writer) { |
- writer->RegisterOnNextSuccessfulWriteCallback(base::Bind( |
- &SuccessfulWriteObserver::on_successful_write, base::Unretained(this))); |
-} |
- |
-bool SuccessfulWriteObserver::GetAndResetObservationState() { |
- bool was_successful_write_observed = successful_write_observed_; |
- successful_write_observed_ = false; |
- return was_successful_write_observed; |
-} |
- |
} // namespace |
class ImportantFileWriterTest : public testing::Test { |
@@ -88,7 +52,6 @@ |
} |
protected: |
- SuccessfulWriteObserver successful_write_observer_; |
FilePath file_; |
MessageLoop loop_; |
@@ -99,49 +62,13 @@ |
TEST_F(ImportantFileWriterTest, Basic) { |
ImportantFileWriter writer(file_, MessageLoopProxy::current().get()); |
EXPECT_FALSE(PathExists(writer.path())); |
- EXPECT_FALSE(successful_write_observer_.GetAndResetObservationState()); |
writer.WriteNow("foo"); |
RunLoop().RunUntilIdle(); |
- EXPECT_FALSE(successful_write_observer_.GetAndResetObservationState()); |
ASSERT_TRUE(PathExists(writer.path())); |
EXPECT_EQ("foo", GetFileContent(writer.path())); |
} |
-TEST_F(ImportantFileWriterTest, BasicWithSuccessfulWriteObserver) { |
- ImportantFileWriter writer(file_, MessageLoopProxy::current().get()); |
- EXPECT_FALSE(PathExists(writer.path())); |
- EXPECT_FALSE(successful_write_observer_.GetAndResetObservationState()); |
- successful_write_observer_.ObserveNextSuccessfulWrite(&writer); |
- writer.WriteNow("foo"); |
- RunLoop().RunUntilIdle(); |
- |
- // Confirm that the observer is invoked. |
- EXPECT_TRUE(successful_write_observer_.GetAndResetObservationState()); |
- ASSERT_TRUE(PathExists(writer.path())); |
- EXPECT_EQ("foo", GetFileContent(writer.path())); |
- |
- // Confirm that re-installing the observer works for another write. |
- EXPECT_FALSE(successful_write_observer_.GetAndResetObservationState()); |
- successful_write_observer_.ObserveNextSuccessfulWrite(&writer); |
- writer.WriteNow("bar"); |
- RunLoop().RunUntilIdle(); |
- |
- EXPECT_TRUE(successful_write_observer_.GetAndResetObservationState()); |
- ASSERT_TRUE(PathExists(writer.path())); |
- EXPECT_EQ("bar", GetFileContent(writer.path())); |
- |
- // Confirm that writing again without re-installing the observer doesn't |
- // result in a notification. |
- EXPECT_FALSE(successful_write_observer_.GetAndResetObservationState()); |
- writer.WriteNow("baz"); |
- RunLoop().RunUntilIdle(); |
- |
- EXPECT_FALSE(successful_write_observer_.GetAndResetObservationState()); |
- ASSERT_TRUE(PathExists(writer.path())); |
- EXPECT_EQ("baz", GetFileContent(writer.path())); |
-} |
- |
TEST_F(ImportantFileWriterTest, ScheduleWrite) { |
ImportantFileWriter writer(file_, MessageLoopProxy::current().get()); |
writer.set_commit_interval(TimeDelta::FromMilliseconds(25)); |