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 WEBKIT_BROWSER_FILEAPI_MOCK_FILE_CHANGE_OBSERVER_H_
6#define WEBKIT_BROWSER_FILEAPI_MOCK_FILE_CHANGE_OBSERVER_H_
7
8#include "base/basictypes.h"
9#include "base/compiler_specific.h"
10#include "storage/browser/fileapi/file_observers.h"
11#include "storage/browser/fileapi/file_system_url.h"
12#include "storage/browser/fileapi/task_runner_bound_observer_list.h"
13
14namespace storage {
15
16// Mock file change observer.
17class MockFileChangeObserver : public FileChangeObserver {
18 public:
19  MockFileChangeObserver();
20  virtual ~MockFileChangeObserver();
21
22  // Creates a ChangeObserverList which only contains given |observer|.
23  static ChangeObserverList CreateList(MockFileChangeObserver* observer);
24
25  // FileChangeObserver overrides.
26  virtual void OnCreateFile(const FileSystemURL& url) OVERRIDE;
27  virtual void OnCreateFileFrom(const FileSystemURL& url,
28                                const FileSystemURL& src) OVERRIDE;
29  virtual void OnRemoveFile(const FileSystemURL& url) OVERRIDE;
30  virtual void OnModifyFile(const FileSystemURL& url) OVERRIDE;
31  virtual void OnCreateDirectory(const FileSystemURL& url) OVERRIDE;
32  virtual void OnRemoveDirectory(const FileSystemURL& url) OVERRIDE;
33
34  void ResetCount() {
35    create_file_count_ = 0;
36    create_file_from_count_ = 0;
37    remove_file_count_ = 0;
38    modify_file_count_ = 0;
39    create_directory_count_ = 0;
40    remove_directory_count_ = 0;
41  }
42
43  bool HasNoChange() const {
44    return create_file_count_ == 0 &&
45           create_file_from_count_ == 0 &&
46           remove_file_count_ == 0 &&
47           modify_file_count_ == 0 &&
48           create_directory_count_ == 0 &&
49           remove_directory_count_ == 0;
50  }
51
52  int create_file_count() const { return create_file_count_; }
53  int create_file_from_count() const { return create_file_from_count_; }
54  int remove_file_count() const { return remove_file_count_; }
55  int modify_file_count() const { return modify_file_count_; }
56  int create_directory_count() const { return create_directory_count_; }
57  int remove_directory_count() const { return remove_directory_count_; }
58
59  int get_and_reset_create_file_count() {
60    int tmp = create_file_count_;
61    create_file_count_ = 0;
62    return tmp;
63  }
64  int get_and_reset_create_file_from_count() {
65    int tmp = create_file_from_count_;
66    create_file_from_count_ = 0;
67    return tmp;
68  }
69  int get_and_reset_remove_file_count() {
70    int tmp = remove_file_count_;
71    remove_file_count_ = 0;
72    return tmp;
73  }
74  int get_and_reset_modify_file_count() {
75    int tmp = modify_file_count_;
76    modify_file_count_ = 0;
77    return tmp;
78  }
79  int get_and_reset_create_directory_count() {
80    int tmp = create_directory_count_;
81    create_directory_count_ = 0;
82    return tmp;
83  }
84  int get_and_reset_remove_directory_count() {
85    int tmp = remove_directory_count_;
86    remove_directory_count_ = 0;
87    return tmp;
88  }
89
90 private:
91  int create_file_count_;
92  int create_file_from_count_;
93  int remove_file_count_;
94  int modify_file_count_;
95  int create_directory_count_;
96  int remove_directory_count_;
97
98  DISALLOW_COPY_AND_ASSIGN(MockFileChangeObserver);
99};
100
101}  // namespace storage
102
103#endif  // WEBKIT_BROWSER_FILEAPI_MOCK_FILE_CHANGE_OBSERVER_H_
104