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

Unified Diff: webkit/fileapi/test_mount_point_provider.cc

Issue 10386069: Add RegisterMountPointProvider and TestMountPointProvider for testing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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: webkit/fileapi/test_mount_point_provider.cc
diff --git a/webkit/fileapi/test_mount_point_provider.cc b/webkit/fileapi/test_mount_point_provider.cc
new file mode 100644
index 0000000000000000000000000000000000000000..eda05876d01542ccfd1f2d9ed6331157c75eb5c8
--- /dev/null
+++ b/webkit/fileapi/test_mount_point_provider.cc
@@ -0,0 +1,147 @@
+// Copyright (c) 2012 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.
+
+#include "webkit/fileapi/test_mount_point_provider.h"
+
+#include <vector>
+
+#include "base/file_util.h"
+#include "base/sequenced_task_runner.h"
+#include "webkit/fileapi/file_system_file_reader.h"
+#include "webkit/fileapi/file_system_operation.h"
+#include "webkit/fileapi/file_system_quota_util.h"
+#include "webkit/fileapi/local_file_util.h"
+#include "webkit/fileapi/native_file_util.h"
+
+namespace fileapi {
+
+namespace {
+
+// This only supports single origin.
+class TestFileSystemQuotaUtil : public FileSystemQuotaUtil {
+ public:
+ TestFileSystemQuotaUtil(base::SequencedTaskRunner* task_runner)
tzik 2012/05/10 08:31:00 need explicit?
kinuko 2012/05/11 06:59:34 Done.
+ : FileSystemQuotaUtil(task_runner), usage_(0) {}
+ virtual ~TestFileSystemQuotaUtil() {}
+
+ virtual void GetOriginsForTypeOnFileThread(
+ FileSystemType type,
+ std::set<GURL>* origins) OVERRIDE {
+ NOTREACHED();
+ }
+ virtual void GetOriginsForHostOnFileThread(
+ FileSystemType type,
+ const std::string& host,
+ std::set<GURL>* origins) OVERRIDE {
+ NOTREACHED();
+ }
+ virtual int64 GetOriginUsageOnFileThread(
+ const GURL& origin_url,
+ FileSystemType type) OVERRIDE {
+ return usage_;
+ }
+ virtual void NotifyOriginWasAccessedOnIOThread(
+ quota::QuotaManagerProxy* proxy,
+ const GURL& origin_url,
+ FileSystemType type) OVERRIDE {
+ // Do nothing.
+ }
+ virtual void UpdateOriginUsageOnFileThread(
+ quota::QuotaManagerProxy* proxy,
+ const GURL& origin_url,
+ FileSystemType type,
+ int64 delta) OVERRIDE {
+ usage_ += delta;
+ }
+ virtual void StartUpdateOriginOnFileThread(
+ const GURL& origin_url,
+ FileSystemType type) OVERRIDE {
+ // Do nothing.
+ }
+ virtual void EndUpdateOriginOnFileThread(
+ const GURL& origin_url,
+ FileSystemType type) OVERRIDE {}
+ virtual void InvalidateUsageCache(const GURL& origin_url,
+ FileSystemType type) OVERRIDE {
+ usage_ = 0;
tzik 2012/05/10 08:31:00 This method should not reset usage. Could you leav
kinuko 2012/05/11 06:59:34 Done.
+ }
+
+ private:
+ int64 usage_;
+};
+
+} // namespace
+
+TestMountPointProvider::TestMountPointProvider(
+ base::SequencedTaskRunner* task_runner,
+ const FilePath& base_path)
+ : base_path_(base_path),
+ local_file_util_(new LocalFileUtil(new NativeFileUtil())),
+ quota_util_(new TestFileSystemQuotaUtil(task_runner)) {
+}
+
+TestMountPointProvider::~TestMountPointProvider() {
+}
+
+void TestMountPointProvider::ValidateFileSystemRoot(
+ const GURL& origin_url,
+ FileSystemType type,
+ bool create,
+ const ValidateFileSystemCallback& callback) {
+ // This won't be called unless we add test code that opens a test
+ // filesystem by OpenFileSystem.
+ NOTREACHED();
+}
+
+FilePath TestMountPointProvider::GetFileSystemRootPathOnFileThread(
+ const GURL& origin_url,
+ FileSystemType type,
+ const FilePath& virtual_path,
+ bool create) {
+ DCHECK_EQ(kFileSystemTypeTest, type);
tzik 2012/05/10 08:31:00 Maybe, we should check if the directory exists, an
kinuko 2012/05/11 06:59:34 Done.
+ if (create)
+ file_util::CreateDirectory(base_path_);
+ return base_path_;
+}
+
+bool TestMountPointProvider::IsAccessAllowed(
+ const GURL& origin_url, FileSystemType type, const FilePath& virtual_path) {
+ return type == fileapi::kFileSystemTypeTest;
+}
+
+bool TestMountPointProvider::IsRestrictedFileName(
+ const FilePath& filename) const {
+ return false;
+}
+
+std::vector<FilePath> TestMountPointProvider::GetRootDirectories() const {
+ return std::vector<FilePath>();
tzik 2012/05/10 08:31:00 extra space?
kinuko 2012/05/11 06:59:34 Fixed.
+}
+
+FileSystemFileUtil* TestMountPointProvider::GetFileUtil() {
+ return local_file_util_.get();
+}
+
+FilePath TestMountPointProvider::GetPathForPermissionsCheck(
+ const FilePath& virtual_path) const {
+ return base_path_.Append(virtual_path);
+}
+
+FileSystemOperationInterface*
+TestMountPointProvider::CreateFileSystemOperation(
+ const GURL& origin_url,
+ FileSystemType file_system_type,
+ const FilePath& virtual_path,
+ FileSystemContext* context) const {
+ return new FileSystemOperation(context);
+}
+
+webkit_blob::FileReader* TestMountPointProvider::CreateFileReader(
+ const GURL& url,
+ int64 offset,
+ FileSystemContext* context) const {
+ return new FileSystemFileReader(context, url, offset);
+}
+
+} // namespace fileapi

Powered by Google App Engine
This is Rietveld 408576698