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

Unified Diff: base/prefs/testing_pref_store.h

Issue 210063003: Refactor TestingPrefStore to make it useful to some tests of load errors and asynchrony. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adopt a non-gmock approach in the clients. Created 6 years, 9 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
Index: base/prefs/testing_pref_store.h
diff --git a/base/prefs/testing_pref_store.h b/base/prefs/testing_pref_store.h
index c6a2b8336f0c3d1dcb13dd0d40c6771f0c55292b..785f935539e7d7f99f1cad3f045c5b829b69c820 100644
--- a/base/prefs/testing_pref_store.h
+++ b/base/prefs/testing_pref_store.h
@@ -40,7 +40,7 @@ class TestingPrefStore : public PersistentPrefStore {
virtual PrefReadError GetReadError() const OVERRIDE;
virtual PersistentPrefStore::PrefReadError ReadPrefs() OVERRIDE;
virtual void ReadPrefsAsync(ReadErrorDelegate* error_delegate) OVERRIDE;
- virtual void CommitPendingWrite() OVERRIDE {}
+ virtual void CommitPendingWrite() OVERRIDE;
// Marks the store as having completed initialization.
void SetInitializationCompleted();
@@ -58,9 +58,18 @@ class TestingPrefStore : public PersistentPrefStore {
bool GetInteger(const std::string& key, int* value) const;
bool GetBoolean(const std::string& key, bool* value) const;
+ // Determines whether ReadPrefsAsync completes immediately. Defaults to false
+ // (non-blocking). To block, invoke this with true (blocking) before the call
+ // to ReadPrefsAsync. To unblock, invoke again with false (non-blocking) after
+ // the call to ReadPrefsAsync.
+ void SetBlockAsyncRead(bool block_async_read);
+
// Getter and Setter methods for setting and getting the state of the
// |TestingPrefStore|.
virtual void set_read_only(bool read_only);
+ void set_read_success(bool read_success);
+ void set_read_error(PersistentPrefStore::PrefReadError read_error);
+ bool committed() { return committed_; }
protected:
virtual ~TestingPrefStore();
@@ -72,9 +81,26 @@ class TestingPrefStore : public PersistentPrefStore {
// Flag that indicates if the PrefStore is read-only
bool read_only_;
+ // The result to pass to PrefStore::Observer::OnInitializationCompleted
+ bool read_success_;
+
+ // The result to return from ReadPrefs or ReadPrefsAsync.
+ PersistentPrefStore::PrefReadError read_error_;
+
+ // Whether a call to ReadPrefsAsync should block.
+ bool block_async_read_;
+
+ // Whether there is a pending call to ReadPrefsAsync.
+ bool pending_async_read_;
+
// Whether initialization has been completed.
bool init_complete_;
+ // Whether the store contents have been committed to disk since the last
+ // mutation.
+ bool committed_;
+
+ scoped_ptr<ReadErrorDelegate> error_delegate_;
Mattias Nissler (ping if slow) 2014/03/27 20:28:05 Why is this a scoped_ptr? In production PrefStore
erikwright (departed) 2014/03/28 12:29:22 No, see JsonPrefStore. scoped_ptr, held for the li
Mattias Nissler (ping if slow) 2014/03/28 12:32:53 Ah, right, my bad.
ObserverList<PrefStore::Observer, true> observers_;
DISALLOW_COPY_AND_ASSIGN(TestingPrefStore);

Powered by Google App Engine
This is Rietveld 408576698