Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / extensions / browser / value_store / testing_value_store.h
1 // Copyright 2014 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.
4
5 #ifndef EXTENSIONS_BROWSER_VALUE_STORE_TESTING_VALUE_STORE_H_
6 #define EXTENSIONS_BROWSER_VALUE_STORE_TESTING_VALUE_STORE_H_
7
8 #include "base/compiler_specific.h"
9 #include "extensions/browser/value_store/value_store.h"
10
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   ~TestingValueStore() override;
17
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; }
21
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_; }
29
30   // ValueStore implementation.
31   size_t GetBytesInUse(const std::string& key) override;
32   size_t GetBytesInUse(const std::vector<std::string>& keys) override;
33   size_t GetBytesInUse() override;
34   ReadResult Get(const std::string& key) override;
35   ReadResult Get(const std::vector<std::string>& keys) override;
36   ReadResult Get() override;
37   WriteResult Set(WriteOptions options,
38                   const std::string& key,
39                   const base::Value& value) override;
40   WriteResult Set(WriteOptions options,
41                   const base::DictionaryValue& values) override;
42   WriteResult Remove(const std::string& key) override;
43   WriteResult Remove(const std::vector<std::string>& keys) override;
44   WriteResult Clear() override;
45   // TestingValueStores can't get corrupted (they're all in-memory), so these
46   // just return true.
47   bool Restore() override;
48   bool RestoreKey(const std::string& key) override;
49
50  private:
51   scoped_ptr<ValueStore::Error> TestingError();
52
53   base::DictionaryValue storage_;
54   int read_count_;
55   int write_count_;
56   ErrorCode error_code_;
57
58   DISALLOW_COPY_AND_ASSIGN(TestingValueStore);
59 };
60
61 #endif  // EXTENSIONS_BROWSER_VALUE_STORE_TESTING_VALUE_STORE_H_