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

Unified Diff: trunk/src/base/files/important_file_writer_unittest.cc

Issue 273243002: Revert 269415 "Introduce a new framework for back-and-forth trac..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 7 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 | « trunk/src/base/files/important_file_writer.cc ('k') | trunk/src/base/prefs/json_pref_store.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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));
« no previous file with comments | « trunk/src/base/files/important_file_writer.cc ('k') | trunk/src/base/prefs/json_pref_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698