Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / value_store / testing_value_store.h
blob53fc7c81f1c3c7645b1f85597b69919a122066e6
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_VALUE_STORE_TESTING_VALUE_STORE_H_
6 #define CHROME_BROWSER_VALUE_STORE_TESTING_VALUE_STORE_H_
8 #include "base/compiler_specific.h"
9 #include "chrome/browser/value_store/value_store.h"
11 // ValueStore for testing, with an in-memory storage but the ability to
12 // optionally fail all operations.
13 class TestingValueStore : public ValueStore {
14 public:
15 TestingValueStore();
16 virtual ~TestingValueStore();
18 // Sets the error code for requests. If OK, errors won't be thrown.
19 // Defaults to OK.
20 void set_error_code(ErrorCode error_code) { error_code_ = error_code; }
22 // Accessors for the number of reads/writes done by this value store. Each
23 // Get* operation (except for the BytesInUse ones) counts as one read, and
24 // each Set*/Remove/Clear operation counts as one write. This is useful in
25 // tests seeking to assert that some number of reads/writes to their
26 // underlying value store have (or have not) happened.
27 int read_count() { return read_count_; }
28 int write_count() { return write_count_; }
30 // ValueStore implementation.
31 virtual size_t GetBytesInUse(const std::string& key) OVERRIDE;
32 virtual size_t GetBytesInUse(const std::vector<std::string>& keys) OVERRIDE;
33 virtual size_t GetBytesInUse() OVERRIDE;
34 virtual ReadResult Get(const std::string& key) OVERRIDE;
35 virtual ReadResult Get(const std::vector<std::string>& keys) OVERRIDE;
36 virtual ReadResult Get() OVERRIDE;
37 virtual WriteResult Set(
38 WriteOptions options,
39 const std::string& key,
40 const base::Value& value) OVERRIDE;
41 virtual WriteResult Set(
42 WriteOptions options, const base::DictionaryValue& values) OVERRIDE;
43 virtual WriteResult Remove(const std::string& key) OVERRIDE;
44 virtual WriteResult Remove(const std::vector<std::string>& keys) OVERRIDE;
45 virtual WriteResult Clear() OVERRIDE;
47 private:
48 scoped_ptr<ValueStore::Error> TestingError();
50 base::DictionaryValue storage_;
51 int read_count_;
52 int write_count_;
53 ErrorCode error_code_;
55 DISALLOW_COPY_AND_ASSIGN(TestingValueStore);
58 #endif // CHROME_BROWSER_VALUE_STORE_TESTING_VALUE_STORE_H_