summaryrefslogtreecommitdiffstats
path: root/content/browser/fileapi/mock_file_update_observer.h
blob: 78aef9fae253e2bf1fda533f33f0a7de3de25999 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef WEBKIT_BROWSER_FILEAPI_MOCK_FILE_UPDATE_OBSERVER_H_
#define WEBKIT_BROWSER_FILEAPI_MOCK_FILE_UPDATE_OBSERVER_H_

#include <map>

#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "storage/browser/fileapi/file_observers.h"
#include "storage/browser/fileapi/file_system_url.h"
#include "storage/browser/fileapi/task_runner_bound_observer_list.h"

namespace storage {

// Mock file change observer.
class MockFileUpdateObserver : public FileUpdateObserver {
 public:
  MockFileUpdateObserver();
  ~MockFileUpdateObserver() override;

  // Creates a ChangeObserverList which only contains given |observer|.
  static UpdateObserverList CreateList(MockFileUpdateObserver* observer);

  // FileUpdateObserver overrides.
  void OnStartUpdate(const FileSystemURL& url) override;
  void OnUpdate(const FileSystemURL& url, int64 delta) override;
  void OnEndUpdate(const FileSystemURL& url) override;

  void Enable() { is_ready_ = true; }

  void Disable() {
    start_update_count_.clear();
    end_update_count_.clear();
    is_ready_ = false;
  }

 private:
  std::map<FileSystemURL, int, FileSystemURL::Comparator> start_update_count_;
  std::map<FileSystemURL, int, FileSystemURL::Comparator> end_update_count_;
  bool is_ready_;

  DISALLOW_COPY_AND_ASSIGN(MockFileUpdateObserver);
};

}  // namespace storage

#endif  // WEBKIT_BROWSER_FILEAPI_MOCK_FILE_UPDATE_OBSERVER_H_